Revision history for PageAndCategoryDivisionInACategory


Revision [22712]

Last edited on 2016-03-31 23:03:37 by MasinAlDujaili [fixed bug]
Additions:
ON from_tag = tag
ON from_tag = tag
Deletions:
ON to_tag = tag
ON to_tag = tag


Revision [22711]

Edited on 2016-03-31 19:57:18 by MasinAlDujaili [Update for 1.3.6]
Additions:
>>Working for 1.3.6 (latest)>>''03/31/2016:version 2.1 (see below).''
==3. Plugin this in plugins/actions/category/category.php==
* Shows the pages and subcategories belonging to a category.
*
* See WikiCategory to understand how the system works.
*
* @package Actions
* @version $Id$
*
* @input string $page optional: the category for which you want to display the pages and categories. Default: current page
* @input integer $compact optional: 0 produces a columnar layout with a layout table; 1 produces output in the form of an unordered list. Default: 0
* @input integer $col optional: number of columns (for compact=0). Default: 1
* @output A html table with pages
* @uses Wakka::GetPageTag();
* @uses Wakka::ListPages()
* @uses Wakka::LoadPagesLinkingTo()
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
* @filesource
require_once 'libs/showarray.php'; #the two functions showing the output in a list/ in columns
# 'col' option
$col = 1;
if(isset($vars['col']))
$col = $this->htmlspecialchars_ent($vars['col']);
# 'compact' option
$compact = 0;
if(isset($vars['compact']))
$compact = $this->htmlspecialchars_ent($vars['compact']);
# 'class' option
$class = 0;
if(isset($vars['class']))
$class = $this->htmlspecialchars_ent($vars['class']);
# 'sort' option
$sort = 'ASC';
if(isset($vars['sort']))
$val_sort = strtoupper($this->htmlspecialchars_ent($vars['sort']));
if(in_array($val_sort, ['ASC','DESC'])) $sort = $val_sort;
# 'inctpl' option
$inctpl = FALSE;
if(isset($vars['inctpl']))
$inctpl = TRUE;
# 'show' option
$show = 'all';
if(isset($vars['all']))
$val_show = $this->htmlspecialchars_ent($vars['class']);
if(in_array($val_show, ['all','pages','categories'])) $show = $val_show;
# 'page' option
if(isset($vars['page']))
$page = $this->htmlspecialchars_ent($vars['page']);
else
#232 : if page is not given, and if this action is called from an included page, use the name of the page that is included
# and not the caller's PageTag.
if (isset($this->config['includes']) && is_array($this->GetConfigValue('includes')))
$count = count($this->GetConfigValue('includes')) - 1;
$page = $this->config['includes'][$count];
echo $page.":"; print_r($this->config['includes']);
$page=$this->GetPageTag();
if ($page=="/") $page="CategoryCategory";
if (!$inctpl && preg_match('/Template$/',$page))
if (!preg_match('/^Category/',$page)) $page = 'CategoryCategory'; # exception for a category that contains templates
if ($show == 'all' || $show == 'categories')
$categorySearchphrase = "
SELECT tag AS page_tag
FROM ".$this->GetConfigValue('table_prefix')."links
INNER JOIN ".$this->GetConfigValue('table_prefix')."pages
ON to_tag = tag
AND latest = 'Y'
AND body LIKE '%[[(cat)".$page."]]%'
AND body LIKE '%{{category%'
GROUP BY tag
ORDER BY tag ".strtoupper($sort);
$results = $this->LoadAll($categorySearchphrase);
// filter what we show AS content of the requested category
if($keys = array_keys(array_column($results, 'page_tag'), ['CategoryCategory', $page]))
foreach($keys as $key) unset($results[$key]);
$errmsg = '<em>'.sprintf(T_("No categories found for %s"), $page).'</em>';
$list_pages_option = array(
'nopagesText' => $errmsg,
'class' => $class,
'columns' => $col,
'sort' => 'no',
'compact' => $compact
);
$str = $this->ListPages($results, $list_pages_option);
print($this->Format(T_("=====Categories=====")));
if ($str != $errmsg)
if(1 < count($results))
printf(T_("The following %d categories belong to %s").'<br /><br />', count($results), $page);
else
printf(T_("The following category belongs to %s").'<br /><br />', $page);
print($str);
if ($show == 'all') print('<br /><br />');
if ($show == 'all' || $show == 'categories')
$categorySearchphrase = "
SELECT tag AS page_tag
FROM ".$this->GetConfigValue('table_prefix')."links
INNER JOIN ".$this->GetConfigValue('table_prefix')."pages
ON to_tag = tag
AND latest = 'Y'
AND body LIKE '%[[(cat)".$page."]]%'
AND body NOT LIKE '%{{category%'
GROUP BY tag
ORDER BY tag ".strtoupper($sort);
$results = $this->LoadAll($categorySearchphrase);
// filter what we show AS content of the requested category
if($keys = array_keys(array_column($results, 'page_tag'), ['CategoryCategory', $page]))
foreach($keys as $key) unset($results[$key]);
$errmsg = '<em>'.sprintf(T_("No pages found for %s"), $page).'</em>';
$list_pages_option = array(
'nopagesText' => $errmsg,
'class' => $class,
'columns' => $col,
'sort' => 'no',
'compact' => $compact
);
$str = $this->ListPages($results, $list_pages_option);
print($this->Format(T_("=====Pages=====")));
if ($str != $errmsg)
if(1 < count($results))
printf(T_("The following %d pages belong to %s").'<br /><br />', count($results), $page);
else
printf(T_("The following page belongs to %s").'<br /><br />', $page);
print($str);
====Older Versions====


Revision [19996]

