b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (0.9.x) [ class tree: evocore ] [ index: evocore ] [ all elements ]

Source for file _class_comment.php

Documentation is available at _class_comment.php

  1. <?php
  2. /**
  3.  * This file implements comments
  4.  *
  5.  * b2evolution - {@link http://b2evolution.net/}
  6.  * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
  7.  * @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
  8.  *
  9.  * @package evocore
  10.  */
  11. if!defined('DB_USER') ) die'Please, do not access this page directly.' );
  12.  
  13. /**
  14.  * Includes:
  15.  */
  16. require_once dirname(__FILE__)'/_class_dataobject.php';
  17.  
  18. /**
  19.  * Comment Class
  20.  *
  21.  * @package evocore
  22.  */
  23. class Comment extends DataObject
  24. {
  25.     /**
  26.      * @access protected
  27.      */
  28.     var $Item = NULL;
  29.     var $author_User = NULL;
  30.     var    $type;
  31.     var    $status;
  32.     var    $author;
  33.     var    $author_email;
  34.     var    $author_url;
  35.     var    $author_ip;
  36.     var    $date;
  37.     var    $content;
  38.     var    $karma;
  39.  
  40.     /* 
  41.      * Comment::Comment(-)
  42.      *
  43.      * Constructor
  44.      */
  45.     function Comment$db_row NULL )
  46.     {
  47.         global $tablecomments$ItemCache;
  48.         
  49.         // Call parent constructor:
  50.         parent::DataObject$tablecomments'comment_''comment_ID' );
  51.     
  52.         if$db_row == NULL )
  53.         {
  54.             echo 'null comment';
  55.         }
  56.         else
  57.         {
  58.             $this->ID = $db_row['comment_ID'];
  59.  
  60.             // Get parent Item
  61.             $this->Item = $ItemCache->get_by_ID(  $db_row['comment_post_ID');
  62.             
  63.             // Get Author User
  64.             $author_ID $db_row['comment_author_ID'];
  65.             if!empty($author_ID) )
  66.             {
  67.                 $authordata get_userdata$author_ID );
  68.                 $this->author_User = new User$authordata )// COPY!
  69.             }
  70.                         
  71.             $this->type = $db_row['comment_type'];
  72.             $this->status = $db_row['comment_status'];
  73.             $this->author = $db_row['comment_author'];
  74.             $this->author_email = $db_row['comment_author_email'];
  75.             $url trim$db_row['comment_author_url');
  76.             $url preg_replace('#&([^amp\;])#is''&amp;$1'$url);    // Escape &
  77.             $this->author_url = (!stristr($url'://')) 'http://'.$url $url;
  78.             $this->author_ip = $db_row['comment_author_IP'];
  79.             $this->date = $db_row['comment_date'];
  80.             $this->content = $db_row['comment_content'];
  81.             $this->karma = $db_row['comment_karma'];
  82.         }
  83.     }    
  84.     
  85.     /* 
  86.      * Comment::set(-)
  87.      *
  88.      * Set param value
  89.      */
  90.     function set$parname$parvalue )
  91.     {
  92.         switch$parname )
  93.         {
  94.             case 'Item':
  95.                 die ('coment->Post assignement not handled');
  96.     
  97.             case 'karma':
  98.                 parent::set_param$parname'number'$parvalue );
  99.             break;
  100.             
  101.             default:
  102.                 parent::set_param$parname'string'$parvalue );
  103.         }
  104.     }
  105.  
  106.  
  107.     /** 
  108.      * Template function: display anchor for permalinks to refer to
  109.      *
  110.      * {@internal Comment::anchor(-) }}
  111.      */
  112.     function anchor(
  113.     {
  114.         echo '<a name="c'.$this->ID.'"></a>';
  115.     }
  116.  
  117.  
  118.     /** 
  119.      * Template function: display author of comment
  120.      *
  121.      * {@internal Comment::author(-) }}
  122.      *
  123.      * @param string String to display before author name if not a user
  124.      * @param string String to display after author name if not a user
  125.      * @param string String to display before author name if he's a user
  126.      * @param string String to display after author name if he's a user
  127.      * @param string Output format, see {@link format_to_output()}
  128.      * @param boolean true for link, false if you want NO html link
  129.      */
  130.     function author$before ''$after '#'$before_user ''$after_user '#'
  131.                                         $format 'htmlbody'$makelink false 
  132.     {
  133.         if$this->author_User !== NULL )
  134.         // Author is a user
  135.             if$after_user == '#' $after_user ' ['.T_('Member').']';
  136.             echo $before_user;
  137.             $this->author_User->prefered_name$format );
  138.             echo $after_user;
  139.         }
  140.         else
  141.         {    // Display info recorded at edit time:
  142.             ifstrlen$this->author_url <= 10 $makelink false;
  143.             if$after == '#' $after ' ['.T_('Visitor').']';
  144.             echo $before;
  145.             if$makelink echo '<a href="'.$this->author_url.'">';
  146.             $this->disp'author'$format );
  147.             if$makelink echo '</a>';
  148.             echo $after;
  149.         }
  150.     }
  151.  
  152.  
  153.     /** 
  154.      * Template function: display comment's author's IP
  155.      *
  156.      * {@internal Comment::author_ip(-) }}
  157.      * 
  158.      * @param string String to display before IP, if IP exists
  159.      * @param string String to display after IP, if IP exists
  160.      */
  161.     function author_ip$before=''$after='' 
  162.     {
  163.         if!empty$this->author_ip ) )
  164.         {
  165.             echo $before;
  166.             echo $this->author_ip;
  167.             echo $after;
  168.         }
  169.     }
  170.  
  171.  
  172.     /** 
  173.      * Template function: display link to comment author's provided email
  174.      *
  175.      * {@internal Comment::author_email(-) }}
  176.      *
  177.      * @param string String to display for link: leave empty to display email
  178.      * @param string String to display before email, if email exists
  179.      * @param string String to display after email, if email exists
  180.      * @param boolean false if you want NO html link
  181.      */
  182.     function author_email$linktext=''$before=''$after=''$makelink true 
  183.     {
  184.         if$this->author_User !== NULL )
  185.         // Author is a user
  186.             $email $this->author_User->get('email');
  187.         }
  188.         else
  189.         {
  190.             $email $this->author_email;
  191.         }
  192.         
  193.         ifstrlen$email )
  194.         {    // If email exists:
  195.             echo $before;
  196.             if$makelink echo '<a href="mailto:'.$email.'">';
  197.             echo ($linktext != ''$linktext $email;
  198.             if$makelink echo '</a>';
  199.             echo $after;
  200.         }
  201.     }
  202.  
  203.  
  204.     /** 
  205.      * Template function: display link to comment author's provided URL
  206.      *
  207.      * {@internal Comment::author_url(-) }}
  208.      *
  209.      * @param string String to display for link: leave empty to display URL
  210.      * @param string String to display before link, if link exists
  211.      * @param string String to display after link, if link exists
  212.      * @param boolean false if you want NO html link
  213.      * @return boolean true if URL has been displayed
  214.      */
  215.     function author_url$linktext=''$before=''$after=''$makelink true )
  216.     {
  217.         if$this->author_User !== NULL )
  218.         // Author is a user
  219.             $url $this->author_User->get('url');
  220.         }
  221.         else
  222.         {
  223.             $url $this->author_url;
  224.         }
  225.  
  226.         ifstrlen$url 10 )
  227.         {    // If URL exists:
  228.             echo $before;
  229.             if$makelink echo '<a href="'.$url.'" rel="nofollow">';
  230.             echo ($linktext != ''$linktext $url;
  231.             if$makelink echo '</a>';
  232.             echo $after;
  233.             return true;
  234.         }
  235.         
  236.         return false;
  237.     }
  238.  
  239.  
  240.     /**
  241.      * Provide link to edit a comment if user has edit rights
  242.      *
  243.      * {@internal Comment::edit_link(-)}}
  244.      *
  245.      * @param string to display before link
  246.      * @param string to display after link
  247.      * @param string link text
  248.      * @param string link title
  249.      * @param string class name
  250.      */
  251.     function edit_link$before ' '$after ' '$text '#'$title '#'$class '' )
  252.     {
  253.         global $current_User$admin_url;
  254.         
  255.         ifis_logged_in() ) return false;
  256.     
  257.         if$current_User->check_perm'blog_comments'''false$this->Item->get'blog_ID' ) ) )
  258.         {    // If User has no permission to edit comments:
  259.             return false;
  260.         }
  261.     
  262.         if$text == '#' $text T_('Edit');
  263.         if$title == '#' $title T_('Edit this comment');
  264.         
  265.         echo $before;
  266.         echo '<a href="'.$admin_url.'/b2edit.php?action=editcomment&amp;comment='.$this->ID;
  267.         echo '" title="'.$title.'"';
  268.         if!empty$class ) ) echo ' class="'.$class.'"';
  269.         echo '>'.$text.'</a>';
  270.         echo $after;
  271.     
  272.         return true;
  273.     }
  274.  
  275.  
  276.     /**
  277.      * Displays button for deleeing the Comment if user has proper rights
  278.      *
  279.      * {@internal Comment::delete_link(-)}}
  280.      *
  281.      * @param string to display before link
  282.      * @param string to display after link
  283.      * @param string link text
  284.      * @param string link title
  285.      * @param string class name
  286.      * @param boolean true to make this a button instead of a link
  287.      */
  288.     function delete_link$before ' '$after ' '$text '#'$title '#'$class ''$button  false )
  289.     {
  290.         global $current_User$admin_url;
  291.  
  292.          ifis_logged_in() ) return false;
  293.  
  294.          if$current_User->check_perm'blog_comments'''false$this->Item->get'blog_ID' ) ) )
  295.         {    // If User has permission to edit comments:
  296.             return false;
  297.         }
  298.  
  299.         if$text == '#' $text T_('Delete');
  300.         if$title == '#' $title T_('Delete this comment');
  301.  
  302.         $url $admin_url.'/edit_actions.php?action=deletecomment&amp;comment_ID='.$this->ID;
  303.  
  304.         echo $before;
  305.         if$button )
  306.         {    // Display as button
  307.             echo '<input type="button"';
  308.             echo ' value="'.$text.'" title="'.$title.'" onclick="if ( confirm(\'';
  309.             /* TRANS: Warning this is a javascript string */
  310.             echo T_('You are about to delete this comment!\\n\\\'Cancel\\\' to stop, \\\'OK\\\' to delete.');
  311.             echo '\') ) { document.location.href=\''.$url.'\' }"';
  312.             if!empty$class ) ) echo ' class="'.$class.'"';
  313.             echo '/>';
  314.         }
  315.         else
  316.         {    // Display as link
  317.             echo '<a href="'.$url.'" title="'.$title.'" onclick="return confirm(\'';
  318.             /* TRANS: Warning this is a javascript string */
  319.             echo T_('You are about to delete this comment!\\n\\\'Cancel\\\' to stop, \\\'OK\\\' to delete.');
  320.             echo '\')"';
  321.             if!empty$class ) ) echo ' class="'.$class.'"';
  322.             echo '>'.$text.'</a>';
  323.         }
  324.         echo $after;
  325.  
  326.         return true;
  327.     }
  328.  
  329.  
  330.     /** 
  331.      * Template function: display permalink to this comment
  332.      *
  333.      * {@internal Comment::permalink(-) }}
  334.      * 
  335.      * @param string 'urltitle', 'pid', 'archive#id' or 'archive#title'
  336.      * @param string url to use
  337.      */
  338.     function permalink$mode ''$blogurl='' )
  339.     {
  340.         global $Settings;
  341.         
  342.         ifempty$mode ) )
  343.             $mode $Settings->get'permalink_type' );
  344.  
  345.         // some permalink modes are not acceptable here:
  346.         switch$mode )
  347.         {
  348.             case 'archive#id':
  349.             case 'archive#title':            
  350.               $mode 'pid';
  351.         }
  352.  
  353.         $post_permalink $this->Item->gen_permalink$mode$blogurl );
  354.         echo $post_permalink.'#c'.$this->ID;
  355.     }
  356.  
  357.     /** 
  358.      * Template function: display content of comment
  359.      *
  360.      * {@internal Comment::content(-) }}
  361.      *
  362.      * @param string Output format, see {@link format_to_output()}
  363.      */
  364.     function content$format 'htmlbody' 
  365.     {
  366.         $comment $this->content;
  367.         $comment str_replace('<trackback />'''$comment);
  368.         $comment str_replace('<pingback />'''$comment);
  369.         $comment format_to_output$comment$format );
  370.         echo $comment;
  371.     }
  372.  
  373.     /** 
  374.      * Template function: display date (datetime) of comment
  375.      *
  376.      * {@internal Comment::date(-) }}
  377.      *
  378.      * @param string date/time format: leave empty to use locale default date format
  379.      * @param boolean true if you want GMT
  380.      */
  381.     function date$format=''$useGM false )
  382.     {
  383.         ifempty($format) ) 
  384.             echo mysql2datelocale_datefmt()$this->date$useGM);
  385.         else
  386.             echo mysql2date$format$this->date$useGM);
  387.     }
  388.  
  389.     /** 
  390.      * Template function: display time (datetime) of comment
  391.      *
  392.      * {@internal Comment::time(-) }}
  393.      *
  394.      * @param string date/time format: leave empty to use locale default time format
  395.      * @param boolean true if you want GMT
  396.      */
  397.     function time$format=''$useGM false )
  398.     {
  399.         ifempty($format) ) 
  400.             echo mysql2datelocale_timefmt()$this->date$useGM );
  401.         else
  402.             echo mysql2date$format$this->date$useGM );
  403.     }
  404.  
  405. }
  406. ?>

Documentation generated on Tue, 20 May 2008 01:52:40 +0200 by phpDocumentor 1.4.2