Source for file Abstract_Page_Controller.php

Documentation is available at Abstract_Page_Controller.php

  1. <?php
  2. /**
  3.  *    LAIKA FRAMEWORK Release Notes:
  4.  *
  5.  *    @filesource     Abstract_Page_Controller.php
  6.  *
  7.  *    @version        0.1.0b
  8.  *    @package        Laika
  9.  *    @subpackage     core
  10.  *    @category       abstract
  11.  *    @date           2012-05-18 21:47:22 -0400 (Fri, 18 May 2012)
  12.  *
  13.  *    @author         Leonard M. Witzel <witzel@post.harvard.edu>
  14.  *    @copyright      Copyright (c) 2012  Laika Soft <{@link http://oafbot.com}>
  15.  *
  16.  */
  17. /**
  18.  * Abstract Laika_Abstract_Page_Controller class.
  19.  * 
  20.  * @abstract
  21.  * @extends Laika_Abstract_Controller
  22.  */
  23.     
  24.     const            CACHE_TIME    = 60;
  25.     
  26.     public    static $access_level 'PUBLIC'// PUBLIC, PRIVATE, PROTECTED
  27.     public    static $access_group 'USER';   // USER, ADMIN, WORLD
  28.     public    static $caching      TRUE;
  29.     protected        $ignore       = array('action_handler');
  30.     
  31. //-------------------------------------------------------------------
  32. //    METHODS
  33. //-------------------------------------------------------------------    
  34.     /**
  35.      * display function.
  36.      * 
  37.      * @access public
  38.      * @return void 
  39.      */
  40.     public function display(){
  41.         $args func_get_args();
  42.         $view str_replace('_Controller''_Page'get_called_class());        
  43.         $this->set_pagination();
  44.  
  45.         if(CACHE_PAGES && $this::$caching):
  46.             $this->caching($args);
  47.         else:
  48.             ob_start(OB_HANDLER);
  49.             $view::init()->render_page($args);          
  50.         endif;
  51.  
  52.         ob_end_flush();
  53.         Laika_Event::dispatch('PAGE_RENDER_COMPLETE',__FILE__);
  54.  
  55.         /*$html = ob_get_contents();
  56.         $html = ob_get_clean();
  57.         $config = array(
  58.            'indent'=> false,
  59.            'hide-comments' => true,
  60.            'output-xhtml' => false,
  61.            'wrap' => false
  62.         );        
  63.         $tidy = new tidy;
  64.         $tidy->parseString($html, $config, 'utf8');
  65.         $tidy->cleanRepair();
  66.         echo tidy_get_output($tidy);
  67.         ob_end_flush();*/
  68.  
  69.     }
  70.  
  71.     /**
  72.      * caching function.
  73.      * 
  74.      * @access public
  75.      * @param mixed $args 
  76.      * @return void 
  77.      */
  78.     public function caching($args){
  79.         $zip true;
  80.         $view  str_replace('_Controller''_Page'get_called_class());
  81.         $class get_called_class();
  82.         $url   urlencodestr_replace(HTTP_ROOT"File_".md5(Laika_User::active()->username)Laika_Router::init()->uri) );
  83.         //$cachefile = SYS_CACHE.basename($class, '.php') . '.cache';
  84.         $cachefile SYS_CACHE.$url.'.cache';
  85.         clearstatcache();
  86.         
  87.         if (file_exists($cachefile&& filemtime($cachefiletime($this::CACHE_TIME// good to serve!
  88.             if($zip)
  89.                 echo gzuncompress(file_get_contents($cachefile));
  90.             else include($cachefile);
  91.             Laika_Event::dispatch('PAGE_RENDER_COMPLETE',__FILE__);
  92.             exit;
  93.         }        
  94.  
  95.         ob_start();
  96.         $view::init()->render_page($args);        
  97.  
  98.         $contents ob_get_contents();
  99.         ob_end_clean();
  100.         $handle fopen($cachefile"w");
  101.         fwrite($handlegzcompress($contents));
  102.         fclose($handle);
  103.         
  104.         if($zipecho gzuncompress(file_get_contents($cachefile));
  105.         else include($cachefile);
  106.         Laika_Event::dispatch('PAGE_RENDER_COMPLETE',__FILE__);        
  107.     }
  108.        
  109.     /**
  110.      * action_handler function.
  111.      * 
  112.      * Check if method exists. If called method does not exist or action_handler
  113.      * is called recursively, direct flow of control to the default_action.
  114.      * Otherwise perform requested action.
  115.      *
  116.      * @access public
  117.      * @param mixed $action 
  118.      * @param mixed $parameters 
  119.      * @return void 
  120.      */
  121.     public function action_handler($action,$parameters){
  122.         $this->ignore = array_merge($this->ignoreget_class_methods(get_parent_class(get_parent_class($this))));
  123.         
  124.         !empty($parameters$this->parameters $parameters $this->parameters NULL;        
  125.         if$action == 'default' )
  126.             $this->default_action();
  127.         else if!method_exists(get_called_class()$actionin_array($action,$this->ignore)) 
  128.             $this->default_action();
  129.         else $this->$action();    
  130.     }
  131.         
  132.     /**
  133.      * default_action function.
  134.      * 
  135.      * @access public
  136.      * @return void 
  137.      */
  138.     abstract protected function default_action();
  139.  
  140.     
  141.     /**
  142.      * set_pagination function.
  143.      * 
  144.      * @access public
  145.      * @return void 
  146.      */
  147.     public function set_pagination(){
  148.         if(!isset($this->parameters['p']))
  149.             $_SESSION['pagination'1;
  150.         else
  151.             $_SESSION['pagination'$this->parameters['p'];
  152.     }
  153.     
  154.     /**
  155.      * alert function.
  156.      * 
  157.      * @access public
  158.      * @return void 
  159.      */
  160.     public function alert(){        
  161.         $view str_replace('_Controller''_Page'get_called_class());
  162.         $view::init()->alert_type $this->parameters['type'];
  163.         $view::init()->alert $this->parameters['message'];
  164.         $view::render_alert();    
  165.     }
  166. }

Documentation generated on Sat, 19 May 2012 02:16:54 -0400 by phpDocumentor 1.4.4