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

280 lines
12KB

  1. <?php
  2. /**
  3. * 修改图片模型
  4. *
  5. * @version $id:album_edit.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_Edit,a_AccEdit,a_MyEdit');
  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(DEDEADMIN."/inc/inc_catalog_options.php");
  18. require_once(DEDEINC."/dedetag.class.php");
  19. ClearMyAddon();
  20. $aid = intval($aid);
  21. //读取归档信息
  22. $arcQuery = "SELECT ch.typename as channelname,ar.membername as rankname,arc.* FROM `#@__archives` arc LEFT JOIN `#@__channeltype` ch ON ch.id=arc.channel LEFT JOIN `#@__arcrank` ar ON ar.`rank`=arc.arcrank WHERE arc.id='$aid' ";
  23. $arcRow = $dsql->GetOne($arcQuery);
  24. if (!is_array($arcRow)) {
  25. ShowMsg("读取文档信息出错", "-1");
  26. exit();
  27. }
  28. $query = "SELECT * FROM `#@__channeltype` WHERE id='".$arcRow['channel']."'";
  29. $cInfos = $dsql->GetOne($query);
  30. if (!is_array($cInfos)) {
  31. ShowMsg("读取栏目信息出错", "javascript:;");
  32. exit();
  33. }
  34. $addtable = $cInfos['addtable'];
  35. $addRow = $dsql->GetOne("SELECT * FROM `$addtable` WHERE aid='$aid'");
  36. $channelid = $arcRow['channel'];
  37. $imgurls = $addRow["imgurls"];
  38. $maxwidth = $addRow["maxwidth"];
  39. $pagestyle = $addRow["pagestyle"];
  40. $irow = $addRow["row"];
  41. $icol = $addRow["col"];
  42. $isrm = $addRow["isrm"];
  43. $body = $addRow["body"];
  44. $ddmaxwidth = $addRow["ddmaxwidth"];
  45. $pagepicnum = $addRow["pagepicnum"];
  46. $tags = GetTags($aid);
  47. $arcRow = XSSClean($arcRow);
  48. $addRow = XSSClean($addRow);
  49. include DedeInclude("templets/album_edit.htm");
  50. exit();
  51. } else if ($dopost == 'save') {
  52. require_once(DEDEINC.'/image.func.php');
  53. require_once(DEDEINC.'/libraries/oxwindow.class.php');
  54. $flag = isset($flags) ? join(',', $flags) : '';
  55. $notpost = isset($notpost) && $notpost == 1 ? 1 : 0;
  56. if (empty($typeid2)) $typeid2 = 0;
  57. if (!isset($autokey)) $autokey = 0;
  58. if (!isset($remote)) $remote = 0;
  59. if (!isset($dellink)) $dellink = 0;
  60. if (!isset($autolitpic)) $autolitpic = 0;
  61. if (!isset($albums)) $albums = '';
  62. if (!isset($formzip)) $formzip = 0;
  63. if (!isset($ddisfirst)) $ddisfirst = 0;
  64. if (!isset($delzip)) $delzip = 0;
  65. if (trim($title) == '') {
  66. ShowMsg("文档标题不能为空", "-1");
  67. exit();
  68. }
  69. if (empty($typeid)) {
  70. ShowMsg("请选择文档栏目", "-1");
  71. exit();
  72. }
  73. if (empty($channelid)) {
  74. ShowMsg("文档为非指定类型,请检查您发布文档是否正确", "-1");
  75. exit();
  76. }
  77. if (!CheckChannel($typeid, $channelid)) {
  78. ShowMsg("您所选择的栏目与当前模型不相符,请重新选择", "-1");
  79. exit();
  80. }
  81. if (!TestPurview('a_Edit')) {
  82. CheckCatalog($typeid, "您没有操作栏目{$typeid}文档权限");
  83. }
  84. //对保存的文档进行处理
  85. $pubdate = GetMkTime($pubdate);
  86. $senddate = GetMkTime($senddate);
  87. $sortrank = AddDay($pubdate, $sortup);
  88. $ismake = $ishtml == 0 ? -1 : 0;
  89. $title = cn_substrR($title, $cfg_title_maxlen);
  90. $shorttitle = cn_substrR($shorttitle, 255);
  91. $color = cn_substrR($color, 7);
  92. $writer = cn_substrR($writer, 255);
  93. $source = cn_substrR($source, 255);
  94. $description = cn_substrR($description, 255);
  95. $keywords = trim(cn_substrR($keywords, 255));
  96. $filename = trim(cn_substrR($filename, 50));
  97. $isremote = 0;
  98. $serviterm = empty($serviterm) ? "" : $serviterm;
  99. if (!TestPurview('a_Check,a_AccCheck,a_MyCheck')) {
  100. $arcrank = -1;
  101. }
  102. $adminid = $cuserLogin->getUserID();
  103. //处理上传的缩略图
  104. if (empty($ddisremote)) {
  105. $ddisremote = 0;
  106. }
  107. $litpic = GetDDImage('none', $picname, $ddisremote);
  108. //分析body里的文档
  109. $body = AnalyseHtmlBody($body, $description, $litpic, $keywords, 'htmltext');
  110. //处理图片文档的自定义属性
  111. if ($litpic != '' && !preg_match("#p#", $flag)) {
  112. $flag = ($flag == '' ? 'p' : $flag.',p');
  113. }
  114. if ($redirecturl != '' && !preg_match("#j#", $flag)) {
  115. $flag = ($flag == '' ? 'j' : $flag.',j');
  116. }
  117. //跳转网址的文档强制为动态
  118. if (preg_match("#j#", $flag)) $ismake = -1;
  119. //更新数据库的SQL语句
  120. $query = "
  121. UPDATE `#@__archives` SET typeid='$typeid',typeid2='$typeid2',sortrank='$sortrank',flag='$flag',click='$click',ismake='$ismake',arcrank='$arcrank',money='$money',title='$title',color='$color',source='$source',writer='$writer',litpic='$litpic',pubdate='$pubdate',senddate='$senddate',notpost='$notpost',description='$description',keywords='$keywords',shorttitle='$shorttitle',filename='$filename',dutyadmin='$adminid' WHERE id='$id'; ";
  122. if (!$dsql->ExecuteNoneQuery($query)) {
  123. ShowMsg("数据保存到数据库文档主表出错,请检查数据库字段".$dsql->GetError(), "javascript:;");
  124. exit();
  125. }
  126. $imgurls = "{dede:pagestyle maxwidth='$maxwidth' pagepicnum='$pagepicnum' ddmaxwidth='$ddmaxwidth' row='$row' col='$col' value='$pagestyle'/}\r\n";
  127. $hasone = false;
  128. //检查旧的图片是否有更新,并保存
  129. for ($i = 1; $i <= 120; $i++) {
  130. if (!isset(${'imgurl'.$i})) continue;
  131. $info = '';
  132. $iinfo = str_replace("'", "`", stripslashes(${'imgmsg'.$i}));
  133. $iurl = stripslashes(${'imgurl'.$i});
  134. $ddurl = stripslashes(${'imgddurl'.$i});
  135. if (preg_match("#swfupload#i", $ddurl)) $ddurl = '';
  136. $imgfile = $cfg_basedir.$iurl;
  137. $litimgfile = $cfg_basedir.$ddurl;
  138. //有上传文件的情况
  139. if (isset(${'imgfile'.$i}) && is_uploaded_file(${'imgfile'.$i})) {
  140. $tmpFile = ${'imgfile'.$i};
  141. //检测上传的图片,如果类型不对,保留原来图片
  142. $imginfos = @GetImageSize($tmpFile, $info);
  143. if (!is_array($imginfos)) {
  144. $imginfos = @GetImageSize($imgfile, $info);
  145. $imgurls .= "{dede:img ddimg='$ddurl' text='$iinfo' width='".$imginfos[0]."' height='".$imginfos[1]."'} $iurl {/dede:img}\r\n";
  146. continue;
  147. }
  148. $mime = get_mime_type($tmpFile);
  149. if (preg_match("#^unknow#", $mime)) {
  150. ShowMsg("系统不支持fileinfo组件,建议php.ini中开启", -1);
  151. exit;
  152. }
  153. if (!preg_match("#^image#i", $mime)) {
  154. ShowMsg("非图片格式文件,无法正常上传", -1);
  155. exit;
  156. }
  157. move_uploaded_file($tmpFile, $imgfile);
  158. $imginfos = @GetImageSize($imgfile, $info);
  159. if ($ddurl == $iurl) {
  160. $litpicname = $pagestyle > 2 ? GetImageMapDD($iurl, $cfg_ddimg_width) : $iurl;
  161. $litimgfile = $cfg_basedir.$litpicname;
  162. } else {
  163. ImageResizeNew($imgfile, $cfg_ddimg_width, $cfg_ddimg_height, $litimgfile);
  164. $litpicname = $ddurl;
  165. }
  166. $imgurls .= "{dede:img ddimg='$litpicname' text='$iinfo' width='".$imginfos[0]."' height='".$imginfos[1]."'} $iurl {/dede:img}\r\n";
  167. }
  168. //没上传图片,只修改msg信息
  169. else {
  170. $iinfo = str_replace("'", "`", stripslashes(${'imgmsg'.$i}));
  171. $iurl = stripslashes(${'imgurl'.$i});
  172. $ddurl = stripslashes(${'imgddurl'.$i});
  173. if (preg_match("#swfupload#i", $ddurl)) {
  174. $ddurl = $pagestyle > 2 ? GetImageMapDD($iurl, $cfg_ddimg_width) : $iurl;
  175. }
  176. $imginfos = @GetImageSize($imgfile, $info);
  177. $imgurls .= "{dede:img ddimg='$ddurl' text='$iinfo' width='".$imginfos[0]."' height='".$imginfos[1]."'} $iurl {/dede:img}\r\n";
  178. }
  179. }
  180. if ($albums !== "") {
  181. $albumsArr = json_decode(stripslashes($albums), true);
  182. for ($i = 0; $i <= count($albumsArr) - 1; $i++) {
  183. $album = $albumsArr[$i];
  184. if (strpos($data[0], "data:image") > 0) {
  185. $data = explode(',', $album['img']);
  186. $ext = ".png";
  187. if (strpos($data[0], "data:image/jpeg") === 0){
  188. $ext = ".jpg";
  189. } elseif (strpos($data[0], "data:image/gif") === 0) {
  190. $ext = ".gif";
  191. } elseif (strpos($data[0], "data:image/webp") === 0) {
  192. $ext = ".webp";
  193. } elseif (strpos($data[0], "data:image/bmp") === 0) {
  194. $ext = ".bmp";
  195. }
  196. $ntime = time();
  197. $savepath = $cfg_image_dir.'/'.MyDate($cfg_addon_savetype, $ntime);
  198. CreateDir($savepath);
  199. $fullUrl = $savepath.'/'.dd2char(MyDate('mdHis', $ntime).$cuserLogin->getUserID().mt_rand(1000, 9999));
  200. $fullUrl = $fullUrl.$ext;
  201. file_put_contents($cfg_basedir.$fullUrl, base64_decode($data[1]));
  202. $info = '';
  203. $imginfos = GetImageSize($cfg_basedir.$fullUrl, $info);
  204. $v = $fullUrl;
  205. } else {
  206. $v = $album['img'];
  207. $info = '';
  208. $imginfos = GetImageSize($cfg_basedir.$v, $info);
  209. }
  210. $imginfo = !empty($album['txt']) ? $album['txt'] : '';
  211. $imgurls .= "{dede:img ddimg='$v' text='$imginfo' width='".$imginfos[0]."' height='".$imginfos[1]."'} $v {/dede:img}\r\n";
  212. }
  213. }
  214. $imgurls = addslashes($imgurls);
  215. //分析处理附加表数据
  216. $inadd_f = '';
  217. $inadd_v = '';
  218. if (!empty($dede_addonfields)) {
  219. $addonfields = explode(';', $dede_addonfields);
  220. $inadd_f = '';
  221. $inadd_v = '';
  222. if (is_array($addonfields)) {
  223. foreach ($addonfields as $v) {
  224. if ($v == '') {
  225. continue;
  226. }
  227. $vs = explode(',', $v);
  228. if ($vs[1] == 'htmltext' || $vs[1] == 'textdata') //网页文本特殊处理
  229. {
  230. ${$vs[0]} = AnalyseHtmlBody(${$vs[0]}, $description, $litpic, $keywords, $vs[1]);
  231. } else {
  232. if (!isset(${$vs[0]})) {
  233. ${$vs[0]} = '';
  234. }
  235. ${$vs[0]} = GetFieldValueA(${$vs[0]}, $vs[1], $id);
  236. }
  237. $inadd_f .= ",`{$vs[0]}` = '".${$vs[0]}."'";
  238. }
  239. }
  240. }
  241. //更新附加表
  242. $cts = $dsql->GetOne("SELECT addtable FROM `#@__channeltype` WHERE id='$channelid' ");
  243. $addtable = trim($cts['addtable']);
  244. if ($addtable != '') {
  245. $useip = GetIP();
  246. $query = "UPDATE `$addtable` SET typeid='$typeid',pagestyle='$pagestyle',body='$body',maxwidth='$maxwidth',ddmaxwidth='$ddmaxwidth',pagepicnum='$pagepicnum',imgurls='$imgurls',`row`='$row',col='$col',isrm='$isrm'{$inadd_f},redirecturl='$redirecturl',userip='$useip' WHERE aid='$id'; ";
  247. if (!$dsql->ExecuteNoneQuery($query)) {
  248. ShowMsg("数据保存到数据库附加表出错,请检查数据库字段".$dsql->GetError(), "javascript:;");
  249. exit();
  250. }
  251. }
  252. //生成网页
  253. UpIndexKey($id, $arcrank, $typeid, $sortrank, $tags);
  254. $arcUrl = MakeArt($id, true, true, $isremote);
  255. if ($arcUrl == '') {
  256. $arcUrl = $cfg_phpurl."/view.php?aid=$id";
  257. }
  258. ClearMyAddon($id, $title);
  259. //自动更新关联文档
  260. if (is_array($automake)) {
  261. foreach ($automake as $key => $value) {
  262. if (isset(${$key}) && !empty(${$key})) {
  263. $ids = explode(",", ${$key});
  264. foreach ($ids as $id) {
  265. MakeArt($id, true, true, $isremote);
  266. }
  267. }
  268. }
  269. }
  270. //返回成功信息
  271. $msg = "<tr>
  272. <td align='center'><a href='$arcUrl' 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=".$id."&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>
  273. </tr>";
  274. $wintitle = "成功修改图片文档";
  275. $win = new OxWindow();
  276. $win->AddMsgItem($msg);
  277. $winform = $win->GetWindow("hand", false);
  278. $win->Display();
  279. }
  280. ?>