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

273 lines
8.8KB

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