View Single Post
  #23 (permalink)  
Old 12-30-2007, 12:04 PM
redwine's Avatar
redwine redwine is offline
Pligg Donor
 
Join Date: Jul 2007
Location: Canada
Posts: 216
Thanks: 20
Thanked 102 Times in 65 Posts
[Solution] mail: "there is a new comment in your story"

Thanks to inggenia for the idea.

I came up with a fix for providing the user with an option to subscribe or not to a certain news/story that he or she posts. The user can always turn off/on this option by clicking on the “admin links” within the story post and then clicking on “Edit the title or description.”. I tested it thoroughly and it works with no problems.
Start by adding a new column to the links table in your database. This is needed to mark the stories that the user wants to receive emails whenever a comment is added to the story. It is “0” by default, meaning that this option was not selected. If selected, the value would be “1”.
Code:
 
ALTER TABLE `pligg_links` ADD COLUMN `link_subscribe` TINYINT( 1 ) NULL DEFAULT '0';
Open “/libs/lang.conf” and add the following under “SUBMIT - STEP 2” section:

Code:
 
//<SECTION>SUBMIT - STEP 2</SECTION><ADDED>0.5</ADDED>
PLIGG_Visual_Submit2Subscribe_To = "Check this option if you want to receive emails whenever other users comment on your story."
Save and close.
Open “submit_step_2.tpl” in your template folder and add the following right before the “{checkActionsTpl location="submit_step_2_pre_extrafields"}” line:
Code:
 
<br />
<label for"subscribeto"><input type="checkbox" name="subscribeto" id="subscribeto"> {#PLIGG_Visual_Submit2Subscribe_To#}</label><br/>
Save and close.
Open “submit_step_3.tpl” in your template folder and search for “$linkres->category=” and place the following in the same section:
Code:
$linkres->subscribe=$_POST['subscribeto']; 

Search for “$main_smarty->assign('submit_content” and add the following to the same section:
Code:
$main_smarty->assign('submit_subscribe', $linkres->subscribe); 
 
Save and close.
Now we have to provide an option to turn on and off this option. To do so, we modify the “editlink_edit_center.tpl” in your template folder by adding a checkbox like we did in the “submit_step_2.tpl”. However, we have to check the database for the value of the link_subscribe to set the checkbox as CHECKED or not. Remember that the author of the story can edit/modify the story by clicking on the “admin links” within the story post and then clicking on “Edit the title or description.”.
Open “editlink_edit_center.tpl” in your template folder and add the following anywhere you want before the submit button:
Notice the conditions (in red) to accurately set the checkbox state.
Code:
 
<br />            
<label for"subscribeto">{if $submit_subscribe eq 1}<input type="checkbox" name="subscribeto" id="subscribeto" CHECKED> {else} <input type="checkbox" name="subscribeto" id="subscribeto">{/if}{#PLIGG_Visual_Submit2Subscribe_To#}</label>
<br/><br/>
Save and close.
Now, we have to edit the “/libs/link.php” file to accommodate the new changes we have made.
Open “/libs/link.php” and add the following code:
In the “class link {“ section.
Add:
Code:
var $subscribe = 0; 

Right after the global declaration in the store() function, add:
Code:
if(isset($_POST['subscribeto'])){
$this->subscribe = "1";
}
 
Within the same store() function:
anywhere before the “$sql = "UPDATE " line add:
Code:
$link_subscribe = $db->escape($this->subscribe); 

Add the following to the “$sql = "UPDATE " line right before the “WHERE” condition:
Code:
, link_subscribe='$link_subscribe'
 
Look for “if($link) {“ section and add:

Code:
$this->subscribe = $link->link_subscribe; 

Look for the “function fill_smarty” section and add the following (make sure not to add it within an IF statement:
Code:
$smarty->assign('subscribe', $this->subscribe); 

Save and close.
Now open the “editlink.php” and look for “$edit = false;” then go down few lines and add the following after the “$linkres->read();”:
Code:
$link_subscribe=$linkres->subscribe; 

Go down few more lines to where the “$main_smarty->assign” begin and add:
Code:
$main_smarty->assign('submit_subscribe', $link_subscribe); 

Save and close.

Now the last step is to add the code to send the email if the option is selected.

Open “story.php”

Change this:

Code:
if(isset($_POST['process'])){
         if ($_POST['process']=='newcomment') {
                     insert_comment();
         }
}
 
Change it to:

Code:
if(isset($_POST['process'])){
         if ($_POST['process']=='newcomment') {
                     if ($link->subscribe==1) {
//If you find that most users do not provide a public email, it would be safer to change the query below to "Select user_email FROM" instead.
$authormail = $db->get_var("SELECT public_email FROM " .table_users ." WHERE user_id = $link->author;");
 
$subject= 'You have a new comment about your story ' . $link->title;
$message = "The following user '". $current_user->user_login . "' commented on your impact '" . $link->title . "'\r\n\r\n\t" . "'".$_POST['comment_content']. "\r\n\r\nHere is the link to the story: " . my_base_url . my_pligg_base . "/story.php?title=". $link->title_url . "\r\n\r\nRegards,\r\nAdministrator";
                                 $headers = "From: admin@yoursite.com"  . "\r\nReply-To: admin@yoursite.com " . "\r\nX-Priority: 1\r\n";
                                             $to=$authormail;
                                             @mail($to, $subject, $message, $headers);
                                 }
 
                                 insert_comment();
                     }
         }
 
The files that you need to upload:
  1. /libs/lang.conf
  2. /libs/link.php
  3. story.php
  4. editlink.php
  5. /templates/yourtemplate/editlink_edit_center.tpl
  6. /templates/yourtemplate/submit_step_2.tpl
  7. /templates/yourtemplate/submit_step_3.tpl

Last edited by redwine; 02-12-2008 at 05:55 PM.. Reason: Modified the $message in the last step to add a direct link to the story in the sent email
Reply With Quote
The Following 5 Users Say Thank You to redwine For This Useful Post: