国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

244 lines
8.6KB

  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 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. global $dsql;
  106. $tags = '';
  107. $query = "SELECT tag FROM `#@__taglist` WHERE aid='$aid' ";
  108. $dsql->Execute('tag', $query);
  109. while ($row = $dsql->GetArray('tag')) {
  110. $tags .= ($tags == '' ? $row['tag'] : ','.$row['tag']);
  111. }
  112. return $tags;
  113. }
  114. }
  115. /**
  116. * 获取一个微表的索引键
  117. *
  118. * @access public
  119. * @param string $arcrank 权限值
  120. * @param int $typeid 栏目id
  121. * @param int $sortrank 排序id
  122. * @param int $channelid 模型id
  123. * @param int $senddate 发布日期
  124. * @param int $mid 会员id
  125. * @return int
  126. */
  127. if (!function_exists('GetIndexKey')) {
  128. function GetIndexKey($arcrank, $typeid, $sortrank = 0, $channelid = 1, $senddate = 0, $mid = 1)
  129. {
  130. global $dsql, $senddate, $typeid2;
  131. if (empty($typeid2)) $typeid2 = 0;
  132. if (empty($senddate)) $senddate = time();
  133. if (empty($sortrank)) $sortrank = $senddate;
  134. $typeid2 = intval($typeid2);
  135. $senddate = intval($senddate);
  136. $iquery = "INSERT INTO `#@__arctiny` (`arcrank`,`typeid`,`typeid2`,`channel`,`senddate`,`sortrank`,`mid`) VALUES ('$arcrank','$typeid','$typeid2','$channelid','$senddate','$sortrank','$mid') ";
  137. $dsql->ExecuteNoneQuery($iquery);
  138. $aid = $dsql->GetLastID();
  139. return $aid;
  140. }
  141. }
  142. /**
  143. * 更新微表key及Tag
  144. *
  145. * @access public
  146. * @param int $id 文档id
  147. * @param string $arcrank 权限值
  148. * @param int $typeid 栏目id
  149. * @param int $sortrank 排序id
  150. * @param string $tags 标签
  151. * @return string
  152. */
  153. if (!function_exists('UpIndexKey')) {
  154. function UpIndexKey($id, $arcrank, $typeid, $sortrank = 0, $tags = '')
  155. {
  156. global $dsql, $typeid2;
  157. if (empty($typeid2)) $typeid2 = 0;
  158. $addtime = time();
  159. $query = "UPDATE `#@__arctiny` SET `arcrank`='$arcrank', `typeid`='$typeid', `typeid2`='$typeid2', `sortrank`='$sortrank' WHERE id = '$id' ";
  160. $dsql->ExecuteNoneQuery($query);
  161. //处理修改后的Tag
  162. if ($tags != '') {
  163. $oldtag = GetTags($id);
  164. $oldtags = explode(',', $oldtag);
  165. $tagss = explode(',', $tags);
  166. foreach ($tagss as $tag) {
  167. $tag = trim($tag);
  168. if (isset($tag[12]) || $tag != stripslashes($tag)) {
  169. continue;
  170. }
  171. if (!in_array($tag, $oldtags)) {
  172. InsertOneTag($tag, $id);
  173. }
  174. }
  175. foreach ($oldtags as $tag) {
  176. if (!in_array($tag, $tagss)) {
  177. $dsql->ExecuteNoneQuery("DELETE FROM `#@__taglist` WHERE aid='$id' AND tag LIKE '$tag' ");
  178. $dsql->ExecuteNoneQuery("UPDATE `#@__tagindex` SET total=total-1 WHERE tag LIKE '$tag' ");
  179. } else {
  180. $dsql->ExecuteNoneQuery("UPDATE `#@__taglist` SET `arcrank` = '$arcrank', `typeid` = '$typeid' WHERE tag LIKE '$tag' ");
  181. }
  182. }
  183. }
  184. }
  185. }
  186. /**
  187. * 插入Tags
  188. *
  189. * @access public
  190. * @param string $tag 标签
  191. * @param int $aid 文档AID
  192. * @return void
  193. */
  194. if (!function_exists('InsertTags')) {
  195. function InsertTags($tag, $aid)
  196. {
  197. $tags = explode(',', $tag);
  198. foreach ($tags as $tag) {
  199. $tag = trim($tag);
  200. if (isset($tag[20]) || $tag != stripslashes($tag)) {
  201. continue;
  202. }
  203. InsertOneTag($tag, $aid);
  204. }
  205. }
  206. }
  207. /**
  208. * 插入一个tag
  209. *
  210. * @access public
  211. * @param string $tag 标签
  212. * @param int $aid 文档AID
  213. * @return void
  214. */
  215. if (!function_exists('InsertOneTag')) {
  216. function InsertOneTag($tag, $aid)
  217. {
  218. global $typeid, $arcrank, $dsql;
  219. $tag = trim($tag);
  220. if ($tag == '') {
  221. return '';
  222. }
  223. if (empty($typeid)) {
  224. $typeid = 0;
  225. }
  226. if (empty($arcrank)) {
  227. $arcrank = 0;
  228. }
  229. $rs = false;
  230. $addtime = time();
  231. $row = $dsql->GetOne("SELECT * FROM `#@__tagindex` WHERE tag LIKE '$tag' ");
  232. if (!is_array($row)) {
  233. $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');");
  234. $tid = $dsql->GetLastID();
  235. } else {
  236. $rs = $dsql->ExecuteNoneQuery("UPDATE `#@__tagindex` SET total=total+1,addtime=$addtime WHERE tag LIKE '$tag' ");
  237. $tid = $row['id'];
  238. }
  239. if ($rs) {
  240. $dsql->ExecuteNoneQuery("INSERT INTO `#@__taglist` (`tid`,`aid`,`arcrank`,`typeid`,`tag`) VALUES ('$tid','$aid','$arcrank','$typeid','$tag');");
  241. }
  242. }
  243. }
  244. ?>