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

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