SMF Shop

SMFShop => Coding => Topic started by: Smith Online on April 15, 2007, 03:13:10 am

Title: Joining SMF Gallery Pro to Smf Shop
Post by: Smith Online on April 15, 2007, 03:13:10 am
Is there any way i can given my members 10 credit for posting a image in the gallery.

Regards

Smith-Online
Title: Re: Joining SMF Gallery Pro to Smf Shop
Post by: Smith Online on May 21, 2007, 05:27:05 am
anyone???
Title: Re: Joining SMF Gallery Pro to Smf Shop
Post by: David on May 21, 2007, 08:01:58 pm
Not currently...it would need a mod like the one Hambil was kind enough to write and that links the shop to SMF Arcade.
Title: Re: Joining SMF Gallery Pro to Smf Shop
Post by: olandir on May 23, 2007, 08:15:04 am
I've done it actually... I do it in my forums (actually I give 25 credits but that's not the point)

Do you still need to know how?
Title: Re: Joining SMF Gallery Pro to Smf Shop
Post by: David on May 23, 2007, 09:09:57 am
Yes please! Saves me losing a few more hairs off of my already quite bald head...not all gone from thinking about too much code but it's probably seen some of them off.
Title: Re: Joining SMF Gallery Pro to Smf Shop
Post by: olandir on May 23, 2007, 10:48:09 am
Okay, it's pretty simple actually.

All you have to do is edit Gallery.php in your sources directory. Because Gallery.php is added in its entirety by the smfgallery mod, you can edit it and it won't mess you up if you need to uninstall it. (Just remember to go back and make the edits again when you upgrade) because smfgallery will wipe out the changes on an upgrade.

1) Find the AddPicture2 function

2) Look for this piece of code (it's near the end of the function)

Code: [Select]
//Last recheck Image if it was resized

3) Add this code in before it

Code: [Select]
// BEGIN SMFShop New Version (Build 12) code
$points = 10;
// Give the user their points
$result_shop = db_query("
UPDATE {$db_prefix}members
SET money = money + {$points}
WHERE ID_MEMBER = {$ID_MEMBER}
LIMIT 1", __FILE__, __LINE__);

// END SMFShop


Note the $points = 10, that's what tells the script how many points to add. So you can set it to any number

-----
Also you need to do this one other place. It's the exact same process

1) Find the BulkAdd2 function

2) Look for this piece of code (it's near the end of the function)

Code: [Select]
//Last recheck Image if it was resized

3) Add this code in before it

Code: [Select]
// BEGIN SMFShop New Version (Build 12) code
$points = 10;
// Give the user their points
$result_shop = db_query("
UPDATE {$db_prefix}members
SET money = money + {$points}
WHERE ID_MEMBER = {$ID_MEMBER}
LIMIT 1", __FILE__, __LINE__);

// END SMFShop


-----

Now your users will get points whether they do a regular add or a bulk add. Like I said, if you upgrade the smfgallery mod, it will more than likely completely overwrite the gallery script, so you'll need to be sure to apply these changes whenever you do that. But it's pretty straight forward.

Hope this helps. Let me know if something doesn't work.
Title: Re: Joining SMF Gallery Pro to Smf Shop
Post by: David on May 23, 2007, 10:58:07 am
Thanks very much for this...perhaps it would be a good idea to package it up just for ease of installation...i'll do that if you want...let me know.
Title: Re: Joining SMF Gallery Pro to Smf Shop
Post by: olandir on May 23, 2007, 11:01:16 am
The reason why I didn't do that is because the smfgallery package always overwrites gallery.php (it doesn't edit it even if the file already exists), so it seemed pointless. I'd always have to be re-applying the package

So what I do instead is when I get the smfgallery package, I go into the package itself, and edit gallery.php before I install the package, that way the package is complete the way I want it before I install (i make some other changes too besides this one). It's easier for me to keep up with that way.
Title: Re: Joining SMF Gallery Pro to Smf Shop
Post by: David on May 23, 2007, 06:16:40 pm
 Fair enough...and thanks again for your code.

 The edits you've been kind enough to supply apply to the pro version only...the "Lite" version is even easier to modify this way as there is no bulk uploader and thus there is only one function to edit...

 Add the code given by olandir above the following line:

Code: [Select]
//Redirect to the users image page.
 BTW I've never used the pro version of SMF Gallery myself...when I need to give more than the "Lite" version offers I use Oldiesman's bridge to Menalto Gallery (Open Source) instead...it's such an excellent product and so very full featured it didn't seem, to me, to be worth looking at a pay to use option instead...but that's just me.

 I tend to offer edits as packages simply because any edit task puts some users off trying a modification whereas if you offer it as a package they'll have no hesitation in using it...editaphobia perhaps.
Title: Re: Joining SMF Gallery Pro to Smf Shop
Post by: olandir on May 23, 2007, 09:56:13 pm
Sorry, I forgot that there were two versions. I'm glad you were able to figure out where to put it in the "light" version.

I do a lot of other changes in the gallery.php, to make it do things like

