Navigation

Pligg Support

In this post:
http://pligg.com/support/question/bug-fix-for-the-sidebar-saved-story-module/#question
I fixed a bug in the sidebar_saved Module that was preventing it from loading and displaying the saved stories in the sidebar. The bug was fixed assuming that the purpose of the sidebar_saved module is to list 5 (or the set limit) links in the sidebar, no matter who the logged-in user is. See discussion post:
http://pligg.com/support/question/issue-with-saved-stories/#question
From the discussion in the provided link, I understood from YankiDank that the module was intended to show saved stories that were saved by the logged-in user. In this case, the result is not met.
If you want to show any set of saved stories no matter who saved them, then keep the module as is. However, if you want to only show the saved stories by the logged-in user, then this is the solution:
First, I could not find a Smarty variable for the logged-in user id, so I had to create one as follows:
1. Open \libs\smartyvariables.php
2. Go to line 44 or look for “$main_smarty->assign('user_logged_in', $current_user->user_login);” and paste this right after it:

$main_smarty->assign('user_logged_id', $current_user->user_id);
3. Save and close
4. Open \modules\sidebar_saved\templates\sidebar_saved_index.tpl
5. Go to line 22 or look for “global $the_template, $main_smarty, $db;”
6. Paste this right after it: (this is to import the smarty variable we created above to php and be able to use it.)
$user_logged_id = $main_smarty->get_template_vars('user_logged_id');
7. Change this query:
$res = "select link_id,link_title,saved_id,saved_user_id,saved_link_id from ".table_links.",".table_saved_links." WHERE saved_link_id = link_id AND link_author = link_author ORDER BY saved_id DESC limit 5";
To this:
$res = "select link_id,link_title,saved_id,saved_user_id,saved_link_id from test_links , test_saved_links WHERE saved_user_id =$user_logged_id and link_id = saved_link_id ORDER BY saved_id DESC limit 5";
8. Save and close
Now the saved stories in the sidebar will only show those belonging to the logged-in user.

