Changeset 5991


Ignore:
Timestamp:
02/02/12 07:01:06 (4 months ago)
Author:
vain
Message:
  • moved checkTemplateExtension() and getTemplateName() to the templatemapper
Location:
trunk/core
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/modulecontroller.core.php

    r5979 r5991  
    9393 
    9494    /** 
     95     * Returns the Doctrine Entity Manager  
     96     * 
    9597     * @return \Doctrine\ORM\EntityManager 
    9698     */ 
     
    158160 
    159161    /** 
    160      * Initalizes the model (active records/entities/repositories) of the module 
     162     * Initializes the model (active records/entities/repositories) of the module 
    161163     * 
    162164     * @param $modulename Modulname 
     
    181183        if(is_dir($module_models_path) === true) 
    182184        { 
    183            if(isset($entity) === true) # method parameter 
     185           if(isset($entity) === true) 
    184186           { 
     187               # use second parameter of method 
    185188               $entity = $module_models_path . 'entities' . DS . ucfirst($entity) . '.php'; 
    186189           } 
    187            else # build entity filename by modulename 
     190           else 
    188191           { 
     192               # build entity filename by modulename 
    189193               $entity = $module_models_path . 'entities' . DS . ucfirst($modulename) . '.php'; 
    190194           } 
     
    196200 
    197201           $repos = $module_models_path . 'repositories' . DS . ucfirst($modulename) . 'Repository.php'; 
     202            
    198203           if(is_file($repos) === true and class_exists('Entities\\' . ucfirst($modulename), false) === false) 
    199204           { 
     
    240245     * 
    241246     * @param string $keyname The keyname to find in the array. 
    242      * @param mixed $default_one A default value, which is returned, if the keyname was not found. 
    243      * @param mixed $default_two A default value, which is returned, if the keyname was not found and default_one is null. 
     247     * @param mixed $default_one A default value returned, when keyname was not found. 
     248     * @param mixed $default_two A default value returned, when keyname was not found and default_one is null. 
     249     * @return mixed 
    244250     */ 
    245251    public static function getConfigValue($keyname, $default_one = null, $default_two = null) 
     
    377383 
    378384    /** 
    379      * Ensures the template extension is correct. 
    380      * 
    381      * @param string $template The template filename. 
    382      */ 
    383     public static function checkTemplateExtension($template) 
    384     { 
    385         # get extension of template 
    386         $template_extension = mb_strtolower(pathinfo($template, PATHINFO_EXTENSION)); 
    387  
    388         # whitelist definition for listing all allowed template filetypes 
    389         $allowed_extensions = array('html','php','tpl'); 
    390  
    391         # check if extension is one of the allowed ones 
    392         if (false === in_array($template_extension, $allowed_extensions)) 
    393         { 
    394             $message = 'Template Extension invalid <strong>'.$template_extension.'</strong> on <strong>'.$template.'</strong>'; 
    395             trigger_error($message, E_USER_NOTICE); 
    396         } 
    397     } 
    398  
    399     /** 
    400      * Returns the Template Name 
    401      * 
    402      * @return Returns the templateName as String 
    403      */ 
    404     public function getTemplateName() 
    405     { 
    406         # if the templateName was not set manually, we construct it from module/action infos 
    407         if(empty($this->template) === true) 
    408         { 
    409             # construct template name 
    410             $template = Clansuite_TargetRoute::getActionName() . '.tpl'; 
    411             $this->setTemplate($template); 
    412         } 
    413         return $this->template; 
    414     } 
    415  
    416     /** 
    417385     * Sets the Render Mode 
    418386     * 
     
    426394    /** 
    427395     * Get the Render Mode 
     396     * 
     397     * @return string LAYOUT|NOLAYOUT 
    428398     */ 
    429399    public function getRenderMode() 
     
    433403            $this->getView()->renderMode = 'LAYOUT'; 
    434404        } 
     405 
    435406        return $this->getView()->renderMode; 
    436407    } 
     
    475446 
    476447        # Debug display of Layout Template and Content Template 
    477         if(DEBUG == true) 
    478         { 
    479             #Clansuite_Debug::firebug('Layout/Wrapper Template: ' . $this->view->getLayoutTemplate() . '<br />'); 
    480             #Clansuite_Debug::firebug('Template Name: ' . $templatename . '<br />'); 
    481         } 
     448        #Clansuite_Debug::firebug('Layout/Wrapper Template: ' . $this->view->getLayoutTemplate() . '<br />'); 
     449        #Clansuite_Debug::firebug('Template Name: ' . $templatename . '<br />'); 
    482450 
    483451        # render the content / template 
     
    542510    public function redirectToReferer() 
    543511    { 
    544         $referer = ''; 
    545512        $referer = self::getHttpRequest()->getReferer(); 
    546513 
     
    554521            $route = Clansuite_HttpRequest::getRoute(); 
    555522 
    556             # we use internal rewrite style here: /module/action 
    557             # redirect() builds the url 
    558             $redirect_to = '/'; 
    559             $redirect_to .= $route->getModuleName(); 
    560  
     523            # we use internal rewrite style here: /module/action             
     524            $redirect_to = '/' . $route->getModuleName(); 
    561525            $submodule = $route->getSubModuleName(); 
     526 
    562527            if(empty($submodule) === false) 
    563528            { 
     
    565530            } 
    566531 
     532            # redirect() builds the url 
    567533            $this->redirect($redirect_to); 
    568534        } 
  • trunk/core/renderer/templatemapper.php

    r5941 r5991  
    4040 * Clansuite_View_Mapper 
    4141 * 
     42 * By definition a mapper sets up a communication between two independent objects. 
    4243 * Clansuite_View_Mapper is a "class action" to "template" mapper. 
    4344 * This has nothing to do with rendering, but with template selection for the view. 
    44  * If no template was set manually, this class will help determining the template, 
     45 * If no template was set manually in the action of a module (class),  
     46 * this class will help determining the template,  
    4547 * by mapping the requested class and action to a template. 
    4648 */ 
    4749class Clansuite_View_Mapper 
    4850{ 
     51    /** 
     52     * Ensures the template extension is correct. 
     53     * 
     54     * @param string $template The template filename. 
     55     */ 
     56    public static function checkTemplateExtension($template) 
     57    { 
     58        # get extension of template 
     59        $template_extension = mb_strtolower(pathinfo($template, PATHINFO_EXTENSION)); 
    4960 
     61        # whitelist definition for listing all allowed template filetypes 
     62        $allowed_extensions = array('html','php','tpl'); 
     63 
     64        # check if extension is one of the allowed ones 
     65        if (false === in_array($template_extension, $allowed_extensions)) 
     66        { 
     67            $message = 'Template Extension invalid <strong>'.$template_extension.'</strong> on <strong>'.$template.'</strong>'; 
     68            trigger_error($message, E_USER_NOTICE); 
     69        } 
     70    } 
     71 
     72    /** 
     73     * Returns the Template Name 
     74     * 
     75     * @return Returns the templateName as String 
     76     */ 
     77    public function getTemplateName() 
     78    { 
     79        # if the templateName was not set manually, we construct it from module/action infos 
     80        if(empty($this->template) === true) 
     81        { 
     82            # construct template name 
     83            $template = Clansuite_TargetRoute::getActionName() . '.tpl'; 
     84              
     85            $this->setTemplate($template); 
     86        } 
     87 
     88        return $this->template; 
     89    } 
    5090} 
     91?> 
Note: See TracChangeset for help on using the changeset viewer.