Edited on 2008-06-04 03:56:56 by MasinAlDujaili [working versions]
Additions:
>>Working for 1.1.6.0 to 1.1.6.4 (latest)>>''04/04/2005:version 2.0 (see below).''
// forced links
// \S : any character that is not a whitespace character
// \s : any whitespace character
//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 "";
}
}
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 && (int)$value > 0) $lCol = (int)$value;
break;
case 'compact':
if ($value) $lCompact = TRUE;
break;
case 'class':
if ('' != $value) $lClass = $value;
break;
case 'show':
if ($value == 'pages' || $value == 'categories') $lShow = $value;
break;
$categorylist = array();
// filter what we show AS content of the requested category
foreach ($categoryresults as $ccategory)
{
// do not list top-level category as member
if ('CategoryCategory' == $ccategory['tag'])
{
continue;
}
// do not list requested category as member
if ($ccategory['tag'] == $lPage)
{
continue;
}
// we have a valid result: add to the list
if ($lCompact)
{
$categorylist[] = $this->Link($ccategory['tag'],'',preg_replace( "/Category/", "",$ccategory['tag']));
}
else
{
$categorylist[] = $this->Link($ccategory['tag'],'',preg_replace( "/Category/", "",$ccategory['tag']));
}
}
sort($categorylist);
// make simple list (useful for sidebar)
if ($lCompact)
{
$lOutput .= ShowArrayAsList($categorylist,$lClass);
}
// make columnar overview (useful for category pages)
else
{
$categorycount = count($categorylist);
$lOutput .= 'The following '.$categorycount.' categories belong to '.$lPage.':<br /><br />'."\n"; #i18n
$lOutput .= ShowArrayInColumns($categorylist, $lCol, $lClass);
}
$lOutput .= 'No categories found for '.$lPage.".\n"; #i18n
$pagelist = array();
// filter what we show AS content of the requested category
foreach ($pageresults as $cpage)
{
// do not list requested category as member
if ($cpage['tag'] == $lPage)
{
continue;
}
// unless inctpl is set, do not list template pages
elseif (!$lIncTpl && preg_match('/Template$/', $cpage['tag']))
{
continue;
}
// we have a valid result: add to the list
if ($lCompact)
{
$pagelist[] = $this->Link($cpage['tag'],'',$cpage['tag']);
}
else
{
$pagelist[] = $this->Link($cpage['tag']);
}
}
sort($pagelist);
// make simple list (useful for sidebar)
if ($lCompact)
{
$lOutput .= ShowArrayAsList($pagelist,$lClass);
}
// make columnar overview (useful for category pages)
else
{
$pagecount = count($pagelist);
$lOutput .= 'The following '.$pagecount.' pages belong to '.$lPage.':<br /><br />'."\n"; #i18n
$lOutput .= ShowArrayInColumns($pagelist, $lCol, $lClass);
}
$lOutput .= 'No pages found for '.$lPage.".\n"; #i18n
Deletions:
''04/04/2005:version 2.0 (see below).''
// forced links
// \S : any character that is not a whitespace character
// \s : any whitespace character
//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 "";
}
}
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 && (int)$value > 0) $lCol = (int)$value;
break;
case 'compact':
if ($value) $lCompact = TRUE;
break;
case 'class':
if ('' != $value) $lClass = $value;
break;
case 'show':
if ($value == 'pages' || $value == 'categories') $lShow = $value;
break;
}
$categorylist = array();
// filter what we show AS content of the requested category
foreach ($categoryresults as $ccategory)
{
// do not list top-level category as member
if ('CategoryCategory' == $ccategory['tag'])
{
continue;
}
// do not list requested category as member
if ($ccategory['tag'] == $lPage)
{
continue;
}
// we have a valid result: add to the list
if ($lCompact)
{
$categorylist[] = $this->Link($ccategory['tag'],'',preg_replace( "/Category/", "",$ccategory['tag']));
}
else
{
$categorylist[] = $this->Link($ccategory['tag'],'',preg_replace( "/Category/", "",$ccategory['tag']));
}
}
sort($categorylist);
// make simple list (useful for sidebar)
if ($lCompact)
{
$lOutput .= ShowArrayAsList($categorylist,$lClass);
}
// make columnar overview (useful for category pages)
else
{
$categorycount = count($categorylist);
$lOutput .= 'The following '.$categorycount.' categories belong to '.$lPage.':<br /><br />'."\n"; #i18n
$lOutput .= ShowArrayInColumns($categorylist, $lCol, $lClass);
}
$lOutput .= 'No categories found for '.$lPage.".\n"; #i18n
$pagelist = array();
// filter what we show AS content of the requested category
foreach ($pageresults as $cpage)
{
// do not list requested category as member
if ($cpage['tag'] == $lPage)
{
continue;
}
// unless inctpl is set, do not list template pages
elseif (!$lIncTpl && preg_match('/Template$/', $cpage['tag']))
{
continue;
}
// we have a valid result: add to the list
if ($lCompact)
{
$pagelist[] = $this->Link($cpage['tag'],'',$cpage['tag']);
}
else
{
$pagelist[] = $this->Link($cpage['tag']);
}
}
sort($pagelist);
// make simple list (useful for sidebar)
if ($lCompact)
{
$lOutput .= ShowArrayAsList($pagelist,$lClass);
}
// make columnar overview (useful for category pages)
else
{
$pagecount = count($pagelist);
$lOutput .= 'The following '.$pagecount.' pages belong to '.$lPage.':<br /><br />'."\n"; #i18n
$lOutput .= ShowArrayInColumns($pagelist, $lCol, $lClass);
}
$lOutput .= 'No pages found for '.$lPage.".\n"; #i18n


Revision [19200]

Edited on 2008-01-28 00:14:43 by JavaWoman [Modified links pointing to docs server]

No Differences

Revision [16976]