Possible Answers

    I finally got around to adding this to Github. I made some slight adjustments to your code, the most notable being a variable name change from $user_logged_id to just $user_id.

    https://github.com/Pligg/pligg-cms/commit/17fb083ce61356dd506dec8ad359eafe2d2dc759

    | Posted 87 days ago | Permalink | Hide Replies

    **ATTENTION YANKIDANK to uodate the Github***

    In \templates\bootstrap\pligg.tpl LINE 174, we find:

    {include file=$the_template"/functions/bookmark.tpl"}

    The \templates\bootstrap\functions\bookmark.tpl includes the scripts for the add/remove bookmarks and the ajax call to update the sidebar saved stories.

    Open \modules\sidebar_saved\update_rightpanel.php

    1- On LINE 13 (right before the query) add the following to get the main smarty variable of the logged in user:

    global $the_template, $main_smarty, $db;

    $user_logged_id = $main_smarty->get_template_vars('user_logged_id');

    Replace the query:

    $res = "select link_id,link_title,saved_id,saved_user_id,saved_link_id from ".table_links.",".table_saved_links." WHERE saved_link_id = link_id ORDER BY saved_id DESC limit 5";

    With this:

    $res = "select link_id,link_title,saved_id,saved_user_id,saved_link_id from ".table_links.",".table_saved_links." WHERE saved_user_id =$user_logged_id and link_id = saved_link_id ORDER BY saved_id DESC limit 5";

    Save and close.

    NOTE

    I am still using $user_logged_id to be conform to what I used above in the original fix. If you used YankiDank’s Github commit, then use:

    global $the_template, $main_smarty, $db;

    $user_id = $main_smarty->get_template_vars('user_id');

    $res = "select link_id,link_title,saved_id,saved_user_id,saved_link_id from ".table_links.",".table_saved_links." WHERE saved_user_id =$user_id and link_id = saved_link_id ORDER BY saved_id DESC limit 5";

    Now whenever a story is added/removed, there is no need to refresh as this fix will properly update the sidebar saved stories.

    | Posted 78 days ago | Permalink | Hide Replies

    Maan it works like a charm!

    You are perfect! It's great to have you here.

    | Posted 78 days ago | Permalink | Hide Replies

    Thank you for bringing this flaw up, so that we fix it! :-)

    | Posted 78 days ago | Permalink | Hide Replies

    Is this error fixed by any of the above? Downloaded 2.02 today and it's coming up regularly...

    [20-Aug-2014 10:49:45 UTC] PHP Warning: Invalid argument supplied for foreach() in /home/ecomme20/public_html/dollar.bargains/libs/friend.php on line 53

    | Posted 66 days ago | Permalink | Hide Replies

    You are in the wrong post. This error has nothing to do with what is discussed here. This post is for the saved stories in the side bar!

    | Posted 66 days ago | Permalink | Hide Replies

    Didnt look familiar. I followed it in here from this post where you commented on fixing it in this thread, but seems it wasnt for all the errors the OP had commented on :)

    | Posted 66 days ago | Permalink | Hide Replies

    The only difference between what Yankidank committed and my code here is what he changed the variable I created in the smartyvariables.php.

    I showed you the snapshots as a proof it is working and obvsiously YankiDank also tried it before committing it.

    Compare my steps above with what you have changed in your files and let me know.

    Go through the steps one more time and make sure they are followed correctly!

    | Posted 79 days ago | Permalink | Hide Replies

    Correction:

    In the query, I mistakenly left my pligg prefix in it. So please change, In step 7 above:

    To this:

    $res = "select link_id,link_title,saved_id,saved_user_id,saved_link_id from ".table_links.",".table_saved_links." WHERE saved_user_id =$user_logged_id and link_id = saved_link_id ORDER BY saved_id DESC limit 5";

    | Posted 79 days ago | Permalink | Hide Replies

    So, I did a new installation of pligg from github master so I didn't change anything and it still doesn't work. The files are made exactly in a way that 'Yankidank' commited . (So they have right prefixes)

    Here you have my test case which shows a bug:

    1. Create admin account during new installation of pligg.

    2. Submit a story from admin account.

    3. Register new account : 'user1'

    4.Logged in as 'user1' submit a story.

    So right now you have 2 stories One made by admin and second by user1.

    5. While still logged in as 'user1' please add to bookmarks only the story that was submitted by admin (admin is the author).

    6. Log out and Log in as admin.

    7. Add to bookmarks story that was submitted by user1.

    8. Now look to sidebar your sidebar saved storied -> There are 2 stories.

    Conclusion: When someone adds to bookmarks a story that is submitted by somebody else then this story shows up on both accounts in sidebar_saved. (on his account and the author of added story account)

    To be exact It will appear on the user account who adds the story (authored by some other person) to his bookmarks (which is good), and on account of the author of that story in sidebar_saved (which is wrong).

    | Posted 79 days ago | Permalink | Hide Replies

    "Conclusion: When someone adds to bookmarks a story that is submitted by somebody else then this story shows up on both accounts in sidebar_saved. (on his account and the author of added story account) "

    That's a completely wrong conclusion my friend!

    I just added this post as story on my development site by a new user. Then, user redwine added it. It showed in the saved stories for redwine but NOT to Giorgio who submitted the stories.

    To elaborate more:

    here is the query to get who saved what and display the stories for each user:

    $res = "select link_id,link_title,saved_id,saved_user_id,saved_link_id from ".table_links.",".table_saved_links." WHERE saved_user_id =$user_logged_id and link_id = saved_link_id ORDER BY saved_id DESC limit 5";

    if you notice in the WHERE clause, we are specifically asking for:

    WHERE saved_user_id =$user_logged_id

    This means we are limiting the result to only those stories bookmarked by the logged in user, hence we created the samrty variable in the smartyvariables.php

    Now if it happens that the submitter of the story bookmarked it and another user bookmarked it as well, then yes it will show to both in the saved stories.

    Have you tried to refresh the page after bookmarking a story?

    | Posted 78 days ago | Permalink | Hide Replies

    Ok, the solution is to refresh a page, after refreshing page it works fine. :D That's true you were right and I didn't check it.

    Nevertheless I have strange behaviour on the dynamic part of adding to sidebar saved. When I don't refresh page and I only click to add 1 story to bookmarks it sometimes adds more (for example it still remembers a story that i have added previously,and later removed from bookmarks - and refreshed site). After I refresh site once again it goes back to normal and shows proper stories in 'sidebar saved'. So there is a tiny flaw that could be improved. Please don't get me wrong - I am grateful that you have wrote the code - Thanks very much for your thorough explanation.

    | Posted 78 days ago | Permalink | Hide Replies

    I am glad it's working. I will take a look tomorrow and closely check the refreshing issue and possibly eliminate the need to it.

    | Posted 78 days ago | Permalink | Hide Replies

    And here are the snapshots

    | Posted 78 days ago | Permalink | Hide Replies

    Furthermore, here is the saved_links table with explanation. (attached)

    | Posted 78 days ago | Permalink | Hide Replies

    For me it (the improved code from github) still doesn't work well and here's why:

    1. There are 2 users : Andrew, John.

    Both of them have published stories.

    Right now both of them have empty list of saved stories.

    When Andrew adds to his saved stories one of stories that has been authored by John he has it in his sidebar and it's OK.

    When you log in as John and look at John's saved stories sidebar it is OK until John wants to save a story. When he click to save a story then in sidebar there is the story he just saved, and a story that Andrew saved (John is an author of that story, but he didn't add it to his saved stories. This story was saved by Andrew).

    When you look to "user/andrew/saved/" and "user/john/saved/ " tabs in Andrew or John profiles they have everything right - there are only stories saved by themselves. But there is a bug in sidebar.

    I'm not that good in programming, but maybe there is a solution to that by using the code that shows properly saved stories from profile tabs and implement them in sidebar.

    I hope you can understand my case. If something is not clear please ask me.

    Could you check if my problem is isolated, or this problem is common with the commit form github?

    Thanks

    | Posted 79 days ago | Permalink | Hide Replies

    You must have missed or incorrectly done something. Attached are 2 snapshots for 2 different users showing the save stories for each accordingly!

    | Posted 79 days ago | Permalink | Hide Replies

    Do I get it right? If I have a Pligg 2.0.1 and I change smartyvariables.php and modulessidebar_savedtemplatessidebar_saved_index.tpl according to the changes that 'yankidank' commited on github it should work with no other changes whatsoever ?

    | Posted 79 days ago | Permalink | Hide Replies

    Great, thanks for your follow up! :-)

    If you can take a look at my other posts, there are quite few things to also add to github.

    | Posted 87 days ago | Permalink | Hide Replies

