22 defined(
'XOOPS_ROOT_PATH') or die('Restricted access');
34 var $xoBundleIdentifier =
'xos_opal_ThemeFactory';
40 var $allowedThemes = array();
46 var $defaultTheme =
'default';
52 var $allowUserSelection =
true;
57 function &createInstance(
$options = array(), $initArgs = array())
61 if (($req = @
$_REQUEST[
'xoops_theme_select']) && $this->isThemeAllowed($req)) {
63 if (isset(
$_SESSION) && $this->allowUserSelection) {
64 $_SESSION[$this->xoBundleIdentifier][
'defaultTheme'] = $req;
66 }
else if (isset(
$_SESSION[$this->xoBundleIdentifier][
'defaultTheme'])) {
68 }
else if (empty(
$options[
'folderName']) || ! $this->isThemeAllowed(
$options[
'folderName'])) {
69 $options[
'folderName'] = $this->defaultTheme;
89 function isThemeAllowed($name)
110 $inst =& parent::createInstance(
$options, $initArgs);
113 $inst->template->assign(array(
114 'theme_path' => $inst->path,
115 'theme_tpl' => $inst->path.
'/xotpl',
116 'theme_url' => $inst->url,
117 'theme_img' => $inst->url.
'/img',
118 'theme_icons' => $inst->url.
'/icons',
119 'theme_css' => $inst->url.
'/css',
120 'theme_js' => $inst->url.
'/js',
121 'theme_lang' => $inst->url.
'/language',
193 'xos_logos_PageBuilder');
213 'script' => array());
259 $this->
template = null;
261 $this->
template->currentTheme =& $this;
262 $this->
template->assign_by_ref(
'xoTheme', $this);
263 $this->
template->assign(array(
264 'xoops_theme' =>
$GLOBALS[
'xoopsConfig'][
'theme_set'] ,
266 'xoops_themecss' =>
xoops_getcss($GLOBALS[
'xoopsConfig'][
'theme_set']),
267 'xoops_requesturi' => htmlspecialchars(
$_SERVER[
'REQUEST_URI'], ENT_QUOTES),
268 'xoops_sitename' => htmlspecialchars($GLOBALS[
'xoopsConfig'][
'sitename'], ENT_QUOTES),
269 'xoops_slogan' => htmlspecialchars($GLOBALS[
'xoopsConfig'][
'slogan'], ENT_QUOTES),
270 'xoops_dirname' => isset($GLOBALS[
'xoopsModule'])&& is_object($GLOBALS[
'xoopsModule']) ? $GLOBALS[
'xoopsModule']->getVar(
'dirname') :
'system',
271 'xoops_banner' => ($GLOBALS[
'xoopsConfig'][
'banners'] && $this->renderBanner) ?
xoops_getbanner() :
' ',
272 'xoops_pagetitle' => isset($GLOBALS[
'xoopsModule']) && is_object($GLOBALS[
'xoopsModule']) ? $GLOBALS[
'xoopsModule']->getVar(
'name') : htmlspecialchars($GLOBALS[
'xoopsConfig'][
'slogan'], ENT_QUOTES)));
274 if (isset($GLOBALS[
'xoopsUser']) && is_object($GLOBALS[
'xoopsUser'])) {
275 $this->
template->assign(array(
276 'xoops_isuser' =>
true,
277 'xoops_avatar' =>
XOOPS_UPLOAD_URL .
"/" . $GLOBALS[
'xoopsUser']->getVar(
'user_avatar'),
278 'xoops_userid' => $GLOBALS[
'xoopsUser']->getVar(
'uid'),
279 'xoops_uname' => $GLOBALS[
'xoopsUser']->getVar(
'uname'),
280 'xoops_name' => $GLOBALS[
'xoopsUser']->getVar(
'name'),
281 'xoops_isadmin' => $GLOBALS[
'xoopsUserIsAdmin'],
282 'xoops_usergroups' => $GLOBALS[
'xoopsUser']->getGroups()));
284 $this->
template->assign(array(
285 'xoops_isuser' =>
false,
286 'xoops_isadmin' =>
false,
287 'xoops_usergroups' => array(XOOPS_GROUP_ANONYMOUS)));
296 $name =
$config[
$i]->getVar(
'conf_name',
'n');
297 $value =
$config[
$i]->getVar(
'conf_value',
'n');
298 if (substr($name, 0, 5) ==
'meta_') {
299 $this->
addMeta(
'meta', substr($name, 5), $value);
302 $this->
template->assign(
"xoops_$name", $value);
309 if ($this->bufferOutput) {
312 $GLOBALS[
'xoTheme'] =& $this;
315 foreach ($this->plugins as $k => $bundleId) {
316 if (!is_object($bundleId)) {
317 $this->plugins[$bundleId] = null;
318 $this->plugins[$bundleId] =
new $bundleId();
319 $this->plugins[$bundleId]->theme =& $this;
320 $this->plugins[$bundleId]->xoInit();
321 unset($this->plugins[$k]);
338 static $extra_string;
339 if (!$this->use_extra_cache_id) {
343 if (empty($extraString)) {
344 if (empty($extra_string)) {
346 $extra_string =
$GLOBALS[
'xoopsConfig'][
'language'];
349 $extra_string .=
'-' . XOOPS_GROUP_ANONYMOUS;
358 $extraString = $extra_string;
360 $cache_id .=
'-' . $extraString;
371 if (
$_SERVER[
'REQUEST_METHOD'] !=
'POST' && $this->contentCacheLifetime) {
372 $template = $this->contentTemplate ? $this->contentTemplate :
'db:system_dummy.html';
373 $this->
template->caching = 2;
375 $uri = str_replace(XOOPS_URL,
'',
$_SERVER[
'REQUEST_URI']);
377 if (defined(
'SID') && SID && strpos($uri, SID)) {
378 $uri = preg_replace(
"/([\?&])(" . SID .
"$|" . SID .
"&)/",
"\\1", $uri);
380 $this->contentCacheId = $this->
generateCacheId(
'page_' . substr(md5($uri), 0, 8));
381 if ($this->template->is_cached(
$template, $this->contentCacheId)) {
383 $xoopsLogger->addExtra(
$template, sprintf(
'Cached (regenerates every %d seconds)', $this->contentCacheLifetime));
405 function render($canvasTpl = null, $pageTpl = null, $contentTpl = null,
$vars = array())
407 if ($this->renderCount) {
417 if ($this->contentCacheLifetime && $this->contentCacheId &&
$content = $cache->read($this->contentCacheId)) {
419 $this->htmlHeadStrings = array_merge($this->htmlHeadStrings,
$content[
'htmlHeadStrings']);
427 if (!empty(
$GLOBALS[
'xoopsOption'][
'xoops_pagetitle'])) {
428 $this->
template->assign(
'xoops_pagetitle',
$GLOBALS[
'xoopsOption'][
'xoops_pagetitle']);
430 $header = empty(
$GLOBALS[
'xoopsOption'][
'xoops_module_header']) ? $this->
template->get_template_vars(
'xoops_module_header') :
$GLOBALS[
'xoopsOption'][
'xoops_module_header'];
433 if ($this->contentCacheLifetime && $this->contentCacheId && !$contentTpl) {
436 $content[
'xoops_pagetitle'] = $this->
template->get_template_vars(
'xoops_pagetitle');
438 $cache->write($this->contentCacheId,
$content);
449 foreach ($this->metas[
'meta'] as $name => $value) {
450 if (in_array($name, $old)) {
451 $this->
template->assign(
"xoops_meta_$name", htmlspecialchars($value, ENT_QUOTES));
452 unset($this->metas[
'meta'][$name]);
457 $this->
template->assign(
'xoops_module_header', $this->
renderMetas(null,
true) .
"\n" . $header);
461 $this->canvasTemplate = $canvasTpl;
464 $this->contentTemplate = $contentTpl;
467 $this->
template->assign(
$vars);
469 if ($this->contentTemplate) {
470 $this->content = $this->
template->fetch($this->contentTemplate, $this->contentCacheId);
472 if ($this->bufferOutput) {
473 $this->content .= ob_get_contents();
477 $this->
template->assign_by_ref(
'xoops_contents', $this->content);
480 $this->
template->caching = 0;
481 $this->
template->display($this->path .
'/' . $this->canvasTemplate);
482 $this->renderCount++;
501 if (file_exists(
$GLOBALS[
'xoops']->path(
'language/' .
$language .
'/style.css'))) {
506 if (file_exists($this->path .
'/language/' .
$language .
'/script.js')) {
507 $this->
addScript($this->url .
'/language/' . $language .
'/script.js');
509 if (file_exists($this->path .
'/language/' . $language .
'/style.css')) {
510 $this->
addStylesheet($this->url .
'/language/' . $language .
'/style.css');
524 if (!file_exists($fileinc =
$GLOBALS[
'xoops']->path($this->
resourcePath(
"/language/{$language}/{$type}.php")))) {
525 if (!file_exists($fileinc =
$GLOBALS[
'xoops']->path($this->
resourcePath(
"/language/english/{$type}.php")))) {
529 $ret = include_once $fileinc;
567 if (empty($attributes)) {
568 $attributes = array();
572 $attributes[
'src'] = $src;
577 if (!isset($attributes[
'type'])) {
578 $attributes[
'type'] =
'text/javascript';
581 $name = md5(serialize($attributes));
583 $this->
addMeta(
'script', $name, $attributes);
598 if (empty($attributes)) {
599 $attributes = array();
603 $attributes[
'href'] = $src;
605 if (!isset($attributes[
'type'])) {
606 $attributes[
'type'] =
'text/css';
612 $name = md5(serialize($attributes));
614 $this->
addMeta(
'stylesheet', $name, $attributes);
625 function addLink($rel, $href =
'', $attributes = array(), $name =
'')
627 if (empty($attributes)) {
628 $attributes = array();
631 $attributes[
'href'] = $href;
633 $attributes[
'rel'] = $rel;
635 $name = md5(serialize($attributes));
637 $this->
addMeta(
'link', $name, $attributes);
647 return $this->
addMeta(
'http', $name, $value);
649 unset($this->metas[
'http'][$name]);
657 if (!isset($this->metas[
$type])) {
658 $this->metas[
$type] = array();
661 $this->metas[
$type][$name] = $value;
663 $this->metas[
$type][md5(serialize(array($value)))] = $value;
680 $this->htmlHeadStrings[] =
$content;
695 foreach (array_keys($this->metas) as
$type) {
698 $str .= implode(
"\n", $this->htmlHeadStrings);
702 foreach ($this->metas[
$type] as $attrs) {
705 $str .=
"\n//<![CDATA[\n" . $attrs[
'_'] .
"\n//]]>";
707 $str .=
"</script>\n";
711 foreach ($this->metas[
$type] as $attrs) {
712 $rel = $attrs[
'rel'];
713 unset($attrs[
'rel']);
714 $str .=
'<link rel="' . $rel .
'"' . $this->
renderAttributes($attrs) .
" />\n";
718 foreach ($this->metas[
$type] as $attrs) {
720 $str .=
'<style' . $this->
renderAttributes($attrs) .
">\n/* <![CDATA[ */\n" . $attrs[
'_'] .
"\n/* //]]> */\n</style>";
722 $str .=
'<link rel="stylesheet"' . $this->
renderAttributes($attrs) .
" />\n";
728 $str .=
'<meta http-equiv="' . htmlspecialchars($name, ENT_QUOTES) .
'" content="' . htmlspecialchars(
$content, ENT_QUOTES) .
"\" />\n";
733 $str .=
'<meta name="' . htmlspecialchars($name, ENT_QUOTES) .
'" content="' . htmlspecialchars(
$content, ENT_QUOTES) .
"\" />\n";
753 static $cache = array();
754 if (!isset($cache[$tagName])) {
755 $cache[$tagName] = 1;
757 return $tagName .
'-' . $cache[$tagName] ++;
769 foreach ($coll as $name => $val) {
771 $str .=
' ' . $name .
'="' . htmlspecialchars($val, ENT_QUOTES) .
'"';
785 if (substr(
$path, 0, 1) ==
'/') {
789 if (file_exists(XOOPS_ROOT_PATH .
"/{$this->themesPath}/{$this->folderName}/{$path}")) {
790 return "{$this->themesPath}/{$this->folderName}/{$path}";
793 if (file_exists(XOOPS_ROOT_PATH .
"/themes/{$this->folderName}/{$path}")) {
794 return "themes/{$this->folderName}/{$path}";