b2evolution

Multilingual multiuser multiblog engine

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

Source for file _functions_cats.php

Documentation is available at _functions_cats.php

  1. <?php
  2. /**
  3.  * Category handling
  4.  * 
  5.  * b2evolution - {@link http://b2evolution.net/}
  6.  * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
  7.  * @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
  8.  *
  9.  * @package evocore
  10.  */
  11. if!defined('DB_USER') ) die'Please, do not access this page directly.' );
  12.  
  13. /**
  14.  * cat_create(-)
  15.  *
  16.  * Create a new category
  17.  * This funtion has to handle all needed DB dependencies!
  18.  *
  19.  * fplanque: created
  20.  */
  21. function cat_create(
  22.     $cat_name,
  23.     $cat_parent_ID,
  24.     $cat_blog_ID NULL)
  25. {
  26.     global $DB$tablecategories;
  27.  
  28.     if$cat_blog_ID == NULL )
  29.     {
  30.         ifempty($cat_parent_ID) ) die 'cat_create(-) missing parameters!' );
  31.         $parent_cat get_the_category_by_ID($cat_parent_ID);
  32.         $cat_blog_ID $parent_cat['cat_blog_ID'];
  33.     }
  34.  
  35.     $sql "INSERT INTO $tablecategories( cat_parent_ID, cat_name, cat_blog_ID)
  36.                     VALUES ( $cat_parent_ID".$DB->quote($cat_name)."$cat_blog_ID )";
  37.     if$DB->query$sql ) )
  38.         return 0;
  39.  
  40.     return $DB->insert_id;
  41. }
  42.  
  43.  
  44. /*
  45.  * cat_update(-)
  46.  *
  47.  * Update a category
  48.  * This funtion has to handle all needed DB dependencies!
  49.  *
  50.  * fplanque: created
  51.  */
  52. function cat_update(
  53.     $cat_ID,
  54.     $cat_name,
  55.     $cat_parent_ID 0,
  56.   $cat_blog_ID '' )
  57. {
  58.     global $tablecategories$DB;
  59.  
  60.     if$cat_parent_ID == $cat_parent_ID 'NULL';
  61.  
  62.     return $DB->query"UPDATE $tablecategories 
  63.                                                 SET cat_name = ".$DB->quote($cat_name).",
  64.                                                         cat_parent_ID = $cat_parent_ID ".
  65.                       (!empty($cat_blog_ID", cat_blog_ID = $cat_blog_ID'')."
  66.                                             WHERE cat_ID = $cat_ID);
  67. }
  68.  
  69.  
  70. /*
  71.  * cat_delete(-)
  72.  *
  73.  * Delete a category
  74.  * This funtion has to handle all needed DB dependencies!
  75.  *
  76.  * fplanque: created
  77.  * TODO: A LOT !!!!!
  78.  */
  79. function cat_delete$cat_ID )
  80. {
  81.     global $DB$tablecategories$tableposts$tablepostcats$query$cache_categories$cache_postcats;
  82.  
  83.     // TODO: START TRANSACTION
  84.  
  85.     // check there are no subcats
  86.     $sql "SELECT COUNT(*)
  87.                     FROM $tablecategories
  88.                     WHERE cat_parent_ID = $cat_ID";
  89.     $child_count $DB->get_var$sql );
  90.     if$child_count != return T_("Cannot delete if there are sub-categories!");
  91.  
  92.     // find parent
  93.     $sql "SELECT cat_parent_ID, cat_blog_ID
  94.                     FROM $tablecategories
  95.                     WHERE cat_ID = $cat_ID";
  96.     if($row $DB->get_row$sql )) )
  97.         return 1// Success: category already deleted!!
  98.  
  99.     $remap_cat_ID $row->cat_parent_ID;
  100.     $cat_blog_ID $row->cat_blog_ID;
  101.  
  102.     // Get the list of posts in this category
  103.     $sql "SELECT ID
  104.                     FROM $tableposts
  105.                     WHERE post_category = $cat_ID";
  106.     $IDarray $DB->get_col$sql );
  107.  
  108.     if$remap_cat_ID )
  109.     {    // No parent, find another cat in same blog
  110.         $sql "SELECT cat_ID
  111.                         FROM $tablecategories
  112.                         WHERE cat_blog_ID = $cat_blog_ID
  113.                             AND cat_ID != $cat_ID
  114.                         ORDER BY cat_ID
  115.                         LIMIT 0, 1";
  116.         $remap_cat_ID $DB->get_var$sql );
  117.         // echo "remap to: $remap_cat_ID<br />";
  118.         // May be NULL if this was the last cat (But there are no posts inside)
  119.  
  120.         if( ($remap_cat_ID == NULL&& (empty($IDarray)) )
  121.         {
  122.             return T_("Cannot delete last category if there are posts inside!");
  123.         }
  124.     }
  125.  
  126.     //  --------------- PROCEED WITH DELETING ------------
  127.  
  128.     // First delete assoc to this cat when it's an extra cat
  129.     $sql "DELETE FROM $tablepostcats
  130.                         WHERE postcat_cat_ID = $cat_ID ";
  131.     if!empty($IDarray) )
  132.     {
  133.         $sql .= " AND postcat_post_ID NOT IN (".implode','$IDarray ).") ";
  134.     }
  135.  
  136.     $DB->query$sql );
  137.  
  138.  
  139.     // Now take care of the main cats (these need to be remapped, we cannot delete them!)
  140.     if$remap_cat_ID )
  141.     {    // We are moving posts to parent or other category
  142.  
  143.         // remap the posts to new category:
  144.         $sql "UPDATE $tableposts
  145.                             SET post_category = $remap_cat_ID
  146.                             WHERE post_category = $cat_ID";
  147.         $DB->query$sql );
  148.  
  149.         // Before remapping the extracats we need to get rid of mappings that would become duplicates
  150.         // We remove every mapping to the old cat where a mapping to the new cat already exists
  151.         $sql "SELECT DISTINCT postcat_post_ID
  152.                         FROM $tablepostcats
  153.                         WHERE postcat_cat_ID = $remap_cat_ID";
  154.         $IDarray $DB->get_col$sql );
  155.  
  156.         if!empty($IDarray) )
  157.         {
  158.             $IDlist implode','$IDarray );
  159.  
  160.             $sql "DELETE FROM $tablepostcats
  161.                             WHERE postcat_cat_ID = $cat_ID
  162.                             AND postcat_post_ID IN ($IDlist)";
  163.             $DB->query$sql );
  164.         }
  165.  
  166.  
  167.         // remap the remaining extracats
  168.         $sql "UPDATE $tablepostcats
  169.                         SET postcat_cat_ID = $remap_cat_ID
  170.                         WHERE postcat_cat_ID = $cat_ID";
  171.         $DB->query$sql );
  172.     }
  173.  
  174.     // do the actual deletion of the cat
  175.     $sql "DELETE FROM $tablecategories
  176.                     WHERE cat_ID = $cat_ID";
  177.     $DB->query$sql );
  178.  
  179.     // TODO: END TRANSACTION
  180.  
  181.     // If we had a cache we'd better forget it!
  182.     // TODO: reset other caches!
  183.     unset$GLOBALS['cache_categories');
  184.     unset$GLOBALS['cache_postcats');
  185.  
  186.  
  187.     return 1// success
  188. }
  189.  
  190.  
  191.  
  192.  
  193. /**
  194.  * get_the_category_by_ID(-)
  195.  *
  196.  * Get category name+blog_id for specified cat ID
  197.  *
  198.  * fplanque: reused "R. U. Serious" optimization here
  199.  * fplanque: added blog ID stuff
  200.  * TODO: move. dis is not a template tag
  201.  *
  202.  * @param integer category ID
  203.  * @param boolean die() if category does not exist? (default: true)
  204.  *
  205.  */
  206. function get_the_category_by_ID$cat_ID$die true )
  207. {
  208.     global $cache_categories$use_cache;
  209.     if( (empty($cache_categories[$cat_ID]) ) OR (!$use_cache) )
  210.     {
  211.         cat_load_cache();
  212.     }
  213.     if!isset$cache_categories[$cat_ID) )
  214.     {
  215.         if$die )
  216.         {
  217.             diesprintfT_('Requested category %s does not exist!'),  $cat_ID ) );
  218.         }
  219.         else return false;
  220.     }
  221.     return $cache_categories[$cat_ID];
  222. }
  223.  
  224.  
  225. /*
  226.  * get_the_category(-)
  227.  *
  228.  * Get category name for current post
  229.  *
  230.  * fplanque: simplified
  231.  *
  232.  * @deprecated
  233.  */
  234. function get_the_category()
  235. {
  236.     global $postdata;
  237.     $cat get_the_category_by_ID$postdata['Category');
  238.     return $cat['cat_name'];
  239. }
  240.  
  241.  
  242.  
  243. /*
  244.  * get_catblog(-)
  245.  *
  246.  * Get blog for a given cat
  247.  * fplanque: added
  248.  */
  249. function get_catblog$cat_ID )
  250. {
  251.     $cat get_the_category_by_ID$cat_ID );
  252.     return $cat['cat_blog_ID'];
  253. }
  254.  
  255.  
  256. /*
  257.  * get_catparent(-)
  258.  *
  259.  * Get parent category for a given cat
  260.  * fplanque: added
  261.  */
  262. function get_catparent$cat_ID )
  263. {
  264.     $cat get_the_category_by_ID$cat_ID );
  265.     return $cat['cat_parent_ID'];
  266. }
  267.  
  268. /*
  269.  * get_catname(-)
  270.  *
  271.  * Get name for a given cat
  272.  * fplanque: reduced to the max
  273.  */
  274. function get_catname($cat_ID)
  275. {
  276.     $cat get_the_category_by_ID$cat_ID );
  277.     return $cat['cat_name'];
  278. }
  279.  
  280.  
  281. /*
  282.  * cat_load_cache()
  283.  *
  284.  * Load cache for category definitions.
  285.  *
  286.  * TODO: replace LEFT JOIN with UNION when switching to mySQL 4
  287.  * This will prevent empty cats from displaying "(1)" as postcount.
  288.  * TODO: get post counts out of here!
  289.  */
  290. function cat_load_cache()
  291. {
  292.     global $DB$tablecategories$tablepostcats$tableposts$cache_categories;
  293.     global $show_statuses$timestamp_min$timestamp_max;
  294.     global $cat_postcounts_loaded$blog;
  295.     global $Settings;
  296.     
  297.     if!isset($cache_categories))
  298.     {
  299.         // echo "loading CAT cache";
  300.         $sql "SELECT cat_ID, cat_parent_ID, cat_name, cat_blog_ID
  301.                         FROM $tablecategories
  302.                         ORDER BY cat_name";
  303.         $rows $DB->get_results$sqlARRAY_A );
  304.         ifcount$rows ) ) foreach$rows as $myrow )
  305.         {
  306.             $this_cat['cat_name'$myrow['cat_name'];
  307.             $this_cat['cat_blog_ID'$myrow['cat_blog_ID'];
  308.             $this_cat['cat_parent_ID'$myrow['cat_parent_ID'];
  309.             $this_cat['cat_postcount'0;                    // Will be increased later
  310.             $this_cat['cat_children'array();
  311.             $cache_categories[$myrow['cat_ID']] $this_cat;
  312.             // echo 'just cached:',$myrow['cat_ID'],':',$cache_categories[$myrow['cat_ID']]['cat_name'], ' parent:',$cache_categories[$myrow['cat_ID']]['cat_parent_ID'],'<br />';
  313.         }
  314.  
  315.         // echo 'Number of cats=', count($cache_categories);
  316.  
  317.         // Reveal children:
  318.         ifempty$cache_categories ) )
  319.         {
  320.             foreach$cache_categories as $icat_ID => $i_cat )
  321.             {
  322.                 // echo '<br>handling cat ', $icat_ID, ' ', $i_cat['cat_name'];
  323.                 $cat_parent_ID $i_cat['cat_parent_ID'];
  324.                 if$cat_parent_ID )
  325.                 {
  326.                     ifisset$cache_categories[$cat_parent_ID) )
  327.                     {    // If the parent exists!
  328.                         $cache_categories[$cat_parent_ID]['cat_children'][$icat_ID;
  329.                     }
  330.                     else
  331.                     {
  332.                         echo"Catgeory #$icat_ID is oprhan of non existant parent #$cat_parent_ID!<br />);
  333.                     }
  334.                 }
  335.             }
  336.         }
  337.  
  338.         // echo 'Number of cats=', count($cache_categories);
  339.     }
  340.     
  341.     // ------------------------------
  342.     // Add post counts:
  343.     // ------------------------------
  344.     if!isset($cat_postcounts_loaded&& $blog )
  345.     {    // Postcounts are not loaded and we have a blog for which to load the counts:
  346.  
  347.         // CONSTRUCT THE WHERE CLAUSE:
  348.  
  349.         /*
  350.          * ----------------------------------------------------
  351.          *  Restrict to the statuses we want to show:
  352.          * ----------------------------------------------------
  353.          */
  354.         $where ' WHERE '.statuses_where_clause$show_statuses );
  355.         $where_link ' AND ';
  356.  
  357.         // Restrict to timestamp limits:
  358.         if$timestamp_min == 'now' $timestamp_min time();
  359.         if!empty($timestamp_min) )
  360.         {    // Hide posts before
  361.             $date_min date('Y-m-d H:i:s'$timestamp_min ($Settings->get('time_difference'3600) );
  362.             $where .= $where_link.' post_issue_date >= \''.$date_min.'\'';
  363.             $where_link ' AND ';
  364.         }
  365.         if$timestamp_max == 'now' $timestamp_max time();
  366.         if!empty($timestamp_max) )
  367.         {    // Hide posts after
  368.             $date_max date('Y-m-d H:i:s'$timestamp_max ($Settings->get('time_difference'3600) );
  369.             $where .= $where_link.' post_issue_date <= \''.$date_max.'\'';
  370.             $where_link ' AND ';
  371.         }
  372.  
  373.         $sql "SELECT postcat_cat_ID AS cat_ID, COUNT(*) AS cat_postcount
  374.                         FROM $tablepostcats INNER JOIN $tableposts ON postcat_post_ID = ID
  375.                         $where
  376.                         GROUP BY cat_ID";
  377.         $rows $DB->get_results$sqlARRAY_A'Load postcounts' );
  378.         ifcount$rows ) ) foreach$rows as $myrow )
  379.         {
  380.             $cat_ID $myrow['cat_ID'];
  381.             if!isset($cache_categories[$cat_ID]) )
  382.                 echo '<p>*** WARNING: There are '$myrow['cat_postcount']' posts attached to inexistant category #'$cat_ID'. You must fix the database! ***</p>';
  383.             // echo 'Postcount for cat #', $cat_ID, ' is ', $myrow['cat_postcount'], '<br />';
  384.             $cache_categories[$cat_ID]['cat_postcount'$myrow['cat_postcount'];
  385.         }
  386.  
  387.         // echo 'Number of cats=', count($cache_categories);
  388.         $cat_postcounts_loaded true;
  389.     }
  390. }
  391.  
  392.  
  393. /*
  394.  * cat_load_postcats_cache(-)
  395.  *
  396.  * Load cache for category associations with current posts
  397.  *
  398.  * fplanque: created
  399.  *
  400.  * TODO: put this into main post query when mySQL 4.0 commonly available
  401.  */
  402. {
  403.     global $DB$tablepostcats$cache_postcats$postIDlist$preview;
  404.  
  405.     ifisset($cache_postcats) )
  406.     {    // already done!
  407.         return;
  408.     }
  409.  
  410.     if$preview )
  411.     {    // Preview mode
  412.         global $extracats$post_category;
  413.         param'extracats''array'array() );
  414.         if!in_array$post_category$extracats ) )
  415.             $extracats[$post_category;
  416.         $cache_postcats[0$extracats;
  417.         return;
  418.     }
  419.  
  420.     if!empty($postIDlist) )
  421.     {
  422.         $sql "SELECT postcat_post_ID, postcat_cat_ID
  423.                         FROM $tablepostcats
  424.                         WHERE postcat_post_ID IN ($postIDlist)
  425.                         ORDER BY postcat_post_ID, postcat_cat_ID";
  426.         $rows $DB->get_results$sqlARRAY_A );
  427.         ifcount$rows ) ) foreach$rows as $myrow )
  428.         {
  429.             $postcat_post_ID $myrow["postcat_post_ID"];
  430.             ifisset$cache_postcats[$postcat_post_ID) )
  431.             {
  432.                  $cache_postcats[$postcat_post_IDarray();
  433.             }
  434.             $cache_postcats[$postcat_post_ID][$myrow["postcat_cat_ID"];
  435.             // echo "just cached: post=$postcat_post_ID  cat=".$myrow["postcat_cat_ID"]."<br />";
  436.         }
  437.     }
  438. }
  439.  
  440.  
  441. /*
  442.  * postcats_get_byID(-)
  443.  *
  444.  * Get category associations with given post
  445.  *
  446.  * fplanque: created
  447.  */
  448. function postcats_get_byID$post_ID )
  449. {
  450.     global $DB$tablepostcats;
  451.  
  452.     //echo "looking up cats for post $post_ID ";
  453.  
  454.     $sql "SELECT postcat_cat_ID
  455.                     FROM $tablepostcats
  456.                     WHERE postcat_post_ID = $post_ID
  457.                     ORDER BY postcat_cat_ID";
  458.     return $DB->get_col$sql );
  459. }
  460.  
  461.  
  462. /*
  463.  * cat_children(-)
  464.  *
  465.  * Taking a recursive walk in the category park...
  466.  *
  467.  * fplanque: created
  468.  */
  469. function cat_children$ccats,     // PHP requires this stupid cloning of the cache_categories array in order to be able to perform foreach on it
  470.     $blog_ID$parent_ID,
  471.     $callback_before_first$callback_before_each$callback_after_each$callback_after_last// Callback functions
  472.     $level )    // Caller nesting level, just to keep track of how far we go :)
  473. {
  474.     // echo 'Number of cats=', count($ccats);
  475.     ifempty$ccats ) ) // this can happen if there are no cats at all!
  476.     {
  477.         $child_count 0;
  478.         foreach$ccats as $icat_ID => $i_cat )
  479.         {
  480.             if$icat_ID && (($blog_ID == 0|| ($i_cat['cat_blog_ID'== $blog_ID)) && ($i_cat['cat_parent_ID'== $parent_ID) )
  481.             // this cat is in the blog and is a child of the parent
  482.                 if$child_count++ == )
  483.                 {    // this is the first child
  484.                         $callback_before_first$parent_ID$level );
  485.                 }
  486.                 if$callback_before_each$icat_ID$level ) ) continue;
  487.                 cat_children$ccats$blog_ID$icat_ID$callback_before_first$callback_before_each,
  488.                                             $callback_after_each$callback_after_last$level+);
  489.                 $callback_after_each$icat_ID$level );
  490.             }
  491.         }
  492.         if$child_count )
  493.         {    // There have been children
  494.             $callback_after_last$parent_ID$level );
  495.         }
  496.     }
  497. }
  498.  
  499.  
  500. /*
  501.  * Does a given bog have categories?
  502.  *
  503.  * {@internal blog_has_cats(-)}}
  504.  */
  505. function blog_has_cats$blog_ID )
  506. {
  507.     global $cache_categories;
  508.  
  509.     cat_load_cache();
  510.  
  511.     ifcount($cache_categories) ) foreach$cache_categories as $icat_ID => $i_cat )
  512.     {
  513.         if$icat_ID && $i_cat['cat_blog_ID'== $blog_ID )
  514.         // this cat is in the blog
  515.             return true;
  516.         }
  517.     }
  518.  
  519.     return false;
  520. }
  521.  
  522.  
  523. /*
  524.  * Functions to be called from the template
  525.  */
  526.  
  527.  
  528.  
  529.  
  530.  
  531. /*
  532.  * cat_query(-)
  533.  *
  534.  * Query for the cats
  535.  *
  536.  */
  537. function cat_query)
  538. {
  539.     // global $cache_categories; // $cache_blogs,
  540.  
  541.     blog_load_cache();
  542.     cat_load_cache();
  543. }
  544.  
  545.  
  546. /**
  547.  * Display currently filtered categories names
  548.  *
  549.  * This tag is out of the b2 loop.
  550.  * It outputs the title of the category when you load the page with <code>?cat=</code>
  551.  * When the weblog page is loaded without ?cat=, this tag doesn't display anything.
  552.  * Generally, you could use this as a page title.
  553.  *
  554.  * fplanque: multiple category support (so it's not really 'single' anymore!)
  555.  *
  556.  * {@internal single_cat_title(-) }}
  557.  *
  558.  * @param string Prefix to be displayed if something is going to be displayed
  559.  * @param mixed Output format, see {@link format_to_output()} or false to
  560.  *                                 return value instead of displaying it
  561.  */
  562. function single_cat_title$prefix '#'$display 'htmlbody' )
  563. {
  564.     global $cat$cat_array;
  565.     if$prefix == '#' )
  566.     {
  567.         ifcount($cat_array)
  568.             $prefix ' '.T_('Categories').': ';
  569.         else $prefix ' '.T_('Category').': ';
  570.     }
  571.  
  572.     if!empty($cat_array) )
  573.     {    // We have requested specific categories...
  574.         $cat_names array();
  575.         foreach$cat_array as $cat_ID )
  576.         {
  577.             $my_cat get_the_category_by_ID($cat_ID);
  578.             $cat_names[$my_cat['cat_name'];
  579.         }
  580.         $cat_names_string implode", "$cat_names );
  581.         if!empty$cat_names_string ) )
  582.         {
  583.             ifstrstr($cat,'-') )
  584.             {
  585.                 $cat_names_string 'All but '.$cat_names_string;
  586.             }
  587.             if ($display)
  588.                 echo format_to_output$prefix.$cat_names_string$display );
  589.             else
  590.                 return $cat_names_string;
  591.         }
  592.     }
  593. }
  594.  
  595.  
  596.  
  597. /**
  598.  * the_category(-)
  599.  *
  600.  * echoes the main category name
  601.  * the name of the main category the post belongs to.
  602.  * you can as an admin add categories, and rename them if needed.
  603.  * default category is 'General', you can rename it too.
  604.  *
  605.  * @deprecated deprecated by {@link Item::main_category()}
  606.  */
  607. function the_category$format 'htmlbody' )
  608. {
  609.     $category get_the_category();
  610.     echo format_to_output($category$format);
  611. }
  612.  
  613.  
  614. /**
  615.  * the_categories(-)
  616.  *
  617.  * lists all the category names
  618.  *
  619.  * fplanque: created
  620.  * fplanque: 0.8.3: changed defaults
  621.  *
  622.  * @deprecated deprecated by {@link Item::categories()}
  623.  */
  624. function the_categories$link_title '#',                // false if you want no links
  625.     $before_main='<strong>'$after_main='</strong>'// 'hide' to ignore main cat
  626.     $before_other=''$after_other='',                                 // 'hide' to ignore other cats
  627.     $before_external='<em>'$after_external='</em>',    // 'hide' to ignore external cats (other blogs)
  628.     $separator ', ',
  629.     $format_each 'raw',
  630.     $format_list 'htmlbody'
  631.  )
  632. {
  633.     global $id$postdata$blog$blogfilename$cache_postcats$preview;
  634.  
  635.     if$link_title == '#' )
  636.     {    /* TRANS: When the categories for a specific post are displayed, the user can click
  637.                 on these cats to browse them, this is the default href title displayed there */
  638.         $link_title T_('Browse category');
  639.     }
  640.  
  641.     $main_cat_ID $postdata['Category'];
  642.     // echo "main cat ID: $main_cat_ID<br />";
  643.     $categoryIDs $cache_postcats[$id];
  644.  
  645.     if!isset($categoryIDs) )
  646.     {    // Can happen in preview mode
  647.         return;
  648.     }
  649.  
  650.     $categoryNames array();
  651.     foreach$categoryIDs as $cat_ID )
  652.     {
  653.         $cat get_the_category_by_ID($cat_ID);
  654.         $cat_name format_to_output$cat["cat_name"]$format_each );
  655.  
  656.         if$link_title && !$preview)
  657.         {    // we want to display links
  658.             $curr_blogparams get_blogparams_by_ID$cat['cat_blog_ID');
  659.             $cat_name '<a href="'.url_add_paramget_bloginfo('blogurl'$curr_blogparams)'cat='.$cat_ID ).'" title="'.$link_title.'">'.$cat_name.'</a>';
  660.         }
  661.  
  662.         if$cat_ID == $main_cat_ID )
  663.         {    // We are displaying the main cat!
  664.             if$before_main == 'hide' )
  665.             {    // ignore main cat !!!
  666.                 continue;
  667.             }
  668.             $cat_name $before_main.$cat_name.$after_main;
  669.         }
  670.         elseif$cat['cat_blog_ID'== $blog )
  671.         // We are displaying another cat in the same blog
  672.             if$before_other == 'hide' )
  673.             {    // ignore main cat !!!
  674.                 continue;
  675.             }
  676.             $cat_name $before_other.$cat_name.$after_other;
  677.         }
  678.         else
  679.         {    // We are displaying an external cat (in another blog)
  680.             if$before_external == 'hide' )
  681.             {    // ignore main cat !!!
  682.                 continue;
  683.             }
  684.             $cat_name $before_external.$cat_name.$after_external;
  685.         }
  686.  
  687.         $categoryNames[$cat_name;
  688.     }
  689.     echo format_to_outputimplode$separator$categoryNames )$format_list );
  690. }
  691.  
  692.  
  693.  
  694. /*
  695.  * the_category_ID(-)
  696.  *
  697.  * echoes the main category ID for current post
  698.  * The ID (number) of the category the post belongs to.
  699.  * This is static data that you can use, for example to associate a category to an image, or a css style.
  700.  */
  701. function the_category_ID()
  702. {
  703.     global $id,$postdata;
  704.     echo $postdata['Category'];
  705. }
  706.  
  707. /*
  708.  * the_categories_IDs(-)
  709.  *
  710.  * lists the category IDs for current post
  711.  *
  712.  * fplanque: created
  713.  */
  714. function the_categories_IDs()
  715. {
  716.     global $id$blogfilename$cache_postcats;
  717.  
  718.     $categoryIDs $cache_postcats[$id];
  719.  
  720.     if!isset($categoryIDs) )
  721.     {    // Can happen in preview mode
  722.         return;
  723.     }
  724.  
  725.     echo implode','$categoryIDs );
  726.  
  727. }
  728.  
  729.  
  730. /*
  731.  * the_category_head(-)
  732.  */
  733. function the_category_head$before=''$after='' )
  734. {
  735.     global $id$postdata$currentcat$previouscat$newday;
  736.     $currentcat $postdata['Category'];
  737.     if ($currentcat != $previouscat)
  738.     {
  739.         echo $before;
  740.         $cat get_the_category_by_ID($currentcat);    // fplanque
  741.         echo $cat['cat_name'];
  742.         echo $after;
  743.         $previouscat $currentcat;
  744.     }
  745. }
  746.  
  747.  
  748. ?>

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