b2evolution

Multilingual multiuser multiblog engine

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

Source for file _functions_bposts.php

Documentation is available at _functions_bposts.php

  1. <?php
  2. /**
  3.  * Post handling functions
  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.  * Create a new post
  16.  *
  17.  * This funtion has to handle all needed DB dependencies!
  18.  *
  19.  * {@internal bpost_create(-)}}
  20.  */
  21. function bpost_create(
  22.     $author_user_ID,              // Author
  23.     $post_title,
  24.     $post_content,
  25.     $post_timestamp,              // 'Y-m-d H:i:s'
  26.     $main_cat_ID 1,             // Main cat ID
  27.     $extra_cat_IDs array(),     // Table of extra cats
  28.     $post_status 'published',
  29.     $post_locale '#',
  30.     $post_trackbacks '',
  31.     $autobr 0,                  // No AutoBR has been used by default
  32.     $pingsdone true,
  33.     $post_urltitle '',
  34.     $post_url '',
  35.     $post_comments 'open',
  36.     $post_renderers array('default') )
  37. {
  38.     global $DB$tableposts$tablepostcats$query;
  39.     global $localtimenow$default_locale;
  40.  
  41.     if$post_locale == '#' $post_locale $default_locale;
  42.  
  43.     // Handle the flags:
  44.     $post_flags array();
  45.     if$pingsdone $post_flags['pingsdone';
  46.  
  47.     // make sure main cat is in extracat list and there are no duplicates
  48.     $extra_cat_IDs[$main_cat_ID;
  49.     $extra_cat_IDs array_unique$extra_cat_IDs );
  50.  
  51.     // TODO: START TRANSACTION
  52.  
  53.     // validate url title
  54.     $post_urltitle urltitle_validate$post_urltitle$post_title);
  55.  
  56.     // echo 'INSERTING NEW POST ';
  57.  
  58.     $query "INSERT INTO $tableposts( post_author, post_title, post_urltitle, post_content,
  59.                                                         post_issue_date, post_mod_date, post_category,  post_status, post_locale,
  60.                                                         post_url, post_autobr, post_flags, post_wordcount,
  61.                                                         post_comments, post_renderers )
  62.                         VALUES( $author_user_ID, '".$DB->escape($post_title)."',
  63.                                         '".$DB->escape($post_urltitle)."',
  64.                                         '".$DB->escape($post_content)."',
  65.                                         '".$DB->escape($post_timestamp)."',
  66.                                         '".date('Y-m-d H:i:s',$localtimenow)."',
  67.                                         $main_cat_ID,
  68.                                         '".$DB->escape($post_status)."',
  69.                                         '".$DB->escape($post_locale)."',
  70.                                         '".$DB->escape($post_url)."',
  71.                                         '".(integer)$autobr."',
  72.                                         '".$DB->escape(implode(',',$post_flags))."',
  73.                                         ".bpost_count_words($post_content).",
  74.                                         '".$DB->escape($post_comments)."',
  75.                                         '".$DB->escape(implode('.',$post_renderers))."' )";
  76.     if$DB->query$query'Insert New Post' ) ) return 0;
  77.     $post_ID $DB->insert_id;
  78.     // echo "post ID:".$post_ID;
  79.  
  80.     // insert new extracats
  81.     $query "INSERT INTO $tablepostcats( postcat_post_ID, postcat_cat_ID ) VALUES ";
  82.     foreach$extra_cat_IDs as $extra_cat_ID )
  83.     {
  84.         // echo "extracat: $extra_cat_ID <br />";
  85.         $query .= "$post_ID$extra_cat_ID ),";
  86.     }
  87.     $query substr$query0strlen$query );
  88.     if$DB->query$query'Associate new post with extra categories' ) ) return 0;
  89.  
  90.     // TODO: END TRANSACTION
  91.  
  92.     return $post_ID;
  93. }
  94.  
  95.  
  96. /**
  97.  * Update a post
  98.  *
  99.  * This funtion has to handle all needed DB dependencies!
  100.  *
  101.  * {@internal bpost_update(-)}}
  102.  */
  103. function bpost_update(
  104.     $post_ID,
  105.     $post_title,
  106.     $post_content,
  107.     $post_timestamp '',         // 'Y-m-d H:i:s'
  108.     $main_cat_ID 1,             // Main cat ID
  109.     $extra_cat_IDs array(),     // Table of extra cats
  110.     $post_status 'published',
  111.     $post_locale '#',
  112.     $post_trackbacks '',
  113.     $autobr 0,                  // No AutoBR has been used by default
  114.     $pingsdone true,
  115.     $post_urltitle '',
  116.     $post_url '',
  117.     $post_comments 'open',
  118.     $post_renderers array() )
  119. {
  120.     global $DB$tableposts$tablepostcats$query$querycount;
  121.     global $localtimenow$default_locale;
  122.  
  123.     // Handle the flags:
  124.     $post_flags array();
  125.     if$pingsdone $post_flags['pingsdone';
  126.  
  127.     // make sure main cat is in extracat list and there are no duplicates
  128.     $extra_cat_IDs[$main_cat_ID;
  129.     $extra_cat_IDs array_unique$extra_cat_IDs );
  130.  
  131.     // TODO: START TRANSACTION
  132.  
  133.     // validate url title
  134.     $post_urltitle urltitle_validate$post_urltitle$post_title$post_ID );
  135.  
  136.     $query "UPDATE $tableposts
  137.                         SET post_title = '".$DB->escape($post_title)."',
  138.                                 post_urltitle = '".$DB->escape($post_urltitle)."',
  139.                                 post_url = '".$DB->escape($post_url)."',
  140.                                 post_content = '".$DB->escape($post_content)."',
  141.                                 post_mod_date = '".date('Y-m-d H:i:s',$localtimenow)."',
  142.                                 post_category = $main_cat_ID,
  143.                                 post_status = '".$DB->escape($post_status)."',
  144.                                 post_autobr = $autobr,
  145.                                 post_flags = '".$DB->escape(implode(',',$post_flags))."',
  146.                                 post_wordcount = ".bpost_count_words($post_content).",
  147.                                 post_comments = '".$DB->escape($post_comments)."',
  148.                                 post_renderers = '".$DB->escape(implode('.',$post_renderers))."'";
  149.                                 if$post_locale != '#' )
  150.                                 // only update if it was changed
  151.                                     $query .= ",
  152.                                 post_locale = '".$DB->escape($post_locale)."'";
  153.                                 }
  154.  
  155.     if!empty($post_timestamp) )    $query .= ", post_issue_date = '$post_timestamp";
  156.     $query .= "WHERE ID = $post_ID";
  157.     if$DB->query$query ) ) return 0;
  158.  
  159.     // delete previous extracats
  160.     $query "DELETE FROM $tablepostcats WHERE postcat_post_ID = $post_ID";
  161.     if$DB->query$query ) ) return 0;
  162.  
  163.     // insert new extracats
  164.     $query "INSERT INTO $tablepostcats( postcat_post_ID, postcat_cat_ID ) VALUES ";
  165.     foreach$extra_cat_IDs as $extra_cat_ID )
  166.     {
  167.         //echo "extracat: $extracat_ID <br />";
  168.         $query .= "$post_ID$extra_cat_ID ),";
  169.     }
  170.     $query substr$query0strlen$query );
  171.     if$DB->query$query ) ) return 0;
  172.  
  173.     // TODO: END TRANSACTION
  174.  
  175.     return 1;    // success
  176. }
  177.  
  178. /**
  179.  * Update a post's status
  180.  *
  181.  * This funtion has to handle all needed DB dependencies!
  182.  *
  183.  * {@internal bpost_update_status(-)}}
  184.  */
  185.     $post_ID,
  186.     $post_status 'published',
  187.     $pingsdone true,
  188.     $post_timestamp '' )
  189. {
  190.     global $DB$tableposts$tablepostcats;
  191.     global $localtimenow;
  192.     global $query;
  193.  
  194.     // Handle the flags:
  195.     $post_flags array();
  196.     if$pingsdone $post_flags['pingsdone';
  197.  
  198.     $query "UPDATE $tableposts SET ";
  199.     if!empty($post_timestamp) )    $query .= "post_issue_date = '$post_timestamp', ";
  200.     $query .= "post_mod_date = '".date('Y-m-d H:i:s',$localtimenow)."', ";
  201.     $query .= "post_status = '$post_status', ";
  202.     $query .= "post_flags = '".implode(',',$post_flags)."' ";
  203.     $query .= "WHERE ID = $post_ID";
  204.  
  205.     return $DB->query$query );
  206. }
  207.  
  208.  
  209. /**
  210.  * Delete a post
  211.  *
  212.  * This funtion has to handle all needed DB dependencies!
  213.  *
  214.  * {@internal bpost_delete(-)}}
  215.  */
  216. function bpost_delete$post_ID )
  217. {
  218.     global $DB$tableposts$tablepostcats$tablecomments;
  219.  
  220.     // TODO: START TRANSACTION
  221.  
  222.  
  223.     // delete extracats
  224.     $query "DELETE FROM $tablepostcats WHERE postcat_post_ID = $post_ID";
  225.     if$DB->query$query === false return 0;
  226.  
  227.     // delete comments
  228.     $query "DELETE FROM $tablecomments WHERE comment_post_ID = $post_ID";
  229.     if$DB->query$query === false return 0;
  230.  
  231.     // delete post
  232.     $query "DELETE FROM $tableposts WHERE ID = $post_ID";
  233.     if$DB->query$query === false return 0;
  234.  
  235.  
  236.     // TODO: END TRANSACTION
  237.  
  238.     return 1;    // success
  239.  
  240. }
  241.  
  242.  
  243.  
  244. /**
  245.  * {@internal get_lastpostdate(-)}}
  246.  */
  247. function get_lastpostdate(
  248.         $blog 1,
  249.         $show_statuses array(),
  250.         $cat '',
  251.         $catsel array(),
  252.         $timestamp_min '',                                // Do not show posts before this timestamp
  253.         $timestamp_max 'now'                            // Do not show posts after this timestamp
  254.  )
  255. {
  256.     global $localtimenow$postdata;
  257.  
  258.     // echo 'getting last post date';
  259.     $LastPostList new ItemList$blog$show_statuses''''''$cat$catsel'''DESC''issue_date'1'',''''''''''''1'posts'$timestamp_min$timestamp_max );
  260.  
  261.     if$LastItem $LastPostList->get_item() )
  262.     {
  263.         // echo 'we have a last item';
  264.         $last_postdata $LastPostList->get_postdata();    // will set $postdata;
  265.         $lastpostdate $postdata['Date'];
  266.     }
  267.     else
  268.     {
  269.         // echo 'we have no last item';
  270.         $lastpostdate date("Y-m-d H:i:s"$localtimenow);
  271.     }
  272.     // echo $lastpostdate;
  273.     return($lastpostdate);
  274. }
  275.  
  276.  
  277. /**
  278.  * Validate URL title
  279.  *
  280.  * Using title as a source if url title is empty
  281.  *
  282.  * {@internal urltitle_validate(-) }}
  283.  *
  284.  * @param string url title to validate
  285.  * @param string real title to use as a source if $urltitle is empty
  286.  * @param integer ID of post
  287.  * @return string validated url title
  288.  */
  289. function urltitle_validate$urltitle$title$post_ID 0$query_only false )
  290. {
  291.     global $DB$tableposts;
  292.  
  293.     $urltitle trim$urltitle );
  294.  
  295.     ifempty$urltitle )  ) $urltitle $title;
  296.     ifempty$urltitle )  ) $urltitle 'title';
  297.  
  298.     // echo 'staring with: ', $urltitle, '<br />';
  299.  
  300.     // Replace HTML entities
  301.     $urltitle htmlentities$urltitleENT_NOQUOTES );
  302.     // Keep only one char in emtities!
  303.     $urltitle preg_replace'/&(.).+?;/''$1'$urltitle );
  304.     // Remove non acceptable chars
  305.     $urltitle preg_replace'/[^A-Za-z0-9]+/''_'$urltitle );
  306.     $urltitle preg_replace'/^_+/'''$urltitle );
  307.     $urltitle preg_replace'/_+$/'''$urltitle );
  308.     // Uppercase the first character of each word in a string
  309.     $urltitle strtolower$urltitle );
  310.  
  311.     preg_match'/^(.*?)(_[0-9]+)?$/'$urltitle$matches );
  312.  
  313.     $urlbase substr$matches[1]040 );
  314.     $urltitle $urlbase;
  315.     ifisset$matches[2) )
  316.     {
  317.         $urltitle $urlbase $matches[2];
  318.     }
  319.  
  320.  
  321.     // Find all occurrences of urltitle+number in the DB:
  322.     $sql "SELECT post_urltitle
  323.                     FROM $tableposts
  324.                     WHERE post_urltitle REGEXP '^".$urlbase."(_[0-9]+)?$'
  325.                       AND ID <> $post_ID";
  326.     $rows $DB->get_results$sqlARRAY_A );
  327.     $exact_match false;
  328.     $highest_number 0;
  329.     ifcount$rows ) ) foreach$rows as $row )
  330.     {
  331.         $existing_urltitle $row['post_urltitle'];
  332.         // echo "existing = $existing_urltitle <br />";
  333.         if$existing_urltitle == $urltitle )
  334.         // We have an exact match, we'll have to change the number.
  335.             $exact_match true;
  336.         }
  337.         ifpreg_match'/_([0-9]+)$/'$existing_urltitle$matches ) )
  338.         {    // This one has a number, we extract it:
  339.             $existing_number = (integer) $matches[1];
  340.             if$existing_number $highest_number )
  341.             // This is th enew high
  342.                 $highest_number $existing_number;
  343.             }
  344.         }
  345.     }
  346.     // echo "highest existing number = $highest_number <br />";
  347.  
  348.     if$exact_match && !$query_only )
  349.     {    // We got an exact match, we need to change the number:
  350.         $urltitle $urlbase.'_'.($highest_number 1);
  351.     }
  352.  
  353.     // echo "using = $urltitle <br />";
  354.  
  355.     return $urltitle;
  356. }
  357.  
  358. /*
  359.  * get_postdata(-)
  360.  *
  361.  * if global $postdata was not set it will be
  362.  */
  363. function get_postdata($postid)
  364. {
  365.     global $DB$postdata$tableusers$tablecategories$tableposts$tablecomments$show_statuses;
  366.  
  367.     if!empty($postdata&& $postdata['ID'== $postid )
  368.     {    // We are asking for postdata of current post in memory! (we're in the b2 loop)
  369.         // Already in memory! This will be the case when generating permalink at display
  370.         // (but not when sending trackbacks!)
  371.         // echo "*** Accessing post data in memory! ***<br />\n";
  372.         return($postdata);
  373.     }
  374.  
  375.     // echo "*** Loading post data! ***<br>\n";
  376.     // We have to load the post
  377.     $sql "SELECT ID, post_author, post_issue_date, post_mod_date, post_status, post_locale, post_content, post_title, post_url, post_category, post_autobr, post_flags, post_wordcount, post_comments, cat_blog_ID FROM $tableposts INNER JOIN $tablecategories ON post_category = cat_ID WHERE ID = $postid";
  378.     // Restrict to the statuses we want to show:
  379.     // echo $show_statuses;
  380.     // fplanque: 2004-04-04: this should not be needed here. (and is indeed problematic when we want to
  381.     // get a post before even knowning which blog it belongs to. We can think of putting a security check
  382.     // back into the Item class)
  383.     // $sql .= ' AND '.statuses_where_clause( $show_statuses );
  384.  
  385.     // echo $sql;
  386.  
  387.     if$myrow $DB->get_row$sql ) )
  388.     {
  389.         $mypostdata array (
  390.             'ID' => $myrow->ID,
  391.             'Author_ID' => $myrow->post_author,
  392.             'Date' => $myrow->post_issue_date,
  393.             'Status' => $myrow->post_status,
  394.             'Locale' =>  $myrow->post_locale,
  395.             'Content' => $myrow->post_content,
  396.             'Title' => $myrow->post_title,
  397.             'Url' => $myrow->post_url,
  398.             'Category' => $myrow->post_category,
  399.             'AutoBR' => $myrow->post_autobr,
  400.             'Flags' => explode','$myrow->post_flags ),
  401.             'Wordcount' => $myrow->post_wordcount,
  402.             'comments' => $myrow->post_comments,
  403.             'Blog' => $myrow->cat_blog_ID,
  404.             );
  405.  
  406.         // Caching is particularly useful when displaying a single post and you call single_post_title several times
  407.         if!isset$postdata ) ) $postdata $mypostdata;    // Will save time, next time :)
  408.  
  409.         return($mypostdata);
  410.     }
  411.  
  412.     return false;
  413. }
  414.  
  415.  
  416. /**
  417.  * Get an Item by its ID
  418.  *
  419.  * {@internal Item_get_by_ID(-) }}
  420.  *
  421.  * @todo cacheing?
  422.  *
  423.  * @param integer post ID
  424.  * @return Item requested object or false
  425.  */
  426. function Item_get_by_ID$post_ID )
  427. {
  428.     global $DB$postdata$tableusers$tablecategories$tableposts$tablecomments,  $show_statuses;
  429.  
  430.     // We have to load the post
  431.     $sql "SELECT ID, post_author, post_issue_date, post_mod_date, post_status, post_locale,
  432.                                     post_content, post_title, post_urltitle, post_url, post_category,
  433.                                     post_autobr, post_flags, post_wordcount, post_comments,
  434.                                     post_renderers, cat_blog_ID
  435.                     FROM $tableposts INNER JOIN $tablecategories ON post_category = cat_ID
  436.                     WHERE ID = $post_ID";
  437.     // Restrict to the statuses we want to show:
  438.     // echo $show_statuses;
  439.     // fplanque: 2004-04-04: this should not be needed here. (and is indeed problematic when we want to
  440.     // get a post before even knowning which blog it belongs to. We can think of putting a security check
  441.     // back into the Item class)
  442.     // $sql .= ' AND '.statuses_where_clause( $show_statuses );
  443.  
  444.     // echo $sql;
  445.  
  446.     if($row $DB->get_row$sql )) )
  447.         return false;
  448.  
  449.     return new Item$row );    // COPY !
  450. }
  451.  
  452. /**
  453.  * Get an Item by its urltitle
  454.  *
  455.  * {@internal Item_get_by_title(-) }}
  456.  *
  457.  * @todo cacheing?
  458.  *
  459.  * @param string url title of Item
  460.  * @return Item requested object or false
  461.  */
  462. function Item_get_by_title$urltitle )
  463. {
  464.     global $DB$postdata$tableusers$tablecategories$tableposts$tablecomments,  $show_statuses;
  465.  
  466.     // We have to load the post
  467.     $sql "SELECT ID, post_author, post_issue_date, post_mod_date, post_status, post_locale,
  468.                                     post_content, post_title, post_urltitle, post_url, post_category,
  469.                                     post_autobr, post_flags, post_wordcount, post_comments,
  470.                                     post_renderers, cat_blog_ID
  471.                     FROM $tableposts INNER JOIN $tablecategories ON post_category = cat_ID
  472.                     WHERE post_urltitle = ".$DB->quote($urltitle);
  473.  
  474.     if($row $DB->get_row$sql )) )
  475.         return false;
  476.  
  477.     return new Item$row );    // COPY !
  478. }
  479.  
  480.  
  481. /**
  482.  * get_the_title(-)
  483.  *
  484.  * @deprecated
  485.  */
  486. function get_the_title()
  487. {
  488.     global $id,$postdata;
  489.     $output trim$postdata['Title');
  490.     return($output);
  491. }
  492.  
  493.  
  494.  
  495.  
  496. /*
  497.  * TEMPLATE FUNCTIONS
  498.  */
  499.  
  500.  
  501. /*****
  502.  * Post tags
  503.  *****/
  504.  
  505.  
  506.  
  507. /*
  508.  * the_ID(-)
  509.  *
  510.  *
  511.  * @deprecated deprecated by {@link DataObject::ID()}
  512.  *
  513.  */
  514. function the_ID()
  515. {
  516.     global $id;
  517.     echo $id;
  518. }
  519.  
  520. /*
  521.  * the_status(-)
  522.  *
  523.  * Display post status
  524.  *
  525.  * @deprecated deprecated by {@link Item::status()}
  526.  */
  527. function the_status$raw true )
  528. {
  529.     global $post_statuses$postdata;
  530.     $status $postdata['Status'];
  531.     if$raw )
  532.         echo $status;
  533.     else
  534.         echo T_($post_statuses[$status]);
  535. }
  536.  
  537.  
  538. /*
  539.  * the_lang(-)
  540.  *
  541.  * Display post language code
  542.  *
  543.  * @deprecated deprecated by {@link Item::lang()}
  544.  */
  545. function the_lang()
  546. {
  547.     global $postdata;
  548.     echo $postdata['Locale'];
  549. }
  550.  
  551. /*
  552.  * the_language(-)
  553.  *
  554.  * Display post language name
  555.  *
  556.  * @deprecated deprecated by {@link Item::language()}
  557.  */
  558. function the_language()
  559. {
  560.     global $postdata$languages;
  561.     $post_lang $postdata['Locale'];
  562.     echo $languages$post_lang ];
  563. }
  564.  
  565. /*
  566.  * the_wordcount(-)
  567.  * Display the number of words in the post
  568.  *
  569.  *
  570.  * @deprecated deprecated by {@link Item::wordcount()}
  571.  */
  572. function the_wordcount()
  573. {
  574.     global $postdata;
  575.     echo $postdata['Wordcount'];
  576. }
  577.  
  578. /*
  579.  * the_title(-)
  580.  *
  581.  * Display post title
  582.  * 03.10.10 - Updated function to allow for silent operations
  583.  *
  584.  * @deprecated deprecated by {@link Item::title()}
  585.  */
  586. function the_title(
  587.     $before='',                        // HTML/text to be displayed before title
  588.     $after='',                         // HTML/text to be displayed after title
  589.     $add_link true,         // Added link to this title?
  590.     $format 'htmlbody',    // Format to use (example: "htmlbody" or "xml")
  591.     $disp true )                // Display output?
  592. {
  593.     global $postdata;
  594.  
  595.     $title get_the_title();
  596.     $url trim($postdata['Url']);
  597.  
  598.     ifempty($title&& $add_link )
  599.     {
  600.         $title $url;
  601.     }
  602.  
  603.     ifempty($title) )
  604.         return;
  605.  
  606.     if$add_link && (!empty($url)) )
  607.     {
  608.         $title $before.'<a href="'.$url.'">'.$title.'</a>'.$after;
  609.     }
  610.     else
  611.     {
  612.         $title $before.$title.$after;
  613.     }
  614.  
  615.     //    ADDED: 03.10.08 by Travis S. :Support for silent operation
  616.     $return_str format_to_output$title$format );
  617.     if$disp == true )
  618.         echo $return_str;
  619.     else
  620.         return $return_str;
  621. }
  622.  
  623.  
  624. /*
  625.  * the_link(-)
  626.  *
  627.  * Display post link
  628.  *
  629.  * @deprecated deprecated by {@link Item::url_link()}
  630.  */
  631. function the_link$before=''$after=''$format 'htmlbody' )
  632. {
  633.     global $postdata;
  634.  
  635.     $url trim($postdata['Url']);
  636.  
  637.     ifempty($url) )
  638.     {
  639.         return false;
  640.     }
  641.  
  642.     $link $before.'<a href="'.$url.'">'.$url.'</a>'.$after;
  643.  
  644.     echo format_to_output$link$format );
  645. }
  646.  
  647.  
  648.  
  649. /**
  650.  * {@internal single_post_title(-)}}
  651.  *
  652.  * @todo use cache
  653.  */
  654. function single_post_title$prefix '#'$display 'htmlhead' )
  655. {
  656.     global $p$title$preview;
  657.  
  658.     $disp_title '';
  659.  
  660.     if$prefix == '#' $prefix ' '.T_('Post details').': ';
  661.  
  662.     if$preview )
  663.     {
  664.         if$prefix == '#' $prefix ' ';
  665.         $disp_title T_('PREVIEW');
  666.     }
  667.     elseifintval($p) )
  668.     {
  669.         if$Item Item_get_by_ID$p ) )        // TODO: use cache
  670.         {
  671.             $disp_title $Item->get('title');
  672.         }
  673.     }
  674.     elseif!empty$title ) )
  675.     {
  676.         if$Item Item_get_by_title$title ) ) // TODO: use cache
  677.         {
  678.             $disp_title $Item->get('title');
  679.         }
  680.     }
  681.  
  682.     if!empty$disp_title ) )
  683.     {
  684.         if ($display)
  685.         {
  686.             echo $prefixformat_to_output($disp_title$display );
  687.         }
  688.         else
  689.         {
  690.             return $disp_title;
  691.         }
  692.     }
  693. }
  694.  
  695. /**
  696.  * {@internal preview_title(-)}}
  697.  */
  698. function preview_title$string '#'$before ' '$after ''  )
  699. {
  700.     global $preview;
  701.  
  702.     if$preview )
  703.     {
  704.         echo $before;
  705.         echo ($string == '#'T_('PREVIEW'$string;
  706.         echo $after;
  707.     }
  708. }
  709.  
  710.  
  711. /**
  712.  * the_content(-)
  713.  *
  714.  * @deprecated deprecated by {@link Item::content()}
  715.  */
  716. function the_content(
  717.     $more_link_text='#',
  718.     $stripteaser=0,
  719.     $more_file='',
  720.     $more_anchor='#',
  721.     $before_more_link '#',
  722.     $after_more_link '#',
  723.     $format 'htmlbody',
  724.     $cut 0,
  725.     $dispmore '#',     // 1 to display 'more' text, # for url parameter
  726.     $disppage '#' // page number to display specific page, # for url parameter
  727. {
  728.     global $id$postdata$pages$multipage$numpages;
  729.     global $preview;
  730.  
  731.     // echo $format,'-',$cut,'-',$dispmore,'-',$disppage;
  732.  
  733.     if$more_link_text == '#' )
  734.     {    // TRANS: this is the default text for the extended post "more" link
  735.         $more_link_text '=> '.T_('Read more!');
  736.     }
  737.  
  738.     if$more_anchor == '#' )
  739.     {    // TRANS: this is the default text displayed once the more link has been activated
  740.         $more_anchor '['.T_('More:').']';
  741.     }
  742.  
  743.     if$before_more_link == '#' )
  744.         $before_more_link '<p class="bMore">';
  745.  
  746.     if$after_more_link == '#' )
  747.         $after_more_link '</p>';
  748.  
  749.     if$dispmore === '#' )
  750.     {
  751.         global $more;
  752.         $dispmore $more;
  753.     }
  754.  
  755.     if$disppage === '#' )
  756.     {
  757.         global $page;
  758.         $disppage $page;
  759.     }
  760.     if$disppage $numpages $disppage $numpages;
  761.     // echo 'Using: dmore=', $dispmore, ' dpage=', $disppage;
  762.  
  763.     $output '';
  764.     if ($more_file != '')
  765.         $file $more_file;
  766.     else
  767.         $file get_bloginfo('blogurl');
  768.  
  769.     $content $pages[$disppage-1];
  770.     $content explode('<!--more-->'$content);
  771.  
  772.     if ((preg_match('/<!--noteaser-->/'$postdata['Content']&& ((!$multipage|| ($disppage==1))))
  773.         $stripteaser=1;
  774.     $teaser=$content[0];
  775.     if (($dispmore&& ($stripteaser))
  776.     {    // We don't want to repeat the teaser:
  777.         $teaser='';
  778.     }
  779.     $output .= $teaser;
  780.  
  781.     if (count($content)>1)
  782.     {
  783.         if ($dispmore)
  784.         {    // Viewer has already asked for more
  785.             if!empty($more_anchor) ) $output .= $before_more_link;
  786.             $output .= '<a id="more'.$id.'" name="more'.$id.'"></a>'.$more_anchor;
  787.             if!empty($more_anchor) ) $output .= $after_more_link;
  788.             $output .= $content[1];
  789.         }
  790.         else
  791.         // We are offering to read more
  792.             $more_link gen_permalink$file$id'id''single');
  793.             $output .= $before_more_link.'<a href="'.$more_link.'#more'.$id.'">'.$more_link_text.'</a>'.$after_more_link;
  794.         }
  795.     }
  796.     if ($preview)
  797.     // preview fix for javascript bug with foreign languages
  798.         $output =  preg_replace('/\%u([0-9A-F]{4,4})/e',  "'&#'.base_convert('\\1',16,10).';'"$output);
  799.     }
  800.  
  801.     $content format_to_output$output$format );
  802.  
  803.     if( ($format == 'xml'&& $cut )
  804.     {    // Let's cut this down...
  805.         $blah explode(' '$content);
  806.         if (count($blah$cut)
  807.         {
  808.             for ($i=0$i<$cut$i++)
  809.             {
  810.                 $excerpt .= $blah[$i].' ';
  811.             }
  812.             $content $excerpt '...';
  813.         }
  814.     }
  815.     echo $content;
  816. }
  817.  
  818.  
  819.  
  820.  
  821. /*
  822.  * link_pages(-)
  823.  * vegarg: small bug when using $more_file fixed
  824.  */
  825. function link_pages$before='#'$after='#'$next_or_number='number'$nextpagelink='#'$previouspagelink='#'$pagelink='%d'$more_file='')
  826. {
  827.     global $id$page$numpages$multipage$more;
  828.  
  829.     if$before == '#' $before '<p>'.T_('Pages:').' ';
  830.     if$after == '#' $after '</p>';
  831.     if$nextpagelink == '#' $nextpagelink T_('Next page');
  832.     if$previouspagelink == '#' $previouspagelink T_('Previous page');
  833.  
  834.     if ($more_file != '')
  835.         $file $more_file;
  836.     else
  837.         $file get_bloginfo('blogurl');
  838.  
  839.     if$multipage // && ($more)) {
  840.         echo $before;
  841.         if$next_or_number == 'number' )
  842.         {
  843.             for ($i 1$i ($numpages+1)$i $i 1)
  844.             {
  845.                 $j str_replace('%d'$i$pagelink);
  846.                 echo ' ';
  847.                 if( ($i != $page|| ( (!$more&& ($page==1) ))
  848.                     echo '<a href="'.url_add_param($file'p='.$id.'&amp;more=1&amp;page='.$i).'">';
  849.                 echo $j;
  850.                 if( ($i != $page|| ( (!$more&& ($page==1) ))
  851.                     echo '</a>';
  852.             }
  853.         }
  854.         else
  855.         {
  856.             $i $page 1;
  857.             if$i )
  858.                 echo ' <a href="'.url_add_param($file'p='.$id.'&amp;page='.$i).'">'.$previouspagelink.'</a>';
  859.  
  860.             $i $page+1;
  861.  
  862.             if$i <= $numpages )
  863.                 echo ' <a href="'.url_add_param($file'p='.$id.'&amp;page='.$i).'">'.$nextpagelink.'</a>';
  864.         }
  865.         echo $after;
  866.     }
  867. }
  868.  
  869.  
  870. /*
  871.  * previous_post(-)
  872.  *
  873.  *
  874.  */
  875. function previous_post($format='%'$previous='#'$title='yes'$in_same_cat='no'$limitprev=1$excluded_categories='')
  876. {
  877.     if$previous == '#' $previous T_('Previous post'': ';
  878.  
  879.     global $DB$tableposts$postdata;
  880.     global $p$posts$s;
  881.  
  882.     if(($p|| ($posts==1))
  883.     {
  884.  
  885.         $current_post_date $postdata['Date'];
  886.         $current_category $postdata['Category'];
  887.  
  888.         $sqlcat '';
  889.         if ($in_same_cat != 'no'{
  890.             $sqlcat " AND post_category='$current_category";
  891.         }
  892.  
  893.         $sql_exclude_cats '';
  894.         if (!empty($excluded_categories)) {
  895.             $blah explode('and'$excluded_categories);
  896.             foreach($blah as $category{
  897.                 $category intval($category);
  898.                 $sql_exclude_cats .= " AND post_category != $category";
  899.             }
  900.         }
  901.  
  902.         $limitprev--;
  903.         $sql "SELECT ID,post_title
  904.                         FROM $tableposts
  905.                         WHERE post_issue_date < '$current_post_date'
  906.                             $sqlcat
  907.                             $sql_exclude_cats
  908.                         ORDER BY post_issue_date DESC
  909.                         LIMIT $limitprev, 1";
  910.  
  911.         if$p_info $DB->get_row$sql ) )
  912.         {
  913.             $p_title $p_info->post_title;
  914.             $p_id $p_info->ID;
  915.             $string '<a href="'.url_add_paramget_bloginfo('blogurl')'p='.$p_id.'&amp;more=1&amp;c=1').'">'.$previous;
  916.             if (!($title!='yes')) {
  917.                 $string .= $p_title;
  918.             }
  919.             $string .= '</a>';
  920.             $format str_replace('%',$string,$format);
  921.             echo $format;
  922.         }
  923.     }
  924. }
  925.  
  926.  
  927. /*
  928.  * next_post(-)
  929.  *
  930.  *
  931.  */
  932. function next_post($format='%'$next='#'$title='yes'$in_same_cat='no'$limitnext=1$excluded_categories='')
  933. {
  934.     if$next == '#' $next T_('Next post'': ';
  935.  
  936.     global $tableposts$p$posts$postdata$localtimenow$DB;
  937.     if(($p|| ($posts==1))
  938.     {
  939.  
  940.         $current_post_date $postdata['Date'];
  941.         $current_category $postdata['Category'];
  942.         $sqlcat '';
  943.         if ($in_same_cat != 'no')
  944.         {
  945.             $sqlcat " AND post_category='$current_category";
  946.         }
  947.  
  948.         $sql_exclude_cats '';
  949.         if (!empty($excluded_categories)) {
  950.             $blah explode('and'$excluded_categories);
  951.             foreach($blah as $category{
  952.                 $category intval($category);
  953.                 $sql_exclude_cats .= " AND post_category != $category";
  954.             }
  955.         }
  956.  
  957.         $now date('Y-m-d H:i:s'$localtimenow );
  958.  
  959.         $limitnext--;
  960.         $sql "SELECT ID, post_title
  961.                         FROM $tableposts
  962.                         WHERE post_issue_date > '$current_post_date'
  963.                             AND post_issue_date < '$now'
  964.                             $sqlcat
  965.                             $sql_exclude_cats
  966.                         ORDER BY post_issue_date ASC
  967.                         LIMIT $limitnext, 1";
  968.  
  969.         if$p_info $DB->get_row$sql ) )
  970.         {
  971.             $p_title $p_info->post_title;
  972.             $p_id $p_info->ID;
  973.             $string '<a href="'.url_add_paramget_bloginfo('blogurl')'p='.$p_id.'&amp;more=1&amp;c=1' ).'">'.$next;
  974.             if ($title=='yes'{
  975.                 $string .= $p_title;
  976.             }
  977.             $string .= '</a>';
  978.             $format str_replace('%',$string,$format);
  979.             echo $format;
  980.         }
  981.     }
  982. }
  983.  
  984.  
  985. /*
  986.  * next_posts(-)
  987.  */
  988. function next_posts($max_page 0$page='' )
  989. {
  990.     global $p$paged$Settings$edited_Blog$generating_static;
  991.  
  992.     if (empty($p&& ($Settings->get('what_to_show'== 'paged'))
  993.     {
  994.         if (!$paged$paged 1;
  995.         $nextpage intval($paged1;
  996.         if (!$max_page || $max_page >= $nextpage)
  997.         {
  998.             if!isset($generating_static|| $generating_static == false )
  999.             {    // We are not generating a static page here:
  1000.                 echo regenerate_url'paged''paged='.$nextpage$page );
  1001.             }
  1002.             elseifisset($edited_Blog) )
  1003.             {    // We are generating a static page
  1004.                 echo url_add_param$edited_Blog->get('dynurl')'paged='.$nextpage  );
  1005.             }
  1006.             // else...should not happen
  1007.         }
  1008.     }
  1009. }
  1010.  
  1011.  
  1012.  
  1013. /*
  1014.  * previous_posts(-)
  1015.  */
  1016. function previous_posts$page='' )
  1017. {
  1018.     global $p$paged$Settings$edited_Blog$generating_static;
  1019.  
  1020.     if (empty($p&& ($Settings->get('what_to_show'== 'paged'))
  1021.     {
  1022.         $nextpage intval($paged1;
  1023.         if ($nextpage 1$nextpage 1;
  1024.         if!isset($generating_static|| $generating_static == false )
  1025.         {    // We are not generating a static page here:
  1026.             echo regenerate_url'paged''paged='.$nextpage$page );
  1027.         }
  1028.         elseifisset($edited_Blog) )
  1029.         {    // We are generating a static page
  1030.             echo url_add_param$edited_Blog->get('dynurl')'paged='.$nextpage  );
  1031.         }
  1032.         // else...should not happen
  1033.     }
  1034. }
  1035.  
  1036.  
  1037. /**
  1038.  * next_posts_link(-)
  1039.  *
  1040.  *
  1041.  */
  1042. function next_posts_link($label='#'$max_page=0$page='')
  1043. {
  1044.     global $p$paged$result$request$Settings;
  1045.  
  1046.     if$label == '#' $label T_('Next Page').' >>';
  1047.  
  1048.     if ($Settings->get('what_to_show'== 'paged')
  1049.     {
  1050.         global $MainList;
  1051.         if (!$max_page)    $max_page $MainList->get_max_paged();
  1052.         if (!$paged$paged 1;
  1053.         $nextpage intval($paged1;
  1054.         if (empty($p&& (empty($paged|| $nextpage <= $max_page))
  1055.         {
  1056.             echo '<a href="';
  1057.             echo next_posts($max_page$page);
  1058.             echo '">'htmlspecialchars($label.'</a>';
  1059.         }
  1060.     }
  1061. }
  1062.  
  1063.  
  1064.  
  1065. /**
  1066.  * previous_posts_link(-)
  1067.  *
  1068.  *
  1069.  */
  1070. function previous_posts_link($label='#'$page='')
  1071. {
  1072.     global $Settings;
  1073.  
  1074.     if$label == '#' $label '<< '.T_('Previous Page');
  1075.  
  1076.     global $p$paged;
  1077.     if (empty($p)  && ($paged 1&& ($Settings->get('what_to_show'== 'paged'))
  1078.     {
  1079.         echo '<a href="';
  1080.         echo previous_posts$page );
  1081.         echo '">'.  htmlspecialchars($label.'</a>';
  1082.     }
  1083. }
  1084.  
  1085.  
  1086.  
  1087. /**
  1088.  * Links to previous/next page
  1089.  *
  1090.  * posts_nav_link(-)
  1091.  */
  1092. function posts_nav_link($sep=' :: '$prelabel='#'$nxtlabel='#'$page='')
  1093. {
  1094.     global $request$p;
  1095.     global $Settings;
  1096.  
  1097.     if!empty$request && empty($p&& ($Settings->get('what_to_show'== 'paged'))
  1098.     {
  1099.         global $MainList;
  1100.         $max_paged $MainList->get_max_paged();
  1101.         if$max_paged )
  1102.         {
  1103.             previous_posts_link$prelabel$page );
  1104.             echo htmlspecialchars($sep);
  1105.             next_posts_link$nxtlabel$max_paged$page );
  1106.         }
  1107.     }
  1108. }
  1109.  
  1110. /*****
  1111.  * // Post tags
  1112.  *****/
  1113.  
  1114.  
  1115.  
  1116.  
  1117. /*****
  1118.  * Date/Time tags
  1119.  *****/
  1120.  
  1121. /**
  1122.  * the_date(-)
  1123.  *
  1124.  * @deprecated deprecated by {@link ItemList::date_if_changed()}
  1125.  */
  1126. function the_date($d=''$before=''$after=''$echo 1)
  1127. {
  1128.     global $id$postdata$day$previousday$newday;
  1129.     $the_date '';
  1130.     if ($day != $previousday)
  1131.     {
  1132.         $the_date .= $before;
  1133.         if ($d==''{
  1134.             $the_date .= mysql2datelocale_datefmt()$postdata['Date']);
  1135.         else {
  1136.             $the_date .= mysql2date$d$postdata['Date']);
  1137.         }
  1138.         $the_date .= $after;
  1139.         $previousday $day;
  1140.     }
  1141.     if ($echo{
  1142.         echo $the_date;
  1143.     else {
  1144.         return $the_date;
  1145.     }
  1146. }
  1147.  
  1148. /**
  1149.  * the_time(-)
  1150.  *
  1151.  *
  1152.  * @deprecated deprecated by {@link Item::time()} / {@link Item::date()}
  1153.  *
  1154.  */
  1155. function the_time($d=''$echo 1$useGM 0)
  1156. {
  1157.     global $id,$postdata;
  1158.     if ($d=='')
  1159.     {
  1160.         $the_time mysql2datelocale_timefmt()$postdata['Date']$useGM);
  1161.     else {
  1162.         $the_time mysql2date$d$postdata['Date']$useGM);
  1163.     }
  1164.  
  1165.     if ($echo)
  1166.     {
  1167.         echo $the_time;
  1168.     else {
  1169.         return $the_time;
  1170.     }
  1171. }
  1172.  
  1173. /*
  1174.  * the_weekday(-)
  1175.  *
  1176.  *
  1177.  */
  1178. function the_weekday()
  1179. {
  1180.     global $weekday,$id,$postdata;
  1181.     $the_weekday T_($weekday[mysql2date('w'$postdata['Date'])]);
  1182.     echo $the_weekday;
  1183. }
  1184.  
  1185. /*
  1186.  * the_weekday_date(-)
  1187.  *
  1188.  *
  1189.  */
  1190. function the_weekday_date($before='',$after='')
  1191. {
  1192.     global $weekday,$id,$postdata,$day,$previousweekday;
  1193.     $the_weekday_date '';
  1194.     if ($day != $previousweekday{
  1195.         $the_weekday_date .= $before;
  1196.         $the_weekday_date .= T_($weekday[mysql2date('w'$postdata['Date'])]);
  1197.         $the_weekday_date .= $after;
  1198.         $previousweekday $day;
  1199.     }
  1200.  
  1201.     echo $the_weekday_date;
  1202. }
  1203.  
  1204. /*****
  1205.  * // Date/Time tags
  1206.  *****/
  1207.  
  1208. /*****
  1209.  * Author tags
  1210.  *****/
  1211.  
  1212. /*
  1213.  * the_author(-)
  1214.  *
  1215.  * @deprecated deprecated by {@link User::prefered_name()}
  1216.  */
  1217. function the_author$format 'htmlbody' )
  1218. {
  1219.     global $authordata;
  1220.     switch$authordata['user_idmode')
  1221.     {
  1222.         case 'nickname':
  1223.             $author $authordata['user_nickname'];
  1224.             break;
  1225.  
  1226.         case 'login':
  1227.             $author $authordata['user_login'];
  1228.             break;
  1229.  
  1230.         case 'firstname':
  1231.             $author $authordata['user_firstname'];
  1232.             break;
  1233.  
  1234.         case 'lastname':
  1235.             $author $authordata['user_lastname'];
  1236.             break;
  1237.  
  1238.         case 'namefl':
  1239.             $author $authordata['user_firstname'].' '.$authordata['user_lastname'];
  1240.             break;
  1241.  
  1242.         case 'namelf':
  1243.             $author $authordata['user_lastname'].' '.$authordata['user_firstname'];
  1244.             break;
  1245.  
  1246.         default:
  1247.             $author $authordata['user_nickname'];
  1248.     }
  1249.  
  1250.     echo format_to_output$author$format );
  1251. }
  1252.  
  1253.  
  1254. /*
  1255.  * the_author_level(-)
  1256.  *
  1257.  * @deprecated deprecated by {@link User::level()}
  1258.  */
  1259. function the_author_level()
  1260. {
  1261.     global $authordata;
  1262.     echo $authordata['user_level'];
  1263. }
  1264.  
  1265. /*
  1266.  * the_author_login(-)
  1267.  *
  1268.  * @deprecated deprecated by {@link User::level()}
  1269.  */
  1270. function the_author_login$format 'htmlbody' )
  1271. {
  1272.     global $authordata;
  1273.     echo format_to_output$authordata['user_login']$format );
  1274. }
  1275.  
  1276. /*
  1277.  * the_author_firstname(-)
  1278.  */
  1279. function the_author_firstname$format 'htmlbody' )
  1280. {
  1281.     global $authordata;
  1282.     echo format_to_output$authordata['user_firstname']$format );
  1283. }
  1284.  
  1285. /*
  1286.  * the_author_lastname(-)
  1287.  */
  1288. function the_author_lastname$format 'htmlbody' )
  1289. {
  1290.     global $authordata;
  1291.     echo format_to_output$authordata['user_lastname']$format );
  1292. }
  1293.  
  1294. /*
  1295.  * the_author_nickname(-)
  1296.  */
  1297. function the_author_nickname$format 'htmlbody' )
  1298. {
  1299.     global $authordata;
  1300.     echo format_to_output$authordata['user_nickname']$format );
  1301. }
  1302.  
  1303. /*
  1304.  * the_author_ID(-)
  1305.  *
  1306.  * @deprecated deprecated by {@link DataObject::ID()}
  1307.  */
  1308. function the_author_ID()
  1309. {
  1310.     global $authordata;
  1311.     echo $authordata['ID'];
  1312. }
  1313.  
  1314. /*
  1315.  * the_author_email(-)
  1316.  */
  1317. function the_author_email$format 'raw' )
  1318. {
  1319.     global $authordata;
  1320.     echo format_to_outputantispambot($authordata['user_email'])$format );
  1321. }
  1322.  
  1323. /*
  1324.  * the_author_url(-)
  1325.  *
  1326.  * @deprecated deprecated by {@link User::url()}
  1327.  */
  1328. function the_author_url$format 'raw' )
  1329. {
  1330.     global $authordata;
  1331.     echo format_to_output$authordata['user_url']$format );
  1332. }
  1333.  
  1334. /*
  1335.  * the_author_icq(-)
  1336.  */
  1337. function the_author_icq$format 'raw' )
  1338. {
  1339.     global $authordata;
  1340.     echo format_to_output$authordata['user_icq']$format );
  1341. }
  1342.  
  1343. /*
  1344.  * the_author_aim(-)
  1345.  */
  1346. function the_author_aim$format 'raw' )
  1347. {
  1348.     global $authordata;
  1349.     echo format_to_outputstr_replace(' ''+'$authordata['user_aim'])$format );
  1350. }
  1351.  
  1352. /*
  1353.  * the_author_yim(-)
  1354.  */
  1355. function the_author_yim$format 'raw' )
  1356. {
  1357.     global $authordata;
  1358.     echo format_to_output$authordata['user_yim']$format );
  1359. }
  1360.  
  1361. /*
  1362.  * the_author_msn(-)
  1363.  */
  1364. function the_author_msn$format 'raw' )
  1365. {
  1366.     global $authordata;
  1367.     echo format_to_output$authordata['user_msn']$format );
  1368. }
  1369.  
  1370. /*
  1371.  * the_author_posts(-)
  1372.  */
  1373. function the_author_posts()
  1374. {
  1375.     global $postdata;
  1376.     $posts get_usernumposts($postdata['Author_ID']);
  1377.     echo $posts;
  1378. }
  1379.  
  1380. /*****
  1381.  * // Author tags
  1382.  *****/
  1383.  
  1384.  
  1385.  
  1386.  
  1387.  
  1388. /***** Permalink tags *****/
  1389.  
  1390. /**
  1391.  * permalink_anchor(-)
  1392.  *
  1393.  * generate anchor for permalinks to refer to
  1394.  *
  1395.  * TODO: archives modes in clean mode
  1396.  *
  1397.  * @deprecated deprecated by {@link Item::anchor()}
  1398.  */
  1399. function permalink_anchor$mode 'id' )
  1400. {
  1401.     global $id$postdata;
  1402.     switch(strtolower($mode))
  1403.     {
  1404.         case 'title':
  1405.             $title preg_replace('/[^a-zA-Z0-9_\.-]/''_'$postdata['Title']);
  1406.             echo '<a name="'.$title.'"></a>';
  1407.             break;
  1408.         case 'id':
  1409.         default:
  1410.             echo '<a name="'.$id.'"></a>';
  1411.             break;
  1412.     }
  1413. }
  1414.  
  1415. /**
  1416.  * gen_permalink(-)
  1417.  *
  1418.  * generate permalink
  1419.  *
  1420.  * TODO: archives modes in clean mode
  1421.  *
  1422.  * @deprecated deprecated by {@link Item::gen_permalink(-)}
  1423.  */
  1424. function gen_permalink(
  1425.     $file,                  // base URL of the blog
  1426.     $id,                    // post ID to be linked to
  1427.     $use_anchor_mode '',  // Default to id
  1428.     $use_destination '',  // Default to config
  1429.     $use_more NULL,              // DEPRECATED
  1430.     $use_comments NULL,   // DEPRECATED
  1431.     $use_trackback NULL,  // DEPRECATED
  1432.     $use_pingback NULL )  // DEPRECATED
  1433. {
  1434.     global $cacheweekly;
  1435.     global $Settings;
  1436.  
  1437.     // We're gonna need access to more postdata in several cases:
  1438.     $postdata get_postdata$id );
  1439.  
  1440.     // Defaults:
  1441.     if (empty($use_anchor_mode)) $use_anchor_mode 'id';
  1442.     if (empty($use_destination))
  1443.             $use_destination strstr$Settings->get('permalink_type')'archive' !== false )
  1444.                     ? 'archive' 'single';
  1445.     if ($use_destination=='archive'$use_destination $Settings->get('archive_mode');
  1446.  
  1447.     // Generate anchor
  1448.     switch(strtolower($use_anchor_mode))
  1449.     {
  1450.         case 'title':
  1451.             $title preg_replace('/[^a-zA-Z0-9_\.-]/''_'$postdata['Title']);
  1452.             $anchor $title;
  1453.             break;
  1454.  
  1455.         case 'id':
  1456.         default:
  1457.             $anchor $id;
  1458.             break;
  1459.     }
  1460.  
  1461.     if$Settings->get('links_extrapath') )
  1462.     {    // We reference by Query: Dirty but explicit permalinks
  1463.  
  1464.         switch($use_destination)
  1465.         {
  1466.             case 'monthly':
  1467.                 $permalink url_add_param$file'm='.substr($postdata['Date'],0,4).substr($postdata['Date'],5,2).'#'.$anchor );
  1468.                 break;
  1469.             case 'weekly':
  1470.                 if((!isset($cacheweekly)) || (empty($cacheweekly[$postdata['Date']])))
  1471.                 {
  1472.                     $cacheweekly[$post_date$DB->get_var"SELECT WEEK('".$post_date."')" );
  1473.                 }
  1474.                 $permalink url_add_param$file'm='.substr($postdata['Date'],0,4).'&amp;w='.$cacheweekly[$postdata['Date']].'#'.$anchor );
  1475.                 break;
  1476.             case 'daily':
  1477.                 $permalink url_add_param$file'm='.substr($postdata['Date'],0,4).substr($postdata['Date'],5,2).substr($postdata['Date'],8,2).'#'.$anchor );
  1478.                 break;
  1479.             case 'postbypost':
  1480.             case 'single':
  1481.             default:
  1482.                 $permalink url_add_param$file'p='.$id.'&amp;more=1&amp;c=1&amp;tb=1&amp;pb=1' );
  1483.                 break;
  1484.         }
  1485.     }
  1486.     else
  1487.     {    // We reference by path (CLEAN permalinks!)
  1488.         switch($use_destination)
  1489.         {
  1490.             case 'monthly':
  1491.                 $permalink $file.mysql2date("/Y/m/"$postdata['Date']).'#'.$anchor;
  1492.                 break;
  1493.             case 'weekly':
  1494.                 if((!isset($cacheweekly)) || (empty($cacheweekly[$postdata['Date']])))
  1495.                 {
  1496.                     $cacheweekly[$post_date$DB->get_var"SELECT WEEK('".$post_date."')" );
  1497.                 }
  1498.                 $permalink $file.mysql2date("/Y/m/"$postdata['Date']).'w'.$cacheweekly[$postdata['Date']].'/#'.$anchor;
  1499.                 break;
  1500.             case 'daily':
  1501.                 $permalink $file.mysql2date("/Y/m/d/"$postdata['Date']).'#'.$anchor;
  1502.                 break;
  1503.             case 'postbypost':
  1504.             case 'single':
  1505.             default:
  1506.                 // This is THE CLEANEST available: RECOMMENDED!
  1507.                 $permalink $file.mysql2date("/Y/m/d/"$postdata['Date']).'p'.$id;
  1508.                 break;
  1509.         }
  1510.     }
  1511.  
  1512.     return $permalink;
  1513. }
  1514.  
  1515.  
  1516. /**
  1517.  * permalink_link(-)
  1518.  *
  1519.  * Display permalink
  1520.  *
  1521.  * @deprecated deprecated by {@link (Item::permalink())} but still used by _archives.php
  1522.  */
  1523. function permalink_link($file=''$mode 'id'$post_ID '' )        // id or title
  1524. {
  1525.     global $id;
  1526.     ifempty($post_ID) ) $post_ID $id;
  1527.     ifempty($file) ) $file get_bloginfo('blogurl');
  1528.     echo gen_permalink$file$post_ID$mode );
  1529. }
  1530.  
  1531. /**
  1532.  * permalink_single(-)
  1533.  *
  1534.  * Permalink forced to a single post
  1535.  *
  1536.  * @deprecated deprecated by {@link Item::permalink()}
  1537.  */
  1538. function permalink_single($file='')
  1539. {
  1540.     global $id;
  1541.     if (empty($file)) $file get_bloginfo('blogurl');
  1542.     echo gen_permalink$file$id'id''single' );
  1543. }
  1544.  
  1545.  
  1546. /**
  1547.  * {@internal the_permalink(-) }}
  1548.  *
  1549.  * @deprecated deprecated by {@link $Item::permalink()}
  1550.  */
  1551. function the_permalink()
  1552. {
  1553.     global $Item;
  1554.     $Item->permalink();
  1555. }
  1556.  
  1557.  
  1558. /***** // Permalink tags *****/
  1559.  
  1560.  
  1561.  
  1562. // @@@ These aren't template tags, do not edit them
  1563.  
  1564.  
  1565. /*
  1566.  * is_new_day(-)
  1567.  */
  1568. function is_new_day()
  1569. {
  1570.     global $day$previousday;
  1571.     if ($day != $previousday{
  1572.         return(1);
  1573.     else {
  1574.         return(0);
  1575.     }
  1576. }
  1577.  
  1578.  
  1579. /*
  1580.  * bpost_count_words(-)
  1581.  *
  1582.  * Returns the number of the words in a string, sans HTML
  1583.  */
  1584. function bpost_count_words($string)
  1585. {
  1586.     $string trim(strip_tags($string));
  1587.     iffunction_exists'str_word_count' ) )
  1588.     {    // PHP >= 4.3
  1589.         return str_word_count($string);
  1590.     }
  1591.  
  1592.     /* In case str_word_count() doesn't exist (to accomodate PHP < 4.3).
  1593.         (Code adapted from post by "brettNOSPAM at olwm dot NO_SPAM dot com" at
  1594.         PHP documentation page for str_word_count(). A better implementation
  1595.         probably exists.)
  1596.     */
  1597.     if($string == '')
  1598.     {
  1599.         return 0;
  1600.     }
  1601.  
  1602.     $pattern "/[^(\w|\d|\'|\"|\.|\!|\?|;|,|\\|\/|\-\-|:|\&|@)]+/";
  1603.     $string preg_replace($pattern" "$string);
  1604.     $string count(explode(" "$string));
  1605.  
  1606.     return $string;
  1607. }
  1608.  
  1609. /**
  1610.  * Construct the where clause to limit retrieved posts on their status
  1611.  *
  1612.  * {@internal statuses_where_clause(-)}}
  1613.  *
  1614.  * @param Array statuses of posts we want to get
  1615.  */
  1616. function statuses_where_clause$show_statuses '' )
  1617. {
  1618.     global $current_User$blog;
  1619.  
  1620.     ifempty($show_statuses) )
  1621.         $show_statuses array'published''protected''private' );
  1622.  
  1623.     $where ' ( ';
  1624.     $or '';
  1625.  
  1626.     if( ($key array_search'private'$show_statuses )) !== false )
  1627.     {    // Special handling for Private status:
  1628.         unset$show_statuses[$key);
  1629.         ifis_logged_in() )
  1630.         {    // We need to be logged in to have a chance to see this:
  1631.             global $user_ID;
  1632.             $where .= $or." ( post_status = 'private' AND post_author = $user_ID ) ";
  1633.             $or ' OR ';
  1634.         }
  1635.     }
  1636.  
  1637.     if$key array_search'protected'$show_statuses ) )
  1638.     {    // Special handling for Protected status:
  1639.         if( (!is_logged_in()) || (!$current_User->check_perm'blog_ismember'1false$blog )) )
  1640.         // we are not allowed to see this if we are not a member of the current blog:
  1641.             unset$show_statuses[$key);
  1642.         }
  1643.     }
  1644.  
  1645.     // Remaining statuses:
  1646.     $other_statuses '';
  1647.     $sep '';
  1648.     foreach$show_statuses as $other_status )
  1649.     {
  1650.         $other_statuses .= $sep.'\''.$other_status.'\'';
  1651.         $sep ',';
  1652.     }
  1653.     ifstrlen$other_statuses ) )
  1654.     {
  1655.         $where .= $or.'post_status IN ('$other_statuses .') ';
  1656.     }
  1657.  
  1658.     $where .= ') ';
  1659.  
  1660.     // echo $where;
  1661.     return $where;
  1662. }
  1663.  
  1664. ?>

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