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

215 lines
9.4KB

  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. }
  44. /*--------------------------------
  45. function __save(){ }
  46. -------------------------------*/
  47. else if ($dopost == 'save') {
  48. require_once(DEDEINC.'/image.func.php');
  49. require_once(DEDEINC.'/libraries/oxwindow.class.php');
  50. $flag = isset($flags) ? join(',', $flags) : '';
  51. $notpost = isset($notpost) && $notpost == 1 ? 1 : 0;
  52. if (empty($typeid2)) $typeid2 = '';
  53. if (!isset($autokey)) $autokey = 0;
  54. if (!isset($remote)) $remote = 0;
  55. if (!isset($dellink)) $dellink = 0;
  56. if (!isset($autolitpic)) $autolitpic = 0;
  57. if (empty($click)) $click = ($cfg_arc_click == '-1' ? mt_rand(200, 1000) : $cfg_arc_click);
  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. if (trim($title) == '') {
  108. ShowMsg('标题不能为空', '-1');
  109. exit();
  110. }
  111. //处理body字段自动摘要、自动提取缩略图等
  112. $body = AnalyseHtmlBody($body, $description, $litpic, $keywords, 'htmltext');
  113. //自动分页
  114. if ($sptype == 'auto') {
  115. $body = SpLongBody($body, $spsize * 1024, "#p#分页标题#e#");
  116. }
  117. //分析处理附加表数据
  118. $inadd_f = $inadd_v = '';
  119. if (!empty($dede_addonfields)) {
  120. $addonfields = explode(';', $dede_addonfields);
  121. if (is_array($addonfields)) {
  122. foreach ($addonfields as $v) {
  123. if ($v == '') continue;
  124. $vs = explode(',', $v);
  125. if ($vs[1] == 'htmltext' || $vs[1] == 'textdata') {
  126. ${$vs[0]} = AnalyseHtmlBody(${$vs[0]}, $description, $litpic, $keywords, $vs[1]);
  127. } else {
  128. if (!isset(${$vs[0]})) ${$vs[0]} = '';
  129. ${$vs[0]} = GetFieldValueA(${$vs[0]}, $vs[1], $arcID);
  130. }
  131. $inadd_f .= ','.$vs[0];
  132. $inadd_v .= " ,'".${$vs[0]}."' ";
  133. }
  134. }
  135. }
  136. //处理图片文档的自定义属性
  137. if ($litpic != '' && !preg_match("#p#", $flag)) {
  138. $flag = ($flag == '' ? 'p' : $flag.',p');
  139. }
  140. if ($redirecturl != '' && !preg_match("#j#", $flag)) {
  141. $flag = ($flag == '' ? 'j' : $flag.',j');
  142. }
  143. //跳转网址的文档强制为动态
  144. if (preg_match("#j#", $flag)) $ismake = -1;
  145. //保存到主表
  146. $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');";
  147. if (!$dsql->ExecuteNoneQuery($query)) {
  148. $gerr = $dsql->GetError();
  149. $dsql->ExecuteNoneQuery("DELETE FROM `#@__arctiny` WHERE id='$arcID'");
  150. ShowMsg("数据保存到数据库主表`#@__archives`时出错,请检查数据库字段".str_replace('"', '', $gerr), "javascript:;");
  151. exit();
  152. }
  153. //保存到附加表
  154. $cts = $dsql->GetOne("SELECT addtable FROM `#@__channeltype` WHERE id='$channelid' ");
  155. $addtable = trim($cts['addtable']);
  156. if (empty($addtable)) {
  157. $dsql->ExecuteNoneQuery("DELETE FROM `#@__archives` WHERE id='$arcID'");
  158. $dsql->ExecuteNoneQuery("DELETE FROM `#@__arctiny` WHERE id='$arcID'");
  159. ShowMsg("没找到当前模型<span class='text-primary'>{$channelid}</span>主表信息,无法完成操作", "javascript:;");
  160. exit();
  161. }
  162. $useip = GetIP();
  163. $templet = empty($templet) ? '' : $templet;
  164. $query = "INSERT INTO `{$addtable}` (aid,typeid,redirecturl,templet,userip,body{$inadd_f}) VALUES ('$arcID','$typeid','$redirecturl','$templet','$useip','$body'{$inadd_v})";
  165. if (!$dsql->ExecuteNoneQuery($query)) {
  166. $gerr = $dsql->GetError();
  167. $dsql->ExecuteNoneQuery("DELETE FROM `#@__archives` WHERE id='$arcID'");
  168. $dsql->ExecuteNoneQuery("DELETE FROM `#@__arctiny` WHERE id='$arcID'");
  169. ShowMsg("数据保存到数据库附加表时出错,请检查数据库字段".str_replace('"', '', $gerr), "javascript:;");
  170. exit();
  171. }
  172. //生成网页
  173. InsertTags($tags, $arcID);
  174. $picTitle = false;
  175. if (count($_SESSION['bigfile_info']) > 0) {
  176. foreach ($_SESSION['bigfile_info'] as $k => $v) {
  177. if (!empty($v)) {
  178. $pictitle = ${'picinfook'.$k};
  179. $titleSet = '';
  180. if (!empty($pictitle)) {
  181. $picTitle = TRUE;
  182. $titleSet = ",title='{$pictitle}'";
  183. }
  184. $dsql->ExecuteNoneQuery("UPDATE `#@__uploads` SET arcid='{$arcID}'{$titleSet} WHERE url LIKE '{$v}'; ");
  185. }
  186. }
  187. }
  188. $artUrl = MakeArt($arcID, true, true, $isremote);
  189. if ($artUrl == '') {
  190. $artUrl = $cfg_phpurl."/view.php?aid=$arcID";
  191. }
  192. ClearMyAddon($arcID, $title);
  193. //自动更新关联文档
  194. if (is_array($automake)) {
  195. foreach ($automake as $key => $value) {
  196. if (isset(${$key}) && !empty(${$key})) {
  197. $ids = explode(",", ${$key});
  198. foreach ($ids as $id) {
  199. MakeArt($id, true, true, $isremote);
  200. }
  201. }
  202. }
  203. }
  204. //返回成功信息
  205. $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";
  206. $msg = "<div>{$msg}</div>".GetUpdateTest();
  207. $wintitle = "成功发布文档";
  208. $wecome_info = "文档管理::发布文档";
  209. $win = new OxWindow();
  210. $win->AddTitle("成功发布文档");
  211. $win->AddMsgItem($msg);
  212. $winform = $win->GetWindow("hand", "&nbsp;", false);
  213. $win->Display();
  214. }
  215. ?>