b2evolution

Multilingual multiuser multiblog engine

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

Source for file _functions_comments.php

Documentation is available at _functions_comments.php

  1. <?php
  2. /**
  3.  * Comment handling
  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.  * @author This file built upon code from original b2 - http://cafelog.com/
  11.  */
  12. if!defined('DB_USER') ) die'Please, do not access this page directly.' );
  13.  
  14. /**
  15.  * Includes:
  16.  */
  17. require_once dirname(__FILE__)'/_class_comment.php';
  18.  
  19. /**
  20.  * generic_ctp_number(-)
  21.  *
  22.  * generic comments/trackbacks/pingbacks numbering
  23.  *
  24.  * fplanque: added stuff to load all number for this page at ounce
  25.  */
  26. function generic_ctp_number($post_id$mode 'comments')
  27. {
  28.     global $DB$debug$postdata$tablecomments$cache_ctp_number$use_cache$preview;
  29.     if$preview )
  30.     {    // we are in preview mode, no comments yet!
  31.         return 0;
  32.     }
  33.     
  34.     if$mode == 'feedbacks' $mode ='ctp';
  35.  
  36.     // fplanque added: load whole cache
  37.     if (!isset($cache_ctp_number|| (!$use_cache))
  38.     {
  39.         global $postIDlist$postIDarray;
  40.         // if( $debug ) echo "LOADING generic_ctp_number CACHE for posts: $postIDlist<br />";
  41.         foreach$postIDarray as $tmp_post_id)
  42.         {        // Initializes each post to nocount!
  43.                 $cache_ctp_number[$tmp_post_idarray'comments' => 0'trackbacks' => 0'pingbacks' => 0'ctp' => 0);
  44.         }
  45.         $query "SELECT comment_post_ID, comment_type, COUNT(*) AS type_count 
  46.                             FROM $tablecomments 
  47.                             WHERE comment_post_ID IN ($postIDlist
  48.                             GROUP BY comment_post_ID, comment_type";
  49.         $rows $DB->get_results$query );
  50.         ifcount$rows ) ) foreach$rows as $row )
  51.         {
  52.             switch$row->comment_type )
  53.             {
  54.                 case 'comment';
  55.                     $cache_ctp_number[$row->comment_post_ID]['comments'$row->type_count;
  56.                     break;
  57.  
  58.                 case 'trackback';
  59.                     $cache_ctp_number[$row->comment_post_ID]['trackbacks'$row->type_count;
  60.                     break;
  61.  
  62.                 case 'pingback';
  63.                     $cache_ctp_number[$row->comment_post_ID]['pingbacks'$row->type_count;
  64.                     break;
  65.             }
  66.             $cache_ctp_number[$row->comment_post_ID]['ctp'+= $row->type_count;
  67.         }
  68.     }
  69.     /*    else
  70.     {
  71.         echo "cache set";
  72.     }*/
  73.     if (!isset($cache_ctp_number[$post_id]|| (!$use_cache))
  74.     {    // this should be extremely rare...
  75.         // echo "CACHE not set for $post_id";
  76.         $post_id intval($post_id);
  77.         $query "SELECT comment_post_ID, comment_type, COUNT(*) AS type_count 
  78.                             FROM $tablecomments 
  79.                             WHERE comment_post_ID = $post_id 
  80.                             GROUP BY comment_post_ID, comment_type";
  81.         $rows $DB->get_results$query );
  82.         ifcount$rows ) ) foreach$rows as $row )
  83.         {
  84.             switch$row->comment_type )
  85.             {
  86.                 case 'comment';
  87.                     $cache_ctp_number[$row->comment_post_ID]['comments'$row->type_count;
  88.                     break;
  89.  
  90.                 case 'trackback';
  91.                     $cache_ctp_number[$row->comment_post_ID]['trackbacks'$row->type_count;
  92.                     break;
  93.  
  94.                 case 'pingback';
  95.                     $cache_ctp_number[$row->comment_post_ID]['pingbacks'$row->type_count;
  96.                     break;
  97.             }
  98.             $cache_ctp_number[$row->comment_post_ID]['ctp'+= $row->type_count;
  99.         }
  100.     else {
  101.         $ctp_number $cache_ctp_number[$post_id];
  102.     }
  103.     if (($mode != 'comments'&& ($mode != 'trackbacks'&& ($mode != 'pingbacks'&& ($mode != 'ctp')) {
  104.         $mode 'ctp';
  105.     }
  106.     return $ctp_number[$mode];
  107. }
  108.  
  109.  
  110. /*
  111.  * get_commentdata(-)
  112.  */
  113. function get_commentdata($comment_ID,$no_cache=0)
  114. // less flexible, but saves mysql queries
  115.     global $DB$rowc,$id,$commentdata,$tablecomments$baseurl;
  116.  
  117.     if ($no_cache)
  118.     {
  119.         $query "SELECT * 
  120.                             FROM $tablecomments 
  121.                             WHERE comment_ID = $comment_ID";
  122.         $myrow $DB->get_row$queryARRAY_A );
  123.     }
  124.     else
  125.     {
  126.         $myrow['comment_ID'$rowc->comment_ID;
  127.         $myrow['comment_post_ID'$rowc->comment_post_ID;
  128.         $myrow['comment_author'$rowc->comment_author;
  129.         $myrow['comment_author_email'$rowc->comment_author_email;
  130.         $myrow['comment_author_url'$rowc->comment_author_url;
  131.         $myrow['comment_author_IP'$rowc->comment_author_IP;
  132.         $myrow['comment_date'$rowc->comment_date;
  133.         $myrow['comment_content'$rowc->comment_content;
  134.         $myrow['comment_karma'$rowc->comment_karma;
  135.         $myrow['comment_type'$rowc->comment_type;
  136.         ifisset($rowc->ID) ) $myrow['post_ID'$rowc->ID;
  137.         ifisset($rowc->post_title) ) $myrow['post_title'$rowc->post_title;
  138.         ifisset($rowc->blog_name) ) $myrow['blog_name'$rowc->blog_name;
  139.         ifisset($rowc->blog_siteurl) ) $myrow['blog_siteurl'$baseurl.$rowc->blog_siteurl;
  140.         ifisset($rowc->blog_stub) ) $myrow['blog_stub'$rowc->blog_stub;
  141.     }
  142.     return($myrow);
  143. }
  144.  
  145.  
  146. /*
  147.  * Comment_get_by_ID(-)
  148.  */
  149. function Comment_get_by_ID$comment_ID )
  150. {
  151.     global $DB$cache_Comments$use_cache$tablecomments$querycount;
  152.  
  153.     if((empty($cache_Comments[$comment_ID])) OR (!$use_cache))
  154.     {    // Load this entry into cache:
  155.         $query "SELECT * 
  156.                             FROM $tablecomments 
  157.                             WHERE comment_ID = $comment_ID";
  158.         if$row $DB->get_row$queryARRAY_A ) )
  159.         {
  160.             $cache_Comments[$comment_IDnew Comment$row )// COPY !
  161.         }
  162.     }
  163.  
  164.     ifempty$cache_Comments$comment_ID ) ) die('Requested comment does not exist!');
  165.  
  166.     return $cache_Comments$comment_ID ];
  167. }
  168.  
  169.  
  170. /*
  171.  * TEMPLATE functions
  172.  */
  173.  
  174. /**
  175.  * Display "Last comments" title if these have been requested
  176.  *
  177.  * {@internal last_comments_title(-) }}
  178.  *
  179.  * @param string Prefix to be displayed if something is going to be displayed
  180.  * @param mixed Output format, see {@link format_to_output()} or false to
  181.  *                                 return value instead of displaying it
  182.  */
  183. function last_comments_title$prefix ' '$display 'htmlbody' )
  184. {
  185.     global $disp;
  186.  
  187.     if$disp == 'comments' )
  188.     {
  189.         $info $prefix.T_('Last comments');
  190.         if ($display)
  191.             echo format_to_output$info$display );
  192.         else
  193.             return $info;
  194.     }
  195. }
  196.  
  197.  
  198.  
  199. /***** Comment tags *****/
  200.  
  201.  
  202.  
  203. /**
  204.  * comments_number(-)
  205.  *
  206.  * @deprecated deprecated by {@link Item::feedback_link()}
  207.  */
  208. function comments_number$zero='#'$one='#'$more='#' )
  209. {
  210.     if$zero == '#' $zero T_('Leave a comment');
  211.     if$one == '#' $one T_('1 comment');
  212.     if$more == '#' $more T_('%d comments');
  213.  
  214.     // original hack by dodo@regretless.com
  215.     global $id,$postdata,$tablecomments,$c,$querycount,$cache_commentsnumber,$use_cache;
  216.     $number generic_ctp_number($id'comments');
  217.     if ($number == 0{
  218.         $blah $zero;
  219.     elseif ($number == 1{
  220.         $blah $one;
  221.     elseif ($number  1{
  222.         $n $number;
  223.         $more str_replace('%d'$n$more);
  224.         $blah $more;
  225.     }
  226.     echo $blah;
  227. }
  228.  
  229. /**
  230.  * {@internal comments_link(-)}}
  231.  *
  232.  * Displays link to comments page
  233.  *
  234.  * @deprecated deprecated by {@link Item::feedback_link()}
  235.  */
  236. function comments_link($file=''$tb=0$pb=)
  237. {
  238.     global $id;
  239.     if( ($file == ''|| ($file == '/')    )
  240.         $file get_bloginfo('blogurl');
  241.     echo url_add_param$file'p='$id'&amp;c=1' );
  242.     if$tb == )
  243.     {    // include trackback // fplanque: added
  244.         echo '&amp;tb=1';
  245.     }
  246.     if$pb == )
  247.     {    // include pingback // fplanque: added
  248.         echo '&amp;pb=1';
  249.     }
  250.     echo '#comments';
  251. }
  252.  
  253.  
  254. /**
  255.  * This will include the javascript that is required to open comments,
  256.  * trackback and pingback in popup windows.
  257.  *
  258.  * You should put this tag before the </head> tag in your template.
  259.  *
  260.  * {@internal comments_popup_script(-)}}
  261.  *
  262.  * @param integer width of window or false
  263.  * @param integer height of window or false
  264.  * @param boolean do you want a scrollbar
  265.  * @param boolean do you want a status bar
  266.  * @param boolean do you want the windows to be resizable
  267.   */
  268. function comments_popup_script$width 600$height 450
  269.                                                                 $scrollbars true$status true$resizable true )
  270. {
  271.     global $b2commentsjavascript;
  272.     $b2commentsjavascript true;
  273.     $properties array();
  274.     if$width $properties['width='.$width;
  275.     if$height $properties['height='.$height;
  276.     $properties['scrollbars='.intval$scrollbars );
  277.     $properties['status='.intval$status );
  278.     $properties['resizable='.intval$resizable );
  279.     $properties implode','$properties );
  280.     ?>
  281.     <script language="javascript" type="text/javascript">
  282.     <!--
  283.         function b2open( url )
  284.         {
  285.             window.open( url, '_blank', '<?php echo $properties?>');
  286.         }
  287.         //-->
  288.     </script>
  289.     <?php
  290. }
  291.  
  292.  
  293. /**
  294.  * comments_popup_link(-)
  295.  *
  296.  * @deprecated deprecated by {@link Item::feedback_link()}
  297.  */
  298. function comments_popup_link($zero='#'$one='#'$more='#'$CSSclass='')
  299. {
  300.     global $blog$id$b2commentspopupfile$b2commentsjavascript;
  301.     echo '<a href="';
  302.     if($b2commentsjavascript)
  303.     {
  304.         echo url_add_paramget_bloginfo('blogurl')'template=popup&amp;p='.$id.'&amp;c=1' );
  305.         echo '" onclick="b2open(this.href); return false"';
  306.     }
  307.     else
  308.     {    // if comments_popup_script() is not in the template, display simple comment link
  309.         comments_link();
  310.         echo '"';
  311.     }
  312.     if (!empty($CSSclass)) {
  313.         echo ' class="'.$CSSclass.'"';
  314.     }
  315.     echo '>';
  316.     comments_number($zero$one$more);
  317.     echo '</a>';
  318. }
  319.  
  320. /**
  321.  * comment_ID(-)
  322.  *
  323.  * @deprecated deprecated by {@link DataObject::ID()}
  324.  */
  325. function comment_ID()
  326. {
  327.     global $commentdata;    echo $commentdata['comment_ID'];
  328. }
  329.  
  330. /**
  331.  * comment_author(-)
  332.  *
  333.  * @deprecated deprecated by {@link Comment::author()}
  334.  */
  335. function comment_author()
  336. {
  337.     global $commentdata;
  338.     echo $commentdata['comment_author'];
  339. }
  340.  
  341. /**
  342.  * comment_author_email(-)
  343.  *
  344.  * @deprecated deprecated by {@link Comment::author_email()}
  345.  */
  346. {
  347.     global $commentdata;    echo antispambot$commentdata['comment_author_email');
  348. }
  349.  
  350. /**
  351.  * comment_author_url(-)
  352.  *
  353.  * @deprecated deprecated by {@link Comment::author_url()}
  354.  */
  355. function comment_author_url($echo=true)
  356. {
  357.     global $commentdata;
  358.     $url trim($commentdata['comment_author_url']);
  359.     $url (!stristr($url'://')) 'http://'.$url $url;
  360.     // convert & into &amp;
  361.     $url preg_replace('#&([^amp\;])#is''&amp;$1'$url);
  362.     if ($url != 'http://')
  363.     {
  364.         if ($echo)
  365.             echo $url;
  366.         else
  367.             return $url;
  368.     }
  369. }
  370.  
  371. /**
  372.  * comment_author_url_basedomain(-)
  373.  *
  374.  * @deprecated
  375.  */
  376. function comment_author_url_basedomain$disp true )
  377. {
  378.     global $commentdata;
  379.     $url comment_author_url(false);
  380.     $baseDomain preg_replace("/http:\/\//i"""$url);
  381.     $baseDomain preg_replace("/^www\./i"""$baseDomain);
  382.     $baseDomain preg_replace("/\/.*/i"""$baseDomain);
  383.     if$disp )
  384.         echo $baseDomain;
  385.     else
  386.         return $baseDomain;
  387. }
  388.  
  389. /**
  390.  * comment_author_email_link(-)
  391.  *
  392.  * @deprecated deprecated by {@link Comment::author_email()}
  393.  */
  394. function comment_author_email_link($linktext=''$before=''$after='')
  395. {
  396.     global $commentdata;
  397.     $email=$commentdata['comment_author_email'];
  398.     if ((!empty($email)) && ($email != '@')) {
  399.         $display ($linktext != ''$linktext antispambot($email);
  400.         echo $before;
  401.         echo '<a href="mailto:'.antispambot($email).'">'.$display.'</a>';
  402.         echo $after;
  403.     }
  404. }
  405.  
  406.  
  407. /**
  408.  * comment_author_url_link(-)
  409.  *
  410.  * @deprecated deprecated by {@link $Comment->author_url()}
  411.  */
  412. function comment_author_url_link($linktext=''$before=''$after='')
  413. {
  414.     global $commentdata;
  415.     $url trim($commentdata['comment_author_url']);
  416.     $url preg_replace('#&([^amp\;])#is''&amp;$1'$url);
  417.     $url (!stristr($url'://')) 'http://'.$url $url;
  418.     if ((!empty($url)) && ($url != 'http://'&& ($url != 'http://url'))
  419.     {
  420.         $display ($linktext != ''$linktext $url;
  421.         echo $before;
  422.         echo '<a href="'.$url.'">'.$display.'</a>';
  423.         echo $after;
  424.     }
  425. }
  426.  
  427. /**
  428.  * comment_author_IP(-)
  429.  *
  430.  * @deprecated deprecated by {@link Comment::author_ip()}
  431.  */
  432. function comment_author_IP({
  433.     global $commentdata;    echo $commentdata['comment_author_IP'];
  434. }
  435.  
  436. /**
  437.  * comment_text(-)
  438.  *
  439.  * @deprecated deprecated by {@link $Comment::content()}
  440.  */
  441. function comment_text()
  442. {
  443.     global $commentdata;
  444.  
  445.     $comment $commentdata['comment_content'];
  446.     $comment str_replace('<trackback />'''$comment);
  447.     $comment str_replace('<pingback />'''$comment);
  448.     $comment format_to_output$comment'htmlbody' );
  449.     echo $comment;
  450. }
  451.  
  452. /*$
  453.  * comment_date(-)
  454.  *
  455.  * @deprecated deprecated by {@link $Comment::date()}
  456.  */
  457. function comment_date($d=''{
  458.     global $commentdata;
  459.     if$d == '' )
  460.         echo mysql2datelocale_datefmt()$commentdata['comment_date']);
  461.     else
  462.         echo mysql2date($d$commentdata['comment_date']);
  463. }
  464.  
  465. /**
  466.  * comment_time(-)
  467.  *
  468.  * @deprecated deprecated by {@link $Comment::time()}
  469.  */
  470. function comment_time$d '' )
  471. {
  472.     global $commentdata;
  473.     if$d == '' )
  474.         echo mysql2datelocale_timefmt()$commentdata['comment_date']);
  475.     else
  476.         echo mysql2date($d$commentdata['comment_date']);
  477. }
  478.  
  479. /**
  480.  * comment_post_title(-)
  481.  * fplanque added
  482.  *
  483.  * @deprecated deprecated by {@link $Comment::post_title()}
  484.  */
  485. function comment_post_title()
  486. {
  487.     global $commentdata;
  488.     $title $commentdata['post_title'];
  489.     echo format_to_output$title'htmlbody' );
  490. }
  491.  
  492. /**
  493.  * comment_post_link(-)
  494.  * fplanque added
  495.  *
  496.  * @deprecated deprecated by {@link $Comment::post_link()}
  497.  */
  498. function comment_post_link()
  499. {
  500.     global $commentdata;
  501.     echo gen_permalink$commentdata['blog_siteurl']'/'$commentdata['blog_stub']$commentdata['post_ID'],    'id''single' );
  502. }
  503.  
  504.  
  505. /**
  506.  * comment_blog_name(-)
  507.  * fplanque added
  508.  *
  509.  * @deprecated
  510.  */
  511. function comment_blog_name$disp true )
  512. {
  513.     global $commentdata;
  514.     $blog_name $commentdata['blog_name'];
  515.     if!$disp )
  516.         return $blog_name;
  517.     echo $blog_name;
  518. }
  519.  
  520. /*****
  521.  * /Comment tags
  522.  *****/
  523.  
  524.  
  525.  
  526. ?>

Documentation generated on Tue, 20 May 2008 01:54:47 +0200 by phpDocumentor 1.4.2