------------------------------------------------------------
revno: 909
committer: Roger Martin <[email protected]>
branch nick: aikiframework
timestamp: Mon 2011-10-10 21:55:05 +0200
message:
  processVar improved
modified:
  src/libs/aiki.php
  src/libs/config.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 'src/libs/aiki.php'
--- src/libs/aiki.php	2011-10-09 20:47:13 +0000
+++ src/libs/aiki.php	2011-10-10 19:55:05 +0000
@@ -332,88 +332,91 @@
      *
      * @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)
     {
-        global $aiki, $page, $membership, $config;
-
-        /**
-         * @todo Setting variables really doesn't have a place in this function
-         */
-        if ( function_exists('date_default_timezone_set') &&
-             function_exists('date_default_timezone_get') )
-        {
-            if ( isset($config['timezone']) and !empty($config['timezone']) )
-                date_default_timezone_set($config['timezone']);
-            else
-                date_default_timezone_set(@date_default_timezone_get());
-        }
-
-        $current_month = date("n");
-        $current_year  = date("Y");
-        $current_day   = date("j");
-
-        // calculate view, prefix, route
-        $view       = $aiki->site->view();
-        $language   = $aiki->site->language();
-        $prefix     = $aiki->site->prefix();
-        $view_prefix= $aiki->site->view_prefix();
-        $paths[]= $config['url'];
-
-        if ( $prefix )      { $paths[] = $prefix; }
-        if ( $view_prefix)  { $paths[] = $view_prefix; }
-        if ( count($aiki->site->languages()) > 1 ){ $paths[] = $language; }
-
-        if ($config['pretty_urls'] == 0){
-            $text = preg_replace('/href\=\"\[root\](.*)\"/U',
-                                 'href="[root]?pretty=\\1"', $text);
-        }
-
-        $aReplace = array (
-            '[userid]'    => $membership->userid,
-            '[full_name]' => $membership->full_name,
-            '[language]'  => $aiki->site->language(),
-            '[username]'  => $membership->username,
-            '[page]'      => $page,
-            '[site_name]' => $aiki->site->site_name(),
-            '[site]'      => $aiki->site->get_site(),
-            '[view]'      => $aiki->site->view(),
-            '[direction]' => $aiki->languages->dir,
-            'insertedby_username' => $membership->username,
-            'insertedby_userid' => $membership->userid,
-            'current_month' => $current_month,
-            'current_year' => $current_year,
-            'current_day' => $current_day,
-            '[root]'          => $config['url'],
-            '[root-language]' => $config['url'].  "/" . $aiki->site->language(),
-            '[site_prefix]'   => $prefix ,
-            '[view_prefix]'   => $view_prefix ,
-            '[route]'         => implode("/",$paths) );
-        $text= strtr ( $text, $aReplace );
-
-        //@TODO by rg1024, this hack is necesary...
-        $text = str_replace($config['url'].'/', $config['url'], $text);
-
-        // substitute all [POST[key]] and [GET[key]]
-        $matches= array();
-        if ( preg_match_all("/\[(POST|GET)\[(.*)\]\]/U", $text, $matches)){
-
-            foreach ($matches[0] as $i => $match) {
-                $method= $matches[1][$i];
-                $key   = $matches[2][$i];
-                if ( $method=="GET" && isset($_GET[$key])) {
-                    $value = $_GET[$key];
-                } elseif ($method=="POST" && isset($_POST[$key])) {
-                    $value = $_POST[$key];
-                } else {
-                    $value="";
-                }
-                $replace[$match] = $value;
-            }
-            $text = strtr( $text, $replace);
-       }
-
-    return $text;
+		static $bufferReplace;
+        global $aiki, $page ;
+
+        $pretty = $aiki->config->get('pretty_urls',1);
+		$url    = $aiki->config->get('url');
+                              
+		if ($bufferReplace== NULL) {
+			
+			$current_month = date("n");
+			$current_year  = date("Y");
+			$current_day   = date("j");
+
+			// calculate view, prefix, route
+			$view       = $aiki->site->view();
+			$language   = $aiki->site->language();
+			$prefix     = $aiki->site->prefix();
+			$view_prefix= $aiki->site->view_prefix();
+			$paths[]    = $url;
+
+			if ( $prefix )      { $paths[] = $prefix; }
+			if ( $view_prefix)  { $paths[] = $view_prefix; }
+			if ( count($aiki->site->languages()) > 1 ){ $paths[] = $language; }
+
+			$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(),           
+				'[page]'      => $page,
+				'[site_name]' => $aiki->site->site_name(),
+				'[site]'      => $aiki->site->get_site(),
+				'[view]'      => $aiki->site->view(),
+				'[direction]' => $aiki->languages->dir,
+				'insertedby_username' => $aiki->membership->username,
+				'insertedby_userid' => $aiki->membership->userid,
+				'current_month' => $current_month,
+				'current_year' => $current_year,
+				'current_day' => $current_day,
+				'[root]'          => $url,
+				'[root-language]' => $url .  "/" . $aiki->site->language(),
+				'[site_prefix]'   => $prefix ,
+				'[view_prefix]'   => $view_prefix ,
+				'[route]'         => implode("/",$paths) );
+		
+			// substitute all [POST[key]] and [GET[key]]
+			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){
+					$bufferReplace[ "[POST[$key]]" ] = $value;				
+				}		            
+			}	
+				
+		}
+				
+        if ( $pretty){
+			/* TODO improve this*/		
+			$text = preg_replace(
+				'/href\=\"\[root\](.*)\"/U',
+				'href="[root]?pretty=\\1"', 
+				$text);
+		}
+		
+		$text = strtr( $text, $bufferReplace);
+		
+		// remove all [GET[foo]] or [POST[bar]]
+		$text = preg_replace ( '#\[(GET|POST)\[.*\]\]#U', "", $text );
+				
+		//@TODO by rg1024, this hack is necesary...
+		$text = str_replace($url.'/', $url, $text);
+		return $text;
+
     } // end of processVars method
 } // end of aiki class

=== modified file 'src/libs/config.php'
--- src/libs/config.php	2011-10-08 21:38:31 +0000
+++ src/libs/config.php	2011-10-10 19:55:05 +0000
@@ -44,6 +44,30 @@
 
 
 	/**
+	 * set timezone calling date_default_timezone_set
+	 * 
+	 * @return void 
+	 * 
+	 */
+
+	function set_timezone(){
+				
+		if ( function_exists('date_default_timezone_set') &&
+             function_exists('date_default_timezone_get') )
+        {
+			$timezone= $this->get("timezone", false);
+            if ( $timezone ) {
+                date_default_timezone_set($timezone);
+            } else {
+				// see http://php.net/manual/en/function.date-default-timezone-get.php to understand this				
+                date_default_timezone_set( @date_default_timezone_get());
+            }
+        }
+		
+	}
+
+
+	/**
 	 * Load configuration for actual site/view/language
 	 * 
 	 * The constructor calls this methods, so use this method 
@@ -90,6 +114,10 @@
 				$count++;
 			}
 		}		
+		
+		// special config values
+		$this->set_timezone();
+		
 		return $count;		    
 	}
 

_______________________________________________
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