------------------------------------------------------------
revno: 1157
committer: Jakub Jankiewicz <[email protected]>
branch nick: aikiframework
timestamp: Wed 2012-04-04 21:09:23 +0200
message:
  Add custom constants
modified:
  libs/AikiScript.php
  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/AikiScript.php'
--- libs/AikiScript.php	2012-04-03 06:57:14 +0000
+++ libs/AikiScript.php	2012-04-04 19:09:23 +0000
@@ -135,7 +135,7 @@
 					break;
 	
 				case '$aiki':
-					if (preg_match('/\$aiki\-\>(.*)\-\>(.*)\(([^\)]*)\)\;?/Us', 
+					if (preg_match('/\$aiki\-\>(.*)\-\>(.*)\((.*?)\)\;?/Us', 
 						$php_function, $partial)) {
 						$php_output = $this->aiki_function($partial[1],
 									  $partial[2], $partial[3]);

=== modified file 'libs/aiki.php'
--- libs/aiki.php	2012-03-14 21:46:05 +0000
+++ libs/aiki.php	2012-04-04 19:09:23 +0000
@@ -45,13 +45,13 @@
 		$this->pretty_url = isset($_GET["pretty"]) ? $_GET["pretty"] : "";
 	}
 
-   
+
 	/**
 	 * magic method that allowed on demand libs and extensions
 	 *
 	 * @return object loaded class or false
 	 */
-	public function __get ($what) {		
+	public function __get ($what) {
 		return $this->load($what);
 	}
 
@@ -76,18 +76,18 @@
 		if (file_exists($AIKI_ROOT_DIR . '/libs/' . $class . '.php')) {
 			require_once($AIKI_ROOT_DIR.'/libs/'.$class.'.php');
 		} else {
-			
+
 			// filter extensions..
-			$allowed = "," . $this->config->get("extensions_allowed", "ALL") . ",";   
+			$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;
 				}
 			}
-			 
-			// search in dirs	   
+
+			// search in dirs
 			$SearchIn = $this->config->get("extensions_dir", "assets/extensions");
 			$loaded = false;
 			foreach (explode(",", $SearchIn) as $dir) {
@@ -95,17 +95,17 @@
 					require_once($AIKI_ROOT_DIR . "/$dir/$class.php");
 					$loaded= true;
 					break;
-				} 
+				}
 				if (file_exists($AIKI_ROOT_DIR . "/$dir/$class/$class.php")) {
 					require_once($AIKI_ROOT_DIR . "/$dir/$class/$class.php");
 					$loaded= true;
 					break;
-				} 
-			
+				}
+
 			}
 			if (!$loaded) {
 				return false;
-			}							
+			}
 		}
 
 		$object = new $class();
@@ -295,41 +295,41 @@
 	 * @return mixed  false if not found or array with 0:initial,1:lenght
 	 *                2 delim
 	 */
-		
+
 	function outer_markup($string, $offset=0, $tag="[a-z_]*" ){
         $i = 64; //max level of recursion.
         $delim = "";
-        
+
 		$temp = "";
 		if (preg_match("/\(($tag)\(/U", $string, $temp)) {
 			$delim = $temp[1];
 			$startDelim = "($delim(";
 			$endDelim = ")$delim)";
-			$temp = "";				
+			$temp = "";
 		} else {
 			return false;
-		}			
-		               
+		}
+
         $initial = strpos($string, $startDelim, $offset);
         if ($initial === false) {
             return false;
         }
 
 		$end = $initial;
-		$nested = $initial;		
-        
+		$nested = $initial;
+
         do {
 
             $nested = strpos($string, $startDelim, $nested+1);
             $end    = strpos($string, $endDelim, $end+1);
-            
+
             if ($end === false) {
                 return false;
             }
             if ($nested === false || $nested > $end) {
 				return array($initial, $end-$initial, $delim);
             }
-                            
+
             $i--;
         } while ($i);
         return false;
