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

270 lines
9.8KB

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