"HandleTags"); /* Can be overridden in 'local/conf.php' to provide a different title. */ $tags_title_prefix="Sites that are tagged with: "; $tags_prefix="Tags"; /* If not 0 this value declares the maximum allowed font size within the tag cloud. */ $tags_size_limit=0; /* All tags currently declared on this page. */ $tags=array(); Markup("tags", "directives", '/\\(:tags\\s(.*?):\\)/ei', "Tagger('$1',false)"); Markup("tags-hide", "directives", '/\\(:tags-hide\\s(.*?):\\)/ei', "Tagger('$1',true)"); Markup("listtags", "directives", '/\\(:listtags(.*?):\\)/ei', "ListTags('$1')"); Markup("listgrouptags", "directives", '/\\(:listgrouptags\\s(.*?):\\)/ei', "ListGroupTags('$1')"); function Tagger($i,$hide) { global $action; global $tags; $currenttags = explode(",",$i); $tags = array_merge($tags, $currenttags); if($hide) { return ""; } else { $output = "
"; $first = true; foreach ($currenttags as $tag) { $tag=trim($tag); if ($first===false) { $output = $output.', '; } $first = false; $output=$output.''.$tag.''; } return $output."
"; } } function HandleTags() { global $tags_prefix; global $tags_title_prefix; $taggedPages; $tag = $_GET["tag"]; $pagelist = ListPages(); foreach ($pagelist as $pagename) { $page=ReadPage($pagename, READPAGE_CURRENT); if (preg_match('/\\(:tags\\s.*?\b'.$tag.'\b.*?:\\)/i',$page['text']) || preg_match('/\\(:tags-hide\\s.*?\b'.$tag.'\b.*?:\\)/i',$page['text'])) { $name=explode(".",$page['name']); $taggedPages=$taggedPages.'*[['.$name[1].'->'.$pagename.']] '; $taggedPages=$taggedPages." \n"; } } $text = $tags_title_prefix." @@".$tag."@@ \n\n"; $page = array("text"=>$text.$taggedPages); $sitename=$tags_prefix.".".ucfirst(str_replace(" ","",$tag)); WritePage($sitename,$page); Redirect($sitename); } function __LoadTags($text) { $count1 = preg_match('/\\(:tags\\s(.*?):\\)/ei',$text, $matches1); $count2 = preg_match('/\\(:tags-hide\\s(.*?):\\)/ei',$text, $matches2); $result = array(); if($count1 > 0) { $result = array_merge($result, explode(",", substr($matches1[0], 6, -2))); } if($count2 > 0) { $result = array_merge($result, explode(",", substr($matches2[0], 11, -2))); } return $result; } function __GenerateTagList($pagelist, $showselected) { global $tags; global $tags_size_limit; $tagcount=array(); $tagselection=array(); $output; foreach ($pagelist as $pagename) { $page=ReadPage($pagename, READPAGE_CURRENT); $matched_tags = __LoadTags($page['text']); foreach($matched_tags as $value) { $key=ucfirst(trim($value)); $tagcount[$key]+=1; $tagselection[$key] = in_array($value, $tags); } } ksort($tagcount); foreach ($tagcount as $tag=>$value) { $size = $value + 10; if ($tags_size_limit > 0) { if ($size > $tags_size_limit) { $size = $tags_size_limit; } } if ($tagselection[$tag] && $showselected) { $output=$output.' '.$tag.' '; } else { $output=$output.' '.$tag.' '; } } return $output; } function ListTags($i) { $showselected = preg_match('/\\s\bshowselected\b/ei',$i) > 0; $pagelist = ListPages(); return __GenerateTagList($pagelist, $showselected); } function ListGroupTags($i) { global $tags; $showselected = false; $parameters = explode(" ", $i); foreach ($parameters as $parameter) { $parameter = trim($parameter); if ($parameter === "showselected") { $showselected = true; } else { $group = $parameter; } } $pagelist = ListPages("/^$group.*/"); return __GenerateTagList($pagelist, $showselected); }