$value) { $_POST[$key]= stripslashes($value); } } //Create categories from entered data if (isset($_POST['Tags']) && $_POST['Tags'] != "") { $newtext = XESTag2Cat($_POST['Tags']); // Append the actual Simile group page with the new Category markup # change 'false' to 'true' if you want a password prompt $oldpage = RetrieveAuthPage($pagename, 'edit', true); if (!$oldpage) { Abort("You don't have permission to edit $pagename"); } $newpage = $oldpage; // dupe check, remove blanks & sort $newpage['text'] = XESMergeCats($newpage['text'], $newtext); UpdatePage($pagename, $oldpage, $newpage); } HandleBrowse($pagename); } // This function grabs all the categories on the page // and eliminates dupes, sorts...and spits it out in a nice div. function XESMergeCats($oldtext, $newtext){ preg_match_all('/\[\[!(.*?)]]/', $oldtext, $oldmatch); preg_match_all('/\[\[!(.*?)]]/', $newtext, $newmatch); $output = (array_merge($oldmatch[0], $newmatch[0])); /* print_r($output); exit(); */ array_walk($output,trim); sort($output); $output = implode (" | ", array_unique($output)); $search = array ('/([A-Z-])/', '/([\d]+)/', '/[-][\d\w]/','/[ ]{2,}/'); $replace = array (' $1', ' $1', '- ', ' '); $output = trim(preg_replace($search, $replace, $output)); $other = preg_replace('/\(:div class\=category:\)(.*?)$\n\(:divend:\)/m', '', $oldtext); return $other . "\n(:div class=category:)" . $output . "\n(:divend:)"; } // This function creates the category info // Turns value into category tags function XESTag2Cat($Tags) { $Tags = explode(',', $Tags); // clean up the array foreach ($Tags as $tag) { $tag = ucwords(trim($tag)); // don't allow messing with tags - allowed characters $clean = preg_replace("/[^A-Za-z0-9-]/","",$tag); if (($clean != "") && ($clean != "[[!]]") ) $cat_clean[] = $clean; } // prep the return value $text = "[[! " . (implode (']] [[! ', $cat_clean)) . "]] "; // pass return value return $text; }