3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
4 * Copyright (C) 2002-2005 The Nucleus Group
\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
13 * Media popup window for Nucleus
\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
22 * @license http://nucleuscms.org/license.txt GNU General Public License
\r
23 * @copyright Copyright (C) 2002-2005 The Nucleus Group
\r
24 * @version $Id: media.php,v 1.5 2005-08-13 07:33:45 kimitake Exp $
\r
25 * $NucleusJP: media.php,v 1.4 2005/03/16 07:55:04 kimitake Exp $
\r
31 // defines how much media items will be shown per page. You can override this
\r
32 // in config.php if you like. (changing it in config.php instead of here will
\r
33 // allow your settings to be kept even after a Nucleus upgrade)
\r
34 $CONF['MediaPerPage'] = 10;
\r
36 // include all classes and config data
\r
37 include('../config.php');
\r
38 include($DIR_LIBS . 'MEDIA.php'); // media classes
\r
40 sendContentType('application/xhtml+xml', 'media');
\r
42 // user needs to be logged in to use this
\r
43 if (!$member->isLoggedIn()) {
\r
44 media_loginAndPassThrough();
\r
48 // check if member is on at least one teamlist
\r
49 $query = 'SELECT * FROM ' . sql_table('team'). ' WHERE tmember=' . $member->getID();
\r
50 $teams = mysql_query($query);
\r
51 if (mysql_num_rows($teams) == 0)
\r
52 media_doError(_ERROR_DISALLOWEDUPLOAD);
\r
55 $action = requestVar('action');
\r
57 $action = 'selectmedia';
\r
60 $aActionsNotToCheck = array('selectmedia', _MEDIA_FILTER_APPLY, _MEDIA_COLLECTION_SELECT);
\r
61 if (!in_array($action, $aActionsNotToCheck))
\r
63 if (!$manager->checkTicket())
\r
64 media_doError(_ERROR_BADTICKET);
\r
69 case 'chooseupload':
\r
70 case _MEDIA_UPLOAD_TO:
\r
71 case _MEDIA_UPLOAD_NEW:
\r
77 case _MEDIA_FILTER_APPLY:
\r
79 case _MEDIA_COLLECTION_SELECT:
\r
86 function media_select() {
\r
87 global $member, $CONF, $DIR_MEDIA, $manager;
\r
91 // show 10 files + navigation buttons
\r
92 // show msg when no files
\r
94 // files sorted according to last modification date
\r
96 // currently selected collection
\r
97 $currentCollection = requestVar('collection');
\r
98 if (!$currentCollection || !@is_dir($DIR_MEDIA . $currentCollection))
\r
99 $currentCollection = $member->getID();
\r
102 // get collection list
\r
103 $collections = MEDIA::getCollectionList();
\r
105 if (sizeof($collections) > 1) {
\r
107 <form method="post" action="media.php"><div>
\r
108 <label for="media_collection"><?php echo htmlspecialchars(_MEDIA_COLLECTION_LABEL)?></label>
\r
109 <select name="collection" id="media_collection">
\r
110 <?php foreach ($collections as $dirname => $description) {
\r
111 echo '<option value="',htmlspecialchars($dirname),'"';
\r
112 if ($dirname == $currentCollection) {
\r
113 echo ' selected="selected"';
\r
115 echo '>',htmlspecialchars($description),'</option>';
\r
119 <input type="submit" name="action" value="<?php echo htmlspecialchars(_MEDIA_COLLECTION_SELECT) ?>" title="<?php echo htmlspecialchars(_MEDIA_COLLECTION_TT)?>" />
\r
120 <input type="submit" name="action" value="<?php echo htmlspecialchars(_MEDIA_UPLOAD_TO) ?>" title="<?php echo htmlspecialchars(_MEDIA_UPLOADLINK) ?>" />
\r
121 <?php $manager->addTicketHidden() ?>
\r
125 <form method="post" action="media.php" style="float:right"><div>
\r
126 <input type="hidden" name="collection" value="<?php echo htmlspecialchars($currentCollection)?>" />
\r
127 <input type="submit" name="action" value="<?php echo htmlspecialchars(_MEDIA_UPLOAD_NEW) ?>" title="<?php echo htmlspecialchars(_MEDIA_UPLOADLINK) ?>" />
\r
128 <?php $manager->addTicketHidden() ?>
\r
130 <?php } // if sizeof
\r
132 $filter = requestVar('filter');
\r
133 $offset = intRequestVar('offset');
\r
134 $arr = MEDIA::getMediaListByCollection($currentCollection, $filter);
\r
137 <form method="post" action="media.php"><div>
\r
138 <label for="media_filter"><?php echo htmlspecialchars(_MEDIA_FILTER_LABEL)?></label>
\r
139 <input id="media_filter" type="text" name="filter" value="<?php echo htmlspecialchars($filter)?>" />
\r
140 <input type="submit" name="action" value="<?php echo htmlspecialchars(_MEDIA_FILTER_APPLY) ?>" />
\r
141 <input type="hidden" name="collection" value="<?php echo htmlspecialchars($currentCollection)?>" />
\r
142 <input type="hidden" name="offset" value="<?php echo intval($offset)?>" />
\r
148 <table width="100%">
\r
149 <caption><?php echo _MEDIA_COLLECTION_LABEL . htmlspecialchars($collections[$currentCollection])?></caption>
\r
151 <th><?php echo _MEDIA_MODIFIED?></th><th><?php echo _MEDIA_FILENAME?></th><th><?php echo _MEDIA_DIMENSIONS?></th>
\r
156 if (sizeof($arr)>0) {
\r
158 if (($offset + $CONF['MediaPerPage']) >= sizeof($arr))
\r
159 $offset = sizeof($arr) - $CONF['MediaPerPage'];
\r
161 if ($offset < 0) $offset = 0;
\r
163 $idxStart = $offset;
\r
164 $idxEnd = $offset + $CONF['MediaPerPage'];
\r
165 $idxNext = $idxEnd;
\r
166 $idxPrev = $idxStart - $CONF['MediaPerPage'];
\r
168 if ($idxPrev < 0) $idxPrev = 0;
\r
170 if ($idxEnd > sizeof($arr))
\r
171 $idxEnd = sizeof($arr);
\r
173 for($i=$idxStart;$i<$idxEnd;$i++) {
\r
175 $filename = $DIR_MEDIA . $currentCollection . '/' . $obj->filename;
\r
177 $old_level = error_reporting(0);
\r
178 $size = @GetImageSize($filename);
\r
179 error_reporting($old_level);
\r
181 $height = $size[1];
\r
182 $filetype = $size[2];
\r
185 echo "<td>". date("Y-m-d",$obj->timestamp) ."</td>";
\r
187 // strings for javascript
\r
188 $jsCurrentCollection = str_replace("'","\\'",$currentCollection);
\r
189 $jsFileName = str_replace("'","\\'",$obj->filename);
\r
191 if ($filetype != 0) {
\r
192 // image (gif/jpg/png/swf)
\r
193 echo "<td><a href=\"media.php\" onclick=\"chooseImage('", htmlspecialchars($jsCurrentCollection), "','", htmlspecialchars($jsFileName), "',"
\r
194 . "'", htmlspecialchars($width), "','" , htmlspecialchars($height), "'"
\r
195 . ")\" title=\"" . htmlspecialchars($obj->filename). "\">"
\r
196 . htmlspecialchars(shorten($obj->filename,25,'...'))
\r
198 echo ' (<a href="', htmlspecialchars($CONF['MediaURL'] . $currentCollection . '/' . $obj->filename), '" onclick="window.open(this.href); return false;" title="',htmlspecialchars(_MEDIA_VIEW_TT),'">',_MEDIA_VIEW,'</a>)';
\r
201 // no image (e.g. mpg)
\r
202 echo "<td><a href='media.php' onclick=\"chooseOther('" , htmlspecialchars($jsCurrentCollection), "','", htmlspecialchars($jsFileName), "'"
\r
203 . ")\" title=\"" . htmlspecialchars($obj->filename). "\">"
\r
204 . htmlspecialchars(shorten($obj->filename,30,'...'))
\r
208 echo '<td>' , htmlspecialchars($width) , 'x' , htmlspecialchars($height) , '</td>';
\r
211 } // if (sizeof($arr)>0)
\r
217 echo "<a href='media.php?offset=$idxPrev&collection=".urlencode($currentCollection)."'>". _LISTS_PREV."</a> ";
\r
218 if ($idxEnd < sizeof($arr))
\r
219 echo "<a href='media.php?offset=$idxNext&collection=".urlencode($currentCollection)."'>". _LISTS_NEXT."</a> ";
\r
222 <input id="typeradio0" type="radio" name="typeradio" onclick="setType(0);" checked="checked" /><label for="typeradio0"><?php echo _MEDIA_INLINE?></label>
\r
223 <input id="typeradio1" type="radio" name="typeradio" onclick="setType(1);" /><label for="typeradio1"><?php echo _MEDIA_POPUP?></label>
\r
231 * Shows a screen where you can select the file to upload
\r
233 function media_choose() {
\r
234 global $CONF, $member, $manager;
\r
236 $currentCollection = requestVar('collection');
\r
238 $collections = MEDIA::getCollectionList();
\r
242 <h1><?php echo _UPLOAD_TITLE?></h1>
\r
244 <p><?php echo _UPLOAD_MSG?></p>
\r
246 <form method="post" enctype="multipart/form-data" action="media.php">
\r
248 <input type="hidden" name="action" value="uploadfile" />
\r
249 <?php $manager->addTicketHidden() ?>
\r
250 <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $CONF['MaxUploadSize']?>" />
\r
253 <input name="uploadfile" type="file" size="40" />
\r
254 <?php if (sizeof($collections) > 1) {
\r
256 <br /><br /><label for="upload_collection">Collection:</label>
\r
257 <br /><select name="collection" id="upload_collection">
\r
258 <?php foreach ($collections as $dirname => $description) {
\r
259 echo '<option value="',htmlspecialchars($dirname),'"';
\r
260 if ($dirname == $currentCollection) {
\r
261 echo ' selected="selected"';
\r
263 echo '>',htmlspecialchars($description),'</option>';
\r
269 <input name="collection" type="hidden" value="<?php echo htmlspecialchars(requestVar('collection'))?>" />
\r
270 <?php } // if sizeof
\r
273 <input type="submit" value="<?php echo _UPLOAD_BUTTON?>" />
\r
283 * accepts a file for upload
\r
285 function media_upload() {
\r
286 global $DIR_MEDIA, $member, $CONF;
\r
288 $uploadInfo = postFileInfo('uploadfile');
\r
290 $filename = $uploadInfo['name'];
\r
291 $filetype = $uploadInfo['type'];
\r
292 $filesize = $uploadInfo['size'];
\r
293 $filetempname = $uploadInfo['tmp_name'];
\r
295 if ($filesize > $CONF['MaxUploadSize'])
\r
296 media_doError(_ERROR_FILE_TOO_BIG);
\r
298 // check file type against allowed types
\r
300 $allowedtypes = explode (',', $CONF['AllowedTypes']);
\r
301 foreach ( $allowedtypes as $type )
\r
302 if (eregi("\." .$type. "$",$filename)) $ok = 1;
\r
303 if (!$ok) media_doError(_ERROR_BADFILETYPE);
\r
305 if (!is_uploaded_file($filetempname))
\r
306 media_doError(_ERROR_BADREQUEST);
\r
308 // prefix filename with current date (YYYY-MM-DD-)
\r
309 // this to avoid nameclashes
\r
310 if ($CONF['MediaPrefix'])
\r
311 $filename = strftime("%Y%m%d-", time()) . $filename;
\r
313 $collection = requestVar('collection');
\r
314 $res = MEDIA::addMediaObject($collection, $filetempname, $filename);
\r
317 media_doError($res);
\r
319 // shows updated list afterwards
\r
323 function media_loginAndPassThrough() {
\r
326 <h1><?php echo _LOGIN_PLEASE?></h1>
\r
328 <form method="post" action="media.php">
\r
330 <input name="action" value="login" type="hidden" />
\r
331 <input name="collection" value="<?php echo htmlspecialchars(requestVar('collection'))?>" type="hidden" />
\r
332 <?php echo _LOGINFORM_NAME?>: <input name="login" />
\r
333 <br /><?php echo _LOGINFORM_PWD?>: <input name="password" type="password" />
\r
334 <br /><input type="submit" value="<?php echo _LOGIN?>" />
\r
337 <p><a href="media.php" onclick="window.close();"><?php echo _POPUP_CLOSE?></a></p>
\r
338 <?php media_foot();
\r
342 function media_doError($msg) {
\r
345 <h1><?php echo _ERROR?></h1>
\r
346 <p><?php echo $msg?></p>
\r
347 <p><a href="media.php" onclick="history.back()"><?php echo _BACK?></a></p>
\r
348 <?php media_foot();
\r
353 function media_head() {
\r
355 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
\r
356 <html xmlns="http://www.w3.org/1999/xhtml">
\r
358 <meta http-equiv="Content-Type" content="text/html; charset=<?php echo _CHARSET ?>" />
\r
359 <title>Nucleus Media</title>
\r
360 <link rel="stylesheet" type="text/css" href="styles/popups.css" />
\r
361 <script type="text/javascript">
\r
363 function setType(val) { type = val; }
\r
365 function chooseImage(collection, filename, width, height) {
\r
366 window.opener.focus();
\r
367 window.opener.includeImage(collection,
\r
369 type == 0 ? 'inline' : 'popup',
\r
376 function chooseOther(collection, filename) {
\r
377 window.opener.focus();
\r
378 window.opener.includeOtherMedia(collection, filename);
\r
387 function media_foot() {
\r