Nucleus Support Forum Index

Find on the forum:
any terms  all terms  Advanced Search

RSS 2.0
Browse posts: Unanswered | Mark all read

« »
Loading Nucleus FAQ ticker...
Post new topic Reply to topic
Author Message
matt_t_hat
Nucleus Geek


Joined: 21 Aug 2005
Posts: 1124
Location: UK

Post Posted: Fri Sep 12, 2008 12:41 pm   Post subject: NP_FriendlyComment - Protect readers/commenter email address
Reply with quote

I wanted a way to stop email addresses showing up when people posted comments. Up to now this had not been much of an issue but I am now blogging in a niche that has less awareness of such issues and does not contain "pro" or full time bloggers.

I felt that the default of showing the email address was a bit rude and unfriendly to new readers without blogs to link to. I also feel that it has been keeping my comment level lower than it could be.

This was my solution.

Code:
<?php

class NP_FriendlyComment extends NucleusPlugin {

   function getName() {
      return 'Friendly Comment';
   }

   function getAuthor()  {
      return 'Lord Matt';
   }

   function getURL()
   {
      return 'http://lordmatt.co.uk';
   }

   function getVersion() {
      return '1.0';
   }

   function getDescription() {
      return 'Stops data being brashly shown (such as email adresses).';
   }

   function getEventList() { return array('PreComment'); }
   
   function event_PreComment(&$data){
      Global $manager;

      $pos = strpos($data['comment']['userlinkraw'], '@');

      if ($pos === false) {
         // do nothing it is a link and that's cool
      } else {
         $created = false;
         $url = '';
         $params = array('itemid'=>$data['comment']['itemid'], 'blogid'=>$data['comment']['blogid']);
         $manager->notify(
            'GenerateURL',
            array(
               'type' => 'item',
               'params' => $params,
               'completed' => &$created,
               'url' => &$url
            )
         );         
         $data['comment']['userlinkraw'] = $url . '#' . $data['commentid'];         
      }

   }

}



Tip: You might want to add a note near the comment area to the effect that email addresses are not shown to the public.

You will notice that there is no closing php tag this is deliberate as it uses a lesser known feature of PHP that is that as long as the code is fully valid and you don't need to drop back to HTML mode the close tag is not needed. Doing things this way stops copy and past errors from sending the headers with a little white space creeping in.

The code itself is dead simple and simply look for an "@" and if it finds one assumes it is an email address (a fairly safe assumption I think). When it finds an email address it replaces it with a link to the comment itself.

To dot ht it calls on the manager to fire the GenerateURL event and get back a full qualified URL to the item in question it then adds the comment id as a document reference link.

Possible Limit in the Nucleus core code there are two ways URLs are created fancy and default. Default is done purely internally and can not be called upon (something I feel is a weakness) as such you will need a URL solution of some sort (fancierURL2 works well for me) or a default URL making plugin to use this code.

Yes I know that one could add more if statements and replicate the core process for default URLs but I don't have a need to do that yet so I have not.

It should go without saying that I'm sharing this under the GNU GPL v3 but I've said it anyway.

I'd be most interested if anyone modifies this to see the changes they make.

Lastly - enjoy.

_________________
Host Plugins | Blog | Hundred Quid A Day | My Big Fat Arse

Back to top

View user's profile Send private message Visit poster's website
Leng
Nucleus Guru
Nucleus Guru


Joined: 19 Sep 2004
Posts: 2830
Location: Australia

Post Posted: Tue Sep 16, 2008 12:48 pm   Post subject:
Reply with quote

Added to plugin wiki:

http://wakka.xiffy.nl/friendlycomment

_________________

deborahlau.com | To-Do List
Questions? See the FAQ, read the docs, or browse our plugins!!

Back to top

View user's profile Send private message Send e-mail Visit poster's website AIM Address ICQ Number
WillyP
Nucleus Guru
Nucleus Guru


Joined: 30 Aug 2009
Posts: 770
Location: Pembroke, NH

Post Posted: Sun Aug 21, 2011 9:21 pm   Post subject:
Reply with quote

I would like to disable this for admins, so an admin can just click on a commentator's name to send them an e-mail.

