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

221 lines
9.6KB

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