[Cs-content-commits] SF.net SVN: cs-content:[489] trunk/1.0
PHP Templating & Includes System
Brought to you by:
crazedsanity
|
From: <cra...@us...> - 2011-01-25 00:01:13
|
Revision: 489
http://cs-content.svn.sourceforge.net/cs-content/?rev=489&view=rev
Author: crazedsanity
Date: 2011-01-25 00:01:07 +0000 (Tue, 25 Jan 2011)
Log Message:
-----------
Move URL-cleaning to global functions so other classes can use it.
/cs_globalFunctions.class.php:
* clean_url() [NEW]:
-- derived from contentSystem::clean_url()
/contentSystem.class.php:
* clean_url():
-- mostly moved to cs_globalFunctions::clean_url(), except some
internally-specific things.
Modified Paths:
--------------
trunk/1.0/contentSystem.class.php
trunk/1.0/cs_globalFunctions.class.php
Modified: trunk/1.0/contentSystem.class.php
===================================================================
--- trunk/1.0/contentSystem.class.php 2011-01-19 15:36:24 UTC (rev 488)
+++ trunk/1.0/contentSystem.class.php 2011-01-25 00:01:07 UTC (rev 489)
@@ -331,52 +331,17 @@
}
//make sure we've still got something valid to work with.
- if(!strlen($section)) {
- //TODO: remove the extra return statement (should only be one at the bottom of the method).
- return(NULL);
- }
- else {
-
- //if there's an "APPURL" constant, drop that from the section.
- if(defined('APPURL') && strlen(constant('APPURL'))) {
- $dropThis = preg_replace('/^\//', '', constant('APPURL'));
- $dropThis = preg_replace('/\//', '\\/', $dropThis);
- $section = preg_replace('/^'. $dropThis .'/', '', $section);
+ if(strlen($section)) {
+ try {
+ $section = $this->gfObj->clean_url($section);
}
-
- //check the string to make sure it doesn't begin with a "/"
- if($section[0] == '/') {
- $section = substr($section, 1, strlen($section));
+ catch(Exception $e) {
+ //hide the exception and allow it to return NULL.
}
-
- //check the last char for a "/"...
- if($section[strlen($section) -1] == '/') {
- //last char is a '/'... kill it.
- $section = substr($section, 0, strlen($section) -1);
- }
-
- //if we've been sent a query, kill it off the string...
- if(preg_match('/\?/', $section)) {
- $section = split('\?', $section);
- $section = $section[0];
- }
-
- if(preg_match("/\./", $section)) {
- //disregard file extensions, but keep everything else...
- // i.e. "index.php/yermom.html" becomes "index/yermom"
- $tArr = explode('/', $section);
- $tSection = null;
- foreach($tArr as $tSecName) {
- $temp = explode(".", $tSecName);
- if(strlen($temp[0]) > 1) {
- $tSecName = $temp[0];
- }
- $tSection = $this->gfObj->create_list($tSection, $tSecName, '/');
- }
- $section = $tSection;
- }
}
-
+ else {
+ $section = null;
+ }
return($section);
}//end clean_url()
//------------------------------------------------------------------------
Modified: trunk/1.0/cs_globalFunctions.class.php
===================================================================
--- trunk/1.0/cs_globalFunctions.class.php 2011-01-19 15:36:24 UTC (rev 488)
+++ trunk/1.0/cs_globalFunctions.class.php 2011-01-25 00:01:07 UTC (rev 489)
@@ -878,7 +878,64 @@
return($this->debug_print($printThis, $printItForMe, $removeHr));
}//end debug_var_dump()
//##########################################################################
+
+
+
+ //------------------------------------------------------------------------
+ /**
+ * Removes all the crap from the url, so we can figure out what section we
+ * need to load templates & includes for.
+ */
+ public function clean_url($url=NULL) {
+ //make sure we've still got something valid to work with.
+ if(strlen($url)) {
+ //if there's an "APPURL" constant, drop that from the url.
+ if(defined('APPURL') && strlen(constant('APPURL'))) {
+ $dropThis = preg_replace('/^\//', '', constant('APPURL'));
+ $dropThis = preg_replace('/\//', '\\/', $dropThis);
+ $url = preg_replace('/^'. $dropThis .'/', '', $url);
+ }
+
+ //check the string to make sure it doesn't begin with a "/"
+ if($url[0] == '/') {
+ $url = substr($url, 1, strlen($url));
+ }
+
+ //check the last char for a "/"...
+ if($url[strlen($url) -1] == '/') {
+ //last char is a '/'... kill it.
+ $url = substr($url, 0, strlen($url) -1);
+ }
+
+ //if we've been sent a query, kill it off the string...
+ if(preg_match('/\?/', $url)) {
+ $url = split('\?', $url);
+ $url = $url[0];
+ }
+
+ if(preg_match("/\./", $url)) {
+ //disregard file extensions, but keep everything else...
+ // i.e. "index.php/yermom.html" becomes "index/yermom"
+ $tArr = explode('/', $url);
+ $tUrl = null;
+ foreach($tArr as $tUrlPart) {
+ $temp = explode(".", $tUrlPart);
+ if(strlen($temp[0]) > 1) {
+ $tUrlPart = $temp[0];
+ }
+ $tUrl = $this->create_list($tUrl, $tUrlPart, '/');
+ }
+ $url = $tUrl;
+ }
+ }
+ else {
+ throw new exception(__METHOD__ .": invalid url (". $url .")");
+ }
+ return($url);
+ }//end clean_url()
+ //------------------------------------------------------------------------
+
}//end cs_globalFunctions{}
?>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|