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

239 line
11KB

  1. <?php
  2. /**
  3. * 选择图片
  4. *
  5. * @version $id:select_images.php 2022-07-01 tianya $
  6. * @package DedeBIZ.Dialog
  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. include(DEDEDATA.'/mark/inc_photowatermark_config.php');
  13. if (empty($activepath)) {
  14. $activepath = '';
  15. }
  16. if (empty($imgstick)) {
  17. $imgstick = '';
  18. }
  19. $noeditor = isset($noeditor) ? $noeditor : '';
  20. $iseditor = isset($iseditor) ? intval($iseditor) : '';
  21. $activepath = str_replace('.', '', $activepath);
  22. $activepath = preg_replace("#\/{1,}#", '/', $activepath);
  23. if (strlen($activepath) < strlen($cfg_image_dir)) {
  24. $activepath = $cfg_image_dir;
  25. }
  26. $inpath = $cfg_basedir.$activepath;
  27. $activeurl = '..'.$activepath;
  28. if (empty($f)) {
  29. $f = 'form1.picname';
  30. }
  31. $f = RemoveXSS($f);
  32. if (empty($v)) {
  33. $v = 'picview';
  34. }
  35. if (empty($comeback)) {
  36. $comeback = '';
  37. }
  38. $addparm = '';
  39. if (!empty($CKEditor)) {
  40. $addparm = '&CKEditor='.$CKEditor;
  41. $f = $CKEditor;
  42. }
  43. if (!empty($CKEditorFuncNum)) {
  44. $addparm .= '&CKEditorFuncNum='.$CKEditorFuncNum;
  45. }
  46. if (!empty($noeditor)) {
  47. $addparm .= '&noeditor=yes';
  48. }
  49. if (!empty($iseditor)) {
  50. $addparm .= '&iseditor='.$iseditor;
  51. }
  52. ?>
  53. <!DOCTYPE html>
  54. <html>
  55. <head>
  56. <meta charset="utf-8">
  57. <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
  58. <title>选择图片</title>
  59. <link rel="stylesheet" href="/static/web/css/font-awesome.min.css">
  60. <link rel="stylesheet" href="/static/web/css/bootstrap.min.css">
  61. <link rel="stylesheet" href="/static/web/css/admin.css">
  62. <script src="/static/web/js/jquery.min.js"></script>
  63. </head>
  64. <body class="body-bg">
  65. <div class="upload-bg shadow-sm">
  66. <table align="center" class="table icon">
  67. <tr>
  68. <td colspan="3">
  69. <form name="myform" action="select_images_post.php" method="POST" enctype="multipart/form-data">
  70. <?php $noeditor = !empty($noeditor) ? "<input type='hidden' name='noeditor' value='yes'>" : ''; echo $noeditor;?>
  71. <input type="hidden" name="activepath" value="<?php echo $activepath ?>">
  72. <input type="hidden" name="f" value="<?php echo $f ?>">
  73. <input type="hidden" name="v" value="<?php echo $v ?>">
  74. <input type="hidden" name="iseditor" value="<?php echo $iseditor ?>">
  75. <input type="hidden" name="imgstick" value="<?php echo $imgstick ?>">
  76. <input type="hidden" name="CKEditorFuncNum" value="<?php echo isset($CKEditorFuncNum) ? $CKEditorFuncNum : 1;?>">
  77. <input type="hidden" name="job" value="upload">
  78. <input type="file" name="imgfile" class="w-50">
  79. <label><input type="checkbox" name="needwatermark" value="1" <?php if ($photo_markup == '1') echo "checked";?>> 水印</label>
  80. <label><input type="checkbox" name="resize" value="1"> 缩小</label>
  81. <label>宽:<input type="text" name="iwidth" value="<?php echo $cfg_ddimg_width ?>" class="admin-input-xs"></label>
  82. <label>高:<input type="text" name="iheight" value="<?php echo $cfg_ddimg_height ?>" class="admin-input-xs"></label>
  83. <button type="submit" name="sb1" class="btn btn-success btn-sm">上传</button>
  84. </form>
  85. </td>
  86. </tr>
  87. <tr>
  88. <td colspan="3">点击图片预览,再点击图片关闭预览,点击文件名选择图片</td>
  89. </tr>
  90. <tr>
  91. <td width="40%">选择图片</td>
  92. <td width="26%">文件大小</td>
  93. <td>修改时间</td>
  94. </tr>
  95. <?php
  96. $dh = scandir($inpath);
  97. $ty1 = "";
  98. $ty2 = "";
  99. foreach ($dh as $file) {
  100. //计算文件大小和创建时间
  101. if ($file != "." && $file != ".." && !is_dir("$inpath/$file")) {
  102. $filesize = filesize("$inpath/$file");
  103. $filesize = $filesize / 1024;
  104. if ($filesize != "")
  105. if ($filesize < 0.1) {
  106. @list($ty1, $ty2) = explode("\.", $filesize);
  107. $filesize = $ty1.".".substr($ty2, 0, 2);
  108. } else {
  109. @list($ty1, $ty2) = explode("\.", $filesize);
  110. $filesize = $ty1.".".substr($ty2, 0, 1);
  111. }
  112. $filetime = filemtime("$inpath/$file");
  113. $filetime = MyDate("Y-m-d H:i:s", $filetime);
  114. }
  115. if ($file == ".") continue;
  116. else if ($file == "..") {
  117. if ($activepath == "") continue;
  118. $tmp = preg_replace("#[\/][^\/]*$#i", "", $activepath);
  119. $line = "<tr>
  120. <td colspan='2'><a href='select_images.php?imgstick=$imgstick&v=$v&f=$f&activepath=".urlencode($tmp).$addparm."'><img src='/static/web/img/icon_dir2.png'>上级目录</a></td>
  121. <td>当前目录:$activepath</td>
  122. </tr>";
  123. echo $line;
  124. } else if (is_dir("$inpath/$file")) {
  125. if (preg_match("#^_(.*)$#i", $file)) continue;
  126. if (preg_match("#^\.(.*)$#i", $file)) continue;
  127. $line = "<tr>
  128. <td colspan='3'><a href='select_images.php?imgstick=$imgstick&v=$v&f=$f&activepath=".urlencode("$activepath/$file").$addparm."'><img src='/static/web/img/icon_dir.png'>$file</a></td>
  129. </tr>";
  130. echo "$line";
  131. } else if (preg_match("#\.(".$cfg_imgtype.")#i", $file)) {
  132. $reurl = "$activeurl/$file";
  133. $reurl = preg_replace("#^\.\.#", "", $reurl);
  134. $reurl = $reurl;
  135. if ($file == $comeback) $lstyle = "class='text-danger'";
  136. else $lstyle = "";
  137. $line = "<tr>
  138. <td>
  139. <a href=\"$reurl\" class=\"toolimg\"><img src='$reurl' title='$file'></a>
  140. <a href=\"javascript:;\" onclick=\"ReturnImg('$reurl');\" $lstyle>$file</a>
  141. </td>
  142. <td>$filesize KB</td>
  143. <td>$filetime</td>
  144. </tr>";
  145. echo "$line";
  146. } else if (preg_match("#\.(jpg)#i", $file)) {
  147. $reurl = "$activeurl/$file";
  148. $reurl = preg_replace("#^\.\.#", "", $reurl);
  149. $reurl = $reurl;
  150. if ($file == $comeback) $lstyle = "class='text-danger'";
  151. else $lstyle = "";
  152. $line = "<tr>
  153. <td>
  154. <a href=\"$reurl\" class=\"toolimg\"><img src='$reurl' title='$file'></a>
  155. <a href=\"javascript:;\" onclick=\"ReturnImg('$reurl');\" $lstyle>$file</a>
  156. </td>
  157. <td>$filesize KB</td>
  158. <td>$filetime</td>
  159. </tr>";
  160. echo "$line";
  161. }
  162. }//End Loop
  163. ?>
  164. </tr>
  165. </table>
  166. </div>
  167. <script>
  168. function nullLink() {
  169. return;
  170. }
  171. function TNav() {
  172. if (window.navigator.userAgent.indexOf("MSIE") >= 1) return 'IE';
  173. else if (window.navigator.userAgent.indexOf("Firefox") >= 1) return 'FF';
  174. else return "OT";
  175. }
  176. //获取地址参数
  177. function getUrlParam(paramName) {
  178. var reParam = new RegExp('(?:[\?&]|&amp;)' + paramName + '=([^&]+)', 'i');
  179. var match = window.location.search.match(reParam);
  180. return (match && match.length > 1) ? match[1] : '';
  181. }
  182. function ReturnImg(reimg) {
  183. var funcNum = getUrlParam('CKEditorFuncNum');
  184. var iseditor = parseInt(getUrlParam('iseditor'));
  185. if (funcNum > 1) {
  186. var fileUrl = reimg;
  187. window.opener.CKEDITOR.tools.callFunction(funcNum, fileUrl);
  188. }
  189. if (iseditor==1) {
  190. let addonHTML = `<img src='${reimg}'>`;
  191. window.opener.CKEDITOR.instances["<?php echo $f ?>"].insertHtml(addonHTML);
  192. } else {
  193. if (window.opener.document.<?php echo $f ?> != null) {
  194. window.opener.document.<?php echo $f ?>.value = reimg;
  195. if (window.opener.document.getElementById('div<?php echo $v ?>')) {
  196. if (TNav() == 'IE') {
  197. //window.opener.document.getElementById('div<?php echo $v ?>').filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = reimg;
  198. window.opener.document.getElementById('div<?php echo $v ?>').src = reimg;
  199. window.opener.document.getElementById('div<?php echo $v ?>').style.width = '150px';
  200. window.opener.document.getElementById('div<?php echo $v ?>').style.height = '100px';
  201. } else
  202. window.opener.document.getElementById('div<?php echo $v ?>').style.backgroundImage = "url(" + reimg + ")";
  203. } else if (window.opener.document.getElementById('<?php echo $v ?>')) {
  204. window.opener.document.getElementById('<?php echo $v ?>').src = reimg;
  205. }
  206. //适配新的缩略图
  207. if (window.opener.document.getElementById('litPic')) {
  208. window.opener.document.getElementById('litPic').src = reimg;
  209. }
  210. if (document.all) window.opener = true;
  211. } else if (typeof window.opener.CKEDITOR.instances["<?php echo $f ?>"] !== "undefined") {
  212. let addonHTML = `<img src='${reimg}'>`;
  213. window.opener.CKEDITOR.instances["<?php echo $f ?>"].insertHtml(addonHTML);
  214. }
  215. }
  216. window.close();
  217. }
  218. $(function() {
  219. var x = 10;
  220. var y = 20;
  221. $("a.toolimg").mouseover(function(e) {
  222. var toolimg = "<div id='toolimg'><img src='" + this.href + "'></div>";
  223. $("body").append(toolimg);
  224. $("#toolimg").css({
  225. "top": (e.pageY + y) + "px",
  226. "left": (e.pageX + x) + "px"
  227. }).show("fast");
  228. }).mouseout(function() {
  229. $("#toolimg").remove();
  230. }).mousemove(function(e) {
  231. $("#toolimg").css({
  232. "top": (e.pageY + y) + "px",
  233. "left": (e.pageX + x) + "px"
  234. });
  235. });
  236. });
  237. </script>
  238. </body>
  239. </html>