------------------------------------------------------------
revno: 1098
committer: Roger Martin <[email protected]>
branch nick: aikiframework
timestamp: Sun 2012-02-19 21:19:24 +0100
message:
  engines enabled per site
modified:
  assets/apps/upgrader/upgrades.php
  configs/changelog.php
  configs/last-revision
  index.php
  libs/Engine_v8.php
  libs/site.php
  libs/widgets.php
  sql/CreateTables.sql
  sql/UpdateDefaults.sql


--
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 'assets/apps/upgrader/upgrades.php'
--- assets/apps/upgrader/upgrades.php	2012-02-05 17:33:06 +0000
+++ assets/apps/upgrader/upgrades.php	2012-02-19 20:19:24 +0000
@@ -26,5 +26,9 @@
 //                 "UPDATE aiki_foo SET bar='foo'", 
 //                 "UPDATE aiki_bar SET bar=1");
 
+
+// revision 1097 introduces engines for site.
+$upgrades[1097]= 'UPDATE aiki_sites SET site_engine="aiki" WHERE site_engine="" OR site_engine is null';
+
 // Revision 942 changes old php script markup with new (script(....)script)
 $upgrades[942] =  'UPDATE aiki_widgets SET widget=REPLACE( REPLACE(widget,"<php ","(script("),"php>",")script)");';

=== modified file 'configs/changelog.php'
--- configs/changelog.php	2012-02-01 22:40:03 +0000
+++ configs/changelog.php	2012-02-19 20:19:24 +0000
@@ -17,6 +17,7 @@
  */
  
 
+ $changes[1097]= "Engines enabled per site";
  $changes[1056]= "Installer Added";
  $changes[1050]= "Fix instant login bug";
  $changes[1040]= "Added rel next and prev to pagination for SEO";

=== modified file 'configs/last-revision'
--- configs/last-revision	2012-02-01 22:40:03 +0000
+++ configs/last-revision	2012-02-19 20:19:24 +0000
@@ -1,1 +1,1 @@
-1057 [email protected]
+1097 [email protected]

=== modified file 'index.php'
--- index.php	2012-02-17 21:11:13 +0000
+++ index.php	2012-02-19 20:19:24 +0000
@@ -45,14 +45,12 @@
  */
 $html_cache_file = $aiki->Output->cache_file();
 
+$engineType = $aiki->site->engine();
 
