PageRenderTime 68ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/railfrog/tags/railfrog-0.5/public/xinha/plugins/InsertPicture/InsertPicture.php

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