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

181 lines
8.2KB

  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 name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
  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="p-3">
  65. <div class="card shadow-sm mb-3">
  66. <div class="card-body">
  67. <form name="myform" action="select_images_post.php" method="POST" enctype="multipart/form-data">
  68. <?php $noeditor = !empty($noeditor) ? "<input type='hidden' name='noeditor' value='yes'>" : ''; echo $noeditor;?>
  69. <input type="hidden" name="activepath" value="<?php echo $activepath ?>">
  70. <input type="hidden" name="f" value="<?php echo $f ?>">
  71. <input type="hidden" name="v" value="<?php echo $v ?>">
  72. <input type="hidden" name="iseditor" value="<?php echo $iseditor ?>">
  73. <input type="hidden" name="imgstick" value="<?php echo $imgstick ?>">
  74. <input type="hidden" name="CKEditorFuncNum" value="<?php echo isset($CKEditorFuncNum) ? $CKEditorFuncNum : 1;?>">
  75. <input type="hidden" name="job" value="upload">
  76. <input type="file" name="imgfile">
  77. <label><input type="checkbox" name="needwatermark" value="1" <?php if ($photo_markup == '1') echo 'checked';?>> 水印</label>
  78. <label><input type="checkbox" name="resize" value="1"> 缩小</label>
  79. <label><input type="text" name="iwidth" value="<?php echo $cfg_ddimg_width ?>" class="admin-input-xs"> 宽</label>
  80. <label><input type="text" name="iheight" value="<?php echo $cfg_ddimg_height ?>" class="admin-input-xs"> 高</label>
  81. <button type="submit" class="btn btn-success btn-sm">上传</button>
  82. </form>
  83. </div>
  84. </div>
  85. <div class="card shadow-sm">
  86. <div class="card-header">选择图片</div>
  87. <div class="card-body opt">
  88. <?php
  89. $dh = scandir($inpath);
  90. foreach ($dh as $file) {
  91. if ($file == ".") continue;
  92. else if ($file == "..") {
  93. if ($activepath == "") continue;
  94. $tmp = preg_replace("#[\/][^\/]*$#i", "", $activepath);
  95. $line = "<div class='d-flex justify-content-between mb-3'>
  96. <a href='select_images.php?imgstick=$imgstick&v=$v&f=$f&activepath=".urlencode($tmp).$addparm."' class='btn btn-success btn-sm'>返回上级</a>
  97. <span>当前目录:$activepath</span>
  98. </div>";
  99. echo $line;
  100. } else if (is_dir("$inpath/$file")) {
  101. if (preg_match("#^_(.*)$#i", $file)) continue;
  102. if (preg_match("#^\.(.*)$#i", $file)) continue;
  103. $line = "<div class='list'>
  104. <a href='select_images.php?imgstick=$imgstick&v=$v&f=$f&activepath=".urlencode("$activepath/$file").$addparm."'>
  105. <img src='/static/web/img/icon_dir.png'>
  106. <span>$file</span>
  107. </a>
  108. </div>";
  109. echo "$line";
  110. } else if (preg_match("#\.(".$cfg_imgtype.")#i", $file)) {
  111. $reurl = "$activeurl/$file";
  112. $reurl = preg_replace("#^\.\.#", "", $reurl);
  113. $reurl = $reurl;
  114. if ($file == $comeback) $lstyle = "class='text-danger'";
  115. else $lstyle = '';
  116. $line = "<div class='list'>
  117. <a href='$reurl' onclick=\"ReturnImg('$reurl');\" $lstyle>
  118. <img src='$reurl' title='$file'>
  119. <span>$file</span>
  120. </a>
  121. </div>";
  122. echo "$line";
  123. } else if (preg_match("#\.(jpg)#i", $file)) {
  124. $reurl = "$activeurl/$file";
  125. $reurl = preg_replace("#^\.\.#", "", $reurl);
  126. $reurl = $reurl;
  127. if ($file == $comeback) $lstyle = "class='text-danger'";
  128. else $lstyle = '';
  129. $line = "<div class='list'>
  130. <a href='$reurl' onclick=\"ReturnImg('$reurl');\" $lstyle>
  131. <img src='$reurl' title='$file'>
  132. <span>$file</span>
  133. </a>
  134. </div>";
  135. echo "$line";
  136. }
  137. }
  138. ?>
  139. </div>
  140. </div>
  141. <script>
  142. function nullLink() {
  143. return;
  144. }
  145. //获取地址参数
  146. function getUrlParam(paramName) {
  147. var reParam = new RegExp('(?:[\?&]|&amp;)' + paramName + '=([^&]+)', 'i');
  148. var match = window.location.search.match(reParam);
  149. return (match && match.length > 1) ? match[1] : '';
  150. }
  151. function ReturnImg(reimg) {
  152. var funcNum = getUrlParam('CKEditorFuncNum');
  153. var iseditor = parseInt(getUrlParam('iseditor'));
  154. if (funcNum > 1) {
  155. var fileUrl = reimg;
  156. window.opener.CKEDITOR.tools.callFunction(funcNum, fileUrl);
  157. }
  158. if (iseditor==1) {
  159. let addonHTML = `<img src='${reimg}'>`;
  160. window.opener.CKEDITOR.instances["<?php echo $f ?>"].insertHtml(addonHTML);
  161. } else {
  162. if (window.opener.document.<?php echo $f ?> != null) {
  163. window.opener.document.<?php echo $f ?>.value = reimg;
  164. if (window.opener.document.getElementById('div<?php echo $v ?>')) {
  165. window.opener.document.getElementById('<?php echo $v ?>').src = reimg;
  166. }
  167. //适配新的缩略图
  168. if (window.opener.document.getElementById('litPic')) {
  169. window.opener.document.getElementById('litPic').src = reimg;
  170. }
  171. if (document.all) window.opener = true;
  172. } else if (typeof window.opener.CKEDITOR.instances["<?php echo $f ?>"] !== "undefined") {
  173. let addonHTML = `<img src='${reimg}'>`;
  174. window.opener.CKEDITOR.instances["<?php echo $f ?>"].insertHtml(addonHTML);
  175. }
  176. }
  177. window.close();
  178. }
  179. </script>
  180. </body>
  181. </html>