Also, I don't see the reason for redirecting users who click on a commentator's name to the top of the page. If the commenter did not enter a website and is not a member, and the person clicking on the name is not an admin, it should not be a link.

_________________
My Skins | Suncook Carpentry

Back to top

View user's profile Send private message Visit poster's website
matt_t_hat
Nucleus Geek


Joined: 21 Aug 2005
Posts: 1124
Location: UK

Post Posted: Tue Aug 23, 2011 5:15 pm   Post subject:
Reply with quote

WillyP wrote:
I would like to disable this for admins, so an admin can just click on a commentator's name to send them an e-mail.

Also, I don't see the reason for redirecting users who click on a commentator's name to the top of the page. If the commenter did not enter a website and is not a member, and the person clicking on the name is not an admin, it should not be a link.
That should be fairly simple to do with an if statement. I use other plugins that give admins an overview of all available data about the user so I've never needed to extend this any further.
_________________
Host Plugins | Blog | Hundred Quid A Day | My Big Fat Arse

Back to top

View user's profile Send private message Visit poster's website
gRegor
Nucleus PhD


Joined: 14 May 2002
Posts: 715
Location: Indianapolis, IN USA

Post Posted: Sun Oct 16, 2011 8:13 pm   Post subject:
Reply with quote

See also SmarterUserLink, which I haven't updated in quite some time, but does basically the same thing. I don't use GenerateURL, so that might be a weakness.
_________________
gRegor
"Live free or die; death is not the worst of evils." .. John Stark

Back to top

View user's profile Send private message Visit poster's website AIM Address ICQ Number
matt_t_hat
Nucleus Geek


Joined: 21 Aug 2005
Posts: 1124
Location: UK

Post Posted: Thu Nov 03, 2011 7:02 pm   Post subject:
Reply with quote

gRegor wrote:
See also SmarterUserLink, which I haven't updated in quite some time, but does basically the same thing. I don't use GenerateURL, so that might be a weakness.
Great minds think alike clearly although I think SmartUserLink creates an alternative skinvar/tempaltevar where as FriendlyComment just purges the email address clean out and replaces it with a link to the item in question.

I use a plugin called CommentBuddy which I probably have forgotten to release in a long time. Here's the version that I use - it allows me to do all sorts of things to comments as well as see (as the super admin) every little detail - I keep meaning to add a feature to show who many other comments, user names etc that IP/user/email has been a part of:

Code:
<?php

//ini_set('display_errors',1);
//error_reporting(E_ALL);

class NP_CommentBuddy extends NucleusPlugin {




   function getName() {return 'Comment Buddy';}
   function getAuthor() {return 'Lord Matt';}
   function getURL() {return 'http://lordmatt.co.uk/';}
   function getVersion() {return '0.3.0 Beta DisEmV+ban+Naughty';}
   
   function getDescription() {
      return 'A plugin for adding extra "on the page" actions for comments';
   }
             
