b2evolution

Multilingual multiuser multiblog engine

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

Source for file _class_item.php

Documentation is available at _class_item.php

  1. <?php
  2. /**
  3.  * This file implements items
  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.  * Item Class
  20.  *
  21.  * @package evocore
  22.  */
  23. class Item extends DataObject
  24. {
  25.     /**
  26.      * @var User 
  27.      * @access public
  28.      */
  29.     var $Author;
  30.     var $issue_date;
  31.     var $mod_date;
  32.     var $status;
  33.     /**
  34.      * locale code for the Item content
  35.      *
  36.      * examples: en-US, zh-CN-utf-8
  37.      *
  38.      * @var string 
  39.      */
  40.     var $locale;
  41.     var $title;
  42.     var $urltitle;
  43.     var $content;
  44.     var $wordcount = 0;
  45.     var $main_cat_ID = 0;
  46.     var $flags;
  47.     var $renderers;
  48.     var $comments;            // Comments status
  49.     var $url;                    // Should move
  50.     /**
  51.      * @var boolean 
  52.      * @deprecated
  53.      */
  54.     var $autobr = 0;        // Should move
  55.     /**
  56.      * Derived from $main_cat_ID
  57.    *
  58.      * @var integer 
  59.      */
  60.     var $blog_ID;
  61.  
  62.     /**
  63.      * Constructor
  64.      *
  65.      * {@internal Item::Item(-)}}
  66.      */
  67.     function Item$db_row NULL )
  68.     {
  69.         global $tableposts;
  70.  
  71.         // Call parent constructor:
  72.         parent::DataObject$tableposts'post_''ID' );
  73.  
  74.         if$db_row == NULL )
  75.         {
  76.             $this->ID = 0;
  77.             $this->flags = array();
  78.             $this->renderers = array();
  79.         }
  80.         else
  81.         {
  82.             $this->ID = $db_row->ID;
  83.             $authordata get_userdata($db_row->post_author);
  84.             $this->Author = new User$authordata )// COPY!
  85.             $this->issue_date = $db_row->post_issue_date;
  86.             $this->mod_date = $db_row->post_mod_date;
  87.             $this->status = $db_row->post_status;
  88.             $this->locale = $db_row->post_locale;
  89.             $this->title = $db_row->post_title;
  90.             $this->urltitle = $db_row->post_urltitle;
  91.             $this->content = $db_row->post_content;
  92.             $this->wordcount = $db_row->post_wordcount;
  93.             $this->main_cat_ID = $db_row->post_category;
  94.             $this->flags = $db_row->post_flags;
  95.             $this->comments = $db_row->post_comments;            // Comments status
  96.             // echo 'renderers=', $db_row->post_renderers;
  97.             $this->renderers = explode'.'$db_row->post_renderers );
  98.             $this->url = $db_row->post_url;                // Should move
  99.             $this->autobr = $db_row->post_autobr;                    // Should move
  100.             // Derived vars
  101.             $this->blog_ID = get_catblog$this->main_cat_ID );
  102.         }
  103.     }
  104.  
  105.  
  106.     /**
  107.       * generate permalink for item
  108.      *
  109.      * {@internal Item::gen_permalink(-)}}
  110.      *
  111.      * @todo archives modes in clean mode
  112.      *
  113.      * @param string 'urltitle', 'pid', 'archive#id' or 'archive#title'
  114.      * @param string url to use
  115.    * @param boolean true to force single post on destination page
  116.    * @param string glue between url params
  117.      */
  118.     function gen_permalink$mode ''$blogurl ''$force_single false$glue '&amp;' )
  119.     {
  120.         global $DB$BlogCache$cacheweekly$Settings;
  121.  
  122.         ifempty$mode ) )
  123.             $mode $Settings->get'permalink_type' );
  124.  
  125.         if$force_single && (strpos$mode'archive' !== false) )
  126.         {    // Comments cannot be displayed in archive mode
  127.             $mode 'pid';
  128.         }
  129.  
  130.         ifempty$blogurl ) ) 
  131.         {
  132.             $current_Blog $BlogCache->get_by_ID$this->blog_ID );
  133.             $blogurl $current_Blog->gen_blogurl();
  134.         }
  135.  
  136.         $post_date $this->issue_date;
  137.  
  138.         switch$mode )
  139.         {
  140.             case 'archive#id':
  141.                 // Link to an archive page:
  142.                 $dest_type $Settings->get('archive_mode');
  143.                 $anchor $this->ID;
  144.                 $urltail 'p'.$this->ID;
  145.                 break;
  146.  
  147.             case 'archive#title':
  148.                 // Link to an archive page:
  149.                 $dest_type $Settings->get('archive_mode');
  150.                 $anchor preg_replace('/[^a-zA-Z0-9_\.-]/''_'$this->title );
  151.                 $urltail 'p'.$this->ID;
  152.                 break;
  153.  
  154.             case 'pid':
  155.                 // Link to individual post:
  156.                 $dest_type 'postbypost';
  157.                 $urlparam 'p='.$this->ID;
  158.                 $urltail 'p'.$this->ID;
  159.                 break;
  160.  
  161.             case 'urltitle':
  162.             default:
  163.                 // Link to individual post:
  164.                 $dest_type 'postbypost';
  165.                 if!empty$this->urltitle ) )
  166.                 {
  167.                     $urlparam 'title='.$this->urltitle;
  168.                     $urltail $this->urltitle;
  169.                 }
  170.                 else
  171.                 {
  172.                     $urlparam 'p='.$this->ID;
  173.                     $urltail 'p'.$this->ID;
  174.                 }
  175.         }
  176.  
  177.         if$Settings->get('links_extrapath') )
  178.         {    // We reference by Query: Dirty but explicit permalinks
  179.  
  180.             switch$dest_type )
  181.             {
  182.                 case 'monthly':
  183.                     $permalink url_add_param$blogurl'm='.substr($post_date,0,4).substr($post_date,5,2)$glue ).'#'.$anchor;
  184.                     break;
  185.  
  186.                 case 'weekly':
  187.                     if((!isset($cacheweekly)) || (empty($cacheweekly[$post_date])))
  188.                     {
  189.                         $cacheweekly[$post_date$DB->get_var"SELECT WEEK('".$post_date."')" );
  190.                     }
  191.                     $permalink url_add_param$blogurl'm='.substr($post_date,0,4).$glue.'w='.$cacheweekly[$post_date]$glue ).'#'.$anchor;
  192.                     break;
  193.  
  194.                 case 'daily':
  195.                     $permalink url_add_param$blogurl'm='.substr($post_date,0,4).substr($post_date,5,2).substr($post_date,8,2)$glue ).'#'.$anchor;
  196.                     break;
  197.  
  198.                 case 'postbypost':
  199.                 default:
  200.                     $permalink url_add_param$blogurl$urlparam.$glue.'more=1'.$glue.'c=1'.$glue.'tb=1'.$glue.'pb=1'$glue );
  201.                     break;
  202.             }
  203.         }
  204.         else
  205.         {    // We reference by path (CLEAN permalinks!)
  206.             switch$dest_type )
  207.             {
  208.                 case 'monthly':
  209.                     $permalink url_add_tail$blogurlmysql2date("/Y/m"$post_date) ).'#'.$anchor;
  210.                     break;
  211.  
  212.                 case 'weekly':
  213.                     if((!isset($cacheweekly)) || (empty($cacheweekly[$post_date])))
  214.                     {
  215.                         $cacheweekly[$post_date$DB->get_var"SELECT WEEK('".$post_date."')" );
  216.                     }
  217.                     $permalink url_add_tail$blogurlmysql2date("/Y/"$post_date).'w'.$cacheweekly[$post_date).'#'.$anchor;
  218.                     break;
  219.  
  220.                 case 'daily':
  221.                     $permalink url_add_tail$blogurlmysql2date("/Y/m/d"$post_date) ).'#'.$anchor;
  222.                     break;
  223.  
  224.                 case 'postbypost':
  225.                 default:
  226.                     // This is THE CLEANEST available: RECOMMENDED!
  227.                     $permalink url_add_tail$blogurlmysql2date("/Y/m/d/"$post_date).$urltail );
  228.                     break;
  229.             }
  230.         }
  231.  
  232.         return $permalink;
  233.     }
  234.  
  235.  
  236.     /**
  237.      * Template function: display anchor for permalinks to refer to
  238.      *
  239.      * {@internal Item::anchor(-) }}
  240.      *
  241.      * @todo archives modes in clean mode
  242.      *
  243.      * @param string 'id' or 'title'
  244.      */
  245.     function anchor$mode '' )
  246.     {
  247.         global $Settings;
  248.  
  249.         ifempty$mode ) )
  250.             $mode $Settings->get'permalink_type' );
  251.  
  252.         switch$mode )
  253.         {
  254.             case 'archive#title'// permalink_type
  255.             case 'title'// explicit choice
  256.                 $title preg_replace'/[^a-zA-Z0-9_\.-]/''_'$this->title );
  257.                 echo '<a name="'.$title.'"></a>';
  258.                 break;
  259.  
  260.             case 'archive#id'// permalink_type
  261.             case 'id'// explicit choice
  262.                 echo '<a name="'.$this->ID.'"></a>';
  263.                 break;
  264.  
  265.  
  266.             case 'pid'// permalink type where we need no ID
  267.             case 'urltitle'// permalink type where we need no ID
  268.             default:
  269.         }
  270.     }
  271.  
  272.  
  273.     /**
  274.      * Template function: list all the category names
  275.      *
  276.      * {@internal Item::categories(-) }}
  277.      *
  278.      * @param string link title, '#' for default, false if you want no links
  279.      * @param string string fo display before the MAIN category, 'hide' to ignore main cat
  280.      * @param string string fo display after the MAIN category, 'hide' to ignore main cat
  281.      * @param string string fo display before OTHER categories, 'hide' to ignore other cats
  282.      * @param string string fo display after OTHER categories, 'hide' to ignore other cats
  283.      * @param string string fo display before EXTERNAL categories, 'hide' to ignore external cats
  284.      * @param string string fo display after EXTERNAL categories, 'hide' to ignore external cats
  285.      * @param string separator string
  286.      * @param string Output format for each cat, see {@link format_to_output()}
  287.      */
  288.     function categories(
  289.         $link_title '#',
  290.         $before_main='<strong>'$after_main='</strong>',
  291.         $before_other=''$after_other='',
  292.         $before_external='<em>'$after_external='</em>',
  293.         $separator ', ',
  294.         $format 'htmlbody'
  295.      )
  296.     {
  297.         global $cache_postcats;
  298.  
  299.         if$link_title == '#' )
  300.         {    /* TRANS: When the categories for a specific post are displayed, the user can click
  301.                     on these cats to browse them, this is the default href title displayed there */
  302.             $link_title T_('Browse category');
  303.         }
  304.  
  305.         cat_load_postcats_cache();
  306.         $categoryIDs $cache_postcats[$this->ID];
  307.  
  308.         $categoryNames array();
  309.         foreach$categoryIDs as $cat_ID )
  310.         {
  311.             $cat get_the_category_by_ID($cat_ID);
  312.             $cat_name format_to_output$cat["cat_name"]$format );
  313.  
  314.             if$link_title )
  315.             {    // we want to display links
  316.                 $curr_blogparams get_blogparams_by_ID$cat['cat_blog_ID');
  317.                 $cat_name '<a href="'.url_add_paramget_bloginfo('blogurl'$curr_blogparams)'cat='.$cat_ID ).'" title="'.$link_title.'">'.$cat_name.'</a>';
  318.             }
  319.  
  320.             if$cat_ID == $this->main_cat_ID )
  321.             {    // We are displaying the main cat!
  322.                 if$before_main == 'hide' )
  323.                 {    // ignore main cat !!!
  324.                     continue;
  325.                 }
  326.                 $cat_name $before_main.$cat_name.$after_main;
  327.             }
  328.             elseif$cat['cat_blog_ID'== $this->blog_ID )
  329.             // We are displaying another cat in the same blog
  330.                 if$before_other == 'hide' )
  331.                 {    // ignore main cat !!!
  332.                     continue;
  333.                 }
  334.                 $cat_name $before_other.$cat_name.$after_other;
  335.             }
  336.             else
  337.             {    // We are displaying an external cat (in another blog)
  338.                 if$before_external == 'hide' )
  339.                 {    // ignore main cat !!!
  340.                     continue;
  341.                 }
  342.                 $cat_name $before_external.$cat_name.$after_external;
  343.             }
  344.  
  345.             $categoryNames[$cat_name;
  346.         }
  347.         echo implode$separator$categoryNames );
  348.     }
  349.  
  350.  
  351.     /**
  352.      * Template function: display main category name
  353.      *
  354.      * {@internal Item::main_category(-) }}
  355.      *
  356.      * @param string Output format, see {@link format_to_output()}
  357.      */
  358.     function main_category$format 'htmlbody' )
  359.     {
  360.         echo format_to_outputget_catname$this->main_cat_ID )$format );
  361.     }
  362.  
  363.  
  364.     /**
  365.      * Check if user can see comments on this post
  366.      *
  367.      * {@internal Item::can_see_comments(-) }}
  368.      */
  369.     function can_see_comments()
  370.     {
  371.         if$this->comments == 'disabled'  )
  372.         {    // Comments are disabled on this post
  373.             return false;
  374.         }
  375.  
  376.         return true// OK, user can see comments
  377.     }
  378.  
  379.     /**
  380.      * Template function: Check if user can leave comment on this post or display error
  381.      *
  382.      * {@internal Item::can_comment(-) }}
  383.      *
  384.      * @param string string to display before any error message
  385.      * @param string string to display after any error message
  386.      * @param string error message for non published posts, '#' for default
  387.      * @param string error message for closed comments posts, '#' for default
  388.      * @return boolean true if user can post
  389.      */
  390.     function can_comment(
  391.                         $before_error '<p><em>',
  392.                         $after_error '</em></p>',
  393.                         $non_published_msg '#',
  394.                         $closed_msg '#'
  395.                         )
  396.     {
  397.         if$this->comments == 'disabled'  )
  398.         {    // Comments are disabled on this post
  399.             return false;
  400.         }
  401.  
  402.         if$this->comments == 'closed'  )
  403.         {    // Comments are closed on this post
  404.             if$closed_msg == '#' )
  405.                 $closed_msg T_'Comments are closed for this post.' );
  406.  
  407.             echo $before_error;
  408.             echo $closed_msg;
  409.             echo $after_error;
  410.  
  411.             return false;
  412.         }
  413.  
  414.         if( ($this->status == 'draft'|| ($this->status == 'deprecated' ) )
  415.         {    // Post is not published
  416.             if$non_published_msg == '#' )
  417.                 $non_published_msg T_'This post is not published. You cannot leave comments.' );
  418.  
  419.             echo $before_error;
  420.             echo $non_published_msg;
  421.             echo $after_error;
  422.  
  423.             return false;
  424.         }
  425.  
  426.         return true// OK, user can comment!
  427.     }
  428.  
  429.  
  430.     /**
  431.      * Template function: display content of item
  432.      *
  433.      * WARNING: parameter order is different from deprecated the_content(...)
  434.      *
  435.      * {@internal Item::content(-) }}
  436.      *
  437.      * @todo Param order and cleanup
  438.      * @param mixed page number to display specific page, # for url parameter
  439.      * @param mixed true to display 'more' text, false not to display, # for url parameter
  440.      * @param string text to display as the more link
  441.      * @param string text to display as the more anchor (once the more link has been clicked)
  442.      * @param string string to display before more link/anchor
  443.      * @param string string to display after more link/anchor
  444.      * @param string Output format, see {@link format_to_output()}
  445.      * @param integer max number of words
  446.      * @param boolean true if you don't want to repeat teaser after more link was pressed
  447.      * @param string filename to use to display more
  448.      */
  449.     function content(
  450.         $disppage '#',
  451.         $dispmore '#',
  452.         $more_link_text '#',
  453.         $more_anchor '#',
  454.         $before_more '#',
  455.         $after_more '#',
  456.         $format 'htmlbody',
  457.         $cut 0,
  458.         $stripteaser false,
  459.         $more_file ''
  460.         )
  461.     {
  462.         global $Renderer;
  463.         // echo $format,'-',$cut,'-',$dispmore,'-',$disppage;
  464.  
  465.         if$more_link_text == '#' )
  466.         {    // TRANS: this is the default text for the extended post "more" link
  467.             $more_link_text '=> '.T_('Read more!');
  468.         }
  469.  
  470.         if$more_anchor == '#' )
  471.         {    // TRANS: this is the default text displayed once the more link has been activated
  472.             $more_anchor '['.T_('More:').']';
  473.         }
  474.  
  475.         if$before_more == '#' )
  476.             $before_more '<p class="bMore">';
  477.  
  478.         if$after_more == '#' )
  479.             $after_more '</p>';
  480.  
  481.         if$dispmore === '#' )
  482.         // We want to display more if requested by user:
  483.             global $more;
  484.             $dispmore $more;
  485.         }
  486.  
  487.         $content $this->content;
  488.         $numpages 1;
  489.  
  490.         ifpreg_match('/<!--nextpage-->/'$content ) )
  491.         {    // This is a multipage post
  492.             $content str_replace("\n<!--nextpage-->\n"'<!--nextpage-->'$content);
  493.             $content str_replace("\n<!--nextpage-->"'<!--nextpage-->'$content);
  494.             $content str_replace("<!--nextpage-->\n"'<!--nextpage-->'$content);
  495.             $pages explode('<!--nextpage-->'$content);
  496.             $numpages count($pages);
  497.             if$disppage === '#' )
  498.             // We want to display the page requested by the user:
  499.                 global $page;
  500.                 $disppage $page;
  501.             }
  502.             if$disppage $numpages )
  503.                 $disppage $numpages;
  504.             $content $pages[$disppage-1];
  505.             if($disppage 1$dispmore=1;
  506.         }
  507.  
  508.         $content_parts explode('<!--more-->'$content);
  509.  
  510.         ifcount($content_parts)>)
  511.         {    // This is an extended post (has a more section):
  512.             if$dispmore )
  513.             {    // Viewer has already asked for more
  514.                 if$stripteaser || preg_match('/<!--noteaser-->/'$content ) )
  515.                 {    // We want to strip the teaser:
  516.                     $output '';
  517.                 }
  518.                 else
  519.                 // We keep the teaser:
  520.                     $output $content_parts[0];
  521.                     if!empty($more_anchor) ) $output .= $before_more;
  522.                     $output .= '<a id="more'.$this->ID.'" name="more'.$this->ID.'"></a>'.$more_anchor;
  523.                     if!empty($more_anchor) ) $output .= $after_more;
  524.                 }
  525.                 ifcount($content_parts)
  526.                 // we have additional <!--more--> tags somewhere
  527.                     array_shift($content_parts);
  528.                     $output .= implode(''$content_parts);
  529.                 }
  530.                 else $output .= $content_parts[1];
  531.             }
  532.             else
  533.             // We are offering to read more
  534.                 $output $content_parts[0];
  535.                 $output .= $before_more .
  536.                                         '<a href="'.$this->gen_permalink'pid'$more_file ).'#more'.$this->ID.'">'.
  537.                                         $more_link_text.'</a>' .
  538.                                         $after_more;
  539.             }
  540.         }
  541.         else
  542.         // Regular post
  543.             $output $content_parts[0];
  544.         }
  545.  
  546.         // Apply rendering
  547.         $post_renderers $Renderer->validate_list$this->renderers );
  548.         $output $Renderer->render$output$post_renderers$format );
  549.  
  550.         // Character conversions
  551.         $output format_to_output$output$format );
  552.  
  553.         if( ($format == 'xml'&& $cut )
  554.         {    // Let's cut this down...
  555.             $blah explode(' '$output);
  556.             if (count($blah$cut)
  557.             {
  558.                 for ($i=0$i<$cut$i++)
  559.                 {
  560.                     $excerpt .= $blah[$i].' ';
  561.                 }
  562.                 $output $excerpt '...';
  563.             }
  564.         }
  565.  
  566.         echo $output;
  567.     }
  568.  
  569.  
  570.     /**
  571.      * Template function: display issue date (datetime) of Item
  572.      *
  573.      * {@internal Item::issue_date(-) }}
  574.      *
  575.      * @param string date/time format: leave empty to use locale default date format
  576.      * @param boolean true if you want GMT
  577.      */
  578.     function issue_date$format ''$useGM false )
  579.     {
  580.         ifempty($format) )
  581.             echo mysql2datelocale_datefmt()$this->issue_date$useGM);
  582.         else
  583.             echo mysql2date$format$this->issue_date$useGM);
  584.     }
  585.  
  586.     /**
  587.      * Template function: display issue time (datetime) of Item
  588.      *
  589.      * {@internal Item::issue_time(-) }}
  590.      *
  591.      * @param string date/time format: leave empty to use locale default time format
  592.      * @param boolean true if you want GMT
  593.      */
  594.     function issue_time$format ''$useGM false )
  595.     {
  596.         ifempty($format) )
  597.             echo mysql2datelocale_timefmt()$this->issue_date$useGM );
  598.         else
  599.             echo mysql2date$format$this->issue_date$useGM );
  600.     }
  601.  
  602.  
  603.     /**
  604.      * Template function: display locale for item
  605.      *
  606.      * {@internal Item::lang(-) }}
  607.      */
  608.     function lang()
  609.     {
  610.         $this->disp'locale''raw' );
  611.     }
  612.  
  613.     /**
  614.      * Template function: display locale for item
  615.      *
  616.      * {@internal Item::locale(-) }}
  617.      */
  618.     function locale()
  619.     {
  620.         $this->disp'locale''raw' );
  621.     }
  622.  
  623.  
  624.  
  625.     /**
  626.      * Template function: display language name for item
  627.      *
  628.      * {@internal Item::language(-) }}
  629.      *
  630.      * @param string Output format, see {@link format_to_output()}
  631.      */
  632.     function language$format 'htmlbody' )
  633.     {
  634.         global $locales;
  635.         $locale $locales$this->locale ];
  636.         echo format_to_output$locale['name']$format );
  637.     }
  638.  
  639.  
  640.     /**
  641.      * Template function: display last mod date (datetime) of Item
  642.      *
  643.      * {@internal Item::mod_date(-) }}
  644.      *
  645.      * @param string date/time format: leave empty to use locale default date format
  646.      * @param boolean true if you want GMT
  647.      */
  648.     function mod_date$format ''$useGM false )
  649.     {
  650.         ifempty($format) )
  651.             echo mysql2datelocale_datefmt()$this->mod_date$useGM);
  652.         else
  653.             echo mysql2date$format$this->mod_date$useGM);
  654.     }
  655.  
  656.     /**
  657.      * Template function: display last mod time (datetime) of Item
  658.      *
  659.      * {@internal Item::mod_time(-) }}
  660.      *
  661.      * @param string date/time format: leave empty to use locale default time format
  662.      * @param boolean true if you want GMT
  663.      */
  664.     function mod_time$format ''$useGM false )
  665.     {
  666.         ifempty($format) )
  667.             echo mysql2datelocale_timefmt()$this->mod_date$useGM );
  668.         else
  669.             echo mysql2date$format$this->mod_date$useGM );
  670.     }
  671.  
  672.  
  673.     /**
  674.      * Template function: display permalink for item
  675.      *
  676.      * {@internal Item::permalink(-)}}
  677.      *
  678.      * @param string 'post', 'archive#id' or 'archive#title'
  679.      * @param string url to use
  680.      */
  681.     function permalink$mode ''$blogurl='' )
  682.     {
  683.         echo $this->gen_permalink$mode$blogurl );
  684.     }
  685.  
  686.  
  687.     /**
  688.      * Template function: Displays link to feedback page (under some conditions)
  689.      *
  690.      * {@internal Item::feedback_link(-)}}
  691.      *
  692.      * @param string Type of feedback to link to (feedbacks (all)/comments/trackbacks/pingbacks)
  693.      * @param string String to display before the link (if comments are to be displayed)
  694.      * @param string String to display after the link (if comments are to be displayed)
  695.      * @param string Link text to display when there are 0 comments
  696.      * @param string Link text to display when there is 1 comment
  697.      * @param string Link text to display when there are >1 comments (include %d for # of comments)
  698.      * @param string Link title
  699.      * @param boolean true to use a popup windows ('#' to use if comments_popup_windows() is there)
  700.      * @param boolean true to hide if no feedback ('#' for default)
  701.      * @param string 'pid' or 'title'
  702.      * @param string url to use
  703.      */
  704.     function feedback_link$type 'feedbacks'$before ''$after '',
  705.                                                     $zero='#'$one='#'$more='#'$title='#',
  706.                                                     $use_popup '#',    $hideifnone '#'$mode ''$blogurl='' )
  707.     {
  708.         global $b2commentsjavascript$BlogCache;
  709.  
  710.         switch$type )
  711.         {
  712.             case 'feedbacks':
  713.                 if$hideifnone == '#' $hideifnone false;
  714.                 if$title == '#' $title T_('Display feedback / Leave a comment');
  715.                 if$zero == '#' $zero T_('Send feedback');
  716.                 if$one == '#' $one T_('1 feedback');
  717.                 if$more == '#' $more T_('%d feedbacks');
  718.                 break;
  719.  
  720.             case 'comments':
  721.                 if$this->can_see_comments() )
  722.                     return false;
  723.                 if$hideifnone == '#' )
  724.                 {
  725.                     if$this->can_comment'''''''' ) )
  726.                         $hideifnone false;
  727.                     else
  728.                         $hideifnone true;
  729.                 }
  730.                 if$title == '#' $title T_('Display comments / Leave a comment');
  731.                 if$zero == '#' $zero T_('Leave a comment');
  732.                 if$one == '#' $one T_('1 comment');
  733.                 if$more == '#' $more T_('%d comments');
  734.                 break;
  735.  
  736.             case 'trackbacks':
  737.                 $current_Blog $BlogCache->get_by_ID$this->blog_ID );
  738.                 if$current_Blog->get'allowtrackbacks' ) )
  739.                 {    // Trackbacks not allowed on this blog:
  740.                     return;
  741.                 }
  742.                 if$hideifnone == '#' $hideifnone false;
  743.                 if$title == '#' $title T_('Display trackbacks / Get trackback address for this post');
  744.                 if$zero == '#' $zero T_('Trackback (0)');
  745.                 if$one == '#' $one T_('Trackback (1)');
  746.                 if$more == '#' $more T_('Trackbacks (%d)');
  747.                 break;
  748.  
  749.             case 'pingbacks':
  750.                 $current_Blog $BlogCache->get_by_ID$this->blog_ID );
  751.                 if$current_Blog->get'allowpingbacks' ) )
  752.                 {    // Pingbacks not allowed on this blog:
  753.                     return;
  754.                 }
  755.                 if$hideifnone == '#' $hideifnone true;
  756.                 if$title == '#' $title T_('Display pingbacks');
  757.                 if$zero == '#' $zero T_('Pingback (0)');
  758.                 if$one == '#' $one T_('Pingback (1)');
  759.                 if$more == '#' $more T_('Pingbacks (%d)');
  760.                 break;
  761.  
  762.             default:
  763.                 die"Unkown feedback type [$type]);
  764.         }
  765.  
  766.         if$use_popup == '#' )
  767.         {    // Use popups if javascript is included in page
  768.             $use_popup $b2commentsjavascript;
  769.         }
  770.  
  771.         $number generic_ctp_number($this->ID$type);
  772.  
  773.         if( ($number == 0&& $hideifnone )
  774.             return false;
  775.  
  776.         $url $this->gen_permalink$mode$blogurltrue );
  777.         if$use_popup )
  778.         // We need to tell b2evo to use the popup template
  779.             $url url_add_param$url'template=popup' );
  780.         }
  781.  
  782.         echo $before;
  783.  
  784.         echo '<a href="'$url;
  785.         echo '#'$type'" ';    // Position on feedback
  786.         echo 'title="'$title'"';
  787.         if$use_popup echo ' onclick="b2open(this.href); return false"';
  788.         echo '>';
  789.  
  790.         if$number == )
  791.             echo $zero;
  792.         elseif$number == )
  793.             echo $one;
  794.         elseif$number )
  795.             echo str_replace'%d'$number$more );
  796.  
  797.         echo '</a>';
  798.  
  799.         echo $after;
  800.  
  801.     }
  802.  
  803.  
  804.   /**
  805.      * Displays button for deleting the Item if user has proper rights
  806.      *
  807.      * {@internal Item::delete_link(-)}}
  808.      *
  809.      * @param string to display before link
  810.      * @param string to display after link
  811.      * @param string link text
  812.      * @param string link title
  813.      * @param string class name
  814.      * @param boolean true to make this a button instead of a link
  815.    * @param string glue between url params
  816.      */
  817.     function delete_link$before ' '$after ' '$text '#'$title '#'$class ''$button  false$glue '&amp;' )
  818.     {
  819.         global $current_User$admin_url;
  820.  
  821.          ifis_logged_in() ) return false;
  822.  
  823.         if$current_User->check_perm'blog_del_post''any'false$this->blog_ID ) )
  824.         {    // User has right to delete this post
  825.             return false;
  826.         }
  827.  
  828.         if$text == '#' $text T_('Delete');
  829.         if$title == '#' $title T_('Delete this post');
  830.  
  831.         $url $admin_url.'/edit_actions.php?action=delete'.$glue.'post='.$this->ID;
  832.  
  833.         echo $before;
  834.         if$button )
  835.         {    // Display as button
  836.             echo '<input type="button"';
  837.             echo ' value="'.$text.'" title="'.$title.'" onclick="if ( confirm(\'';
  838.             /* TRANS: Warning this is a javascript string */
  839.             echo T_('You are about to delete this post!\\n\\\'Cancel\\\' to stop, \\\'OK\\\' to delete.');
  840.             echo '\') ) { document.location.href=\''.$url.'\' }"';
  841.             if!empty$class ) ) echo ' class="'.$class.'"';
  842.             echo '/>';
  843.         }
  844.         else
  845.         {    // Display as link
  846.             echo '<a href="'.$url.'" title="'.$title.'" onclick="return confirm(\'';
  847.             /* TRANS: Warning this is a javascript string */
  848.             echo T_('You are about to delete this post!\\n\\\'Cancel\\\' to stop, \\\'OK\\\' to delete.');
  849.             echo '\')"';
  850.             if!empty$class ) ) echo ' class="'.$class.'"';
  851.             echo '>'.$text.'</a>';
  852.         }
  853.         echo $after;
  854.  
  855.         return true;
  856.     }
  857.  
  858.  
  859.     /**
  860.      * Provide link to edit a post if user has edit rights
  861.      *
  862.      * {@internal Item::edit_link(-)}}
  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.      */
  871.     function edit_link$before ' '$after ' '$text '#'$title '#'$class ''$glue '&amp;' )
  872.     {
  873.         global $current_User$admin_url;
  874.         
  875.         ifis_logged_in() ) return false;
  876.  
  877.         if$current_User->check_perm'blog_post_statuses'$this->statusfalse,
  878.                                                                             $this->blog_ID ) )
  879.         {    // User has no right to edit this post
  880.             return false;
  881.         }
  882.  
  883.         if$text == '#' $text T_('Edit');
  884.         if$title == '#' $title T_('Edit this post');
  885.  
  886.         echo $before;
  887.         echo '<a href="'.$admin_url.'/b2edit.php?action=edit'.$glue.'post='.$this->ID;
  888.         echo '" title="'.$title.'"';
  889.         if!empty$class ) ) echo ' class="'.$class.'"';
  890.         echo '>'.$text.'</a>';
  891.         echo $after;
  892.  
  893.         return true;
  894.     }
  895.  
  896.  
  897.     /**
  898.      * Provide link to publish a post if user has edit rights
  899.      *
  900.      * Note: publishing date will be updated
  901.      *
  902.      * {@internal Item::publish_link(-)}}
  903.      *
  904.      * @param string to display before link
  905.      * @param string to display after link
  906.      * @param string link text
  907.      * @param string link title
  908.      * @param string class name
  909.    * @param string glue between url params
  910.      */
  911.     function publish_link$before ' '$after ' '$text '#'$title '#'$class ''$glue '&amp;' )
  912.     {
  913.         global $current_User$admin_url;
  914.  
  915.         ifis_logged_in() ) return false;
  916.  
  917.         if( ($this->status == 'published'// Already published!
  918.             || ($current_User->check_perm'blog_post_statuses''published'false$this->blog_ID ))
  919.             || ($current_User->check_perm'edit_timestamp' ) ) )
  920.         {    // User has no right to publish this post now:
  921.             return false;
  922.         }
  923.  
  924.         if$text == '#' $text T_('Publish NOW!');
  925.         if$title == '#' $title T_('Publish now using current date and time.');
  926.  
  927.         echo $before;
  928.         echo '<a href="'.$admin_url.'/edit_actions.php?action=publish'.$glue.'post_ID='.$this->ID;
  929.         echo '" title="'.$title.'"';
  930.         if!empty$class ) ) echo ' class="'.$class.'"';
  931.         echo '>'.$text.'</a>';
  932.         echo $after;
  933.  
  934.         return true;
  935.     }
  936.  
  937.     /**
  938.      * Template function: display status of item
  939.      *
  940.      * Statuses:
  941.      * - published
  942.      * - deprecated
  943.      * - protected
  944.      * - private
  945.      * - draft
  946.      *
  947.      * {@internal Item::status(-) }}
  948.      *
  949.      * @param string Output format, see {@link format_to_output()}
  950.      */
  951.     function status$format 'htmlbody' )
  952.     {
  953.         global $post_statuses;
  954.  
  955.         if$format == 'raw' )
  956.         {
  957.             $this->disp'status''raw' );
  958.         }
  959.         else
  960.         {
  961.             echo format_to_outputT_$post_statuses[$this->status)$format );
  962.         }
  963.     }
  964.  
  965.  
  966.     /**
  967.      * Template function: display title for item and link to related URL
  968.      *
  969.      * {@internal Item::title(-) }}
  970.      *
  971.      * @param string String to display before the title if there is something to display
  972.      * @param string String to display after the title if there is something to display
  973.      * @param boolean false if you don't want to link to URL
  974.      * @param string Output format, see {@link format_to_output()}
  975.      */
  976.     function title(
  977.         $before='',                        // HTML/text to be displayed before title
  978.         $after='',                         // HTML/text to be displayed after title
  979.         $add_link true,         // Added link to this title?
  980.         $format 'htmlbody' )
  981.     {
  982.         ifempty($this->title&& $add_link )
  983.             $title $this->url;
  984.         else
  985.             $title $this->title;
  986.  
  987.         ifempty($title) )
  988.         {    // Nothing to display
  989.             return;
  990.         }
  991.  
  992.         $title format_to_output$title$format );
  993.  
  994.         if$add_link && (!empty($this->url)) )
  995.         {
  996.             $title '<a href="'.$this->url.'">'.$title.'</a>';
  997.         }
  998.  
  999.         echo $before;
  1000.         echo $title;
  1001.         echo $after;
  1002.     }
  1003.  
  1004.     /**
  1005.      * Template function: Displays trackback autodiscovery information
  1006.      *
  1007.      * {@internal Item::trackback_rdf(-) }}
  1008.      */
  1009.     function trackback_rdf()
  1010.     {
  1011.         // if (!stristr($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator')) {
  1012.         // fplanque WARNING: this isn't a very clean way to validate :/
  1013.         // fplanque added: html comments (not perfect but better way of validating!)
  1014.         echo "<!--\n";
  1015.         echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" '."\n";
  1016.         echo '  xmlns:dc="http://purl.org/dc/elements/1.1/"'."\n";
  1017.         echo '  xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">'."\n";
  1018.         echo '<rdf:Description'."\n";
  1019.         echo '  rdf:about="';
  1020.         $this->permalink'single' );
  1021.         echo '"'."\n";
  1022.         echo '  dc:identifier="';
  1023.         $this->permalink'single' );
  1024.         echo '"'."\n";
  1025.         $this->title'  dc:title="''"'."\n"false'xmlattr' );
  1026.         echo '  trackback:ping="';
  1027.         $this->trackback_url();
  1028.         echo '" />'."\n";
  1029.         echo '</rdf:RDF>';
  1030.         echo "-->\n";
  1031.         // }
  1032.     }
  1033.  
  1034.  
  1035.     /**
  1036.      * Template function: displays url to use to trackback this item
  1037.      *
  1038.      * {@internal Item::trackback_url(-) }}
  1039.      */
  1040.     function trackback_url()
  1041.     {
  1042.         global $htsrv_url$Settings;
  1043.         
  1044.         if$Settings->get('links_extrapath') )
  1045.         {
  1046.             echo "$htsrv_url/trackback.php/$this->ID";
  1047.         }
  1048.         else
  1049.         {
  1050.             echo "$htsrv_url/trackback.php?tb_id=$this->ID";
  1051.         }
  1052.     }
  1053.  
  1054.  
  1055.     /**
  1056.      * Template function: Display link to item related url
  1057.      *
  1058.      * {@internal Item::url_link(-) }}
  1059.      *
  1060.      * @param string string to display before the url (if exists)
  1061.      * @param string string to display after the url (if exists)
  1062.      * @param string Output format, see {@link format_to_output()}
  1063.      */
  1064.     function url_link$before=''$after=''$format 'htmlbody' )
  1065.     {
  1066.         if!empty$this->url ) )
  1067.         {
  1068.             echo $before;
  1069.             echo format_to_output'<a href="'.$this->url.'">'.$this->url.'</a>'$format );
  1070.             echo $after;
  1071.         }
  1072.     }
  1073.  
  1074.  
  1075.     /**
  1076.      * Template function: Display the number of words in the post
  1077.      *
  1078.      * {@internal Item::wordcount(-) }}
  1079.      */
  1080.     function wordcount()
  1081.     {
  1082.         echo $this->wordcount;
  1083.     }
  1084.  
  1085. }
  1086. ?>

Documentation generated on Tue, 20 May 2008 01:53:08 +0200 by phpDocumentor 1.4.2