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

180 lines
8.1KB

  1. <?php
  2. /**
  3. * 发布自定义文档模型
  4. *
  5. * @version $id:archives_add.php 8:26 2010年7月12日 tianya $
  6. * @package DedeBIZ.Administrator
  7. * @copyright Copyright (c) 2022 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+1以确定当前权重
  36. $maxWright = $dsql->GetOne("SELECT id+1 AS cc FROM `#@__archives` ORDER BY id DESC LIMIT 1");
  37. $maxWright = empty($maxWright)? array('cc'=>1) : $maxWright;
  38. include DedeInclude('templets/archives_add.htm');
  39. exit();
  40. } else if ($dopost == 'save') {
  41. require_once(DEDEINC.'/image.func.php');
  42. require_once(DEDEINC.'/libraries/oxwindow.class.php');
  43. $flag = isset($flags) ? join(',', $flags) : '';
  44. $notpost = isset($notpost) && $notpost == 1 ? 1 : 0;
  45. if (empty($click)) $click = ($cfg_arc_click == '-1' ? mt_rand(1000,6000) : $cfg_arc_click);
  46. if (empty($typeid2)) $typeid2 = 0;
  47. if (!isset($autokey)) $autokey = 0;
  48. if (!isset($remote)) $remote = 0;
  49. if (!isset($dellink)) $dellink = 0;
  50. if (!isset($autolitpic)) $autolitpic = 0;
  51. if (empty($click)) $click = ($cfg_arc_click == '-1' ? mt_rand(1000,6000) : $cfg_arc_click);
  52. if ($typeid == 0) {
  53. ShowMsg('请指定文档的栏目', '-1');
  54. exit();
  55. }
  56. if (empty($channelid)) {
  57. ShowMsg('文档为非指定的类型,请检查您发布文档的表单是否合法', '-1');
  58. exit();
  59. }
  60. if (!CheckChannel($typeid, $channelid)) {
  61. ShowMsg('您所选择的栏目与当前模型不相符,请重新选择', '-1');
  62. exit();
  63. }
  64. if (!TestPurview('a_New')) {
  65. CheckCatalog($typeid, "您没有操作栏目<span class='text-primary'>{$typeid}</span>权限");
  66. }
  67. //对保存的文档进行处理
  68. if (empty($writer)) $writer = $cuserLogin->getUserName();
  69. if (empty($source)) $source = '未知';
  70. $pubdate = GetMkTime($pubdate);
  71. $senddate = time();
  72. $sortrank = AddDay($pubdate, $sortup);
  73. $ismake = $ishtml == 0 ? -1 : 0;
  74. $title = preg_replace("#\"#", '"', $title);
  75. $title = cn_substrR($title, $cfg_title_maxlen);
  76. $shorttitle = cn_substrR($shorttitle, 36);
  77. $color = cn_substrR($color, 7);
  78. $writer = cn_substrR($writer, 20);
  79. $source = cn_substrR($source, 30);
  80. $description = cn_substrR($description, $cfg_auot_description);
  81. $keywords = cn_substrR($keywords, 60);
  82. $filename = trim(cn_substrR($filename, 40));
  83. $userip = GetIP();
  84. $isremote = 0;
  85. $serviterm = empty($serviterm) ? "" : $serviterm;
  86. if (!TestPurview('a_Check,a_AccCheck,a_MyCheck')) {
  87. $arcrank = -1;
  88. }
  89. $adminid = $cuserLogin->getUserID();
  90. //处理上传的缩略图
  91. if (empty($ddisremote)) {
  92. $ddisremote = 0;
  93. }
  94. $litpic = GetDDImage('none', $picname, $ddisremote);
  95. //生成文档id
  96. $arcID = GetIndexKey($arcrank, $typeid, $sortrank, $channelid, $senddate, $adminid);
  97. if (empty($arcID)) {
  98. ShowMsg("无法获得主键,因此无法进行后续操作", "-1");
  99. exit();
  100. }
  101. //分析处理附加表数据
  102. $inadd_f = $inadd_v = '';
  103. if (!empty($dede_addonfields)) {
  104. $addonfields = explode(';', $dede_addonfields);
  105. if (is_array($addonfields)) {
  106. foreach ($addonfields as $v) {
  107. if ($v == '') continue;
  108. $vs = explode(',', $v);
  109. if ($vs[1] == 'htmltext' || $vs[1] == 'textdata') {
  110. ${$vs[0]} = AnalyseHtmlBody(${$vs[0]}, $description, $litpic, $keywords, $vs[1]);
  111. } else {
  112. if (!isset(${$vs[0]})) ${$vs[0]} = '';
  113. ${$vs[0]} = GetFieldValueA(${$vs[0]}, $vs[1], $arcID);
  114. }
  115. $inadd_f .= ','.$vs[0];
  116. $inadd_v .= " ,'".${$vs[0]}."' ";
  117. }
  118. }
  119. }
  120. //处理图片文档的自定义属性
  121. if ($litpic != '' && !preg_match("#p#", $flag)) {
  122. $flag = ($flag == '' ? 'p' : $flag.',p');
  123. }
  124. if ($redirecturl != '' && !preg_match("#j#", $flag)) {
  125. $flag = ($flag == '' ? 'j' : $flag.',j');
  126. }
  127. //跳转网址的文档强制为动态
  128. if (preg_match("#j#", $flag)) $ismake = -1;
  129. //保存到主表
  130. $query = "INSERT INTO `#@__archives` (id,typeid,typeid2,sortrank,flag,ismake,channel,arcrank,click,money,title,shorttitle,color,writer,source,litpic,pubdate,senddate,mid,notpost,description,keywords,filename,dutyadmin,weight) VALUES ('$arcID','$typeid','$typeid2','$sortrank','$flag','$ismake','$channelid','$arcrank','$click','$money','$title','$shorttitle','$color','$writer','$source','$litpic','$pubdate','$senddate','$adminid','$notpost','$description','$keywords','$filename','$adminid','$weight');";
  131. if (!$dsql->ExecuteNoneQuery($query)) {
  132. $gerr = $dsql->GetError();
  133. $dsql->ExecuteNoneQuery("DELETE FROM `#@__arctiny` WHERE id='$arcID'");
  134. ShowMsg("数据保存到数据库主表`#@__archives`时出错,请检查数据库字段".str_replace('"', '', $gerr), "javascript:;");
  135. exit();
  136. }
  137. //保存到附加表
  138. $cts = $dsql->GetOne("SELECT addtable FROM `#@__channeltype` WHERE id='$channelid' ");
  139. $addtable = trim($cts['addtable']);
  140. if (!empty($addtable)) {
  141. $useip = GetIP();
  142. $query = "INSERT INTO `{$addtable}` (aid,typeid,redirecturl,userip{$inadd_f}) VALUES ('$arcID','$typeid','$redirecturl','$useip'{$inadd_v})";
  143. if (!$dsql->ExecuteNoneQuery($query)) {
  144. $gerr = $dsql->GetError();
  145. $dsql->ExecuteNoneQuery("DELETE FROM `#@__archives` WHERE id='$arcID'");
  146. $dsql->ExecuteNoneQuery("DELETE FROM `#@__arctiny` WHERE id='$arcID'");
  147. ShowMsg("数据保存到数据库附加表时出错,请检查数据库字段".str_replace('"', '', $gerr), "javascript:;");
  148. exit();
  149. }
  150. }
  151. //生成网页
  152. InsertTags($tags, $arcID);
  153. $artUrl = MakeArt($arcID, true, true, $isremote);
  154. if ($artUrl == '') {
  155. $artUrl = $cfg_phpurl."/view.php?aid=$arcID";
  156. }
  157. ClearMyAddon($arcID, $title);
  158. //自动更新关联文档
  159. if (is_array($automake)) {
  160. foreach ($automake as $key => $value) {
  161. if (isset(${$key}) && !empty(${$key})) {
  162. $ids = explode(",", ${$key});
  163. foreach ($ids as $id) {
  164. MakeArt($id, true, true, $isremote);
  165. }
  166. }
  167. }
  168. }
  169. //返回成功信息
  170. $msg = "请选择您的后续操作:<a href='archives_add.php?cid=$typeid' class='btn btn-success btn-sm'>发布自定义文档</a><a href='archives_do.php?aid=".$arcID."&dopost=editArchives' class='btn btn-success btn-sm'>修改自定义文档</a><a href='$artUrl' target='_blank' class='btn btn-success btn-sm'>浏览自定义文档</a><a href='catalog_do.php?cid=$typeid&dopost=listArchives' class='btn btn-success btn-sm'>管理自定义文档</a>$backurl";
  171. $msg = "<div>{$msg}</div>".GetUpdateTest();
  172. $wintitle = '成功发布自定义文档';
  173. $wecome_info = '文档管理::发布自定义文档';
  174. $win = new OxWindow();
  175. $win->AddTitle('成功发布自定义文档:');
  176. $win->AddMsgItem($msg);
  177. $winform = $win->GetWindow('hand', false);
  178. $win->Display();
  179. }
  180. ?>