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

240 lines
11KB

  1. <?php
  2. /**
  3. * 发布图片模型
  4. *
  5. * @version $id:album_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) $channelid = 2;
  28. }
  29. //获得栏目模型信息
  30. $cInfos = $dsql->GetOne("SELECT * FROM `#@__channeltype` WHERE id='$channelid' ");
  31. $channelid = $cInfos['id'];
  32. //获取文档最大id+1以确定当前权重
  33. $maxWright = $dsql->GetOne("SELECT id+1 AS cc FROM `#@__archives` ORDER BY id DESC LIMIT 1");
  34. $maxWright = empty($maxWright)? array('cc'=>1) : $maxWright;
  35. include DedeInclude("templets/album_add.htm");
  36. exit();
  37. } else if ($dopost == 'save') {
  38. require_once(DEDEINC.'/image.func.php');
  39. require_once(DEDEINC.'/libraries/oxwindow.class.php');
  40. $flag = isset($flags) ? join(',', $flags) : '';
  41. $notpost = isset($notpost) && $notpost == 1 ? 1 : 0;
  42. if (empty($click)) $click = ($cfg_arc_click == '-1' ? mt_rand(1000,6000) : $cfg_arc_click);
  43. if (!isset($typeid2)) $typeid2 = 0;
  44. if (!isset($autokey)) $autokey = 0;
  45. if (!isset($remote)) $remote = 0;
  46. if (!isset($dellink)) $dellink = 0;
  47. if (!isset($autolitpic)) $autolitpic = 0;
  48. if (!isset($ddisfirst)) $ddisfirst = 0;
  49. if (!isset($albums)) $albums = "";
  50. if (!isset($delzip)) $delzip = 0;
  51. if (empty($click)) $click = ($cfg_arc_click == '-1' ? mt_rand(1000,6000) : $cfg_arc_click);
  52. if (trim($title) == '') {
  53. ShowMsg("文档标题不能为空", "-1");
  54. exit();
  55. }
  56. if (empty($typeid)) {
  57. ShowMsg("请选择文档栏目", "-1");
  58. exit();
  59. }
  60. if (empty($channelid)) {
  61. ShowMsg("文档为非指定类型,请检查您发布文档是否正确", "-1");
  62. exit();
  63. }
  64. if (!CheckChannel($typeid, $channelid)) {
  65. ShowMsg("您所选择的栏目与当前模型不相符,请重新选择", "-1");
  66. exit();
  67. }
  68. if (!TestPurview('a_New')) {
  69. CheckCatalog($typeid, "您没有操作栏目<span class='text-primary'>{$typeid}</span>权限");
  70. }
  71. //对保存的文档进行处理
  72. if (empty($writer)) $writer = $cuserLogin->getUserName();
  73. if (empty($source)) $source = '未知';
  74. $pubdate = GetMkTime($pubdate);
  75. $senddate = time();
  76. $sortrank = AddDay($pubdate, $sortup);
  77. $ismake = $ishtml == 0 ? -1 : 0;
  78. $title = preg_replace("#\"#", '"', $title);
  79. $title = cn_substrR($title, $cfg_title_maxlen);
  80. $shorttitle = cn_substrR($shorttitle, 36);
  81. $color = cn_substrR($color, 7);
  82. $writer = cn_substrR($writer, 20);
  83. $source = cn_substrR($source, 30);
  84. $description = cn_substrR($description, $cfg_auot_description);
  85. $keywords = cn_substrR($keywords, 60);
  86. $filename = trim(cn_substrR($filename, 40));
  87. $userip = GetIP();
  88. $isremote = 0;
  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)) $ddisremote = 0;
  96. $litpic = GetDDImage('none', $picname, $ddisremote);
  97. //生成文档id
  98. $arcID = GetIndexKey($arcrank, $typeid, $sortrank, $channelid, $senddate, $adminid);
  99. if (empty($arcID)) {
  100. ShowMsg("获取主键失败,无法进行后续操作", "-1");
  101. exit();
  102. }
  103. $imgurls = "{dede:pagestyle maxwidth='$maxwidth' pagepicnum='$pagepicnum' ddmaxwidth='$ddmaxwidth' row='$row' col='$col' value='$pagestyle'/}\r\n";
  104. $hasone = FALSE;
  105. if ($albums !== "") {
  106. $albumsArr = json_decode(stripslashes($albums), true);
  107. for ($i = 0; $i <= count($albumsArr) - 1; $i++) {
  108. $album = $albumsArr[$i];
  109. if (strpos($data[0], "data:image") > 0) {
  110. $data = explode(',', $album['img']);
  111. $ext = ".png";
  112. if (strpos($data[0], "data:image/jpeg") === 0){
  113. $ext = ".jpg";
  114. } elseif (strpos($data[0], "data:image/gif") === 0) {
  115. $ext = ".gif";
  116. } elseif (strpos($data[0], "data:image/webp") === 0) {
  117. $ext = ".webp";
  118. } elseif (strpos($data[0], "data:image/bmp") === 0) {
  119. $ext = ".bmp";
  120. }
  121. $ntime = time();
  122. $savepath = $cfg_image_dir.'/'.MyDate($cfg_addon_savetype, $ntime);
  123. CreateDir($savepath);
  124. $fullUrl = $savepath.'/'.dd2char(MyDate('mdHis', $ntime).$cuserLogin->getUserID().mt_rand(1000, 9999));
  125. $fullUrl = $fullUrl.$ext;
  126. file_put_contents($cfg_basedir.$fullUrl, base64_decode($data[1]));
  127. $info = '';
  128. $imginfos = GetImageSize($cfg_basedir.$fullUrl, $info);
  129. $v = $fullUrl;
  130. } else {
  131. $v = $album['img'];
  132. $info = '';
  133. $imginfos = GetImageSize($cfg_basedir.$v, $info);
  134. }
  135. if ($ddisfirst == 1) {
  136. $litpic = $v;
  137. }
  138. $imginfo = !empty($album['txt']) ? $album['txt'] : '';
  139. $imgurls .= "{dede:img ddimg='$v' text='$imginfo' width='".$imginfos[0]."' height='".$imginfos[1]."'} $v {/dede:img}\r\n";
  140. }
  141. }
  142. $imgurls = addslashes($imgurls);
  143. //处理body字段自动摘要、自动提取缩略图等
  144. $body = AnalyseHtmlBody($body, $description, $litpic, $keywords, 'htmltext');
  145. //分析处理附加表数据
  146. $inadd_f = '';
  147. $inadd_v = '';
  148. if (!empty($dede_addonfields)) {
  149. $addonfields = explode(';', $dede_addonfields);
  150. $inadd_f = '';
  151. $inadd_v = '';
  152. if (is_array($addonfields)) {
  153. foreach ($addonfields as $v) {
  154. if ($v == '') {
  155. continue;
  156. }
  157. $vs = explode(',', $v);
  158. if (!isset(${$vs[0]})) {
  159. ${$vs[0]} = '';
  160. } else if ($vs[1] == 'htmltext' || $vs[1] == 'textdata') //网页文本特殊处理
  161. {
  162. ${$vs[0]} = AnalyseHtmlBody(${$vs[0]}, $description, $litpic, $keywords, $vs[1]);
  163. } else {
  164. if (!isset(${$vs[0]})) {
  165. ${$vs[0]} = '';
  166. }
  167. ${$vs[0]} = GetFieldValueA(${$vs[0]}, $vs[1], $arcID);
  168. }
  169. $inadd_f .= ','.$vs[0];
  170. $inadd_v .= " ,'".${$vs[0]}."' ";
  171. }
  172. }
  173. }
  174. //处理图片文档的自定义属性
  175. if ($litpic != '' && !preg_match("#p#", $flag)) {
  176. $flag = ($flag == '' ? 'p' : $flag.',p');
  177. }
  178. if ($redirecturl != '' && !preg_match("#j#", $flag)) {
  179. $flag = ($flag == '' ? 'j' : $flag.',j');
  180. }
  181. //跳转网址的文档强制为动态
  182. if (preg_match("#j#", $flag)) $ismake = -1;
  183. //加入主文档表
  184. $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'); ";
  185. if (!$dsql->ExecuteNoneQuery($query)) {
  186. $gerr = $dsql->GetError();
  187. $dsql->ExecuteNoneQuery(" DELETE FROM `#@__arctiny` WHERE id='$arcID' ");
  188. ShowMsg("数据保存到数据库文档主表出错,请检查数据库字段".str_replace('"', '', $gerr), "javascript:;");
  189. exit();
  190. }
  191. //加入附加表
  192. $cts = $dsql->GetOne("SELECT addtable FROM `#@__channeltype` WHERE id='$channelid' ");
  193. $addtable = trim($cts['addtable']);
  194. if (empty($addtable)) {
  195. $dsql->ExecuteNoneQuery("DELETE FROM `#@__archives` WHERE id='$arcID'");
  196. $dsql->ExecuteNoneQuery("DELETE FROM `#@__arctiny` WHERE id='$arcID'");
  197. ShowMsg("没找到模型<span class='text-primary'>{$channelid}</span>主表信息,无法完成操作", "javascript:;");
  198. exit();
  199. }
  200. $useip = GetIP();
  201. $query = "INSERT INTO `$addtable` (aid,typeid,redirecturl,userip,pagestyle,maxwidth,imgurls,`row`,col,isrm,ddmaxwidth,pagepicnum,body{$inadd_f}) VALUES ('$arcID','$typeid','$redirecturl','$useip','$pagestyle','$maxwidth','$imgurls','$row','$col','$isrm','$ddmaxwidth','$pagepicnum','$body'{$inadd_v}); ";
  202. if (!$dsql->ExecuteNoneQuery($query)) {
  203. $gerr = $dsql->GetError();
  204. $dsql->ExecuteNoneQuery("DELETE FROM `#@__archives` WHERE id='$arcID'");
  205. $dsql->ExecuteNoneQuery("DELETE FROM `#@__arctiny` WHERE id='$arcID'");
  206. ShowMsg("数据保存到数据库附加表出错,请检查数据库字段".str_replace('"', '', $gerr), "javascript:;");
  207. exit();
  208. }
  209. //生成网页
  210. InsertTags($tags, $arcID);
  211. $artUrl = MakeArt($arcID, TRUE, TRUE, $isremote);
  212. if ($artUrl == '') {
  213. $artUrl = $cfg_phpurl."/view.php?aid=$arcID";
  214. }
  215. ClearMyAddon($arcID, $title);
  216. //自动更新关联文档
  217. if (is_array($automake)) {
  218. foreach ($automake as $key => $value) {
  219. if (isset(${$key}) && !empty(${$key})) {
  220. $ids = explode(",", ${$key});
  221. foreach ($ids as $id) {
  222. MakeArt($id, true, true, $isremote);
  223. }
  224. }
  225. }
  226. }
  227. //返回成功信息
  228. $msg = "<tr>
  229. <td bgcolor='#f5f5f5' align='center'><a href='album_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</td>
  230. </tr>";
  231. $msg = "{$msg}".GetUpdateTest();
  232. $wintitle = "成功发布图片文档";
  233. $wecome_info = "文档管理 - 发布图片文档";
  234. $win = new OxWindow();
  235. $win->AddTitle("成功发布图片文档");
  236. $win->AddMsgItem($msg);
  237. $winform = $win->GetWindow("hand", FALSE);
  238. $win->Display();
  239. }
  240. ?>