------------------------------------------------------------
revno: 1203
committer: Jakub Jankiewicz <[email protected]>
branch nick: aikiframework
timestamp: Mon 2012-05-28 19:55:38 +0200
message:
  Fix custom output and order of widgets
modified:
  libs/Engine_aiki.php
  libs/Output.php
  libs/widgets.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/Engine_aiki.php'
--- libs/Engine_aiki.php	2012-05-23 14:46:43 +0000
+++ libs/Engine_aiki.php	2012-05-28 17:55:38 +0000
@@ -82,25 +82,25 @@
      * @global aiki   $aiki
      * @TODO unusedParameters.
      */
-          
-    public function render( $unusedParameters ) {
+    
+    public function render($unusedParameters) {
         global $aiki;
-
         // Convert global_values to an object to cache the SOL results in parsDBpars function.
         $this->global_values = new stdClass();
 
-		$this->target = array(
-			"body"=>"" ,
-			"header"=>"",
-			"css"=>array() );
+		$this->target = array("body"=>array(),
+                              "header"=>array(),
+                              "css"=>array());
 
 		$aiki->widgets->render_site($this);
 		$html_output = $aiki->Output->render_output($this);
 
 		// corrections for old aiki engine
         // @TODO, someday, this will be deleted.
-		if (  isset($_REQUEST["noheaders"]) || $this->widget_custom_output ) {
-			$html_output = str_replace(	'[page_title]', $aiki->Output->get_title(),	$html_output);
+		if (isset($_REQUEST["noheaders"]) || $this->widget_custom_output) {
+			$html_output = str_replace('[page_title]',
+                                       $aiki->Output->get_title(),
+                                       $html_output);
 		}
 		$html_output = $aiki->languages->L10n($html_output);
 		return $html_output;

=== modified file 'libs/Output.php'
--- libs/Output.php	2012-05-08 21:34:14 +0000
+++ libs/Output.php	2012-05-28 17:55:38 +0000
@@ -232,7 +232,7 @@
 	 * @todo the html hardcoded in here needs abstraction and shouldn't make
 	 * assumptions about setup
 	 */
-	public function header ( $css, $aditionalHeader) {
+	public function header( $css, $aditionalHeader) {
 		global $aiki, $db, $config;
 		     
 		$output="";
@@ -255,7 +255,7 @@
 				( $view ? "view={$view}&amp;" : ""),
 				implode("_", array_keys($css)),
 				$aiki->site->language() );
-		}			
+		}
         $head .= $this->favicon();
 
 		if ( !is_null($aditionalHeader) ){
@@ -297,30 +297,50 @@
 	} // end of headers function
 
 
+    public function render_output($engine){
 
-    public function render_output ($engine){	   
-		
-		if ( isset($_REQUEST['noheaders']) || $engine->widget_custom_output) {
-			return $this->custom_output($engine);		
-		} else {   	
-			return 
-			$this->header($engine->target['css'],  $engine->target['header']).
-			$this->body($engine->target['body']).
-			$this->end();
+        if (isset($_REQUEST['noheaders']) || $engine->widget_custom_output) {
+            return $this->custom_output($engine);
+		} else {
+            $header = $this->get_output($engine->target["header"]);
+            $body = $this->get_output($engine->target["body"]);
+			return
+                $this->header($engine->target['css'], $header) .
+                $this->body($body) .
+                $this->end();
 		}
     }
 
+    private function get_output($target) {
+        $content = '';
+        foreach ($target as $item) {
+            $content .= $item[0];
+        }
+        return $content;
+    }
+    
+    private function get_output_no_globals($target) {
+        $content = '';
+        foreach ($target as $item) {
+            if (!$item[1]) {
+                $content .= $item[0];
+            }
+        }
+        return $content;
+    }
 
 	public function custom_output($engine){
 		global $aiki;
 		// @TODO will this work for images output (or a plugin)
 		$begin="";
-		$end="";			
-		$aiki->Plugins->doAction("output_begin",$begin);
-		$output = $engine->target["header"]. $engine->target["body"];		
+		$end="";
+		$aiki->Plugins->doAction("output_begin", $begin);
+        $output = '';
+        $output .= $this->get_output_no_globals($engine->target["header"]);
+        $output .= $this->get_output_no_globals($engine->target["body"]);
 		$aiki->Plugins->doAction("output_custom", $output);
 		$aiki->Plugins->doAction("output_end", $end);
-		return $output; 
+		return $output;
 	}
 
 	/**
@@ -332,9 +352,9 @@
 
 	public function end(){
 		global $aiki;
-		$end= "</html>";		
+		$end= "</html>";
 		$aiki->Plugins->doAction("output_end", $end);
-		return $end; 
+		return $end;
 	}
 	
 

=== modified file 'libs/widgets.php'
--- libs/widgets.php	2012-05-15 13:45:29 +0000
+++ libs/widgets.php	2012-05-28 17:55:38 +0000
@@ -58,17 +58,16 @@
         global $db, $aiki;
         $search = $aiki->url->url[0];
         $SQL =
-            "SELECT id, display_urls, kill_urls, widget_name, widget_target, css<>'' as have_css" .
-            " FROM aiki_widgets " .
+            "SELECT * FROM aiki_widgets " .
             " WHERE father_widget=$father AND " .
             $this->widget_scope() ." AND (".
             " concat('|',display_urls,'|')  LIKE '%|$search|%' OR".
             " concat('|',display_urls)      LIKE '%|$search/%' OR".
-            " concat('|',display_urls)      LIKE '%|$search$%' OR".          
+            " concat('|',display_urls)      LIKE '%|$search$%' OR".
             " display_urls = '*' OR".
             " display_urls LIKE '%#%#%')" .
-            " AND (kill_urls='' OR concat('|',kill_urls,'|') not like '%|$search|%') " .
-            " ORDER BY  display_order, id";
+            " AND (kill_urls='' OR concat('|',kill_urls,'|') not like ".
+			"'%|$search|%') ORDER BY  display_order, id";
          return $db->get_results($SQL);
     }
 
@@ -84,23 +83,23 @@
         
         // first check if we have a error_404 page.
         $SQL =
-            "SELECT id  FROM aiki_widgets ".
+            "SELECT id FROM aiki_widgets ".
             " WHERE " . $this->widget_scope() . " AND ".
-            " display_urls LIKE '%error_404%' AND kill_urls not like '%error_404%'".           
-            " LIMIT 1";
+            " display_urls LIKE '%error_404%' AND kill_urls not like ".
+			"'%error_404%' LIMIT 1";
         if ( !$db->get_var($SQL) ) {
 			return NULL;
-		}        
+		}
                                                   
         // Now return all 404 widget and * include
         $SQL =
-            "SELECT id, display_urls, kill_urls, widget_name, widget_target, css<>'' as have_css" .
-            " FROM aiki_widgets WHERE " .
+            "SELECT * FROM aiki_widgets WHERE " .
             $this->widget_scope() . " AND ".
             " (display_urls LIKE '%error_404%' OR ".
-            "display_urls = '*' OR display_urls like '*|%' OR display_urls like '%|*|%' OR display_urls like '%|*'".
-            ") AND kill_urls not like '%error_404%'".           
-            " ORDER BY display_order, id";          
+            "display_urls = '*' OR display_urls like '*|%' OR display_urls ".
+			"like '%|*|%' OR display_urls like '%|*'".
+            ") AND kill_urls not like '%error_404%'".
+            " ORDER BY display_order, id";
          // error_404 can't be part of a path: error_404/foo have no sense.
          // @TODO kill_urls = "*"
         return $db->get_results($SQL);
@@ -163,25 +162,27 @@
 	// the widget is given directly or
 	if (isset($_GET["widget"])) {
 		$widget= $this->get_widget($_GET["widget"]);
-		if ( is_null($widget) ){
-			$content=  __sprintf( "No valid widget %s", strip_tags($_GET["widget"]));
+		if (is_null($widget)) {
+			$content=  __sprintf("No valid widget %s", strip_tags($_GET["widget"]));
 		} else {
 			$content = $engine->parseWidget($widget);
 		}
 		
-		if ( $content !== false ){ 				
-			if ( is_array ($content) ){
-				$engine->target[$widget->widget_target] .= $content[0].$content[1];	
+		if ($content !== false) {
+			if (is_array($content)){
+				$engine->target[$widget->widget_target][] = 
+					array($content[0].$content[1], false);
 			} else {
-				$engine->target[$widget->widget_target] .= $content;
+				$engine->target[$widget->widget_target][] =
+					array($content, false);
 			}
-		}		
-		return; 
+		}
+		return;
 	}
 
 	// or in url,
 	// search widget and test there is a unique response
-	$module_widgets = $aiki->widgets->get_candidate_widgets();
+	$module_widgets = $this->get_candidate_widgets();
 	$unique_widget_exists = false;
 	if ($module_widgets) {
 		foreach($module_widgets as $tested_widget){
@@ -197,18 +198,19 @@
 		// first look for widget that responds error_404,
 		// else use config error_404.
 		$module_widgets= $aiki->widgets->get_Page_Not_Found_Widgets();
-		if ( !is_null($module_widgets) ) {
+		if (!is_null($module_widgets)) {
 			$aiki->Errors->pageNotFound(false);
-			$aiki->url->set_404();			
+			$aiki->url->set_404();
 		} else {
-			$engine->target["body"] = $aiki->Errors->pageNotFound(true);			
+			$engine->target["body"][] =
+				array($aiki->Errors->pageNotFound(true), false);
 			return;
 		}
 		
 	}
 	
 	foreach ($module_widgets as $parent) {
-		$this->render_widget($engine, $parent->id, 0);
+		$this->render_widget($engine, $parent, 0);
 	}
 
 	return true;
@@ -224,25 +226,26 @@
      * @level  0
      */
 
-	function render_widget($engine, $id, $level=0 ){
+	function render_widget($engine, $widget, $level=0 ){
 		global $aiki;
 		
+
 		// checks to avoid cycling trees
 		if ( $level > 256) {
 			return ;
 		}
 		
-		// first process the widget		
-		$widget = $this->get_widget($id) ;
+		// first process the widget
+		//$widget = $this->get_widget($id) ;
 		
 		if (!is_null($widget)) {
-			if ($engine->widget_custom_output && $widget->display_urls == "*") {
-				return ;
-			}
+			//if ($engine->widget_custom_output && $widget->display_urls == "*") {
+			//	return ;
+			//}
 			if ($aiki->url->match($widget->display_urls) &&
 				!$aiki->url->match($widget->kill_urls) ) {
 		
-				if ( $widget->css) {
+				if ($widget->css) {
 					$engine->target["css"][$widget->id] = true;
 				}
 				
@@ -250,25 +253,28 @@
 				
 				if ($content !== false) { 
 				
-					if ( is_array ($content) ){
-						$engine->target[$widget->widget_target] .= $content[0];			
+					if (is_array($content)){
+						$engine->target[$widget->widget_target][] =
+							array($content[0], $widget->display_urls == "*");
 					} else {
-						$engine->target[$widget->widget_target] .= $content;
+						$engine->target[$widget->widget_target][] = 
+							array($content, $widget->display_urls == "*");
 					}
 					
-					// and now the children 		
-					$childrens = $aiki->widgets->get_candidate_widgets($id);
-					if ( !is_null( $childrens ) ){
-						foreach ( $childrens as $children ){
-							$this->render_widget($engine,$children->id,$level+1);
+					// and now the children
+					$childrens = $aiki->widgets->get_candidate_widgets($widget->id);
+					if (!is_null($childrens)){
+						foreach ($childrens as $children) {
+							$this->render_widget($engine,$children,$level+1);
 						}
 					}
 					
-					if ( is_array ($content) ){
-						$engine->target[$widget->widget_target] .= $content[1];	
-					}	
+					if (is_array($content)) {
+						$engine->target[$widget->widget_target][] =
+							array($content[1], $widget->display_urls == "*");
+					}
 				}
-					
+				
 			}
 		}
 	}

_______________________________________________
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