------------------------------------------------------------
revno: 1129
committer: Jakub Jankiewicz <[email protected]>
branch nick: aikiframework
timestamp: Thu 2012-03-08 14:08:33 +0100
message:
  add slash at the end of url and code clean up
modified:
  libs/aiki.php


--
lp:aikiframework
https://code.launchpad.net/~aikiframework-devel/aikiframework/trunk

Your team Aiki Framework Developers is subscribed to branch lp:aikiframework.
To unsubscribe from this branch go to 
https://code.launchpad.net/~aikiframework-devel/aikiframework/trunk/+edit-subscription
=== modified file 'libs/aiki.php'
--- libs/aiki.php	2012-03-02 14:35:05 +0000
+++ libs/aiki.php	2012-03-08 13:08:33 +0000
@@ -42,7 +42,7 @@
 
 
 	public function __construct() {
-		$this->pretty_url = isset($_GET["pretty"]) ?  $_GET["pretty"] : "" ;
+		$this->pretty_url = isset($_GET["pretty"]) ? $_GET["pretty"] : "";
 	}
 
    
@@ -68,7 +68,7 @@
 	public function load($class) {
 		global $AIKI_ROOT_DIR;
 
-		if (isset($this->$class)){
+		if (isset($this->$class)) {
 			return $this->$class;
 		}
 		// Try to load the class file in /libs, assets/extensions and
@@ -81,10 +81,10 @@
 			$allowed = "," . $this->config->get("extensions_allowed", "ALL") . ",";   
 			// a tip..be sure "web" doesn't match "web2date".
 					
-			if ( $allowed != ",ALL," ) {		
-				if ( $allowed == ",NONE," or strpos($allowed, $class)===false ) {
-					return false;   
-				}				
+			if ($allowed != ",ALL,") {
+				if ($allowed == ",NONE," or strpos($allowed, $class) === false) {
+					return false;
+				}
 			}
 			 
 			// search in dirs	   
@@ -135,7 +135,7 @@
 
 		// go through every config record. if the config item
 		// is not already set then use the database record
-		if ( !is_null($settings) ) {
+		if (!is_null($settings)) {
 			foreach ($settings as $setting_group) {
 
 				// unserialize array key => value pairs stored
@@ -150,7 +150,11 @@
 				}
 			}
 		}
-
+		if (isset($config['url'])) {
+			if ($config['url'][strlen($config['url'])-1] != '/') {
+  				$config['url'] .= '/';
+			}
+		}
 		return $config;
 	}
 
@@ -164,12 +168,12 @@
 	 */
 	public function get_string_between($string, $start, $end) {
 		$ini = strpos($string,$start);
-		if ( $ini ===false ) {
+		if ($ini === false) {
 			return "";
 		}
 		$ini += strlen($start);
-		$len = strpos($string,$end,$ini) - $ini;
-		return substr($string,$ini,$len);
+		$len = strpos($string, $end, $ini) - $ini;
+		return substr($string, $ini, $len);
 	}
 
 
@@ -190,7 +194,7 @@
 		$html_entities = array("&#41;", "&#40;", "&#91;", "&#93;", "&#123;",
 							   "&#124;", "&#125;", "&#60;", "&#62;", "&#95;");
 
-		$text = str_replace($html_chars, $html_entities,$text);
+		$text = str_replace($html_chars, $html_entities, $text);
 
 		return $text;
 	}
@@ -203,9 +207,9 @@
 	 *
 	 * @return boolean
 	 */
-	function match_pair_one( $condition, $var){
-		if ( $condition=='*' || $condition=='' || $condition==$var ||
-			 ( substr($condition,0,1)=="!" &&  $condition<>"!$var" ) ) {
+	function match_pair_one($condition, $var){
+		if ($condition == '*' || $condition == '' || $condition == $var ||
+			 ( substr($condition,0,1) == "!" &&  $condition <> "!$var")) {
 			return true;
 		}
 		return false;
@@ -220,23 +224,22 @@
 	 *
 	 * @return boolean
 	 */
-	function match_pair( $condition,$first, $second="*", $third ="*") {
+	function match_pair($condition,$first, $second="*", $third ="*") {
 		//clean conditions,
-		$condition= strtr(
-						$condition,
-						array("\n" =>" ",
-							","  =>" ",
-							"\r" =>" "));
+		$condition= strtr($condition,
+						array("\n" => " ",
+							","  => " ",
+							"\r" => " "));
 		$condition= preg_replace('/\s{2,}/', ' ', $condition); //clean double space
 		$condition= trim($condition);
 
 		$matches = explode(" ", $condition);
 
 		foreach ($matches as $match) {
-			$pair = explode("/", $match, 3) + array("*","*","*");
-			if ( $this->match_pair_one($pair[0],$first) &&
+			$pair = explode("/", $match, 3) + array("*", "*", "*");
+			if ($this->match_pair_one($pair[0],$first) &&
 				 $this->match_pair_one($pair[1],$second) &&
-				 $this->match_pair_one($pair[2],$third) ) {
+				 $this->match_pair_one($pair[2],$third)) {
 				return true;
 			}
 		}
@@ -261,17 +264,17 @@
 		$i= 10 ; //max level of recursion.
 
 		$start = strpos($string, $startDelim);
-		if ( $start === false ) {
+		if ($start === false) {
 			return false;
 		}
 
 		do {
-
-			$end  = strpos($string, $endDelim, $start);
-			if ( $end === false )
+			$end = strpos($string, $endDelim, $start);
+			if ($end === false) {
 				return false;
+			}
 			$nested = strpos($string, $startDelim, $start+1);
-			if ( $nested === false || $nested > $end ) {
+			if ($nested === false || $nested > $end) {
 				$position = array($start, $end) ;
 				return true;
 			}
@@ -293,22 +296,22 @@
 	 *                2 delim
 	 */
 		
-	function outer_markup ( $string , $offset=0 ){
-        $i= 64; //max level of recursion.
-        $delim= "";
+	function outer_markup($string, $offset=0 ){
+        $i = 64; //max level of recursion.
+        $delim = "";
         
-		$temp ="";
-		if ( preg_match ('/\(([a-z_]*)\(/U', $string, $temp)  ){
-			$delim      = $temp[1];
-			$startDelim ="($delim(";
-			$endDelim   =")$delim)";
+		$temp = "";
+		if (preg_match('/\(([a-z_]*)\(/U', $string, $temp)) {
+			$delim = $temp[1];
+			$startDelim = "($delim(";
+			$endDelim = ")$delim)";
 			$temp = "";				
 		} else {
 			return false;
 		}			
 		               
-        $initial = strpos ($string, $startDelim, $offset);
-        if ( $initial === false ) {
+        $initial = strpos($string, $startDelim, $offset);
+        if ($initial === false) {
             return false;
         }
 
@@ -320,10 +323,11 @@
             $nested = strpos($string, $startDelim, $nested+1);
             $end    = strpos($string, $endDelim, $end+1);
             
-            if ( $end === false )
+            if ($end === false) {
                 return false;
-            if ( $nested === false || $nested > $end ){
-				return array($initial, $end-$initial,$delim);				
+            }
+            if ($nested === false || $nested > $end) {
+				return array($initial, $end-$initial, $delim);
             }
                             
             $i--;
@@ -348,15 +352,15 @@
 	 */
 	function eval_expression($expr, &$var) {
 		$matches = 0;
-		if ( $expr == "" ) {
+		if ($expr == "") {
 			return 0;
-		}elseif (preg_match('/^[+-]?[0-9]*(\.[0-9]*)?$/', $expr, $matches)) {
+		} elseif (preg_match('/^[+-]?[0-9]*(\.[0-9]*)?$/', $expr, $matches)) {
 			return (float) $expr;
 		} elseif (preg_match('/^\$([a-z_]+[a-z_0-9]*)$/i', $expr, $matches)) {		
 			return ( isset($var[$matches[1]]) ? $var[$matches[1]] : 0 );
-		} elseif (preg_match('/^(.*)\(([^\(\)]*)\)(.*)$/i', $expr, $matches) ) {
+		} elseif (preg_match('/^(.*)\(([^\(\)]*)\)(.*)$/i', $expr, $matches)) {
 			return meval($matches[1] . meval($matches[2],$var) . $matches[3], $var);
-		} elseif (preg_match('~^(.*)([\+\-/\\\*%])(.*)$~', $expr, $matches)){
+		} elseif (preg_match('~^(.*)([\+\-/\\\*%])(.*)$~', $expr, $matches)) {
 			 $op1= meval($matches[1], $var);
 			 $op2= meval($matches[3], $var);
 			 if( is_null($op1) || is_null($op2) ) {
@@ -395,7 +399,7 @@
 		$pretty = $aiki->config->get('pretty_urls', 1);
 		$url = $aiki->config->get('url');
 
-		if ( $bufferReplace == NULL ) {
+		if ($bufferReplace == NULL) {
 			
 			$current_month = date("n");
 			$current_year = date("Y");
@@ -414,12 +418,12 @@
 			if ($view_prefix) {
 				$paths[] = $view_prefix;
 			}
-			if ( count($aiki->site->languages()) > 1 ) {
+			if (count($aiki->site->languages()) > 1) {
 				$paths[] = $language;
 			}
 			$paths = implode("/",$paths);
 			
-			if ( isset($_SERVER["HTTPS"])) {
+			if (isset($_SERVER["HTTPS"])) {
 				$url = str_replace("http://";, "https://";, $url);
 			}	
 			$trimedUrl = preg_replace('#/$#',"",$url); // reg: remove ending /
@@ -450,17 +454,17 @@
 				'[route-local]'	 => $paths );
 									
 			// substitute all [POST[key]] and [GET[key]]
-			if ( $aiki->config->get("show_gets", true) ){
-				foreach ( $_GET as $key => $value ){
+			if ($aiki->config->get("show_gets", true)) {
+				foreach ($_GET as $key => $value) {
 					$bufferReplace["[GET[$key]]"] = $value;				
 				}			
 			}	
 			
 			if ($aiki->config->get("show_posts", true)) {
-				foreach ( $_POST as $key => $value ) {
+				foreach ($_POST as $key => $value) {
 					$bufferReplace["[POST[$key]]"] = $value;				
 				}					
-			}	
+			}
 				
 		}
 				

_______________________________________________
Mailing list: https://launchpad.net/~aikiframework-devel
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~aikiframework-devel
More help   : https://help.launchpad.net/ListHelp

Reply via email to