Who Upvoted this Story

Pligg.com's Support area is where you can ask questions and get answers. Just getting started with the Support area? This section describes tips for participating.

Submitting a Question or Comment

By taking a minute to research previous posts you may receive an answer much faster than waiting for a response to a new question. Begin by searching the support section for an answer. Sometimes you may even want to extend your search to the entire pligg.com domain.

If you are unable to find a relevant answer, submit a new question or comment here. Please provide a detailed description and, when necessary, debugging information such as your server environment (a link to a <?php phypinfo(); ?> .php page would be very helpful), your web browser, and any steps necessary to reproduce your issue.

Submitting an Answer

If you have an answer or useful response that you would like to add to a post, you can submit it as a comment which other users will then vote on. Answers are sorted by most popular to least, allowing the best information to climb to the top of the page.

Please read and vote for existing answers before submitting your own, as there may already be an acceptable answer provided. You can use the "Reply" link found within an answer to submit a response to it, in case you want to expand or comment on someone else's contribution.

Including Files or Code

Sometimes it is necessary for you to attach a file or include a snippet of code for others to reference in your response. In most cases, you can .zip up files and attach them to a question or answer using Pligg's file manager. At times though this may fail, and in these circumstances we recommend using a third party host. Below we are including a list of recommended websites where you can share easily share file uploads (or snippets of code) through the web.