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

296 lines
8.9KB

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