maj version dans config.xml
[mtweb] / mw / libs / tiny_mce / plugins / tinybrowser / tinybrowser.php
1 <?php\r
2 require_once('config_tinybrowser.php');\r
3 // Set language\r
4 if(isset($tinybrowser['language']) && file_exists('langs/'.$tinybrowser['language'].'.php'))\r
5         {\r
6         require_once('langs/'.$tinybrowser['language'].'.php'); \r
7         }\r
8 else\r
9         {\r
10         require_once('langs/en.php'); // Falls back to English\r
11         }\r
12 require_once('fns_tinybrowser.php');\r
13 \r
14 // Check session, if it exists\r
15 if(session_id() != '')\r
16         {\r
17         if(!isset($_SESSION[$tinybrowser['sessioncheck']]))\r
18                 {\r
19                 echo TB_DENIED;\r
20                 exit;\r
21                 }\r
22         }\r
23 \r
24 // Assign file operation variables\r
25 $validtypes = array('image','media','file');\r
26 $typenow = ((isset($_GET['type']) && in_array($_GET['type'],$validtypes)) ? $_GET['type'] : 'image');\r
27 $standalone = ((isset($_GET['feid']) && $_GET['feid']!='') ? true : false);\r
28 $foldernow = str_replace(array('../','..\\','./','.\\'),'',($tinybrowser['allowfolders'] && isset($_REQUEST['folder']) ? urldecode($_REQUEST['folder']) : ''));\r
29 \r
30 if($standalone)\r
31         {\r
32         $passfeid = '&feid='.$_GET['feid'];     \r
33         $rowhlightinit =  ' onload="rowHighlight();"';\r
34         }\r
35 else\r
36         {\r
37         $passfeid = '';\r
38         $rowhlightinit =  '';   \r
39         }\r
40 \r
41 // Assign browsing options\r
42 $sortbynow = (isset($_REQUEST['sortby']) ? $_REQUEST['sortby'] : $tinybrowser['order']['by']);\r
43 $sorttypenow = (isset($_REQUEST['sorttype']) ? $_REQUEST['sorttype'] : $tinybrowser['order']['type']);\r
44 $sorttypeflip = ($sorttypenow == 'asc' ? 'desc' : 'asc');  \r
45 $viewtypenow = (isset($_REQUEST['viewtype']) ? $_REQUEST['viewtype'] : $tinybrowser['view']['image']);\r
46 $findnow = (isset($_POST['find']) && !empty($_POST['find']) ? $_POST['find'] : false);\r
47 $showpagenow = (isset($_REQUEST['showpage']) ? $_REQUEST['showpage'] : 0);\r
48 \r
49 // Assign url pass variables\r
50 $passfolder = '&folder='.urlencode($foldernow);\r
51 $passfeid = (isset($_GET['feid']) && $_GET['feid']!='' ? '&feid='.$_GET['feid'] : '');\r
52 $passviewtype = '&viewtype='.$viewtypenow;\r
53 $passsortby = '&sortby='.$sortbynow.'&sorttype='.$sorttypenow;\r
54 \r
55 // Assign view, thumbnail and link paths\r
56 $browsepath = $tinybrowser['path'][$typenow].$foldernow;\r
57 $linkpath = $tinybrowser['link'][$typenow].$foldernow;\r
58 $thumbpath = $tinybrowser[$tinybrowser['thumbsrc']][$typenow].$foldernow;\r
59 \r
60 // Assign sort parameters for column header links\r
61 $sortbyget = array();\r
62 $sortbyget['name'] = '&viewtype='.$viewtypenow.'&sortby=name';\r
63 $sortbyget['size'] = '&viewtype='.$viewtypenow.'&sortby=size'; \r
64 $sortbyget['type'] = '&viewtype='.$viewtypenow.'&sortby=type'; \r
65 $sortbyget['modified'] = '&viewtype='.$viewtypenow.'&sortby=modified';\r
66 $sortbyget['dimensions'] = '&viewtype='.$viewtypenow.'&sortby=dimensions'; \r
67 $sortbyget[$sortbynow] .= '&sorttype='.$sorttypeflip;\r
68 \r
69 // Assign css style for current sort type column\r
70 $thclass = array();\r
71 $thclass['name'] = '';\r
72 $thclass['size'] = ''; \r
73 $thclass['type'] = ''; \r
74 $thclass['modified'] = '';\r
75 $thclass['dimensions'] = ''; \r
76 $thclass[$sortbynow] = ' class="'.$sorttypenow.'"';\r
77 \r
78 // Initalise alert array\r
79 $notify = array(\r
80         'type' => array(),\r
81         'message' => array()\r
82 );\r
83 $newthumbqty = 0;\r
84 \r
85 // read folder contents if folder exists\r
86 if(file_exists($tinybrowser['docroot'].$browsepath))\r
87         {\r
88         // Read directory contents and populate $file array\r
89         $dh = opendir($tinybrowser['docroot'].$browsepath);\r
90         $file = array();\r
91         while (($filename = readdir($dh)) !== false)\r
92                 {\r
93                 // get file extension\r
94                 $nameparts = explode('.',$filename);\r
95                 $ext = end($nameparts);\r
96 \r
97                 // filter directories and prohibited file types\r
98                 if($filename != '.' && $filename != '..' && !is_dir($tinybrowser['docroot'].$browsepath.$filename) && !in_array($ext, $tinybrowser['prohibited']) && ($typenow == 'file' || strpos(strtolower($tinybrowser['filetype'][$typenow]),strtolower($ext))))\r
99                         {\r
100                         // search file name if search term entered\r
101                         if($findnow) $exists = strpos(strtolower($filename),strtolower($findnow));\r
102         \r
103                         // assign file details to array, for all files or those that match search\r
104                         if(!$findnow || ($findnow && $exists !== false))\r
105                                 {\r
106                                 $file['name'][] = $filename;\r
107                                 $file['sortname'][] = strtolower($filename);\r
108                                 $file['modified'][] = filemtime($tinybrowser['docroot'].$browsepath.$filename);\r
109                                 $file['size'][] = filesize($tinybrowser['docroot'].$browsepath.$filename);\r
110         \r
111                                 // image specific info or general\r
112                                 if($typenow=='image' && $imginfo = getimagesize($tinybrowser['docroot'].$browsepath.$filename))\r
113                                         {\r
114                                         $file['width'][] = $imginfo[0];\r
115                                         $file['height'][] = $imginfo[1];\r
116                                         $file['dimensions'][] = $imginfo[0] + $imginfo[1];\r
117                                         $file['type'][] = $imginfo['mime'];\r
118                                         \r
119                                         // Check a thumbnail exists\r
120                                         if(!file_exists($tinybrowser['docroot'].$browsepath.'_thumbs/')) createfolder($tinybrowser['docroot'].$browsepath.'_thumbs/',$tinybrowser['unixpermissions']);\r
121                                         $thumbimg = $tinybrowser['docroot'].$browsepath.'_thumbs/_'.$filename;\r
122                                         if (!file_exists($thumbimg))\r
123                                                 {\r
124                                                 $nothumbimg = $tinybrowser['docroot'].$browsepath.$filename;\r
125                                                 $mime = getimagesize($nothumbimg);\r
126                                                 $im = convert_image($nothumbimg,$mime['mime']);\r
127                                                 resizeimage($im,$tinybrowser['thumbsize'],$tinybrowser['thumbsize'],$thumbimg,$tinybrowser['thumbquality'],$mime['mime']);\r
128                                                 imagedestroy($im);\r
129                                                 $newthumbqty++;\r
130                                                 }\r
131                                         }\r
132                                 else \r
133                                         {\r
134                                         $file['width'][] = 'N/A';\r
135                                         $file['height'][] = 'N/A';\r
136                                         $file['dimensions'][] = 'N/A';\r
137                                         $file['type'][] = returnMIMEType($filename);\r
138                                         }\r
139                                 }                       \r
140                         }\r
141                 }\r
142         closedir($dh);\r
143         }\r
144 // create file upload folder\r
145 else\r
146         {\r
147         $success = createfolder($tinybrowser['docroot'].$browsepath,$tinybrowser['unixpermissions']);\r
148         if($success)\r
149                 {\r
150                 if($typenow=='image') createfolder($tinybrowser['docroot'].$browsepath.'_thumbs/',$tinybrowser['unixpermissions']);\r
151                 $notify['type'][]='success';\r
152                 $notify['message'][]=sprintf(TB_MSGMKDIR, $browsepath);\r
153                 }\r
154         else\r
155                 {\r
156                 $notify['type'][]='error';\r
157                 $notify['message'][]=sprintf(TB_MSGMKDIRFAIL, $browsepath);\r
158                 }\r
159         }\r
160         \r
161 // Assign directory structure to array\r
162 $browsedirs=array();\r
163 dirtree($browsedirs,$tinybrowser['filetype'][$typenow],$tinybrowser['docroot'],$tinybrowser['path'][$typenow]);\r
164         \r
165 // generate alert if new thumbnails created\r
166 if($newthumbqty>0)\r
167    {\r
168         $notify['type'][]='info';\r
169         $notify['message'][]=sprintf(TB_MSGNEWTHUMBS, $newthumbqty);\r
170         }\r
171         \r
172 \r
173 // determine sort order\r
174 $sortorder = ($sorttypenow == 'asc' ? SORT_ASC : SORT_DESC);\r
175 $num_of_files = (isset($file['name']) ? count($file['name']) : 0);\r
176 \r
177 if($num_of_files>0)\r
178         {\r
179         // sort files by selected order\r
180         sortfileorder($sortbynow,$sortorder,$file);\r
181         }\r
182 \r
183 // determine pagination\r
184 if($tinybrowser['pagination']>0)\r
185         {\r
186         $showpage_start = ($showpagenow ? ($_REQUEST['showpage']*$tinybrowser['pagination'])-$tinybrowser['pagination'] : 0);\r
187         $showpage_end = $showpage_start+$tinybrowser['pagination'];\r
188         if($showpage_end>$num_of_files) $showpage_end = $num_of_files;\r
189         }\r
190 else\r
191         {\r
192         $showpage_start = 0;\r
193         $showpage_end = $num_of_files;\r
194         }\r
195 ?>\r
196 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
197 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\r
198 <head>\r
199 <title>TinyBrowser :: <?php echo TB_BROWSE; ?></title>\r
200 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />\r
201 <meta http-equiv="Pragma" content="no-cache" />\r
202 <?php\r
203 if(!$standalone && $tinybrowser['integration']=='tinymce')\r
204         {\r
205         ?><script language="javascript" type="text/javascript" src="../../tiny_mce_popup.js"></script>\r
206         <link rel="stylesheet" type="text/css" media="all" href="<?php echo $tinybrowser['tinymcecss']; ?>" /><?php\r
207         }\r
208 else\r
209         {\r
210         ?><link rel="stylesheet" type="text/css" media="all" href="css/stylefull_tinybrowser.css" /><?php \r
211         }\r
212 ?>\r
213 <link rel="stylesheet" type="text/css" media="all" href="css/style_tinybrowser.css.php" />\r
214 <script language="javascript" type="text/javascript" src="js/tinybrowser.js.php?<?php echo substr($passfeid,1); ?>"></script>\r
215 </head>\r
216 <body<?php echo $rowhlightinit; ?>>\r
217 <?php\r
218 if(count($notify['type'])>0) alert($notify);\r
219 form_open('foldertab',false,'tinybrowser.php','?type='.$typenow.$passviewtype.$passsortby.$passfeid);\r
220 ?>\r
221 <div class="tabs">\r
222 <ul>\r
223 <li id="browse_tab" class="current"><span><a href="tinybrowser.php?type=<?php echo $typenow.$passfolder.$passfeid; ?>"><?php echo TB_BROWSE; ?></a></span></li><?php\r
224 if($tinybrowser['allowupload']) \r
225         {\r
226         ?><li id="upload_tab"><span><a href="upload.php?type=<?php echo $typenow.$passfolder.$passfeid; ?>"><?php echo TB_UPLOAD; ?></a></span></li><?php\r
227         }\r
228 if($tinybrowser['allowedit'] || $tinybrowser['allowdelete'])\r
229         {\r
230         ?><li id="edit_tab"><span><a href="edit.php?type=<?php echo $typenow.$passfolder.$passfeid; ?>"><?php echo TB_EDIT; ?></a></span></li><?php\r
231         }\r
232 if($tinybrowser['allowfolders'])\r
233         {\r
234         ?><li id="folders_tab"><span><a href="folders.php?type=<?php echo $typenow.$passfolder.$passfeid; ?>"><?php echo TB_FOLDERS; ?></a></span></li><?php\r
235         }\r
236 // Display folder select, if multiple exist\r
237 if(count($browsedirs)>1)\r
238         {\r
239         ?><li id="folder_tab" class="right"><span><?php\r
240         form_select($browsedirs,'folder',TB_FOLDERCURR,urlencode($foldernow),true);\r
241         ?></span></li><?php\r
242         } \r
243 ?>\r
244 </ul>\r
245 </div>\r
246 </form>\r
247 <div class="panel_wrapper">\r
248 <div id="general_panel" class="panel currentmod">\r
249 <fieldset>\r
250 <legend><?php echo TB_BROWSEFILES; ?></legend>\r
251 <?php\r
252 form_open('browse','custom','tinybrowser.php','?type='.$typenow.$passfolder.$passfeid);\r
253 ?>\r
254 <div class="pushleft">\r
255 <?php\r
256 \r
257 // Offer view type if file type is image\r
258 if($typenow=='image')\r
259         {\r
260         $select = array(\r
261                 array('thumb',TB_THUMBS),\r
262                 array('detail',TB_DETAILS)\r
263         );\r
264         form_select($select,'viewtype',TB_VIEW,$viewtypenow,true);\r
265         }\r
266         \r
267 // Show page select if pagination is set\r
268 if($tinybrowser['pagination']>0)\r
269         {\r
270         $pagelimit = ceil($num_of_files/$tinybrowser['pagination'])+1;\r
271         $page = array();\r
272         for($i=1;$i<$pagelimit;$i++)\r
273                 {\r
274                 $page[] = array($i,TB_PAGE.' '.$i);\r
275                 }\r
276         if($i>2) form_select($page,'showpage',TB_SHOW,$showpagenow,true);\r
277         }\r
278 ?></div><div class="pushright"><?php\r
279 \r
280 form_hidden_input('sortby',$sortbynow);\r
281 form_hidden_input('sorttype',$sorttypenow);\r
282 form_text_input('find',false,$findnow,25,50);\r
283 form_submit_button('search',TB_SEARCH,'');\r
284 \r
285 ?></div>\r
286 <?php\r
287 \r
288 // if image show dimensions header\r
289 if($typenow=='image')\r
290         {\r
291         $imagehead = '<th><a href="?type='.$typenow.$passfolder.$passfeid.$sortbyget['dimensions'].'"'.$thclass['dimensions'].'>'.TB_DIMENSIONS.'</a></th>';\r
292         }\r
293 else $imagehead = '';\r
294 \r
295 echo '<div class="tabularwrapper"><table class="browse">'\r
296                 .'<tr><th><a href="?type='.$typenow.$passfolder.$passfeid.$sortbyget['name'].'"'.$thclass['name'].'>'.TB_FILENAME.'</a></th>'\r
297                 .'<th><a href="?type='.$typenow.$passfolder.$passfeid.$sortbyget['size'].'"'.$thclass['size'].'>'.TB_SIZE.'</a></th>'\r
298                 .$imagehead\r
299                 .'<th><a href="?type='.$typenow.$passfolder.$passfeid.$sortbyget['type'].'"'.$thclass['type'].'>'.TB_TYPE.'</th>'\r
300                 .'<th><a href="?type='.$typenow.$passfolder.$passfeid.$sortbyget['modified'].'"'.$thclass['modified'].'>'.TB_DATE.'</th></tr>';\r
301 \r
302 // show image thumbnails, unless detail view is selected\r
303 if($typenow=='image' && $viewtypenow != 'detail')\r
304         {\r
305         echo '</table></div>';\r
306 \r
307         for($i=$showpage_start;$i<$showpage_end;$i++)\r
308                 {\r
309                 echo '<div class="img-browser"><a href="#" onclick="selectURL(\''.$linkpath.$file['name'][$i].'\');" title="'.TB_FILENAME.': '.$file['name'][$i]\r
310                                 .'&#13;&#10;'.TB_DIMENSIONS.': '.$file['width'][$i].' x '.$file['height'][$i]\r
311                                 .'&#13;&#10;'.TB_DATE.': '.date($tinybrowser['dateformat'],$file['modified'][$i])\r
312                                 .'&#13;&#10;'.TB_TYPE.': '.$file['type'][$i]\r
313                                 .'&#13;&#10;'.TB_SIZE.': '.bytestostring($file['size'][$i],1)\r
314                                 .'"><img src="'.$thumbpath.'_thumbs/_'.$file['name'][$i]\r
315                                 .'"  /><div class="filename">'.$file['name'][$i].'</div></a></div>';\r
316                 }\r
317         }\r
318 else\r
319         {\r
320         for($i=$showpage_start;$i<$showpage_end;$i++)\r
321                 {\r
322                 $alt = (IsOdd($i) ? 'r1' : 'r0');\r
323                 echo '<tr class="'.$alt.'">';\r
324                 if($typenow=='image') echo '<td><a class="imghover" href="#" onclick="selectURL(\''.$linkpath.$file['name'][$i].'\');" title="'.$file['name'][$i].'"><img src="'.$thumbpath.'_thumbs/_'.$file['name'][$i].'" alt="" />'.truncate_text($file['name'][$i],30).'</a></td>';\r
325                 else echo '<td><a href="#" onclick="selectURL(\''.$linkpath.$file['name'][$i].'\');" title="'.$file['name'][$i].'">'.truncate_text($file['name'][$i],30).'</a></td>';\r
326                 echo '<td>'.bytestostring($file['size'][$i],1).'</td>';\r
327                 if($typenow=='image') echo '<td>'.$file['width'][$i].' x '.$file['height'][$i].'</td>'; \r
328                 echo '<td>'.$file['type'][$i].'</td>'\r
329                         .'<td>'.date($tinybrowser['dateformat'],$file['modified'][$i]).'</td></tr>'."\n";\r
330                 }\r
331         echo '</table></div>';\r
332         }\r
333 ?>\r
334 </fieldset></div></div>\r
335 <form name="passform"><input name = "fileurl" type="hidden" value= "" /></form>\r
336 </body>\r
337 </html>\r