1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489: 490: 491: 492: 493: 494: 495: 496: 497: 498: 499: 500: 501: 502: 503: 504: 505: 506: 507: 508: 509: 510: 511: 512: 513: 514: 515: 516: 517: 518: 519: 520: 521: 522: 523: 524: 525: 526: 527: 528: 529: 530: 531: 532: 533: 534: 535: 536: 537: 538: 539: 540: 541: 542: 543: 544: 545: 546: 547: 548: 549: 550: 551: 552: 553: 554: 555: 556: 557: 558: 559: 560: 561: 562: 563: 564: 565: 566: 567: 568: 569: 570: 571: 572: 573: 574: 575: 576: 577: 578: 579: 580: 581: 582: 583: 584: 585: 586: 587: 588: 589: 590: 591: 592: 593: 594: 595: 596: 597: 598: 599: 600: 601: 602: 603: 604: 605: 606: 607: 608: 609: 610: 611: 612: 613: 614: 615: 616: 617: 618: 619: 620: 621: 622: 623: 624: 625: 626: 627: 628: 629: 630: 631: 632: 633: 634: 635: 636: 637: 638: 639: 640: 641: 642: 643: 644: 645: 646: 647: 648: 649: 650: 651: 652: 653: 654: 655: 656: 657: 658: 659: 660: 661: 662: 663: 664: 665: 666: 667: 668: 669: 670: 671: 672: 673: 674: 675: 676: 677: 678: 679: 680: 681: 682: 683: 684: 685: 686: 687: 688: 689: 690: 691: 692: 693: 694: 695: 696: 697: 698: 699: 700: 701: 702: 703: 704: 705: 706: 707:
<?php
class icms_view_theme_Object {
public $folderName = '';
public $path = '';
public $url = '';
public $bufferOutput = TRUE;
public $canvasTemplate = 'theme.html';
public $contentTemplate = '';
public $contentCacheLifetime = 0;
public $contentCacheId = NULL;
public $content = '';
public $plugins = array('icms_view_PageBuilder');
public $renderCount = 0;
public $template = FALSE;
public $metas = array(
'head' => array(),
'module' => array(),
'foot' => array(),
);
public $types = array('http', 'meta', 'link', 'stylesheet', 'script', 'property', 'itemprop');
public $htmlHeadStrings = array();
public $templateVars = array();
public $use_extra_cache_id = TRUE;
public function xoInit($options = array()) {
global $xoops;
$this->path = (is_dir(ICMS_MODULES_PATH . '/system/themes/' . $this->folderName))
? ICMS_MODULES_PATH . '/system/themes/' . $this->folderName
: ICMS_THEME_PATH . '/' . $this->folderName;
$this->url = (is_dir(ICMS_MODULES_PATH . '/system/themes/' . $this->folderName))
? ICMS_MODULES_URL . '/system/themes/' . $this->folderName
: ICMS_THEME_URL . '/' . $this->folderName;
$this->template = new icms_view_Tpl();
$this->template->currentTheme =& $this;
$this->template->assign_by_ref('xoTheme', $this);
global $icmsConfig, $icmsConfigMetaFooter, $icmsModule, $xoopsModule;
$this->template->assign(
array(
'icms_style' => ICMS_URL . '/icms' . ((defined('_ADM_USE_RTL') && _ADM_USE_RTL) ? '_rtl' : '') . '.css',
'icms_theme' => $this->folderName,
'icms_imageurl' => (is_dir(ICMS_MODULES_PATH . '/system/themes/' . $this->folderName . '/'))
? ICMS_MODULES_URL . '/system/themes/' . $this->folderName . '/'
: ICMS_THEME_URL . '/' . $this->folderName . '/',
'icms_themecss'=> xoops_getcss($this->folderName),
'icms_requesturi' => htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES),
'icms_sitename' => htmlspecialchars($icmsConfig['sitename'], ENT_QUOTES),
'icms_slogan' => htmlspecialchars($icmsConfig['slogan'], ENT_QUOTES),
'icms_dirname' => @$icmsModule ? $icmsModule->getVar('dirname') : 'system',
'icms_pagetitle' => isset($icmsModule) && is_object($icmsModule)
? $icmsModule->getVar('name')
: htmlspecialchars($icmsConfig['slogan'], ENT_QUOTES)
)
);
$this->template->assign(array(
'xoops_theme' => $this->template->get_template_vars('icms_theme'),
'xoops_imageurl' => $this->template->get_template_vars('icms_imageurl'),
'xoops_themecss' => $this->template->get_template_vars('icms_themecss'),
'xoops_requesturi' => $this->template->get_template_vars('icms_requesturi'),
'xoops_sitename' => $this->template->get_template_vars('icms_sitename'),
'xoops_slogan' => $this->template->get_template_vars('icms_slogan'),
'xoops_dirname' => $this->template->get_template_vars('icms_dirname'),
));
if (isset(icms::$user) && is_object(icms::$user)) {
$this->template->assign(array(
'icms_isuser' => TRUE,
'icms_userid' => icms::$user->getVar('uid'),
'icms_uname' => icms::$user->getVar('uname'),
'icms_isadmin' => icms::$user->isAdmin(),
'xoops_isuser' => TRUE,
'xoops_userid' => icms::$user->getVar('uid'),
'xoops_uname' => icms::$user->getVar('uname'),
'xoops_isadmin' => icms::$user->isAdmin(),
)
);
} else {
$this->template->assign(
array('icms_isuser' => FALSE,
'icms_isadmin' => FALSE,
'xoops_isuser' => FALSE,
'xoops_isadmin' => FALSE
)
);
}
foreach ($icmsConfigMetaFooter as $name => $value) {
if (substr($name, 0, 5) == 'meta_') {
$this->addMeta('meta', substr($name, 5), $value);
} elseif (substr($name, 0, 6) == 'footer') {
$values = $value;
$this->template->assign("xoops_$name", $values);
$this->template->assign("icms_$name", $values);
} else {
$this->template->assign("xoops_$name", $value);
$this->template->assign("icms_$name", $value);
}
}
if ($this->bufferOutput) {
ob_start();
}
$GLOBALS['xoTheme'] =& $this;
$GLOBALS['xoopsTpl'] =& $this->template;
foreach ($this->plugins as $k => $bundleId) {
if (!is_object($bundleId)) {
$this->plugins[$bundleId] = new $bundleId();
$this->plugins[$bundleId]->theme =& $this;
$this->plugins[$bundleId]->xoInit();
unset($this->plugins[$k]);
}
}
return TRUE;
}
public function generateCacheId($cache_id, $extraString = '') {
static $extra_string;
if (!$this->use_extra_cache_id) {
return $cache_id;
}
if (empty($extraString)) {
if (empty($extra_string)) {
global $icmsConfig;
$extra_string = $icmsConfig['language'];
if (!@is_object(icms::$user)) {
$extra_string .= '|' . ICMS_GROUP_ANONYMOUS;
} else {
$groups = icms::$user->getGroups();
sort($groups);
$extra_string .= '|' . implode(",", $groups)
. substr(md5(XOOPS_DB_PASS . XOOPS_DB_NAME), 0, strlen(XOOPS_DB_USER) * 2);
}
}
$extraString = $extra_string;
}
$cache_id .= '|' . $extraString;
return $cache_id;
}
public function checkCache() {
global $xoopsModule, $icmsModule;
if ($_SERVER['REQUEST_METHOD'] != 'POST' && $this->contentCacheLifetime) {
$template = $this->contentTemplate ? $this->contentTemplate : 'db:system_dummy.html';
$dirname = $icmsModule->getVar('dirname', 'n');
$this->template->caching = 2;
$this->template->cache_lifetime = $this->contentCacheLifetime;
$uri = str_replace(ICMS_URL, '', $_SERVER['REQUEST_URI']);
if (defined('SID') && SID && strpos($uri, SID)) {
$uri = preg_replace("/([\?&])(" . SID . "$|" . SID . "&)/", "\\1", $uri);
}
$this->contentCacheId = $this->generateCacheId($dirname . '|' . $uri);
if ($this->template->is_cached($template, $this->contentCacheId)) {
icms::$logger->addExtra($template, sprintf(_REGENERATES, $this->contentCacheLifetime));
$this->render(NULL, NULL, $template);
return TRUE;
}
}
return FALSE;
}
public function render($canvasTpl = NULL, $pageTpl = NULL, $contentTpl = NULL, $vars = array()) {
global $xoops, $xoopsOption;
if ($this->renderCount) {
return FALSE;
}
icms::$logger->startTime('Page rendering');
$old = array('robots', 'keywords', 'description', 'rating', 'author', 'copyright');
foreach ($this->metas['module']['meta'] as $name => $value) {
if (in_array($name, $old)) {
$this->template->assign("xoops_meta_$name", htmlspecialchars($value['value'], ENT_QUOTES));
$this->template->assign("icms_meta_$name", htmlspecialchars($value['value'], ENT_QUOTES));
unset($this->metas['module']['meta'][$name]);
}
}
if ($canvasTpl) $this->canvasTemplate = $canvasTpl;
if ($contentTpl) $this->contentTemplate = $contentTpl;
if (!empty($vars)) {
$this->template->assign($vars);
}
if ($this->contentTemplate) {
$this->content = $this->template->fetch($this->contentTemplate, $this->contentCacheId);
}
if ($this->bufferOutput) {
$this->content .= ob_get_contents();
ob_end_clean();
}
$this->template->assign_by_ref('xoops_contents', $this->content);
$this->template->assign_by_ref('icms_contents', $this->content);
$header = empty($xoopsOption['icms_module_header'])
? $this->template->get_template_vars('icms_module_header')
: $xoopsOption['icms_module_header'];
$xheader = empty($xoopsOption['xoops_module_header'])
? $this->template->get_template_vars('xoops_module_header')
: $xoopsOption['xoops_module_header'];
if ($xheader != "") icms_core_Debug::setDeprecated('icms_module_header', sprintf(_CORE_REMOVE_IN_VERSION, "2.0"));
$header = ($header != "") ? $header : $xheader;
$this->template->assign('xoops_module_header', $header . "\n" . $this->renderOldMetas(NULL, TRUE));
$this->template->assign('icms_module_header', $header . "\n" . $this->renderOldMetas(NULL, TRUE));
foreach ($this->metas as $zone => $value) {
$this->template->assign($zone, "<!-- " . ucfirst($zone) . " section-->\n" . $this->renderMetas(NULL, TRUE, $zone));
}
$pagetitle = empty($xoopsOption['icms_pagetitle'])
? $this->template->get_template_vars('icms_pagetitle')
: $xoopsOption['icms_pagetitle'];
$xpagetitle = empty($xoopsOption['xoops_pagetitle'])
? $this->template->get_template_vars('xoops_pagetitle')
: $xoopsOption['xoops_pagetitle'];
if ($xpagetitle != "") icms_core_Debug::setDeprecated('icms_pagetitle', sprintf(_CORE_REMOVE_IN_VERSION, "2.0"));
$pagetitle = ($pagetitle != "") ? $pagetitle : $xpagetitle;
$this->template->assign('xoops_pagetitle', $pagetitle);
$this->template->assign('icms_pagetitle', $pagetitle);
$this->template->caching = 0;
$this->template->display($this->path . '/' . $this->canvasTemplate);
$this->renderCount++;
icms::$logger->stopTime('Page rendering');
}
public function addScript($src = '', $attributes = array(), $content = '', $zone = 'module', $weight = 0) {
if (empty($attributes)) {
$attributes = array();
}
if (!empty($src)) {
$attributes['src'] = icms::url($this->resourcePath($src));
}
if (!empty($content)) {
$attributes['_'] = $content;
}
if (!isset($attributes['type'])) {
$attributes['type'] = 'text/javascript';
}
$this->addMeta('script', $src, $attributes, $zone, $weight);
}
public function addStylesheet($src = '', $attributes = array(), $content = '', $zone = 'module', $weight = 0) {
if (empty($attributes)) {
$attributes = array();
}
if (!empty($src)) {
$attributes['href'] = icms::url($this->resourcePath($src));
}
if (!isset($attributes['type'])) {
$attributes['type'] = 'text/css';
}
if (!empty($content)) {
$attributes['_'] = $content;
}
$this->addMeta('stylesheet', $src, $attributes, $zone, $weight);
}
public function addLink($rel, $href = '', $attributes = array(), $zone = 'module', $weight = 0) {
if (empty($attributes)) {
$attributes = array();
}
if (!empty($href)) {
$attributes['href'] = $href;
}
$this->addMeta('link', $rel, $attributes, $zone, $weight);
}
public function addHttpMeta($name, $value = NULL, $zone = 'module', $weight = 0) {
if (isset($value)) {
return $this->addMeta('http', $name, $value, $zone, $weight);
}
unset($this->metas[$zone]['http'][$name]);
}
public function addPropertyMeta($name, $value = NULL, $zone = 'module', $weight = 0) {
if (isset($value)) {
return $this->addMeta('property', $name, $value, $zone, $weight);
}
unset($this->metas[$zone]['property'][$name]);
}
public function addItempropMeta($name, $value = NULL, $zone = 'module', $weight = 0) {
if (isset($value)) {
return $this->addMeta('itemprop', $name, $value, $zone, $weight);
}
unset($this->metas[$zone]['itemprop'][$name]);
}
function addMeta($type = 'meta', $name = '', $value = '', $zone = 'module', $weight = 0) {
!empty($zone) || $zone = 'module';
if (!isset($this->metas[$zone][$type])) {
$this->metas[$zone][$type] = array();
}
if (!empty($name)) {
$this->metas[$zone][$type][$name] = array('value' => $value, 'weight' => $weight);
} else {
$this->metas[$zone][$type][] = array('value' => $value, 'weight' => $weight);
}
return $value;
}
public function headContent($params, $content, &$smarty, &$repeat) {
if (!$repeat) {
$this->htmlHeadStrings[] = $content;
}
}
public function renderMetas($type = NULL, $return = FALSE, $zone = 'module') {
$str = '';
if (!isset($type)) {
if (!is_array($this->metas[$zone])) return;
$types = $this->types;
$usedTypes = array_keys($this->metas[$zone]);
foreach (array_intersect($types, $usedTypes) as $type) {
$str .= $this->renderMetas($type, TRUE, $zone);
}
$str .= implode("\n", $this->htmlHeadStrings);
} else {
$sort = array();
foreach($this->metas[$zone][$type] as $name => $item) {
$sort[] = $item['weight'];
}
array_multisort(array_values($sort), array_keys($sort), $this->metas[$zone][$type]);
switch($type) {
case 'script':
foreach ($this->metas[$zone][$type] as $attrs) {
$str .= '<script' . $this->renderAttributes($attrs['value']) . ">";
if (@$attrs['value']['_']) {
$str .= "\n" . $attrs['value']['_'] . "\n";
}
$str .= "</script>\n";
}
break;
case 'link':
foreach ($this->metas[$zone][$type] as $rel => $attrs) {
$str .= '<link rel="' . $rel . '"' . $this->renderAttributes($attrs['value']) . " />\n";
}
break;
case 'stylesheet':
foreach ($this->metas[$zone][$type] as $attrs) {
if (@$attrs['value']['_']) {
$str .= '<style' . $this->renderAttributes($attrs['value']) . ">\n" . $attrs['value']['_'] . "\n</style>";
} else {
$str .= '<link rel="stylesheet"' . $this->renderAttributes($attrs['value']) . " />\n";
}
}
break;
case 'http':
foreach ($this->metas[$zone][$type] as $name => $content) {
$str .= '<meta http-equiv="' . htmlspecialchars($name, ENT_QUOTES) . '" content="' . htmlspecialchars($content, ENT_QUOTES) . "\" />\n";
}
break;
case 'property':
foreach ($this->metas[$zone][$type] as $name => $content) {
$str .= '<meta property="' . htmlspecialchars($name, ENT_QUOTES) . '" content="' . htmlspecialchars($content, ENT_QUOTES) . "\" />\n";
}
break;
case 'itemprop':
foreach ($this->metas[$zone][$type] as $name => $content) {
$str .= '<meta itemprop="' . htmlspecialchars($name, ENT_QUOTES) . '" content="' . htmlspecialchars($content, ENT_QUOTES) . "\" />\n";
}
break;
default:
foreach ($this->metas[$zone][$type] as $name => $content) {
$str .= '<meta name="' . htmlspecialchars($name, ENT_QUOTES) . '" content="' . htmlspecialchars($content['value'], ENT_QUOTES) . "\" />\n";
}
break;
}
}
if ($return) {
return $str;
}
echo $str;
return TRUE;
}
public function renderOldMetas($type = NULL, $return = TRUE) {
$str = '';
foreach ($this->metas as $z => $values) {
$str .= $this->renderMetas($type, TRUE, $z);
}
return $str;
}
public function genElementId($tagName = 'xos') {
static $cache = array();
if (!isset($cache[$tagName])) {
$cache[$tagName] = 1;
}
return $tagName . '-' . $cache[$tagName]++;
}
public function renderAttributes($coll) {
$str = '';
foreach ($coll as $name => $val) {
if ($name != '_') {
$str .= ' ' . $name . '="' . htmlspecialchars($val, ENT_QUOTES) . '"';
}
}
return $str;
}
public function resourcePath($path) {
if (substr($path, 0, 1) == '/') {
$path = substr($path, 1);
}
if (file_exists("$this->path/$path")) {
return "themes/$this->folderName/$path";
}
return $path;
}
}