   function doTemplateCommentsVar($a, $b='', $c=''){
      global $member, $CONF;
      $manager =& MANAGER::instance();
      /*
      $helptext = '         <p style="color:#666">
         Mangle this comment and make the commenter look as small as he or she actually is.<br />
         <strong>Disemvowelling options:</strong> <br />
         +msg: adds a message to the start of the comment including the users IP<br />
         -name: removes the users chosen name in favour of "TROLL"<br />
         +name: prefixes "TROLLISHLY" to the users name<br /> 
         </p>';
      */
      if ($c == "nohelp"){$helptext = '';}
      if ($member->isAdmin()){
         //ActionURL
         $url = $manager->addTicketToUrl("{$CONF['ActionURL']}?action=plugin&name=CommentBuddy");
         
         echo <<<EOF
         <div style="margin:5px;padding:5px;border:1px solid #333;background-color:whitesmoke;width:400px;" class="adminonly">
         <p><a href="#{$b['commentid']}" onclick="document.getElementById('adminstuff{$b['commentid']}').style.display = (document.getElementById('adminstuff{$b['commentid']}').style.display == 'none') ? '' : 'none';
">Admin options for comment {$b['commentid']}</a></p>


         <div id="adminstuff{$b['commentid']}" style="display: none;">
         <h4>Admin Control for Comment {$b['commentid']}</h4>
         <strong>Information</strong>
<pre>Link: {$b['userlinkraw']}
IP: {$b['ip']}
Host: {$b['host']}
email: {$b['email']}</pre>

<small>
<p><a onclick="window.open(this.href, \'popupeditwindow\', \'width=720,height=560,scrollbars,resizable\'); return false;"href="{$CONF['AdminURL']}?action=commentedit&amp;commentid={$comments['commentid']}">Edit This Comment</a></p>
         <p><strong>Quick Ban Options</strong>:</p>
         <p>
         <a href="{$url}&type=ban&r=troll&ip={$b['ip']}&b={$b['blog']}">BAN: Troll</a> |
         <a href="{$url}&type=ban&r=spam&ip={$b['ip']}&b={$b['blog']}">BAN: Spam</a> |
         <a href="{$url}&type=ban&r=offensive&ip={$b['ip']}&b={$b['blog']}">BAN: Offensive</a>
         </p>
         
         <p><strong>Unlink Options</strong> (<em>Exposing IP</em>)</p>
         <ul>
         <li><a href="{$url}&id={$b['commentid']}&type=unlink&naughty=y&newname=Naughty+User">Naughty User</a> ("Naughty User" name / no link)</li>
         <li><a href="{$url}&id={$b['commentid']}&type=unlink&naughty=y&newname=keep">Naughty Link</a> (no link)</li>
         <li><a href="{$url}&id={$b['commentid']}&type=unlink&naughty=y&newname=Naughty+User">Naughty Name</a> ("Naughty User" name)</li>
         </ul>         
         <p><strong>Unlink Options</strong> (<em>Protecting IP</em>)</p>
         <ul>
         <li><a href="{$url}&id={$b['commentid']}&type=unlink&naughty=n&newname=Anonymous">Remove Name</a> ("Anonymous" name)</li>
         <li><a href="{$url}&id={$b['commentid']}&type=unlink&naughty=n&newname=keep">Remove Link</a> (no link)</li>
         </ul>
         
         
         <p><strong>DisEmVowle This Comment</strong>:</p>
         
         $helptext
         
         <ul>
         <li><a href="{$url}&type=demv&x=n&id={$b['commentid']}&p=n">DisEmVowle</a> (crush the comment)</li>
         <li><a href="{$url}&type=demv&x=n&id={$b['commentid']}&p=y">DisEmVowle +msg</a> (add message)</li>
         <li><a href="{$url}&type=demv&x=y&id={$b['commentid']}&p=y">DisEmVowle -name +msg</a> (no name + a message)</li>
         <li><a href="{$url}&type=demv&x=x&id={$b['commentid']}&p=n">DisEmVowle +name</a> (modify name)</li>
         <li><a href="{$url}&type=demv&x=x&id={$b['commentid']}&p=y">DisEmVowle +name +msg</a> (modify name + a message)</li>
         </ul>
         </small></div>
         
         </div>
EOF;
         
         
/*         
[user]
[userid]
[email]
[memberid]
[ctime] => 2009-12-03 19:48:30
[host]
[timestamp]
[userlinkraw]
*/
                     
                       
         
         //echo "<pre>" . print_r($b) . "</pre>" ;
      }
   }

