Source for file Abstract_Page.php

Documentation is available at Abstract_Page.php

  1. <?php
  2. /**
  3.  *    LAIKA FRAMEWORK Release Notes:
  4.  *
  5.  *    @filesource     Abstract_Page.php
  6.  *
  7.  *    @version        0.1.0b
  8.  *    @package        Laika
  9.  *    @subpackage     core
  10.  *    @category       abstract
  11.  *    @date           2012-05-18 21:48:04 -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 class.
  19.  * 
  20.  * @abstract
  21.  * @extends Laika_Singleton
  22.  */
  23. abstract class Laika_Abstract_Page extends Laika_Singleton{
  24.  
  25.     private static $instance;
  26.     private        $template;
  27.     private        $component;
  28.     private        $page;    
  29.     
  30.     public  static $access_level 'PUBLIC';
  31.     public  static $access_group 'USER'
  32.     
  33.  
  34.     /**
  35.      * __callStatic function.
  36.      * 
  37.      * If method name includes 'render_' it will render a partial
  38.      * Otherwise it will echo a proprerty.
  39.      *
  40.      * @access public
  41.      * @static
  42.      * @param string $name 
  43.      * @param mixed $arg 
  44.      * @return void 
  45.      */
  46.     public static function __callStatic($name,$arg){
  47.         $class get_called_class();
  48.         if(substr($name,0,7)=='render_'):
  49.             $class::render(substr($name,7));
  50.         elseif(empty($arg)):
  51.             echo $class::init()->$name;
  52.         elseif(is_array($class::init()->$name)):
  53.             $array $class::init()->$name;
  54.             echo $array[$arg[0]];
  55.         endif;
  56.     }    
  57.         
  58.     /**
  59.      * render_page function.
  60.      * 
  61.      * @access public
  62.      * @return void 
  63.      */
  64.     public function render_page(){
  65.         
  66.         $class get_called_class();
  67.         $arg   func_get_arg(0);
  68.                
  69.         if!empty($arg) )
  70.             foreach($arg as $params)
  71.                 foreach$params as $key => $value)
  72.                     $class::init()->$key $value;
  73.         if(!isset($class::init()->component))
  74.             $class::init()->component "DEFAULT";
  75.         if(!isset($class::init()->template))
  76.             $class::init()->template "DEFAULT";
  77.         if(!isset($class::init()->page))
  78.             $class::init()->page strtolower(str_replace('_Page','',substr($class,6)));
  79.         //include_once($class::add_component($component));
  80.         include_once($class::add_template($class::init()->template));
  81.     }
  82.     
  83.         
  84.     /**
  85.      * render_component function.
  86.      * 
  87.      * @access public
  88.      * @static
  89.      * @return void 
  90.      */
  91.     public static function render_component(){
  92.         $class get_called_class();
  93.         include_once($class::add_component($class::init()->component));    
  94.     }    
  95.     
  96.     /**
  97.      * render_alert function.
  98.      * 
  99.      * @access public
  100.      * @static
  101.      * @return void 
  102.      */
  103.     public static function render_alert(){
  104.         if(self::init()->alert_type == 'warning')
  105.             $icon '<span class=alert_icon >W</span>';
  106.         elseif(self::init()->alert_type == 'success')
  107.             $icon '<span class=alert_icon >&#47;</span>';
  108.         if(isset(self::init()->alert))
  109.             echo '<div id="alert" class="'.self::init()->alert_type.'">'.$icon.self::init()->alert.'
  110.             <a href="javascript:;" onclick="close_alert();" class="webfont close" title="close">&#215;</a>
  111.             </div>';
  112.     }
  113.         
  114.     /**
  115.      * render function.
  116.      *
  117.      * renders a view partial
  118.      * parameters passed into the method can be accessed from the called partial by
  119.      * the "$parameter" variable.
  120.      * 
  121.      * @access public
  122.      * @static
  123.      * @param mixed $partial 
  124.      * @return void 
  125.      */
  126.     public static function render(){
  127.         func_num_args()>$parameters func_get_arg(1$parameters NULL;
  128.         $partial func_get_arg(0);
  129.         $class get_called_class();
  130.         
  131.         if(file_exists(PUBLIC_DIRECTORY."/js/$partial.js"))
  132.             echo '<script type="text/javascript" src="'.HTTP_ROOT.'/js/'.$partial.'.js"></script>';
  133.  
  134.         if(file_exists(PUBLIC_DIRECTORY."/stylesheets/$partial.css"))
  135.             echo '<link rel="stylesheet" href="'.HTTP_ROOT.'/stylesheets/'.$partial.'.css" type="text/css">';
  136.  
  137.         include_once($class::add_partial($partial));
  138.     }
  139.     
  140.     /**
  141.      * render_foreach function.
  142.      *
  143.      * renders a view partial for each object in a collection
  144.      * 
  145.      * @access public
  146.      * @static
  147.      * @param mixed $partial 
  148.      * @return void 
  149.      */
  150.     public static function render_foreach($partial,$collection){
  151.         $class get_called_class();
  152.         $count 0;
  153.         foreach($collection as $label => $object)
  154.             include($class::add_partial($partial));   
  155.     }
  156.     
  157.     /**
  158.      * add_partial function.
  159.      * 
  160.      * @access public
  161.      * @static
  162.      * @param string $partial 
  163.      * @return void 
  164.      */
  165.     public static function add_partial($partial){
  166.         if(file_exists(APP_VIEW_SHARED.'partials/'.$partial.'.php'))
  167.             return APP_VIEW_SHARED.'partials/'.$partial.'.php';
  168.         elseif(file_exists(APP_VIEW_COMPONENTS.'partials/'.$partial.'.php'))
  169.             return APP_VIEW_COMPONENTS.'partials/'.$partial.'.php';
  170.         elseif(file_exists($partial.'php'))
  171.             return $partial.'php';
  172.         throw new Laika_Exception('MISSING_PARTIAL',811);
  173.     }
  174.     
  175.     /**
  176.      * add_logic function.
  177.      * 
  178.      * @access public
  179.      * @static
  180.      * @param mixed $file 
  181.      * @return void 
  182.      */
  183.     public static function add_logic($file){
  184.         include_once(APP_VIEW_LOGIC.basename($file).'_logic.php');
  185.     }
  186.     
  187.     /**
  188.      * add_component function.
  189.      * 
  190.      * @access public
  191.      * @param string $component 
  192.      * @return string 
  193.      */
  194.     public function add_component($component){
  195.         $class_name get_called_class();
  196.         $page_name  str_replace(CODE_NAME.'_',""$class_name,$count 1)
  197.                 
  198.         if($component == "DEFAULT")
  199.             $page_name  str_replace('_Page',"_Component",$page_name,$count 1);             
  200.         else           
  201.             $page_name  str_replace('_Page','_'.ucfirst(strtolower($component)).'_Component',$page_name,$count 1);
  202.         return APP_VIEW_COMPONENTS.$page_name.'.php';        
  203.     }
  204.     
  205.     /**
  206.      * add_template function.
  207.      * 
  208.      * @access public
  209.      * @param string $template 
  210.      * @return string 
  211.      */
  212.     public function add_template($template){
  213.         $class_name get_called_class();
  214.         $page_name  str_replace(CODE_NAME.'_',""$class_name,$count 1);
  215.  
  216.         if($template == "DEFAULT"):
  217.             return APP_VIEW_SHARED.'default_template.php';
  218.         else:
  219.             str_replace('_Page','_'.ucfirst(strtolower($template)).'_Template',$page_name,$count 1);
  220.             return APP_VIEW_SHARED.$page_name.'.php';
  221.         endif;
  222.     }
  223.  
  224.     
  225.     /**
  226.      * scripts function.
  227.      *
  228.      * Outputs javascript src includes constructed from parameters
  229.      * 
  230.      * @access public
  231.      * @static
  232.      * @return void 
  233.      */
  234.     public static function scripts(){
  235.         $args func_get_args();
  236.         $page self::init()->page;
  237.         $component self::init()->component;
  238.         
  239.         foreach($args as $k => $v)
  240.             if(file_exists(PUBLIC_DIRECTORY."/js/$v.js"))
  241.                 echo '<script type="text/javascript" src="'.HTTP_ROOT.'/js/'.$v.'.js"></script>';
  242.         
  243.         if(isset($page))
  244.             if(file_exists(PUBLIC_DIRECTORY."/js/$page.js"))
  245.                 echo '<script type="text/javascript" src="'.HTTP_ROOT.'/js/'.$page.'.js"></script>';
  246.                 
  247.         if(isset($component&& $component!="DEFAULT")
  248.             if(file_exists(PUBLIC_DIRECTORY."/js/$component.js"))
  249.                 echo '<script type="text/javascript" src="'.HTTP_ROOT."/js/$component.js".'"></script>'
  250.     }
  251.     
  252.     /**
  253.      * styles function.
  254.      *
  255.      * Outputs stylesheet includes constructed from parameters
  256.      * 
  257.      * @access public
  258.      * @static
  259.      * @return void 
  260.      */
  261.     public static function styles(){
  262.         $args func_get_args();
  263.         $page self::init()->page;
  264.         $component self::init()->component;
  265.         foreach($args as $k => $v)
  266.             if(file_exists(PUBLIC_DIRECTORY."/stylesheets/$v.css"))
  267.                 echo '<link rel="stylesheet" href="'.HTTP_ROOT.'/stylesheets/'.$v.'.css" type="text/css">';
  268.             elseif(file_exists(PUBLIC_DIRECTORY."/$v.css"))
  269.                 echo '<link rel="stylesheet" href="'.HTTP_ROOT."/$v.css".'" type="text/css">';
  270.         if(isset($page))
  271.             echo '<link rel="stylesheet" href="'.HTTP_ROOT.'/stylesheets/'.$page.'.css" type="text/css">';
  272.         if(isset($component&& $component!="DEFAULT")
  273.             echo '<link rel="stylesheet" href="'.HTTP_ROOT.'/stylesheets/'.$component.'.css" type="text/css">';        
  274.     }
  275.     
  276.     /**
  277.      * add_style function.
  278.      * 
  279.      * @access public
  280.      * @static
  281.      * @return void 
  282.      */
  283.     public static function add_style(){
  284.         $args func_get_args();
  285.         foreach($args as $k => $v)
  286.             if(file_exists(PUBLIC_DIRECTORY."/stylesheets/$v.css"))
  287.                 echo '<link rel="stylesheet" href="'.HTTP_ROOT.'/stylesheets/'.$v.'.css" type="text/css">';
  288.             elseif(file_exists(PUBLIC_DIRECTORY."/$v.css"))
  289.                 echo '<link rel="stylesheet" href="'.HTTP_ROOT."/$v.css".'" type="text/css">';
  290.              
  291.     }
  292.     
  293.     /**
  294.      * path function.
  295.      *
  296.      * Outputs url.
  297.      * 
  298.      * @access public
  299.      * @static
  300.      * @param string $path 
  301.      * @return void 
  302.      */
  303.     public static function path_to($path){
  304.         echo HTTP_ROOT.$path;
  305.     }
  306.     
  307.     /**
  308.      * link_to function.
  309.      * 
  310.      * Outputs a HTML link inside a anchor tag.
  311.      * View Superclass Laika::link_to method for usage.
  312.      *
  313.      * @access public
  314.      * @static
  315.      * @return void 
  316.      */
  317.     public static function link_to(){
  318.         echo call_user_func_array('Laika::link_to'func_get_args() );
  319.     }
  320.     
  321.     /**
  322.      * img function.
  323.      * 
  324.      * @access public
  325.      * @static
  326.      * @return void 
  327.      */
  328.     public static function img(){
  329.         echo call_user_func_array('Laika::img'func_get_args());
  330.     }    
  331.     
  332.     /**
  333.      * paginate function.
  334.      * 
  335.      * @access public
  336.      * @static
  337.      * @param mixed $class 
  338.      * @param mixed $limit 
  339.      * @param mixed $k 
  340.      * @param mixed $v 
  341.      * @return void 
  342.      */
  343.     public static function paginate($class,$limit,$params,$partial,$order=NULL){
  344.         
  345.         if($order)
  346.            $c $class::paginate($limit,$params,$order)
  347.         else        
  348.             $c $class::paginate($limit,$params);
  349.         
  350.         $collection array();
  351.  
  352.         foreach($c as $key => $value)
  353.             $collection[$value->revive();
  354.         self::render_foreach($partial,$collection);    
  355.     }
  356.     
  357.     public static function render_pagination(){
  358.         
  359.     }
  360.     
  361.     public static function set_login_redirect(){
  362.         (func_num_args()>0$url HTTP_ROOT.func_get_arg(0$url Laika_Router::init()->uri;
  363.         $_SESSION['REDIRECT'$url;        
  364.     }
  365.         
  366. }

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