Changeset 1128:9e868a6c21c3
- Timestamp:
- 03/25/13 04:31:18 (12 years ago)
- Branch:
- twig
- Location:
- inc
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/admin/class.dc.admincontext.php
r1091 r1128 13 13 14 14 /** 15 @ingroup DC_CORE16 @brief Template extension for admin context 17 18 This extends template environment with tools required in admin context.19 */20 class dcAdminContext extends Twig_Extension15 * @ingroup DC_CORE 16 * @brief Template extension for admin context. 17 * 18 * This extends template environment with tools required in admin context. 19 */ 20 class dcAdminContext extends dcContext 21 21 { 22 protected $core;23 protected $globals = array();24 protected $protected_globals = array();25 protected $memory = array();26 27 22 public function __construct($core) 28 23 { 29 $this->core = $core; 30 31 # Globals editable via context 32 $this->globals = array(); 33 34 # Globals not editable via context 35 $this->protected_globals = array( 36 'messages' => array( 37 'static' => array(), 38 'lists' => array(), 39 'alert' => '', 40 'errors' => array() 41 ), 42 24 parent::__construct($core); 25 26 $this->protected_globals = array_merge($this->protected_globals,array( 43 27 'page_title' => array(), 44 28 'page_global' => false, … … 47 31 'theme_url' => DC_ADMIN_URL.'index.php?tf=', 48 32 'plugin_url' => DC_ADMIN_URL.'index.php?pf=', 49 50 'version' => DC_VERSION, 51 'vendor_name' => DC_VENDOR_NAME, 52 53 'safe_mode' => isset($_SESSION['sess_safe_mode']) && $_SESSION['sess_safe_mode'], 54 'debug_mode' => DC_DEBUG 55 ); 56 } 57 58 /** 59 Prevent call crash from template on method that return this class 60 */ 61 public function __toString() 62 { 63 return ''; 64 } 65 66 /** 67 Test a global variable 68 69 @param string $name Name of the variable to test 70 @return boolean 71 */ 72 public function __isset($name) 73 { 74 return isset($this->globals[$name]); 75 } 76 77 /** 78 Add a global variable 79 80 @param string $name Name of the variable 81 @param mixed $value Value of the variable 82 */ 83 public function __set($name,$value) 84 { 85 /* 86 # Overload protect 87 if ($value === null && isset($this->globals[$name])) { 88 unset($this->globals[$name]); 89 } 90 elseif (!isset($this->globals[$name])) { 91 throw new Exception('Modification of overloaded globals has no effect'); 92 } 93 //*/ 94 $this->globals[$name] = $value; 95 } 96 97 /** 98 Get a global variable 99 100 @param string $name Name of the variable 101 @return mixed Value of the variable or null 102 */ 103 public function __get($name) 104 { 105 return isset($this->globals[$name]) ? $this->globals[$name] : null; 106 } 107 108 /** 109 Returns a list of filters to add to the existing list. 110 111 @return array An array of filters 112 */ 113 public function getFilters() 114 { 115 return array( 116 'trans' => new Twig_Filter_Function("__", array('is_safe' => array('html'))) 117 ); 118 } 119 120 /** 121 Returns a list of functions to add to the existing list. 122 123 @return array An array of functions 124 */ 125 public function getFunctions() 126 { 127 return array( 128 '__' => new Twig_Function_Function("__", array('is_safe' => array('html'))), 129 'debug_info' => new Twig_Function_Method($this, 'getDebugInfo', array('is_safe' => array('html'))), 130 'memorize' => new Twig_Function_Method($this, 'setMemory', array('is_safe' => array('html'))), 131 'memorized' => new Twig_Function_Method($this, 'getMemory', array('is_safe' => array('html'))) 132 ); 133 } 134 135 /** 136 Returns a list of global variables to add to the existing list. 137 138 This merges overloaded variables with defined variables. 139 140 @return array An array of global variables 141 */ 33 )); 34 } 35 36 /** 37 * Returns a list of global variables to add to the existing list. 38 * 39 * This merges overloaded variables with defined variables. 40 * 41 * @return array An array of global variables 42 */ 142 43 public function getGlobals() 143 44 { … … 164 65 165 66 /** 166 Returns the name of the extension. 167 168 @return string The extension name 169 */ 170 public function getName() 171 { 172 return 'AdminContext'; 173 } 174 175 176 /** 177 Add an informational message 178 179 @param string $message A message 180 @return object self 181 */ 182 public function setSafeMode($safe_mode) 183 { 184 $this->protected_globals['safe_mode'] = (boolean) $safe_mode; 185 return $this; 186 } 187 188 /** 189 Add an informational message 190 191 @param string $message A message 192 @return object self 193 */ 194 public function addMessageStatic($message) 195 { 196 $this->protected_globals['messages']['static'][] = $message; 197 return $this; 198 } 199 200 /** 201 Add a list of informational messages 202 203 @param string $message A title 204 @param array $message A list of messages 205 @return object self 206 */ 207 public function addMessagesList($title,$messages) 208 { 209 $this->protected_globals['messages']['lists'][$title] = $messages; 210 return $this; 211 } 212 213 /** 214 Set an important message 215 216 @param string $message A message 217 @return object self 218 */ 219 public function setAlert($message) 220 { 221 $this->protected_globals['messages']['alert'] = $message; 222 return $this; 223 } 224 225 /** 226 Add an error message 227 228 @param string Error message 229 @return object self 230 */ 231 public function addError($error) 232 { 233 $this->protected_globals['messages']['errors'][] = $error; 234 return $this; 235 } 236 237 /** 238 Check if there is an error message 239 240 @return boolean 241 */ 242 public function hasError() 243 { 244 return !empty($this->protected_globals['messages']['errors']); 245 } 246 247 /** 248 Fill the page title 249 250 $title can be: 251 a string for page title part or 252 TRUE to add blog name at the begining of title or 253 NULL to empty/reset title 254 255 @param mixed $title A title part 256 @param boolean $url Link of the title part 257 @return object self 258 */ 67 * Fill the page title. 68 * 69 * $title can be: 70 * - a string for page title part or 71 * - TRUE to add blog name at the begining of title or 72 * - NULL to empty/reset title 73 * 74 * @param mixed $title A title part 75 * @param boolean $url Link of the title part 76 * @return object self 77 */ 259 78 public function fillPageTitle($title,$url='') 260 79 { … … 276 95 277 96 /** 278 Check if a page title is set279 */97 * Check if a page title is set 98 */ 280 99 public function hasPageTitle() 281 100 { … … 284 103 285 104 /** 286 Get list of blogs287 */105 * Get list of blogs 106 */ 288 107 protected function getBlogs() 289 108 { … … 321 140 322 141 /** 323 Get current blog information324 */142 * Get current blog information 143 */ 325 144 protected function getCurrentBlog() 326 145 { … … 346 165 347 166 /** 348 Get current user information349 */167 * Get current user information 168 */ 350 169 protected function getCurrentUser() 351 170 { … … 395 214 396 215 /** 397 Get sidebar menus398 */216 * Get sidebar menus 217 */ 399 218 protected function getMenus() 400 219 { … … 416 235 } 417 236 } 418 419 /**420 Get an array of debug/dev infos421 */422 public function getDebugInfo()423 {424 if (!DC_DEBUG) {425 return array();426 }427 428 $di = array(429 'global_vars' => implode(', ',array_keys($GLOBALS)),430 'memory' => array(431 'usage' => memory_get_usage(),432 'size' => files::size(memory_get_usage())433 ),434 'xdebug' => array()435 );436 437 if (function_exists('xdebug_get_profiler_filename')) {438 439 $url = http::getSelfURI();440 $url .= strpos($url,'?') === false ? '?' : '&';441 $url .= 'XDEBUG_PROFILE';442 443 $di['xdebug'] = array(444 'elapse_time' => xdebug_time_index(),445 'profiler_file' => xdebug_get_profiler_filename(),446 'profiler_url' => $url447 );448 449 /* xdebug configuration:450 zend_extension = /.../xdebug.so451 xdebug.auto_trace = On452 xdebug.trace_format = 0453 xdebug.trace_options = 1454 xdebug.show_mem_delta = On455 xdebug.profiler_enable = 0456 xdebug.profiler_enable_trigger = 1457 xdebug.profiler_output_dir = /tmp458 xdebug.profiler_append = 0459 xdebug.profiler_output_name = timestamp460 */461 }462 463 return $di;464 }465 466 /**467 Add a value in a namespace memory468 469 This help keep variable when recalling Twig macros470 471 @param string $ns A namespace472 @param string $str A value to memorize in this namespace473 */474 public function setMemory($ns,$str)475 {476 if (!array_key_exists($ns,$this->memory) || !in_array($str,$this->memory[$ns])) {477 $this->memory[$ns][] = $str;478 }479 }480 481 /**482 Check if a value is previously memorized in a namespace483 484 @param string $ns A namespace485 @param string $str A value to search in this namespace486 @return array True if exists487 */488 public function getMemory($ns,$str)489 {490 return array_key_exists($ns,$this->memory) && in_array($str,$this->memory[$ns]);491 }492 237 } 493 238 ?> -
inc/core/class.dc.core.php
r1099 r1128 97 97 $this->addFormater('wiki', array($this,'wikiTransform')); 98 98 99 $this-> loadTemplateEnvironment();99 $this->tpl = new dcTemplate(DC_TPL_CACHE,'$core->tpl',$this); 100 100 } 101 101 … … 119 119 120 120 return new $c($this); 121 }122 123 /**124 Create template environment (Twig_Environment instance)125 126 default-templates path must be added from admin|public/prepend.php with:127 $core->tpl->getLoader()->addPath('PATH_TO/default-templates');128 Selected theme path must be added with:129 $core->tpl->getLoader()->prependPath('PATH_TO/MY_THEME');130 */131 protected function loadTemplateEnvironment()132 {133 # If cache dir is writable, use it.134 $cache_dir = path::real(DC_TPL_CACHE.'/twtpl',false);135 if (!is_dir($cache_dir)) {136 try {137 files::makeDir($cache_dir);138 } catch (Exception $e) {139 $cache_dir = false;140 }141 }142 143 $this->tpl = new Twig_Environment(144 new Twig_Loader_Filesystem(dirname(__FILE__).'/../swf'),145 array(146 'auto_reload' => true,147 'autoescape' => false,148 'base_template_class' => 'Twig_Template',149 'cache' => $cache_dir,150 'charset' => 'UTF-8',151 'debug' => DC_DEBUG,152 'optimizations' => -1,153 'strict_variables' => 0 //DC_DEBUG // Please fix undefined variables!154 )155 );156 $this->tpl->addExtension(new dcFormExtension($this));157 $this->tpl->addExtension(new dcTabExtension($this));158 121 } 159 122 -
inc/prepend.php
r1106 r1128 46 46 $__autoload['dcWorkspace'] = dirname(__FILE__).'/core/class.dc.workspace.php'; 47 47 $__autoload['dcPrefs'] = dirname(__FILE__).'/core/class.dc.prefs.php'; 48 $__autoload['dcTwigPage'] = dirname(__FILE__).'/core/class.dc.twig.page.php'; 48 //$__autoload['dcTwigPage'] = dirname(__FILE__).'/core/class.dc.twig.page.php'; 49 $__autoload['dcTemplate'] = dirname(__FILE__).'/core/class.dc.template.php'; 50 $__autoload['dcContext'] = dirname(__FILE__).'/core/class.dc.context.php'; 49 51 50 52 $__autoload['rsExtPost'] = dirname(__FILE__).'/core/class.dc.rs.extensions.php'; … … 62 64 $__autoload['adminUserList'] = dirname(__FILE__).'/admin/lib.pager.php'; 63 65 64 $__autoload['dcTemplate'] = dirname(__FILE__).'/public/class.dc.template.php'; 65 $__autoload['context'] = dirname(__FILE__).'/public/lib.tpl.context.php'; 66 $__autoload['dcPublicContext'] = dirname(__FILE__).'/public/class.dc.publiccontext.php'; 67 //$__autoload['dcTemplate'] = dirname(__FILE__).'/public/class.dc.template.php'; 68 //$__autoload['context'] = dirname(__FILE__).'/public/lib.tpl.context.php'; 66 69 $__autoload['dcUrlHandlers'] = dirname(__FILE__).'/public/lib.urlhandlers.php'; 67 70 $__autoload['dcForm'] = dirname(__FILE__).'/admin/class.dc.form.php'; -
inc/public/lib.urlhandlers.php
r779 r1128 86 86 $_ctx->nb_entry_per_page = $core->blog->settings->system->nb_post_per_page; 87 87 } 88 89 // Break public template here for now 90 // just to check if template engine is well loaded. 91 $core->tpl->display($tpl.'.twig'); 92 // To be continued... 88 93 89 94 $tpl_file = $core->tpl->getFilePath($tpl); -
inc/public/prepend.php
r921 r1128 55 55 } catch (Exception $e) {} 56 56 57 # Add public default templates path 58 $core->tpl->getLoader()->addPath(dirname(__FILE__).'/default-templates'); 59 # Set public context 60 $_ctx = new dcPublicContext($core); 61 $core->tpl->addExtension($_ctx); 62 63 /* 57 64 # Creating template context 58 65 $_ctx = new context(); … … 64 71 ,640); 65 72 } 66 73 */ 67 74 # Loading locales 68 75 $_lang = $core->blog->settings->system->lang; … … 120 127 121 128 # --BEHAVIOR-- publicPrepend 122 $core->callBehavior('publicPrepend',$core );129 $core->callBehavior('publicPrepend',$core,$_ctx); 123 130 124 131 # Prepare the HTTP cache thing … … 127 134 $mod_ts[] = $core->blog->upddt; 128 135 136 137 # Add parent theme path 138 if ($__parent_theme && is_dir($core->blog->themes_path.'/'.$__parent_theme.'/tpl')) { 139 $core->tpl->getLoader()->addPath($core->blog->themes_path.'/'.$__parent_theme.'/tpl'); 140 } 141 # Add theme path at the begining of path list 142 if (is_dir($core->blog->themes_path.'/'.$__theme.'/tpl')) { 143 $core->tpl->getLoader()->prependPath($core->blog->themes_path.'/'.$__theme.'/tpl'); 144 } 145 /* 129 146 $__theme_tpl_path = array( 130 147 $core->blog->themes_path.'/'.$__theme.'/tpl' … … 138 155 dirname(__FILE__).'/default-templates', 139 156 $core->tpl->getPath()); 140 157 */ 141 158 $core->url->mode = $core->blog->settings->system->url_scan; 142 159
Note: See TracChangeset
for help on using the changeset viewer.