   /**
   BAN::addBan($blogid, $ip, $reason);
    * <a href="action.php?action=plugin&name=CommentBuddy&type=demv&x=n&id=<COMMENTID>&p=n">DisEmV Basic</a>|
    * <a href="action.php?action=plugin&name=CommentBuddy&type=demv&x=n&id=<COMMENTID>&p=y">DisEmV +Msg</a>|
    * <a href="action.php?action=plugin&name=CommentBuddy&type=demv&x=y&id=<COMMENTID>&p=y">DisEmV -name</a>|
    * <a href="action.php?action=plugin&name=CommentBuddy&type=demv&x=y&id=<COMMENTID>&p=y">DisEmV Mod name</a>
    * x kill the name? y name becomes "TROLL"; x name prepends "TROLLISHLY: "; n no action
    * p prefix a message to the comment? y prefixes "Disemvoweled! (IPADDRESS)"
    * address link changes automatically to a page explaining what a disemvowelling is.
    */
   function doAction($actionType) {
      global $member;   
      
      $message = <<<EOF
         <p>Comment Buddy by <a href="http://lordmatt.co.uk">Lord Matt</a> has now "enhanced" the comment as requested. You should now go back and look at the changes. Hopefully now the few that spoil it might start to pay attention to your comment policy (you do have one right?). We can but hope.</p>
         
         <p>Please note: sometimes you may need to refresh the page to see the changes.</p>
EOF;

      if (($actionType == 'demv') AND ($member->isAdmin())){
   
         $content = COMMENT::getComment(getvar('id'));
         $prefix = "";
         
         //Options:
         if (getvar('p') == 'y'){$prefix = "<strong>Disemvoweled!</strong> (". $content['ip'] .")";}
         if (getvar('x') == 'y'){$content['user'] = "TROLL";}
         if (getvar('x') == 'x'){$content['user'] = "TROLLISHLY: " . $content['user'];}   
                  
         $content['body'] = $prefix . preg_replace("/[aeiouy]/i", '<!--disemvowel[$1]-->', $content['body']);
         $content['userid'] = 'http://lordmatt.co.uk/extra/disemvoweled';
         
         $updatesql = 'UPDATE '.sql_table('comment').' ' .
         ' SET cbody = "' . $this->precleantext($content['body']) . '", ' .
         ' cuser = "' . $content['user'] . '", ' .
         ' cmail = "' . $content['userid'] . '" ' .
         ' WHERE cnumber=' . intval(getvar('id'));
         sql_query($updatesql);
         
         $result = "<p>OK! The evil message has been taken care of.</p>";
            
      }elseif(($actionType == 'ban') AND ($member->isAdmin())){
      
         $reason = 'This IP address has been banned for leaving ' . getvar('r') . ' comments.';
         $blogid = getvar('b');
         $ip = getvar('ip');
         
         BAN::addBan($blogid, $ip, $reason);
         $result = "<p>OK! The bad IP has been taken care of.</p>";
         
      }elseif(($actionType == 'unlink') AND ($member->isAdmin())){
      
         $content = COMMENT::getComment(getvar('id'));
         $prefix = "";
         
         if (getvar('naughty') == 'y'){ $prefix = "<strong>[Naughty IP: ". $content['ip'] ."]</strong> "; }
         if (getvar('newname') != 'keep'){ $content['user'] = getvar('newname'); }
         $content['userid'] = '';
         
         $content['body'] = $prefix . $content['body'];
            //echo "1...";      
         $updatesql = 'UPDATE '.sql_table('comment').' ' ;
         
         
         //echo "1.1...";
         $updatesql .= ' SET cbody = "' .  $this->precleantext($content['body']) . '", ' ;
         
         
         //echo "1.2...";
         $updatesql .= ' cuser = "' . $content['user'] . '", ' .
         ' cmail = "' . $content['userid'] . '" ' .
         ' WHERE cnumber=' . intval(getvar('id'));
         //echo "2...";
         if(sql_query($updatesql)){
            echo "Happy?";
            $result = "<p>OK! The naughty message has been taken care of.</p>";
         }else{
            return "Not Happy: <p>$updatesql</p>";
         }
      }else{
         return 'invalid action - Comment Buddy does not know how to do that. If this error is in error please let <a href="http://lordmattandyou.com">Matt</a> know.';
      }
      return $result . $message;
   }

   
   function precleantext($text){
      $text = mysql_real_escape_string($text);
      return $text; //optional if you pass by refrence
   }
   
   function WhoLovesYa(){
   /*
   
   SELECT count( cnumber ) AS number, `cip` , `cmember` , `chost` , `cuser`
FROM `nucleus_comment`
GROUP BY `cip` , `cmember` , `chost` , `cuser`
   
   */
   }


}
?>

_________________
Host Plugins | Blog | Hundred Quid A Day | My Big Fat Arse

Back to top

View user's profile Send private message Visit poster's website
Post new topic Reply to topic
Display posts from previous:   

Page 1 of 1

All times are GMT + 1 Hour

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2002 phpBB Group