b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (CVS HEAD) [ class tree: evocore ] [ index: evocore ] [ all elements ]

Source for file _comment.class.php

Documentation is available at _comment.class.php

  1. <?php
  2. /**
  3.  * This file implements the Comment class.
  4.  *
  5.  * This file is part of the b2evolution/evocms project - {@link http://b2evolution.net/}.
  6.  * See also {@link http://sourceforge.net/projects/evocms/}.
  7.  *
  8.  * @copyright (c)2003-2010 by Francois PLANQUE - {@link http://fplanque.net/}.
  9.  *  Parts of this file are copyright (c)2004-2005 by Daniel HAHLER - {@link http://thequod.de/contact}.
  10.  *
  11.  * @license http://b2evolution.net/about/license.html GNU General Public License (GPL)
  12.  *
  13.  *  {@internal Open Source relicensing agreement:
  14.  *  Daniel HAHLER grants Francois PLANQUE the right to license
  15.  *  Daniel HAHLER's contributions to this file and the b2evolution project
  16.  *  under any OSI approved OSS license (http://www.opensource.org/licenses/).
  17.  *  }}}
  18.  *
  19.  * @package evocore
  20.  *
  21.  *  {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  22.  * @author blueyed: Daniel HAHLER.
  23.  * @author fplanque: Francois PLANQUE
  24.  *
  25.  * @version $Id: _comment.class.php,v 1.52 2010/03/04 18:21:26 fplanque Exp $
  26.  */
  27. if!defined('EVO_MAIN_INIT') ) die'Please, do not access this page directly.' );
  28.  
  29. load_class'_core/model/dataobjects/_dataobject.class.php''DataObject' );
  30.  
  31. /**
  32.  * Comment Class
  33.  *
  34.  * @package evocore
  35.  */
  36. class Comment extends DataObject
  37. {
  38.     /**
  39.      * The item (parent) of this Comment (lazy-filled).
  40.      * @see Comment::get_Item()
  41.      * @see Comment::set_Item()
  42.      * @access protected
  43.      * @var Item 
  44.      */
  45.     var $Item;
  46.     /**
  47.      * The ID of the comment's Item.
  48.      * @var integer 
  49.      */
  50.     var $item_ID;
  51.     /**
  52.      * The comment's user, this is NULL for (anonymous) visitors (lazy-filled).
  53.      * @see Comment::get_author_User()
  54.      * @see Comment::set_author_User()
  55.      * @access protected
  56.      * @var User 
  57.      */
  58.     var $author_User;
  59.     /**
  60.      * The ID of the author's user. NULL for anonymous visitors.
  61.      * @var integer 
  62.      */
  63.     var $author_user_ID;
  64.     /**
  65.      * Comment type: 'comment', 'linkback', 'trackback' or 'pingback'
  66.      * @var string 
  67.      */
  68.     var $type;
  69.     /**
  70.      * Comment visibility status: 'published', 'deprecated', 'redirected', 'protected', 'private' or 'draft'
  71.      * @var string 
  72.      */
  73.     var $status;
  74.     /**
  75.      * Name of the (anonymous) visitor (if any).
  76.      * @var string 
  77.      */
  78.     var $author;
  79.     /**
  80.      * Email address of the (anonymous) visitor (if any).
  81.      * @var string 
  82.      */
  83.     var $author_email;
  84.     /**
  85.      * URL/Homepage of the (anonymous) visitor (if any).
  86.      * @var string 
  87.      */
  88.     var $author_url;
  89.     /**
  90.      * IP address of the comment's author (while posting).
  91.      * @var string 
  92.      */
  93.     var $author_IP;
  94.     /**
  95.      * Date of the comment (MySQL DATETIME - use e.g. {@link mysql2timestamp()}); local time ({@link $localtimenow})
  96.      * @var string 
  97.      */
  98.     var $date;
  99.     /**
  100.      * @var string 
  101.      */
  102.     var $content;
  103.     /**
  104.      * Spam karma of the comment (0-100), 0 being "probably no spam at all"
  105.      * @var integer 
  106.      */
  107.     var $spam_karma;
  108.     /**
  109.      * Does an anonymous commentator allow to send messages through a message form?
  110.      * @var boolean 
  111.      */
  112.     var $allow_msgform;
  113.  
  114.     var $nofollow;
  115.     /**
  116.      * @var string 
  117.      */
  118.     var $secret;
  119.  
  120.     /**
  121.      * Constructor
  122.      */
  123.     function Comment$db_row NULL )
  124.     {
  125.         // Call parent constructor:
  126.         parent::DataObject'T_comments''comment_''comment_ID' );
  127.  
  128.         if$db_row == NULL )
  129.         {
  130.             // echo 'null comment';
  131.             $this->rating NULL;
  132.             $this->featured 0;
  133.             $this->nofollow = 1;
  134.         }
  135.         else
  136.         {
  137.             $this->ID = $db_row['comment_ID'];
  138.             $this->item_ID = $db_row['comment_post_ID'];
  139.             ifempty($db_row['comment_author_ID']) )
  140.             {
  141.                 $this->author_user_ID = $db_row['comment_author_ID'];
  142.             }
  143.             $this->type = $db_row['comment_type'];
  144.             $this->status = $db_row['comment_status'];
  145.             $this->author = $db_row['comment_author'];
  146.             $this->author_email = $db_row['comment_author_email'];
  147.             $url trim$db_row['comment_author_url');
  148.             ifempty($url&& preg_match'~^\w+://~'$url ) )
  149.             // URL given and does not start with a protocol:
  150.                 $url 'http://'.$url;
  151.             }
  152.             $this->author_url = $url;
  153.             $this->author_IP = $db_row['comment_author_IP'];
  154.             $this->date = $db_row['comment_date'];
  155.             $this->content = $db_row['comment_content'];
  156.             $this->rating $db_row['comment_rating'];
  157.             $this->featured $db_row['comment_featured'];
  158.             $this->nofollow = $db_row['comment_nofollow'];
  159.             $this->spam_karma = $db_row['comment_spam_karma'];
  160.             $this->allow_msgform = $db_row['comment_allow_msgform'];
  161.             $this->secret = $db_row['comment_secret'];
  162.         }
  163.     }
  164.  
  165.  
  166.     /**
  167.      * Get the author User of the comment. This is NULL for anonymous visitors.
  168.      *
  169.      * @return User 
  170.      */
  171.     function get_author_User()
  172.     {
  173.         ifisset($this->author_user_ID&& isset($this->author_User) )
  174.         {
  175.             $UserCache get_UserCache();
  176.             $this->author_User = $UserCache->get_by_ID$this->author_user_ID );
  177.         }
  178.  
  179.         return $this->author_User;
  180.     }
  181.  
  182.  
  183.     /**
  184.      * Get the Item this comment relates to
  185.      *
  186.      * @return Item 
  187.      */
  188.     function get_Item()
  189.     {
  190.         ifisset($this->Item) )
  191.         {
  192.             $ItemCache get_ItemCache();
  193.             $this->Item = $ItemCache->get_by_ID$this->item_ID );
  194.         }
  195.  
  196.         return $this->Item;
  197.     }
  198.  
  199.  
  200.     /**
  201.      * Get a member param by its name
  202.      *
  203.      * @param mixed Name of parameter
  204.      * @return mixed Value of parameter
  205.      */
  206.     function get$parname )
  207.     {
  208.         global $post_statuses;
  209.  
  210.         switch$parname )
  211.         {
  212.             case 't_status':
  213.                 // Text status:
  214.                 return T_$post_statuses[$this->status);
  215.         }
  216.  
  217.         return parent::get$parname );
  218.     }
  219.  
  220.  
  221.     /**
  222.      * Set param value
  223.      *
  224.      * @param string parameter name
  225.      * @param mixed parameter value
  226.      * @param boolean true to set to NULL if empty value
  227.      * @return boolean true, if a value has been set; false if it has not changed
  228.      */
  229.     function set$parname$parvalue$make_null false )
  230.     {
  231.         switch$parname )
  232.         {
  233.             case 'rating':
  234.                 return $this->set_param$parname'string'$parvaluetrue );
  235.  
  236.             default:
  237.                 return $this->set_param$parname'string'$parvalue$make_null );
  238.         }
  239.     }
  240.  
  241.  
  242.     /**
  243.      * Set Item this comment relates to
  244.      * @param Item 
  245.      */
  246.     function set_Item$Item )
  247.     {
  248.         $this->Item = $Item;
  249.         $this->item_ID = $Item->ID;
  250.         parent::set_param'post_ID''number'$Item->ID );
  251.     }
  252.  
  253.  
  254.     /**
  255.      * Set author User of this comment
  256.      */
  257.     function set_author_User$author_User )
  258.     {
  259.         $this->author_User = $author_User;
  260.         parent::set_param'author_ID''number'$author_User->ID );
  261.     }
  262.  
  263.  
  264.     /**
  265.      * Set the spam karma, as a number.
  266.      * @param integer Spam karma (-100 - 100)
  267.      * @access protected
  268.      */
  269.     function set_spam_karma$spam_karma )
  270.     {
  271.         return $this->set_param'spam_karma''number'$spam_karma );
  272.     }
  273.  
  274.  
  275.     /**
  276.      * Get the anchor-ID of the comment
  277.      *
  278.      * @return string 
  279.      */
  280.     function get_anchor()
  281.     {
  282.         return 'c'.$this->ID;
  283.     }
  284.  
  285.  
  286.     /**
  287.      * Template function: display anchor for permalinks to refer to
  288.      */
  289.     function anchor()
  290.     {
  291.         echo '<a id="'.$this->get_anchor().'"></a>';
  292.     }
  293.  
  294.  
  295.     /**
  296.      * Get the comment author's name.
  297.      *
  298.      * @return string 
  299.      */
  300.     function get_author_name()
  301.     {
  302.         if$this->get_author_User() )
  303.         {
  304.             return $this->author_User->get_preferred_name();
  305.         }
  306.         else
  307.         {
  308.             return $this->author;
  309.         }
  310.     }
  311.  
  312.  
  313.     /**
  314.      * Get the EMail of the comment's author.
  315.      *
  316.      * @return string 
  317.      */
  318.     function get_author_email()
  319.     {
  320.         if$this->get_author_User() )
  321.         // Author is a user
  322.             return $this->author_User->get('email');
  323.         }
  324.         else
  325.         {
  326.             return $this->author_email;
  327.         }
  328.     }
  329.  
  330.  
  331.     /**
  332.      * Get the URL of the comment's author.
  333.      *
  334.      * @return string 
  335.      */
  336.     function get_author_url()
  337.     {
  338.         if$this->get_author_User() )
  339.         // Author is a user
  340.             return $this->author_User->get('url');
  341.         }
  342.         else
  343.         {
  344.             return $this->author_url;
  345.         }
  346.     }
  347.  
  348.  
  349.     /**
  350.      * Template function: display the avatar of the comment's author.
  351.      *
  352.      */
  353.     function avatar$size 'crop-64x64'$class 'bCommentAvatar'$params array() )
  354.     {
  355.         if$r $this->get_avatar$size$class$params ) )
  356.         {
  357.             echo $r;
  358.         }
  359.     }
  360.  
  361.  
  362.     /**
  363.      * Get the avatar of the comment's author.
  364.      *
  365.      * @return string 
  366.      */
  367.     function get_avatar$size 'crop-64x64'$class 'bCommentAvatar'$params array() )
  368.     {
  369.         global $Plugins$default_avatar;
  370.  
  371.         if$comment_author_User $this->get_author_User() )
  372.         {    // Author is a user
  373.             if$r $comment_author_User->get_avatar_imgtag$size$class ) )
  374.             {    // Got an image
  375.                 return $r;
  376.             }
  377.         }
  378.  
  379.         // TODO> add new event
  380.         // See if plugin supplies an image
  381.         // $img_url = $Plugins->trigger_event( 'GetCommentAvatar', array( 'Comment' => & $this, 'size' => $size ) );
  382.  
  383.         ifempty($img_url) )
  384.         {    // Use gravatar
  385.             $params array_mergearray(
  386.                     'default'    => $default_avatar,
  387.                     'size'        => '64',
  388.                 )$params );
  389.  
  390.             $img_url 'http://www.gravatar.com/avatar.php?gravatar_id='.md5$this->get_author_email() );
  391.  
  392.             if!empty($params['rating']) )
  393.                 $img_url .= '&amp;rating='.$params['rating'];
  394.  
  395.             if!empty($params['size']) )
  396.                 $img_url .='&amp;size='.$params['size'];
  397.  
  398.             if!empty($params['default']) )
  399.                 $img_url .= '&amp;default='.urlencode($params['default']);
  400.         }
  401.         $img_params array(
  402.             'src' => $img_url,
  403.             'alt' => $this->get_author_name(),
  404.             'title' => $this->get_author_name(),
  405.             'width' => $params['size']//  dh> NOTE: works with gravatar, check if extending
  406.             'height' => $params['size']// dh> NOTE: works with gravatar, check if extending
  407.         );
  408.         if$class )
  409.         // add class
  410.             $img_params['class'$class;
  411.         }
  412.         $imgtag '<img'.get_field_attribs_as_string($img_params).' />';
  413.  
  414.         return $imgtag;
  415.     }
  416.  
  417.  
  418.  
  419.     /**
  420.      * Template function: display author of comment
  421.      *
  422.      * @param string String to display before author name if not a user
  423.      * @param string String to display after author name if not a user
  424.      * @param string String to display before author name if he's a user
  425.      * @param string String to display after author name if he's a user
  426.      * @param string Output format, see {@link format_to_output()}
  427.      * @param boolean true for link, false if you want NO html link
  428.      */
  429.     function author$before ''$after '#'$before_user ''$after_user '#',
  430.                                         $format 'htmlbody'$makelink false )
  431.     {
  432.         echo $this->get_author($before$after$before_user$after_user$format$makelink);
  433.     }
  434.  
  435.  
  436.     /**
  437.      * Get author of comment
  438.      *
  439.      * @param string String to display before author name if not a user
  440.      * @param string String to display after author name if not a user
  441.      * @param string String to display before author name if he's a user
  442.      * @param string String to display after author name if he's a user
  443.      * @param string Output format, see {@link format_to_output()}
  444.      * @param boolean true for link, false if you want NO html link
  445.      * @return string 
  446.      */
  447.     function get_author$before ''$after '#'$before_user ''$after_user '#',
  448.                                         $format 'htmlbody'$makelink false )
  449.     {
  450.         global $Plugins;
  451.  
  452.         if$this->get_author_User() )
  453.         // Author is a user
  454.             ifstrlen$this->author_User->url <= 10 )
  455.             {
  456.                 $makelink false;
  457.             }
  458.             if$after_user == '#' $after_user ' ['.T_('Member').']';
  459.  
  460.             $author_name format_to_output$this->author_User->get_preferred_name()$format );
  461.  
  462.             $before $before_user;
  463.             $after $after_user;
  464.  
  465.         }
  466.         else
  467.         // Display info recorded at edit time:
  468.             ifstrlen$this->author_url <= 10 )
  469.             {
  470.                 $makelink false;
  471.             }
  472.             if$after == '#' $after ' ['.T_('Visitor').']';
  473.  
  474.             $author_name $this->dget'author'$format );
  475.  
  476.         }
  477.  
  478.         if$makelink )
  479.         {    // Make a link:
  480.             $r $this->get_author_url_link$author_name$before$aftertrue );
  481.         }
  482.         else
  483.         {    // Display the name: (NOTE: get_author_url_link( with nolink option ) would NOT handle this correctly when url is empty
  484.             $r $before.$author_name.$after;
  485.         }
  486.  
  487.         $Plugins->trigger_event'FilterCommentAuthor'array'data' => $r'makelink' => $makelink'Comment' => $this ) );
  488.  
  489.         return $r;
  490.     }
  491.  
  492.  
  493.     /**
  494.      * Template function: display comment's author's IP
  495.      *
  496.      * @param string String to display before IP, if IP exists
  497.      * @param string String to display after IP, if IP exists
  498.      */
  499.     function author_ip$before=''$after='' )
  500.     {
  501.         if!empty$this->author_IP ) )
  502.         {
  503.             global $Plugins;
  504.  
  505.             echo $before;
  506.             // Filter the IP by plugins for display, allowing e.g. the DNSBL plugin to add a link that displays info about the IP:
  507.             echo $Plugins->get_trigger_event'FilterIpAddress'array(
  508.                     'format'=>'htmlbody',
  509.                     'data' => $this->author_IP ),
  510.                 'data' );
  511.             echo $after;
  512.         }
  513.     }
  514.  
  515.  
  516.     /**
  517.      * Template function: display link to comment author's provided email
  518.      *
  519.      * @param string String to display for link: leave empty to display email
  520.      * @param string String to display before email, if email exists
  521.      * @param string String to display after email, if email exists
  522.      * @param boolean false if you want NO html link
  523.      */
  524.     function author_email$linktext=''$before=''$after=''$makelink true )
  525.     {
  526.         $email $this->get_author_email();
  527.  
  528.         ifstrlen$email )
  529.         // If email exists:
  530.             echo $before;
  531.             if$makelink echo '<a href="mailto:'.$email.'">';
  532.             echo ($linktext != ''$linktext $email;
  533.             if$makelink echo '</a>';
  534.             echo $after;
  535.         }
  536.     }
  537.  
  538.  
  539.     /**
  540.      * Get link to comment author's provided URL
  541.      *
  542.      * @param string String to display for link: leave empty to display URL
  543.      * @param string String to display before link, if link exists
  544.      * @param string String to display after link, if link exists
  545.      * @param boolean false if you want NO html link
  546.      * @return boolean true if URL has been displayed
  547.      */
  548.     function get_author_url_link$linktext=''$before=''$after=''$makelink true )
  549.     {
  550.         global $Plugins;
  551.  
  552.         $url $this->get_author_url();
  553.  
  554.         ifstrlen$url 10 )
  555.         {
  556.             return false;
  557.         }
  558.  
  559.         // If URL exists:
  560.         $r $before;
  561.         if$makelink )
  562.         {
  563.             $r .= '<a ';
  564.             if$this->nofollow )
  565.             {
  566.                 $r .= 'rel="nofollow" ';
  567.             }
  568.             $r .= 'href="'.$url.'">';
  569.         }
  570.         $r .= empty($linktext$url $linktext );
  571.         if$makelink $r .= '</a>';
  572.         $r .= $after;
  573.  
  574.         $Plugins->trigger_event'FilterCommentAuthorUrl'array'data' => $r'makelink' => $makelink'Comment' => $this ) );
  575.  
  576.         return $r;
  577.     }
  578.  
  579.  
  580.   /**
  581.      * Template function: display link to comment author's provided URL
  582.      *
  583.      * @param string String to display for link: leave empty to display URL
  584.      * @param string String to display before link, if link exists
  585.      * @param string String to display after link, if link exists
  586.      * @param boolean false if you want NO html link
  587.      * @return boolean true if URL has been displayed
  588.      */
  589.     function author_url$linktext=''$before=''$after=''$makelink true )
  590.     {
  591.         $r $this->get_author_url_link$linktext$before$after$makelink );
  592.         if!empty$r ) )
  593.         {
  594.             echo $r;
  595.             return true;
  596.         }
  597.         return false;
  598.     }
  599.  
  600.  
  601.     /**
  602.      * Template function: display spam karma of the comment (in percent)
  603.      *
  604.      * "%s" gets replaced by the karma value
  605.      *
  606.      * @param string Template string to display, if we have a karma value
  607.      * @param string Template string to display, if we have no karma value (pre-Phoenix)
  608.      */
  609.     function spam_karma$template '%s%'$template_unknown NULL )
  610.     {
  611.         ifisset($this->spam_karma) )
  612.         {
  613.             echo str_replace'%s'$this->spam_karma$template );
  614.         }
  615.         else
  616.         {
  617.             ifisset($template_unknown) )
  618.             {
  619.                 echo /* TRANS: "not available" */ T_('N/A');
  620.             }
  621.             else
  622.             {
  623.                 echo $template_unknown;
  624.             }
  625.         }
  626.     }
  627.  
  628.  
  629.     /**
  630.      * Provide link to edit a comment if user has edit rights
  631.      *
  632.      * @param string to display before link
  633.      * @param string to display after link
  634.      * @param string link text
  635.      * @param string link title
  636.      * @param string class name
  637.      * @return boolean 
  638.      */
  639.     function edit_link$before ' '$after ' '$text '#'$title '#'$class ''$glue '&amp;'$save_context true )
  640.     {
  641.         global $current_User$admin_url;
  642.  
  643.         ifis_logged_in() ) return false;
  644.  
  645.         ifempty($this->ID) )
  646.         {    // Happens in Preview
  647.             return false;
  648.         }
  649.  
  650.         $this->get_Item();
  651.  
  652.         if$current_User->check_perm'blog_comments'''false$this->Item->get_blog_ID() ) )
  653.         // If User has no permission to edit comments:
  654.             return false;
  655.         }
  656.  
  657.         if$text == '#' $text get_icon'edit' ).' '.T_('Edit...');
  658.         if$title == '#' $title T_('Edit this comment');
  659.  
  660.         echo $before;
  661.         echo '<a href="'.$admin_url.'?ctrl=comments&amp;action=edit&amp;comment_ID='.$this->ID;
  662.        if$save_context )
  663.         {
  664.             echo $glue.'redirect_to='.rawurlencoderegenerate_url'''''''&' ) );
  665.         }
  666.         echo '" title="'.$title.'"';
  667.         if!empty$class ) ) echo ' class="'.$class.'"';
  668.         echo '>'.$text.'</a>';
  669.         echo $after;
  670.  
  671.         return true;
  672.     }
  673.  
  674.  
  675.     /**
  676.      * Display delete icon for deleting author_url if user has proper rights
  677.      * @param boolean true if create ajax button
  678.      * @param glue between url params
  679.      */
  680.     function deleteurl_link$ajax_button true$glue '&amp;' )
  681.     {
  682.         global $current_User$admin_url;
  683.  
  684.         ifis_logged_in() ) return false;
  685.  
  686.         $this->get_Item();
  687.         if$current_User->check_perm'blog_comments'''false$this->Item->get_blog_ID() ) )
  688.         // If User has no permission to edit comments:
  689.             return false;
  690.         }
  691.  
  692.         if$ajax_button )
  693.         {
  694.             echo ' <a href="javascript:delete_comment_url('.$this->ID.');"'.get_icon'delete' ).'</a>';
  695.         }
  696.         else
  697.         {
  698.             $url $admin_url.'?ctrl=comments&amp;action=delete_url&amp;comment_ID='.$this->ID.'&amp;'.url_crumb('comment';
  699.             echo ' <a href="'.$url.$glue.'redirect_to='.rawurlencoderegenerate_url'''''''&' ) ).'"'.get_icon'delete' ).'</a>';
  700.         }
  701.     }
  702.  
  703.  
  704.     /**
  705.      * Displays button for deleeing the Comment if user has proper rights
  706.      *
  707.      * @param string to display before link
  708.      * @param string to display after link
  709.      * @param string link text
  710.      * @param string link title
  711.      * @param string class name
  712.      * @param boolean true to make this a button instead of a link
  713.      * @param string glue between url params
  714.      * @param boolean save context?
  715.      * @param boolean true if create AJAX button
  716.      */
  717.     function delete_link$before ' '$after ' '$text '#'$title '#'$class ''$button false$glue '&amp;'$save_context true$ajax_button false )
  718.     {
  719.         global $current_User$admin_url;
  720.  
  721.         ifis_logged_in() ) return false;
  722.  
  723.         ifempty($this->ID) )
  724.         {    // Happens in Preview
  725.             return false;
  726.         }
  727.  
  728.         $this->get_Item();
  729.  
  730.         if$current_User->check_perm'blog_comments'''false$this->Item->get_blog_ID() ) )
  731.         // If User has no permission to edit comments:
  732.             return false;
  733.         }
  734.  
  735.         if$text == '#' )
  736.         // Use icon+text as default, if not displayed as button (otherwise just the text)
  737.             if$button )
  738.             {
  739.                 $text get_icon'delete''imgtag' ).' '.T_('Delete!');
  740.             }
  741.             else
  742.             {
  743.                 $text T_('Delete!');
  744.             }
  745.         }
  746.         if$title == '#' $title T_('Delete this comment');
  747.  
  748.         $url $admin_url.'?ctrl=comments&amp;action=delete&amp;comment_ID='.$this->ID.'&amp;'.url_crumb('comment';
  749.            if$save_context )
  750.         {
  751.             $url .= $glue.'redirect_to='.rawurlencoderegenerate_url'''''''&' ) );
  752.         }
  753.  
  754.         echo $before;
  755.         if$ajax_button )
  756.         {
  757.             echo '<a href="javascript:deleteComment('.$this->ID.');" title="'.$title.'" onclick="return confirm(\'';
  758.             echo TS_('You are about to delete this comment!\\nThis cannot be undone!');
  759.             echo '\')"';
  760.             if!empty$class ) ) echo ' class="'.$class.'"';
  761.             echo '>'.$text.'</a>';
  762.         }
  763.         else
  764.         {
  765.             if$button )
  766.             // Display as button
  767.                 echo '<input type="button"';
  768.                 echo ' value="'.$text.'" title="'.$title.'" onclick="if ( confirm(\'';
  769.                 echo TS_('You are about to delete this comment!\\nThis cannot be undone!');
  770.                 echo '\') ) { document.location.href=\''.$url.'\' }"';
  771.                 if!empty$class ) ) echo ' class="'.$class.'"';
  772.                 echo '/>';
  773.             }
  774.             else
  775.             // Display as link
  776.                 echo '<a href="'.$url.'" title="'.$title.'" onclick="return confirm(\'';
  777.                 echo TS_('You are about to delete this comment!\\nThis cannot be undone!');
  778.                 echo '\')"';
  779.                 if!empty$class ) ) echo ' class="'.$class.'"';
  780.                 echo '>'.$text.'</a>';
  781.             }
  782.         }
  783.         echo $after;
  784.  
  785.         return true;
  786.     }
  787.  
  788.  
  789.     /**
  790.      * Provide link to deprecate a comment if user has edit rights
  791.      *
  792.      * @param string to display before link
  793.      * @param string to display after link
  794.      * @param string link text
  795.      * @param string link title
  796.      * @param string class name
  797.      * @param string glue between url params
  798.      * @param boolean save context?
  799.      * @param boolean true if create AJAX button
  800.      */
  801.     function get_deprecate_link$before ' '$after ' '$text '#'$title '#'$class ''$glue '&amp;'$save_context true$ajax_button false )
  802.     {
  803.         global $current_User$admin_url;
  804.  
  805.         ifis_logged_in() ) return false;
  806.  
  807.         $this->get_Item();
  808.  
  809.         if( ($this->status == 'deprecated'// Already deprecateded!
  810.             || $current_User->check_perm'blog_comments'''false$this->Item->get_blog_ID() ) )
  811.         // If User has no permission to edit comments:
  812.             return false;
  813.         }
  814.  
  815.         if$text == '#' $text get_icon'deprecate''imgtag' ).' '.T_('Deprecate!');
  816.         if$title == '#' $title T_('Deprecate this comment!');
  817.  
  818.         $r $before;
  819.         $r .= '<a href="';
  820.  
  821.         if$ajax_button )
  822.         {
  823.             $r .= 'javascript:setCommentStatus('.$this->ID.', \'deprecated\');';
  824.         }
  825.         else
  826.         {
  827.             $r .= $admin_url.'?ctrl=comments'.$glue.'action=deprecate'.$glue.'comment_ID='.$this->ID.'&amp;'.url_crumb('comment');
  828.                if$save_context )
  829.             {
  830.                 $r .= $glue.'redirect_to='.rawurlencoderegenerate_url'''''''&' ) );
  831.             }
  832.         }
  833.  
  834.         $r .= '" title="'.$title.'"';
  835.         if!empty$class ) ) $r .= ' class="'.$class.'"';
  836.         $r .= '>'.$text.'</a>';
  837.         $r .= $after;
  838.  
  839.         return $r;
  840.     }
  841.  
  842.  
  843.     /**
  844.      * Display link to deprecate a comment if user has edit rights
  845.      *
  846.      * @param string to display before link
  847.      * @param string to display after link
  848.      * @param string link text
  849.      * @param string link title
  850.      * @param string class name
  851.      * @param string glue between url params
  852.      * @param boolean save context?
  853.      * @param boolean true if create AJAX button
  854.      */
  855.     function deprecate_link$before ' '$after ' '$text '#'$title '#'$class ''$glue '&amp;'$save_context true$ajax_button false )
  856.     {
  857.         echo $this->get_deprecate_link$before$after$text$title$class$glue$save_context$ajax_button );
  858.     }
  859.  
  860.  
  861.     /**
  862.      * Provide link to publish a comment if user has edit rights
  863.      *
  864.      * @param string to display before link
  865.      * @param string to display after link
  866.      * @param string link text
  867.      * @param string link title
  868.      * @param string class name
  869.      * @param string glue between url params
  870.      * @param boolean save context?
  871.      * @param boolean true if create AJAX button
  872.      */
  873.     function get_publish_link$before ' '$after ' '$text '#'$title '#'$class ''$glue '&amp;'$save_context true$ajax_button false )
  874.     {
  875.         global $current_User$admin_url;
  876.  
  877.         ifis_logged_in() ) return false;
  878.  
  879.         $this->get_Item();
  880.  
  881.         if( ($this->status == 'published'// Already published!
  882.             || $current_User->check_perm'blog_comments'''false$this->Item->get_blog_ID() ) )
  883.         // If User has no permission to edit comments:
  884.             return false;
  885.         }
  886.  
  887.         if$text == '#' $text get_icon'publish''imgtag' ).' '.T_('Publish!');
  888.         if$title == '#' $title T_('Publish this comment!');
  889.  
  890.         $r $before;
  891.         $r .= '<a href="';
  892.         if$ajax_button )
  893.         {
  894.             $r .= 'javascript:setCommentStatus('.$this->ID.', \'published\');';
  895.         }
  896.         else
  897.         {
  898.             $r .= $admin_url.'?ctrl=comments'.$glue.'action=publish'.$glue.'comment_ID='.$this->ID.'&amp;'.url_crumb('comment');
  899.                if$save_context )
  900.             {
  901.                 $r .= $glue.'redirect_to='.rawurlencoderegenerate_url'''''''&' ) );
  902.             }
  903.         }
  904.  
  905.         $r .= '" title="'.$title.'"';
  906.         if!empty$class ) ) $r .= ' class="'.$class.'"';
  907.         $r .= '>'.$text.'</a>';
  908.         $r .= $after;
  909.  
  910.         return $r;
  911.     }
  912.  
  913.  
  914.     /**
  915.      * Display link to publish a comment if user has edit rights
  916.      *
  917.      * @param string to display before link
  918.      * @param string to display after link
  919.      * @param string link text
  920.      * @param string link title
  921.      * @param string class name
  922.      * @param string glue between url params
  923.      * @param boolean save context?
  924.      * @param boolean true if create AJAX button
  925.      */
  926.     function publish_link$before ' '$after ' '$text '#'$title '#'$class ''$glue '&amp;'$save_context true$ajax_button false )
  927.     {
  928.         echo $this->get_publish_link$before$after$text$title$class$glue$save_context$ajax_button );
  929.     }
  930.  
  931.  
  932.     /**
  933.      * Provide link to message form for this comment's author
  934.      *
  935.      * @param string url of the message form
  936.      * @param string to display before link
  937.      * @param string to display after link
  938.      * @param string link text
  939.      * @param string link title
  940.      * @param string class name
  941.      */
  942.     function msgform_link$form_url$before ' '$after ' '$text '#'$title '#'$class '' )
  943.     {
  944.         if$this->get_author_User() )
  945.         // This comment is from a registered user:
  946.             ifempty($this->author_User->email) )
  947.             // We have no email for this Author :(
  948.                 return false;
  949.             }
  950.             elseifempty($this->author_User->allow_msgform) )
  951.             // User does not allow message form
  952.                 return false;
  953.             }
  954.             $form_url url_add_param$form_url'recipient_id='.$this->author_User->ID );
  955.         }
  956.         else
  957.         // This comment is from a visitor:
  958.             ifempty($this->author_email) )
  959.             // We have no email for this comment :(
  960.                 return false;
  961.             }
  962.             elseifempty($this->allow_msgform) )
  963.             // Anonymous commentator does not allow message form (for this comment)
  964.                 return false;
  965.             }
  966.         }
  967.  
  968.         $form_url url_add_param$form_url'comment_id='.$this->ID.'&amp;post_id='.$this->item_ID
  969.                 .'&amp;redirect_to='.rawurlencode(url_rel_to_same_host(regenerate_url('','','','&')$form_url)) );
  970.  
  971.         if$title == '#' $title T_('Send email to comment author');
  972.         if$text == '#' $text get_icon'email''imgtag'array'class' => 'middle''title' => $title ) );
  973.  
  974.         echo $before;
  975.         echo '<a href="'.$form_url.'" title="'.$title.'"';
  976.         if!empty$class ) ) echo ' class="'.$class.'"';
  977.         // TODO: have an SEO setting for nofollow here, default to nofollow
  978.         echo ' rel="nofollow"';
  979.         echo '>'.$text.'</a>';
  980.         echo $after;
  981.  
  982.         return true;
  983.     }
  984.  
  985.  
  986.     /**
  987.      * Generate permalink to this comment.
  988.      *
  989.      * Note: This actually only returns the URL, to get a real link, use Comment::get_permanent_link()
  990.      */
  991.     function get_permanent_url()
  992.     {
  993.         $this->get_Item();
  994.  
  995.         $post_permalink $this->Item->get_single_url'auto' );
  996.  
  997.         return $post_permalink.'#'.$this->get_anchor();
  998.     }
  999.  
  1000.  
  1001.     /**
  1002.      * Template function: display permalink to this comment
  1003.      *
  1004.      * Note: This actually only returns the URL, to get a real link, use Comment::permanent_link()
  1005.      *
  1006.      * @param string 'urltitle', 'pid', 'archive#id' or 'archive#title'
  1007.      * @param string url to use
  1008.      */
  1009.     function permanent_url$mode ''$blogurl='' )
  1010.     {
  1011.         echo $this->get_permanent_url$mode$blogurl );
  1012.     }
  1013.  
  1014.  
  1015.     /**
  1016.      * Returns a permalink link to the Comment
  1017.      *
  1018.      * Note: If you only want the permalink URL, use Comment::get_permanent_url()
  1019.      *
  1020.      * @param string link text or special value: '#', '#icon#', '#text#'
  1021.      * @param string link title
  1022.      * @param string class name
  1023.      */
  1024.     function get_permanent_link$text '#'$title '#'$class ''$nofollow false )
  1025.     {
  1026.         global $current_User$baseurl;
  1027.  
  1028.         switch$text )
  1029.         {
  1030.             case '#':
  1031.                 $text get_icon'permalink' ).T_('Permalink');
  1032.                 break;
  1033.  
  1034.             case '#icon#':
  1035.                 $text get_icon'permalink' );
  1036.                 break;
  1037.  
  1038.             case '#text#':
  1039.                 $text T_('Permalink');
  1040.                 break;
  1041.         }
  1042.  
  1043.         if$title == '#' $title T_('Permanent link to this comment');
  1044.  
  1045.         $url $this->get_permanent_url();
  1046.  
  1047.         // Display as link
  1048.         $r '<a href="'.$url.'" title="'.$title.'"';
  1049.         if!empty$class ) ) $r .= ' class="'.$class.'"';
  1050.         if!empty$nofollow ) ) $r .= ' rel="nofollow"';
  1051.         $r .= '>'.$text.'</a>';
  1052.  
  1053.         return $r;
  1054.     }
  1055.  
  1056.  
  1057.     /**
  1058.      * Displays a permalink link to the Comment
  1059.      *
  1060.      * Note: If you only want the permalink URL, use Comment::permanent_url()
  1061.      */
  1062.     function permanent_link$params array() )
  1063.     {
  1064.         // Make sure we are not missing any param:
  1065.         $params array_mergearray(
  1066.                 'before'      => ' ',
  1067.                 'after'       => ' ',
  1068.                 'text'        => '#',
  1069.                 'title'       => '#',
  1070.                 'class'       => '',
  1071.                 'nofollow'    => false,
  1072.             )$params );
  1073.  
  1074.         echo $params['before'];
  1075.         echo $this->get_permanent_link$params['text']$params['title']$params['class']$params['nofollow');
  1076.         echo $params['after'];
  1077.     }
  1078.  
  1079.  
  1080.     /**
  1081.      * Template function: get content of comment
  1082.      *
  1083.      * @param string Output format, see {@link format_to_output()}
  1084.      * @return string 
  1085.      */
  1086.     function get_content$format 'htmlbody' )
  1087.     {
  1088.         global $Plugins;
  1089.  
  1090.         $comment $this->content;
  1091.         // fp> obsolete: $comment = str_replace('<trackback />', '', $comment);
  1092.         $Plugins->trigger_event'FilterCommentContent'array'data' => $comment'Comment' => $this ) );
  1093.         $comment format_to_output$comment$format );
  1094.  
  1095.         return $comment;
  1096.     }
  1097.  
  1098.  
  1099.     /**
  1100.      * Template function: display content of comment
  1101.      *
  1102.      * @param string Output format, see {@link format_to_output()}
  1103.      */
  1104.     function content$format 'htmlbody' )
  1105.     {
  1106.         echo $this->get_content$format );
  1107.     }
  1108.  
  1109.  
  1110.     /**
  1111.      * Get title of comment, e.g. "Comment from: Foo Bar"
  1112.      *
  1113.      * @param array Params
  1114.      *    'author_format': Formatting of the author (%s gets replaced with
  1115.      *                     the author string)
  1116.      * @return string 
  1117.      */
  1118.     function get_title($params array())
  1119.     {
  1120.         ifempty($params['author_format']) )
  1121.         {
  1122.             $params['author_format''%s';
  1123.         }
  1124.         $author sprintf($params['author_format']$this->get_author());
  1125.  
  1126.         switch$this->get'type' ) )
  1127.         {
  1128.             case 'comment'// Display a comment:
  1129.                 $s T_('Comment from %s');
  1130.                 break;
  1131.  
  1132.             case 'trackback'// Display a trackback:
  1133.                 $s T_('Trackback from %s');
  1134.                 break;
  1135.  
  1136.             case 'pingback'// Display a pingback:
  1137.                 $s T_('Pingback from %s');
  1138.                 break;
  1139.         }
  1140.         return sprintf($s$author);
  1141.     }
  1142.  
  1143.  
  1144.     /**
  1145.      * Template function: display date (datetime) of comment
  1146.      *
  1147.      * @param string date/time format: leave empty to use locale default date format
  1148.      * @param boolean true if you want GMT
  1149.      */
  1150.     function date$format=''$useGM false )
  1151.     {
  1152.         ifempty($format) )
  1153.             echo mysql2datelocale_datefmt()$this->date$useGM);
  1154.         else
  1155.             echo mysql2date$format$this->date$useGM);
  1156.     }
  1157.  
  1158.  
  1159.     /**
  1160.      * Template function: display time (datetime) of comment
  1161.      *
  1162.      * @param string date/time format: leave empty to use locale default time format
  1163.      * @param boolean true if you want GMT
  1164.      */
  1165.     function time$format=''$useGM false )
  1166.     {
  1167.         ifempty($format) )
  1168.             echo mysql2datelocale_timefmt()$this->date$useGM );
  1169.         else
  1170.             echo mysql2date$format$this->date$useGM );
  1171.     }
  1172.  
  1173.  
  1174.     /**
  1175.      * Template tag:  display rating
  1176.      */
  1177.     function rating$params array() )
  1178.     {
  1179.         ifempty$this->rating ) )
  1180.         {
  1181.             return false;
  1182.         }
  1183.  
  1184.         // Make sure we are not missing any param:
  1185.         $params array_mergearray(
  1186.                 'before'      => '<div class="comment_rating">',
  1187.                 'after'       => '</div>',
  1188.                 'star_class'  => 'middle',
  1189.             )$params );
  1190.  
  1191.         echo $params['before'];
  1192.  
  1193.         star_rating$this->rating$params['star_class');
  1194.  
  1195.         echo $params['after'];
  1196.     }
  1197.  
  1198.   /**
  1199.      * Rating input
  1200.      */
  1201.     function rating_input$params array() )
  1202.     {
  1203.         $params array_mergearray(
  1204.                                     'before'    => '',
  1205.                                     'after'     => '',
  1206.                                     'label_low'  => T_('Poor'),
  1207.                                     'label_high' => T_('Excellent'),
  1208.                                 )$params );
  1209.  
  1210.         echo $params['before'];
  1211.  
  1212.         echo $params['label_low'];
  1213.  
  1214.         for$i=1$i<=5$i++ )
  1215.         {
  1216.             echo '<input type="radio" class="radio" name="comment_rating" value="'.$i.'"';
  1217.             if$this->rating == $i )
  1218.             {
  1219.                 echo ' checked="checked"';
  1220.             }
  1221.             echo ' />';
  1222.         }
  1223.  
  1224.         echo $params['label_high'];
  1225.  
  1226.         echo $params['after'];
  1227.     }
  1228.  
  1229.  
  1230.   /**
  1231.      * Rating reset input
  1232.      */
  1233.     function rating_none_input$params array() )
  1234.     {
  1235.         $params array_mergearray(
  1236.                                     'before'    => '',
  1237.                                     'after'     => '',
  1238.                                     'label'     => T_('No rating'),
  1239.                                 )$params );
  1240.  
  1241.         echo $params['before'];
  1242.  
  1243.         echo '<label><input type="radio" class="radio" name="comment_rating" value="0"';
  1244.         ifempty($this->rating) )
  1245.         {
  1246.             echo ' checked="checked"';
  1247.         }
  1248.         echo ' />';
  1249.  
  1250.         echo $params['label'].'</label>';
  1251.  
  1252.         echo $params['after'];
  1253.     }
  1254.  
  1255.  
  1256.     /**
  1257.      * Template function: display status of comment
  1258.      *
  1259.      * Statuses:
  1260.      * - published
  1261.      * - deprecated
  1262.      * - protected
  1263.      * - private
  1264.      * - draft
  1265.      *
  1266.      * @param string Output format, see {@link format_to_output()}
  1267.      */
  1268.     function status$format 'htmlbody' )
  1269.     {
  1270.         global $post_statuses;
  1271.  
  1272.         if$format == 'raw' )
  1273.         {
  1274.             $this->disp'status''raw' );
  1275.         }
  1276.         else
  1277.         {
  1278.             echo format_to_output$this->get('t_status')$format );
  1279.         }
  1280.     }
  1281.  
  1282.  
  1283.     /**
  1284.      * Send email notifications to subscribed users:
  1285.      *
  1286.      * @todo fp> SEPARATE MODERATION notifications from SUBSCRIPTION notifications
  1287.      * @todo shall we notify suscribers of blog were this is in extra-cat?
  1288.      * @todo cache message by locale like {@link Item::send_email_notifications()}
  1289.      * @todo dh> Indicator in url to see where the user came from (&from=subnote ["subscription notification"]) - Problem: too long urls.
  1290.      * @todo dh> "Beautify" like {@link Item::send_email_notifications()} ? fp > sure
  1291.      * @todo Should include "visibility status" in the mail to the Item's Author
  1292.      */
  1293.     function send_email_notifications()
  1294.     {
  1295.         global $DB$admin_url$debug$Debuglog$baseurl;
  1296.  
  1297.         $edited_Item $this->get_Item();
  1298.         $edited_Blog $edited_Item->get_Blog();
  1299.  
  1300.         $notify_array array();
  1301.  
  1302.         if$edited_Blog->get_setting'allow_subscriptions' ) )
  1303.         {    // Get list of users who want to be notfied:
  1304.             // TODO: also use extra cats/blogs??
  1305.             // So far you get notifications for everything. We'll need a setting to decide if you want to received unmoderated (aka unpublished) comments or not.
  1306.             // Note: users receive comments on their own posts. This is done on purpose. Otherwise they think it's broken when they test the app.
  1307.             $sql 'SELECT DISTINCT user_email, user_locale
  1308.                                 FROM T_subscriptions INNER JOIN T_users ON sub_user_ID = user_ID
  1309.                              WHERE sub_coll_ID = '.$this->Item->get_blog_ID().'
  1310.                                AND sub_comments <> 0
  1311.                                AND LENGTH(TRIM(user_email)) > 0';
  1312.             $notify_list $DB->get_results$sql );
  1313.  
  1314.             // Preprocess list:
  1315.             foreach$notify_list as $notification )
  1316.             {
  1317.                 $notify_array[$notification->user_email$notification->user_locale;
  1318.             }
  1319.         }
  1320.  
  1321.         // Check if we need to include the author:
  1322.         $item_author_User $edited_Item->get_creator_User();
  1323.         if$item_author_User->notify
  1324.                 && empty$item_author_User->email ) ) )
  1325.         // Author wants to be notified...
  1326.             if($this->get_author_User(// comment is from registered user
  1327.                             && $item_author_User->login == $this->author_User->login) ) // comment is from same user as post
  1328.                 {    // Author is not commenting on his own post...
  1329.                     $notify_array[$item_author_User->email$item_author_User->locale;
  1330.                 }
  1331.         }
  1332.  
  1333.         ifcount($notify_array) )
  1334.         // No-one to notify:
  1335.             return false;
  1336.         }
  1337.  
  1338.  
  1339.         /*
  1340.          * We have a list of email addresses to notify:
  1341.          */
  1342.         // TODO: dh> this reveals the comments author's email address to all subscribers!!
  1343.         //           $notify_from should get used by default, unless the user has opted in to be the sender!
  1344.         // fp>If the subscriber has permission to moderate the comments, he SHOULD receive the email address.
  1345.         if$this->get_author_User() )
  1346.         // Comment from a registered user:
  1347.             $mail_from $this->author_User->get('email');
  1348.             $mail_from_name $this->author_User->get('preferredname');
  1349.         }
  1350.         elseifempty$this->author_email ) )
  1351.         // non-member, but with email address:
  1352.             $mail_from $this->author_email;
  1353.             $mail_from_name $this->author;
  1354.         }
  1355.         else
  1356.         // Fallback (we have no email address):  fp>TODO: or the subscriber is not allowed to view it.
  1357.             global $notify_from;
  1358.             $mail_from $notify_from;
  1359.             $mail_from_name NULL;
  1360.         }
  1361.  
  1362.         // Send emails:
  1363.         foreach$notify_array as $notify_email => $notify_locale )
  1364.         {
  1365.             locale_temp_switch($notify_locale);
  1366.  
  1367.             switch$this->type )
  1368.             {
  1369.                 case 'trackback':
  1370.                     /* TRANS: Subject of the mail to send on new trackbacks. First %s is the blog's shortname, the second %s is the item's title. */
  1371.                     $subject T_('[%s] New trackback on "%s"');
  1372.                     break;
  1373.  
  1374.                 default:
  1375.                     /* TRANS: Subject of the mail to send on new comments. First %s is the blog's shortname, the second %s is the item's title. */
  1376.                     $subject T_('[%s] New comment on "%s"');
  1377.             }
  1378.  
  1379.             $subject sprintf$subject$edited_Blog->get('shortname')$edited_Item->get('title') );
  1380.  
  1381.             $notify_message T_('Blog').': '.$edited_Blog->get('shortname')."\n"
  1382.                 // Mail bloat: .' ( '.str_replace('&amp;', '&', $edited_Blog->gen_blogurl())." )\n"
  1383.                 .T_('Post').': '.$edited_Item->get('title')."\n";
  1384.                 // Mail bloat: .' ( '.str_replace('&amp;', '&', $edited_Item->get_permanent_url())." )\n";
  1385.                 // TODO: fp> We MAY want to force short URL and avoid it to wrap on a new line in the mail which may prevent people from clicking
  1386.  
  1387.             switch$this->type )
  1388.             {
  1389.                 case 'trackback':
  1390.                     $user_domain gethostbyaddr($this->author_IP);
  1391.                     $notify_message .= T_('Website')."$this->author (IP: $this->author_IP$user_domain)\n";
  1392.                     $notify_message .= T_('Url')."$this->author_url\n";
  1393.                     break;
  1394.  
  1395.                 default:
  1396.                     if$this->get_author_User() )
  1397.                     // Comment from a registered user:
  1398.                         $notify_message .= T_('Author').': '.$this->author_User->get('preferredname').' ('.$this->author_User->get('login').")\n";
  1399.                     }
  1400.                     else
  1401.                     // Comment from visitor:
  1402.                         $user_domain gethostbyaddr($this->author_IP);
  1403.                         $notify_message .= T_('Author')."$this->author (IP: $this->author_IP$user_domain)\n";
  1404.                         $notify_message .= T_('Email')."$this->author_email\n";
  1405.                         $notify_message .= T_('Url')."$this->author_url\n";
  1406.                     }
  1407.             }
  1408.  
  1409.             $notify_message =
  1410.                 T_('Comment').': '.str_replace('&amp;''&'$this->get_permanent_url())."\n"
  1411.                 // TODO: fp> We MAY want to force a short URL and avoid it to wrap on a new line in the mail which may prevent people from clicking
  1412.                 .$notify_message;
  1413.  
  1414.             if!empty$this->rating ) )
  1415.             {
  1416.                 $notify_message .= T_('Rating')."$this->rating\n";
  1417.             }
  1418.  
  1419.             $notify_message .= $this->get('content')
  1420.                 ."\n\n-- \n";
  1421.                 
  1422.             if$this->status == 'draft' )
  1423.             {
  1424.                 $secret_value '&secret='.$this->secret;
  1425.                 $notify_message .= T_('Quick moderation').': '.$baseurl.'htsrv/comment_review.php?cmt_ID='.$this->ID.$secret_value."\n\n";
  1426.             }
  1427.             
  1428.             $notify_message .= T_('Edit screen').': '.$admin_url.'?ctrl=items&blog='.$edited_Blog->ID.'&p='.$edited_Item->ID.'&c=1#c'.$this->ID."\n\n"
  1429.                                .T_('Edit your subscriptions/notifications').': '.str_replace('&amp;''&'url_add_param$edited_Blog->gen_blogurl()'disp=subs' ) )."\n";
  1430.  
  1431.             if$debug )
  1432.             {
  1433.                 $mail_dump "Sending notification to $notify_email:<pre>Subject: $subject\n$notify_message</pre>";
  1434.  
  1435.                 if$debug >= )
  1436.                 // output mail content - NOTE: this will kill sending of headers.
  1437.                     echo "<p>$mail_dump</p>";
  1438.                 }
  1439.  
  1440.                 $Debuglog->add$mail_dump'notification' );
  1441.             }
  1442.  
  1443.             send_mail$notify_emailNULL$subject$notify_message$mail_from$mail_from_name );
  1444.  
  1445.             locale_restore_previous();
  1446.         }
  1447.     }
  1448.  
  1449.  
  1450.     /**
  1451.      * Trigger event AfterCommentUpdate after calling parent method.
  1452.      *
  1453.      * @return boolean true on success
  1454.      */
  1455.     function dbupdate()
  1456.     {
  1457.         global $Plugins;
  1458.         
  1459.         if$this->status != 'draft' )
  1460.         {    // We don't want to keep "secret" moderation access once we've published or deprecated a comment
  1461.             $this->set'secret'null );
  1462.         }
  1463.  
  1464.         $dbchanges $this->dbchanges;
  1465.  
  1466.         if( ( $r parent::dbupdate() ) !== false )
  1467.         {
  1468.             $Plugins->trigger_event'AfterCommentUpdate'$params array'Comment' => $this'dbchanges' => $dbchanges ) );
  1469.         }
  1470.  
  1471.         return $r;
  1472.     }
  1473.  
  1474.  
  1475.     /**
  1476.      * Get karma and set it before adding the Comment to DB.
  1477.      *
  1478.      * @return boolean true on success, false if it did not get inserted
  1479.      */
  1480.     function dbinsert()
  1481.     {
  1482.         /**
  1483.          * @var Plugins
  1484.          */
  1485.         global $Plugins;
  1486.         global $Settings;
  1487.  
  1488.         // Get karma percentage (interval -100 - 100)
  1489.         $spam_karma $Plugins->trigger_karma_collect'GetSpamKarmaForComment'array'Comment' => $this ) );
  1490.  
  1491.         $this->set_spam_karma$spam_karma );
  1492.  
  1493.         // Change status accordingly:
  1494.         ifis_null($spam_karma) )
  1495.         {
  1496.             if$spam_karma $Settings->get('antispam_threshold_publish') )
  1497.             // Publish:
  1498.                 $this->set'status''published' );
  1499.             }
  1500.             elseif$spam_karma $Settings->get('antispam_threshold_delete') )
  1501.             // Delete/No insert:
  1502.                 return false;
  1503.             }
  1504.         }
  1505.  
  1506.         if$this->status == 'draft' )
  1507.         {    // We will allow "secret" moderation only to draft comments:
  1508.             $this->set'secret'generate_random_key() );
  1509.         }
  1510.  
  1511.         $dbchanges $this->dbchanges;
  1512.  
  1513.         if$r parent::dbinsert() )
  1514.         {
  1515.             $Plugins->trigger_event'AfterCommentInsert'$params array'Comment' => $this'dbchanges' => $dbchanges ) );
  1516.         }
  1517.  
  1518.         return $r;
  1519.     }
  1520.  
  1521.  
  1522.     /**
  1523.      * Trigger event AfterCommentDelete after calling parent method.
  1524.      *
  1525.      * @return boolean true on success
  1526.      */
  1527.     function dbdelete()
  1528.     {
  1529.         global $Plugins;
  1530.  
  1531.         // remember ID, because parent method resets it to 0
  1532.         $old_ID $this->ID;
  1533.  
  1534.         if$r parent::dbdelete() )
  1535.         {
  1536.             // re-set the ID for the Plugin event
  1537.             $this->ID = $old_ID;
  1538.  
  1539.             $Plugins->trigger_event'AfterCommentDelete'$params array'Comment' => $this ) );
  1540.  
  1541.             $this->ID = 0;
  1542.         }
  1543.  
  1544.         return $r;
  1545.     }
  1546.  
  1547. }
  1548.  
  1549.  
  1550. /*
  1551.  * $Log: _comment.class.php,v $
  1552.  * Revision 1.52  2010/03/04 18:21:26  fplanque
  1553.  * minor/doc
  1554.  *
  1555.  * Revision 1.51  2010/03/04 15:46:02  efy-asimo
  1556.  * remove javascript from comment_review + add comment_secret just for draft comments
  1557.  *
  1558.  * Revision 1.50  2010/03/03 19:49:08  fplanque
  1559.  * fix
  1560.  *
  1561.  * Revision 1.49  2010/03/03 16:29:15  fplanque
  1562.  * minor
  1563.  *
  1564.  * Revision 1.48  2010/03/03 16:25:13  fplanque
  1565.  * todo
  1566.  *
  1567.  * Revision 1.47  2010/03/01 08:34:25  efy-asimo
  1568.  *  delete url come back to the same screen
  1569.  *
  1570.  * Revision 1.46  2010/02/28 23:38:40  fplanque
  1571.  * minor changes
  1572.  *
  1573.  * Revision 1.45  2010/02/10 11:45:04  efy-asimo
  1574.  * Quick Edit option on comment notification
  1575.  *
  1576.  * Revision 1.44  2010/02/08 17:52:12  efy-yury
  1577.  * copyright 2009 -> 2010
  1578.  *
  1579.  * Revision 1.43  2010/01/31 17:39:52  efy-asimo
  1580.  * delete url from comments in dashboard and comments form
  1581.  *
  1582.  * Revision 1.42  2010/01/13 19:49:45  efy-yury
  1583.  * update comments: crumbs
  1584.  *
  1585.  * Revision 1.41  2009/11/24 22:09:24  efy-maxim
  1586.  * dashboard comments - ajax
  1587.  *
  1588.  * Revision 1.40  2009/09/30 00:38:14  sam2kb
  1589.  * Space is not needed before get_field_attribs_as_string()
  1590.  *
  1591.  * Revision 1.39  2009/09/28 02:26:36  sam2kb
  1592.  * 80x80px image looks weird, changed to 64x64
  1593.  *
  1594.  * Revision 1.38  2009/09/26 12:00:42  tblue246
  1595.  * Minor/coding style
  1596.  *
  1597.  * Revision 1.37  2009/09/25 07:32:52  efy-cantor
  1598.  * replace get_cache to get_*cache
  1599.  *
  1600.  * Revision 1.36  2009/09/24 01:20:16  blueyed
  1601.  * width and height for gravatar images
  1602.  *
  1603.  * Revision 1.35  2009/09/20 18:13:20  fplanque
  1604.  * doc
  1605.  *
  1606.  * Revision 1.34  2009/09/20 13:48:46  blueyed
  1607.  * Cleanup get_avatar some.
  1608.  *
  1609.  * Revision 1.33  2009/09/16 21:29:31  sam2kb
  1610.  * Display user/visitor avatar in comments
  1611.  *
  1612.  * Revision 1.32  2009/09/14 12:46:36  efy-arrin
  1613.  * Included the ClassName in load_class() call with proper UpperCase
  1614.  *
  1615.  * Revision 1.31  2009/08/30 17:27:03  fplanque
  1616.  * better NULL param handling all over the app
  1617.  *
  1618.  * Revision 1.30  2009/08/25 17:01:50  tblue246
  1619.  * Bugfix #2, not my day today...
  1620.  *
  1621.  * Revision 1.27  2009/03/08 23:57:42  fplanque
  1622.  * 2009
  1623.  *
  1624.  * Revision 1.26  2009/02/25 22:17:53  blueyed
  1625.  * ItemLight: lazily load blog_ID and main_Chapter.
  1626.  * There is more, but I do not want to skim the diff again, after
  1627.  * "cvs ci" failed due to broken pipe.
  1628.  *
  1629.  * Revision 1.25  2009/01/26 20:45:51  blueyed
  1630.  * Fix Comment::get_author_name for User (returned and echoed). Used nowhere and buggy since move to MVC (2007-06-25) at least. Thanks Walter for finding it :)
  1631.  *
  1632.  * Revision 1.24  2008/12/18 00:34:13  blueyed
  1633.  * - Add Comment::get_author() and make Comment::author() use it
  1634.  * - Add Comment::get_title() and use it in Dashboard and Admin comment list
  1635.  *
  1636.  * Revision 1.23  2008/07/01 08:32:12  fplanque
  1637.  * minor
  1638.  *
  1639.  * Revision 1.22  2008/04/13 22:07:59  fplanque
  1640.  * email fixes
  1641.  *
  1642.  * Revision 1.21  2008/04/13 15:15:59  fplanque
  1643.  * attempt to fix email headers for non latin charsets
  1644.  *
  1645.  * Revision 1.20  2008/03/31 00:27:49  fplanque
  1646.  * Enhanced comment moderation
  1647.  *
  1648.  * Revision 1.19  2008/03/30 23:04:23  fplanque
  1649.  * fix
  1650.  *
  1651.  * Revision 1.18  2008/03/16 22:39:07  fplanque
  1652.  * doc
  1653.  *
  1654.  * Revision 1.17  2008/03/16 13:57:01  fplanque
  1655.  * WTF?
  1656.  *
  1657.  * Revision 1.15  2008/02/10 00:58:56  fplanque
  1658.  * no message
  1659.  *
  1660.  * Revision 1.14  2008/01/21 09:35:27  fplanque
  1661.  * (c) 2008
  1662.  *
  1663.  * Revision 1.13  2008/01/11 19:18:29  fplanque
  1664.  * bugfixes
  1665.  *
  1666.  * Revision 1.12  2008/01/10 19:59:51  fplanque
  1667.  * reduced comment PITA
  1668.  *
  1669.  * Revision 1.11  2008/01/08 20:15:21  personman2
  1670.  * Post author no longer gets emails when he comments on his own post
  1671.  *
  1672.  * Revision 1.10  2007/12/28 13:45:33  fplanque
  1673.  * bugfix again
  1674.  *
  1675.  * Revision 1.9  2007/12/28 13:24:29  fplanque
  1676.  * bugfix
  1677.  *
  1678.  * Revision 1.8  2007/12/26 20:04:26  fplanque
  1679.  * fixed missing nofollow handling
  1680.  *
  1681.  * Revision 1.7  2007/12/23 20:10:49  fplanque
  1682.  * removed suspects
  1683.  *
  1684.  * Revision 1.6  2007/12/22 17:24:35  fplanque
  1685.  * cleanup
  1686.  *
  1687.  * Revision 1.5  2007/12/18 23:51:32  fplanque
  1688.  * nofollow handling in comment urls
  1689.  *
  1690.  * Revision 1.4  2007/11/03 04:56:03  fplanque
  1691.  * permalink / title links cleanup
  1692.  *
  1693.  * Revision 1.3  2007/11/02 01:50:54  fplanque
  1694.  * comment ratings
  1695.  *
  1696.  * Revision 1.2  2007/09/04 19:51:26  fplanque
  1697.  * in-context comment editing
  1698.  *
  1699.  * Revision 1.1  2007/06/25 10:59:40  fplanque
  1700.  * MODULES (refactored MVC)
  1701.  *
  1702.  * Revision 1.65  2007/05/28 15:18:30  fplanque
  1703.  * cleanup
  1704.  *
  1705.  * Revision 1.64  2007/05/20 20:54:49  fplanque
  1706.  * better comment moderation links
  1707.  *
  1708.  * Revision 1.63  2007/04/26 00:11:08  fplanque
  1709.  * (c) 2007
  1710.  *
  1711.  * Revision 1.62  2007/03/24 20:41:16  fplanque
  1712.  * Refactored a lot of the link junk.
  1713.  * Made options blog specific.
  1714.  * Some junk still needs to be cleaned out. Will do asap.
  1715.  *
  1716.  * Revision 1.61  2007/03/22 00:03:40  blueyed
  1717.  * Escape author_url and author_User->url in author_url() template function
  1718.  *
  1719.  * Revision 1.60  2007/03/11 23:57:06  fplanque
  1720.  * item editing: allow setting to 'redirected' status
  1721.  *
  1722.  * Revision 1.59  2007/02/28 23:37:52  blueyed
  1723.  * doc
  1724.  *
  1725.  * Revision 1.58  2007/02/25 01:34:19  fplanque
  1726.  * doc
  1727.  *
  1728.  * Revision 1.57  2007/02/21 23:59:00  blueyed
  1729.  * Trigger FilterIpAddress event in author_ip()
  1730.  *
  1731.  * Revision 1.56  2006/12/26 00:08:29  fplanque
  1732.  * wording
  1733.  *
  1734.  * Revision 1.55  2006/12/16 01:30:46  fplanque
  1735.  * Setting to allow/disable email subscriptions on a per blog basis
  1736.  *
  1737.  * Revision 1.54  2006/12/12 02:53:56  fplanque
  1738.  * Activated new item/comments controllers + new editing navigation
  1739.  * Some things are unfinished yet. Other things may need more testing.
  1740.  *
  1741.  * Revision 1.53  2006/12/07 23:13:10  fplanque
  1742.  * @var needs to have only one argument: the variable type
  1743.  * Otherwise, I can't code!
  1744.  *
  1745.  * Revision 1.52  2006/12/03 18:10:22  fplanque
  1746.  * Not releasable. Discussion by email.
  1747.  *
  1748.  * Revision 1.51  2006/11/26 02:30:39  fplanque
  1749.  * doc / todo
  1750.  *
  1751.  * Revision 1.50  2006/11/17 18:36:23  blueyed
  1752.  * dbchanges param for AfterItemUpdate, AfterItemInsert, AfterCommentUpdate and AfterCommentInsert
  1753.  *
  1754.  * Revision 1.49  2006/11/16 22:41:59  blueyed
  1755.  * Fixed email from address in notifications, but also added TODO
  1756.  *
  1757.  * Revision 1.48  2006/11/16 19:23:12  fplanque
  1758.  * minor
  1759.  *
  1760.  * Revision 1.47  2006/11/14 21:02:57  blueyed
  1761.  * TODO
  1762.  *
  1763.  * Revision 1.46  2006/11/06 00:05:36  blueyed
  1764.  * Encoding of "&" in Comment::author_url makes no sense, should get done on output.
  1765.  *
  1766.  * Revision 1.45  2006/11/05 22:12:35  blueyed
  1767.  * Fix
  1768.  *
  1769.  * Revision 1.44  2006/10/23 22:19:02  blueyed
  1770.  * Fixed/unified encoding of redirect_to param. Use just rawurlencode() and no funky &amp; replacements
  1771.  *
  1772.  * Revision 1.43  2006/10/18 00:03:50  blueyed
  1773.  * Some forgotten url_rel_to_same_host() additions
  1774.  */
  1775. ?>

Documentation generated on Sat, 06 Mar 2010 04:06:29 +0100 by phpDocumentor 1.4.2. This site is hosted and maintained by Daniel HAHLER (Contact).