国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

266 lines
9.3KB

  1. <?php
  2. if (!defined('DEDEINC')) exit ('dedebiz');
  3. /**
  4. * 文档助手
  5. *
  6. * @version $id:archive.helper.php 2 23:00 2010年7月5日 tianya $
  7. * @package DedeBIZ.Helpers
  8. * @copyright Copyright (c) 2022 DedeBIZ.COM
  9. * @license GNU GPL v2 (https://www.dedebiz.com/license)
  10. * @link https://www.dedebiz.com
  11. */
  12. /**
  13. * 获取单篇文档信息
  14. *
  15. * @param int $aid 文档id
  16. * @return array
  17. */
  18. if (!function_exists('GetOneArchive')) {
  19. function GetOneArchive($aid)
  20. {
  21. global $dsql;
  22. include_once(DEDEINC."/channelunit.func.php");
  23. $aid = trim(preg_replace('/[^0-9]/', '', $aid));
  24. $reArr = array();
  25. $chRow = $dsql->GetOne("SELECT arc.*,ch.maintable,ch.addtable,ch.issystem FROM `#@__arctiny` arc LEFT JOIN `#@__channeltype` ch ON ch.id=arc.channel WHERE arc.id='$aid'");
  26. if (!is_array($chRow)) {
  27. return $reArr;
  28. } else {
  29. if (empty($chRow['maintable'])) $chRow['maintable'] = '#@__archives';
  30. }
  31. if ($chRow['issystem'] != -1) {
  32. $nquery = "SELECT arc.*,tp.typedir,tp.topid,tp.namerule,tp.moresite,tp.siteurl,tp.sitepath FROM `{$chRow['maintable']}` arc LEFT JOIN `#@__arctype` tp ON tp.id=arc.typeid WHERE arc.id='$aid'";
  33. } else {
  34. $nquery = "SELECT arc.*,1 AS ismake,0 AS money,'' AS filename,tp.typedir,tp.topid,tp.namerule,tp.moresite,tp.siteurl,tp.sitepath FROM `{$chRow['addtable']}` arc LEFT JOIN `#@__arctype` tp ON tp.id=arc.typeid WHERE arc.aid='$aid'";
  35. }
  36. $arcRow = $dsql->GetOne($nquery);
  37. if (!is_array($arcRow)) {
  38. return $reArr;
  39. }
  40. if (!isset($arcRow['description'])) {
  41. $arcRow['description'] = '';
  42. }
  43. if (empty($arcRow['description']) && isset($arcRow['body'])) {
  44. $arcRow['description'] = cn_substr(html2text($arcRow['body']), 250);
  45. }
  46. if (!isset($arcRow['pubdate'])) {
  47. $arcRow['pubdate'] = $arcRow['senddate'];
  48. }
  49. if (!isset($arcRow['notpost'])) {
  50. $arcRow['notpost'] = 0;
  51. }
  52. $reArr = $arcRow;
  53. $reArr['aid'] = $aid;
  54. $reArr['topid'] = $arcRow['topid'];
  55. $reArr['arctitle'] = $arcRow['title'];
  56. $reArr['arcurl'] = GetFileUrl(
  57. $aid,
  58. $arcRow['typeid'],
  59. $arcRow['senddate'],
  60. $reArr['title'],
  61. $arcRow['ismake'],
  62. $arcRow['arcrank'],
  63. $arcRow['namerule'],
  64. $arcRow['typedir'],
  65. $arcRow['money'],
  66. $arcRow['filename'],
  67. $arcRow['moresite'],
  68. $arcRow['siteurl'],
  69. $arcRow['sitepath']
  70. );
  71. return $reArr;
  72. }
  73. }
  74. /**
  75. * 获取模型的表信息
  76. *
  77. * @param int $id 模型id
  78. * @param string $formtype 表单类型
  79. * @return array
  80. */
  81. if (!function_exists('GetChannelTable')) {
  82. function GetChannelTable($id, $formtype = 'channel')
  83. {
  84. global $dsql;
  85. if ($formtype == 'archive') {
  86. $query = "SELECT ch.maintable, ch.addtable FROM `#@__arctiny` tin LEFT JOIN `#@__channeltype` ch ON ch.id=tin.channel WHERE tin.id='$id'";
  87. } else if ($formtype == 'typeid') {
  88. $query = "SELECT ch.maintable, ch.addtable FROM `#@__arctype` act LEFT JOIN `#@__channeltype` ch ON ch.id=act.channeltype WHERE act.id='$id'";
  89. } else {
  90. $query = "SELECT maintable, addtable FROM `#@__channeltype` WHERE id='$id'";
  91. }
  92. $row = $dsql->GetOne($query);
  93. return $row;
  94. }
  95. }
  96. /**
  97. * 获得某文档的所有tag
  98. *
  99. * @param int $aid 文档id
  100. * @return string
  101. */
  102. if (!function_exists('GetTags')) {
  103. function GetTags($aid)
  104. {
  105. $tarr = GetTagsArray($aid);
  106. return count($tarr) > 0? implode(",", $tarr) : '';
  107. }
  108. }
  109. /**
  110. * 获得某文档的所有tag数组
  111. *
  112. * @param int $aid 文档id
  113. * @return array
  114. */
  115. if (!function_exists('GetTagsArray')) {
  116. function GetTagsArray($aid)
  117. {
  118. global $dsql;
  119. $tags = array();
  120. $query = "SELECT tag FROM `#@__taglist` WHERE aid='$aid' ";
  121. $dsql->Execute('tag', $query);
  122. while ($row = $dsql->GetArray('tag')) {
  123. $tags[] = $row['tag'];
  124. }
  125. return $tags;
  126. }
  127. }
  128. /**
  129. * 获取一个微表的索引键
  130. *
  131. * @access public
  132. * @param string $arcrank 权限值
  133. * @param int $typeid 栏目id
  134. * @param int $sortrank 排序id
  135. * @param int $channelid 模型id
  136. * @param int $senddate 发布日期
  137. * @param int $mid 会员id
  138. * @return int
  139. */
  140. if (!function_exists('GetIndexKey')) {
  141. function GetIndexKey($arcrank, $typeid, $sortrank = 0, $channelid = 1, $senddate = 0, $mid = 1)
  142. {
  143. global $dsql, $senddate, $typeid2;
  144. if (empty($typeid2)) $typeid2 = 0;
  145. if (empty($senddate)) $senddate = time();
  146. if (empty($sortrank)) $sortrank = $senddate;
  147. $typeid2 = intval($typeid2);
  148. $senddate = intval($senddate);
  149. $iquery = "INSERT INTO `#@__arctiny` (`arcrank`,`typeid`,`typeid2`,`channel`,`senddate`,`sortrank`,`mid`) VALUES ('$arcrank','$typeid','$typeid2','$channelid','$senddate','$sortrank','$mid') ";
  150. $dsql->ExecuteNoneQuery($iquery);
  151. $aid = $dsql->GetLastID();
  152. return $aid;
  153. }
  154. }
  155. /**
  156. * 更新微表key及tag
  157. *
  158. * @access public
  159. * @param int $id 文档id
  160. * @param string $arcrank 权限值
  161. * @param int $typeid 栏目id
  162. * @param int $sortrank 排序id
  163. * @param string $tags 标签
  164. * @return string
  165. */
  166. if (!function_exists('UpIndexKey')) {
  167. function UpIndexKey($id, $arcrank, $typeid, $sortrank = 0, $tags = '')
  168. {
  169. global $dsql, $typeid2;
  170. if (empty($typeid2)) $typeid2 = 0;
  171. $indexedsql = '';
  172. //商业全文检索组件索引
  173. if (TableHasField("#@__arctiny", "indexed")) {
  174. $indexedsql = ",`indexed`=2 ";
  175. }
  176. $query = "UPDATE `#@__arctiny` SET `arcrank`='$arcrank', `typeid`='$typeid', `typeid2`='$typeid2', `sortrank`='$sortrank'{$indexedsql} WHERE id = '$id' ";
  177. $dsql->ExecuteNoneQuery($query);
  178. //处理修改后的tag
  179. if ($tags != '') {
  180. $oldtags = GetTagsArray($id);
  181. $tagss = explode(',', $tags);
  182. foreach ($tagss as $tag) {
  183. $tag = trim($tag);
  184. if (isset($tag[255]) || $tag != stripslashes($tag)) {
  185. continue;
  186. }
  187. if (!in_array($tag, $oldtags)) {
  188. InsertOneTag($tag, $id);
  189. }
  190. }
  191. foreach ($oldtags as $tag) {
  192. if (!in_array($tag, $tagss)) {
  193. $dsql->ExecuteNoneQuery("DELETE FROM `#@__taglist` WHERE aid='$id' AND tag LIKE '$tag' ");
  194. $dsql->ExecuteNoneQuery("UPDATE `#@__tagindex` SET total=total-1 WHERE tag LIKE '$tag' ");
  195. } else {
  196. $dsql->ExecuteNoneQuery("UPDATE `#@__taglist` SET `arcrank` = '$arcrank', `typeid` = '$typeid' WHERE tag LIKE '$tag' ");
  197. }
  198. }
  199. } else {
  200. $oldtags = GetTagsArray($id);
  201. foreach ($oldtags as $tag) {
  202. $dsql->ExecuteNoneQuery("DELETE FROM `#@__taglist` WHERE aid='$id' AND tag LIKE '$tag' ");
  203. $dsql->ExecuteNoneQuery("UPDATE `#@__tagindex` SET total=total-1 WHERE tag LIKE '$tag' ");
  204. }
  205. }
  206. }
  207. }
  208. /**
  209. * 插入tags
  210. *
  211. * @access public
  212. * @param string $tag 标签
  213. * @param int $aid 文档aid
  214. * @return void
  215. */
  216. if (!function_exists('InsertTags')) {
  217. function InsertTags($tag, $aid)
  218. {
  219. $tags = explode(',', $tag);
  220. foreach ($tags as $tag) {
  221. $tag = trim($tag);
  222. if (isset($tag[255]) || $tag != stripslashes($tag)) {
  223. continue;
  224. }
  225. InsertOneTag($tag, $aid);
  226. }
  227. }
  228. }
  229. /**
  230. * 插入tag
  231. *
  232. * @access public
  233. * @param string $tag 标签
  234. * @param int $aid 文档aid
  235. * @return void
  236. */
  237. if (!function_exists('InsertOneTag')) {
  238. function InsertOneTag($tag, $aid)
  239. {
  240. global $typeid, $arcrank, $dsql;
  241. $tag = trim($tag);
  242. if ($tag == '') {
  243. return '';
  244. }
  245. if (empty($typeid)) {
  246. $typeid = 0;
  247. }
  248. if (empty($arcrank)) {
  249. $arcrank = 0;
  250. }
  251. $rs = false;
  252. $addtime = time();
  253. $row = $dsql->GetOne("SELECT * FROM `#@__tagindex` WHERE tag LIKE '$tag' ");
  254. if (!is_array($row)) {
  255. $rs = $dsql->ExecuteNoneQuery("INSERT INTO `#@__tagindex` (`tag`,`typeid`,`count`,`total`,`weekcc`,`monthcc`,`weekup`,`monthup`,`addtime`) VALUES ('$tag','$typeid','0','1','0','0','$addtime','$addtime','$addtime');");
  256. $tid = $dsql->GetLastID();
  257. } else {
  258. $rs = $dsql->ExecuteNoneQuery("UPDATE `#@__tagindex` SET total=total+1,addtime=$addtime WHERE tag LIKE '$tag' ");
  259. $tid = $row['id'];
  260. }
  261. if ($rs) {
  262. $dsql->ExecuteNoneQuery("INSERT INTO `#@__taglist` (`tid`,`aid`,`arcrank`,`typeid`,`tag`) VALUES ('$tid','$aid','$arcrank','$typeid','$tag');");
  263. }
  264. }
  265. }
  266. ?>