国内流行的内容管理系统(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.

249 lines
8.7KB

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