source: trunk/plugins/InsertPicture/InsertPicture.php @ 987

Last change on this file since 987 was 987, checked in by ray, 11 years ago

#1179 minor html syntax changes

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