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

277 line
9.8KB

  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. if ($arcrank == -1) {
  173. //如果内容被改为待审核状态,删除索引
  174. if ($dsql->IsTable('#@__search_sync')) {
  175. $intime = time();
  176. $insql = "INSERT INTO `#@__search_sync` (`aid`, `add_at`) VALUES ({$id}, $intime)";
  177. $dsql->ExecuteNoneQuery($insql);
  178. DedeSearchDo("delete", array("id" => $id));
  179. }
  180. } else {
  181. //商业全文检索组件索引,更新索引信息
  182. if (TableHasField("#@__arctiny", "indexed")) {
  183. $indexedsql = ",`indexed`=2 ";
  184. }
  185. $query = "UPDATE `#@__arctiny` SET `arcrank`='$arcrank', `typeid`='$typeid', `typeid2`='$typeid2', `sortrank`='$sortrank'{$indexedsql} WHERE id = '$id' ";
  186. DedeSearchDo("add", array("id" => $id));
  187. $dsql->ExecuteNoneQuery($query);
  188. }
  189. //处理修改后的tag
  190. if ($tags != '') {
  191. $oldtags = GetTagsArray($id);
  192. $tagss = explode(',', $tags);
  193. foreach ($tagss as $tag) {
  194. $tag = trim($tag);
  195. if (isset($tag[255]) || $tag != stripslashes($tag)) {
  196. continue;
  197. }
  198. if (!in_array($tag, $oldtags)) {
  199. InsertOneTag($tag, $id);
  200. }
  201. }
  202. foreach ($oldtags as $tag) {
  203. if (!in_array($tag, $tagss)) {
  204. $dsql->ExecuteNoneQuery("DELETE FROM `#@__taglist` WHERE aid='$id' AND tag LIKE '$tag' ");
  205. $dsql->ExecuteNoneQuery("UPDATE `#@__tagindex` SET total=total-1 WHERE tag LIKE '$tag' ");
  206. } else {
  207. $dsql->ExecuteNoneQuery("UPDATE `#@__taglist` SET `arcrank` = '$arcrank', `typeid` = '$typeid' WHERE tag LIKE '$tag' ");
  208. }
  209. }
  210. } else {
  211. $oldtags = GetTagsArray($id);
  212. foreach ($oldtags as $tag) {
  213. $dsql->ExecuteNoneQuery("DELETE FROM `#@__taglist` WHERE aid='$id' AND tag LIKE '$tag' ");
  214. $dsql->ExecuteNoneQuery("UPDATE `#@__tagindex` SET total=total-1 WHERE tag LIKE '$tag' ");
  215. }
  216. }
  217. }
  218. }
  219. /**
  220. * 插入tags
  221. *
  222. * @access public
  223. * @param string $tag 标签
  224. * @param int $aid 文档aid
  225. * @return void
  226. */
  227. if (!function_exists('InsertTags')) {
  228. function InsertTags($tag, $aid)
  229. {
  230. $tags = explode(',', $tag);
  231. foreach ($tags as $tag) {
  232. $tag = trim($tag);
  233. if (isset($tag[255]) || $tag != stripslashes($tag)) {
  234. continue;
  235. }
  236. InsertOneTag($tag, $aid);
  237. }
  238. }
  239. }
  240. /**
  241. * 插入tag
  242. *
  243. * @access public
  244. * @param string $tag 标签
  245. * @param int $aid 文档aid
  246. * @return void
  247. */
  248. if (!function_exists('InsertOneTag')) {
  249. function InsertOneTag($tag, $aid)
  250. {
  251. global $typeid, $arcrank, $dsql;
  252. $tag = trim($tag);
  253. if ($tag == '') {
  254. return '';
  255. }
  256. if (empty($typeid)) {
  257. $typeid = 0;
  258. }
  259. if (empty($arcrank)) {
  260. $arcrank = 0;
  261. }
  262. $rs = false;
  263. $addtime = time();
  264. $row = $dsql->GetOne("SELECT * FROM `#@__tagindex` WHERE tag LIKE '$tag' ");
  265. if (!is_array($row)) {
  266. $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');");
  267. $tid = $dsql->GetLastID();
  268. } else {
  269. $rs = $dsql->ExecuteNoneQuery("UPDATE `#@__tagindex` SET total=total+1,addtime=$addtime WHERE tag LIKE '$tag' ");
  270. $tid = $row['id'];
  271. }
  272. if ($rs) {
  273. $dsql->ExecuteNoneQuery("INSERT INTO `#@__taglist` (`tid`,`aid`,`arcrank`,`typeid`,`tag`) VALUES ('$tid','$aid','$arcrank','$typeid','$tag');");
  274. }
  275. }
  276. }
  277. ?>