source: branches/ray/plugins/InsertPicture/InsertPicture.php @ 761

Last change on this file since 761 was 761, checked in by ray, 13 years ago

updated branch

  • Property svn:keywords set to LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
File size: 10.4 KB
RevLine 
[304]1<?PHP
[307]2  //this plugin only use the relativ webpath to the picturefolder
[761]3  //default ~  /Xinha/plugins/InsertPicture/demo_pictures/
[307]4  strstr( PHP_OS, "WIN") ? $strPathSeparator = "\\" : $strPathSeparator = "/";
5  if (isset($_REQUEST['picturepath'])) {
[761]6    $PicturePath = $_REQUEST['picturepath'];
[307]7
[761]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);
[307]12
[761]13    $LocalPicturePath = str_replace('http://'.$_SERVER['HTTP_HOST'], "", $PicturePath);
14    $LocalPicturePath = str_replace('/', $strPathSeparator, $LocalPicturePath);
15    $LocalPicturePath = $RootPath.$LocalPicturePath;
[307]16
[761]17    $LocalPicturePath = dirname(__FILE__).$strPathSeparator.'demo_pictures'.$strPathSeparator;
18    //$LocalPicturePath = realpath('../../../../images/content/').$strPathSeparator;
[307]19  }
[304]20  $limitedext = array(".gif",".jpg",".png",".jpeg"); //Extensions you want files uploaded limited to.
[307]21  $limitedsize = "1000000"; //size limit in bytes
22  $message = "";
[761]23
24  function formatSize($size)
[307]25  {
[761]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';
[307]30    else
[761]31      return sprintf('%01.2f',$size/(1024.0*1024)).' Mb';
[307]32  }
[761]33  $DestFileName = "";
[307]34  if (isset($_FILES['file'])) {
[304]35    $file = $_FILES['file'];
[307]36    $ext = strrchr($file['name'],'.');
[761]37    if (!in_array($ext,$limitedext))
[304]38      $message = "The file you are uploading doesn't have the correct extension.";
[761]39    else if (file_exists($LocalPicturePath.$file['name']))
[304]40      $message = "The file you are uploading already exists.";
[761]41    else if ($file['size'] > $limitedsize)
[304]42      $message = "The file you are uploading is to big. The max Filesize is</span><span> ".formatSize($limitedsize).".";
[761]43    else
44      copy($file['tmp_name'], $LocalPicturePath.$file['name']);
45    $DestFileName = $file['name'];
[307]46  }
[304]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">
[761]55  window.resizeTo(500, 490);
56var Xinha = window.opener.Xinha;
[304]57function i18n(str) {
[761]58  return (Xinha._lc(str, 'Xinha'));
[419]59}
[304]60
61function Init() {
[307]62  __dlg_translate("InsertPicture");
[304]63  __dlg_init();
[761]64
[304]65  // Make sure the translated string appears in the drop down. (for gecko)
[761]66  document.getElementById("f_align").selectedIndex = 0;
67  document.getElementById("f_align").selectedIndex = document.getElementById("f_align").selectedIndex;
[304]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"];
[761]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"] : "";
[438]76      document.getElementById("f_height").value = param["f_height"];
[761]77      document.getElementById("f_width").value = param["f_width"];
[304]78      window.ipreview.location.replace(param.f_url);
79  }
80  document.getElementById("f_url").focus();
[761]81  document.getElementById("filelist").selectedIndex = document.getElementById("filelist").selectedIndex;
82<?php If ($DestFileName<>"")
83  echo "CopyToURL(\"".$PicturePath.$DestFileName."\");"
84?>
[419]85}
[304]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
[761]100  var fields = ["f_url", "f_alt", "f_align", "f_border", "f_horiz", "f_vert", "f_width", "f_height"];
[304]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;
[419]109}
[304]110
[307]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  }
[761]123  return true;
[307]124}
125
[304]126function onCancel() {
127  __dlg_close(null);
128  return false;
[419]129}
[304]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;
[419]145}
[304]146
[438]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
[304]159function CopyToURL(imgName) {
160  document.getElementById("f_url").value = imgName;
161  onPreview();
[438]162  img.src = imgName;
163  img.onLoad = imgWait()
[419]164}
[304]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>
[761]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);">
[304]178<?php
[307]179  $d = @dir($LocalPicturePath);
[761]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>';
[307]186    }
187  }
188  $d->close();
[304]189?>
190    </select>
[761]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 ?>">
[307]195        <input type="file" name="file" id="file" size="30"><br>
[761]196        <button type="submit" name="ok" onclick="onUpload();">Upload file</button><br>
[307]197        <span><?php echo $message ?></span>
[304]198      </form>
199
200    </td>
201    <td valign="center" 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">
[761]211  <input type="hidden" name="localpicturepath" value="<?php echo $LocalPicturePath ?>">
212  <input type="hidden" name="picturepath" value="<?php echo $PicturePath ?>">
[304]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%"
[761]219      title="Enter the image URL here"  value="<?php echo $PicturePath.$DestFileName ?>"/>
[304]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
[438]240<div class="fl" style="width: 6em;">Alignment:</div>
[304]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>
[761]248  <option value="baseline"                     >Baseline</option>
[304]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
[438]257<div class="fl" style="width: 6em;">Border thickness:</div>
[761]258<input type="text" name="border" id="f_border" size="5" title="Leave empty for no border" />
[304]259<div class="space"></div>
260
261</fieldset>
262
[438]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
[304]278<fieldset style="float:right; margin-right: 5px;">
279<legend>Spacing</legend>
280
281<div class="space"></div>
282
[438]283<div class="fr" style="width: 5em;">Horizontal:</div>
[761]284<input type="text" name="horiz" id="f_horiz" size="5" title="Horizontal padding" />
[304]285<p />
286
[438]287<div class="fr" style="width: 5em;">Vertical:</div>
[761]288<input type="text" name="vert" id="f_vert" size="5" title="Vertical padding" />
[304]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>
[419]301</html>
Note: See TracBrowser for help on using the repository browser.