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

286 lines
11KB

  1. <?php
  2. /**
  3. * 文档发布
  4. *
  5. * @version $Id: article_add.php 2020年9月14日 tianya $
  6. * @package DedeBIZ.Administrator
  7. * @copyright Copyright (c) 2021, 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. -------------------------------*/ else if ($dopost == 'save') {
  53. require_once(DEDEINC . '/image.func.php');
  54. require_once(DEDEINC . '/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. // 处理新的缩略图上传
  107. if ($litpic_b64 != "") {
  108. $data = explode(',', $litpic_b64);
  109. $ntime = time();
  110. $savepath = $ddcfg_image_dir . '/' . MyDate($cfg_addon_savetype, $ntime);
  111. CreateDir($savepath);
  112. $fullUrl = $savepath . '/' . dd2char(MyDate('mdHis', $ntime) . $cuserLogin->getUserID() . mt_rand(1000, 9999));
  113. $fullUrl = $fullUrl . ".png";
  114. file_put_contents($cfg_basedir . $fullUrl, base64_decode($data[1]));
  115. // 加水印
  116. WaterImg($cfg_basedir . $fullUrl, 'up');
  117. $litpic = $fullUrl;
  118. }
  119. //生成文档ID
  120. $arcID = GetIndexKey($arcrank, $typeid, $sortrank, $channelid, $senddate, $adminid);
  121. if (empty($arcID)) {
  122. ShowMsg("无法获得主键,因此无法进行后续操作!", "-1");
  123. exit();
  124. }
  125. if (trim($title) == '') {
  126. ShowMsg('标题不能为空', '-1');
  127. exit();
  128. }
  129. //处理body字段自动摘要、自动提取缩略图等
  130. $body = AnalyseHtmlBody($body, $description, $litpic, $keywords, 'htmltext');
  131. //自动分页
  132. if ($sptype == 'auto') {
  133. $body = SpLongBody($body, $spsize * 1024, "#p#分页标题#e#");
  134. }
  135. //分析处理附加表数据
  136. $inadd_f = $inadd_v = '';
  137. if (!empty($dede_addonfields)) {
  138. $addonfields = explode(';', $dede_addonfields);
  139. if (is_array($addonfields)) {
  140. foreach ($addonfields as $v) {
  141. if ($v == '') continue;
  142. $vs = explode(',', $v);
  143. if ($vs[1] == 'htmltext' || $vs[1] == 'textdata') {
  144. ${$vs[0]} = AnalyseHtmlBody(${$vs[0]}, $description, $litpic, $keywords, $vs[1]);
  145. } else {
  146. if (!isset(${$vs[0]})) ${$vs[0]} = '';
  147. ${$vs[0]} = GetFieldValueA(${$vs[0]}, $vs[1], $arcID);
  148. }
  149. $inadd_f .= ',' . $vs[0];
  150. $inadd_v .= " ,'" . ${$vs[0]} . "' ";
  151. }
  152. }
  153. }
  154. //处理图片文档的自定义属性
  155. if ($litpic != '' && !preg_match("#p#", $flag)) {
  156. $flag = ($flag == '' ? 'p' : $flag . ',p');
  157. }
  158. if ($redirecturl != '' && !preg_match("#j#", $flag)) {
  159. $flag = ($flag == '' ? 'j' : $flag . ',j');
  160. }
  161. //跳转网址的文档强制为动态
  162. if (preg_match("#j#", $flag)) $ismake = -1;
  163. //保存到主表
  164. $query = "INSERT INTO `#@__archives`(id,typeid,typeid2,sortrank,flag,ismake,channel,arcrank,click,money,title,shorttitle,
  165. 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',
  167. '$title','$shorttitle','$color','$writer','$source','$litpic','$pubdate','$senddate',
  168. '$adminid','0','$notpost','$description','$keywords','$filename','$adminid','$weight');";
  169. if (!$dsql->ExecuteNoneQuery($query)) {
  170. $gerr = $dsql->GetError();
  171. $dsql->ExecuteNoneQuery("DELETE FROM `#@__arctiny` WHERE id='$arcID'");
  172. ShowMsg("把数据保存到数据库主表 `#@__archives` 时出错,请把相关信息提交给DedeCMS官方。" . str_replace('"', '', $gerr), "javascript:;");
  173. exit();
  174. }
  175. //保存到附加表
  176. $cts = $dsql->GetOne("SELECT addtable FROM `#@__channeltype` WHERE id='$channelid' ");
  177. $addtable = trim($cts['addtable']);
  178. if (empty($addtable)) {
  179. $dsql->ExecuteNoneQuery("DELETE FROM `#@__archives` WHERE id='$arcID'");
  180. $dsql->ExecuteNoneQuery("DELETE FROM `#@__arctiny` WHERE id='$arcID'");
  181. ShowMsg("没找到当前模型[{$channelid}]的主表信息,无法完成操作!。", "javascript:;");
  182. exit();
  183. }
  184. $useip = GetIP();
  185. $templet = empty($templet) ? '' : $templet;
  186. $query = "INSERT INTO `{$addtable}`(aid,typeid,redirecturl,templet,userip,body{$inadd_f}) Values('$arcID','$typeid','$redirecturl','$templet','$useip','$body'{$inadd_v})";
  187. if (!$dsql->ExecuteNoneQuery($query)) {
  188. $gerr = $dsql->GetError();
  189. $dsql->ExecuteNoneQuery("Delete From `#@__archives` where id='$arcID'");
  190. $dsql->ExecuteNoneQuery("Delete From `#@__arctiny` where id='$arcID'");
  191. ShowMsg("把数据保存到数据库附加表 `{$addtable}` 时出错,请把相关信息提交给DedeCMS官方。" . str_replace('"', '', $gerr), "javascript:;");
  192. exit();
  193. }
  194. //生成HTML
  195. InsertTags($tags, $arcID);
  196. if ($cfg_remote_site == 'Y' && $isremote == "1") {
  197. if ($serviterm != "") {
  198. list($servurl, $servuser, $servpwd) = explode(',', $serviterm);
  199. $config = array('hostname' => $servurl, 'username' => $servuser, 'password' => $servpwd, 'debug' => 'TRUE');
  200. } else {
  201. $config = array();
  202. }
  203. if (!$ftp->connect($config)) exit('Error:None FTP Connection!');
  204. }
  205. $picTitle = false;
  206. if (count($_SESSION['bigfile_info']) > 0) {
  207. foreach ($_SESSION['bigfile_info'] as $k => $v) {
  208. if (!empty($v)) {
  209. $pictitle = ${'picinfook' . $k};
  210. $titleSet = '';
  211. if (!empty($pictitle)) {
  212. $picTitle = TRUE;
  213. $titleSet = ",title='{$pictitle}'";
  214. }
  215. $dsql->ExecuteNoneQuery("UPDATE `#@__uploads` SET arcid='{$arcID}'{$titleSet} WHERE url LIKE '{$v}'; ");
  216. }
  217. }
  218. }
  219. $artUrl = MakeArt($arcID, true, true, $isremote);
  220. if ($artUrl == '') {
  221. $artUrl = $cfg_phpurl . "/view.php?aid=$arcID";
  222. }
  223. ClearMyAddon($arcID, $title);
  224. // 自动更新关联内容
  225. if (is_array($automake)) {
  226. foreach ($automake as $key => $value) {
  227. if (isset(${$key}) && !empty(${$key})) {
  228. $ids = explode(",", ${$key});
  229. foreach ($ids as $id) {
  230. MakeArt($id, true, true, $isremote);
  231. }
  232. }
  233. }
  234. }
  235. //返回成功信息
  236. $msg = "   请选择你的后续操作:
  237. <a href='article_add.php?cid=$typeid' class='btn btn-secondary btn-sm'>继续发布文章</a>
  238. &nbsp;&nbsp;
  239. <a href='$artUrl' target='_blank' class='btn btn-secondary btn-sm'>查看文章</a>
  240. &nbsp;&nbsp;
  241. <a href='archives_do.php?aid=" . $arcID . "&dopost=editArchives' class='btn btn-secondary btn-sm'>更改文章</a>
  242. &nbsp;&nbsp;
  243. <a href='catalog_do.php?cid=$typeid&dopost=listArchives' class='btn btn-secondary btn-sm'>已发布文章管理</a>
  244. &nbsp;&nbsp;
  245. $backurl
  246. ";
  247. $msg = "<div style=\"line-height:36px;height:36px\">{$msg}</div>" . GetUpdateTest();
  248. $wintitle = "成功发布文章!";
  249. $wecome_info = "文章管理::发布文章";
  250. $win = new OxWindow();
  251. $win->AddTitle("成功发布文章:");
  252. $win->AddMsgItem($msg);
  253. $winform = $win->GetWindow("hand", "&nbsp;", false);
  254. $win->Display();
  255. }