PageRenderTime 61ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 0ms

/mode/cms/require/core.php

https://bitbucket.org/johnroyer/phpwind8.7
PHP | 206 lines | 124 code | 28 blank | 54 comment | 27 complexity | 89bb4a460bd26b3d18a9c5058c854052 MD5 | raw file
  1. <?php
  2. !defined('P_W') && exit('Forbidden');
  3. !defined('CMS_BASEURL') && define("CMS_BASEURL", "index.php?m=cms&");;
  4. /**
  5. * @param string $_page 當前頁面信息(list,view)
  6. * @param string $_definedSeo 自定義SEO配置信息
  7. * @param string $_fname 板塊名稱
  8. * @param string $_types 分類信息
  9. * @param string $_subject 帖子名稱
  10. * @param string $_tags 標籤
  11. * @param string $_summary 摘要
  12. */
  13. function cmsSeoSettings($_page = 'index', $_definedSeo = '', $_column = '', $_subject = '', $_tags = '', $_summary = '') {
  14. global $cms_sitename, $cms_seoset;
  15. /* 網站名稱,欄目名稱,文章名稱,標籤名稱,文章概要 */
  16. $_targets = array('{wzmc}', '{lmmc}', '{armc}', '{tmc}', '{wzgy}');
  17. $_replace = array($cms_sitename, $_column, $_subject, $_tags, $_summary);
  18. /*獲取SEO配置信息 自定義->後台定義->默認*/
  19. empty($_definedSeo['title']) && $_definedSeo['title'] = $cms_seoset['title'][$_page];
  20. empty($_definedSeo['metaDescription']) && $_definedSeo['metaDescription'] = $cms_seoset['metaDescription'][$_page];
  21. empty($_definedSeo['metaKeywords']) && $_definedSeo['metaKeywords'] = $cms_seoset['metaKeywords'][$_page];
  22. /*如果以上設置為空則採用默認配置*/
  23. $_default = array('title' => '{armc} | {lmmc} - {wzmc}', 'descp' => '{wzgy} | {armc}',
  24. 'keywords' => '{tmc} , {armc} | {lmmc} - {wzmc}');
  25. return seoSettings($_definedSeo, $_replace, $_default, $_targets);
  26. }
  27. /**
  28. * 獲取發表文章權限
  29. * @param string $username
  30. * @param array $_G
  31. * return bool
  32. */
  33. function getPostPurview($username, $_G) {
  34. if (isGM($username)) return true;
  35. if (isset($_G['cms_post']) && $_G['cms_post']) return true;
  36. return false;
  37. }
  38. /**
  39. * 檢查用戶是否有管理文章權限
  40. * @param unknown_type $name
  41. * @param unknown_type $cid
  42. * @return string|string|string|boolean
  43. */
  44. function checkEditPurview($name, $cid='') {
  45. if (isGM($name)) return true;
  46. if (!$name) return false;
  47. $cms_editadmin = L::config('cms_editadmin', 'cms_config');
  48. if (!S::isArray($cms_editadmin)) return false;
  49. if (empty($cid)) {
  50. $_keys = array_keys($cms_editadmin);
  51. foreach ($_keys as $key) {
  52. if (S::inArray($name, $cms_editadmin[$key])) return true;
  53. }
  54. return false;
  55. }
  56. return S::inArray($name, $cms_editadmin[$cid]);
  57. }
  58. /**
  59. * 獲取頁面位置
  60. * @param $cid
  61. * @param $id
  62. * @param $columns
  63. */
  64. function getPosition($cid, $id = 0, $columns = array(), $cms_sitename = '') {
  65. if (!$columns) {
  66. $columnService = C::loadClass('columnservice');
  67. $columns = $columnService->findAllColumns();
  68. }
  69. $postion = $cms_sitename ? "<a href='index.php?m=cms'>$cms_sitename</a>":'<a href="index.php?m=cms">資訊</a>';
  70. if (!$cid) {return $postion . '<em>&gt;</em>文章列表';}
  71. $columnLists = getColumnList($columns, $cid);
  72. foreach ($columnLists as $value) {
  73. $postion .= '<em>&gt;</em><a href="' . getColumnUrl($value['column_id']) . '">' . $value['name'] . '</a>';
  74. }
  75. if (!$id) {return $postion;}
  76. return $postion . '<em>&gt;</em>正文內容';
  77. }
  78. /**
  79. * 獲取欄目鏈接地址
  80. * @param unknown_type $cid
  81. */
  82. function getColumnUrl($cid) {
  83. $cid = (int) $cid;
  84. return CMS_BASEURL.'q=list&column=' . $cid;
  85. }
  86. /**
  87. * 獲取文章鏈接地址
  88. * @param $id
  89. */
  90. function getArticleUrl($id) {
  91. $id = (int) $id;
  92. return CMS_BASEURL.'q=view&id=' . $id;
  93. }
  94. function getColumnList($columns, $cid) {
  95. static $list = array();
  96. if (!$cid) return $list;
  97. $thisColumn = $columns[$cid];
  98. array_unshift($list, $thisColumn);
  99. $parentColumnId = $thisColumn['parent_id'];
  100. return getColumnList($columns, $parentColumnId);
  101. }
  102. /**
  103. * 更新文章列表
  104. */
  105. function updateArticleHits() {
  106. global $hitsize, $hitfile, $db;
  107. if (file_exists($hitfile)) {
  108. if (!$hitsize) $hitsize = @filesize($hitfile);
  109. if ($hitsize < 10240) {
  110. $hitarray = explode("\t", readover($hitfile));
  111. $hits = array_count_values($hitarray);
  112. $count = 0;
  113. $hits_a = '';
  114. foreach ($hits as $key => $val) {
  115. $hits_a .= ",('$key','$val')";
  116. if (++$count > 300) break;
  117. }
  118. if ($hits_a) {
  119. $hits_a = trim($hits_a, ', ');
  120. $db->query("CREATE TEMPORARY TABLE heap_hitupdate (article_id INT(10) UNSIGNED NOT NULL ,hits SMALLINT(6) UNSIGNED NOT NULL) TYPE = HEAP");
  121. $db->update("INSERT INTO heap_hitupdate (article_id,hits) VALUES $hits_a");
  122. $db->update("UPDATE pw_cms_articleextend as a, heap_hitupdate as h SET a.hits = a.hits+h.hits WHERE a.article_id=h.article_id");
  123. $db->query("DELETE FROM heap_hitupdate");
  124. }
  125. unset($hitarray, $hits, $hits_a);
  126. }
  127. pwCache::deleteData($hitfile);
  128. }
  129. }
  130. function checkReplyPurview() {
  131. global $_G,$windid;
  132. if (isGM($windid) || (isset($_G['cms_replypost']) && $_G['cms_replypost'])) return true;
  133. return false;
  134. }
  135. class cmsTemplate {
  136. var $dir;
  137. function cmsTemplate() {
  138. $this->dir = M_P . 'template/';
  139. }
  140. function getpath($template, $EXT = 'htm') {
  141. $srcTpl = $this->dir . 'default/' . "$template.$EXT";
  142. $tarTpl = D_P . "data/tplcache/cms_" . $template . '.' . $EXT;
  143. if (!file_exists($srcTpl)) return false;
  144. if (pwFilemtime($tarTpl) > pwFilemtime($srcTpl)) return $tarTpl;
  145. return modeTemplate($srcTpl, $tarTpl);
  146. }
  147. function getDefaultDir() {
  148. return $this->dir . 'default/';
  149. }
  150. //static function
  151. function printEot($template, $EXT = 'htm') {
  152. static $uTemplate = null;
  153. isset($uTemplate) || $uTemplate = new template(new cmsTemplate());
  154. return $uTemplate->printEot($template, $EXT);
  155. }
  156. }
  157. class C extends PW_BaseLoader {
  158. /**
  159. * 類文件的加載入口
  160. *
  161. * @param string $className 類的名稱
  162. * @param string $dir 目錄:末尾不需要'/'
  163. * @param boolean $isGetInstance 是否實例化
  164. * @return mixed
  165. */
  166. function loadClass($className, $dir = '', $isGetInstance = true) {
  167. return parent::_loadClass($className, 'mode/cms/lib/' . parent::_formatDir($dir), $isGetInstance);
  168. }
  169. /**
  170. * 加載db類
  171. * @param $className
  172. */
  173. function loadDB($dbName, $dir = '') {
  174. parent::_loadBaseDB();
  175. return C::loadClass($dbName . 'DB', parent::_formatDir($dir) . 'db');
  176. }
  177. }
  178. ?>