Edited on 2007-05-31 23:27:32 by JavaWoman [Reverted]
Additions:
// forced links
// \S : any character that is not a whitespace character
// \s : any whitespace character
//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 "";
}
}
$lines++;
for ($i=0;$i<$colnumber;$i++)
for ($j=0;$j<$lines;$j++)
$a++;
$a++;
for ($i=0;$i<$entries;$i++)
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 && (int)$value > 0) $lCol = (int)$value;
break;
case 'compact':
if ($value) $lCompact = TRUE;
break;
case 'class':
if ('' != $value) $lClass = $value;
break;
case 'show':
if ($value == 'pages' || $value == 'categories') $lShow = $value;
break;
}
// filter WHICH category we (may) show the content OF
if ($lPage == '/')
$lPage = 'CategoryCategory';
if (!$lIncTpl && preg_match('/Template$/',$lPage))
if (!preg_match('/^Category/',$lPage)) $lPage = 'CategoryCategory'; # exception for a category that contains templates
//searching for categories belonging to the requested category, if necessary, and preparing the output
if ($lShow == 'all' || $lShow == 'categories')
$lCategorySearchphrase = "SELECT tag FROM ".$this->config['table_prefix']."pages WHERE latest = 'Y' AND body LIKE '%[[(cat)".$lPage."%' AND body LIKE '%{{category%'";
$categoryresults = $this->LoadAll($lCategorySearchphrase);
//print_r($categoryresults); //DEBUG
if ($categoryresults)
$categorylist = array();
// filter what we show AS content of the requested category
foreach ($categoryresults as $ccategory)
{
// do not list top-level category as member
if ('CategoryCategory' == $ccategory['tag'])
{
continue;
}
// do not list requested category as member
if ($ccategory['tag'] == $lPage)
{
continue;
}
// we have a valid result: add to the list
if ($lCompact)
{
$categorylist[] = $this->Link($ccategory['tag'],'',preg_replace( "/Category/", "",$ccategory['tag']));
}
else
{
$categorylist[] = $this->Link($ccategory['tag'],'',preg_replace( "/Category/", "",$ccategory['tag']));
}
}
sort($categorylist);
// make simple list (useful for sidebar)
if ($lCompact)
{
$lOutput .= ShowArrayAsList($categorylist,$lClass);
}
// make columnar overview (useful for category pages)
else
{
$categorycount = count($categorylist);
$lOutput .= 'The following '.$categorycount.' categories belong to '.$lPage.':<br /><br />'."\n"; #i18n
$lOutput .= ShowArrayInColumns($categorylist, $lCol, $lClass);
}
else
$lOutput .= 'No categories found for '.$lPage.".\n"; #i18n
//if necessary, a division between the categories and the pages
if ($lShow == 'all') $lOutput .= '<br /><br />';
//searching for pages belonging to the requested category, if necessary, and preparing the output
if ($lShow == 'all' || $lShow == 'pages')
$lPageSearchphrase = "SELECT tag FROM ".$this->config['table_prefix']."pages WHERE latest = 'Y' and body LIKE '%[[(cat)".$lPage."%' AND body NOT LIKE '%{{category%'";
$pageresults = $this->LoadAll($lPageSearchphrase);
//print_r($pageresults); //DEBUG
if ($pageresults)
$pagelist = array();
// filter what we show AS content of the requested category
foreach ($pageresults as $cpage)
{
// do not list requested category as member
if ($cpage['tag'] == $lPage)
{
continue;
}
// unless inctpl is set, do not list template pages
elseif (!$lIncTpl && preg_match('/Template$/', $cpage['tag']))
{
continue;
}
// we have a valid result: add to the list
if ($lCompact)
{
$pagelist[] = $this->Link($cpage['tag'],'',$cpage['tag']);
}
else
{
$pagelist[] = $this->Link($cpage['tag']);
}
}
sort($pagelist);
// make simple list (useful for sidebar)
if ($lCompact)
{
$lOutput .= ShowArrayAsList($pagelist,$lClass);
}
// make columnar overview (useful for category pages)
else
{
$pagecount = count($pagelist);
$lOutput .= 'The following '.$pagecount.' pages belong to '.$lPage.':<br /><br />'."\n"; #i18n
$lOutput .= ShowArrayInColumns($pagelist, $lCol, $lClass);
}
else
$lOutput .= 'No pages found for '.$lPage.".\n"; #i18n
echo $lOutput;
%%
----
CategoryDevelopmentActions
Deletions:
// forced links
// \S : any character that is not a whitespace character
// \s : any whitespace character
//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 "";
}
}
$lines ;
for ($i=0;$i<$colnumber;$i )
for ($j=0;$j<$lines;$j )
$a ;
$a ;
for ($i=0;$i<$entries;$i )
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


Revision [16775]