-$engineType = config("engine","aiki");
 
 if ( $engineType =="aiki" ){
-
-	/**
-	 * @see widgets.php
-	 */
+	// Content is generated by old aiki engine
+	
 	require_once("libs/Engine_aiki.php");
 	$layout = new Engine_Aiki();
 	$layout->layout();	
@@ -78,12 +76,14 @@
 	$html_output = $aiki->languages->L10n($html_output);
 
 } elseif  ( file_exists( "$AIKI_ROOT_DIR/libs/Engine_$engineType.php") ) {	
+	// content is generated by a engine 
     include "$AIKI_ROOT_DIR/libs/Engine_$engineType.php";
-    $engineClass= "Engine_" . $engineType;    
+    $engineClass= "Engine_" . $engineType;       
     $engine = new $engineClass();
-    $html_output = $engine->layout();
+    $html_output = $engine->layout($aiki->site->engine_parameters());    
 	
 } else {
+	// engine is no valid
 	$html_output = 
 		"<p>".
 		t( sprintf('Unkown engine %1$s. File /libs/Engine_%1$s.php doesn\'t exists.',$engineType)).
@@ -132,6 +132,6 @@
 if ( is_debug_on() ){
 	$end = (float)array_sum(explode(' ',microtime()));
 	$end_time = sprintf("%.4f", ($end-$start_time));
-	echo "\n <!-- queries: ".$db->num_queries." -->\n";
+	echo "\n <!-- Queries: ".$db->num_queries." -->\n";
 	echo "\n <!-- Time: ".$end_time." seconds -->";
 }

=== modified file 'libs/Engine_v8.php'
--- libs/Engine_v8.php	2012-02-17 21:11:13 +0000
+++ libs/Engine_v8.php	2012-02-19 20:19:24 +0000
@@ -33,7 +33,7 @@
 	 * Create layout
 	 */
 
-	function layout(){
+	function layout( $parameters ){
 		global $db, $aiki;
 
 		// Initialize

=== modified file 'libs/site.php'
--- libs/site.php	2012-02-11 23:09:09 +0000
+++ libs/site.php	2012-02-19 20:19:24 +0000
@@ -8,7 +8,7 @@
  * This source file is subject to the AGPL-3.0 license that is bundled
  * with this package in the file LICENSE.
  *
- * @author      Roger Martin 
+ * @author      Roger Martin
  * @copyright   (c) 2008-2011 Aiki Lab Pte Ltd
  * @license     http://www.fsf.org/licensing/licenses/agpl-3.0.html
  * @link        http://www.aikiframework.org
@@ -26,80 +26,79 @@
 
 
 class Site {
- 
-	private $site; 
-	private $site_name; 
+
+	private $site; // contains all information of site:
+
 	private $languages; // a array like [0]=>'en',[1]=>'fr'...
 	private $need_translation;
 	private $default_language;
 	private $widget_language;
-	private $site_prefix; 
 	private $site_view;
 	private $site_view_prefix;
 
 	/**
-	 * return site view 
-	 * @return string 
-	 */	  
+	 * return site view
+	 * @return string
+	 */
 
 	function view() {
-		return $this->site_view;		
+		return $this->site_view;
 	}
-	
+
 	 /**
 	 * return site view prefix
-	 * @return string 
-	 */	  
+	 * @return string
+	 */
 
 	function view_prefix() {
-		return $this->site_view_prefix;		
+		return $this->site_view_prefix;
 	}
-	
-	
+
+
 	/**
 	 * return site prefix
-	 * @return string 
-	 */	  
+	 * @return string
+	 */
 
 	function prefix() {
-		return $this->site_prefix;		
+		return $this->site->site_prefix;
 	}
-	
-	
+
+
 	 /**
 	 * return the default language of a site.
 	 * @return string language
-	 */	  
-	function language($new=NULL) {		
+	 */
+	function language($new=NULL) {
 		global $aiki;
 		if (!is_null($new)) {
-			if (in_array($new, $this->languages)) {	
+			if (in_array($new, $this->languages)) {
 				$this->default_language = $new;
 				$this->need_translation = ($new != $this->widget_language);
-				return true;				
+				return true;
 			} else {
 				return false;
-			}	 
+			}
 		}
 		return $this->default_language;
-	}  
-	
-	
+	}
+
+
 	/**
 	 * return list (array) of allowed languages in a site.
 	 * @return array languages
-	 */	 
+	 */
 	function languages() {
 		return $this->languages;
-	}  
-	
+	}
+
 	/**
 	 * return site
 	 * @return string Return site short name
-	 */	 
+	 */
 	function get_site() {
-		return $this->site;
-	}   
+		return $this->site->site_shortcut;
+	}
 
 
 	/**
@@ -107,9 +106,46 @@
 	 * @return string Return site long name
 	 */
 	function site_name() {
-		return $this->site_name;
+		return $this->site->site_name;
 	}
 
+
+	/**
+	 * return site engine (aiki by default)
+	 * @return string
+	 */
+	function engine() {
+		if ( !isset($this->site->site_engine) ||  $this->site->site_engine=="" ){
+			return "aiki";
+		}
+		return $this->site->site_engine;
+    }
+
+
+	/**
+	 * return site engine parameters
+	 * @return arrays
+	 */
+	function engine_parameters() {
+		if ( !isset($this->site->site_engine_parameters) || isset($this->site->site_engine_parameters)=="" ){
+			return array();
+		}
+
+		// parameters is a string width pair of var=value or var, separated ";"
+		// example: checkHtml;markup=c;debug=on;
+		foreach ($data= explode(";",$this->site->site_engine_parameters) as $pair ){
+			$npos=strpos($pair,"=");
+			if ($npos){
+				$ret[ substr($pair,0,$npos)] = substr($pair,$npos+1);
+			} else {
+				$ret[$pair]=1;
+			}
+		}
+
+		return $ret;
+    }
+
+
 	/**
 	 * return true if site need to be translated
 	 * @return boolean
@@ -124,108 +160,133 @@
 	 */
 
 	function __toString() {
-		return $this->site;
-	}
-
-	/** 
+		return $this->site->site_shortcut;
+	}
+
+
+	/**
+	 * set site, checking if is active or closed.
+	 * @param mixed Object (site) or a sitename
+	 */
+
+    private function set_site($sitename) {
+		global $db, $config, $aiki;
+		if ( !is_string($sitename) ) {
+			// $sitename is a object
+			$this->site = $sitename;
+			$config['site'] = $sitename->site_shortcut;
+			return ;
+		}
+
+		// search site
+		$site = $db->get_row("SELECT * from aiki_sites where site_shortcut='$sitename' limit 1");
+		if ( is_null($site) ){
+			// not found
+			die($aiki->message->error( t("Fatal Error: Wrong site name provided.") ,NULL,false));
+		} elseif ( $site->is_active != 1 ) {
+			// not active or closed;
+			die($aiki->message->error($site->if_closed_output ? $info->if_closed_output : t("Site $sitename is closed."),
+					NULL,
+					false));
+		} else {
+			$this->site = $site;
+			$config['site'] = $sitename;
+		}
+	}
+
+
+	/**
 	 * Constructor: set site name or die if is inexistent or inactive.
 	 * The site is established by (in this order), GET[site], $config[site]
 	 * and finaly Default.
-	 * 
+	 *
 	 * @global $db
-	 * @global $config 
+	 * @global $config
 	 */
 
 	function __construct() {
 		global $db, $config, $aiki;
-		
+
 		// determine site name
-		if (isset($_GET['site'])) {
-			$config['site'] = addslashes($_GET['site']);
+
+		// when aiki receive directly the wigdet to render, widget_site is set as site
+		$widget= isset($_GET["widget"]) ? $aiki->widgets->get_widget($_GET['widget'],false) : NULL ;
+
+		if ( !is_null($widget)){
+			// 1. site is determind by widget
+			$this->set_site($widget->widget_site);
+		} elseif (isset($_GET['site'])) {
+			// 2. site is given
+			$this->set_site($_GET['site']);
 		} else {
-			if (!isset($config['site'])) {
-				$config['site'] = 'default';
-			}	
-		 
-			// determine site by url (for multisite and apps)
-			$this->site_prefix = "";							
+
+			// 3. try determine site by url (for multi-site and apps)
+			$this->site_prefix = "";
 			$path = $aiki->url->first_url();
-			if ( $path != "homepage" ) {
-				$site= $db->get_var("SELECT site_shortcut from aiki_sites where site_prefix='$path'");
-				if ($site){
-					$config['site'] = $site;					
-					$aiki->url->shift_url();
-					$this->site_prefix = $path;				  
-				}	
-			}						
-		}
-		
-		// try read site information and test if is_active.
-		$info = $db->get_row("SELECT * from aiki_sites where site_shortcut='{$config['site']}' limit 1");		
-		if (is_null($info)) {		
-			die($aiki->message->error("Fatal Error: Wrong site name provided. " ,NULL,false));
-		} elseif ( $info->is_active != 1 ) {
-			die($aiki->message->error($info->if_closed_output ? $info->if_closed_output : "Site {$config['site']} is closed.",
-				NULL,
-				false));
-		}
-			
+			$site = ($path == "homepage" ? NULL : $db->get_row("SELECT * FROM aiki_sites WHERE is_active!=0 AND site_prefix='$path'"));
+			if ( is_null($site) ) {
+				// 4 by config[site] else default.
+				$this->set_site ( ( isset($config['site']) ? $config['site'] : 'default' ) );
+			} else {
+				$path = $aiki->url->shift_url();
+				$this->set_site($site);
+			}
+
+		}
+
 		// determine view
 		if (isset($_GET['view'])) {
-			$this->site_view= addslashes($_GET['view']);			 
+			$this->site_view= addslashes($_GET['view']);
 		} else {
 			$prefix = $aiki->url->first_url();
 			$view = $db->get_var("SELECT view_name, view_prefix FROM aiki_views " .
 					" WHERE view_site='{$config['site']}' AND view_active='1' AND view_prefix='$prefix'");
 			if ($view) {
-				$aiki->url->shift_url();			
+				$aiki->url->shift_url();
 				$this->site_view = $view;
-				$this->site_view_prefix = $prefix;						
+				$this->site_view_prefix = $prefix;
 			}
-		}	 
-								
+		}
+
 		// define default language, list of allowed languages
-		$this->default_language = ( $info->site_default_language ? 
-			$info->site_default_language :
+		$this->default_language = ( $this->site->site_default_language ?
+			$this->siteo->site_default_language :
 			"en" );
-		$this->languages = ( $info->site_languages ? 
-			explode(",", $info->site_languages) : 
+		$this->languages = ( $this->site->site_languages ?
+			explode(",", $this->site->site_languages) :
 			array($this->default_language) );
-			
-		$this->widget_language  = ( $info->widget_language ? 
-			$info->widget_language : 
+
+		$this->widget_language  = ( $this->site->widget_language ?
+			$this->site->widget_language :
 			$this->default_language );
-		
-		if (!in_array($this->default_language, $this->languages)) { 
+
+		if (!in_array($this->default_language, $this->languages)) {
 			// correction: include default in allowed languages.
 			$this->languages[]= $this->default_language;
-		}				
-		
-		// determine language 
-		if (isset($_GET['language'])) {			
+		}
+
+		// determine language
+		if (isset($_GET['language'])) {
 			$this->language(addslashes($_GET['language']));
 		} elseif ($this->language($aiki->url->first_url())) {
-			$aiki->url->shift_url();			
+			$aiki->url->shift_url();
 		}
 		$this->need_translation = ($this->default_language != $this->widget_language);
 
-		//  the site manages dictionaries		
+		//  the site manages dictionaries
 		if ( $this->default_language != "en" ) {
 			$aiki->dictionary->add("core", new dictionaryTable($this->default_language));
 			$aiki->dictionary->translateTo($this->default_language);
-		}			
-		
+		}
+
 		if ( $this->widget_language != "en" ) {
 			$aiki->dictionary->translateFrom($this->widget_language);
 			$aiki->dictionary->add($config['site'], new dictionaryTable($this->default_language,$this->widget_language));
-		}	
+		}
 
 		// language
 		$aiki->languages->set( $this->language());
 
-		// site names
-		$this->site = $config['site'];
-		$this->site_name = $info->site_name;
 	}
 }
 

=== modified file 'libs/widgets.php'
--- libs/widgets.php	2012-02-17 21:11:13 +0000
+++ libs/widgets.php	2012-02-19 20:19:24 +0000
@@ -33,16 +33,16 @@
  */
 
 class widgets {
-    
+
     /**
      * return sql filter to select only widget of current apps & engine
      *
      * @return string part of a SQL WHERE clausule
      */
 
-	private function widget_scope (){
-		global $aiki;		
-		return "is_active=1 AND ( widget_site='{$aiki->site}' OR widget_site ='aiki_shared')"	;
+	private function widget_scope ( $checkSite= true  ){
+		global $aiki;
+		return "is_active=1" . ( $checkSite ? " AND ( widget_site='{$aiki->site}' OR widget_site ='aiki_shared')": "");
 	}
 
 	/**
@@ -55,7 +55,7 @@
      */
 
     function get_candidate_widgets($father=0) {
-        global $db, $aiki;        
+        global $db, $aiki;
         $search = $aiki->url->url[0];
         $SQL =
             "SELECT id, display_urls, kill_urls, widget_name, widget_target, css<>'' as have_css" .
@@ -65,7 +65,7 @@
             " (display_urls LIKE '%$search%' OR display_urls = '*' OR ".
             " display_urls LIKE '%#%#%') AND " .
             " (kill_urls='' OR kill_urls not rlike '^$search\$|^$search\\\\||\\\\|$search\$|\\\\|$search\\\\|') " .
-            " ORDER BY  display_order, id";         
+            " ORDER BY  display_order, id";
          return $db->get_results($SQL);
     }
 
@@ -75,7 +75,7 @@
      *
      * @return array of id
      */
-    
+
     function get_page_not_found_widgets() {
         global $db, $aiki;
 
@@ -89,7 +89,7 @@
             " ORDER BY display_order, id";
         return $db->get_results($SQL);
     }
-    
+
     /**
      * lookup a widget by id or name
      *
@@ -108,24 +108,24 @@
      * @return object_Ezsql_row
      */
 
-	function get_widget($widgetNameOrId) {
-		return $this->get_widget_helper($widgetNameOrId, true);
+	function get_widget($widgetNameOrId, $checkSite = true) {
+		return $this->get_widget_helper($widgetNameOrId, true, $direct);
 	}
 
 
-    private function get_widget_helper($widgetNameOrId, $record=false) {
+    private function get_widget_helper($widgetNameOrId, $record=false, $checkSite=true) {
         global $db;
         if ( (int)$widgetNameOrId > 0 ) {
             $where= "id='$widgetNameOrId' AND is_active='1'";
-        } else {            			                       
-            $where = 
-                $this->widget_scope() ." AND ".
-				"widget_name='" . addslashes($widgetNameOrId) ."'"; // paranoic test.        
+        } else {
+            $where =
+                $this->widget_scope($checkSite) ." AND " .
+				"widget_name='" . addslashes($widgetNameOrId) ."'"; // paranoic test.
         }
 
         $searchSQL =
             "SELECT " . ($record? "*" :"id" ).  " FROM aiki_widgets ".
-            "WHERE {$where} LIMIT 1" ;        
+            "WHERE {$where} LIMIT 1" ;
         return ( $record ? $db->get_row($searchSQL) : $db->get_var($searchSQL));
     }
 

=== modified file 'sql/CreateTables.sql'
--- sql/CreateTables.sql	2012-01-15 00:22:15 +0000
+++ sql/CreateTables.sql	2012-02-19 20:19:24 +0000
@@ -224,6 +224,8 @@
   widget_language varchar(5) NOT NULL,
   site_prefix varchar(80) NOT NULL DEFAULT '',
   site_default_view varchar(32) NOT NULL,
+  site_engine varchar(32) NOT NULL DEFAULT 'aiki',
+  site_engine_parameters text NOT NULL,      
   PRIMARY KEY (site_id),
   KEY site_prefix (site_prefix)
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
@@ -440,4 +442,4 @@
   db_encoding varchar(255) NOT NULL,
   db_use_mysql_set_charset varchar(255) NOT NULL,
   PRIMARY KEY (id)
-) ENGINE=MyISAM DEFAULT CHARSET=utf8;;
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;

=== modified file 'sql/UpdateDefaults.sql'
--- sql/UpdateDefaults.sql	2012-02-06 22:18:41 +0000
+++ sql/UpdateDefaults.sql	2012-02-19 20:19:24 +0000
@@ -27,14 +27,14 @@
 aiki_widget 29 is last id for oficial aiki widget.
 aiki_forms id (1,4,6,9,12,13,17,18,20 are oficial
 
+DELETE FROM `aiki_forms` WHERE `id` IN (1,4,6,9,12,13,17,18,20);
+DELETE FROM `aiki_widgets` WHERE `id` < 30;
+-- ------------------------------------------------------
+
 */ 
 
 DELETE FROM `aiki_dictionary` WHERE `term_id` < 39;
 
--- ------------------------------------------------------
-
-DELETE FROM `aiki_forms` WHERE `id` IN (1,4,6,9,12,13,17,18,20);
-
--- ------------------------------------------------------
-
-DELETE FROM `aiki_widgets` WHERE `id` < 30;
+
+
+

_______________________________________________
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