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

237 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 GNU GPL v2 (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($albums)) $albums = '';
  49. if (!isset($delzip)) $delzip = 0;
  50. if (empty($click)) $click = ($cfg_arc_click == '-1' ? mt_rand(1000, 6000) : $cfg_arc_click);
  51. if (trim($title) == '') {
  52. ShowMsg("文档标题不能为空", "-1");
  53. exit();
  54. }
  55. if (empty($typeid)) {
  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, 255);
  80. $color = cn_substrR($color, 7);
  81. $writer = cn_substrR($writer, 255);
  82. $source = cn_substrR($source, 255);
  83. $description = cn_substrR($description, $cfg_auot_description);
  84. $keywords = cn_substrR($keywords, 255);
  85. $filename = trim(cn_substrR($filename, 50));
  86. $userip = GetIP();
  87. $isremote = 0;
  88. $serviterm = empty($serviterm) ? "" : $serviterm;
  89. if (!TestPurview('a_Check,a_AccCheck,a_MyCheck')) {
  90. $arcrank = -1;
  91. }
  92. $adminid = $cuserLogin->getUserID();
  93. //处理上传的缩略图
  94. if (empty($ddisremote)) $ddisremote = 0;
  95. $litpic = GetDDImage('none', $picname, $ddisremote);
  96. //生成文档id
  97. $arcID = GetIndexKey($arcrank, $typeid, $sortrank, $channelid, $senddate, $adminid);
  98. if (empty($arcID)) {
  99. ShowMsg("获取主键失败,无法进行后续操作", "-1");
  100. exit();
  101. }
  102. $imgurls = "{dede:pagestyle maxwidth='$maxwidth' pagepicnum='$pagepicnum' ddmaxwidth='$ddmaxwidth' row='$row' col='$col' value='$pagestyle'/}\r\n";
  103. $hasone = FALSE;
  104. if ($albums !== "") {
  105. $albumsArr = json_decode(stripslashes($albums), true);
  106. for ($i = 0; $i <= count($albumsArr) - 1; $i++) {
  107. $album = $albumsArr[$i];
  108. if (strpos($data[0], "data:image") > 0) {
  109. $data = explode(',', $album['img']);
  110. $ext = ".png";
  111. if (strpos($data[0], "data:image/jpeg") === 0){
  112. $ext = ".jpg";
  113. } elseif (strpos($data[0], "data:image/gif") === 0) {
  114. $ext = ".gif";
  115. } elseif (strpos($data[0], "data:image/webp") === 0) {
  116. $ext = ".webp";
  117. } elseif (strpos($data[0], "data:image/bmp") === 0) {
  118. $ext = ".bmp";
  119. }
  120. $ntime = time();
  121. $savepath = $cfg_image_dir.'/'.MyDate($cfg_addon_savetype, $ntime);
  122. CreateDir($savepath);
  123. $fullUrl = $savepath.'/'.dd2char(MyDate('mdHis', $ntime).$cuserLogin->getUserID().mt_rand(1000, 9999));
  124. $fullUrl = $fullUrl.$ext;
  125. file_put_contents($cfg_basedir.$fullUrl, base64_decode($data[1]));
  126. $info = '';
  127. $imginfos = GetImageSize($cfg_basedir.$fullUrl, $info);
  128. $v = $fullUrl;
  129. } else {
  130. $v = $album['img'];
  131. $info = '';
  132. $imginfos = GetImageSize($cfg_basedir.$v, $info);
  133. }
  134. if ($autolitpic == 1 && empty($litpic)) {
  135. $litpic = $v;
  136. }
  137. $imginfo = !empty($album['txt']) ? $album['txt'] : '';
  138. $imgurls .= "{dede:img ddimg='$v' text='$imginfo' width='".$imginfos[0]."' height='".$imginfos[1]."'} $v {/dede:img}\r\n";
  139. }
  140. }
  141. $imgurls = addslashes($imgurls);
  142. //处理body字段自动摘要、自动提取缩略图等
  143. $body = AnalyseHtmlBody($body, $description, $litpic, $keywords, 'htmltext');
  144. //分析处理附加表数据
  145. $inadd_f = '';
  146. $inadd_v = '';
  147. if (!empty($dede_addonfields)) {
  148. $addonfields = explode(';', $dede_addonfields);
  149. $inadd_f = '';
  150. $inadd_v = '';
  151. if (is_array($addonfields)) {
  152. foreach ($addonfields as $v) {
  153. if ($v == '') {
  154. continue;
  155. }
  156. $vs = explode(',', $v);
  157. if (!isset(${$vs[0]})) {
  158. ${$vs[0]} = '';
  159. } else if ($vs[1] == 'htmltext' || $vs[1] == 'textdata') //网页文本特殊处理
  160. {
  161. ${$vs[0]} = AnalyseHtmlBody(${$vs[0]}, $description, $litpic, $keywords, $vs[1]);
  162. } else {
  163. if (!isset(${$vs[0]})) {
  164. ${$vs[0]} = '';
  165. }
  166. ${$vs[0]} = GetFieldValueA(${$vs[0]}, $vs[1], $arcID);
  167. }
  168. $inadd_f .= ','.$vs[0];
  169. $inadd_v .= " ,'".${$vs[0]}."' ";
  170. }
  171. }
  172. }
  173. //处理图片文档的自定义属性
  174. if ($litpic != '' && !preg_match("#p#", $flag)) {
  175. $flag = ($flag == '' ? 'p' : $flag.',p');
  176. }
  177. if ($redirecturl != '' && !preg_match("#j#", $flag)) {
  178. $flag = ($flag == '' ? 'j' : $flag.',j');
  179. }
  180. //跳转网址的文档强制为动态
  181. if (preg_match("#j#", $flag)) $ismake = -1;
  182. //加入主文档表
  183. $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'); ";
  184. if (!$dsql->ExecuteNoneQuery($query)) {
  185. $gerr = $dsql->GetError();
  186. $dsql->ExecuteNoneQuery(" DELETE FROM `#@__arctiny` WHERE id='$arcID' ");
  187. ShowMsg("数据保存到数据库文档主表出错,请检查数据库字段".str_replace('"', '', $gerr), "javascript:;");
  188. exit();
  189. }
  190. //加入附加表
  191. $cts = $dsql->GetOne("SELECT addtable FROM `#@__channeltype` WHERE id='$channelid' ");
  192. $addtable = trim($cts['addtable']);
  193. if (empty($addtable)) {
  194. $dsql->ExecuteNoneQuery("DELETE FROM `#@__archives` WHERE id='$arcID'");
  195. $dsql->ExecuteNoneQuery("DELETE FROM `#@__arctiny` WHERE id='$arcID'");
  196. ShowMsg("没找到模型{$channelid}主表信息,无法完成操作", "javascript:;");
  197. exit();
  198. }
  199. $useip = GetIP();
  200. $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}); ";
  201. if (!$dsql->ExecuteNoneQuery($query)) {
  202. $gerr = $dsql->GetError();
  203. $dsql->ExecuteNoneQuery("DELETE FROM `#@__archives` WHERE id='$arcID'");
  204. $dsql->ExecuteNoneQuery("DELETE FROM `#@__arctiny` WHERE id='$arcID'");
  205. ShowMsg("数据保存到数据库附加表出错,请检查数据库字段".str_replace('"', '', $gerr), "javascript:;");
  206. exit();
  207. }
  208. //生成网页
  209. InsertTags($tags, $arcID);
  210. $artUrl = MakeArt($arcID, TRUE, TRUE, $isremote);
  211. if ($artUrl == '') {
  212. $artUrl = $cfg_phpurl."/view.php?aid=$arcID";
  213. }
  214. ClearMyAddon($arcID, $title);
  215. //自动更新关联文档
  216. if (is_array($automake)) {
  217. foreach ($automake as $key => $value) {
  218. if (isset(${$key}) && !empty(${$key})) {
  219. $ids = explode(",", ${$key});
  220. foreach ($ids as $id) {
  221. MakeArt($id, true, true, $isremote);
  222. }
  223. }
  224. }
  225. }
  226. //返回成功信息
  227. $msg = "<tr>
  228. <td align='center'><a href='$artUrl' target='_blank' class='btn btn-success btn-sm'>浏览文档</a><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='catalog_do.php?cid=$typeid&dopost=listArchives' class='btn btn-success btn-sm'>返回文档列表</a></td>
  229. </tr>";
  230. $msg = "{$msg}".GetUpdateTest();
  231. $wintitle = "成功发布图片文档";
  232. $win = new OxWindow();
  233. $win->AddMsgItem($msg);
  234. $winform = $win->GetWindow("hand", FALSE);
  235. $win->Display();
  236. }
  237. ?>