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

249 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($formhtml)) $formhtml = 0;
  49. if (!isset($formzip)) $formzip = 0;
  50. if (!isset($ddisfirst)) $ddisfirst = 0;
  51. if (!isset($albums)) $albums = "";
  52. if (!isset($delzip)) $delzip = 0;
  53. if (empty($click)) $click = ($cfg_arc_click == '-1' ? mt_rand(1000,6000) : $cfg_arc_click);
  54. if ($typeid == 0) {
  55. ShowMsg("请指定文档的栏目", "-1");
  56. exit();
  57. }
  58. if (empty($channelid)) {
  59. ShowMsg("文档为非指定的类型,请检查您发布文档的表单是否合法", "-1");
  60. exit();
  61. }
  62. if (!CheckChannel($typeid, $channelid)) {
  63. ShowMsg("您所选择的栏目与当前模型不相符,请重新选择", "-1");
  64. exit();
  65. }
  66. if (!TestPurview('a_New')) {
  67. CheckCatalog($typeid, "您没有操作栏目<span class='text-primary'>{$typeid}</span>权限");
  68. }
  69. //对保存的文档进行处理
  70. if (empty($writer)) $writer = $cuserLogin->getUserName();
  71. if (empty($source)) $source = '未知';
  72. $pubdate = GetMkTime($pubdate);
  73. $senddate = time();
  74. $sortrank = AddDay($pubdate, $sortup);
  75. $ismake = $ishtml == 0 ? -1 : 0;
  76. $title = preg_replace("#\"#", '"', $title);
  77. $title = cn_substrR($title, $cfg_title_maxlen);
  78. $shorttitle = cn_substrR($shorttitle, 36);
  79. $color = cn_substrR($color, 7);
  80. $writer = cn_substrR($writer, 20);
  81. $source = cn_substrR($source, 30);
  82. $description = cn_substrR($description, $cfg_auot_description);
  83. $keywords = cn_substrR($keywords, 60);
  84. $filename = trim(cn_substrR($filename, 40));
  85. $userip = GetIP();
  86. $isremote = 0;
  87. $serviterm = empty($serviterm) ? "" : $serviterm;
  88. if (!TestPurview('a_Check,a_AccCheck,a_MyCheck')) {
  89. $arcrank = -1;
  90. }
  91. $adminid = $cuserLogin->getUserID();
  92. //处理上传的缩略图
  93. if (empty($ddisremote)) $ddisremote = 0;
  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. $imgurls = "{dede:pagestyle maxwidth='$maxwidth' pagepicnum='$pagepicnum' ddmaxwidth='$ddmaxwidth' row='$row' col='$col' value='$pagestyle'/}\r\n";
  102. $hasone = FALSE;
  103. //处理并保存从网上复制的图片
  104. if ($formhtml == 1) {
  105. $imagebody = stripslashes($imagebody);
  106. $imgurls .= GetCurContentAlbum($imagebody, $copysource, $litpicname);
  107. if ($ddisfirst == 1 && $litpic == '' && !empty($litpicname)) {
  108. $litpic = $litpicname;
  109. $hasone = TRUE;
  110. }
  111. }
  112. //处理从ZIP中解压的图片
  113. if ($formzip == 1) {
  114. include_once(DEDEADMIN."/file_class.php");
  115. $zipfile = $cfg_basedir.str_replace($cfg_mainsite, '', $zipfile);
  116. $tmpzipdir = DEDEDATA.'/ziptmp/'.cn_substr(md5(ExecTime()), 16);
  117. $ntime = time();
  118. }
  119. if ($albums !== "") {
  120. $albumsArr = json_decode(stripslashes($albums), true);
  121. for ($i = 0; $i <= count($albumsArr) - 1; $i++) {
  122. $album = $albumsArr[$i];
  123. if (strpos($data[0], "data:image") > 0) {
  124. $data = explode(',', $album['img']);
  125. $ext = ".png";
  126. if (strpos($data[0], "data:image/jpeg") === 0){
  127. $ext = ".jpg";
  128. } elseif (strpos($data[0], "data:image/gif") === 0) {
  129. $ext = ".gif";
  130. } elseif (strpos($data[0], "data:image/webp") === 0) {
  131. $ext = ".webp";
  132. } elseif (strpos($data[0], "data:image/bmp") === 0) {
  133. $ext = ".bmp";
  134. }
  135. $ntime = time();
  136. $savepath = $cfg_image_dir.'/'.MyDate($cfg_addon_savetype, $ntime);
  137. CreateDir($savepath);
  138. $fullUrl = $savepath.'/'.dd2char(MyDate('mdHis', $ntime).$cuserLogin->getUserID().mt_rand(1000, 9999));
  139. $fullUrl = $fullUrl.$ext;
  140. file_put_contents($cfg_basedir.$fullUrl, base64_decode($data[1]));
  141. $info = '';
  142. $imginfos = GetImageSize($cfg_basedir.$fullUrl, $info);
  143. $v = $fullUrl;
  144. } else {
  145. $v = $album['img'];
  146. $info = '';
  147. $imginfos = GetImageSize($cfg_basedir.$v, $info);
  148. }
  149. $imginfo = !empty($album['txt']) ? $album['txt'] : '';
  150. $imgurls .= "{dede:img ddimg='$v' text='$imginfo' width='".$imginfos[0]."' height='".$imginfos[1]."'} $v {/dede:img}\r\n";
  151. }
  152. }
  153. $imgurls = addslashes($imgurls);
  154. //处理body字段自动摘要、自动提取缩略图等
  155. $body = AnalyseHtmlBody($body, $description, $litpic, $keywords, 'htmltext');
  156. //分析处理附加表数据
  157. $inadd_f = '';
  158. $inadd_v = '';
  159. if (!empty($dede_addonfields)) {
  160. $addonfields = explode(';', $dede_addonfields);
  161. $inadd_f = '';
  162. $inadd_v = '';
  163. if (is_array($addonfields)) {
  164. foreach ($addonfields as $v) {
  165. if ($v == '') {
  166. continue;
  167. }
  168. $vs = explode(',', $v);
  169. if (!isset(${$vs[0]})) {
  170. ${$vs[0]} = '';
  171. } else if ($vs[1] == 'htmltext' || $vs[1] == 'textdata') //网页文本特殊处理
  172. {
  173. ${$vs[0]} = AnalyseHtmlBody(${$vs[0]}, $description, $litpic, $keywords, $vs[1]);
  174. } else {
  175. if (!isset(${$vs[0]})) {
  176. ${$vs[0]} = '';
  177. }
  178. ${$vs[0]} = GetFieldValueA(${$vs[0]}, $vs[1], $arcID);
  179. }
  180. $inadd_f .= ','.$vs[0];
  181. $inadd_v .= " ,'".${$vs[0]}."' ";
  182. }
  183. }
  184. }
  185. //处理图片文档的自定义属性
  186. if ($litpic != '' && !preg_match("#p#", $flag)) {
  187. $flag = ($flag == '' ? 'p' : $flag.',p');
  188. }
  189. if ($redirecturl != '' && !preg_match("#j#", $flag)) {
  190. $flag = ($flag == '' ? 'j' : $flag.',j');
  191. }
  192. //跳转网址的文档强制为动态
  193. if (preg_match("#j#", $flag)) $ismake = -1;
  194. //加入主文档表
  195. $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'); ";
  196. if (!$dsql->ExecuteNoneQuery($query)) {
  197. $gerr = $dsql->GetError();
  198. $dsql->ExecuteNoneQuery(" DELETE FROM `#@__arctiny` WHERE id='$arcID' ");
  199. ShowMsg("数据保存到数据库主表`#@__archives`时出错,请检查数据库字段".str_replace('"', '', $gerr), "javascript:;");
  200. exit();
  201. }
  202. //加入附加表
  203. $cts = $dsql->GetOne("SELECT addtable FROM `#@__channeltype` WHERE id='$channelid' ");
  204. $addtable = trim($cts['addtable']);
  205. if (empty($addtable)) {
  206. $dsql->ExecuteNoneQuery("DELETE FROM `#@__archives` WHERE id='$arcID'");
  207. $dsql->ExecuteNoneQuery("DELETE FROM `#@__arctiny` WHERE id='$arcID'");
  208. ShowMsg("没找到当前模型<span class='text-primary'>{$channelid}</span>主表信息,无法完成操作", "javascript:;");
  209. exit();
  210. }
  211. $useip = GetIP();
  212. $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}); ";
  213. if (!$dsql->ExecuteNoneQuery($query)) {
  214. $gerr = $dsql->GetError();
  215. $dsql->ExecuteNoneQuery("DELETE FROM `#@__archives` WHERE id='$arcID'");
  216. $dsql->ExecuteNoneQuery("DELETE FROM `#@__arctiny` WHERE id='$arcID'");
  217. ShowMsg("数据保存到数据库附加表时出错,请检查数据库字段".str_replace('"', '', $gerr), "javascript:;");
  218. exit();
  219. }
  220. //生成网页
  221. InsertTags($tags, $arcID);
  222. $artUrl = MakeArt($arcID, TRUE, TRUE, $isremote);
  223. if ($artUrl == '') {
  224. $artUrl = $cfg_phpurl."/view.php?aid=$arcID";
  225. }
  226. ClearMyAddon($arcID, $title);
  227. //自动更新关联文档
  228. if (is_array($automake)) {
  229. foreach ($automake as $key => $value) {
  230. if (isset(${$key}) && !empty(${$key})) {
  231. $ids = explode(",", ${$key});
  232. foreach ($ids as $id) {
  233. MakeArt($id, true, true, $isremote);
  234. }
  235. }
  236. }
  237. }
  238. //返回成功信息
  239. $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";
  240. $msg = "<div>{$msg}</div>".GetUpdateTest();
  241. $wintitle = "成功发布图片文档";
  242. $wecome_info = "文档管理::发布图片文档";
  243. $win = new OxWindow();
  244. $win->AddTitle("成功发布图片文档");
  245. $win->AddMsgItem($msg);
  246. $winform = $win->GetWindow("hand", FALSE);
  247. $win->Display();
  248. }
  249. ?>