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

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