[Elgg 1.8-1.12 & 2.X: Gifts] v1.8.0beta1

Release Notes

Initial release! Please test it before using on a productive site!

  • Updated Gifts plugin for Elgg 1.8,
  • Several fixes since Elgg 1.7 version.
  • @iionly I tried arranging the plugins as you said but I was till unable to get it to work. The cost for the gift itself appears correct but the amount for the user is incorrect, for example I have 24 points but the send page says I have 184. The points within our site are manually aproved, I dont know if that makes a difference.

    And thank you for getting back to me

  • @Miks101: if you have the userpoints manually approved on your site it does make a difference for the gifts plugin, too. You should see some entries on the "Moderate" tab of the userpoints plugin with a negative number of points (= cost of the gifts). Only if you approve these actions the points for the gifts will get substracted. It will only work automatically, if you set the points to be approved automatically, too, I'm afraid. Also, you might need to make some adjustments on the userpoints plugin settings on the "Plugin settings" tab: "Allow points to be substracted" should be set to "yes". The difference in the points shown on the profile page and the points shown on the "Send gift" page can happen due to the moderated userpoints, too.

    In addition the userpoints settings "Allow points to be deleted" ("Plugin settings") and "Delete points if the content they were awarded for is deleted" ("Points settings") also could result in a difference. The reason is that the userpoints plugin differs between "Approved" and "Pending" userpoints while the gift plugin only counts the "Approved" points. Under some circumstances the points shown by the userpoints plugin and the gift plugin might differ unfortunately. I thought so far this might only happen in connection with Elgg annotations (for example comments) as the points for the annotations can not be deleted by the userpoints plugin yet. But I might need to do some more thorough testing to see if it might be some undetected bug in the code, too...

  • remove an uploaded image as a gift?

  • @jesus524: are you asking how to disable/ remove a gift from being selectable to be sent? As I mentioned in an earlier comment here, this is currently not possible. I don't know if there's a way to implement this without all gifts sent using this image getting lost, too. If you want to, you can replace an image with another one by uploaded a new image to the same slot. If you want to delete the image file from the server you can delete the image (and the resized thumbnail files) from the image folder in the gift plugin folder.

  • Kwanzaa is coming! It's gift time! Thanks!

     

  • is there a way to make the gifts so only the admin can give them?

  • @crystal waldeck: the gifts plugin does not include any option to restrict sending gifts to admins only. But it shouldn't be too complicated for you to modify the code to achieve this. Take a look at start.php of the gifts plugin. You can restrict the display of the "Send gift" and "Sent" menu items to admins by embedding the corresponding code into an additional if-clause:

    if(elgg_is_admin_logged_in()) {

    ...

    }

    In a similar way you would also need to modify the pagehandler function to only show the "Sent" and "Send" pages if an admin is logged in. You might want to set up a little test installation for working on these modifications to see if there might be other changes necessary and to verify that everything works as intended.

  • thank you so much for your quick response, i have no idea what you mean but i am going to look it up in my text book and google it and try and figure it out, I just started a class working with php. 

     

    Thank you!

  • @crystal waldeck: it's not necessarily a question of knowing PHP but more a question of how to achieve it within the Elgg framework. Actually, it's not that difficult but you need to know a bit about the basics of Elgg and how an Elgg plugin is built up. If you want to get an overview about Elgg and development of Elgg plugins I would suggest to buy the book "Elgg 1.8 Social Networking" by Cash Costello. While you can get the same information surely for free for example here (http://docs.elgg.org/) or by studying the code of other Elgg plugins you can get surely a more structured introduction by this book.

    So, sending gifts only if you are an admin:

    You need to modify tw things:

    1. the corresponding menu entries should only be visible when logged in as admin,
    2. the corresponding pages should only be accessible to admins.

    All changes necessary to make are within the file start.php of the gifts plugin.

    No 1 - the menu entries:

    First we have the menu entries "Send gift" and "Sent gifts" in the sidebar. Of course, you want only admins being able to send gifts but in this case only admins will have "sent" any gifts, too. So, in the function gifts_init() you see these two menu entries getting created:

    elgg_register_menu_item('page', array('name' => elgg_echo('gifts:sent'),
                                              'text' => elgg_echo('gifts:sent'),
                                              'href' => $CONFIG->wwwroot."gifts/" . $_SESSION['user']->username . "/sent",
                                              'context' => 'gifts',
                                              'section' => 'default'));
    elgg_register_menu_item('page', array('name' => elgg_echo('gifts:sendgifts'),
                                              'text' => elgg_echo('gifts:sendgifts'),
                                              'href' => $CONFIG->wwwroot."gifts/" . $_SESSION['user']->username . "/sendgift",
                                              'context' => 'gifts',
                                              'section' => 'default'));

    To get them only to show for admins enclose them in a if-clause that checks if the logged in user is an admin:

    if (elgg_is_admin_logged_in()) {

    elgg_register_menu_item('page', array('name' => elgg_echo('gifts:sent'),
                                              'text' => elgg_echo('gifts:sent'),
                                              'href' => $CONFIG->wwwroot."gifts/" . $_SESSION['user']->username . "/sent",
                                              'context' => 'gifts',
                                              'section' => 'default'));
    elgg_register_menu_item('page', array('name' => elgg_echo('gifts:sendgifts'),
                                              'text' => elgg_echo('gifts:sendgifts'),
                                              'href' => $CONFIG->wwwroot."gifts/" . $_SESSION['user']->username . "/sendgift",
                                              'context' => 'gifts',
                                              'section' => 'default'));

    }

    Then we have the so called hover menu entry (that opens if you click on the downward arrow on user profile pictures). The same menu entry also shows up on user's profile pages below their avatar. To make this link only visible for admins, you need to change the if-clause condition in the function gifts_user_hover_menu(). Change

     if (elgg_is_logged_in() && elgg_get_logged_in_user_guid() != $user->guid) {
            $url = "mod/gifts/sendgift.php?send_to={$user->guid}";
            $item = new ElggMenuItem('gifts', elgg_echo("gifts:send"), $url);
            $item->setSection('action');
            $return[] = $item;
        }

    simply to

     if (elgg_is_admin_logged_in() && elgg_get_logged_in_user_guid() != $user->guid) {
            $url = "mod/gifts/sendgift.php?send_to={$user->guid}";
            $item = new ElggMenuItem('gifts', elgg_echo("gifts:send"), $url);
            $item->setSection('action');
            $return[] = $item;
        }

    For No 2 (access to the send / sent gifts pages):

    Elgg handles such this by so called page handler functions. In case of the gifts plugin it's the function gifts_page_handler(). This function controls what content a page is built up with depending on its URL and also if this page / URL does exist at all. You see a switch-clause used. For the pages / URL that end with "sent" and "sendgift" the code is

    case "sent":
                    @include(dirname(__FILE__) . "/sent.php");
                    return true;
                    break;
    case "sendgift":
                    @include(dirname(__FILE__) . "/sendgift.php");
                    return true;
                    break;

    If you change this code part to

    case "sent":
                    admin_gatekeeper;

                    @include(dirname(__FILE__) . "/sent.php");
                    return true;
                    break;
    case "sendgift":

                    admin_gatekeeper;
                    @include(dirname(__FILE__) . "/sendgift.php");
                    return true;
                    break;

    it should block access to these pages for non-admins. In case this code does not work (I've not tested myself), you would need to add the line

    admin_gatekeeper;

    at the beginning of the files sent.php and sendgift.php instead. "At the beginning" means after "<?php" but surely before the "require()" / "include()" lines in these files.

    I hope I haven't forgotten anything and I hope it works as expected.

  • Hello iionly, Thanks for all your hard work on this and other plugin for elgg, I am trying the gift plugin on my local xampp site running elgg 1.8.12 after following your 4 step installation process, uploading then enabling the gifts plugin I don't get any mention of the gifts settings under the sites admin/utilities. any ideas?

     

    Thanks

    Tony

  • I'm not sure why the gift settings section is not visible on your site. What I can think of is:

    • are you sure you downloaded the gifts plugin for Elgg 1.8 and not the gifts plugin for Elgg 1.7 by mistake?
    • maybe it helps to disable the gifts plugin, then remove the gifts folder and copy it again to the mod folder of your installation. Maybe there are some files missing/incomplete currently in your installation.
    • it might be some conflict with another plugin. I don't know which other plugin could cause such an issue though. Maybe it helps to place the gift plugin at the bottom of the pluginlist to find out if the settings section becomes visible then. If yes, you know at least that some other plugin is responsible. In the most extreme case you could even disable all other 3rd party plugins temporarily to see if the gifts settings section appears then...
  • Hi iiionly thank you for your message I don't know how but this was somehow my fault, I removed the gifts plugin from the site and downloaded gifts 1.8.0beta1 reinstalled it and vallah it's all working.

     

    Thanks for the heads up!

     

  • Plugin works great, absolutely no issues with it...Very nice!

  • what steps do i need to increase parameters for php.ini?

  • @Dave: it depends on your hosting plan if you can adjust max_file_uploads in php.ini (or if you are allowed to change any php.ini variables at all). If you have access to the server-wide php.ini file it's simply a matter of changing the value of max_file_uploads as some default value is already defined there. On shared servers you will most likely won't be able to modify php.ini though. Via CPanel you can't change it neither. If you have a VPS or dedicated server with WHM you can change any php.ini values via WHM. On other servers (or your local computer) you can modify php.ini directly with a text editor also.

    Unfortunatly, it's not possible to modify the value of max_file_uploads via Elgg's .htaccess file (as opposed to for example memory_limit or post_max_size which php allows to be changed via .htaccess). If you don't know how to change max_file_uploads or if you don't know if you can change it at all, I would suggest asking your webhoster's support about it.

    If you are stuck with a max_file_uploads value that does not allow you to upload gift images to higher slots, you can still use these slots by uploading the image to a lower slot first and then renaming the image file on the server in the mod/gifts/images directory by changing the number in the file name to fit the number of the higher slot you want to get it into.

    Sorry, that this is slightly complicated and surely not the best way to handle it. On my TODO list I have the task of trying to rewrite the upload code of the gifts plugin to allow for uploading of any number of gift images without any need of adjusting max_file_uploads. I've just not managed to find the time to deal with it...

  • Thanks iionly, this would do for now until a rewrite version is available!

Stats

  • Category: Misc
  • License: GNU General Public License (GPL) version 2
  • Updated: 2018-6-2
  • Downloads: 4857
  • Recommendations: 24

Other Projects

View iionly's plugins