From 73a659d81bd38df6b6e64df413c58f4876629f60 Mon Sep 17 00:00:00 2001 From: John Klehm Date: Mon, 7 Apr 2008 15:24:55 -0500 Subject: include/nice_urls.php: Util functions for nice urls feature --- include/nice_urls.php | 77 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 77 insertions(+), 0 deletions(-) create mode 100644 include/nice_urls.php diff --git a/include/nice_urls.php b/include/nice_urls.php new file mode 100644 index 0000000..064a77f --- /dev/null +++ b/include/nice_urls.php @@ -0,0 +1,77 @@ += 'a' && $char <= 'z') || + ($char >= '0' && $char <= '9') ); +} + +function nice_url_ignore_char($char) +{ + return ($char == '\''); +} + +# simply an apps name +# 1) lowercase +# 2) chars a-z0-9 => nice_url_valid_char +# 3) smoosh out apostrophes (other non separating non valid chars?) +# => nice_url_ignore_char +# 4) add a separator ( '-' ) if any non valid non ignored char is encountered +# 5) only allow 1 separator in a row +# 6) no separator allowed at front or back of simplified name +# 7) if name cant be simplified return empty string +function nice_url_name($name) +{ + $curName = strtolower($name); + $curNameLen = strlen($curName); + $fixedName = ''; + $fixedNameLen = 0; + + for ($i = 0; $i < $curNameLen; ++$i) + { + if (nice_url_valid_char($curName[$i])) + { + $fixedName .= $curName[$i]; + ++$fixedNameLen; + } + else if ( ($fixedNameLen) && + ($fixedName[$fixedNameLen - 1] != '-') && + (!nice_url_ignore_char($curName[$i])) ) + { + $fixedName .= '-'; + ++$fixedNameLen; + } + } + + # hack off the last '-' char + $fixedNameLastCharPos = $fixedNameLen - 1; + if ($fixedName[$fixedNameLastCharPos] == '-') + { + $fixedName = substr($fixedName,0,$fixedNameLastCharPos); + } + + return $fixedName; +} + +function nice_urls_display($html, $title="") +{ + apidb_header($title); + echo "
\n"; + echo $html; + echo "
\n"; + apidb_footer(); + return; +} + +?> -- 1.5.4.5