read()) { if($file != "." && $file != "..") { if (is_dir($curpath.$file)) { $result = array_merge(array_values($result),array_values(ls($curpath.$file."/"))); } else { $result[] = $file; } } } $dir->close(); return $result; } global $pageList; if ($useDirectory) { $pageList = ls($directoryWithPages); } else { $pageList = array(); }; function wikifiedWord($theWord) { global $pageList; global $urlPrefix; global $pageSuffix; global $useDirectory; global $lowerCaseCamelCase; if ($lowerCaseCamelCase) { $theWord = strtolower($theWord); }; if (in_array($theWord.$pageSuffix,$pageList) || !$useDirectory) { return ''.$theWord.''; } else { return $theWord; }; } function wikifyFirstElement($theArray) { return wikifiedWord($theArray[0]); } function wikify_text($theContent) { return preg_replace_callback("/(?|\/|\"|[A-Z]|[a-z]|[0-9])([A-Z]+([a-z]|[0-9])+){2,}(?!<|\/|\"|[A-Z]|[a-z]|[0-9])/",'wikifyFirstElement',$theContent); } # Picks up the [[ ]] enclosed words # Will pickup either [[PageName]] or [[PageName|label]] formats function wikify_text2($theContent) { return preg_replace_callback("/(?|\/|\"|\!|[A-Z]|[a-z]|[0-9])\[\[([^\]\|]+)\]\]|\[\[(.+)\|([^\]]+)\]\](?!<|\/|\"|[A-Z]|[a-z]|[0-9])/",'wikifyBracketedElement',$theContent); # /(\[.+\|.+\])/ /(\[(.+)\|(.+)\])|\[(.+)\]/ /\[([^\]]+)\]|\[(.+)\|([^\]]+)\]/ } function wikifyBracketedElement($theArray) { if ($theArray[2] != "") { return wikifiedWord2($theArray[2], $theArray[3]); } else { return wikifiedWord2($theArray[1], $theArray[1]); } } function wikifiedWord2($thePage, $theLink) { global $pageList; global $urlPrefix; global $pageSuffix; global $useDirectory; if (in_array($thePage.$pageSuffix,$pageList) || !$useDirectory) { return ''.$theLink.''; } else { return $theLink; }; } function wikify_text3($theContent) { return preg_replace_callback("/(?|\/|\"|[A-Za-z0-9])([-A-Za-z0-9])+(?!<|\/|\"|[A-Za-z0-9])/",'wikifyWordElement',$theContent); } function wikifyWordElement($theArray) { return wikifiedWordInList($theArray[0]); } function wikifiedWordInList($theWord) { global $pageList; global $specialWordList; global $pageSuffix; global $urlPrefix; global $useDirectory; if (in_array($theWord,$specialWordList)) { if ($useDirectory) { if (in_array($theWord.$pageSuffix,$pageList)) { return ''.$theWord.''; } else { return $theWord; }; } else { return ''.$theWord.''; }; } else { return $theWord; }; } # to run tests, change the 1 to a 0 in the line below if (1) { # Turn on the wikifying process. if ($processCamelCase) { add_filter('the_content', 'wikify_text'); }; add_filter('the_content', 'wikify_text2'); add_filter('the_content', 'wikify_text3'); } else { print wikify_text("WordPress"); print wikify_text("ordPress"); print wikify_text2("[[login]]"); print wikify_text2("[[ogin]]"); print wikify_text2("[[login|log in]]"); print wikify_text2("[[ogin|log in]]"); print wikify_text3("login"); print wikify_text3("ogin"); }; ?>