Changeset 6002


Ignore:
Timestamp:
02/03/12 17:24:20 (4 months ago)
Author:
vain
Message:
  • moved set|getLayoutTemplate to renderer base class
Location:
trunk/core
Files:
4 edited

Legend:

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

    r5992 r6002  
    411411    public function display($templates = null) 
    412412    { 
    413         include ROOT_CORE . 'renderer/templatemapper.php'; 
    414413        $view_mapper = new Clansuite_View_Mapper; 
    415414 
     
    428427        } 
    429428 
    430         # only the content template is set 
     429        # only the "content template" is set 
    431430        if(is_string($templates)) { $view_mapper->setTemplate($templates); } 
    432431 
    433432        # get the templatename 
    434         $templatename = $view_mapper->getTemplateName(); 
     433        $template = $view_mapper->getTemplateName(); 
    435434 
    436435        # get the view 
     
    442441 
    443442        # render the content / template 
    444         $content = $this->view->render($templatename); 
     443        $content = $this->view->render($template); 
    445444 
    446445        # push content to the response object 
    447446        $this->response->setContent($content); 
    448447 
    449         unset($content, $templatename); 
     448        unset($content, $template); 
    450449    } 
    451450 
  • trunk/core/renderer/renderer.base.php

    r5974 r6002  
    6161     */ 
    6262    public $layoutTemplate = null; 
    63  
    64     /** 
    6563     * @var string The "content" template 
    6664     */ 
     
    180178    { 
    181179        return $this->template; 
    182     } 
    183  
    184     /** 
    185      * Returns the Template Path 
    186      * 
    187      * Fetches the template by searching in the 
    188      * 1) Theme Template Paths 
    189      * 2) Modules Template Paths 
    190      * Note the Path Priority: Themes before Modules. 
    191      * 
    192      * @return $templatepath 
    193      */ 
    194     public function getTemplatePath($template) 
    195     { 
    196         # done: if template is a qualified path and template filename 
    197         if(is_file($template) === true) 
    198         { 
    199             return $template; 
    200         } 
    201  
    202         # fetch the template by searching in the Theme Template Paths 
    203         $theme_template = $this->getThemeTemplatePath($template); 
    204  
    205         # check if template was found there, else it's null 
    206         if($theme_template != null) 
    207         { 
    208             #Clansuite_Debug::firebug(__METHOD__ .' tries fetching template ("'. $theme_template . '") from THEME directory.'); 
    209             return $theme_template; 
    210         } 
    211         else # fetch the template by searching in the Module Template Path 
    212         { 
    213             #Clansuite_Debug::firebug(__METHOD__ .' tries fetching template ("'. $template . '") from MODULE directory.'); 
    214             return $this->getModuleTemplatePath($template); 
    215         } 
    216     } 
    217  
    218     /** 
    219      * Return Theme Template Paths 
    220      * 
    221      * @return array Theme Template Paths 
    222      */ 
    223     public static function getThemeTemplatePaths() 
    224     { 
    225         # get module, submodule, renderer names 
    226         $module    = Clansuite_HttpRequest::getRoute()->getModuleName(); 
    227         $submodule = Clansuite_HttpRequest::getRoute()->getSubModuleName(); 
    228         #$renderer  = Clansuite_HttpRequest::getRoute()->getRenderEngine(); 
    229  
    230         $theme_paths = array(); 
    231  
    232         /** 
    233          * 1. BACKEND THEME 
    234          * when controlcenter or admin is requested, it has to be a BACKEND theme 
    235          */ 
    236         if($module == 'controlcenter' or $submodule == 'admin') 
    237         { 
    238             # get backend theme from session for path construction 
    239             $backendtheme  = Clansuite_HttpRequest::getRoute()->getBackendTheme(); 
    240  
    241             # (a) USER BACKENDTHEME - check in the active session backendtheme 
    242             # e.g. /themes/backend/ + admin/template_name.tpl 
    243             $theme_paths[] = ROOT_THEMES_BACKEND . $backendtheme . DS; 
    244             # e.g. /themes/backend/ + admin/modules/template_name.tpl 
    245             $theme_paths[] = ROOT_THEMES_BACKEND . $backendtheme . DS . 'modules' . DS . $module . DS; 
    246             # (b) BACKEND FALLBACK - check the fallback dir: themes/admin 
    247             $theme_paths[] = ROOT_THEMES_BACKEND . 'admin' . DS; 
    248         } 
    249         /** 
    250          * 2. FRONTEND THEME 
    251          */ 
    252         else 
    253         { 
    254             # get frontend theme from session for path construction 
    255             $frontendtheme = Clansuite_HttpRequest::getRoute()->getFrontendTheme(); 
    256  
    257             # (a) USER FRONTENDTHEME - check, if template exists in current session user THEME 
    258             $theme_paths[] = ROOT_THEMES_FRONTEND . $frontendtheme . DS; 
    259             # (b) FRONTEND FALLBACK - check, if template exists in usertheme/modulename/tpl 
    260             $theme_paths[] = ROOT_THEMES_FRONTEND . $frontendtheme . DS . 'modules' . DS . $module . DS; 
    261             # (c) FRONTEND FALLBACK - check, if template exists in standard theme 
    262             $theme_paths[] = ROOT_THEMES_FRONTEND . 'standard' . DS; 
    263         } 
    264  
    265         return $theme_paths; 
    266     } 
    267  
    268     /** 
    269      * Returns the fullpath to Template by searching in the Theme Template Paths 
    270      * 
    271      * Note: For the implementation of module specific renderers and their related templates two ways exist: 
    272      * a) add either a directory named after the "renderer/", like modules/modulename/view/renderer/actioname.tpl 
    273      * b) name fileextension of the templates after the renderer (.xtpl, .phptpl, .tal). 
    274      * 
    275      * @param string $template Template Filename 
    276      * @return string 
    277      */ 
    278     public function getThemeTemplatePath($template) 
    279     { 
    280         $paths = self::getThemeTemplatePaths(); 
    281  
    282         return self::findFileInPaths($paths, $template); 
    283     } 
    284  
    285     /** 
    286      * Returns Module Template Paths 
    287      * 
    288      * @return array Module Template Paths 
    289      */ 
    290     public static function getModuleTemplatePaths() 
    291     { 
    292         # fetch modulename for template path construction 
    293         $module = Clansuite_TargetRoute::getModuleName(); 
    294  
    295         # fetch renderer name for template path construction 
    296         $renderer = Clansuite_HttpRequest::getRoute()->getRenderEngine(); 
    297  
    298         # compose templates paths in the module dir 
    299         $module_paths = array( 
    300             ROOT_MOD, 
    301             ROOT_MOD . $module . DS, 
    302             ROOT_MOD . $module . DS . 'view' . DS, 
    303             ROOT_MOD . $module . DS . 'view' . DS . $renderer . DS 
    304         ); 
    305  
    306         return $module_paths; 
    307     } 
    308  
    309     /** 
    310      * Returns the fullpath to Template by searching in the Module Template Path 
    311      * 
    312      * @param string $template Template Filename 
    313      * @return string 
    314      */ 
    315     public function getModuleTemplatePath($template) 
    316     { 
    317         $paths = self::getModuleTemplatePaths(); 
    318  
    319         # check if template exists in one of the defined paths 
    320         $module_template = null; 
    321         $module_template = self::findFileInPaths($paths, $template); 
    322         #Clansuite_Debug::firebug($module_template); 
    323         if($module_template != null) 
    324         { 
    325             return $module_template; 
    326         } 
    327         else 
    328         { 
    329             # fetch renderer name for template path construction 
    330             $renderer = Clansuite_HttpRequest::getRoute()->getRenderEngine(); 
    331  
    332             # the template with that name is not found on our default paths 
    333             return ROOT_THEMES_CORE . 'view' . DS . $renderer . DS . 'template_not_found.tpl'; 
    334         } 
    335     } 
    336  
    337     /** 
    338      * Checks all paths of the array for the filename 
    339      * 
    340      * @param array $paths Paths to check 
    341      * @param strig $filename template name 
    342      * @return string Filepath. 
    343      */ 
    344     public static function findFileInPaths($paths, $filename) 
    345     { 
    346         # check if file exists in one of the defined paths 
    347         foreach($paths as $path) 
    348         { 
    349             $file = $path . $filename; 
    350  
    351             #Clansuite_Debug::firebug($file); 
    352  
    353             if(is_file($file) === true) 
    354             { 
    355                 # file found 
    356                 return $file; 
    357             } 
    358         } 
    359  
    360         # file not found 
    361         return false; 
    362180    } 
    363181 
     
    386204        $template_constants['www_root_uploads']         = WWW_ROOT . 'uploads/'; 
    387205        $template_constants['www_root_mod']             = WWW_ROOT . 'modules/' . $modulename . '/'; 
    388         $template_constants['www_root_theme']           = $this->getTheme()->getWWWPath(); 
     206        $template_constants['www_root_theme']           = $this->getTheme()->getWebPath(); 
    389207        $template_constants['www_root_themes']          = WWW_ROOT_THEMES; 
    390208        $template_constants['www_root_themes_core']     = WWW_ROOT_THEMES_CORE; 
     
    465283    public function getLayoutTemplate() 
    466284    { 
    467         if ($this->layoutTemplate == null) 
    468         { 
    469             $this->setLayoutTemplate($this->getTheme()->getLayoutFile()); 
     285        if($this->layoutTemplate == null) 
     286        { 
     287            $this->setLayoutTemplate( $this->getTheme()->getLayoutFile() ); 
    470288        } 
    471289 
     
    546364        else 
    547365        { 
    548             throw new Exception('Method "'. $method .'" not existant in RenderEngine "' . get_class($this->renderer) .'"!', 1); 
     366            throw new Exception('Method "'. $method .'()" not existant in Render Engine "' . get_class($this->renderer) .'"!', 1); 
    549367        } 
    550368    } 
  • trunk/core/renderer/smarty.renderer.php

    r5940 r6002  
    213213         * 6) "/themes/" 
    214214         */ 
    215         $tpl_array = array( $this->getThemeTemplatePaths(), # 1 + 2 
    216                             $this->getModuleTemplatePaths(), # 3 + 4 
    217                             ROOT_THEMES_CORE . 'view' . DS . 'smarty', # 5 
    218                             ROOT_THEMES); # 6 
     215        $tpl_array = array( 
     216            Clansuite_View_Mapper::getThemeTemplatePaths(), # 1 + 2 
     217            Clansuite_View_Mapper::getModuleTemplatePaths(), # 3 + 4 
     218            ROOT_THEMES_CORE . 'view' . DS . 'smarty', # 5 
     219            ROOT_THEMES # 6 
     220        ); 
    219221 
    220222        # flatten that thing 
     
    233235 
    234236        $this->renderer->setPluginsDir( 
    235             array( ROOT_LIBRARIES . 'smarty' . DS . 'plugins', 
    236                    ROOT_CORE . 'viewhelper' . DS . 'smarty' . DS, 
    237                    ROOT_MOD . Clansuite_TargetRoute::getModuleName() . DS . 'viewhelper' . DS. 'smarty' . DS 
     237            array( 
     238                ROOT_LIBRARIES . 'smarty' . DS . 'plugins', 
     239                ROOT_CORE . 'viewhelper' . DS . 'smarty' . DS, 
     240                ROOT_MOD . Clansuite_TargetRoute::getModuleName() . DS . 'viewhelper' . DS . 'smarty' . DS 
    238241        )); 
    239242 
     
    398401    public function fetch($template, $cache_id = null, $compile_id = null, $parent = null, $display = false) 
    399402    { 
    400         # asks the parent class (renderer.base.core) for the template path 
    401         $template = $this->getTemplatePath($template); 
     403        # ask the view mapper for the template path 
     404        $template = Clansuite_View_Mapper::getTemplatePath($template); 
    402405 
    403406        # create cache_id 
     
    511514 
    512515        /** 
    513          * Rendering depends on the RenderMode 
     516         * Rendering depends on the RenderMode. 
    514517         * 
    515          * If the modulecontent should be rendered in a layout (LAYOUT) or without a layout (NOLAYOUT). 
     518         * RenderMode "NOLAYOUT" means that only the (module) content template is rendered. 
     519         * 
     520         * RenderMode "LAYOUT" means that the (module) content template is embedded, 
     521         * into a layout template, by replacing the {$content} placeholder. 
    516522         */ 
    517523        if($this->getRenderMode() === 'NOLAYOUT') 
  • trunk/core/renderer/templatemapper.php

    r5992 r6002  
    4646 * this class will help determining the template, 
    4747 * by mapping the requested class and action to a template. 
     48 * 
     49 * layout_template selection, depends on the main configuration and user selection (settings). 
     50 * 
    4851 */ 
    4952class Clansuite_View_Mapper 
    5053{ 
    5154    /** 
    52      * Template name. 
    53      * 
    54      * @var string 
    55      */ 
    56     public $template; 
     55     * @var string Template name. 
     56     */ 
     57    public $template = null; 
    5758 
    5859    /** 
     
    6768 
    6869        # whitelist definition for listing all allowed template filetypes 
    69         $allowed_extensions = array('html','php','tpl'); 
     70        $allowed_extensions = array('html', 'php', 'tpl'); 
    7071 
    7172        # check if extension is one of the allowed ones 
    72         if (false === in_array($template_extension, $allowed_extensions)) 
    73         { 
    74             $message = 'Template Extension invalid <strong>'.$template_extension.'</strong> on <strong>'.$template.'</strong>'; 
     73        if(false === in_array($template_extension, $allowed_extensions)) 
     74        { 
     75            $message = 'Template Extension invalid <strong>' . $template_extension . '</strong> on <strong>' . $template . '</strong>'; 
    7576            trigger_error($message, E_USER_NOTICE); 
    7677        } 
     
    106107        $this->template = (string) $template; 
    107108    } 
     109 
     110    /** 
     111     * Returns the Template Path 
     112     * 
     113     * Fetches the template by searching in the 
     114     * 1) Theme Template Paths 
     115     * 2) Modules Template Paths 
     116     * Note the Path Priority: Themes before Modules. 
     117     * 
     118     * @return $templatepath 
     119     */ 
     120    public static function getTemplatePath($template) 
     121    { 
     122        # done: if template is a qualified path and template filename 
     123        if(is_file($template) === true) 
     124        { 
     125            return $template; 
     126        } 
     127 
     128        # fetch the template by searching in the Theme Template Paths 
     129        $theme_template = self::getThemeTemplatePath($template); 
     130 
     131        # check if template was found there, else it's null 
     132        if($theme_template != null) 
     133        { 
     134            #Clansuite_Debug::firebug(__METHOD__ .' tries fetching template ("'. $theme_template . '") from THEME directory.'); 
     135            return $theme_template; 
     136        } 
     137        else # fetch the template by searching in the Module Template Path 
     138        { 
     139            #Clansuite_Debug::firebug(__METHOD__ .' tries fetching template ("'. $template . '") from MODULE directory.'); 
     140            return self::getModuleTemplatePath($template); 
     141        } 
     142    } 
     143 
     144    /** 
     145     * Return Theme Template Paths 
     146     * 
     147     * @return array Theme Template Paths 
     148     */ 
     149    public static function getThemeTemplatePaths() 
     150    { 
     151        # get module, submodule, renderer names 
     152        $module = Clansuite_HttpRequest::getRoute()->getModuleName(); 
     153        $submodule = Clansuite_HttpRequest::getRoute()->getSubModuleName(); 
     154        #$renderer  = Clansuite_HttpRequest::getRoute()->getRenderEngine(); 
     155 
     156        $theme_paths = array(); 
     157 
     158        /** 
     159         * 1. BACKEND THEME 
     160         * when controlcenter or admin is requested, it has to be a BACKEND theme 
     161         */ 
     162        if($module == 'controlcenter' or $submodule == 'admin') 
     163        { 
     164            # get backend theme from session for path construction 
     165            $backendtheme = Clansuite_HttpRequest::getRoute()->getBackendTheme(); 
     166 
     167            # (a) USER BACKENDTHEME - check in the active session backendtheme 
     168            # e.g. /themes/backend/ + admin/template_name.tpl 
     169            $theme_paths[] = ROOT_THEMES_BACKEND . $backendtheme . DS; 
     170            # e.g. /themes/backend/ + admin/modules/template_name.tpl 
     171            $theme_paths[] = ROOT_THEMES_BACKEND . $backendtheme . DS . 'modules' . DS . $module . DS; 
     172            # (b) BACKEND FALLBACK - check the fallback dir: themes/admin 
     173            $theme_paths[] = ROOT_THEMES_BACKEND . 'admin' . DS; 
     174        } 
     175        /** 
     176         * 2. FRONTEND THEME 
     177         */ 
     178        else 
     179        { 
     180            # get frontend theme from session for path construction 
     181            $frontendtheme = Clansuite_HttpRequest::getRoute()->getFrontendTheme(); 
     182 
     183            # (a) USER FRONTENDTHEME - check, if template exists in current session user THEME 
     184            $theme_paths[] = ROOT_THEMES_FRONTEND . $frontendtheme . DS; 
     185            # (b) FRONTEND FALLBACK - check, if template exists in usertheme/modulename/tpl 
     186            $theme_paths[] = ROOT_THEMES_FRONTEND . $frontendtheme . DS . 'modules' . DS . $module . DS; 
     187            # (c) FRONTEND FALLBACK - check, if template exists in standard theme 
     188            $theme_paths[] = ROOT_THEMES_FRONTEND . 'standard' . DS; 
     189        } 
     190 
     191        return $theme_paths; 
     192    } 
     193 
     194    /** 
     195     * Returns the fullpath to Template by searching in the Theme Template Paths 
     196     * 
     197     * Note: For the implementation of module specific renderers and their related templates two ways exist: 
     198     * a) add either a directory named after the "renderer/", like modules/modulename/view/renderer/actioname.tpl 
     199     * b) name fileextension of the templates after the renderer (.xtpl, .phptpl, .tal). 
     200     * 
     201     * @param string $template Template Filename 
     202     * @return string 
     203     */ 
     204    public static function getThemeTemplatePath($template) 
     205    { 
     206        $paths = self::getThemeTemplatePaths(); 
     207 
     208        return self::findFileInPaths($paths, $template); 
     209    } 
     210 
     211    /** 
     212     * Returns Module Template Paths 
     213     * 
     214     * @return array Module Template Paths 
     215     */ 
     216    public static function getModuleTemplatePaths() 
     217    { 
     218        # fetch modulename for template path construction 
     219        $module = Clansuite_TargetRoute::getModuleName(); 
     220 
     221        # fetch renderer name for template path construction 
     222        $renderer = Clansuite_HttpRequest::getRoute()->getRenderEngine(); 
     223 
     224        # compose templates paths in the module dir 
     225        $module_paths = array( 
     226            ROOT_MOD, 
     227            ROOT_MOD . $module . DS, 
     228            ROOT_MOD . $module . DS . 'view' . DS, 
     229            ROOT_MOD . $module . DS . 'view' . DS . $renderer . DS 
     230        ); 
     231 
     232        return $module_paths; 
     233    } 
     234 
     235    /** 
     236     * Returns the fullpath to Template by searching in the Module Template Path 
     237     * 
     238     * @param string $template Template Filename 
     239     * @return string 
     240     */ 
     241    public static function getModuleTemplatePath($template) 
     242    { 
     243        $paths = self::getModuleTemplatePaths(); 
     244 
     245        $module_template = null; 
     246 
     247        # check if template exists in one of the defined paths 
     248        $module_template = self::findFileInPaths($paths, $template); 
     249 
     250        if($module_template != null) 
     251        { 
     252            return $module_template; 
     253        } 
     254        else 
     255        { 
     256            # fetch renderer name for template path construction 
     257            $renderer = Clansuite_HttpRequest::getRoute()->getRenderEngine(); 
     258 
     259            # the template with that name is not found on our default paths 
     260            return ROOT_THEMES_CORE . 'view' . DS . $renderer . DS . 'template_not_found.tpl'; 
     261        } 
     262    } 
     263 
     264    /** 
     265     * Checks all paths of the array for the filename 
     266     * 
     267     * @param array $paths Paths to check 
     268     * @param strig $filename template name 
     269     * @return string Filepath. 
     270     */ 
     271    public static function findFileInPaths($paths, $filename) 
     272    { 
     273        # check if the file exists in one of the defined paths 
     274        foreach($paths as $path) 
     275        { 
     276            $file = $path . $filename; 
     277 
     278            if(is_file($file) === true) 
     279            { 
     280                # file found 
     281                return $file; 
     282            } 
     283        } 
     284 
     285        # file not found 
     286        return false; 
     287    } 
    108288} 
    109289?> 
Note: See TracChangeset for help on using the changeset viewer.