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

213 lines
9.3KB

  1. <?php
  2. /**
  3. * 发布文档模型
  4. *
  5. * @version $id:article_add.php 2020年9月14日 tianya $
  6. * @package DedeBIZ.Administrator
  7. * @copyright Copyright (c) 2022 DedeBIZ.COM
  8. * @license https://www.dedebiz.com/license
  9. * @link https://www.dedebiz.com
  10. */
  11. require_once(dirname(__FILE__).'/config.php');
  12. CheckPurview('a_New,a_AccNew');
  13. require_once(DEDEINC.'/customfields.func.php');
  14. require_once(DEDEADMIN.'/inc/inc_archives_functions.php');
  15. if (file_exists(DEDEDATA.'/template.rand.php')) {
  16. require_once(DEDEDATA.'/template.rand.php');
  17. }
  18. if (empty($dopost)) $dopost = '';
  19. if ($dopost != 'save') {
  20. require_once(DEDEINC."/dedetag.class.php");
  21. require_once(DEDEADMIN."/inc/inc_catalog_options.php");
  22. ClearMyAddon();
  23. $channelid = empty($channelid) ? 0 : intval($channelid);
  24. $cid = empty($cid) ? 0 : intval($cid);
  25. if (empty($geturl)) $geturl = '';
  26. $keywords = $writer = $source = $body = $description = $title = '';
  27. //获得栏目模型id
  28. if ($cid > 0 && $channelid == 0) {
  29. $row = $dsql->GetOne("SELECT channeltype FROM `#@__arctype` WHERE id='$cid';");
  30. $channelid = $row['channeltype'];
  31. } else {
  32. if ($channelid == 0) {
  33. $channelid = 1;
  34. }
  35. }
  36. //获得栏目模型信息
  37. $cInfos = $dsql->GetOne("SELECT * FROM `#@__channeltype` WHERE id='$channelid' ");
  38. //获取文档最大id+1以确定当前权重
  39. $maxWright = $dsql->GetOne("SELECT id+1 AS cc FROM `#@__archives` ORDER BY id DESC LIMIT 1");
  40. $maxWright = empty($maxWright)? array('cc'=>1) : $maxWright;
  41. include DedeInclude("templets/article_add.htm");
  42. exit();
  43. } else if ($dopost == 'save') {
  44. require_once(DEDEINC.'/image.func.php');
  45. require_once(DEDEINC.'/libraries/oxwindow.class.php');
  46. $flag = isset($flags) ? join(',', $flags) : '';
  47. $notpost = isset($notpost) && $notpost == 1 ? 1 : 0;
  48. if (empty($typeid2)) $typeid2 = '';
  49. if (!isset($autokey)) $autokey = 0;
  50. if (!isset($remote)) $remote = 0;
  51. if (!isset($dellink)) $dellink = 0;
  52. if (!isset($autolitpic)) $autolitpic = 0;
  53. if (empty($click)) $click = ($cfg_arc_click == '-1' ? mt_rand(1000,6000) : $cfg_arc_click);
  54. if (trim($title) == '') {
  55. ShowMsg("文档标题不能为空", "-1");
  56. exit();
  57. }
  58. if (empty($typeid)) {
  59. ShowMsg("请选择文档栏目", "-1");
  60. exit();
  61. }
  62. if (empty($channelid)) {
  63. ShowMsg("文档为非指定类型,请检查您发布文档是否正确", "-1");
  64. exit();
  65. }
  66. if (!CheckChannel($typeid, $channelid)) {
  67. ShowMsg("您所选择的栏目与当前模型不相符,请重新选择", "-1");
  68. exit();
  69. }
  70. if (!TestPurview('a_New')) {
  71. CheckCatalog($typeid, "您没有操作栏目<span class='text-primary'>{$typeid}</span>权限");
  72. }
  73. //对保存的文档进行处理
  74. if (empty($writer)) $writer = $cuserLogin->getUserName();
  75. if (empty($source)) $source = '未知';
  76. $pubdate = GetMkTime($pubdate);
  77. $senddate = time();
  78. $sortrank = AddDay($pubdate, $sortup);
  79. $ismake = $ishtml == 0 ? -1 : 0;
  80. $title = preg_replace("#\"#", '"', $title);
  81. $title = dede_htmlspecialchars(cn_substrR($title, $cfg_title_maxlen));
  82. $shorttitle = cn_substrR($shorttitle, 36);
  83. $color = cn_substrR($color, 7);
  84. $writer = cn_substrR($writer, 20);
  85. $source = cn_substrR($source, 30);
  86. $description = cn_substrR($description, $cfg_auot_description);
  87. $keywords = cn_substrR($keywords, 60);
  88. $filename = trim(cn_substrR($filename, 40));
  89. $userip = GetIP();
  90. $isremote = 0;
  91. $serviterm = empty($serviterm) ? "" : $serviterm;
  92. if (!TestPurview('a_Check,a_AccCheck,a_MyCheck')) {
  93. $arcrank = -1;
  94. }
  95. $adminid = $cuserLogin->getUserID();
  96. //处理上传的缩略图
  97. if (empty($ddisremote)) {
  98. $ddisremote = 0;
  99. }
  100. $litpic = GetDDImage('none', $picname, $ddisremote);
  101. //生成文档id
  102. $arcID = GetIndexKey($arcrank, $typeid, $sortrank, $channelid, $senddate, $adminid);
  103. if (empty($arcID)) {
  104. ShowMsg("获取主键失败,无法进行后续操作", "-1");
  105. exit();
  106. }
  107. //处理body字段自动摘要、自动提取缩略图等
  108. $body = AnalyseHtmlBody($body, $description, $litpic, $keywords, 'htmltext');
  109. //自动分页
  110. if ($sptype == 'auto') {
  111. $body = SpLongBody($body, $spsize * 1024, "#p#分页标题#e#");
  112. }
  113. //分析处理附加表数据
  114. $inadd_f = $inadd_v = '';
  115. if (!empty($dede_addonfields)) {
  116. $addonfields = explode(';', $dede_addonfields);
  117. if (is_array($addonfields)) {
  118. foreach ($addonfields as $v) {
  119. if ($v == '') continue;
  120. $vs = explode(',', $v);
  121. if ($vs[1] == 'htmltext' || $vs[1] == 'textdata') {
  122. ${$vs[0]} = AnalyseHtmlBody(${$vs[0]}, $description, $litpic, $keywords, $vs[1]);
  123. } else {
  124. if (!isset(${$vs[0]})) ${$vs[0]} = '';
  125. ${$vs[0]} = GetFieldValueA(${$vs[0]}, $vs[1], $arcID);
  126. }
  127. $inadd_f .= ','.$vs[0];
  128. $inadd_v .= " ,'".${$vs[0]}."' ";
  129. }
  130. }
  131. }
  132. //处理图片文档的自定义属性
  133. if ($litpic != '' && !preg_match("#p#", $flag)) {
  134. $flag = ($flag == '' ? 'p' : $flag.',p');
  135. }
  136. if ($redirecturl != '' && !preg_match("#j#", $flag)) {
  137. $flag = ($flag == '' ? 'j' : $flag.',j');
  138. }
  139. //跳转网址的文档强制为动态
  140. if (preg_match("#j#", $flag)) $ismake = -1;
  141. //保存到主表
  142. $query = "INSERT INTO `#@__archives` (id,typeid,typeid2,sortrank,flag,ismake,channel,arcrank,click,money,title,shorttitle,color,writer,source,litpic,pubdate,senddate,mid,notpost,description,keywords,filename,dutyadmin,weight) VALUES ('$arcID','$typeid','$typeid2','$sortrank','$flag','$ismake','$channelid','$arcrank','$click','$money','$title','$shorttitle','$color','$writer','$source','$litpic','$pubdate','$senddate','$adminid','$notpost','$description','$keywords','$filename','$adminid','$weight');";
  143. if (!$dsql->ExecuteNoneQuery($query)) {
  144. $gerr = $dsql->GetError();
  145. $dsql->ExecuteNoneQuery("DELETE FROM `#@__arctiny` WHERE id='$arcID'");
  146. ShowMsg("数据保存到数据库文档主表出错,请检查数据库字段".str_replace('"', '', $gerr), "javascript:;");
  147. exit();
  148. }
  149. //保存到附加表
  150. $cts = $dsql->GetOne("SELECT addtable FROM `#@__channeltype` WHERE id='$channelid' ");
  151. $addtable = trim($cts['addtable']);
  152. if (empty($addtable)) {
  153. $dsql->ExecuteNoneQuery("DELETE FROM `#@__archives` WHERE id='$arcID'");
  154. $dsql->ExecuteNoneQuery("DELETE FROM `#@__arctiny` WHERE id='$arcID'");
  155. ShowMsg("没找到模型<span class='text-primary'>{$channelid}</span>主表信息,无法完成操作", "javascript:;");
  156. exit();
  157. }
  158. $useip = GetIP();
  159. $templet = empty($templet) ? '' : $templet;
  160. $query = "INSERT INTO `{$addtable}` (aid,typeid,redirecturl,templet,userip,body{$inadd_f}) VALUES ('$arcID','$typeid','$redirecturl','$templet','$useip','$body'{$inadd_v})";
  161. if (!$dsql->ExecuteNoneQuery($query)) {
  162. $gerr = $dsql->GetError();
  163. $dsql->ExecuteNoneQuery("DELETE FROM `#@__archives` WHERE id='$arcID'");
  164. $dsql->ExecuteNoneQuery("DELETE FROM `#@__arctiny` WHERE id='$arcID'");
  165. ShowMsg("数据保存到数据库附加表出错,请检查数据库字段".str_replace('"', '', $gerr), "javascript:;");
  166. exit();
  167. }
  168. //生成网页
  169. InsertTags($tags, $arcID);
  170. $picTitle = false;
  171. if (count($_SESSION['bigfile_info']) > 0) {
  172. foreach ($_SESSION['bigfile_info'] as $k => $v) {
  173. if (!empty($v)) {
  174. $pictitle = ${'picinfook'.$k};
  175. $titleSet = '';
  176. if (!empty($pictitle)) {
  177. $picTitle = TRUE;
  178. $titleSet = ",title='{$pictitle}'";
  179. }
  180. $dsql->ExecuteNoneQuery("UPDATE `#@__uploads` SET arcid='{$arcID}'{$titleSet} WHERE url LIKE '{$v}';");
  181. }
  182. }
  183. }
  184. $artUrl = MakeArt($arcID, true, true, $isremote);
  185. if ($artUrl == '') {
  186. $artUrl = $cfg_phpurl."/view.php?aid=$arcID";
  187. }
  188. ClearMyAddon($arcID, $title);
  189. //自动更新关联文档
  190. if (is_array($automake)) {
  191. foreach ($automake as $key => $value) {
  192. if (isset(${$key}) && !empty(${$key})) {
  193. $ids = explode(",", ${$key});
  194. foreach ($ids as $id) {
  195. MakeArt($id, true, true, $isremote);
  196. }
  197. }
  198. }
  199. }
  200. //返回成功信息
  201. $msg = "<tr>
  202. <td bgcolor='#f5f5f5' align='center'><a href='article_add.php?cid=$typeid' class='btn btn-success btn-sm'>发布文档</a><a href='archives_do.php?aid=".$arcID."&dopost=editArchives' class='btn btn-success btn-sm'>修改文档</a><a href='$artUrl' target='_blank' class='btn btn-success btn-sm'>浏览文档</a><a href='catalog_do.php?cid=$typeid&dopost=listArchives' class='btn btn-success btn-sm'>管理文档</a>$backurl</td>
  203. </tr>";
  204. $msg = "{$msg}".GetUpdateTest();
  205. $wintitle = "成功发布文档";
  206. $wecome_info = "文档管理 - 发布文档";
  207. $win = new OxWindow();
  208. $win->AddTitle("成功发布文档");
  209. $win->AddMsgItem($msg);
  210. $winform = $win->GetWindow("hand", false);
  211. $win->Display();
  212. }
  213. ?>