OSDN Git Service

ver 1.0.8.1
[nucleus-jp/nucleus-plugins.git] / NP_Mediatocu / mediatocu / media.php
1 <?php\r
2 /*\r
3  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)\r
4  * Copyright (C) 2002-2007 The Nucleus Group\r
5  *\r
6  * This program is free software; you can redistribute it and/or\r
7  * modify it under the terms of the GNU General Public License\r
8  * as published by the Free Software Foundation; either version 2\r
9  * of the License, or (at your option) any later version.\r
10  * (see nucleus/documentation/index.html#license for more info)\r
11  */\r
12 /**\r
13  * Media popup window for Nucleus\r
14  *\r
15  * Purpose:\r
16  *   - can be openen from an add-item form or bookmarklet popup\r
17  *   - shows a list of recent files, allowing browsing, search and\r
18  *     upload of new files\r
19  *   - close the popup by selecting a file in the list. The file gets\r
20  *     passed through to the add-item form (linkto, popupimg or inline img)\r
21  *\r
22  * @license http://nucleuscms.org/license.txt GNU General Public License\r
23  * @copyright Copyright (C) 2002-2007 The Nucleus Group\r
24  * @version $Id: media.php 1116 2007-02-03 08:24:29Z kimitake $\r
25  * $NucleusJP: media.php,v 1.4 2007/03/27 12:13:47 kimitake Exp $\r
26  *\r
27  */\r
28 \r
29 \r
30 \r
31 if (!defined('_MEDIA_PHP_DEFINED')) {\r
32         define('_MEDIA_PHP_DEFINED', 1);\r
33         // mymbmime choice.\r
34 }\r
35 // add definition end\r
36 $CONF = array();\r
37 \r
38 // defines how much media items will be shown per page. You can override this\r
39 // in config.php if you like. (changing it in config.php instead of here will\r
40 // allow your settings to be kept even after a Nucleus upgrade)\r
41 \r
42 \r
43 //rem yama 20070928 $CONF['MediaPerPage'] = $media_per_page;\r
44 \r
45 $Prefix_thumb = "thumb_";\r
46 \r
47 // include all classes and config data\r
48 require('../../../config.php');\r
49 \r
50 // added yama20070928\r
51 $mediatocu            = $manager->getPlugin('NP_Mediatocu');\r
52 $media_per_page       = $mediatocu->getOption('media_per_page');\r
53 $CONF['MediaPerPage'] = $media_per_page;\r
54 // end yama20070928\r
55 \r
56 include($DIR_LIBS . 'MEDIA.php');       // media classes\r
57 /*\r
58  * Start append by T.Kosugi\r
59  * Reffering /lib/MEDIA.php (v3.22)\r
60  */\r
61 class MEDIADIRS extends MEDIA\r
62 {\r
63         function MEDIADIRES()\r
64         {\r
65                 //$this->MEDIA();\r
66         }\r
67 \r
68         function getCollectionList()\r
69         {\r
70                 global $member, $DIR_MEDIA, $manager;\r
71 \r
72                 $collections = array();\r
73                 /* edit T.Kosugi 2006/09/06\r
74                 // add private directory for member\r
75                 $collections[$member->getID()] = _MEDIA_PHP_32;\r
76                 */\r
77 /*\r
78                 $searchDir   = '/';\r
79                 $prefix      = $member->getID();\r
80                 $collections = array_merge($collections, (array)MEDIADIRS::traceCorrectionDir($searchDir, $prefix, _MEDIA_PHP_32));\r
81 */\r
82                 // add global collections\r
83                 if (!is_dir($DIR_MEDIA)) {\r
84                         return $collections;\r
85                 }\r
86 \r
87                 $dirhandle = opendir($DIR_MEDIA);\r
88                 while ($dirname = readdir($dirhandle)) {\r
89                         // only add non-numeric (numeric=private) dirs\r
90                         if (@is_dir($DIR_MEDIA . $dirname) && ($dirname != '.') && ($dirname != '..') && ($dirname != 'CVS') && (!is_numeric($dirname))) {\r
91                                 $collections[$dirname] = $dirname;\r
92 /*\r
93                                 $searchDir             = '/';\r
94                                 $prefix                = $dirname;\r
95                                 $collections           = array_merge($collections, (array)MEDIADIRS::traceCorrectionDir($searchDir, $prefix, $dirname));\r
96 */\r
97                         }\r
98                 }\r
99                 closedir($dirhandle);\r
100                 // add T.Kosugi 2006/09/06\r
101                 // add private directory for member\r
102 //              $collections[$member->getID()] = _MEDIA_PHP_32;\r
103                 // add end\r
104 //              ksort($collections, SORT_STRING);\r
105 \r
106                 $hiddendir = array();\r
107                 $mediatocu = $manager->getPlugin('NP_Mediatocu');\r
108                 $hiddendir = explode(',', $mediatocu->getOption('hidden_dir'));\r
109                 foreach ($hiddendir as $value)\r
110                 {\r
111                         $value = trim($value);\r
112                         unset($collections["$value"]);\r
113                 }\r
114                 foreach ($collections as $value)\r
115                 {\r
116                                 $searchDir             = '/';\r
117                                 $prefix                = $value;\r
118                                 $collections           = array_merge($collections, (array)MEDIADIRS::traceCorrectionDir($searchDir, $prefix, $value));\r
119                 }\r
120                 $collections[$member->getID()] = _MEDIA_PHP_32;\r
121                 $searchDir   = '/';\r
122                 $prefix      = $member->getID();\r
123                 $collections = array_merge($collections, (array)MEDIADIRS::traceCorrectionDir($searchDir, $prefix, _MEDIA_PHP_32));\r
124                 ksort($collections, SORT_STRING);\r
125                 return $collections;\r
126 \r
127         }\r
128 \r
129         function getPrivateCollectionList()\r
130         {\r
131                 global $member, $DIR_MEDIA;\r
132 \r
133                 $collections = array();\r
134                 $prefix      = $member->getID();\r
135                 $searchDir   = '/';\r
136                 $collections = MEDIADIRS::traceCorrectionDir($searchDir, $prefix, _MEDIA_PHP_32);\r
137                 // add private directory for member\r
138                 $collections[$prefix] = _MEDIA_PHP_32;\r
139                 ksort($collections, SORT_STRING);\r
140                 return $collections;\r
141         }\r
142 \r
143         function traceCorrectionDir($searchDir, $prefix ='', $preName)\r
144         {\r
145                 global $DIR_MEDIA;\r
146                 $collections = array();         //http://japan.nucleuscms.org/bb/viewtopic.php?p=21230&highlight=#21230\r
147                 $dirhandle   = @opendir($DIR_MEDIA . $prefix . $searchDir);\r
148                 if (!$dirhandle) {\r
149                         return;\r
150                 }\r
151                 while ($dirname = readdir($dirhandle)) {\r
152                         // only add non-numeric (numeric=private) dirs\r
153                         if (@is_dir($DIR_MEDIA . $prefix . $searchDir . $dirname) && ($dirname != '.') && ($dirname != '..') && ($dirname != 'CVS'))  {\r
154                                 $collections[$prefix . $searchDir . $dirname] = $preName . $searchDir . $dirname;\r
155                                 $collections = array_merge($collections, (array)MEDIADIRS::traceCorrectionDir($searchDir . $dirname . '/', $prefix, $preName));\r
156                         }\r
157                 }\r
158                 closedir($dirhandle);\r
159 \r
160                 return $collections;\r
161         }\r
162 \r
163         function getMediaListByCollection($collection, $filter = '')\r
164         {\r
165                 global $DIR_MEDIA;\r
166 \r
167                 $filelist = array();\r
168 \r
169                 // 1. go through all objects and add them to the filelist\r
170 \r
171                 $mediadir = $DIR_MEDIA . $collection . '/';\r
172 \r
173                 // return if dir does not exist\r
174                 if (!is_dir($mediadir)) {\r
175                         return $filelist;\r
176                 }\r
177 \r
178                 $dirhandle = opendir($mediadir);\r
179                 while ($filename = readdir($dirhandle)) {\r
180                         // only add files that match the filter\r
181                         if (!@is_dir($mediadir . $filename) && MEDIA::checkFilter($filename, $filter)) {\r
182                                 array_push($filelist, new MEDIAOBJECT($collection, $filename, filemtime($mediadir . $filename)));\r
183                         }\r
184                 }\r
185                 closedir($dirhandle);\r
186 \r
187                 // sort array so newer files are shown first\r
188                 usort($filelist, 'sort_media');\r
189 \r
190                 return $filelist;\r
191         }\r
192 }\r
193 \r
194 /*\r
195  * End append by T.Kosugi\r
196  */\r
197 sendContentType('application/xhtml+xml', 'media');\r
198 \r
199 // user needs to be logged in to use this\r
200 if (!$member->isLoggedIn()) {\r
201         media_loginAndPassThrough();\r
202         exit;\r
203 }\r
204 \r
205 // check if member is on at least one teamlist\r
206 $query = 'SELECT * FROM ' . sql_table('team'). ' WHERE tmember=' . $member->getID();\r
207 //$teams = mysql_query($query);\r
208 $teams = sql_query($query);\r
209 if (mysql_num_rows($teams) == 0) {\r
210         media_doError(_ERROR_DISALLOWEDUPLOAD);\r
211 }\r
212 \r
213 // get action\r
214 $action = requestVar('action');\r
215 if ($action == '') {\r
216         $action = 'selectmedia';\r
217 }\r
218 \r
219 // check ticket\r
220 $aActionsNotToCheck = array('selectmedia', _MEDIA_PHP_30, _MEDIA_COLLECTION_SELECT);\r
221 if (!in_array($action, $aActionsNotToCheck)) {\r
222         if (!$manager->checkTicket()) {\r
223                 media_doError(_ERROR_BADTICKET);\r
224         }\r
225 }\r
226 \r
227                 /*-------kei edit & append 2005.5.26-------*/\r
228 // <080213 fix $_POST to postVar by shizuki>\r
229 //if ($_POST[targetthumb]) {//}\r
230 if (postVar('targetthumb')) {\r
231 //      $mediapath = $DIR_MEDIA . $_POST[currentCollection] . "/";\r
232         $mediapath = $DIR_MEDIA . postVar('currentCollection') . "/";\r
233 //      switch ($_POST[myaction]) {//}\r
234         switch (postVar('myaction')) {\r
235                 case _MEDIA_PHP_1:\r
236 //                      $msg1 = unlink($mediapath . $_POST[targetfile]);\r
237                         $msg1 = unlink($mediapath . postVar('targetfile'));\r
238                         if (!$msg1) {\r
239                                 print $selectfile . htmlspecialchars(_MEDIA_PHP_2);\r
240                         }\r
241 //                      $exist = file_exists($mediapath . $_POST[targetthumb]);\r
242                         $exist = file_exists($mediapath . postVar('targetthumb'));\r
243                         if ($exist) {\r
244 //                              $msg2 = unlink($mediapath.$_POST[targetthumb]);\r
245                                 $msg2 = unlink($mediapath . postVar('targetthumb'));\r
246                                 if (!$msg2) {\r
247 //                                      print $_POST[targetthumb] . _MEDIA_PHP_2;\r
248                                         print postVar('targetthumb') . htmlspecialchars(_MEDIA_PHP_2);\r
249                                 }\r
250                         }\r
251                         break;\r
252                 case _MEDIA_PHP_3:\r
253                         //chmod($mediapath.$targetfile, 706);\r
254                         /*\r
255                         T.Kosugi edit 2006.8.22\r
256                         */\r
257                         // check file type against allowed types\r
258 //                      $newfilename = $_POST[newname];\r
259                         $newfilename = postVar('newname');\r
260                         // T.Kosugi add 2006.9.1\r
261                         if (stristr($newfilename, '%00')) {\r
262                                 media_doError(_MEDIA_PHP_38);\r
263                         }\r
264                         // T.Kosugi add end\r
265                         $ok = 0;\r
266                         $allowedtypes = explode (',', $CONF['AllowedTypes']);\r
267                         foreach ($allowedtypes as $type) {\r
268                                 if (eregi("\." . $type . "$", $newfilename)) {\r
269                                         $ok = 1;\r
270                                 }\r
271                         }\r
272                         if (eregi("\.php$", $newfilename)) {\r
273                                 $ok = 0;\r
274                         }\r
275                         if (!$ok) {\r
276                                 media_doError(_ERROR_BADFILETYPE);\r
277                         }\r
278                         /*\r
279                         T.Kosugi edit End\r
280                         */\r
281 //                      $msg1 = rename($mediapath . $_POST[targetfile], $mediapath . htmlspecialchars($_POST[newname]) );\r
282                         $msg1 = rename($mediapath . postVar('targetfile'), $mediapath . htmlspecialchars(postVar('newname')) );\r
283                         if (!$msg1) {\r
284                                 print $selectfile . htmlspecialchars(_MEDIA_PHP_10);\r
285                         }\r
286 //                      $exist = file_exists($mediapath . $_POST[targetthumb]);\r
287                         $exist = file_exists($mediapath . postVar('targetthumb'));\r
288 \r
289                         //print "targetthumb=$mediapath$_POST[targetthumb]<BR />";\r
290                         if ($exist) {\r
291 //                              $thumbnewname = $Prefix_thumb . $_POST[newname];\r
292                                 $thumbnewname = $Prefix_thumb . postVar('newname');\r
293 //                              $msg2         = rename($mediapath . $_POST[targetthumb], $mediapath . $thumbnewname);\r
294                                 $msg2         = rename($mediapath . postVar('targetthumb'), $mediapath . $thumbnewname);\r
295                                 if (!$msg2) {\r
296                                         print $targetthumb . htmlspecialchars(_MEDIA_PHP_10);\r
297                                 }\r
298                         }\r
299                         break;\r
300         }\r
301 }\r
302 // </080213 fix $_POST to postVar by shizuki>\r
303 switch($action) {\r
304         case 'chooseupload':\r
305         case _MEDIA_UPLOAD_TO:\r
306         case _MEDIA_UPLOAD_NEW:\r
307                 media_choose();\r
308                 break;\r
309         case 'uploadfile':\r
310                 media_upload();\r
311                 break;\r
312         case _MEDIA_PHP_30:\r
313         case 'selectmedia':\r
314         case _MEDIA_COLLECTION_SELECT:\r
315         default:\r
316                 media_select();\r
317                 break;\r
318         /*\r
319                 added forder action by T.Kosugi  2006/08/27\r
320         */\r
321         case _MEDIA_PHP_ACTION_DIR:\r
322         case _MEDIA_PHP_ACTION_MKDIR:\r
323         case _MEDIA_PHP_ACTION_RMDIR:\r
324         case 'rmdir':\r
325         case 'mkdir':\r
326                 media_mkdir($action);\r
327                 break;\r
328         /*\r
329                 END added forder action by T.Kosugi  2006/08/27\r
330         */\r
331 }\r
332 \r
333 // select a file\r
334 function media_select()\r
335 {\r
336         global $member, $CONF, $DIR_MEDIA, $manager;\r
337 //added yama 20071013\r
338         $mediatocu = $manager->getPlugin('NP_Mediatocu');\r
339         if ($mediatocu->getOption('paste_mode_checked')=="yes") {\r
340                 $paste_mode_popup_checked = 'checked="checked"';\r
341         } else {\r
342                 $paste_mode_normal_checked = 'checked="checked"';\r
343         }\r
344 //end yama\r
345 \r
346         media_head();\r
347 \r
348         // show 10 files + navigation buttons\r
349         // show msg when no files\r
350         // show upload form\r
351         // files sorted according to last modification date\r
352 \r
353         // currently selected collection\r
354         $currentCollection = requestVar('collection');\r
355         /*2005.8.31  kei append*/\r
356 // <080213 fix $_POST to postVar by shizuki>\r
357 //      if ($_POST[currentCollection]) {//}\r
358         if (postVar('currentCollection')) {\r
359 //              $currentCollection = $_POST[currentCollection];\r
360                 $currentCollection = postVar('currentCollection');\r
361         }\r
362 // </ 080213 fix $_POST to postVar by shizuki>\r
363         if (!$currentCollection || !@is_dir($DIR_MEDIA . $currentCollection)) {\r
364                 $currentCollection = $member->getID();\r
365         }\r
366 \r
367         // get collection list\r
368         // start modify by T.Kosugi 2006/08/26\r
369         //$collections = MEDIA::getCollectionList();\r
370         $collections = MEDIADIRS::getCollectionList();\r
371         // modify end\r
372         // modify start T.Kosugi 2006/09/01\r
373         // if (sizeof($collections) > 1) {\r
374         if (sizeof($collections) > 0) {\r
375         // modify end T.Kosugi 2006/09/01\r
376 ?>\r
377                 <form method="post" action="media.php" style="margin:5px 0;"><div>\r
378                         <label for="media_collection"><?php echo htmlspecialchars(_MEDIA_COLLECTION_LABEL)?></label>\r
379                         <select name="collection" id="media_collection" onchange="return form.submit()">\r
380                                 <?php\r
381                                         foreach ($collections as $dirname => $description) {\r
382                                                 echo '<option value="',htmlspecialchars($dirname),'"';\r
383                                                 if ($dirname == $currentCollection) {\r
384                                                         echo ' selected="selected"';\r
385                                                 }\r
386                                                 echo '>',htmlspecialchars($description),'</option>';\r
387                                         }\r
388                                 ?>\r
389                         </select>\r
390                         <!--<input type="submit" name="action" value="<?php echo htmlspecialchars(_MEDIA_COLLECTION_SELECT) ?>" title="<?php echo htmlspecialchars(_MEDIA_COLLECTION_TT)?>" />-->\r
391                         <input type="submit" name="action" value="<?php echo htmlspecialchars(_MEDIA_UPLOAD_NEW) ?>" title="<?php echo htmlspecialchars(_MEDIA_UPLOADLINK) ?>" />\r
392 <?php // add button start by T.Kosugi 2006/08/26 ?>\r
393                         <input type="submit" name="action" value="<?php echo htmlspecialchars(_MEDIA_PHP_ACTION_DIR) ?>" title="<?php echo htmlspecialchars(_MEDIA_PHP_ACTION_DIR_TT) ?>" />\r
394 <?php // add bottun end by T.Kosugi 2006/08/26 ?>\r
395                         <?php $manager->addTicketHidden() ?>\r
396                 </div></form>\r
397 <?php\r
398         } else {\r
399 ?>\r
400                 <form method="post" action="media.php" style="float:right"><div>\r
401                         <input type="hidden" name="collection" value="<?php echo htmlspecialchars($currentCollection)?>" />\r
402                         <input type="submit" name="action" value="<?php echo htmlspecialchars(_MEDIA_UPLOAD_NEW) ?>" title="<?php echo htmlspecialchars(_MEDIA_UPLOADLINK) ?>" />\r
403                         <?php $manager->addTicketHidden() ?>\r
404                 </div></form>\r
405 <?php\r
406         } // if sizeof\r
407 \r
408         $filter = requestVar('filter');\r
409         $offset = intRequestVar('offset');\r
410 \r
411         // start modify by T.Kosugi 2006/08/26\r
412         //$arr = MEDIA::getMediaListByCollection($currentCollection, $filter);\r
413         $arr = MEDIADIRS::getMediaListByCollection($currentCollection, $filter);\r
414         // modify end\r
415 ?>\r
416                 <form method="post" action="media.php" style="margin:5px 0;"><div>\r
417                         <label for="media_filter"><?php echo htmlspecialchars(_MEDIA_PHP_31)?></label>\r
418                         <input id="media_filter" type="text" name="filter" value="<?php echo htmlspecialchars($filter)?>" />\r
419                         <input type="submit" name="action" value="<?php echo htmlspecialchars(_MEDIA_PHP_30) ?>" />\r
420                         <input type="hidden" name="collection" value="<?php echo htmlspecialchars($currentCollection)?>" />\r
421                         <input type="hidden" name="offset" value="<?php echo intval($offset)?>" />\r
422                 </div></form>\r
423 \r
424 <?php\r
425         if (sizeof($arr)>0) {\r
426                 $contents = array();\r
427                 /*The numbers of contents except the thumbnail image are requested. */\r
428                 for ($i=0;$i<sizeof($arr);$i++) {\r
429                         $obj = $arr[$i];\r
430                         if (ereg("thumb", $obj->filename)) {\r
431                                 continue;\r
432                         }\r
433                         $contents[] = $obj;\r
434                 }\r
435                 $conts_count = sizeof($contents);\r
436                 //print "conts_count=$conts_count<br />";\r
437                 if ($conts_count < $CONF['MediaPerPage']) {\r
438                         $maxpage = 1;\r
439                 } else {\r
440                         $maxpage = ceil($conts_count/$CONF['MediaPerPage']);\r
441                 }\r
442 \r
443                 if ($offset==0) {\r
444                         $offset=1;\r
445                 }\r
446                 $idxStart = $offset;\r
447                 $idxEnd   = $idxStart * $CONF['MediaPerPage'];\r
448                 if ($idxEnd > $conts_count) {\r
449                         $idxEnd = $conts_count;\r
450                 }\r
451                 if ($idxEnd < 1) {\r
452                         $idxEnd = $CONF['MediaPerPage'];\r
453                 }\r
454                 $idxNext = ($idxStart-1) * $CONF['MediaPerPage'];\r
455                 if ($idxNext < 0) {\r
456                         $idxNext = 0;\r
457                 }\r
458         }\r
459 ?>\r
460 \r
461                 <p><?php echo htmlspecialchars(_MEDIA_COLLECTION_LABEL . $collections[$currentCollection] . _MEDIA_PHP_6 . $conts_count) . " " . intVal($idxNext+1) . " - " . htmlspecialchars($idxEnd . _MEDIA_PHP_7); ?></p>\r
462                 <p>\r
463 <?php\r
464         if ($idxStart >0 && $idxNext >0) {\r
465                 $page = ($idxStart-1);\r
466                 echo "<a href='media.php?offset=$page&amp;collection=" . urlencode($currentCollection) . "' title='$page'>" . htmlspecialchars(_MEDIA_PHP_29) . "</a> ";\r
467         }\r
468         if ($idxStart < $maxpage) {\r
469                 $page = ($idxStart+1);\r
470                 echo "<a href='media.php?offset=$page&amp;collection=" . urlencode($currentCollection) . "' title='$page'>" .  htmlspecialchars(_MEDIA_PHP_28) . "</a> ";\r
471         }\r
472 ?>\r
473                 </p>\r
474 <form name="top" action="media.php" style="margin:5px;">\r
475         <div>\r
476                 <?php echo htmlspecialchars(_MEDIA_PHP_11) ?>\r
477                 <input id="typeradio0" type="radio" class="radio" name="typeradio" onclick="setType(0);document.bottom.typeradio[0].checked=true;" onkeypress="setType(0);document.bottom.typeradio[0].checked=true;" <?php echo $paste_mode_normal_checked; ?> />\r
478                 <label for="typeradio0"><?php echo htmlspecialchars(_MEDIA_INLINE);?></label>\r
479                 <input <?php echo $paste_mode_popup_checked; ?> id="typeradio1" type="radio" class="radio" name="typeradio" onclick="setType(1);document.bottom.typeradio[1].checked=true;" onkeypress="setType(1);document.bottom.typeradio[1].checked=true;" />\r
480                 <label for="typeradio1"><?php echo htmlspecialchars(_MEDIA_POPUP); ?></label>\r
481         </div>\r
482 </form>\r
483 \r
484 <!-- rem yama 20070928            <th><?php echo _MEDIA_MODIFIED; ?></th> -->\r
485 <!--\r
486                         <th><?php echo htmlspecialchars(_MEDIA_PHP_12); ?></th>\r
487                         <th><?php echo htmlspecialchars(_MEDIA_PHP_25); ?></th>\r
488                         <th><?php echo htmlspecialchars(_MEDIA_PHP_20); ?></th>\r
489 -->\r
490 <?php\r
491         if (sizeof($arr)>0) {\r
492                 /*-------kei edit & append 2005.5.26-------*/\r
493                 global $myaction, $targetfile, $targetthumb, $Prefix_thumb;\r
494                 global $newname, $thumbnewname;\r
495 \r
496                 if ($msg1) {\r
497                         $targetfile = $newname;\r
498                 }\r
499                 if ($msg2) {\r
500                         $thumb_targetfile = $thumbnewname;\r
501                         echo "<script type='text/javascript'>\n\tlocation.replace('media.php');\n</script>";\r
502                 }\r
503 \r
504 //              print"idxNext=$idxNext<BR />";\r
505 //              print"idxEnd=$idxEnd<BR />";\r
506 //              print"<BR />";\r
507                 for ($i=$idxNext;$i<$idxEnd;$i++) {\r
508                         $filename = $DIR_MEDIA . $currentCollection . '/' . $contents[$i]->filename;\r
509 //                      if(!$msg1)$targetfile = $contents[$i]->filename;\r
510                         $targetfile = $contents[$i]->filename;\r
511                         $old_level  = error_reporting(0);\r
512                         $size       = @GetImageSize($filename);\r
513                         error_reporting($old_level);\r
514                         $width      = intval($size[0]);\r
515                         $height     = intval($size[1]);\r
516                         $filetype   = $size[2];\r
517 \r
518                         echo "<div class='box'>\n";\r
519 // rem yama                     echo "<td>". date("Y-m-d",$contents[$i]->timestamp) ."</td>\n";\r
520 \r
521                         // strings for javascript\r
522                         $jsCurrentCollection = str_replace("'", "\\'", $currentCollection);\r
523                         $jsFileName          = str_replace("'", "\\'", $contents[$i]->filename);\r
524                         $targetfile          = str_replace($Prefix_thumb, "", $jsFileName);\r
525                         /*-------kei append 2005.5.26-------*/\r
526                         $mediapath           = $DIR_MEDIA . $currentCollection."/";\r
527                         $thumb_file          = $Prefix_thumb . $targetfile;\r
528                         if (!$msg2) {\r
529                                 $thumb_targetfile = $thumb_file;\r
530                         }\r
531                         $thumb_exist = file_exists($mediapath . $thumb_file);\r
532                         /*Thumbnail*/\r
533 // <080213 shizuki add>\r
534                         $hscJsCC = htmlspecialchars($jsCurrentCollection);\r
535                         $hscTGTF = htmlspecialchars($targetfile);\r
536                         $hscTTGT = htmlspecialchars($thumb_targetfile);\r
537                         $hscJsFN = htmlspecialchars($jsFileName);\r
538                         $hscCCol = htmlspecialchars($currentCollection);\r
539                         $hscThFN = htmlspecialchars($thumb_file);\r
540                         $hscMEDA = htmlspecialchars($CONF['MediaURL']);\r
541 //      2008-02-21 cacher\r
542 //                      $hscMVEW = htmlspecialchars(_MEDIA_VIEW_TT);\r
543                         $hscMVEW = htmlspecialchars(_MEDIA_VIEW);\r
544                         $hscMVTT = htmlspecialchars(_MEDIA_VIEW_TT);\r
545 //      /2008-02-21 cacher\r
546                         $media26 = htmlspecialchars(_MEDIA_PHP_26);\r
547 // </080213 shizuki add>\r
548                         if ($filetype != 0 || $thumb_exist) {\r
549                                 // image (gif/jpg/png/swf)\r
550                                 $selectfile = $mediapath . $contents[$i]->filename;\r
551 //                              print "selectfile=$selectfile<BR />";\r
552                                 if (function_exists("ImageCreateFromGif")) {\r
553                                 $pattern = array( "/.wmv/" );\r
554                                 } else {\r
555                                 $pattern = array( "/.gif/", "/.wmv/" );\r
556                                 }\r
557                                 if (!$thumb_exist) {\r
558 //                                      $thumbfile2    = preg_replace($pattern,  ".png", $targetfile); //Extension conversion\r
559 //                                      $thumb_file    = $Prefix_thumb . $thumbfile2;\r
560                                         $thumb_file    = $Prefix_thumb . $targetfile . ".png";\r
561                                         $thumb_exist   = file_exists($mediapath . $thumb_file);\r
562                                         $notmake_thumb = 0;\r
563                                         /*Making is tried if there is no thumbnail.  */\r
564                                         if (!$thumb_exist) {\r
565                                                 $notmake_thumb = make_thumbnail($DIR_MEDIA, $currentCollection, $selectfile, $contents[$i]->filename);\r
566                                         }\r
567                                 }\r
568                                 if ($msg2) {\r
569                                         $thumb_file = $Prefix_thumb . $contents[$i]->filename;\r
570                                 }\r
571 \r
572 // <080213 shizuki add>\r
573                                 $hscThFN = htmlspecialchars($thumb_file);\r
574 // </080213 shizuki add>\r
575 //      2008-11-01 cacher\r
576                                 }\r
577                                 if (file_exists($mediapath . $thumb_file)) {\r
578 //      /2008-11-01 cacher\r
579 // <080213 mod by shizuki>\r
580 //                      echo "<div class=\"tmb\">\r
581 //                              <a href=\"media.php\" onclick=\"chooseImage('", htmlspecialchars($jsCurrentCollection), "','", htmlspecialchars($targetfile), "',"\r
582 //                   . "'", htmlspecialchars($width), "','" , htmlspecialchars($height), "'"\r
583 //                                 . ")\" onkeypress=\"chooseImage('", htmlspecialchars($jsCurrentCollection), "','", htmlspecialchars($targetfile), "',"\r
584 //                   . "'", htmlspecialchars($width), "','" , htmlspecialchars($height), "'"\r
585 //                                 . ")\" title=\"" . htmlspecialchars($targetfile). "\">\r
586 //                              <img src=\"../../../media/$currentCollection/$thumb_file\" alt=\"$targetfile\" /></a></div>\n";\r
587                                 echo <<<_DIVTHUMB_\r
588         <div class="tmb">\r
589                 <a href="media.php" onclick="chooseImage('{$hscJsCC}', '{$hscTGTF}', '{$width}', '{$height}')" onkeypress="chooseImage('{$hscJsCC}', '{$hscTGTF}', '{$width}', '{$height}')" title="{$hscTGTF}">\r
590                         <img src="{$hscMEDA}{$hscCCol}/{$hscThFN}" alt="{$hscTGTF}" /></a></div>\r
591 \r
592 _DIVTHUMB_;\r
593 //2008-02-21 Cacher\r
594 // </ 080213 mod by shizuki>\r
595                         } else {\r
596                                 // When you do not make the thumbnail with mpg and wmv, etc.\r
597 //      2008-11-01 cacher\r
598                                 $revname=strrev($filename);\r
599                                 $file_ext=strtoupper(strrev(substr($revname,0,strpos($revname,"."))));\r
600 // 2008-11-08 yama\r
601 //                              echo "\t<div class=\"tmb\">$file_ext</div>\n";\r
602                                 echo "\t<div class=\"media\">$file_ext</div>\n";\r
603 // /2008-11-08 yama\r
604 //      /2008-11-01 cacher\r
605                         }\r
606 //      2008-11-01 cacher\r
607                         echo "\t";\r
608                         if ($width||$height){\r
609                                 echo $width . ' x ' . $height;\r
610                         }\r
611 //                      echo "<br />\n\t(" . intval(filesize($filename)) . ")<br />\n\t"        //2008-11-06 cacher\r
612                         echo "<br />\n\t" . number_format(filesize($filename)/1024, 1)." KB<br />\n\t"\r
613                                 . date("Y-m-d", $contents[$i]->timestamp) . "<br class=\"clear\" />\n";\r
614 //      /2008-11-01 cacher\r
615                         /*File name and size*/\r
616                         //print "targetfile=$targetfile<BR />";\r
617                         if ($filetype != 0) {\r
618                                 // image (gif/jpg/png/swf)\r
619 // <080213 mod by shizuki>\r
620 //                              echo "<a href=\"media.php\" onclick=\"chooseImage('", htmlspecialchars($jsCurrentCollection), "','", htmlspecialchars($targetfile), "',"\r
621 //                                      . "'", htmlspecialchars($width), "','" , htmlspecialchars($height), "'"\r
622 //                                      . ")\" onkeypress=\"chooseImage('", htmlspecialchars($jsCurrentCollection), "','", htmlspecialchars($targetfile), "',"\r
623 //                                      . "'", htmlspecialchars($width), "','" , htmlspecialchars($height), "'"\r
624 //                                      . ")\" title=\"" . htmlspecialchars($targetfile). "\">"\r
625 // rem yama 20070928                                       . htmlspecialchars(shorten($targetfile,25,'...'))\r
626 //                                         . _MEDIA_PHP_26 //added yama 20070928\r
627 //                                         ."</a>";\r
628 //                         echo ' (<a href="', htmlspecialchars($CONF['MediaURL'] . $currentCollection . '/' . $targetfile), '" onclick="window.open(this.href); return false;" onkeypress="window.open(this.href); return false;" title="',htmlspecialchars(_MEDIA_VIEW_TT),'">',_MEDIA_VIEW,'</a>)';\r
629                         echo <<<_MEDIAPREVIEW_\r
630         <a href="media.php" onclick="chooseImage('{$hscJsCC}', '{$hscTGTF}', '{$width}', '{$height}')" onkeypress="chooseImage('{$hscJsCC}', '{$hscTGTF}', '{$width}', '{$height}')" title="{$hscTGTF}">\r
631                 {$media26}\r
632         </a>\r
633         (<a href="{$hscMEDA}{$hscCCol}/{$hscTGTF}" onclick="window.open(this.href); return false;" onkeypress="window.open(this.href); return false;" title="{$hscMVTT}">{$hscMVEW}</a>)\r
634 \r
635 _MEDIAPREVIEW_;\r
636 //2008-02-21 cacher\r
637 // </ 080213 mod by shizuki>\r
638                         } else {\r
639                         // not image (e.g. mpg)\r
640 // <080213 mod by shizuki>\r
641 //                      echo "<a href=\"media.php\" onclick=\"chooseOther('" , htmlspecialchars($jsCurrentCollection), "','", htmlspecialchars($targetfile), "'"\r
642 //                          . ")\" title=\"" . htmlspecialchars($targetfile). "\">"\r
643 //                          . htmlspecialchars(shorten($targetfile,30,'...'))\r
644 //                          ."</a>";\r
645 //                              $shortFN = htmlspecialchars(shorten($targetfile, 30, '...'));\r
646                                 echo <<<_MEDIAFILE_\r
647         <a href="media.php" onclick="chooseOther('{$hscJsCC}', '{$hscTGTF}')" onkeypress="chooseOther('{$hscJsCC}', '{$hscTGTF}')" title="{$hscTGTF}">\r
648                 {$media26}\r
649         </a>\r
650         (<a href="{$hscMEDA}{$hscCCol}/{$hscTGTF}" onclick="window.open(this.href); return false;" onkeypress="window.open(this.href); return false;" title="{$hscMVTT}">{$hscMVEW}</a>)\r
651 \r
652 _MEDIAFILE_;\r
653 // </080213 mod by shizuki>\r
654                         }\r
655 // <080213 mod by shizuki>\r
656 //              echo"<form method='post' action='media.php' style=\"margin:5px 0 2px;padding:0;\">\n\r
657 //                      <div>\r
658 //                      <input type='hidden' name='currentCollection' value='$currentCollection' />\r
659 //                      <input type='hidden' name='offset' value=\"$offset\" />\r
660 //                      <input type='hidden' name='targetfile' value=\"$targetfile\" />\r
661 //                      <input type ='hidden' name='targetthumb' value=\"$thumb_targetfile\" />\r
662 //                      <input type='text' name='newname' value=\"$targetfile\" size=\"24\" /><br />\r
663 //                      <input type='submit' name='myaction' value='"._MEDIA_PHP_3."' title='"._MEDIA_PHP_4."' onclick='return kakunin(this.value)' onkeypress='return kakunin(this.value)' style=\"margin-left:5px;\" />\n\r
664 //                      <input type='submit' name='myaction' value='"._MEDIA_PHP_1."' onclick='return kakunin(this.value)' onkeypress='return kakunin(this.value)' />\n\r
665 //                      </div>\r
666 //                      </form></div>\n";\r
667                         $media01 = htmlspecialchars(_MEDIA_PHP_1);\r
668                         $media03 = htmlspecialchars(_MEDIA_PHP_3);\r
669                         $media04 = htmlspecialchars(_MEDIA_PHP_4);\r
670                         echo <<<_FORMBLOCK_\r
671         <form method="post" action="media.php" style="margin:5px 0 2px; padding:0;">\r
672                 <div>\r
673                         <input type="hidden" name="currentCollection" value="{$hscCCol}" />\r
674                         <input type="hidden" name="offset" value="{$offset}" />\r
675                         <input type="hidden" name="targetfile" value="{$hscTGTF}" />\r
676                         <input type="hidden" name="targetthumb" value="{$hscTTGT}" />\r
677                         <input type="text"   name="newname" value="{$hscTGTF}" size="24" /><br />\r
678                         <input type="submit" name="myaction" value="{$media03}" title="{$media04}" onclick="return kakunin(this.value)" onkeypress="return kakunin(this.value)" style="margin-left:5px;" />\r
679                         <input type="submit" name="myaction" value="{$media01}" onclick="return kakunin(this.value)" onkeypress="return kakunin(this.value)" />\r
680                 </div>\r
681         </form>\r
682 </div>\r
683 \r
684 _FORMBLOCK_;\r
685 // </080213 mod by shizuki>\r
686                 }\r
687         } // if (sizeof($arr)>0) }\r
688         echo '<p class="clear">' . "\n";\r
689         if ($idxStart > 0 && $idxNext > 0) {\r
690                 echo "<a href='media.php?offset=" . intVal($idxStart-1) . "&amp;collection=" . urlencode($currentCollection) . "'>" . htmlspecialchars(_MEDIA_PHP_29) . "</a> ";\r
691         }\r
692         if ($idxStart < $maxpage) {\r
693                 echo "<a href='media.php?offset=" . intVal($idxStart+1) . "&amp;collection=" . urlencode($currentCollection) . "'>" . htmlspecialchars(_MEDIA_PHP_28) . "</a> ";\r
694         }\r
695 ?>\r
696         </p><form name="bottom" action="media.php" style="margin:5px;"><div>\r
697                 <?php echo htmlspecialchars(_MEDIA_PHP_11); ?> <input id="typeradio0b" type="radio" class="radio" name="typeradio" onclick="setType(0);document.top.typeradio[0].checked=true;" onkeypress="setType(0);document.top.typeradio[0].checked=true;" <?php echo $paste_mode_normal_checked; ?> /><label for="typeradio0b"><?php echo htmlspecialchars(_MEDIA_INLINE); ?></label>\r
698                 <input <?php echo $paste_mode_popup_checked; ?> id="typeradio1b" type="radio" class="radio" name="typeradio" onclick="setType(1);document.top.typeradio[0].checked=true;" onkeypress="setType(1);document.top.typeradio[0].checked=true;" /><label for="typeradio1b"><?php echo htmlspecialchars(_MEDIA_POPUP); ?></label>\r
699         </div></form>\r
700 \r
701 <?php\r
702         media_foot();\r
703 \r
704 \r
705 }\r
706 \r
707 /**\r
708   * Shows a screen where you can select the file to upload\r
709   */\r
710 function media_choose()\r
711 {\r
712         global $CONF, $member, $manager;\r
713 \r
714         $currentCollection = requestVar('collection');\r
715 \r
716         // start modify by T.Kosugi 2006/08/26\r
717 //      $collections = MEDIA::getCollectionList();\r
718         $collections = MEDIADIRS::getCollectionList();\r
719         // modify end\r
720 \r
721         media_head();\r
722 ?>\r
723         <h1><?php echo htmlspecialchars(_UPLOAD_TITLE); ?></h1>\r
724 \r
725         <p><?php echo htmlspecialchars(_UPLOAD_MSG); ?></p>\r
726 <!--//added yama 20070928-->\r
727         <?php echo _MEDIA_PHP_21; ?>\r
728 <!--//end yama 20070928-->\r
729 \r
730         <form method="post" enctype="multipart/form-data" action="media.php">\r
731         <div>\r
732           <input type="hidden" name="action" value="uploadfile" />\r
733           <?php $manager->addTicketHidden() ?>\r
734           <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo intVal($CONF['MaxUploadSize']); ?>" />\r
735           File:\r
736           <br />\r
737           <input name="uploadfile" type="file" size="40" />\r
738         <?php           if (sizeof($collections) > 1) {\r
739 ?>\r
740                 <br /><br /><label for="upload_collection">Collection:</label>\r
741                 <br /><select name="collection" id="upload_collection">\r
742                         <?php\r
743                                         foreach ($collections as $dirname => $description) {\r
744                                                 echo '<option value="' . htmlspecialchars($dirname) . '"';\r
745                                                 if ($dirname == $currentCollection) {\r
746                                                         echo ' selected="selected"';\r
747                                                 }\r
748                                                 echo '>' . htmlspecialchars($description) . '</option>';\r
749                                         }\r
750                         ?>\r
751                 </select>\r
752         <?php           } else {\r
753         ?>\r
754                 <input name="collection" type="hidden" value="<?php echo htmlspecialchars(requestVar('collection'))?>" />\r
755         <?php           } // if sizeof\r
756         ?>\r
757           <br /><br />\r
758           <input type="submit" value="<?php echo htmlspecialchars(_UPLOAD_BUTTON); ?>" />\r
759         </div>\r
760         </form>\r
761 <p><a href="javascript:history.back()"><?php echo htmlspecialchars(_BACK); ?></a></p>\r
762         <?php\r
763         media_foot();\r
764 }\r
765 \r
766 \r
767 /**\r
768   * accepts a file for upload\r
769   */\r
770 function media_upload()\r
771 {\r
772         global $DIR_MEDIA, $member, $CONF, $manager;\r
773 \r
774         $uploadInfo   = postFileInfo('uploadfile');\r
775 \r
776         $filename     = $uploadInfo['name'];\r
777         $filetype     = $uploadInfo['type'];\r
778         $filesize     = $uploadInfo['size'];\r
779         $filetempname = $uploadInfo['tmp_name'];\r
780         $fileerror    = intval($uploadInfo['error']);\r
781         $mediatocu    = $manager->getPlugin('NP_Mediatocu');\r
782 // added yama 20080131\r
783         if ($mediatocu->getOption('filename_rule') == "ascii") {\r
784                 $path_parts = pathinfo($filename);\r
785                 $filename   = time() . "." . $path_parts['extension'];\r
786         }\r
787 // end\r
788         \r
789         switch ($fileerror) {\r
790                 case 0: // = UPLOAD_ERR_OK\r
791                         break;\r
792                 case 1: // = UPLOAD_ERR_INI_SIZE\r
793                 case 2: // = UPLOAD_ERR_FORM_SIZE\r
794                         media_doError(_ERROR_FILE_TOO_BIG);\r
795                         break;\r
796                 case 3: // = UPLOAD_ERR_PARTIAL\r
797                 case 4: // = UPLOAD_ERR_NO_FILE\r
798                 case 6: // = UPLOAD_ERR_NO_TMP_DIR\r
799                 case 7: // = UPLOAD_ERR_CANT_WRITE\r
800                 default:\r
801                         // include error code for debugging\r
802                         // (see http://www.php.net/manual/en/features.file-upload.errors.php)\r
803                         media_doError(_ERROR_BADREQUEST . ' (' . $fileerror . ')');\r
804                         break;\r
805         }\r
806 \r
807         // T.Kosugi add 2006.9.1\r
808         if (stristr($filename, '%00')) {\r
809                 media_doError(_MEDIA_PHP_38);\r
810         }\r
811         // T.Kosugi add end\r
812         if ($filesize > $CONF['MaxUploadSize']) {\r
813                 media_doError(_ERROR_FILE_TOO_BIG);\r
814         }\r
815 \r
816         // check file type against allowed types\r
817         $ok           = 0;\r
818         $allowedtypes = explode (',', $CONF['AllowedTypes']);\r
819         foreach ( $allowedtypes as $type ) {\r
820                 if (eregi("\." .$type. "$",$filename)) {\r
821                         $ok = 1;\r
822                 }\r
823         }\r
824         if (!$ok) {\r
825                 media_doError(_ERROR_BADFILETYPE);\r
826         }\r
827 \r
828         if (!is_uploaded_file($filetempname)) {\r
829                 media_doError(_ERROR_BADREQUEST);\r
830         }\r
831 \r
832         // prefix filename with current date (YYYY-MM-DD-)\r
833         // this to avoid nameclashes\r
834         if ($CONF['MediaPrefix']) {\r
835                 $filename = strftime("%Y%m%d-", time()) . $filename;\r
836         }\r
837 \r
838         $collection = requestVar('collection');\r
839         $res        = MEDIA::addMediaObject($collection, $filetempname, $filename);\r
840 \r
841         if ($res != '') {\r
842                 media_doError($res);\r
843         }\r
844         $uppath = $DIR_MEDIA.$collection . "/";\r
845         $upfile = $DIR_MEDIA.$collection . "/" . $filename;\r
846 \r
847         $res    = move_uploaded_file($filetempname, $upfile);\r
848         if ($res != '') {\r
849           media_doError($res);\r
850         }\r
851 \r
852         make_thumbnail($DIR_MEDIA, $collection, $upfile, $filename);\r
853 \r
854         // shows updated list afterwards\r
855         media_select();\r
856 }\r
857 /**\r
858   * accepts a dirname for mkdir\r
859   * added by T.Kosugi 2006/08/27\r
860   *\r
861   */\r
862 function media_mkdir($action)\r
863 {\r
864         global $DIR_MEDIA, $member, $CONF, $manager;\r
865         if ($action == _MEDIA_PHP_ACTION_MKDIR || $action =='mkdir' ) {\r
866                 $current   = requestVar('mkdir_collection');\r
867                 $mkdirname = postVar('mkdirname');\r
868                 if (!($mkdirname && $current)) {\r
869                         media_select();\r
870                         return;\r
871                 }\r
872                 if (is_numeric($current) && !is_dir($DIR_MEDIA . '/' . $current)) {\r
873                         $oldumask = umask(0000);\r
874                         if (!@mkdir($DIR_MEDIA. '/' . $current, 0777)) {\r
875                                 return _ERROR_BADPERMISSIONS;\r
876                         }\r
877                         umask($oldumask);\r
878                 }\r
879                 $path      = $current . '/' . $mkdirname ;\r
880                 $pathArray = explode('/', $path);\r
881                 if ($pathArray[0] !== $member->getID()) {\r
882                         media_doError(_MEDIA_PHP_39 . $pathArray[0] . ':' . $member->getID());\r
883                 }\r
884                 if (in_array('..', $pathArray)) {\r
885                         media_doError(_MEDIA_PHP_40);\r
886                 }\r
887 \r
888                 if (is_dir($DIR_MEDIA . '/' . $current)) {\r
889                         $res = @mkdir($DIR_MEDIA . '/' . $current . '/' . $mkdirname);\r
890                         $res .= @chmod($DIR_MEDIA . '/' . $current . '/' . $mkdirname , 0777);\r
891                 }\r
892                 if (!$res) {\r
893                         media_doError(_MEDIA_PHP_41 . $res );\r
894                 }\r
895                 // shows updated list afterwards\r
896                 media_select();\r
897         } elseif($action == _MEDIA_PHP_ACTION_RMDIR ||\r
898                          $action == 'rmdir') {\r
899                 $rmdir_collection = postVar('rmdir_collection');\r
900                 $pathArray        = explode('/', $rmdir_collection);\r
901                 if ($pathArray[0] !== $member->getID()) {\r
902                         media_doError(_MEDIA_PHP_39 . $pathArray[0] . ':' . $member->getID());\r
903                 }\r
904                 if (in_array('..', $pathArray)) {\r
905                         media_doError(_MEDIA_PHP_40);\r
906                 }\r
907                 $rmdir = $DIR_MEDIA . $rmdir_collection;\r
908                 $res   = @rmdir($rmdir);\r
909                 if ($res) {\r
910                         media_select();\r
911                 } else {\r
912                         media_doError(_MEDIA_PHP_42);\r
913                 }\r
914         } else {\r
915                 $current     = requestVar('collection');\r
916                 $collections = MEDIADIRS::getPrivateCollectionList();\r
917 \r
918                 media_head();\r
919                 ?>\r
920                 <h1><?php echo htmlspecialchars(_MEDIA_MKDIR_TITLE); ?></h1>\r
921 \r
922                 <p><?php echo htmlspecialchars(_MEDIA_MKDIR_MSG); ?></p>\r
923 \r
924                 <form method="post" action="media.php">\r
925                 <div>\r
926                   <input type="hidden" name="action" value="<?php echo htmlspecialchars(_MEDIA_PHP_ACTION_MKDIR); ?>" />\r
927                   <?php $manager->addTicketHidden() ?>\r
928                   FolderName:\r
929                   <br />\r
930                   <input name="mkdirname" type="text" size="40" />\r
931                 <?php           if (sizeof($collections) > 0) {\r
932                 ?>\r
933                         <br /><br /><label for="mkdir_collection">Collection:</label>\r
934                         <br /><select name="mkdir_collection" id="mkdir_collection">\r
935                                 <?php\r
936                                                 foreach ($collections as $dirname => $description) {\r
937                                                         echo '<option value="',htmlspecialchars($dirname),'"';\r
938                                                         if ($dirname == $current) {\r
939                                                                 echo ' selected="selected"';\r
940                                                         }\r
941                                                         echo '>' . htmlspecialchars($description) . '</option>';\r
942                                                 }\r
943                                 ?>\r
944                         </select>\r
945                 <?php           } elseif (sizeof($collections) == 1) {\r
946                                                 $flipCollections = array_flip($collections);\r
947                                                 $collection = array_pop($flipCollections);\r
948                 ?>\r
949                         <input name="collection" type="hidden" value="<?php echo htmlspecialchars($collection);?>" />\r
950                 <?php           } else {\r
951                                                 media_foot();\r
952                                                 return;\r
953                                         }// if sizeof\r
954                 ?>\r
955                   <br /><br />\r
956                   <input type="submit" value="<?php echo htmlspecialchars(_MEDIA_MKDIR_BUTTON); ?>" />\r
957                 </div>\r
958                 </form>\r
959                 <?php           if (sizeof($collections) > 0) {?>\r
960                         <br /><br /><h1><?php echo htmlspecialchars(_MEDIA_RMDIR_TITLE); ?></h1>\r
961 \r
962                 <p><?php echo htmlspecialchars(_MEDIA_RMDIR_MSG); ?></p>\r
963 \r
964                 <form method="post" action="media.php">\r
965                 <div>\r
966                   <input type="hidden" name="action" value="<?php echo htmlspecialchars(_MEDIA_PHP_ACTION_RMDIR); ?>" />\r
967 \r
968         <label for="rmdir_collection">Collection:</label>\r
969                         <br /><select name="rmdir_collection" id="rmdir_collection">\r
970                                 <?php\r
971                                         foreach ($collections as $dirname => $description) {\r
972                                                 if (is_numeric($dirname)) continue;\r
973                                                 echo '<option value="',htmlspecialchars($dirname),'"';\r
974                                                 if ($dirname == $current) {\r
975                                                         echo ' selected="selected"';\r
976                                                 }\r
977                                                 echo '>',htmlspecialchars($description),'</option>';\r
978                                         }\r
979                                 ?>\r
980                         </select>\r
981                 <?php           } else {\r
982                                                 media_foot();\r
983                                                 return;\r
984                                         }// if sizeof\r
985                 ?>\r
986                   <br /><br />\r
987                   <?php $manager->addTicketHidden() ?>\r
988                   <input type="submit" value="<?php echo htmlspecialchars(_MEDIA_RMDIR_BUTTON); ?>" />\r
989                 </div>\r
990                 </form>\r
991                 <p><a href="javascript:history.back()"><?php echo htmlspecialchars(_BACK); ?></a></p>\r
992                 <?php\r
993                 media_foot();\r
994         }\r
995 }\r
996 \r
997 function make_thumbnail($DIR_MEDIA, $collection, $upfile, $filename)\r
998 {\r
999 \r
1000     global $Prefix_thumb;\r
1001 \r
1002     /*\r
1003     print "DIR_MEDIA=$DIR_MEDIA<BR />";\r
1004     print "collection=$collection<BR />";\r
1005     print "upfile=$upfile<BR />";\r
1006     */\r
1007     //print "filename=$filename<BR />\n";\r
1008     // Thumbnail image size specification\r
1009 \r
1010 //mod yama\r
1011         global $manager;\r
1012         $mediatocu  = $manager->getPlugin('NP_Mediatocu');\r
1013         $thumb_w    = intVal($mediatocu->getOption('thumb_width'));\r
1014         $thumb_h    = intVal($mediatocu->getOption('thumb_height'));\r
1015         $quality    = intVal($mediatocu->getOption('thumb_quality'));\r
1016 //end yama\r
1017     $size       = getimagesize($upfile);\r
1018     $thumb_file = "{$DIR_MEDIA}{$collection}/{$Prefix_thumb}{$filename}";\r
1019     // Resize rate\r
1020     $moto_w = $size[0];\r
1021     $moto_h = $size[1];\r
1022     if ($moto_w > $thumb_w || $moto_h > $thumb_h) {\r
1023       $ritu_w = $thumb_w /$moto_w;\r
1024       $ritu_h = $thumb_h /$moto_h;\r
1025       ($ritu_w < $ritu_h) ? $cv_ritu = $ritu_w : $cv_ritu = $ritu_h;\r
1026       $w = ceil($moto_w * $cv_ritu);\r
1027       $h = ceil($moto_h * $cv_ritu);\r
1028     }\r
1029 \r
1030     if ($w && $h) {\r
1031       // Making preservation of thumbnail image\r
1032       thumb_gd($upfile, $thumb_file, $w, $h, $size, $quality); //GD version\r
1033     } else {\r
1034       //There is no necessity about the resize. \r
1035       thumb_gd($upfile, $thumb_file, $moto_w, $moto_h, $size, $quality); //GD version\r
1036     }\r
1037 }\r
1038 \r
1039 \r
1040 //Thumbnail making(GD)\r
1041 function thumb_gd($fname, $thumbfile, $out_w, $out_h, $size, $quality)\r
1042 {\r
1043         switch ($size[2]) {\r
1044                 case 1 ://.gif(or .png)\r
1045                         if (function_exists("ImageCreateFromGif")) {\r
1046                                 $img_in = @ImageCreateFromGIF($fname);\r
1047                         } else {\r
1048                                 $fname  = str_replace( ".gif", ".png", $fname); //Extension conversion\r
1049                                 $img_in = @ImageCreateFromPng($fname);\r
1050                         }\r
1051                         break;\r
1052                 case 2 ://.jpg\r
1053                         $img_in = @ImageCreateFromJPEG($fname);\r
1054                         break;\r
1055                 case 3 ://.png\r
1056                         $img_in = @ImageCreateFromPng($fname);\r
1057                         break;\r
1058                 default :\r
1059                         return;\r
1060         }\r
1061         if (!$img_in) {\r
1062                 return;\r
1063         }\r
1064         //print "im_in=$img_in<BR />";\r
1065         $img_out = ImageCreateTrueColor($out_w, $out_h);\r
1066         //Former image is copied and the thumbnail is made.\r
1067         ImageCopyResampled($img_out, $img_in, 0, 0, 0, 0, $out_w, $out_h, $size[0], $size[1]);\r
1068         //Preservation of thumbnail image\r
1069         switch ($size[2]) {\r
1070                 case 1 ://.gif\r
1071                         ImageGif($img_out, $thumbfile);\r
1072                         break;\r
1073                 case 2 ://.jpg\r
1074                         ImageJpeg($img_out, $thumbfile, $quality);\r
1075                         break;\r
1076                 case 3 ://.png\r
1077                         ImagePng($img_out, $thumbfile);\r
1078                         break;\r
1079         }\r
1080         //The memory that maintains the making image is liberated. \r
1081         imagedestroy($img_in);\r
1082         imagedestroy($img_out);\r
1083 }\r
1084 \r
1085 function media_loginAndPassThrough()\r
1086 {\r
1087         media_head();\r
1088         ?>\r
1089                 <h1><?php echo _LOGIN_PLEASE?></h1>\r
1090 \r
1091                 <form method="post" action="media.php">\r
1092                 <div>\r
1093                         <input name="action" value="login" type="hidden" />\r
1094                         <input name="collection" value="<?php echo htmlspecialchars(requestVar('collection')); ?>" type="hidden" />\r
1095                         <?php echo htmlspecialchars(_LOGINFORM_NAME); ?>: <input name="login" />\r
1096                         <br /><?php echo htmlspecialchars(_LOGINFORM_PWD); ?>: <input name="password" type="password" />\r
1097                         <br /><input type="submit" value="<?php echo htmlspecialchars(_LOGIN); ?>" />\r
1098                 </div>\r
1099                 </form>\r
1100                 <p><a href="media.php" onclick="window.close();"><?php echo htmlspecialchars(_POPUP_CLOSE); ?></a></p>\r
1101         <?php   media_foot();\r
1102         exit;\r
1103 }\r
1104 \r
1105 function media_doError($msg)\r
1106 {\r
1107         media_head();\r
1108         ?>\r
1109         <h1><?php echo htmlspecialchars(_ERROR); ?></h1>\r
1110         <p><?php echo htmlspecialchars($msg); ?></p>\r
1111         <p><a href="javascript:history.back()"><?php echo htmlspecialchars(_BACK); ?></a></p>\r
1112         <?php   media_foot();\r
1113         exit;\r
1114 }\r
1115 \r
1116 \r
1117 function media_head()\r
1118 {\r
1119         global $manager, $CONF;\r
1120         $mediatocu = $manager->getPlugin('NP_Mediatocu');\r
1121         $thumb_w   = intVal($mediatocu->getOption('thumb_width'));\r
1122         $thumb_h   = intVal($mediatocu->getOption('thumb_height'));\r
1123         if ($mediatocu->getOption('paste_mode_checked') == "yes") {\r
1124                 $setType = "1";\r
1125         } else {\r
1126                 $setType = "0";\r
1127         }\r
1128         $GreyBox   = $mediatocu->getOption('use_gray_box');\r
1129 ?>\r
1130 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\r
1131 <html xmlns="http://www.w3.org/1999/xhtml">\r
1132 <head>\r
1133                 <meta http-equiv="Content-Type" content="text/html; charset=<?php echo htmlspecialchars(_CHARSET); ?>" />\r
1134                 <meta http-equiv="Content-Script-Type" content="text/javascript" />\r
1135                 <meta http-equiv="Content-Style-Type" content="text/css" />\r
1136                 <title>Mediatocu</title>\r
1137                 <link rel="stylesheet" type="text/css" href="popups.css" />\r
1138 <?php\r
1139                 if ($manager->pluginInstalled('NP_TinyMCE')) {\r
1140                         $tinyMCE = $manager->getPlugin('NP_TinyMCE');\r
1141 ?>\r
1142                 <script language="javascript" type="text/javascript" src="<?php echo $tinyMCE->getAdminURL(); ?>jscripts/tiny_mce/tiny_mce_popup.js"></script>\r
1143 <?php\r
1144                 }\r
1145 ?>\r
1146                 <script type="text/javascript">\r
1147                         var type = <?php echo intVal($setType); ?>;\r
1148                         function setType(val) { type = val; }\r
1149 \r
1150                         function chooseImage(collection, filename, width, height) {\r
1151 <?php\r
1152                 if ($manager->pluginInstalled('NP_TinyMCE')) {\r
1153 ?>\r
1154                                 var win = tinyMCEPopup.getWindowArg("w_n");\r
1155                                 var file_path = "<?php echo $CONF['MediaURL']; ?>" + collection + "/" + filename;\r
1156                                 win.document.getElementById(tinyMCEPopup.getWindowArg("f_n")).value = file_path;\r
1157                                 if (tinyMCEPopup.getWindowArg("file_type") == "image") {\r
1158                                         if (win.ImageDialog.getImageData) win.ImageDialog.getImageData();\r
1159                                         if (win.ImageDialog.showPreviewImage) win.ImageDialog.showPreviewImage(file_path);\r
1160                                 }\r
1161                                 tinyMCEPopup.close();\r
1162 <?php\r
1163                 } elseif ($GreyBox == 'yes') {\r
1164 ?>\r
1165                                 top.window.focus();\r
1166                                 top.window.includeImage(collection,\r
1167                                                                                    filename,\r
1168                                                                                    type == 0 ? 'inline' : 'popup',\r
1169                                                                                    width,\r
1170                                                                                    height\r
1171                                                                                    );\r
1172                                 top.window.GB_hide();\r
1173 <?php\r
1174                 } else {\r
1175 ?>\r
1176                                 top.opener.focus();\r
1177                                 top.opener.includeImage(collection,\r
1178                                                                                    filename,\r
1179                                                                                    type == 0 ? 'inline' : 'popup',\r
1180                                                                                    width,\r
1181                                                                                    height\r
1182                                                                                    );\r
1183                                 window.close();\r
1184 <?php\r
1185                 }\r
1186 ?>\r
1187                         }\r
1188 \r
1189                         function chooseOther(collection, filename) {\r
1190 <?php\r
1191                 if ($manager->pluginInstalled('NP_TinyMCE')) {\r
1192 ?>\r
1193                                 var win = tinyMCEPopup.getWindowArg("w_n");\r
1194                                 var file_path = "<?php echo $CONF['MediaURL']; ?>" + collection + "/" + filename;\r
1195                                 win.document.getElementById(tinyMCEPopup.getWindowArg("f_n")).value = file_path;\r
1196                                 tinyMCEPopup.close();\r
1197 <?php\r
1198                 } elseif ($GreyBox == 'yes') {\r
1199 ?>\r
1200                                 top.window.focus();\r
1201                                 top.window.includeOtherMedia(collection, filename);\r
1202                                 top.window.GB_hide();\r
1203 <?php\r
1204                 } else {\r
1205 ?>\r
1206                                 top.opener.focus();\r
1207                                 top.opener.includeOtherMedia(collection, filename);\r
1208                                 window.close();\r
1209 <?php\r
1210                 }\r
1211 ?>\r
1212                         }\r
1213 \r
1214                         function kakunin(value){\r
1215                                 res=confirm('<?php echo htmlspecialchars(_MEDIA_PHP_8); ?>'+value+'<?php echo htmlspecialchars(_MEDIA_PHP_9); ?>');\r
1216                                 return res;\r
1217                         }\r
1218                 </script>\r
1219 \r
1220         <style type="text/css">\r
1221 /* 2008-11-08 yama*/\r
1222                 div.tmb, div.media {\r
1223 /* /2008-11-08 yama*/\r
1224                         margin : 0px;\r
1225                         padding : 0px;\r
1226                         width : <?php echo $thumb_w ?>px;\r
1227                         height : <?php echo $thumb_h ?>px;\r
1228                         line-height : <?php echo $thumb_h ?>px;\r
1229                         float : left;\r
1230                         display : inline;\r
1231 /* 2008-11-08 yama*/\r
1232                         border : 1px solid #999;\r
1233 /* /2008-11-08 yama*/\r
1234                         text-align : center;\r
1235                 }\r
1236 /* 2008-11-08 yama*/\r
1237                 div.tmb {\r
1238                         background-image: url("bg.gif");\r
1239                 }\r
1240                 div.media {\r
1241                         background-color: #fff;\r
1242                 }\r
1243                 div.tmb a, div.media a {\r
1244 /* /2008-11-08 yama*/\r
1245                         width : <?php echo $thumb_w ?>px;\r
1246                         height : <?php echo $thumb_h ?>px;\r
1247                         display : block;\r
1248                 }\r
1249         </style>\r
1250         \r
1251         <base target="_self" />\r
1252                 \r
1253 </head>\r
1254 <body>\r
1255 <?php\r
1256 }\r
1257 \r
1258 function media_foot()\r
1259 {\r
1260 ?>\r
1261 </body>\r
1262 </html>\r
1263 <?php\r
1264 }\r
1265 \r
1266 ?>\r