@@ -337,9 +337,9 @@
 
 
 	/**
-	 * Eval a expression thats contains basic operators (+,-*,/), 
+	 * Eval a expression thats contains basic operators (+,-*,/),
 	 * parentsis, and variables.
-	 * 
+	 *
 	 * Example:
 	 *  $x*2
 	 *  ($x/2)-10
@@ -356,7 +356,7 @@
 			return 0;
 		} elseif (preg_match('/^[+-]?[0-9]*(\.[0-9]*)?$/', $expr, $matches)) {
 			return (float) $expr;
-		} elseif (preg_match('/^\$([a-z_]+[a-z_0-9]*)$/i', $expr, $matches)) {		
+		} 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)) {
 			return meval($matches[1] . meval($matches[2],$var) . $matches[3], $var);
@@ -378,7 +378,7 @@
 		return NULL;
 	}
 
-	
+
 	/**
 	 * Replace Aiki vars with their assigned values.
 	 *
@@ -386,10 +386,10 @@
 	 *
 	 * @param  string   $text before processing
 	 * @return string
-	 * 
+	 *
 	 * @global $aiki
 	 * @global $page
-	 * 
+	 *
 	 * @todo this function is seriously overloaded and needs to be rethought
 	 */
 	public function processVars($text) {
@@ -400,7 +400,7 @@
 		$url = $aiki->config->get('url');
 
 		if ($bufferReplace == NULL) {
-			
+
 			$current_month = date("n");
 			$current_year = date("Y");
 			$current_day = date("j");
@@ -410,7 +410,7 @@
 			$language = $aiki->site->language();
 			$prefix = $aiki->site->prefix();
 			$view_prefix= $aiki->site->view_prefix();
-			
+
 			$paths= array();
 			if ($prefix) {
 				$paths[] = $prefix;
@@ -422,19 +422,19 @@
 				$paths[] = $language;
 			}
 			$paths = implode("/",$paths);
-			
+
 			if (isset($_SERVER["HTTPS"])) {
 				$url = str_replace("http://";, "https://";, $url);
-			}	
+			}
 			$trimedUrl = preg_replace('#/$#',"",$url); // reg: remove ending /
-						
+
 			$bufferReplace = array(
 				'[userid]'	=> $aiki->membership->userid,
 				'[full_name]' => $aiki->membership->full_name,
 				'[username]'  => $aiki->membership->username,
 				'[user_group_level]' => $aiki->membership->group_level,
-				'[user_permissions]' => $aiki->membership->permissions,			
-				'[language]'  => $aiki->site->language(),		   
+				'[user_permissions]' => $aiki->membership->permissions,
+				'[language]'  => $aiki->site->language(),
 				'[page]'	  => $page,
 				'[site_name]' => $aiki->site->site_name(),
 				'[site]'	  => $aiki->site->get_site(),
@@ -452,35 +452,53 @@
 				'[route]'		 => $trimedUrl.  "/". $paths,
 				'[url]'           => $aiki->url->get(),
 				'[route-local]'	 => $paths );
-									
+
 			// substitute all [POST[key]] and [GET[key]]
 			if ($aiki->config->get("show_gets", true)) {
 				foreach ($_GET as $key => $value) {
-					$bufferReplace["[GET[$key]]"] = $value;				
-				}			
-			}	
-			
+					$bufferReplace["[GET[$key]]"] = $value;
+				}
+			}
+
 			if ($aiki->config->get("show_posts", true)) {
 				foreach ($_POST as $key => $value) {
-					$bufferReplace["[POST[$key]]"] = $value;				
-				}					
+					$bufferReplace["[POST[$key]]"] = $value;
+				}
 			}
-				
+
 		}
-				
+
 		if (!$pretty) {
-			/* TODO improve this*/		
+			/* TODO improve this*/
 			$text = preg_replace(
 				'/<a([^>]*)href\s*=\s*(["\'])\[root\](.*)\\2/U',
-				'<a\\1href=\\2[root]?pretty=\\3\\2', 
+				'<a\\1href=\\2[root]?pretty=\\3\\2',
 				$text);
 		}
-		
+
 		$text = strtr($text, $bufferReplace);
-		
-		// remove all [GET[foo]] or [POST[bar]]
+
+		// remove all [GET[foo]] or [POST[bar]] that where not processed
 		$text = preg_replace('#\[(GET|POST)\[.*\]\]#U', "", $text );
-				
+
+		// custom [vars]
+		if (preg_match_all("/\[([^\]]+)\]/", $text, $mached_vars)) {
+			$rgx = '/\$aiki\-\>(.*)\-\>(.*)\((.*?)\)\;?/Us';
+			foreach($mached_vars[1] as $var) {
+				$value = $aiki->config->get($var, null);
+				//value is function invocation
+				if (preg_match($rgx, $value, $mached_value)) {
+					$class = $mached_value[1];
+					$method = array($aiki->$class, $mached_value[2]);
+					$args = $aiki->AikiScript->mtoken($mached_value[3]);
+					$value = call_user_func_array($method, $args);
+				}
+				if ($value !== null) {
+					$text = preg_replace('/\[' . $var . '\]/', $value, $text);
+				}
+			}
+		}
+
 		//@TODO by rg1024, this hack is necesary...
 		$text = str_replace($url . '/', $url, $text);
 		return $text;

_______________________________________________
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