Edited on 2007-05-31 10:46:50 by LgxFvh [Reverted]
Additions:
// forced links
// \S : any character that is not a whitespace character
// \s : any whitespace character
//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 "";
}
}
$lines ;
for ($i=0;$i<$colnumber;$i )
for ($j=0;$j<$lines;$j )
$a ;
$a ;
for ($i=0;$i<$entries;$i )
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
Deletions:
// forced links
// \S : any character that is not a whitespace character
// \s : any whitespace character
//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 "";
}
}
$lines++;
for ($i=0;$i<$colnumber;$i++)
for ($j=0;$j<$lines;$j++)
$a++;
$a++;
for ($i=0;$i<$entries;$i++)
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 && (int)$value > 0) $lCol = (int)$value;
break;
case 'compact':
if ($value) $lCompact = TRUE;
break;
case 'class':
if ('' != $value) $lClass = $value;
break;
case 'show':
if ($value == 'pages' || $value == 'categories') $lShow = $value;
break;
}
// filter WHICH category we (may) show the content OF
if ($lPage == '/')
$lPage = 'CategoryCategory';
if (!$lIncTpl && preg_match('/Template$/',$lPage))
if (!preg_match('/^Category/',$lPage)) $lPage = 'CategoryCategory'; # exception for a category that contains templates
//searching for categories belonging to the requested category, if necessary, and preparing the output
if ($lShow == 'all' || $lShow == 'categories')
$lCategorySearchphrase = "SELECT tag FROM ".$this->config['table_prefix']."pages WHERE latest = 'Y' AND body LIKE '%[[(cat)".$lPage."%' AND body LIKE '%{{category%'";
$categoryresults = $this->LoadAll($lCategorySearchphrase);
//print_r($categoryresults); //DEBUG
if ($categoryresults)
$categorylist = array();
// filter what we show AS content of the requested category
foreach ($categoryresults as $ccategory)
{
// do not list top-level category as member
if ('CategoryCategory' == $ccategory['tag'])
{
continue;
}
// do not list requested category as member
if ($ccategory['tag'] == $lPage)
{
continue;
}
// we have a valid result: add to the list
if ($lCompact)
{
$categorylist[] = $this->Link($ccategory['tag'],'',preg_replace( "/Category/", "",$ccategory['tag']));
}
else
{
$categorylist[] = $this->Link($ccategory['tag'],'',preg_replace( "/Category/", "",$ccategory['tag']));
}
}
sort($categorylist);
// make simple list (useful for sidebar)
if ($lCompact)
{
$lOutput .= ShowArrayAsList($categorylist,$lClass);
}
// make columnar overview (useful for category pages)
else
{
$categorycount = count($categorylist);
$lOutput .= 'The following '.$categorycount.' categories belong to '.$lPage.':<br /><br />'."\n"; #i18n
$lOutput .= ShowArrayInColumns($categorylist, $lCol, $lClass);
}
else
$lOutput .= 'No categories found for '.$lPage.".\n"; #i18n
//if necessary, a division between the categories and the pages
if ($lShow == 'all') $lOutput .= '<br /><br />';
//searching for pages belonging to the requested category, if necessary, and preparing the output
if ($lShow == 'all' || $lShow == 'pages')
$lPageSearchphrase = "SELECT tag FROM ".$this->config['table_prefix']."pages WHERE latest = 'Y' and body LIKE '%[[(cat)".$lPage."%' AND body NOT LIKE '%{{category%'";
$pageresults = $this->LoadAll($lPageSearchphrase);
//print_r($pageresults); //DEBUG
if ($pageresults)
$pagelist = array();
// filter what we show AS content of the requested category
foreach ($pageresults as $cpage)
{
// do not list requested category as member
if ($cpage['tag'] == $lPage)
{
continue;
}
// unless inctpl is set, do not list template pages
elseif (!$lIncTpl && preg_match('/Template$/', $cpage['tag']))
{
continue;
}
// we have a valid result: add to the list
if ($lCompact)
{
$pagelist[] = $this->Link($cpage['tag'],'',$cpage['tag']);
}
else
{
$pagelist[] = $this->Link($cpage['tag']);
}
}
sort($pagelist);
// make simple list (useful for sidebar)
if ($lCompact)
{
$lOutput .= ShowArrayAsList($pagelist,$lClass);
}
// make columnar overview (useful for category pages)
else
{
$pagecount = count($pagelist);
$lOutput .= 'The following '.$pagecount.' pages belong to '.$lPage.':<br /><br />'."\n"; #i18n
$lOutput .= ShowArrayInColumns($pagelist, $lCol, $lClass);
}
else
$lOutput .= 'No pages found for '.$lPage.".\n"; #i18n
echo $lOutput;
%%
----
CategoryDevelopmentActions


Revision [8655]

Edited on 2005-05-29 09:07:52 by JavaWoman [move to subcategory]
Additions:
CategoryDevelopmentActions
Deletions:
CategoryDevelopment


Revision [8484]

Edited on 2005-05-26 05:02:04 by JavaWoman [minor fix]
Additions:
if ($lShow == 'all') $lOutput .= '<br /><br />';
Deletions:
if ($lShow == all) $lOutput .= '<br /><br />';


Revision [7202]

Edited on 2005-04-11 17:03:02 by NilsLindenberg [small code-change]
Additions:
else if (preg_match("/^\[\[\(cat\)(\S+)(\s(.+))*\]\]$/si", $thing, $matches))
Deletions:
else if (preg_match("/^\[\[\(cat\)(\S+)(\s(.+))*\]\]$/s", $thing, $matches))


Revision [7191]

Edited on 2005-04-11 10:53:30 by NilsLindenberg [code change (template-issue)]
Additions:
continue;
Deletions:
- taking care of the "Category_Template" (have forgotten that)
elseif (!$lIncTpl && preg_match('/Template$/', $ccategory['tag']))
// if the requested category ($lPage) is a template category, we do list its contents;
// otherwise this must indeed be a template so we don't list it.
if ( ! (preg_match('/^Category.*?Template$/',$lPage) || preg_match('/^Category/',$cpage['tag'])) )
{
continue;
}
// if the requested category ($lPage) is a template category, we do list its contents;
// otherwise this must indeed be a template so we don't list it.
if ( ! preg_match('/^Category.*?Template$/',$lPage))
{
continue;
}


Revision [7114]

Edited on 2005-04-05 09:36:51 by JavaWoman [I am unique ;-)]
Additions:
this version builds on the beta-version from JavaWoman (running on this wiki) and has in total the following cchanges to the official action:
Deletions:
this version builds on the beta-version from JavaWomen (running on this wiki) and has in total the following cchanges to the official action:


Revision [7092]

