Changeset 6002
- Timestamp:
- 02/03/12 17:24:20 (4 months ago)
- Location:
- trunk/core
- Files:
-
- 4 edited
-
modulecontroller.core.php (modified) (3 diffs)
-
renderer/renderer.base.php (modified) (5 diffs)
-
renderer/smarty.renderer.php (modified) (4 diffs)
-
renderer/templatemapper.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/core/modulecontroller.core.php
r5992 r6002 411 411 public function display($templates = null) 412 412 { 413 include ROOT_CORE . 'renderer/templatemapper.php';414 413 $view_mapper = new Clansuite_View_Mapper; 415 414 … … 428 427 } 429 428 430 # only the content templateis set429 # only the "content template" is set 431 430 if(is_string($templates)) { $view_mapper->setTemplate($templates); } 432 431 433 432 # get the templatename 434 $template name= $view_mapper->getTemplateName();433 $template = $view_mapper->getTemplateName(); 435 434 436 435 # get the view … … 442 441 443 442 # render the content / template 444 $content = $this->view->render($template name);443 $content = $this->view->render($template); 445 444 446 445 # push content to the response object 447 446 $this->response->setContent($content); 448 447 449 unset($content, $template name);448 unset($content, $template); 450 449 } 451 450 -
trunk/core/renderer/renderer.base.php
r5974 r6002 61 61 */ 62 62 public $layoutTemplate = null; 63 64 /**65 63 * @var string The "content" template 66 64 */ … … 180 178 { 181 179 return $this->template; 182 }183 184 /**185 * Returns the Template Path186 *187 * Fetches the template by searching in the188 * 1) Theme Template Paths189 * 2) Modules Template Paths190 * Note the Path Priority: Themes before Modules.191 *192 * @return $templatepath193 */194 public function getTemplatePath($template)195 {196 # done: if template is a qualified path and template filename197 if(is_file($template) === true)198 {199 return $template;200 }201 202 # fetch the template by searching in the Theme Template Paths203 $theme_template = $this->getThemeTemplatePath($template);204 205 # check if template was found there, else it's null206 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 Path212 {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 Paths220 *221 * @return array Theme Template Paths222 */223 public static function getThemeTemplatePaths()224 {225 # get module, submodule, renderer names226 $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 THEME234 * when controlcenter or admin is requested, it has to be a BACKEND theme235 */236 if($module == 'controlcenter' or $submodule == 'admin')237 {238 # get backend theme from session for path construction239 $backendtheme = Clansuite_HttpRequest::getRoute()->getBackendTheme();240 241 # (a) USER BACKENDTHEME - check in the active session backendtheme242 # e.g. /themes/backend/ + admin/template_name.tpl243 $theme_paths[] = ROOT_THEMES_BACKEND . $backendtheme . DS;244 # e.g. /themes/backend/ + admin/modules/template_name.tpl245 $theme_paths[] = ROOT_THEMES_BACKEND . $backendtheme . DS . 'modules' . DS . $module . DS;246 # (b) BACKEND FALLBACK - check the fallback dir: themes/admin247 $theme_paths[] = ROOT_THEMES_BACKEND . 'admin' . DS;248 }249 /**250 * 2. FRONTEND THEME251 */252 else253 {254 # get frontend theme from session for path construction255 $frontendtheme = Clansuite_HttpRequest::getRoute()->getFrontendTheme();256 257 # (a) USER FRONTENDTHEME - check, if template exists in current session user THEME258 $theme_paths[] = ROOT_THEMES_FRONTEND . $frontendtheme . DS;259 # (b) FRONTEND FALLBACK - check, if template exists in usertheme/modulename/tpl260 $theme_paths[] = ROOT_THEMES_FRONTEND . $frontendtheme . DS . 'modules' . DS . $module . DS;261 # (c) FRONTEND FALLBACK - check, if template exists in standard theme262 $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 Paths270 *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.tpl273 * b) name fileextension of the templates after the renderer (.xtpl, .phptpl, .tal).274 *275 * @param string $template Template Filename276 * @return string277 */278 public function getThemeTemplatePath($template)279 {280 $paths = self::getThemeTemplatePaths();281 282 return self::findFileInPaths($paths, $template);283 }284 285 /**286 * Returns Module Template Paths287 *288 * @return array Module Template Paths289 */290 public static function getModuleTemplatePaths()291 {292 # fetch modulename for template path construction293 $module = Clansuite_TargetRoute::getModuleName();294 295 # fetch renderer name for template path construction296 $renderer = Clansuite_HttpRequest::getRoute()->getRenderEngine();297 298 # compose templates paths in the module dir299 $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 . DS304 );305 306 return $module_paths;307 }308 309 /**310 * Returns the fullpath to Template by searching in the Module Template Path311 *312 * @param string $template Template Filename313 * @return string314 */315 public function getModuleTemplatePath($template)316 {317 $paths = self::getModuleTemplatePaths();318 319 # check if template exists in one of the defined paths320 $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 else328 {329 # fetch renderer name for template path construction330 $renderer = Clansuite_HttpRequest::getRoute()->getRenderEngine();331 332 # the template with that name is not found on our default paths333 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 filename339 *340 * @param array $paths Paths to check341 * @param strig $filename template name342 * @return string Filepath.343 */344 public static function findFileInPaths($paths, $filename)345 {346 # check if file exists in one of the defined paths347 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 found356 return $file;357 }358 }359 360 # file not found361 return false;362 180 } 363 181 … … 386 204 $template_constants['www_root_uploads'] = WWW_ROOT . 'uploads/'; 387 205 $template_constants['www_root_mod'] = WWW_ROOT . 'modules/' . $modulename . '/'; 388 $template_constants['www_root_theme'] = $this->getTheme()->getW WWPath();206 $template_constants['www_root_theme'] = $this->getTheme()->getWebPath(); 389 207 $template_constants['www_root_themes'] = WWW_ROOT_THEMES; 390 208 $template_constants['www_root_themes_core'] = WWW_ROOT_THEMES_CORE; … … 465 283 public function getLayoutTemplate() 466 284 { 467 if ($this->layoutTemplate == null)468 { 469 $this->setLayoutTemplate( $this->getTheme()->getLayoutFile());285 if($this->layoutTemplate == null) 286 { 287 $this->setLayoutTemplate( $this->getTheme()->getLayoutFile() ); 470 288 } 471 289 … … 546 364 else 547 365 { 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); 549 367 } 550 368 } -
trunk/core/renderer/smarty.renderer.php
r5940 r6002 213 213 * 6) "/themes/" 214 214 */ 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 ); 219 221 220 222 # flatten that thing … … 233 235 234 236 $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 238 241 )); 239 242 … … 398 401 public function fetch($template, $cache_id = null, $compile_id = null, $parent = null, $display = false) 399 402 { 400 # ask s the parent class (renderer.base.core)for the template path401 $template = $this->getTemplatePath($template);403 # ask the view mapper for the template path 404 $template = Clansuite_View_Mapper::getTemplatePath($template); 402 405 403 406 # create cache_id … … 511 514 512 515 /** 513 * Rendering depends on the RenderMode 516 * Rendering depends on the RenderMode. 514 517 * 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. 516 522 */ 517 523 if($this->getRenderMode() === 'NOLAYOUT') -
trunk/core/renderer/templatemapper.php
r5992 r6002 46 46 * this class will help determining the template, 47 47 * 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 * 48 51 */ 49 52 class Clansuite_View_Mapper 50 53 { 51 54 /** 52 * Template name. 53 * 54 * @var string 55 */ 56 public $template; 55 * @var string Template name. 56 */ 57 public $template = null; 57 58 58 59 /** … … 67 68 68 69 # whitelist definition for listing all allowed template filetypes 69 $allowed_extensions = array('html', 'php','tpl');70 $allowed_extensions = array('html', 'php', 'tpl'); 70 71 71 72 # 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>'; 75 76 trigger_error($message, E_USER_NOTICE); 76 77 } … … 106 107 $this->template = (string) $template; 107 108 } 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 } 108 288 } 109 289 ?>
Note: See TracChangeset
for help on using the changeset viewer.
