Revision [6333]
This is an old revision of PageAndCategoryDivisionInACategory made by NilsLindenberg on 2005-02-25 19:23:46.
Division between Pages and categories in a Category
25/02/2005: new code which uses jws enhanced code. still needs some adjustments in details.
If you use the following code to replace your actions/category.php, Categories are listed seperate from pages, and the first ones without the "Category" in front.
here's the code:
- <?php
- /**
- * Generates a list of pages belonging to the specified or top-level category.
- *
- * If no category page is specified, the current page is assumed to be a category (unless filtered).
- *
- * Unless 'forcecat' is set to 0, only pages starting with 'Category' are considered to be Category
- * pages and if this action is not on a category page, it will list the contents of
- * CategoryCategory instead.
- *
- * Template pages (page name ending with 'Template') may contain category names; they are filtered
- * out automatically unless 'inctpl' is set to 1. One exception: pagenames that start with
- * 'Category' and end with 'Template' are considered a proper category so templates can themselves
- * be categorized.
- *
- * Note: the list view ('compact' = 1) is nice for a sidebar while the columnar view
- * ('compact' = 0) is more suited for a category page.
- *
- * Syntax:
- * {{category [forcecat="0|1"] [inctpl="0|1"] [page="categoryname"] [col="n"] [compact="0|1"] [class="class"]}}
- *
- * @package Actions
- * @subpackage SystemContent
- * @name Category
- *
- * @author {@link http://wikka.jsnx.com/JsnX JsnX}
- * @author {@link http://wikka.jsnx.com/JavaWoman JavaWoman} (rewrite with filtering and table-less columns)
- * @copyright Copyright © 2004, Jason Tourtelotte
- * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
- * @since Wikka 1.0.0
- *
- * @input integer $forcecat optional: consider only pages that start with 'Category' (1) or
- * treat any name as category (0); default: 1
- * @input integer $inctpl optional: include "template" pages (1) or not (0); default: 0.
- * @input integer $page optional: category to list members of; default: current page or CategoryCategory
- * @input integer $col optional: number of columns for table; default: 1
- * @input integer $compact optional: use table (0) or list (1); default: 0
- * @input integer $class optional: class(es) to determine styling of the output list of table
- * @output list of pages belonging to the specified or top-level category,
- * formatted as a list or a layout table
- *
- * @uses CheckMySQLVersion()
- * @uses FullCategoryTextSearch()
- * @uses FullTextSearch()
- * @uses Link()
- * @todo - version dependency FullCategoryTextSearch( / FullTextSearch should be hidden inside call - JW 2005-01-21
- * - refactor two different presentations into function call(s) so backlinks can use the same - JW 2005-01-21
- * - possible? use a single list also for columns, using CSS to visually split up into columns - JW 2005-01-19
- */
- // set defaults
- $lForceCat = TRUE; # only pages starting with 'Category' are considered category pages
- $lIncTpl = FALSE; # do not show template pages or treat a template as a category
- $lPage = $this->tag; # current page is default category
- $lCol = 1; # one column for table
- $lCompact = FALSE; # use table, not list
- $lClass = ''; # no class
- // get parameters
- {
- foreach ($vars as $param => $value)
- {
- switch ($param)
- {
- case 'forcecat':
- if (!$value) $lForceCat = FALSE;
- break;
- case 'inctpl':
- if ($value) $lIncTpl = TRUE;
- break;
- case 'page':
- if ($this->existsPage($value)) $lPage = $value;
- break;
- case 'col':
- if ($value === (string)(int)$value && (int)$value > 0) $lCol = (int)$value;
- break;
- case 'compact':
- if ($value) $lCompact = TRUE;
- break;
- case 'class':
- if ('' != $value) $lClass = $value;
- break;
- }
- }
- }
- // filter WHICH category we (may) show the content OF
- if ($lForceCat)
- {
- }
- elseif ($lPage == '/')
- {
- $lPage = 'CategoryCategory';
- }
- {
- if (!preg_match('/^Category/',$lPage)) $lPage = 'CategoryCategory'; # exception for a category that contains templates
- }
- // get the listed category pages
- if ($this->CheckMySQLVersion(4,0,1))
- {
- $results = $this->FullCategoryTextSearch($lPage);
- }
- else
- {
- $results = $this->FullTextSearch($lPage);
- }
- // filter what we show AS content of the requested category
- if ($results)
- {
- foreach ($results as $cpage)
- {
- // do not list top-level category as member
- if ('CategoryCategory' == $cpage['tag'])
- {
- continue;
- }
- // do not list requested category as member
- elseif ($cpage['tag'] == $lPage)
- {
- continue;
- }
- // unless inctpl is set, do not list template pages
- {
- // if the requested category ($lPage) is a template category, we do list its contents;
- // while a page that starts with 'Category' is not (considered) a template, so we do list that as content;
- // otherwise this must indeed be a template so we don't list it.
- {
- continue;
- }
- }
- // we have a valid result: add to the list
- if ($lCompact)
- {
- if (preg_match('/^Category/', $cpage['tag'])) $categorylist[] = $this->Link($cpage['tag'],'',preg_replace('/Category/','',$cpage['tag']));
- }
- else
- {
- }
- }
- }
- // show resulting list of categories belonging to category $lPage
- if ($categorylist)
- {
- $categorystr ='';
- // make simple list (useful for sidebar)
- if ($lCompact)
- {
- $classattr = ('' != $class) ? ' class="linklist '.$class.'"' : ' class="linklist"';
- $categorystr .= '<div'.$lClass.'>'."\n";
- $categorystr .= "<ul>\n";
- foreach ($categorylist as $val)
- {
- $categorystr .= ' <li>'.$val.'</li>';
- }
- $categorystr .= "</ul>\n</div>\n";
- }
- // make columnar overview (useful for category pages)
- else
- {
- $categorystr .= 'The following '.$categorycount.' categories belong to '.$lPage.':<br /><br />'."\n";
- // data columns
- $lines = ($categorycount % $lCol == 0) ? (int)($categorycount / $lCol) : (int)(($categorycount + $lCol) / $lCol);
- $width = (int) (100 / $lCol);
- $categorycount = 0;
- $classattr = ('' != $class) ? ' class="linkcols '.$class.'"' : ' class="linkcols"';
- $categorystr .= '<div'.$lClass.'>'."\n";
- foreach ($categorylist as $val)
- {
- if (($categorycount++ % $lines) == 0) $categorystr .= ' <div style="width: '.$width.'%; float: left;">'."\n";
- $categorystr .= ' '.$val.'<br />'."\n";
- if (($categorycount % $lines) == 0) $categorystr .= " </div>\n";
- }
- if (($categorycount % $lines) != 0) $categorystr .= " </div>\n";
- $categorystr .= '</div><br style="clear: both;">'."\n";
- }
- }
- else
- {
- $categorystr .= 'Sorry, no categories found for ' . $lPage .'.';
- }
- // show resulting list of pages belonging to category $lPage
- if ($pagelist)
- {
- $pagestr ='';
- // make simple list (useful for sidebar)
- if ($lCompact)
- {
- $classattr = ('' != $class) ? ' class="linklist '.$class.'"' : ' class="linklist"';
- $pagestr .= '<div'.$lClass.'>'."\n";
- $pagestr .= "<ul>\n";
- foreach ($pagelist as $val)
- {
- $pagestr .= ' <li>'.$val.'</li>';
- }
- $pagestr .= "</ul>\n</div>\n";
- }
- // make columnar overview (useful for category pages)
- else
- {
- $pagestr .= 'The following '.$pagecount.' pages belong to '.$lPage.':<br /><br />'."\n";
- // data columns
- $lines = ($pagecount % $lCol == 0) ? (int)($pagecount / $lCol) : (int)(($pagecount + $lCol) / $lCol);
- $width = (int) (100 / $lCol);
- $pagecount = 0;
- $classattr = ('' != $class) ? ' class="linkcols '.$class.'"' : ' class="linkcols"';
- $pagestr .= '<div'.$lClass.'>'."\n";
- foreach ($pagelist as $val)
- {
- if (($pagecount++ % $lines) == 0) $pagestr .= ' <div style="width: '.$width.'%; float: left;">'."\n";
- $pagestr .= ' '.$val.'<br />'."\n";
- if (($pagecount % $lines) == 0) $pagestr .= " </div>\n";
- }
- if (($pagecount % $lines) != 0) $pagestr .= " </div>\n";
- $pagestr .= '</div><br style="clear: both;">'."\n";
- }
- }
- else
- {
- $pagestr .= 'Sorry, no items found for ' . $lPage .'.';
- }
- echo $categorystr;
- echo '<br /><br />';
- echo $pagestr;
- ?>
CategoryDevelopment