Edited on 2005-04-04 10:19:12 by NilsLindenberg [version 2.0]
Additions:
''04/04/2005:version 2.0 (see below).''
this version builds on the beta-version from JavaWomen (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
- taking care of the "Category_Template" (have forgotten that)
- 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
%%(php)
// forced links
// \S : any character that is not a whitespace character
// \s : any whitespace character
add the following:
%%(php)
//links to category pages
else if (preg_match("/^\[\[\(cat\)(\S+)(\s(.+))*\]\]$/s", $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==
==3. Replacement of actions/category.php==
%%(php)
* If no category page is specified, the current page is assumed to be a category.
* {{category [inctpl="0|1"] [page="categoryname"] [col="n"] [compact="0|1"] [class="class"] [show="pages|categories|all"]}}
* @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)
* @author {@link http://wikka.jsnx.com/NilsLindenberg NilsLindenberg} (seperation of categories, functions for output)
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @since Wikka 1.0.0
* @version 2.0
* @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
* @input string $show optional: show "pages" "categories" or "all"; default: all
* @output list of categories and/or pages belonging to the specified or top-level category,
* formatted as a list or in columns
* @uses LoadAll()
* @todo - possible? use a single list also for columns, using CSS to visually split up into columns - JW 2005-01-19
require_once 'library/common/showarray.php'; #the two functions showing the output in a list/ in columns
$lShow = 'all'; # show pages and categories
$lOutput = ''; # the final output
if ($value == 'pages' || $value == 'categories') $lShow = $value;
if ($lPage == '/')
//searching for categories belonging to the requested category, if necessary, and preparing the output
if ($lShow == 'all' || $lShow == 'categories')
$lCategorySearchphrase = "SELECT tag FROM ".$this->config['table_prefix']."pages WHERE latest = 'Y' AND body LIKE '%[[(cat)".$lPage."%' AND body LIKE '%{{category%'";
$categoryresults = $this->LoadAll($lCategorySearchphrase);
//print_r($categoryresults); //DEBUG
if ($categoryresults)
$categorylist = array();
// filter what we show AS content of the requested category
foreach ($categoryresults as $ccategory)
{
// do not list top-level category as member
if ('CategoryCategory' == $ccategory['tag'])
{
continue;
}
// do not list requested category as member
if ($ccategory['tag'] == $lPage)
{
continue;
}
// unless inctpl is set, do not list template pages
elseif (!$lIncTpl && preg_match('/Template$/', $ccategory['tag']))
{
// if the requested category ($lPage) is a template category, we do list its contents;
// otherwise this must indeed be a template so we don't list it.
if ( ! (preg_match('/^Category.*?Template$/',$lPage) || preg_match('/^Category/',$cpage['tag'])) )
{
continue;
}
}
// we have a valid result: add to the list
if ($lCompact)
{
$categorylist[] = $this->Link($ccategory['tag'],'',preg_replace( "/Category/", "",$ccategory['tag']));
}
else
{
$categorylist[] = $this->Link($ccategory['tag'],'',preg_replace( "/Category/", "",$ccategory['tag']));
}
}
sort($categorylist);
// make simple list (useful for sidebar)
if ($lCompact)
{
$lOutput .= ShowArrayAsList($categorylist,$lClass);
}
// make columnar overview (useful for category pages)
else
{
$categorycount = count($categorylist);
$lOutput .= 'The following '.$categorycount.' categories belong to '.$lPage.':<br /><br />'."\n"; #i18n
$lOutput .= ShowArrayInColumns($categorylist, $lCol, $lClass);
}
$lOutput .= 'No categories found for '.$lPage.".\n"; #i18n
//if necessary, a division between the categories and the pages
if ($lShow == all) $lOutput .= '<br /><br />';
//searching for pages belonging to the requested category, if necessary, and preparing the output
if ($lShow == 'all' || $lShow == 'pages')
$lPageSearchphrase = "SELECT tag FROM ".$this->config['table_prefix']."pages WHERE latest = 'Y' and body LIKE '%[[(cat)".$lPage."%' AND body NOT LIKE '%{{category%'";
$pageresults = $this->LoadAll($lPageSearchphrase);
//print_r($pageresults); //DEBUG
if ($pageresults)
$pagelist = array();
// filter what we show AS content of the requested category
foreach ($pageresults as $cpage)
{
// do not list requested category as member
if ($cpage['tag'] == $lPage)
{
continue;
}
// unless inctpl is set, do not list template pages
elseif (!$lIncTpl && preg_match('/Template$/', $cpage['tag']))
{
// if the requested category ($lPage) is a template category, we do list its contents;
// otherwise this must indeed be a template so we don't list it.
if ( ! preg_match('/^Category.*?Template$/',$lPage))
{
continue;
}
}
// we have a valid result: add to the list
if ($lCompact)
{
$pagelist[] = $this->Link($cpage['tag'],'',$cpage['tag']);
}
else
{
$pagelist[] = $this->Link($cpage['tag']);
}
}
sort($pagelist);
// make simple list (useful for sidebar)
if ($lCompact)
{
$lOutput .= ShowArrayAsList($pagelist,$lClass);
}
// make columnar overview (useful for category pages)
else
{
$pagecount = count($pagelist);
$lOutput .= 'The following '.$pagecount.' pages belong to '.$lPage.':<br /><br />'."\n"; #i18n
$lOutput .= ShowArrayInColumns($pagelist, $lCol, $lClass);
}
$lOutput .= 'No pages found for '.$lPage.".\n"; #i18n
echo $lOutput;
%%
Deletions:
''29/03/2005: small code change (building arrays only when needed and better organzation of the output).''
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:
* 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.
* {{category [forcecat="0|1"] [inctpl="0|1"] [page="categoryname"] [col="n"] [compact="0|1"] [class="class"] [show="pages|categories|all"]}}
* @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)
* @author {@link http://wikka.jsnx.com/NilsLindenberg NilsLindenberg} (seperation of categories, functions for output)
* @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
* @input string $show optional: show "pages" "categories" od "all"; default: all
* @output list of categories and/or pages belonging to the specified or top-level category,
* formatted as a list or in columns
* @uses CheckMySQLVersion()
* @uses FullCategoryTextSearch()
* @uses FullTextSearch()
* @todo - version dependency FullCategoryTextSearch/ FullTextSearch should be hidden inside call - JW 2005-01-21
* - possible? use a single list also for columns, using CSS to visually split up into columns - JW 2005-01-19
require_once 'library/common/showarray.php';
$lForceCat = TRUE; # only pages starting with 'Category' are considered category pages
$lshow = 'all'; # show pages and categories
$output = ''; # the final output
case 'forcecat':
if (!$value) $lForceCat = FALSE;
if ($value == 'pages' || $value == 'categories') $lshow = $value;
if ($lForceCat)
if (!preg_match('/^Category/',$lPage)) $lPage = 'CategoryCategory';
elseif ($lPage == '/')
// 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 !== 0)
$pagelist = array();
$categorylist = array();
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
elseif (!$lIncTpl && preg_match('/Template$/', $cpage['tag']))
// 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.
if ( ! (preg_match('/^Category.*?Template$/',$lPage) || preg_match('/^Category/',$cpage['tag'])) )
{
continue;
}
// we have a valid result: add to the list
if (preg_match('/^Category/', $cpage['tag']) && ($lshow == "all" || $lshow == "categories"))
if ($lCompact)
{$categorylist[] = $this->Link($cpage['tag'],'',preg_replace('/Category/','',$cpage['tag']));}
else
{$categorylist[] = $this->Link($cpage['tag']);}
else if (!preg_match('/^Category/', $cpage['tag']) && ($lshow == "all" || $lshow == "pages"))
if ($lCompact)
{$pagelist[] = $this->Link($cpage['tag'],'',$cpage['tag']);}
else
{$pagelist[] = $this->Link($cpage['tag']);}
else $output .= 'No items found for '.$lpage.".\n";
// show resulting list of categories belonging to category $lPage
if ($categorylist)
sort($categorylist);
// make simple list (useful for sidebar)
if ($lCompact)
$output .= ShowArrayAsList($categorylist,$lClass);
// make columnar overview (useful for category pages)
$categorycount = count($categorylist);
$output .= 'The following '.$categorycount.' categories belong to '.$lPage.':<br /><br />'."\n";
$output .= ShowArrayInColumns($categorylist, $lCol, $lClass);
else if ($lshow == "all" || $lshow == "categories")
$output .= 'No categories found for '.$lPage.".\n";
//divide
if ($lshow == all) $output .= '<br><br>';
// show resulting list of pages belonging to category $lPage
if ($pagelist)
sort($pagelist);
// make simple list (useful for sidebar)
if ($lCompact)
$output .= ShowArrayAsList($pagelist,$lClass);
// make columnar overview (useful for category pages)
$pagecount = count($pagelist);
$output .= 'The following '.$pagecount.' pages belong to '.$lPage.':<br /><br />'."\n";
$output .= ShowArrayInColumns($pagelist, $lCol, $lClass);
else if ($lshow == "all" || $lshow == "pages")
$output .= 'No pages found for '.$lPage.".\n";
echo $output;


Revision [7069]

Edited on 2005-04-01 19:33:28 by NilsLindenberg [small code change]
Additions:
if ($results !== 0)
else $output .= 'No items found for '.$lpage.".\n";
$output .= 'No categories found for '.$lPage.".\n";
$output .= 'No pages found for '.$lPage.".\n";
Deletions:
if ($results)
else $output .= 'No items found for '. $lpage .'.';
$output .= 'No categories found for ' . $lPage .'.';
$output .= 'No pages found for ' . $lPage .'.';


Revision [6989]

Edited on 2005-03-29 13:39:41 by NilsLindenberg [small code change]
Additions:
''29/03/2005: small code change (building arrays only when needed and better organzation of the output).''
* @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)
* @author {@link http://wikka.jsnx.com/NilsLindenberg NilsLindenberg} (seperation of categories, functions for output)
* @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
* @input string $show optional: show "pages" "categories" od "all"; default: all
* @output list of categories and/or pages belonging to the specified or top-level category,
* formatted as a list or in columns
* @uses CheckMySQLVersion()
* @uses FullCategoryTextSearch()
* @uses FullTextSearch()
* @uses Link()
* @todo - version dependency FullCategoryTextSearch/ FullTextSearch should be hidden inside call - JW 2005-01-21
* - possible? use a single list also for columns, using CSS to visually split up into columns - JW 2005-01-19
$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
$lshow = 'all'; # show pages and categories
$output = ''; # the final output
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;
case 'show':
if ($value == 'pages' || $value == 'categories') $lshow = $value;
break;
}
if (!preg_match('/^Category/',$lPage)) $lPage = 'CategoryCategory'; # exception for a category that contains templates
// 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
elseif (!$lIncTpl && preg_match('/Template$/', $cpage['tag']))
{
// 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.
if ( ! (preg_match('/^Category.*?Template$/',$lPage) || preg_match('/^Category/',$cpage['tag'])) )
{
continue;
}
}
// we have a valid result: add to the list
if (preg_match('/^Category/', $cpage['tag']) && ($lshow == "all" || $lshow == "categories"))
{
if ($lCompact)
{$categorylist[] = $this->Link($cpage['tag'],'',preg_replace('/Category/','',$cpage['tag']));}
else
{$categorylist[] = $this->Link($cpage['tag']);}
}
else if (!preg_match('/^Category/', $cpage['tag']) && ($lshow == "all" || $lshow == "pages"))
{
if ($lCompact)
{$pagelist[] = $this->Link($cpage['tag'],'',$cpage['tag']);}
else
{$pagelist[] = $this->Link($cpage['tag']);}
}
else $output .= 'No items found for '. $lpage .'.';
if ($categorylist)
$output .= ShowArrayAsList($categorylist,$lClass);
$categorycount = count($categorylist);
$output .= 'The following '.$categorycount.' categories belong to '.$lPage.':<br /><br />'."\n";
$output .= ShowArrayInColumns($categorylist, $lCol, $lClass);
else if ($lshow == "all" || $lshow == "categories")
$output .= 'No categories found for ' . $lPage .'.';
//divide
if ($lshow == all) $output .= '<br><br>';
if ($pagelist)
$output .= ShowArrayAsList($pagelist,$lClass);
$pagecount = count($pagelist);
$output .= 'The following '.$pagecount.' pages belong to '.$lPage.':<br /><br />'."\n";
$output .= ShowArrayInColumns($pagelist, $lCol, $lClass);
else if ($lshow == "all" || $lshow == "pages")
$output .= 'No pages found for ' . $lPage .'.';
echo $output;
Deletions:
''28/02/2005: new option show="categories|pages|all" and a seperate file for the two functions.''
* @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)
* @author {@link http://wikka.jsnx.com/NilsLindenberg NilsLindenberg} (seperation of categories, functions for output)
* @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
* @input string $show optional: show "pages" "categories" od "all"; default: all
* @output list of categories and pages belonging to the specified or top-level category,
* formatted as a list or in columns
* @uses CheckMySQLVersion()
* @uses FullCategoryTextSearch()
* @uses FullTextSearch()
* @uses Link()
* @todo - version dependency FullCategoryTextSearch/ FullTextSearch should be hidden inside call - JW 2005-01-21
* - possible? use a single list also for columns, using CSS to visually split up into columns - JW 2005-01-19
$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
$lshow = 'all'; # show pages and categories
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;
case 'show':
if ($value == 'pages' || $value == 'categories') $lshow = $value;
break;
if (!preg_match('/^Category/',$lPage)) $lPage = 'CategoryCategory'; # exception for a category that contains templates
// 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
elseif (!$lIncTpl && preg_match('/Template$/', $cpage['tag']))
// 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.
if ( ! (preg_match('/^Category.*?Template$/',$lPage) || preg_match('/^Category/',$cpage['tag'])) )
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 $pagelist[] = $this->Link($cpage['tag'],'',$cpage['tag']);
else
if (preg_match('/^Category/', $cpage['tag'])) $categorylist[] = $this->Link($cpage['tag']);
else $pagelist[] = $this->Link($cpage['tag']);
if ($categorylist && ($lshow == 'categories' || $lshow == 'all'))
$categorystr ='';
$categorystr .= ShowArrayAsList($categorylist,$lClass);
$categorycount = count($categorylist);
$categorystr .= 'The following '.$categorycount.' categories belong to '.$lPage.':<br /><br />'."\n";
$categorystr .= ShowArrayInColumns($categorylist, $lCol, $lClass);
$categorystr .= 'Sorry, no categories found for ' . $lPage .'.';
if ($pagelist && ($lshow == 'pages' || $lshow == 'all'))
$pagestr ='';
$pagestr .= ShowArrayAsList($pagelist,$lClass);
$pagecount = count($pagelist);
$pagestr .= 'The following '.$pagecount.' pages belong to '.$lPage.':<br /><br />'."\n";
$pagestr .= ShowArrayInColumns($pagelist, $lCol, $lClass);
$pagestr .= 'Sorry, no items found for ' . $lPage .'.';
if ($lshow == 'categories' || $lshow == 'all')
echo $categorystr;
echo '<br /><br />';
if ($lshow == 'pages' || $lshow == 'all') echo $pagestr;


Revision [6442]

Edited on 2005-03-03 14:08:53 by NilsLindenberg [+documentation]
Additions:
* 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
* 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
Deletions:
//$classattr = ('' != $class) ? ' class="linklist '.$class.'"' : ' class="linklist"';


Revision [6441]

Edited on 2005-03-03 13:56:08 by NilsLindenberg [removed brackets from new code]
Additions:
require_once 'library/common/showarray.php';
Deletions:
require_once('library/common/showarray.php');


Revision [6440]

Edited on 2005-03-03 13:41:29 by NilsLindenberg [new code]
Additions:
''28/02/2005: new option show="categories|pages|all" and a seperate file for the two functions.''
* {{category [forcecat="0|1"] [inctpl="0|1"] [page="categoryname"] [col="n"] [compact="0|1"] [class="class"] [show="pages|categories|all"]}}
* @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)
* @author {@link http://wikka.jsnx.com/NilsLindenberg NilsLindenberg} (seperation of categories, functions for output)
* @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
* @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
* @input string $show optional: show "pages" "categories" od "all"; default: all
* @output list of categories and pages belonging to the specified or top-level category,
* @todo - version dependency FullCategoryTextSearch/ FullTextSearch should be hidden inside call - JW 2005-01-21
*/
//including the needed functions
require_once('library/common/showarray.php');
$lPage = $this->tag; # current page is default category
$lCol = 1; # one column for table
$lClass = ''; # no class
$lshow = 'all'; # show pages and categories
case 'show':
if ($value == 'pages' || $value == 'categories') $lshow = $value;
if ($categorylist && ($lshow == 'categories' || $lshow == 'all'))
if ($pagelist && ($lshow == 'pages' || $lshow == 'all'))
if ($lshow == 'categories' || $lshow == 'all')
echo $categorystr;
echo '<br /><br />';
if ($lshow == 'pages' || $lshow == 'all') echo $pagestr;
The following file has to be saved as ##library/common/showarray.php##:
Deletions:
''28/02/2005: new code which fixes counting-bug. Functions for organizing the list. Still needs adjustments (for example on the "class") and documentation.''
* {{category [forcecat="0|1"] [inctpl="0|1"] [page="categoryname"] [col="n"] [compact="0|1"] [class="class"]}}
* @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)
* @author {@link http://wikka.jsnx.com/NilsLindenberg NilsLindenberg} (seperation of categories, functions for output)
* @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
* @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 categories and pages belonging to the specified or top-level category,
* @todo - version dependency FullCategoryTextSearch( / FullTextSearch should be hidden inside call - JW 2005-01-21
* - put the two function calls in a seperate file so backlinks can use the same - NL 2005-03-01
*/
if (! function_exists('ShowArrayInColumns'))
if (! function_exists('ShowArrayAsList'))
$lPage = $this->tag; # current page is default category
$lCol = 1; # one column for table
$lClass = ''; # no class
if ($categorylist)
if ($pagelist)
echo $categorystr;
echo '<br /><br />';
echo $pagestr;


Revision [6397]

Edited on 2005-03-01 11:01:56 by NilsLindenberg [small changes to the documentation]
Additions:
* @package Actions
* @subpackage SystemContent
* @author {@link http://wikka.jsnx.com/NilsLindenberg NilsLindenberg} (seperation of categories, functions for output)
* @copyright Copyright © 2004, Jason Tourtelotte
* @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 $class optional: class(es) to determine styling of the output list of table
* @output list of categories and pages belonging to the specified or top-level category,
* formatted as a list or in columns
* - put the two function calls in a seperate file so backlinks can use the same - NL 2005-03-01
* - possible? use a single list also for columns, using CSS to visually split up into columns - JW 2005-01-19
* - possible? use a single list also for columns, using CSS to visually split up into columns - JW 2005-01-19
*/
$lIncTpl = FALSE; # do not show template pages or treat a template as a category
$lCol = 1; # one column for table
$lCompact = FALSE; # use table, not list
$lClass = ''; # no class
Deletions:
* @package Actions
* @subpackage SystemContent
* @copyright Copyright © 2004, Jason Tourtelotte
* @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 $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
* - 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
*/
$lIncTpl = FALSE; # do not show template pages or treat a template as a category
$lCol = 1; # one column for table
$lCompact = FALSE; # use table, not list
$lClass = ''; # no class


Revision [6391]

Edited on 2005-02-28 16:39:14 by NiehLe [code update]
Additions:
''28/02/2005: new code which fixes counting-bug. Functions for organizing the list. Still needs adjustments (for example on the "class") and documentation.''
* @package Actions
* @subpackage SystemContent
* @copyright Copyright © 2004, Jason Tourtelotte
* - 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
if (! function_exists('ShowArrayInColumns'))
function ShowArrayInColumns($array, $colnumber=1, $class="")
if (! function_exists('ShowArrayAsList'))
function ShowArrayAsList($array,$class="")
//$classattr = ('' != $class) ? ' class="linklist '.$class.'"' : ' class="linklist"';
$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.";
$categorystr .= ShowArrayAsList($categorylist,$lClass);
$categorycount = count($categorylist);
$pagestr .= ShowArrayAsList($pagelist,$lClass);
$pagecount = count($pagelist);
Deletions:
''28/02/2005: new code which fixes counting-bug. First draft of functions for output. Still needs adjustments.''
* @package Actions
* @subpackage SystemContent
* @copyright Copyright © 2004, Jason Tourtelotte
* - 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
function ShowArrayInColumns($array, $colnumber=1, $class)
$categorycount = count($categorylist);
$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";
$pagecount = count($pagelist);
$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";


Revision [6386]

Edited on 2005-02-28 14:52:19 by NilsLindenberg [code update]
Additions:
''28/02/2005: new code which fixes counting-bug. First draft of functions for output. Still needs adjustments.''
* @package Actions
* - 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
function ShowArrayInColumns($array, $colnumber=1, $class)
$str = "";
if (is_array($array))
$entries = count($array);
$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);
}
$categorystr .= ShowArrayInColumns($categorylist, $lCol, $lClass);
$pagestr .= ShowArrayInColumns($pagelist, $lCol, $lClass);
Deletions:
''25/02/2005: new code which uses jws enhanced code. still needs some adjustments in details.''
* @package Actions
* - 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
// 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"';
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";
// 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"';
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";


Revision [6333]

Edited on 2005-02-25 19:23:46 by NilsLindenberg [new code + category added]
Additions:
''25/02/2005: new code which uses jws enhanced code. still needs some adjustments in details.''
/**
* 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
if (is_array($vars))
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)
if (!preg_match('/^Category/',$lPage)) $lPage = 'CategoryCategory';
elseif ($lPage == '/')
$lPage = 'CategoryCategory';
if (!$lIncTpl && preg_match('/Template$/',$lPage))
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)
$pagelist = array();
$categorylist = array();
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
elseif (!$lIncTpl && preg_match('/Template$/', $cpage['tag']))
// 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.
if ( ! (preg_match('/^Category.*?Template$/',$lPage) || preg_match('/^Category/',$cpage['tag'])) )
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 $pagelist[] = $this->Link($cpage['tag'],'',$cpage['tag']);
else
if (preg_match('/^Category/', $cpage['tag'])) $categorylist[] = $this->Link($cpage['tag']);
else $pagelist[] = $this->Link($cpage['tag']);
sort($categorylist);
sort($pagelist);
// show resulting list of categories belonging to category $lPage
if ($categorylist)
$categorystr ='';
$categorycount = count($categorylist);
// 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)
$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 ='';
$pagecount = count($pagelist);
// 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)
$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);
$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
Deletions:
I haven't found the code for JWs better category-action, see WikkaBetaFeatures for what I mean, and therefore have just made some little changes to the 1.1.6.0 code:
if ($cattag = $_REQUEST["wakka"])
$str ="";
$categorystr="";
if (!isset($col)) $col=1;
if (!isset($compact)) $compact=0;
if (!isset($page)) $page=$this->getPageTag();
if ($page=="/") $page="CategoryCategory";
// $page= preg_replace( "/(\w+)\s(\w+)/", "$1$2",$page);
if (isset($class))
$class="class=\"$class\"";
} else
$class="";
if (!$page) {$page=$cattag;}
if ($this->CheckMySQLVersion(4,0,1))
$results = $this->FullCategoryTextSearch($page);
$results = $this->FullTextSearch($page);
if ($results)
if (!$compact) $str .= ' to ' . $page . ': <br /><br /><table '.$class.' width="100%"><tr>';
else $str .= '<div '.$class.'><ul>';
$categorystr .= ' pages belong to ' . $page . ': <br /><br /><div '.$class.'><ul>';

$count = 0;
$categorycount = 0;

$list = array();

foreach ($results as $i => $cpage) if($cpage['tag'] != $page) { array_push($list,$cpage['tag']);}
sort($list);
while (list($key, $val) = each($list))
if (eregi("^Category", $val)) // do we have a category??
$categorystr .= '<li>'.$this->Format('[['.$val.' '.preg_replace( "/Category/", "",$val).']]').'</li>';
$categorycount++;
else // no, must be a page then!
if ($count == $col & !$compact) { $str .= "</tr><tr>"; $count=0; }
if (!$compact) $str .= '<td>'.$this->Format('[['.$val.']]').'</td>';
else $str .= '<li>'.$this->Format('[['.$val.' '.preg_replace( "/Category/", "",$val).']]').'</li>';
$count++;
$pagecount++;
if ($pagecount == 1) $str = 'The following page belongs'.$str;
else $str = 'The following '.$pagecount.' pages belong'.$str;
if ($categorycount == 1) $categorystr = 'The following category belongs'.$categorystr;
else $categorystr = 'The following '.$categorycount.' categories belong'.$categorystr;
if (!$compact) $str .= '</tr></table>'; else $str .= '</ul></div>';
$categorystr .= '</ul></div>';
else $str .= 'Sorry, no items found for ' .$page .'.';

if ($categorycount)
print ($categorystr);
echo '<br /><br />';
if (pagecount) print($str);
echo '<br /><br />';
%%


Revision [6261]

Edited on 2005-02-23 11:49:21 by NilsLindenberg [little correction in the description]
Additions:
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.
Deletions:
If you use the following code to replace your ##actions/category.php##, Categories are listed seperate from pages, and the later without the "Category" in front.


Revision [6250]

The oldest known version of this page was created on 2005-02-22 14:39:08 by NilsLindenberg [little correction in the description]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki