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

235 lines
10KB

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