source: branches/MootoolsFileManager-Update/unsupported_plugins/InsertPicture/InsertPicture.php @ 1318

Last change on this file since 1318 was 1203, checked in by gogo, 10 years ago

Ticket #472

Disable InsertPicture?

  • Property svn:keywords set to LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
File size: 10.8 KB
Line 
1<?PHP
2 
3 
4  die('Developer, this plugin InsertPicture has been deprecated.  You are STRONGLY advised to use ImageManager plugin instead.  If you really must continue using this plugin, please edit xinha/unsupported_plugins/InsertPicture/InsertPicture.php to remove this notice.');
5 
6  /* DEVELOPER!
7   *
8   * InsertPicture is probably insecure.  There havn't been reports of it being attacked, but
9   * really it is not very good.  If you enable this plugin (by commenting out the die statement above)
10   * you are probably dicing with death.
11   *
12   * ImageManager is recommended to replace this plugin.  This plugin will be removed at a time
13   * in the future.
14   *
15   */
16 
17  //this plugin only use the relativ webpath to the picturefolder
18  //default ~  /Xinha/plugins/InsertPicture/demo_pictures/
19  strstr( PHP_OS, "WIN") ? $strPathSeparator = "\\" : $strPathSeparator = "/";
20  if (isset($_REQUEST['picturepath'])) {
21    $PicturePath = $_REQUEST['picturepath'];
22
23    $AInsertPicturePath = explode ('/', dirname($_SERVER['PHP_SELF']));
24    $ALocalInsertPicturePath = explode($strPathSeparator, dirname(__FILE__));
25    $AtheRootPath = array_values (array_diff ($ALocalInsertPicturePath, $AInsertPicturePath));
26    $RootPath = implode($strPathSeparator, $AtheRootPath);
27
28    $LocalPicturePath = str_replace('http://'.$_SERVER['HTTP_HOST'], "", $PicturePath);
29    $LocalPicturePath = str_replace('/', $strPathSeparator, $LocalPicturePath);
30    $LocalPicturePath = $RootPath.$LocalPicturePath;
31
32    $LocalPicturePath = dirname(__FILE__).$strPathSeparator.'demo_pictures'.$strPathSeparator;
33    //$LocalPicturePath = realpath('../../../../images/content/').$strPathSeparator;
34  }
35  $limitedext = array(".gif",".jpg",".png",".jpeg"); //Extensions you want files uploaded limited to.
36  $limitedsize = "1000000"; //size limit in bytes
37  $message = "";
38
39  function formatSize($size)
40  {
41    if($size < 1024)
42      return $size.' bytes';
43    else if($size >= 1024 && $size < 1024*1024)
44      return sprintf('%01.2f',$size/1024.0).' Kb';
45    else
46      return sprintf('%01.2f',$size/(1024.0*1024)).' Mb';
47  }
48  $DestFileName = "";
49  if (isset($_FILES['file'])) {
50    $file = $_FILES['file'];
51    $ext = strrchr($file['name'],'.');
52    if (!in_array($ext,$limitedext))
53      $message = "The file you are uploading doesn't have the correct extension.";
54    else if (file_exists($LocalPicturePath.$file['name']))
55      $message = "The file you are uploading already exists.";
56    else if ($file['size'] > $limitedsize)
57      $message = "The file you are uploading is to big. The max Filesize is</span><span> ".formatSize($limitedsize).".";
58    else
59      copy($file['tmp_name'], $LocalPicturePath.$file['name']);
60    $DestFileName = $file['name'];
61  }
62?>
63<html>
64<head>
65  <title>Insert Image</title>
66<link rel="stylesheet" type="text/css" href="../../popups/popup.css" />
67<script type="text/javascript" src="../../popups/popup.js"></script>
68
69<script type="text/javascript">
70  window.resizeTo(500, 490);
71var Xinha = window.opener.Xinha;
72function i18n(str) {
73  return (Xinha._lc(str, 'Xinha'));
74}
75
76function Init() {
77  __dlg_translate("InsertPicture");
78  __dlg_init();
79
80  // Make sure the translated string appears in the drop down. (for gecko)
81  document.getElementById("f_align").selectedIndex = 0;
82  document.getElementById("f_align").selectedIndex = document.getElementById("f_align").selectedIndex;
83  var param = window.dialogArguments;
84  if (param) {
85      document.getElementById("f_url").value = param["f_url"];
86      document.getElementById("f_alt").value = param["f_alt"];
87      document.getElementById("f_border").value = param["f_border"];
88      document.getElementById("f_align").value = param["f_align"];
89      document.getElementById("f_vert").value = (param["f_vert"]!="-1") ? param["f_vert"] : "";
90      document.getElementById("f_horiz").value = (param["f_horiz"]!="-1") ? param["f_horiz"] : "";
91      document.getElementById("f_height").value = param["f_height"];
92      document.getElementById("f_width").value = param["f_width"];
93      window.ipreview.location.replace(param.f_url);
94  }
95  document.getElementById("f_url").focus();
96  document.getElementById("filelist").selectedIndex = document.getElementById("filelist").selectedIndex;
97<?php If ($DestFileName<>"")
98  echo "CopyToURL(\"".$PicturePath.$DestFileName."\");"
99?>
100}
101
102function onOK() {
103  var required = {
104    "f_url": i18n("You must enter the URL")
105  };
106  for (var i in required) {
107    var el = document.getElementById(i);
108    if (!el.value) {
109      alert(required[i]);
110      el.focus();
111      return false;
112    }
113  }
114  // pass data back to the calling window
115  var fields = ["f_url", "f_alt", "f_align", "f_border", "f_horiz", "f_vert", "f_width", "f_height"];
116  var param = new Object();
117  for (var i in fields) {
118    var id = fields[i];
119    var el = document.getElementById(id);
120    param[id] = el.value;
121  }
122  __dlg_close(param);
123  return false;
124}
125
126function onUpload() {
127  var required = {
128    "file": i18n("Please select a file to upload.")
129  };
130  for (var i in required) {
131    var el = document.getElementById(i);
132    if (!el.value) {
133      alert(required[i]);
134      el.focus();
135      return false;
136    }
137  }
138  return true;
139}
140
141function onCancel() {
142  __dlg_close(null);
143  return false;
144}
145
146function onPreview() {
147  var f_url = document.getElementById("f_url");
148  var url = f_url.value;
149  if (!url) {
150    alert(i18n("You must enter the URL"));
151    f_url.focus();
152    return false;
153  }
154  if (document.all) {
155    window.ipreview.location.replace('viewpicture.html?'+url);
156  } else {
157    window.ipreview.location.replace(url);
158  }
159  return false;
160}
161
162var img = new Image();
163function imgWait() {
164  waiting = window.setInterval("imgIsLoaded()", 1000)
165}
166function imgIsLoaded() {
167  if(img.width > 0) {
168    window.clearInterval(waiting)
169    document.getElementById("f_width").value = img.width;
170    document.getElementById("f_height").value = img.height;
171  }
172}
173
174function CopyToURL(imgName) {
175  document.getElementById("f_url").value = imgName;
176  onPreview();
177  img.src = imgName;
178  img.onLoad = imgWait()
179}
180
181function openFile() {
182  window.open(document.getElementById("f_url").value,'','');
183}
184</script>
185</head>
186<body class="dialog" onload="Init()">
187<div class="title">Insert Image</div>
188<table border="0" width="100%" style="padding: 0px; margin: 0px">
189  <tbody>
190  <tr>
191    <td>Images on the Server:<?php /*echo $LocalPicturePath*/ ?><br>
192    <select id="filelist" name="filelist" style="width:200" size="10" onClick="CopyToURL(this[this.selectedIndex].value);">
193<?php
194  $d = @dir($LocalPicturePath);
195  while (false !== ($entry = $d->read())) {
196    if(substr($entry,0,1) != '.') {  //not a dot file or directory
197      if ($entry == $DestFileName)
198        echo '<OPTION value="' . $PicturePath.$entry. '" selected="selected">' . $entry . '(' . formatSize(filesize($LocalPicturePath.'\\'.$entry)) .')</OPTION>';
199      else
200        echo '<OPTION value="' . $PicturePath.$entry. '">' . $entry . '(' . formatSize(filesize($LocalPicturePath.'\\'.$entry)) .')</OPTION>';
201    }
202  }
203  $d->close();
204?>
205    </select>
206
207      <form method="post" action="" enctype="multipart/form-data">
208        <input type="hidden" name="localpicturepath" value="<?php echo $LocalPicturePath ?>">
209        <input type="hidden" name="picturepath" value="<?php echo $PicturePath ?>">
210        <input type="file" name="file" id="file" size="30"><br>
211        <button type="submit" name="ok" onclick="onUpload();">Upload file</button><br>
212        <span><?php echo $message ?></span>
213      </form>
214
215    </td>
216    <td style="vertical-align: middle;" width="200" height="230">
217    <span>Image Preview:</span>
218    <a href="#" onClick="javascript:openFile();"title=" Open file in new window"><img src="img/btn_open.gif"  width="18" height="18" border="0" title="Open file in new window" /></a><br />
219    <iframe name="ipreview" id="ipreview" frameborder="0" style="border : 1px solid gray;" height="200" width="200" src=""></iframe>
220    </td>
221  </tr>
222  </tbody>
223</table>
224
225<form action="" method="get">
226  <input type="hidden" name="localpicturepath" value="<?php echo $LocalPicturePath ?>">
227  <input type="hidden" name="picturepath" value="<?php echo $PicturePath ?>">
228<table border="0" width="100%" style="padding: 0px; margin: 0px">
229  <tbody>
230
231  <tr>
232    <td style="width: 7em; text-align: right">Image URL:</td>
233    <td><input type="text" name="url" id="f_url" style="width:75%"
234      title="Enter the image URL here"  value="<?php echo $PicturePath.$DestFileName ?>"/>
235      <button name="preview" onclick="return onPreview();"
236      title="Preview the image in a new window">Preview</button>
237    </td>
238  </tr>
239  <tr>
240    <td style="width: 7em; text-align: right">Alternate text:</td>
241    <td><input type="text" name="alt" id="f_alt" style="width:100%"
242      title="For browsers that don't support images" /></td>
243  </tr>
244
245  </tbody>
246</table>
247
248<p />
249
250<fieldset style="float: left; margin-left: 5px;">
251<legend>Layout</legend>
252
253<div class="space"></div>
254
255<div class="fl" style="width: 6em;">Alignment:</div>
256<select size="1" name="align" id="f_align"
257  title="Positioning of this image">
258  <option value=""                             >Not set</option>
259  <option value="left"                         >Left</option>
260  <option value="right"                        >Right</option>
261  <option value="texttop"                      >Texttop</option>
262  <option value="absmiddle"                    >Absmiddle</option>
263  <option value="baseline"                     >Baseline</option>
264  <option value="absbottom"                    >Absbottom</option>
265  <option value="bottom"                       >Bottom</option>
266  <option value="middle"                       >Middle</option>
267  <option value="top"                          >Top</option>
268</select>
269
270<p />
271
272<div class="fl" style="width: 6em;">Border thickness:</div>
273<input type="text" name="border" id="f_border" size="5" title="Leave empty for no border" />
274<div class="space"></div>
275
276</fieldset>
277
278<fieldset style="float: left; margin-left: 5px;">
279<legend>Size</legend>
280
281<div class="space"></div>
282
283<div class="fl" style="width: 5em;">Width:</div>
284<input type="text" name="width" id="f_width" size="5" title="Leave empty for not defined" />
285<p />
286
287<div class="fl" style="width: 5em;">Height:</div>
288<input type="text" name="height" id="f_height" size="5" title="Leave empty for not defined" />
289<div class="space"></div>
290
291</fieldset>
292
293<fieldset style="float:right; margin-right: 5px;">
294<legend>Spacing</legend>
295
296<div class="space"></div>
297
298<div class="fr" style="width: 5em;">Horizontal:</div>
299<input type="text" name="horiz" id="f_horiz" size="5" title="Horizontal padding" />
300<p />
301
302<div class="fr" style="width: 5em;">Vertical:</div>
303<input type="text" name="vert" id="f_vert" size="5" title="Vertical padding" />
304
305<div class="space"></div>
306
307</fieldset>
308<br clear="all" />
309
310<div id="buttons">
311  <button type="submit" name="ok" onclick="return onOK();">OK</button>
312  <button type="button" name="cancel" onclick="return onCancel();">Cancel</button>
313</div>
314</form>
315</body>
316</html>
Note: See TracBrowser for help on using the repository browser.