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

322 lines
11KB

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