SMF Shop
SMFShop => Coding => Topic started 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
-
anyone???
-
Not currently...it would need a mod like the one Hambil was kind enough to write and that links the shop to SMF Arcade.
-
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?
-
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.
-
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)
//Last recheck Image if it was resized
3) Add this code in before it
// 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)
//Last recheck Image if it was resized
3) Add this code in before it
// 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.
-
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.
-
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.
-
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:
//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.
-
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 :).
-
Just to make the code a little neater, you could replace
// 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
// 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
:)
-
Thanks Daniel...it's comforting to know you're looking over our shoulders....I think... ;)
-
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.
-
oh I never knew you could do that, I just copied the code directly from the shop mod :) sorry.
-
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
-
Hey, just a follow up.
It looks like you forgot an end parenthesis in that code
updateMemberData($context['user']['id'], array('money' => 'money + ' . $points);
It looks like it should be
updateMemberData($context['user']['id'], array('money' => 'money + ' . $points));
Also I decided to use:
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.
-
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)
//Last recheck Image if it was resized
3) Add this code in before it
// 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)
//Last recheck Image if it was resized
3) Add this code in before it
// 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.