v1.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. namespace zin;
  3. class pageBase extends wg
  4. {
  5. static $tag = 'html';
  6. /**
  7. * @var mixed[]
  8. */
  9. protected static $defineProps = array
  10. (
  11. 'metas?: string|array',
  12. 'title?: string',
  13. 'bodyProps?: array',
  14. 'bodyClass?: array|string',
  15. 'zui?: bool',
  16. 'lang?: string',
  17. 'rawContent?: bool'
  18. );
  19. /**
  20. * @var mixed[]
  21. */
  22. protected static $defaultProps = array
  23. (
  24. 'zui' => false,
  25. 'display' => true,
  26. 'metas' => array('<meta charset="utf-8">', '<meta http-equiv="X-UA-Compatible" content="IE=edge">', '<meta name="viewport" content="width=device-width, initial-scale=1">', '<meta name="renderer" content="webkit">')
  27. );
  28. /**
  29. * @var mixed[]
  30. */
  31. protected static $defineBlocks = array('head' => array());
  32. protected function buildHead()
  33. {
  34. return $this->block('head');
  35. }
  36. protected function buildBody()
  37. {
  38. return $this->children();
  39. }
  40. protected function build()
  41. {
  42. global $lang, $config, $app;
  43. $setXuanClass = str_contains($_SERVER['HTTP_USER_AGENT'], 'xuanxuan')
  44. ? setClass('xxc-embed')
  45. : null;
  46. $zui = $this->prop('zui');
  47. $head = $this->buildHead();
  48. $body = $this->buildBody();
  49. $context = context();
  50. $jsConfig = \js::getJSConfigVars();
  51. $bodyProps = $this->prop('bodyProps');
  52. $bodyClass = $this->prop('bodyClass');
  53. $metas = $this->prop('metas');
  54. $rawContent = $this->prop('rawContent', !$context->rawContentCalled);
  55. $hookContent = $this->prop('hookContent', !$context->hookContentCalled);
  56. $title = $this->props->get('title', data('title')) . " - $lang->zentaoPMS";
  57. $attrs = $this->getRestProps();
  58. $css = array(data('pageCSS'), '/*{{ZIN_PAGE_CSS}}*/');
  59. $js = array('/*{{ZIN_PAGE_JS}}*/', data('pageJS'));
  60. $imports = $context->getImports();
  61. $webRoot = $app->getWebRoot();
  62. $themeName = $app->cookie->theme;
  63. $zuiPath = $config->zin->zuiPath;
  64. $pageID = $jsConfig->currentModule . '-' . $jsConfig->currentMethod;
  65. $zinMode = isset($config->zin->mode) ? $config->zin->mode : '';
  66. $jsConfig->zin = !empty($zinMode) ? $zinMode : true;
  67. $jsConfig->maxUploadSize = ini_get('upload_max_filesize');
  68. $headImports = array();
  69. $headImports[] = h::favicon($webRoot . 'favicon.ico');
  70. $headImports[] = h::jsVar('window.config', $jsConfig, setID('configJS'));
  71. if($zui)
  72. {
  73. $headImports[] = h::importCss($zuiPath . 'zui.zentao.css', setID('zuiCSS'));
  74. $headImports[] = h::importCss($zuiPath . 'themes/' . $themeName . '.css', setID('zuiTheme'));
  75. $headImports[] = h::importJs($zuiPath . 'zui.zentao.js', setID('zuiJS'));
  76. $headImports[] = h::jsCall('$.setLibRoot', $zuiPath);
  77. $extraCSS = isset($config->zin->extraCSS) ? $config->zin->extraCSS : '';
  78. if(!empty($extraCSS)) $headImports[] = h::importCss($webRoot . 'js/zui3/' . $extraCSS);
  79. }
  80. if($config->debug)
  81. {
  82. $zinDebugData = array('config' => jsRaw('window.config'));
  83. if($config->debug > 4)
  84. {
  85. $zinDebugData['zinTool'] = isset($config->zinTool) ? $config->zinTool : false;
  86. if($config->debug > 5)
  87. {
  88. $zinDebugData['page'] = $this->toJSON();
  89. $zinDebugData['definedProps'] = wg::$definedPropsMap;
  90. $zinDebugData['wgBlockMap'] = wg::$blockMap;
  91. }
  92. }
  93. $headImports[] = h::js('window.zin = ' . js::value($zinDebugData) . ';');
  94. }
  95. else
  96. {
  97. $headImports[] = h::js('window.zin = {};');
  98. }
  99. if($setXuanClass) $headImports[] = h::importCss($config->webRoot . 'zentaoclient.css', setID('zentaoclient'));
  100. if($zui)
  101. {
  102. $extraJS = isset($config->zin->extraJS) ? $config->zin->extraJS : 'zin.js';
  103. if(!empty($extraJS)) $headImports[] = h::importJs($webRoot . 'js/zui3/' . $extraJS);
  104. array_unshift($js, 'zui.defineFn();');
  105. }
  106. $currentLang = $this->props->get('lang');
  107. if(empty($currentLang)) $currentLang = $app->getClientLang();
  108. return h::html
  109. (
  110. before(html('<!DOCTYPE html>')),
  111. set($attrs),
  112. set::className("theme-$themeName", $this->prop('class')),
  113. set::lang($currentLang),
  114. $setXuanClass,
  115. h::head
  116. (
  117. html($metas),
  118. h::title(html(html_entity_decode($title))),
  119. $this->block('headBefore'),
  120. $headImports,
  121. $head
  122. ),
  123. h::body
  124. (
  125. set($bodyProps),
  126. set::className($bodyClass),
  127. $setXuanClass,
  128. empty($imports) ? null : h::import($imports),
  129. h::css($css, setClass('zin-page-css'), setData('id', $pageID)),
  130. $body,
  131. $rawContent ? rawContent() : null,
  132. $hookContent ? hookContent() : null,
  133. h::js($js, setClass('zin-page-js'), setData('id', $pageID))
  134. )
  135. );
  136. }
  137. }