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

Last change on this file since 304 was 304, checked in by gocher, 14 years ago

New very small php plugin (small Imagemanager):
InsertPicture? replaces the popup insert_image.html
with only a few lines more in full_example.js
if(typeof InsertPicture? != 'undefined') {

InsertPicture?.PicturePath? = _editor_url + "plugins/insertPicture/demo_pictures/";
InsertPicture?.LocalPicturePath? = "d:
inetpub
wwwroot
xinha
trunk
plugins
insertPicture
demo_pictures";

}
it runs with the full_example!

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