Total Complexity | 110 |
Total Lines | 743 |
Duplicated Lines | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
Complex classes like xos_opal_Theme often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use xos_opal_Theme, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
151 | class xos_opal_Theme |
||
152 | { |
||
153 | /** |
||
154 | * Should we render banner? Not for redirect pages or admin side |
||
155 | * |
||
156 | * @var bool |
||
157 | */ |
||
158 | public $renderBanner = true; |
||
159 | /** |
||
160 | * The name of this theme |
||
161 | * |
||
162 | * @var string |
||
163 | */ |
||
164 | public $folderName = ''; |
||
165 | /** |
||
166 | * Physical path of this theme folder |
||
167 | * |
||
168 | * @var string |
||
169 | */ |
||
170 | public $path = ''; |
||
171 | public $url = ''; |
||
172 | |||
173 | /** |
||
174 | * Whether or not the theme engine should include the output generated by php |
||
175 | * |
||
176 | * @var string |
||
177 | */ |
||
178 | public $bufferOutput = true; |
||
179 | /** |
||
180 | * Canvas-level template to use |
||
181 | * |
||
182 | * @var string |
||
183 | */ |
||
184 | public $canvasTemplate = 'theme.tpl'; |
||
185 | |||
186 | /** |
||
187 | * Theme folder path |
||
188 | * |
||
189 | * @var string |
||
190 | */ |
||
191 | public $themesPath = 'themes'; |
||
192 | |||
193 | /** |
||
194 | * Content-level template to use |
||
195 | * |
||
196 | * @var string |
||
197 | */ |
||
198 | public $contentTemplate = ''; |
||
199 | |||
200 | public $contentCacheLifetime = 0; |
||
201 | public $contentCacheId; |
||
202 | |||
203 | /** |
||
204 | * Text content to display right after the contentTemplate output |
||
205 | * |
||
206 | * @var string |
||
207 | */ |
||
208 | public $content = ''; |
||
209 | /** |
||
210 | * Page construction plug-ins to use |
||
211 | * |
||
212 | * @var array |
||
213 | * @access public |
||
214 | */ |
||
215 | public $plugins = array( |
||
216 | 'xos_logos_PageBuilder'); |
||
217 | public $renderCount = 0; |
||
218 | /** |
||
219 | * Pointer to the theme template engine |
||
220 | * |
||
221 | * @var XoopsTpl |
||
222 | */ |
||
223 | public $template = false; |
||
224 | |||
225 | /** |
||
226 | * Array containing the document meta-information |
||
227 | * |
||
228 | * @var array |
||
229 | */ |
||
230 | public $metas = array( |
||
231 | //'http' => array( |
||
232 | // 'Content-Script-Type' => 'text/javascript' , |
||
233 | // 'Content-Style-Type' => 'text/css') , |
||
234 | 'meta' => array(), |
||
235 | 'link' => array(), |
||
236 | 'script' => array()); |
||
237 | |||
238 | /** |
||
239 | * Array of strings to be inserted in the head tag of HTML documents |
||
240 | * |
||
241 | * @var array |
||
242 | */ |
||
243 | public $htmlHeadStrings = array(); |
||
244 | /** |
||
245 | * Custom variables that will always be assigned to the template |
||
246 | * |
||
247 | * @var array |
||
248 | */ |
||
249 | public $templateVars = array(); |
||
250 | |||
251 | /** |
||
252 | * User extra information for cache id, like language, user groups |
||
253 | * |
||
254 | * @var boolean |
||
255 | */ |
||
256 | public $use_extra_cache_id = true; |
||
257 | |||
258 | /** |
||
259 | * *#@- |
||
260 | */ |
||
261 | |||
262 | /** |
||
263 | * *#@+ |
||
264 | * |
||
265 | * @tasktype 10 Initialization |
||
266 | */ |
||
267 | /** |
||
268 | * Initializes this theme |
||
269 | * |
||
270 | * Upon initialization, the theme creates its template engine and instantiates the |
||
271 | * plug-ins from the specified {@link $plugins} list. If the theme is a 2.0 theme, that does not |
||
272 | * display redirection messages, the HTTP redirections system is disabled to ensure users will |
||
273 | * see the redirection screen. |
||
274 | * |
||
275 | * @param array $options |
||
276 | * @return bool |
||
277 | */ |
||
278 | public function xoInit($options = array()) |
||
|
|||
279 | { |
||
280 | /** @var XoopsConfigHandler $configHandler */ |
||
281 | $configHandler = xoops_getHandler('config'); |
||
282 | |||
283 | $this->path = XOOPS_THEME_PATH . '/' . $this->folderName; |
||
284 | $this->url = XOOPS_THEME_URL . '/' . $this->folderName; |
||
285 | $this->template = null; |
||
286 | $this->template = new XoopsTpl(); |
||
287 | $this->template->currentTheme = $this; |
||
288 | $this->template->assign_by_ref('xoTheme', $this); |
||
289 | $GLOBALS['xoTheme'] = $this; |
||
290 | $GLOBALS['xoopsTpl'] = $this->template; |
||
291 | $tempPath = str_replace('\\', '/', realpath(XOOPS_ROOT_PATH) . '/'); |
||
292 | $tempName = str_replace('\\', '/', realpath($_SERVER['SCRIPT_FILENAME'])); |
||
293 | $xoops_page = str_replace($tempPath, '', $tempName); |
||
294 | if (strpos($xoops_page, 'modules') !== false) { |
||
295 | $xoops_page = str_replace('modules/', '', $xoops_page); |
||
296 | } |
||
297 | $tempScriptname = str_replace('\\', '/', $_SERVER['SCRIPT_NAME']); |
||
298 | $tempRequesturi = str_replace('\\', '/', Request::getString('REQUEST_URI', '', 'SERVER')); |
||
299 | if (strlen($tempRequesturi) > strlen($tempScriptname)) { |
||
300 | $xoops_modulepage = $xoops_page . str_replace($tempScriptname, '', $tempRequesturi); |
||
301 | } else { |
||
302 | $xoops_modulepage = ''; |
||
303 | } |
||
304 | $xoops_page = str_replace('.php', '', $xoops_page); |
||
305 | if (isset($GLOBALS['xoopsConfig']['startpage'])) { |
||
306 | $xoops_startpage = $GLOBALS['xoopsConfig']['startpage']; |
||
307 | if ($xoops_startpage == '--') { |
||
308 | $xoops_startpage = 'system'; |
||
309 | } |
||
310 | } else { |
||
311 | $xoops_startpage = 'system'; |
||
312 | } |
||
313 | // call the theme_autorun.php if the theme has one |
||
314 | if (file_exists($this->path . "/theme_autorun.php")) { |
||
315 | include_once($this->path . "/theme_autorun.php"); |
||
316 | } |
||
317 | |||
318 | $searchConfig = $configHandler->getConfigsByCat(XOOPS_CONF_SEARCH); |
||
319 | $xoops_search = (bool) (isset($searchConfig['enable_search']) && $searchConfig['enable_search'] === 1); |
||
320 | $this->template->assign(array( |
||
321 | 'xoops_theme' => $GLOBALS['xoopsConfig']['theme_set'], |
||
322 | 'xoops_imageurl' => XOOPS_THEME_URL . '/' . $GLOBALS['xoopsConfig']['theme_set'] . '/', |
||
323 | 'xoops_themecss' => xoops_getcss($GLOBALS['xoopsConfig']['theme_set']), |
||
324 | 'xoops_requesturi' => htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES), |
||
325 | 'xoops_sitename' => htmlspecialchars($GLOBALS['xoopsConfig']['sitename'], ENT_QUOTES), |
||
326 | 'xoops_slogan' => htmlspecialchars($GLOBALS['xoopsConfig']['slogan'], ENT_QUOTES), |
||
327 | 'xoops_dirname' => isset($GLOBALS['xoopsModule']) && is_object($GLOBALS['xoopsModule']) |
||
328 | ? $GLOBALS['xoopsModule']->getVar('dirname') : 'system', |
||
329 | 'xoops_page' => $xoops_page, |
||
330 | 'xoops_startpage' => $xoops_startpage, |
||
331 | 'xoops_modulepage' => $xoops_modulepage, |
||
332 | 'xoops_banner' => ($GLOBALS['xoopsConfig']['banners'] && $this->renderBanner) |
||
333 | ? xoops_getbanner() : ' ', |
||
334 | 'xoops_pagetitle' => isset($GLOBALS['xoopsModule']) && is_object($GLOBALS['xoopsModule']) |
||
335 | ? $GLOBALS['xoopsModule']->getVar('name') |
||
336 | : htmlspecialchars($GLOBALS['xoopsConfig']['slogan'], ENT_QUOTES), |
||
337 | 'xoops_search' => $xoops_search, |
||
338 | )); |
||
339 | if (isset($GLOBALS['xoopsUser']) && is_object($GLOBALS['xoopsUser'])) { |
||
340 | $this->template->assign(array( |
||
341 | 'xoops_isuser' => true, |
||
342 | 'xoops_avatar' => XOOPS_UPLOAD_URL . '/' . $GLOBALS['xoopsUser']->getVar('user_avatar'), |
||
343 | 'xoops_userid' => $GLOBALS['xoopsUser']->getVar('uid'), |
||
344 | 'xoops_uname' => $GLOBALS['xoopsUser']->getVar('uname'), |
||
345 | 'xoops_name' => $GLOBALS['xoopsUser']->getVar('name'), |
||
346 | 'xoops_isadmin' => $GLOBALS['xoopsUserIsAdmin'], |
||
347 | 'xoops_usergroups' => $GLOBALS['xoopsUser']->getGroups(), |
||
348 | )); |
||
349 | } else { |
||
350 | $this->template->assign(array( |
||
351 | 'xoops_isuser' => false, |
||
352 | 'xoops_isadmin' => false, |
||
353 | 'xoops_usergroups' => array(XOOPS_GROUP_ANONYMOUS), |
||
354 | )); |
||
355 | } |
||
356 | |||
357 | // Meta tags |
||
358 | $criteria = new CriteriaCompo(new Criteria('conf_modid', 0)); |
||
359 | $criteria->add(new Criteria('conf_catid', XOOPS_CONF_METAFOOTER)); |
||
360 | $config = $configHandler->getConfigs($criteria, true); |
||
361 | foreach (array_keys($config) as $i) { |
||
362 | $name = $config[$i]->getVar('conf_name', 'n'); |
||
363 | $value = $config[$i]->getVar('conf_value', 'n'); |
||
364 | // limited substitutions for {X_SITEURL} and {X_YEAR} |
||
365 | if ($name === 'footer' || $name === 'meta_copyright') { |
||
366 | $value = str_replace('{X_SITEURL}', XOOPS_URL . '/', $value); |
||
367 | $value = str_replace('{X_YEAR}', date('Y', time()), $value); |
||
368 | } |
||
369 | if (substr($name, 0, 5) === 'meta_') { |
||
370 | $this->addMeta('meta', substr($name, 5), $value); |
||
371 | } else { |
||
372 | // prefix each tag with 'xoops_' |
||
373 | $this->template->assign("xoops_$name", $value); |
||
374 | } |
||
375 | } |
||
376 | // Load global javascript |
||
377 | $this->addScript('include/xoops.js'); |
||
378 | $this->loadLocalization(); |
||
379 | |||
380 | if ($this->bufferOutput) { |
||
381 | ob_start(); |
||
382 | } |
||
383 | // Instantiate and initialize all the theme plugins |
||
384 | foreach ($this->plugins as $k => $bundleId) { |
||
385 | if (!is_object($bundleId)) { |
||
386 | $this->plugins[$bundleId] = null; |
||
387 | $this->plugins[$bundleId] = new $bundleId(); |
||
388 | $this->plugins[$bundleId]->theme =& $this; |
||
389 | $this->plugins[$bundleId]->xoInit(); |
||
390 | unset($this->plugins[$k]); |
||
391 | } |
||
392 | } |
||
393 | |||
394 | return true; |
||
395 | } |
||
396 | |||
397 | /** |
||
398 | * Generate cache id based on extra information of language and user groups |
||
399 | * |
||
400 | * User groups other than anonymous should be detected to avoid disclosing group sensitive contents |
||
401 | * |
||
402 | * @param string $cache_id raw cache id |
||
403 | * @param string $extraString extra string |
||
404 | * @return string complete cache id |
||
405 | */ |
||
406 | public function generateCacheId($cache_id, $extraString = '') |
||
407 | { |
||
408 | static $extra_string; |
||
409 | if (!$this->use_extra_cache_id) { |
||
410 | return $cache_id; |
||
411 | } |
||
412 | |||
413 | if (empty($extraString)) { |
||
414 | if (empty($extra_string)) { |
||
415 | // Generate language section |
||
416 | $extra_string = $GLOBALS['xoopsConfig']['language']; |
||
417 | // Generate group section |
||
418 | if (!isset($GLOBALS['xoopsUser']) || !is_object($GLOBALS['xoopsUser'])) { |
||
419 | $extra_string .= '-' . XOOPS_GROUP_ANONYMOUS; |
||
420 | } else { |
||
421 | $groups = $GLOBALS['xoopsUser']->getGroups(); |
||
422 | sort($groups); |
||
423 | // Generate group string for non-anonymous groups, |
||
424 | // XOOPS_DB_PASS and XOOPS_DB_NAME (before we find better variables) are used to protect group sensitive contents |
||
425 | $extra_string .= '-' . substr(md5(implode('-', $groups)), 0, 8) . '-' . substr(md5(XOOPS_DB_PASS . XOOPS_DB_NAME . XOOPS_DB_USER), 0, 8); |
||
426 | } |
||
427 | } |
||
428 | $extraString = $extra_string; |
||
429 | } |
||
430 | $cache_id .= '-' . $extraString; |
||
431 | |||
432 | return $cache_id; |
||
433 | } |
||
434 | |||
435 | /** |
||
436 | * xos_opal_Theme::checkCache() |
||
437 | * |
||
438 | * @return bool |
||
439 | */ |
||
440 | public function checkCache() |
||
462 | } |
||
463 | |||
464 | /** |
||
465 | * Render the page |
||
466 | * |
||
467 | * The theme engine builds pages from 2 templates: canvas and content. |
||
468 | * |
||
469 | * A module can call this method directly and specify what templates the theme engine must use. |
||
470 | * If render() hasn't been called before, the theme defaults will be used for the canvas and |
||
471 | * page template (and xoopsOption['template_main'] for the content). |
||
472 | * |
||
473 | * @param string $canvasTpl The canvas template, if different from the theme default |
||
474 | * @param string $pageTpl The page template, if different from the theme default (unsupported, 2.3+ only) |
||
475 | * @param string $contentTpl The content template |
||
476 | * @param array $vars Template variables to send to the template engine |
||
477 | * |
||
478 | * @return bool |
||
479 | */ |
||
480 | public function render($canvasTpl = null, $pageTpl = null, $contentTpl = null, $vars = array()) |
||
481 | { |
||
482 | if ($this->renderCount) { |
||
483 | return false; |
||
484 | } |
||
485 | $xoopsLogger = XoopsLogger::getInstance(); |
||
486 | $xoopsLogger->startTime('Page rendering'); |
||
487 | |||
488 | xoops_load('xoopscache'); |
||
489 | $cache = XoopsCache::getInstance(); |
||
490 | |||
491 | //Get meta information for cached pages |
||
492 | if ($this->contentCacheLifetime && $this->contentCacheId && $content = $cache->read($this->contentCacheId)) { |
||
493 | //we need to merge metas set by blocks ) with the module cached meta |
||
494 | $this->htmlHeadStrings = array_merge($this->htmlHeadStrings, $content['htmlHeadStrings']); |
||
495 | foreach ($content['metas'] as $type => $value) { |
||
496 | $this->metas[$type] = array_merge($this->metas[$type], $content['metas'][$type]); |
||
497 | } |
||
498 | $GLOBALS['xoopsOption']['xoops_pagetitle'] = $content['xoops_pagetitle']; |
||
499 | $GLOBALS['xoopsOption']['xoops_module_header'] = $content['header']; |
||
500 | } |
||
501 | |||
502 | if (!empty($GLOBALS['xoopsOption']['xoops_pagetitle'])) { |
||
503 | $this->template->assign('xoops_pagetitle', $GLOBALS['xoopsOption']['xoops_pagetitle']); |
||
504 | } |
||
505 | $header = empty($GLOBALS['xoopsOption']['xoops_module_header']) ? $this->template->get_template_vars('xoops_module_header') : $GLOBALS['xoopsOption']['xoops_module_header']; |
||
506 | |||
507 | //save meta information of cached pages |
||
508 | if ($this->contentCacheLifetime && $this->contentCacheId && !$contentTpl) { |
||
509 | $content['htmlHeadStrings'] = $this->htmlHeadStrings; |
||
510 | $content['metas'] = $this->metas; |
||
511 | $content['xoops_pagetitle'] =& $this->template->get_template_vars('xoops_pagetitle'); |
||
512 | $content['header'] = $header; |
||
513 | $cache->write($this->contentCacheId, $content); |
||
514 | } |
||
515 | |||
516 | // @internal : Lame fix to ensure the metas specified in the xoops config page don't appear twice |
||
517 | $old = array( |
||
518 | 'robots', |
||
519 | 'keywords', |
||
520 | 'description', |
||
521 | 'rating', |
||
522 | 'author', |
||
523 | 'copyright'); |
||
524 | foreach ($this->metas['meta'] as $name => $value) { |
||
525 | if (in_array($name, $old)) { |
||
526 | $this->template->assign("xoops_meta_$name", htmlspecialchars($value, ENT_QUOTES)); |
||
527 | unset($this->metas['meta'][$name]); |
||
528 | } |
||
529 | } |
||
530 | |||
531 | // We assume no overlap between $GLOBALS['xoopsOption']['xoops_module_header'] and $this->template->get_template_vars( 'xoops_module_header' ) ? |
||
532 | $this->template->assign('xoops_module_header', $this->renderMetas(null, true) . "\n" . $header); |
||
533 | |||
534 | if ($canvasTpl) { |
||
535 | $this->canvasTemplate = $canvasTpl; |
||
536 | } |
||
537 | if ($contentTpl) { |
||
538 | $this->contentTemplate = $contentTpl; |
||
539 | } |
||
540 | if (!empty($vars)) { |
||
541 | $this->template->assign($vars); |
||
542 | } |
||
543 | if ($this->contentTemplate) { |
||
544 | $this->content = $this->template->fetch($this->contentTemplate, $this->contentCacheId); |
||
545 | } |
||
546 | if ($this->bufferOutput) { |
||
547 | $this->content .= ob_get_contents(); |
||
548 | ob_end_clean(); |
||
549 | } |
||
550 | |||
551 | $this->template->assign_by_ref('xoops_contents', $this->content); |
||
552 | |||
553 | // Do not cache the main (theme.html) template output |
||
554 | $this->template->caching = 0; |
||
555 | if (file_exists($this->path . '/' . $this->canvasTemplate)) { |
||
556 | $this->template->display($this->path . '/' . $this->canvasTemplate); |
||
557 | } else { |
||
558 | $this->template->display($this->path . '/theme.html'); |
||
559 | } |
||
560 | $this->renderCount++; |
||
561 | $xoopsLogger->stopTime('Page rendering'); |
||
562 | |||
563 | return true; |
||
564 | } |
||
565 | |||
566 | /** |
||
567 | * Load localization information |
||
568 | * |
||
569 | * Folder structure for localization: |
||
570 | * <ul>themes/themefolder/english |
||
571 | * <li>main.php - language definitions</li> |
||
572 | * <li>style.css - localization stylesheet</li> |
||
573 | * <li>script.js - localization script</li> |
||
574 | * </ul> |
||
575 | * @param string $type |
||
576 | * @return bool |
||
577 | */ |
||
578 | public function loadLocalization($type = 'main') |
||
579 | { |
||
580 | $language = $GLOBALS['xoopsConfig']['language']; |
||
581 | // Load global localization stylesheet if available |
||
582 | if (file_exists($GLOBALS['xoops']->path('language/' . $language . '/style.css'))) { |
||
583 | $this->addStylesheet($GLOBALS['xoops']->url('language/' . $language . '/style.css')); |
||
584 | } |
||
585 | $this->addLanguage($type, $language); |
||
586 | // Load theme localization stylesheet and scripts if available |
||
587 | if (file_exists($this->path . '/language/' . $language . '/script.js')) { |
||
588 | $this->addScript($this->url . '/language/' . $language . '/script.js'); |
||
589 | } |
||
590 | if (file_exists($this->path . '/language/' . $language . '/style.css')) { |
||
591 | $this->addStylesheet($this->url . '/language/' . $language . '/style.css'); |
||
592 | } |
||
593 | |||
594 | return true; |
||
595 | } |
||
596 | |||
597 | /** |
||
598 | * Load theme specific language constants |
||
599 | * |
||
600 | * @param string $type language type, like 'main', 'admin'; Needs to be declared in theme xo-info.php |
||
601 | * @param string $language specific language |
||
602 | * |
||
603 | * @return bool|mixed |
||
604 | */ |
||
605 | public function addLanguage($type = 'main', $language = null) |
||
606 | { |
||
607 | $language = (null === $language) ? $GLOBALS['xoopsConfig']['language'] : $language; |
||
608 | if (!file_exists($fileinc = $this->path . "/language/{$language}/{$type}.php")) { |
||
609 | if (!file_exists($fileinc = $this->path . "/language/english/{$type}.php")) { |
||
610 | return false; |
||
611 | } |
||
612 | } |
||
613 | $ret = include_once $fileinc; |
||
614 | |||
615 | return $ret; |
||
616 | } |
||
617 | |||
618 | /** |
||
619 | * *#@+ |
||
620 | * |
||
621 | * @tasktype 20 Manipulating page meta-information |
||
622 | */ |
||
623 | /** |
||
624 | * Adds script code to the document head |
||
625 | * |
||
626 | * This methods allows the insertion of an external script file (if $src is provided), or |
||
627 | * of a script snippet. The file URI is parsed to take benefit of the theme resource |
||
628 | * overloading system. |
||
629 | * |
||
630 | * The $attributes parameter allows you to specify the attributes that will be added to the |
||
631 | * inserted <script> tag. If unspecified, the <var>type</var> attribute value will default to |
||
632 | * 'text/javascript'. |
||
633 | * |
||
634 | * <code> |
||
635 | * // Add an external script using a physical path |
||
636 | * $theme->addScript( 'www/script.js', null, '' ); |
||
637 | * $theme->addScript( 'modules/newbb/script.js', null, '' ); |
||
638 | * // Specify attributes for the <script> tag |
||
639 | * $theme->addScript( 'mod_xoops_SiteManager#common.js', array( 'type' => 'application/x-javascript' ), '', 'mod_xoops_Sitemanager' ); |
||
640 | * // Insert a code snippet |
||
641 | * $theme->addScript( null, array( 'type' => 'application/x-javascript' ), 'window.open("Hello world");', 'hello' ); |
||
642 | * </code> |
||
643 | * |
||
644 | * @param string $src path to an external script file |
||
645 | * @param array $attributes hash of attributes to add to the <script> tag |
||
646 | * @param string $content Code snippet to output within the <script> tag |
||
647 | * @param string $name Element Name in array scripts are stored in. |
||
648 | * @return void |
||
649 | */ |
||
650 | public function addScript($src = '', $attributes = array(), $content = '', $name = '') |
||
651 | { |
||
652 | if (empty($attributes)) { |
||
653 | $attributes = array(); |
||
654 | } |
||
655 | if (!empty($src)) { |
||
656 | $src = $GLOBALS['xoops']->url($this->resourcePath($src)); |
||
657 | $attributes['src'] = $src; |
||
658 | } |
||
659 | if (!empty($content)) { |
||
660 | $attributes['_'] = $content; |
||
661 | } |
||
662 | if (!isset($attributes['type'])) { |
||
663 | $attributes['type'] = 'text/javascript'; |
||
664 | } |
||
665 | if (empty($name)) { |
||
666 | $name = md5(serialize($attributes)); |
||
667 | } |
||
668 | $this->addMeta('script', $name, $attributes); |
||
669 | } |
||
670 | |||
671 | /** |
||
672 | * Add StyleSheet or CSS code to the document head |
||
673 | * |
||
674 | * @param string $src path to .css file |
||
675 | * @param array $attributes name => value paired array of attributes such as title |
||
676 | * @param string $content CSS code to output between the <style> tags (in case $src is empty) |
||
677 | * @param string $name Element Name in array stylesheets are stored in. |
||
678 | * @return void |
||
679 | */ |
||
680 | public function addStylesheet($src = '', $attributes = array(), $content = '', $name = '') |
||
681 | { |
||
682 | if (empty($attributes)) { |
||
683 | $attributes = array(); |
||
684 | } |
||
685 | if (!empty($src)) { |
||
686 | $src = $GLOBALS['xoops']->url($this->resourcePath($src)); |
||
687 | $attributes['href'] = $src; |
||
688 | } |
||
689 | if (!isset($attributes['type'])) { |
||
690 | $attributes['type'] = 'text/css'; |
||
691 | } |
||
692 | if (!empty($content)) { |
||
693 | $attributes['_'] = $content; |
||
694 | } |
||
695 | if (empty($name)) { |
||
696 | $name = md5(serialize($attributes)); |
||
697 | } |
||
698 | $this->addMeta('stylesheet', $name, $attributes); |
||
699 | } |
||
700 | |||
701 | /** |
||
702 | * Add a <link> to the header |
||
703 | * |
||
704 | * @param string $rel Relationship from the current doc to the anchored one |
||
705 | * @param string $href URI of the anchored document |
||
706 | * @param array $attributes Additional attributes to add to the <link> element |
||
707 | * @param string $name Element Name in array links are stored in. |
||
708 | */ |
||
709 | public function addLink($rel, $href = '', $attributes = array(), $name = '') |
||
710 | { |
||
711 | if (empty($attributes)) { |
||
712 | $attributes = array(); |
||
713 | } |
||
714 | if (!empty($href)) { |
||
715 | $attributes['href'] = $href; |
||
716 | } |
||
717 | $attributes['rel'] = $rel; |
||
718 | if (empty($name)) { |
||
719 | $name = md5(serialize($attributes)); |
||
720 | } |
||
721 | $this->addMeta('link', $name, $attributes); |
||
722 | } |
||
723 | |||
724 | /** |
||
725 | * Set a meta http-equiv value |
||
726 | * @param $name |
||
727 | * @param null $value |
||
728 | * @return string |
||
729 | */ |
||
730 | public function addHttpMeta($name, $value = null) |
||
731 | { |
||
732 | if (isset($value)) { |
||
733 | return $this->addMeta('http', $name, $value); |
||
734 | } |
||
735 | unset($this->metas['http'][$name]); |
||
736 | return null; |
||
737 | } |
||
738 | |||
739 | /** |
||
740 | * Change output page meta-information |
||
741 | * @param string $type |
||
742 | * @param string $name |
||
743 | * @param string $value |
||
744 | * @return string |
||
745 | */ |
||
746 | public function addMeta($type = 'meta', $name = '', $value = '') |
||
758 | } |
||
759 | |||
760 | /** |
||
761 | * xos_opal_Theme::headContent() |
||
762 | * |
||
763 | * @param mixed $params |
||
764 | * @param mixed $content |
||
765 | * @param mixed $smarty |
||
766 | * @param mixed $repeat |
||
767 | * |
||
768 | * @return void |
||
769 | */ |
||
770 | public function headContent($params, $content, &$smarty, &$repeat) |
||
771 | { |
||
772 | if (!$repeat) { |
||
773 | $this->htmlHeadStrings[] = $content; |
||
774 | } |
||
775 | } |
||
776 | |||
777 | /** |
||
778 | * xos_opal_Theme::renderMetas() |
||
779 | * |
||
780 | * @param mixed $type |
||
781 | * @param mixed $return |
||
782 | * @return bool|string |
||
783 | */ |
||
784 | public function renderMetas($type = null, $return = false) |
||
785 | { |
||
786 | $str = ''; |
||
787 | if (!isset($type)) { |
||
788 | foreach (array_keys($this->metas) as $type) { |
||
789 | $str .= $this->renderMetas($type, true); |
||
790 | } |
||
791 | $str .= implode("\n", $this->htmlHeadStrings); |
||
792 | } else { |
||
793 | switch ($type) { |
||
794 | case 'script': |
||
795 | foreach ($this->metas[$type] as $attrs) { |
||
796 | $str .= '<script' . $this->renderAttributes($attrs) . '>'; |
||
797 | if (@$attrs['_']) { |
||
798 | $str .= "\n//<![CDATA[\n" . $attrs['_'] . "\n//]]>"; |
||
799 | } |
||
800 | $str .= "</script>\n"; |
||
801 | } |
||
802 | break; |
||
803 | case 'link': |
||
804 | foreach ($this->metas[$type] as $attrs) { |
||
805 | $rel = $attrs['rel']; |
||
806 | unset($attrs['rel']); |
||
807 | $str .= '<link rel="' . $rel . '"' . $this->renderAttributes($attrs) . " />\n"; |
||
808 | } |
||
809 | break; |
||
810 | case 'stylesheet': |
||
811 | foreach ($this->metas[$type] as $attrs) { |
||
812 | if (@$attrs['_']) { |
||
813 | $str .= '<style' . $this->renderAttributes($attrs) . ">\n/* <![CDATA[ */\n" . $attrs['_'] . "\n/* //]]> */\n</style>"; |
||
814 | } else { |
||
815 | $str .= '<link rel="stylesheet"' . $this->renderAttributes($attrs) . " />\n"; |
||
816 | } |
||
817 | } |
||
818 | break; |
||
819 | case 'http': |
||
820 | foreach ($this->metas[$type] as $name => $content) { |
||
821 | $str .= '<meta http-equiv="' . htmlspecialchars($name, ENT_QUOTES) . '" content="' . htmlspecialchars($content, ENT_QUOTES) . "\" />\n"; |
||
822 | } |
||
823 | break; |
||
824 | default: |
||
825 | foreach ($this->metas[$type] as $name => $content) { |
||
826 | $str .= '<meta name="' . htmlspecialchars($name, ENT_QUOTES) . '" content="' . htmlspecialchars($content, ENT_QUOTES) . "\" />\n"; |
||
827 | } |
||
828 | break; |
||
829 | } |
||
830 | } |
||
831 | if ($return) { |
||
832 | return $str; |
||
833 | } |
||
834 | echo $str; |
||
835 | |||
836 | return true; |
||
837 | } |
||
838 | |||
839 | /** |
||
840 | * Generates a unique element ID |
||
841 | * |
||
842 | * @param string $tagName |
||
843 | * @return string |
||
844 | */ |
||
845 | public function genElementId($tagName = 'xos') |
||
853 | } |
||
854 | |||
855 | /** |
||
856 | * Transform an attributes collection to an XML string |
||
857 | * |
||
858 | * @param array $coll |
||
859 | * @return string |
||
860 | */ |
||
861 | public function renderAttributes($coll) |
||
862 | { |
||
863 | $str = ''; |
||
864 | foreach ($coll as $name => $val) { |
||
865 | if ($name !== '_') { |
||
866 | $str .= ' ' . $name . '="' . htmlspecialchars($val, ENT_QUOTES) . '"'; |
||
867 | } |
||
868 | } |
||
869 | |||
870 | return $str; |
||
871 | } |
||
872 | |||
873 | /** |
||
874 | * Return a themeable file resource path |
||
875 | * |
||
876 | * @param string $path |
||
877 | * @return string |
||
878 | */ |
||
879 | public function resourcePath($path) |
||
894 | } |
||
895 | } |
||
896 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.