ShortURLs are what make “index.php?do=task&data=this is my data” “index.php/task/this+is+my+data.html”
Here I explain what code changes I made to cleanup my code.
So I wrote a little coding for ShortURLs using path_info:
// Path Info Translation
// ——————————
// Lets set some variables
$extensions = array(“.xml”, “.rss”, “.shtml”, “.html”, “.shtm”, “.htm”, “.phps”, “.php”);
$path = preg_split(‘/[\/]+/’, str_replace($extensions, “”, sanatize_data($_SERVER["PATH_INFO"])));
unset($path['0']);
// Split the array into useable chunks.
if(isset($_SERVER["PATH_INFO"])) {
if($path["1"] == “category”) { $cid = (int)$path["2"]; $page_title = “Category – “; } else { $cid = 0; $page_title = “Category List”; }
if($path["1"] == “item”) { $aid = (int)$path["2"]; $page_title = “Item – “; } else { $aid = 0; }
if($path["1"] == “island”) { $island = 1; }
if($path["1"] == “random”) { $random = 1; }
if($path["1"] == “rss”) { $feed = 1; $nocache = 1; $reqpage = $path["2"]; }
if($path["1"] == “map”) { $map = 1; }
if($path["1"] == “latest”) { $latest = 1; }
if($path["1"] == “popular”) { $popular = 1; }
if($path["1"] == “last”) { $last = 1; }
if($path["3"] == “page”) { $page = (int)$path["4"]; } else { $page = 0; $page_title = str_replace(“+”, ” “, $path["3"]); }
if(isset($path["5"]) && !isset($sub_title)) { $page_title = str_replace(“+”, ” “, $path["5"]); }
}
if(($page_title == “”) && ($path["1"] == “category”)) { $page_title = “Category Listing”; }
// echo(“
\nCategory: “. $cid .”
\nItem: “. $aid .”
\nPage: “. $page .”
\n”);
// $cid, $task, $cid, $page
// End Path Info Translation
if(!isset($page_title) || ($page_title == “”)) { $page_title = “Item Category Listing”; }
if($cid != null) { $page_name = “public.list.php”; }
elseif($aid != null) { $page_name = “public.view.php”; }
else { $page_name = “public.index.php”; }
if($feed == 1) { $page_name = “public.rss.php”; $show_integration = 9; }
if($island == 1) { $page_name = “public.island.php”; $show_integration = 9; }
if($latest == 1) { $page_name = “public.latest.php”; $page_title = “Latest Items”; }
if($map == 1) { $page_name = “public.map.php”; $page_title = “Map”; }
if($popular == 1) { $page_name = “public.popular.php”; $page_title = “Most Popular Items”; }
if($random == 1) { $page_name = “public.random.php”; $show_integration = 9; }
if($last == 1) { $page_name = “public.last.php”; $show_integration = 9; }
As you can see, it is a bit more complicated than what it needs to be; so I’ve decided to clean it up a bit in the new pages:
// Path Info Translation
// ——————————
// Lets set some variables
$extensions = array(“.xml”, “.rss”, “.shtml”, “.html”, “.shtm”, “.htm”, “.phps”, “.php”);
$path = preg_split(‘/[\/]+/’, str_replace($extensions, “”, sanatize_data($_SERVER["PATH_INFO"])));
unset($path['0']);
// Split the array into useable chunks.
if(isset($_SERVER["PATH_INFO"])) {
if($path["1"] == “view”) {
$user_id = (int)$path["2"];
$user_name = $path["3"];
$page_title = “Viewing “. $user_name;
$page_name = “public.view.php”;
} elseif($path["1"] == “rss”) {
$page_name = “public.rss.php”;
$nocache = 1;
$show_integration = 9;
} else {
$page_title = “Staff Listing”;
$page_name = “public.index.php”;
}
} else {
$page_title = “Staff Listing”;
$page_name = “public.index.php”;
}
// End Path Info Translation
As you can see, the old is far more complicated than it needs to be; it has shortfalls that annoyed the crap out of me; the new code uses the older and works a little smoother for allowing short urls.
Design by Simon Fletcher. Powered by Tumblr.
© Copyright 2010