"Save this" / "My Stories" completed MOD

Register an Account
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 03-08-2007, 01:44 PM
Casual Pligger
 
Join Date: Jan 2007
Posts: 47
Hey everyone, I just finished this del.icio.us-style mod. To test it out, try my pligg site: http://strandalo.us , and just create a quick user and click "Add to my games", you can then view them in your profile and "Remove from my games" if you wish. It should be noted that this is tested and works with Pligg beta 9 and DigitalNature template. Also, if you would please leave the comment left by me in the addstories.php and remstories.php code to give me credit, thank you! This mod is relatively simple to implement, so here we go!

1. First thing you need to do, login to PHPmyAdmin and create a table with the title "pligg_stories" or anything else you would like. I recommend just doing this by hand instead of using the query code. It is very easy to figure out, considering I knew NOTHING about php or sql before attempting this. Within the table, create 3 rows.

1st row: FIELD: stories_id, TYPE: INT(20), EXTRA: auto_increment
2nd row: FIELD: user_id, TYPE: INT(20), DEFAULT: 0
3rd row: FIELD: link_id, TYPE: INT(20), DEFAULT: 0

2. You will need 2 new files in your main directory, addstories.php and remstories.php. The code for them follows or you can just DOWNLOAD the attached files which are identical.

addstories.php:

Code:
<?php
include_once('Smarty.class.php');
$main_smarty = new Smarty;

include('config.php');
include(mnminclude.'html1.php');
include(mnminclude.'link.php');
include(mnminclude.'smartyvariables.php');

// "Save this" feature by Nick Strand, http://strandalo.us
// -------------------------------------------------------------------------------------

if($current_user->user_id != 0)
{
	global $db, $the_template;
	$linkid = $_REQUEST['category'];
	$link = new Link;
	$link->id=$linkid;
	$link->read();
	$title = $db->get_var("SELECT link_title_url FROM " . table_links . " WHERE link_id = $linkid");
	if (!$db->get_row("SELECT stories_id, user_id, link_id FROM " . table_stories . " WHERE link_id = $linkid AND user_id = $current_user->user_id"))
	{
		$sql="INSERT INTO " . table_stories . " (user_id, link_id) VALUES ($current_user->user_id, $linkid)";
		$db->query($sql);
	}
	if($_REQUEST['from'] == 1)
	{
		//header ('Location: http://strandalo.us/story.php?title='.$title);
		header ('Location: http://strandalo.us/user.php?login='.$current_user->user_login.'&view=stories');
	}
} 
?>
remstories.php:


Code:
<?php
include_once('Smarty.class.php');
$main_smarty = new Smarty;

include('config.php');
include(mnminclude.'html1.php');
include(mnminclude.'link.php');
include(mnminclude.'smartyvariables.php');

// "Save this" feature by Nick Strand, http://strandalo.us
// -------------------------------------------------------------------------------------

if($current_user->user_id != 0)
{
	global $db, $the_template;
	$linkid = $_REQUEST['category'];
	$link = new Link;
	$link->id=$linkid;
	$link->read();
	$title = $db->get_var("SELECT link_title_url FROM " . table_links . " WHERE link_id = $linkid");
	if ($db->get_row("SELECT stories_id, user_id, link_id FROM " . table_stories . " WHERE link_id = $linkid AND user_id = $current_user->user_id"))
	{
		$sql="DELETE FROM " . table_stories . " WHERE user_id=$current_user->user_id AND link_id=$linkid";
		$db->query($sql);
	}
	if($_REQUEST['from'] == 1)
	{
		//header ('Location: http://strandalo.us/story.php?title='.$title);
		header ('Location: http://strandalo.us/user.php?login='.$current_user->user_login.'&view=stories');
	}
} 
?>
3. Open up /config.php and on line 104 DEPENDING ON YOU PLIGG VERSION, add:

Code:
define('table_stories', table_prefix . "stories" );

or

if(!defined('table_stories')){ define('table_stories', table_prefix . "stories" ); }
4. Now we need to edit /templates/yourtemplate/link_summary.tpl, and depending on how familiar you are with pligg editing, you can put the link for "save it" anywhere you like. I had originally placed it next to "Bookmarks" in the "Add to..." drop down field, but I prefer its current location. Find the following code:

Code:
{if $isadmin eq "yes" || $user_logged_in eq $link_submitter}
...
{/if}
and directly AFTER that code, put the following:

Code:
<iframe height="1px;" width="1px;" frameborder="0" name="add_stories"></iframe>
{if $link_mine eq 0}
	<span id="stories">| <a target="add_stories" href="{$my_pligg_base}/addstories.php?category={$link_id}" onclick="show_hide_user_links(document.getElementById('stories-{$link_shakebox_index}'));">Save it!</a>
        {else}
	<span id="stories">| <a target="add_stories" href="{$my_pligg_base}/remstories.php?category={$link_id}" onclick="show_hide_user_links(document.getElementById('stories-{$link_shakebox_index}'));">Remove it!</a>
	{/if}
        </span>
{if $user_logged_in neq ""}
		{if $link_mine eq 0}
		<span id="stories-{$link_shakebox_index}" style="display:none;">
		 &raquo; <b>Success! Go to </b><a href="{$my_pligg_base}/user.php?login={$user_logged_in}&view=stories">My Stories</a> 	  
		 </span>
		{else}
		<span id="stories-{$link_shakebox_index}" style="display:none;">
		 &raquo; <b>Removed, Go to </b><a href="{$my_pligg_base}/user.php?login={$user_logged_in}&view=stories">My Stories</a>	  
		 </span>
		{/if}
		{else}
		
		<span id="stories-{$link_shakebox_index}" style="display:none;">
		 &raquo; <b>You must be logged in.</b>		 	  
		 </span>
		{/if}
Also, open up /libs/link.php and about line 520, add:

Code:
if ($db->get_row("SELECT * FROM " . table_stories . " WHERE user_id=$current_user->user_id AND link_id=$this->id"))
		{
			$smarty->assign('link_mine', 1);
		}
		else {
			$smarty->assign('link_mine', 0);
		}
and on line 353 of /libs/link.php, add $db to the list of variables in "function fill_smarty(" so it looks like:

Code:
global $current_user, $globals, $the_template, $db;
5. Now, open up /user.php and around line 138 or so, add:

Code:
if ($view == 'stories') {
	$main_smarty->assign('page_header', $user->username . ' / My Stories');
	$navwhere['text3'] = 'My Stories';
	$main_smarty->assign('posttitle', " / " . $main_smarty->get_config_vars('PLIGG_Visual_Breadcrumb_Profile') . " / " . $login . " / My Stories");
	}
and now around line 195 (just above function do_voted () ), add:

Code:
function do_stories () {
	global $db, $rows, $user, $offset, $page_size;
	$link = new Link;
	$rows = $db->get_var("SELECT count(*) FROM " . table_stories . " WHERE user_id=$user->id");
	$links = $db->get_col("SELECT link_id FROM " . table_stories . " WHERE user_id=$user->id AND link_id=link_id ORDER BY link_id DESC LIMIT $offset,$page_size");
	if ($links) {
		foreach($links as $link_id) {
			$link->id=$link_id;
			$link->read();
			$link->print_summary('summary');
		}
	}
}
6. Finally, open up /templates/yourtemplate/user_center.tpl , and at about line 6 add the following which will place the tab on the left hand side (because it is listed last):

