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

245 lines
9.7KB

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