------------------------------------------------------------
revno: 879
committer: Roger Martin <[email protected]>
branch nick: aikiframework
timestamp: Fri 2011-07-08 00:17:54 +0200
message:
  improving cache generation
modified:
  src/index.php
  src/libs/output.php
  src/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 'src/index.php'
--- src/index.php	2011-06-27 20:23:02 +0000
+++ src/index.php	2011-07-07 22:17:54 +0000
@@ -36,11 +36,15 @@
  */
 require_once("bootstrap.php");
 
+
 /**
- * Creates a container that holds cached data
+ * cache_file have tree result:
+ *  false: if no cache file must be created
+ *  string: cache file that must be created
+ *  die, after echo a previous a fresh cache file.
  * @global string $html_cache_file
  */
-$html_cache_file = $aiki->output->from_cache();
+$html_cache_file = $aiki->output->cache_file();
 
 /**
  * @see widgets.php
@@ -51,6 +55,9 @@
 /**
  * @todo need to define these before use + integrate into @see widgets.php
  */
+
+
+$noheaders = false;
 if (isset($global_widget)) 
 {
 	$noheaders = true;
@@ -60,27 +67,25 @@
 /**
  * @todo fix the misspelling
  */
+
+
 if ($layout->widget_custom_output)
 	$noheaders = true;
 
-if (!isset($noheaders))
+
+if ( $noheaders) {
+    $html_output = $layout->html_output;
+} else {   
 	$html_output = $aiki->output->write_headers();
-
-
-if ($config['html_cache'] and isset($html_cache_file) and !isset($noheaders))
-	$full_html_input = $aiki->output->write_headers();
-
-if ($config['html_cache'] and isset($html_cache_file))
-	$full_html_input .= $layout->html_output;
-
-if (isset($aiki->output->title))
-	$layout->html_output = 
-        str_replace('[page_title]', $aiki->output->title, $layout->html_output);
-
-$html_output .= $layout->html_output;
-
-if (!isset($noheaders))
-	$html_output .= $aiki->output->write_footer();
+    if (isset($aiki->output->title)) {
+        $layout->html_output =  str_replace(
+            '[page_title]', 
+            $aiki->output->title, 
+            $layout->html_output);
+    } 
+    $html_output .= $layout->html_output;
+    $html_output .= $aiki->output->write_footer();
+} 
 
 $html_output = $aiki->languages->L10n($html_output);
 
@@ -102,59 +107,20 @@
 		echo tidy_get_output($tidy);
 } else {
 
-	if (isset($_REQUEST['compress_output']) or 
-        (isset($config["compress_output"]) and 
-        $config["compress_output"]))
-    {
-		$html_output = preg_replace("/\<\!\-\-(.*)\-\-\>/U", "", $html_output);
-
-		$search = array(
-		'/\n/',			// replace end of line by a space
-		'/\>[^\S ]+/s',		// strip whitespaces after tags, except space
-		'/[^\S ]+\</s',		// strip whitespaces before tags, except space
-	 	'/(\s)+/s'		// shorten multiple whitespace sequences
-	    );
-
-	 $replace = array(
-		' ',
-		'>',
-	 	'<',
-	 	'\\1'
-	  );
-
-	  $html_output  = preg_replace($search, $replace, $html_output );
+	if (isset($_REQUEST['compress_output']) || 
+        (isset($config["compress_output"]) && $config["compress_output"]))  {
+		$html_output = $aiki->output->compress( $html_output);
 	}
 
-	if (!isset($_GET['no_output']))
-    {
-        /**
-         * @todo is this useful, or kill it?
-         */
-		//print htmlspecialchars_decode($html_output);
+	if (!isset($_GET['no_output']))  {
 		print $html_output;
 	}
 } // end of using tidy
 
-if ($config['html_cache'] and 
-    isset($html_cache_file) and 
-    !isset($noheaders))
-{
-	$full_html_input .= $aiki->output->write_footer();
-}
-
-if ($config['html_cache'] and isset($html_cache_file))
-{
-	if ( ! is_dir($config['html_cache']) )
-	{
-		echo($config['html_cache']);
-	}
-	else
-	{
-		$full_html_input = $aiki->languages->L10n($full_html_input);
-
-		//write the cache file
-		error_log ( $full_html_input, 3, $html_cache_file);
-	}
+
+if ( $html_cache_file ) {
+    //write the cache file
+	error_log ( $html_output, 3, $html_cache_file);
 }
 
 /**

=== modified file 'src/libs/output.php'
--- src/libs/output.php	2011-07-07 03:52:30 +0000
+++ src/libs/output.php	2011-07-07 22:17:54 +0000
@@ -243,10 +243,11 @@
 
 
 	/**
-	 * Checks if cache setup and if have permissions, if so, then returns path
+	 * Checks if cache setup and user don't have special permissions (for security
+     * reason this pages will not be cached),if so, then returns path
 	 * to cache file.
 	 *
-	 * Returns false if no cache configuration or nor had permissions.
+	 * Returns false if no cache configuration or had permissions.
 	 * If exist fresh file ( no time-out) it is served and application dies.
 	 * In other case, return the name (including path) of cache file that must 
 	 * be created and if exist, delete the obsolete cache file.
@@ -260,12 +261,15 @@
 	 * @todo this function has side effect to output HTML
 	 * @todo think good to rename this function too
 	 */
-	public function from_cache()
+	public function cache_file()
 	{
 		global $config, $membership;
 
-		if ($config['html_cache'] != false and !$membership->permissions)
-		{
+		if ( isset($config['html_cache']) 
+              && $config['html_cache'] 
+              && is_dir( $config['html_cache'] ) 
+              && !$membership->permissions ){
+                  
 			$start = (float) array_sum(explode(' ',microtime()));
 
 			$html_cache_file = 
@@ -308,5 +312,36 @@
 
 		return $html_cache_file;
 	} // end of from_cache function
+    
+    
+    /**
+     * Compress HTML, deleting line space, doble spaces, space in tags..
+     * and HTML coments
+     * 
+     * @param  $string $input String to be cleaned
+     * @return $string Cleaned input
+     */
+    
+    function compress( &$input){
+        $output = preg_replace("/\<\!\-\-(.*)\-\-\>/U", "", $input);
+
+		$search = array(
+            '/\n/',			// replace end of line by a space
+            '/\>[^\S ]+/s',	// strip whitespaces after tags, except space
+            '/[^\S ]+\</s',	// strip whitespaces before tags, except space
+            '/(\s)+/s'		// shorten multiple whitespace sequences
+            );
+
+        $replace = array(
+            ' ',
+            '>',
+            '<',
+            '\\1'
+            );
+
+        $output  = preg_replace($search, $replace, $output );
+      return $output;
+    }
+    
 
 } // end of Output class

=== modified file 'src/libs/widgets.php'
--- src/libs/widgets.php	2011-07-07 01:17:22 +0000
+++ src/libs/widgets.php	2011-07-07 22:17:54 +0000
@@ -176,7 +176,8 @@
 		 *		 outside this block to be proper!
 		 * @TODO This is totally too long iteration to create $widget
 		 */
-		foreach ($widget_result as $widget)	{
+    
+        foreach ($widget_result as $widget)	{
 
 			if ($widget->css) {
 				$this->widgets_css[]= $widget->id ;

_______________________________________________
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