- Count each picture that a user adds to the gallery as a "post" in their post count
- Count each comment that a user posts as a "post"
- The intergration with the shop
- Integration with "karma" so that rating a picture affects a person's karma
- Other changes (lol)

So yeah, I basically created my own "gallery" package. But I really like smfgallery because it's already so tightly integrated into SMF it makes it easy to make the changes I want. The only thing it doesn't do that I really want is to allow people to post a picture to more than one category... but maybe I'll mod the script myself to do that :).
Title: Re: Joining SMF Gallery Pro to Smf Shop
Post by: Daniel15 on May 26, 2007, 10:02:07 am
Just to make the code a little neater, you could replace
Code: [Select]
// BEGIN SMFShop New Version (Build 12) code
$points = 10;
// Give the user their points
$result_shop = db_query("
UPDATE {$db_prefix}members
SET money = money + {$points}
WHERE ID_MEMBER = {$ID_MEMBER}
LIMIT 1", __FILE__, __LINE__);

// END SMFShop

With
Code: [Select]
// Begin SMFShop code - Modified as per http://www.daniel15.com/forum/index.php/topic,795.0.html
$points = 10;
updateMemberData($context['user']['id'], array('money' => 'money + ' . $points);
// End SMFShop code
:)
Title: Re: Joining SMF Gallery Pro to Smf Shop
Post by: David on May 26, 2007, 10:24:50 am
Thanks Daniel...it's comforting to know you're looking over our shoulders....I think... ;)
Title: Re: Joining SMF Gallery Pro to Smf Shop
Post by: Daniel15 on May 26, 2007, 10:50:14 am
Thanks Daniel...it's comforting to know you're looking over our shoulders....I think... ;)
Hehe, as a part of the SMF Customisation Team, my reaction when I see a segment of code is to clean it up as much as possible :P.
Indeed, a lot of the SMFShop code is very messy at the moment (especially compared to some of my recent mods like SMFBlog), I will work on cleaning it up eventually.
Title: Re: Joining SMF Gallery Pro to Smf Shop
Post by: olandir on May 26, 2007, 10:55:41 am
oh I never knew you could do that, I just copied the code directly from the shop mod :) sorry.
Title: Re: Joining SMF Gallery Pro to Smf Shop
Post by: Daniel15 on May 26, 2007, 11:05:35 am
oh I never knew you could do that, I just copied the code directly from the shop mod :) sorry.
No problem :D. Like I said, some of the SMFShop code is still messy :P
Title: Re: Joining SMF Gallery Pro to Smf Shop
Post by: olandir on May 29, 2007, 01:51:49 am
Hey, just a follow up.

It looks like you forgot an end parenthesis in that code

Code: [Select]
updateMemberData($context['user']['id'], array('money' => 'money + ' . $points);
It looks like it should be

Code: [Select]
updateMemberData($context['user']['id'], array('money' => 'money + ' . $points));
Also I decided to use:

Code: [Select]
updateMemberData($ID_MEMBER, array('money' => 'money + ' . $points));
is there a reason why you use the $context instead of $ID_MEMBER?  This is purely a curiousity question because I'm still learning SMF coding structure.
Title: Re: Joining SMF Gallery Pro to Smf Shop
Post by: vbgamer45 on May 31, 2007, 09:34:31 pm
Okay, it's pretty simple actually.

All you have to do is edit Gallery.php in your sources directory. Because Gallery.php is added in its entirety by the smfgallery mod, you can edit it and it won't mess you up if you need to uninstall it. (Just remember to go back and make the edits again when you upgrade) because smfgallery will wipe out the changes on an upgrade.

1) Find the AddPicture2 function

2) Look for this piece of code (it's near the end of the function)

Code: [Select]
//Last recheck Image if it was resized

3) Add this code in before it

Code: [Select]
// BEGIN SMFShop New Version (Build 12) code
$points = 10;
// Give the user their points
$result_shop = db_query("
UPDATE {$db_prefix}members
SET money = money + {$points}
WHERE ID_MEMBER = {$ID_MEMBER}
LIMIT 1", __FILE__, __LINE__);

// END SMFShop


Note the $points = 10, that's what tells the script how many points to add. So you can set it to any number

-----
Also you need to do this one other place. It's the exact same process

1) Find the BulkAdd2 function

2) Look for this piece of code (it's near the end of the function)

Code: [Select]
//Last recheck Image if it was resized

3) Add this code in before it

Code: [Select]
// BEGIN SMFShop New Version (Build 12) code
$points = 10;
// Give the user their points
$result_shop = db_query("
UPDATE {$db_prefix}members
SET money = money + {$points}
WHERE ID_MEMBER = {$ID_MEMBER}
LIMIT 1", __FILE__, __LINE__);

// END SMFShop


-----

Now your users will get points whether they do a regular add or a bulk add. Like I said, if you upgrade the smfgallery mod, it will more than likely completely overwrite the gallery script, so you'll need to be sure to apply these changes whenever you do that. But it's pretty straight forward.

Hope this helps. Let me know if something doesn't work.

If you would use this by default. I can add a setting in Gallery Lite/Pro to increase points for each image uploaded and allow you to specify the points amount. I can also have it remove points if the image is deleted.