Code:
{if $user_view eq 'stories'}
<div class="tabs" style="margin-top:-50px;">
  <ul>
        <li><a href="{$user_url_personal_data}"><span>{#PLIGG_Visual_User_PersonalData#}</span></a></li>
    <li><a href="{$user_url_news_sent}"><span>{#PLIGG_Visual_User_NewsSent#}</span></a></li>
    <li><a href="{$user_url_news_published}"><span>{#PLIGG_Visual_User_NewsPublished#}</span></a></li>
    <li><a href="{$user_url_news_unpublished}"><span>{#PLIGG_Visual_User_NewsUnPublished#}</span></a></li>
    <li><a href="{$user_url_news_voted}"><span>{#PLIGG_Visual_User_NewsVoted#}</span></a></li>
    <li><a href="{$user_url_commented}"><span>{#PLIGG_Visual_User_NewsCommented#}</span></a></li>
    <li class="active"><a href="{$my_pligg_base}/user.php?login={$user_login}&view=stories"><span>My Stories</span></a></li>
  </ul>
  <br clear="all" />
</div>
{/if}
And then, every chunk of code which starts with something like "{if $user_view eq 'history'}" you will need to add this line RIGHT BEFORE the "</ul>" in that "chunk" of code. This will occur 10 times in the file (for $user_view eq: 1. history, 2. published, 3. shaken, 4. voted, 5. commented, 6. viewfriends, 7. viewfriends2, 8. removefriend, 9. addfriend and 10. profile) :

Code:
<li><a href="{$my_pligg_base}/user.php?login={$user_login}&view=stories"><span>My Stories</span></a></li>
Finally, go to the bottom of user_center.tpl and find all of the CASE statements, and somewhere in there put the following:
Code:
	
case 'stories':
   do_stories();
   do_pages($rows, $page_size, $the_page);
   break;

That should be it! You may notice some extra code in addstories.php or remstories.php like the $_REQUEST['from'] parts. That was used to redirect the user to the actual story page (or to My Stories) by changing the addstories.php link in link_summary.tpl to "addstories.php?category={$link_id}&from=1" which will set from=1 and therefore redirect the user.

One last thing, you may want to open /templates/yourtemplate/header.tpl and after this code:

Code:
<li id="navprofile"><a href="{$URL_userNoVar}" class="main"><span>{#PLIGG_Visual_Profile#}</span></a>
  <ul>
add this so there is a link from the profile menu button (digitalnature):

Code:
<li><a href="user.php?view=stories">View My Stories</a></li>
I hope this is useful to some of you, enjoy! Also, I am willing to do paid installations if anyone requires it as this took me a little while to put together. Cheers!

Update: I have tested this with the latest version of Pligg 9 and YGET template and it works perfectly, you may need to make slight adjustments for user_center.tpl according to YGET's format (instead of <li class="active"><a.... you use <li><a class="navbut4", for the active one and <a class="navbut3" for when it is not active)
Attached Files
File Type: zip savethis.zip (1.2 KB, 33 views)

Last edited by eH9116; 03-08-2007 at 09:52 PM.
Reply With Quote
  #2 (permalink)  
Old 03-08-2007, 02:37 PM
Pligg Developer/Admin
Pligg Version: 0
Pligg Template: none
 
Join Date: Jun 2006
Location: Muncie, Indiana
Posts: 3,215
Very awesome mod I'll clean it up a bit and put it in Pligg. I know back in the day Savant was thinking about working on something like this so hopefully he wasn't in the middle of that :P
Reply With Quote
  #3 (permalink)  
Old 03-08-2007, 03:32 PM
Banned
Pligg Version: 9.8.
Pligg Template: Custom
 
Join Date: Feb 2007
Location: Canada
Posts: 796
Great mod. The only thing I don't like is if I remove a link, then it goes to a blank page.

Did I do something wrong?

Geoserv.
Reply With Quote
  #4 (permalink)  
Old 03-08-2007, 03:42 PM
savant's Avatar
Constant Pligger
 
Join Date: Apr 2006
Location: UK
Posts: 1,181
ashamed to say: i wasn't working on it.

thanks for the contribution
Reply With Quote
  #5 (permalink)  
Old 03-08-2007, 04:45 PM
Casual Pligger
 
Join Date: Jan 2007
Posts: 47
hey Geoserv, it was a small bug, that is now fixed, look at the "link_summary.tpl" code again and update it.
Reply With Quote
  #6 (permalink)  
Old 03-08-2007, 05:15 PM
Casual Pligger
 
Join Date: Jan 2007
Posts: 47
Hey guys, I just updated it AGAIN, now when they already have it added to their list of stories, it will show a "remove this story" instead of "save this story" on ANY page. For all of you who already did it, the only updates were to link_summary.tpl and link.php....
Reply With Quote
  #7 (permalink)  
Old 03-08-2007, 05:47 PM
Pligg Developer/Admin
Pligg Version: 0
Pligg Template: none
 
Join Date: Jun 2006
Location: Muncie, Indiana
Posts: 3,215
I've been messing with it quite a bit and I'm not sure if this is a problem on my end or not but with the latest code it always says "Already added" whenever I tried to remove a story. It still removes the story correctly but the message is wrong.
Reply With Quote
  #8 (permalink)  
Old 03-08-2007, 09:44 PM
Casual Pligger
 
Join Date: Jan 2007
Posts: 47
oh wow, I'm retarded, the text should just say "Removed," instead of "Already added", problem fixed.
Reply With Quote
  #9 (permalink)  
Old 03-08-2007, 09:53 PM
Banned
Pligg Version: 9.8.
Pligg Template: Custom
 
Join Date: Feb 2007
Location: Canada
Posts: 796
what changed in the link.php file?

Geoserv
Reply With Quote
  #10 (permalink)  
Old 03-08-2007, 10:00 PM
Banned
Pligg Version: 9.8.
Pligg Template: Custom
 
Join Date: Feb 2007
Location: Canada
Posts: 796
where abouts is line 520? Whats above or below it?
Reply With Quote
Reply

Thread Tools
Display Modes




Pligg Modules and Pligg Templates from Pligg Pro Find support on the Pligg CMS Forum - 24 hours a day! Make a donation to support Pligg CMS development