Revision [16775]
This is an old revision of PageAndCategoryDivisionInACategory made by LgxFvh on 2007-05-31 10:46:50.
Division between Pages and categories in a Category
04/04/2005:version 2.0 (see below).
this version builds on the beta-version from JavaWoman (running on this wiki) and has in total the following cchanges to the official action:
- pages belong to categories if you use the following markup: [[(cat)Name]]. [[(cat)Name Alternative name for the link]] does work, too
- pages only need the category-action inside them, no more need for a name starting with "Category"
- template-pages , i.e. page-names ending with "template" are not shown, unless you force it or their name starts with "Category"
- output can be shown as a single list, or in a number of columns
- it is possible to show only (sub)"categories" or "pages" or "all" (both). In the last case, categories and pages are shown seperate and not in one list/column
Todo:
- extra css-class for [[(cat)...
- TESTING
- upgrade-script
- code redundancies into a function?
- making name for main-category customizable
- possibility to show the alternative name in the markup in the categorylist instead of the page-name??
- possibility to show the pages belonging to the subcategories, too? Which depth? Problem of recursion! What if a page belongs to a category and a subcategory?
- possible? use a single list also for columns, using CSS to visually split up into columns - JW 2005-01-19
- update the todo-list in the action ;-)
Explanations
The new search-method uses two queries instead of one: one search for subcategories (searching for the category-action) and another for pages (searching for the new link version) belonging to a category (they only load the name, since we know from the search if its a category or not).This allows any page to become a category, their names don't have to start with "Category" anymore. For this reason, i took the "forcecat" param out (if you put the action, for example, on the SandBox without "categorylinking" any page it will simply show that nothing could be found).
Comments?
Installation
Three things have to be changed:
1. addition to formatters/wakka.php
right before
// forced links
// \S : any character that is not a whitespace character
// \s : any whitespace character
// \S : any character that is not a whitespace character
// \s : any whitespace character
add the following:
//links to category pages
else if (preg_match("/^\[\[\(cat\)(\S )(\s(. ))*\]\]$/si", $thing, $matches))
{
list(, $categorylink, $text) = $matches;
if ($categorylink)
{
if (!$help) $help = $categorylink;
return $result.$wakka->Link($categorylink, "", $text);
}
else
{
return "";
}
}
else if (preg_match("/^\[\[\(cat\)(\S )(\s(. ))*\]\]$/si", $thing, $matches))
{
list(, $categorylink, $text) = $matches;
if ($categorylink)
{
if (!$help) $help = $categorylink;
return $result.$wakka->Link($categorylink, "", $text);
}
else
{
return "";
}
}
2. library/common/showarray.php
The following file has to be saved as library/common/showarray.php:
- <?php
- /**
- * Sorts a given array in a given number of columns.
- *
- * @package Library
- * @subpackage Common
- * @name ShowArray
- *
- * @author {@link http://wikka.jsnx.com/JavaWoman JavaWoman} (table-less columns)
- * @author {@link http://wikka.jsnx.com/NilsLindenberg NilsLindenberg} (function and "divison" of the array)
- * @copyright Copyright © 2004,
- * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
- * @since Wikka 1.0.0
- *
- * @input array $array necessary: the data to be shown
- * @input integer $colnumber optional: number of colums; default: 0.
- * @input string $class optional: class(es) to determine styling of the output list of table; default: none.
- * @output list of data from an array, formatted as in columns
- *
- * @todo - possible? use a single list also for columns, using CSS to visually split up into columns - JW 2005-01-19
- */
- function ShowArrayInColumns($array, $colnumber=1, $class="")
- {
- $str = "";
- {
- $width = (int) (100 / $colnumber);
- $lines = 0;
- $a = 0;
- $str .= '<div'.$class.'>'."\n";
- //how many lines with an entry in every column do we have?
- while ($entries / $colnumber > 1)
- {
- $lines ;
- $entries = $entries - $colnumber;
- }
- //prepare output
- for ($i=0;$i<$colnumber;$i )
- {
- $str .=' <div style="width: '.$width.'%; float: left;">'."\n";
- for ($j=0;$j<$lines;$j )
- {
- $str .= ' '.$array[$a].'<br />'."\n";
- $a ;
- }
- //the rest of the entries (less then the number of cols)
- if ($entries)
- {
- $str .= ' '.$array[$a].'<br />'."\n";
- $entries--;
- $a ;
- }
- $str .=" </div>\n";
- }
- $str .= '</div><br style="clear: both;">'."\n";
- return ($str);
- }
- $str .= 'The data delivered to the function ShowArrayInColumns was no array.';
- return ($str);
- }
- /**
- * Sorts a given array as a list.
- *
- * @package Library
- * @subpackage Common
- * @name ShowArray
- *
- * @author {@link http://wikka.jsnx.com/JsnX JsnX} (list)
- * @author {@link http://wikka.jsnx.com/NilsLindenberg NilsLindenberg} (function and "divison" of the array)
- * @copyright Copyright © 2004,
- * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
- * @since Wikka 1.0.0
- *
- * @input array $array necessary: the data to be shown
- * @input string $class optional: class(es) to determine styling of the output list of table; default: none.
- * @output list of data from an array, formatted as a list
- *
- */
- function ShowArrayAsList($array,$class="")
- {
- $str = "";
- {
- $str .= '<div'.$class.'>'."\n";
- $str .= "<ul>\n";
- for ($i=0;$i<$entries;$i )
- {
- $str .= ' <li>'.$array[$i].'</li>';
- }
- $str .= "</ul>\n</div>\n";
- return ($str);
- }
- $str .= "The data delivered to the function ShowArrayAsList was no array.";
- return ($str);
- }
- ?>
3. Replacement of actions/category.php
%%(php)
<?php
including the needed functions
require_once 'library/common/showarray.php'; #the two functions showing the output in a list/ in columns
set defaults
$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
$lShow = 'all'; # show pages and categories
$lOutput = ; # the final output
get parameters
if (is_array($vars))
{
foreach ($vars as $param => $value)
{
switch ($param)
{
case 'inctpl':
if ($value) $lIncTpl = TRUE;
break;
case 'page':
if ($this->existsPage($value)) $lPage = $value;
break;
case 'col':
if ($value (string)(int)$value