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
12 * Media popup window for Nucleus
\r
15 * - can be openen from an add-item form or bookmarklet popup
\r
16 * - shows a list of recent files, allowing browsing, search and
\r
17 * upload of new files
\r
18 * - close the popup by selecting a file in the list. The file gets
\r
19 * passed through to the add-item form (linkto, popupimg or inline img)
\r
21 * $Id: media.php,v 1.3 2005-03-12 06:19:03 kimitake Exp $
\r
26 // defines how much media items will be shown per page. You can override this
\r
27 // in config.php if you like. (changing it in config.php instead of here will
\r
28 // allow your settings to be kept even after a Nucleus upgrade)
\r
29 $CONF['MediaPerPage'] = 10;
\r
31 // include all classes and config data
\r
32 include('../config.php');
\r
33 include($DIR_LIBS . 'MEDIA.php'); // media classes
\r
35 sendContentType('application/xhtml+xml', 'media');
\r
37 // user needs to be logged in to use this
\r
38 if (!$member->isLoggedIn()) {
\r
39 media_loginAndPassThrough();
\r
43 // check if member is on at least one teamlist
\r
44 $query = 'SELECT * FROM ' . sql_table('team'). ' WHERE tmember=' . $member->getID();
\r
45 $teams = mysql_query($query);
\r
46 if (mysql_num_rows($teams) == 0)
\r
47 media_doError(_ERROR_DISALLOWEDUPLOAD);
\r
50 $action = requestVar('action');
\r
52 $action = 'selectmedia';
\r
55 $aActionsNotToCheck = array('selectmedia', _MEDIA_FILTER_APPLY, _MEDIA_COLLECTION_SELECT);
\r
56 if (!in_array($action, $aActionsNotToCheck))
\r
58 if (!$manager->checkTicket())
\r
59 media_doError(_ERROR_BADTICKET);
\r
64 case 'chooseupload':
\r
65 case _MEDIA_UPLOAD_TO:
\r
66 case _MEDIA_UPLOAD_NEW:
\r
72 case _MEDIA_FILTER_APPLY:
\r
74 case _MEDIA_COLLECTION_SELECT:
\r
81 function media_select() {
\r
82 global $member, $CONF, $DIR_MEDIA, $manager;
\r
86 // show 10 files + navigation buttons
\r
87 // show msg when no files
\r
89 // files sorted according to last modification date
\r
91 // currently selected collection
\r
92 $currentCollection = requestVar('collection');
\r
93 if (!$currentCollection || !@is_dir($DIR_MEDIA . $currentCollection))
\r
94 $currentCollection = $member->getID();
\r
97 // get collection list
\r
98 $collections = MEDIA::getCollectionList();
\r
100 if (sizeof($collections) > 1) {
\r
102 <form method="post" action="media.php"><div>
\r
103 <label for="media_collection"><?php echo htmlspecialchars(_MEDIA_COLLECTION_LABEL)?></label>
\r
104 <select name="collection" id="media_collection">
\r
105 <?php foreach ($collections as $dirname => $description) {
\r
106 echo '<option value="',htmlspecialchars($dirname),'"';
\r
107 if ($dirname == $currentCollection) {
\r
108 echo ' selected="selected"';
\r
110 echo '>',htmlspecialchars($description),'</option>';
\r
114 <input type="submit" name="action" value="<?php echo htmlspecialchars(_MEDIA_COLLECTION_SELECT) ?>" title="<?php echo htmlspecialchars(_MEDIA_COLLECTION_TT)?>" />
\r
115 <input type="submit" name="action" value="<?php echo htmlspecialchars(_MEDIA_UPLOAD_TO) ?>" title="<?php echo htmlspecialchars(_MEDIA_UPLOADLINK) ?>" />
\r
116 <?php $manager->addTicketHidden() ?>
\r
120 <form method="post" action="media.php" style="float:right"><div>
\r
121 <input type="hidden" name="collection" value="<?php echo htmlspecialchars($currentCollection)?>" />
\r
122 <input type="submit" name="action" value="<?php echo htmlspecialchars(_MEDIA_UPLOAD_NEW) ?>" title="<?php echo htmlspecialchars(_MEDIA_UPLOADLINK) ?>" />
\r
123 <?php $manager->addTicketHidden() ?>
\r
125 <?php } // if sizeof
\r
127 $filter = requestVar('filter');
\r
128 $offset = intRequestVar('offset');
\r
129 $arr = MEDIA::getMediaListByCollection($currentCollection, $filter);
\r
132 <form method="post" action="media.php"><div>
\r
133 <label for="media_filter"><?php echo htmlspecialchars(_MEDIA_FILTER_LABEL)?></label>
\r
134 <input id="media_filter" type="text" name="filter" value="<?php echo htmlspecialchars($filter)?>" />
\r
135 <input type="submit" name="action" value="<?php echo htmlspecialchars(_MEDIA_FILTER_APPLY) ?>" />
\r
136 <input type="hidden" name="collection" value="<?php echo htmlspecialchars($currentCollection)?>" />
\r
137 <input type="hidden" name="offset" value="<?php echo intval($offset)?>" />
\r
143 <table width="100%">
\r
144 <caption><?php echo _MEDIA_COLLECTION_LABEL . htmlspecialchars($collections[$currentCollection])?></caption>
\r
146 <th><?php echo _MEDIA_MODIFIED?></th><th><?php echo _MEDIA_FILENAME?></th><th><?php echo _MEDIA_DIMENSIONS?></th>
\r
151 if (sizeof($arr)>0) {
\r
153 if (($offset + $CONF['MediaPerPage']) >= sizeof($arr))
\r
154 $offset = sizeof($arr) - $CONF['MediaPerPage'];
\r
156 if ($offset < 0) $offset = 0;
\r
158 $idxStart = $offset;
\r
159 $idxEnd = $offset + $CONF['MediaPerPage'];
\r
160 $idxNext = $idxEnd;
\r
161 $idxPrev = $idxStart - $CONF['MediaPerPage'];
\r
163 if ($idxPrev < 0) $idxPrev = 0;
\r
165 if ($idxEnd > sizeof($arr))
\r
166 $idxEnd = sizeof($arr);
\r
168 for($i=$idxStart;$i<$idxEnd;$i++) {
\r
170 $filename = $DIR_MEDIA . $currentCollection . '/' . $obj->filename;
\r
172 $old_level = error_reporting(0);
\r
173 $size = @GetImageSize($filename);
\r
174 error_reporting($old_level);
\r
176 $height = $size[1];
\r
177 $filetype = $size[2];
\r
180 echo "<td>". date("Y-m-d",$obj->timestamp) ."</td>";
\r
182 // strings for javascript
\r
183 $jsCurrentCollection = str_replace("'","\\'",$currentCollection);
\r
184 $jsFileName = str_replace("'","\\'",$obj->filename);
\r
186 if ($filetype != 0) {
\r
187 // image (gif/jpg/png/swf)
\r
188 echo "<td><a href=\"media.php\" onclick=\"chooseImage('", htmlspecialchars($jsCurrentCollection), "','", htmlspecialchars($jsFileName), "',"
\r
189 . "'", htmlspecialchars($width), "','" , htmlspecialchars($height), "'"
\r
190 . ")\" title=\"" . htmlspecialchars($obj->filename). "\">"
\r
191 . htmlspecialchars(shorten($obj->filename,25,'...'))
\r
193 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
196 // no image (e.g. mpg)
\r
197 echo "<td><a href='media.php' onclick=\"chooseOther('" , htmlspecialchars($jsCurrentCollection), "','", htmlspecialchars($jsFileName), "'"
\r
198 . ")\" title=\"" . htmlspecialchars($obj->filename). "\">"
\r
199 . htmlspecialchars(shorten($obj->filename,30,'...'))
\r
203 echo '<td>' , htmlspecialchars($width) , 'x' , htmlspecialchars($height) , '</td>';
\r
206 } // if (sizeof($arr)>0)
\r
212 echo "<a href='media.php?offset=$idxPrev&collection=".urlencode($currentCollection)."'>". _LISTS_PREV."</a> ";
\r
213 if ($idxEnd < sizeof($arr))
\r
214 echo "<a href='media.php?offset=$idxNext&collection=".urlencode($currentCollection)."'>". _LISTS_NEXT."</a> ";
\r
217 <input id="typeradio0" type="radio" name="typeradio" onclick="setType(0);" checked="checked" /><label for="typeradio0"><?php echo _MEDIA_INLINE?></label>
\r
218 <input id="typeradio1" type="radio" name="typeradio" onclick="setType(1);" /><label for="typeradio1"><?php echo _MEDIA_POPUP?></label>
\r
226 * Shows a screen where you can select the file to upload
\r
228 function media_choose() {
\r
229 global $CONF, $member, $manager;
\r
231 $currentCollection = requestVar('collection');
\r
233 $collections = MEDIA::getCollectionList();
\r
237 <h1><?php echo _UPLOAD_TITLE?></h1>
\r
239 <p><?php echo _UPLOAD_MSG?></p>
\r
241 <form method="post" enctype="multipart/form-data" action="media.php">
\r
243 <input type="hidden" name="action" value="uploadfile" />
\r
244 <?php $manager->addTicketHidden() ?>
\r
245 <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $CONF['MaxUploadSize']?>" />
\r
248 <input name="uploadfile" type="file" size="40" />
\r
249 <?php if (sizeof($collections) > 1) {
\r
251 <br /><br /><label for="upload_collection">Collection:</label>
\r
252 <br /><select name="collection" id="upload_collection">
\r
253 <?php foreach ($collections as $dirname => $description) {
\r
254 echo '<option value="',htmlspecialchars($dirname),'"';
\r
255 if ($dirname == $currentCollection) {
\r
256 echo ' selected="selected"';
\r
258 echo '>',htmlspecialchars($description),'</option>';
\r
264 <input name="collection" type="hidden" value="<?php echo htmlspecialchars(requestVar('collection'))?>" />
\r
265 <?php } // if sizeof
\r
268 <input type="submit" value="<?php echo _UPLOAD_BUTTON?>" />
\r
278 * accepts a file for upload
\r
280 function media_upload() {
\r
281 global $DIR_MEDIA, $member, $CONF;
\r
283 $uploadInfo = postFileInfo('uploadfile');
\r
285 $filename = $uploadInfo['name'];
\r
286 $filetype = $uploadInfo['type'];
\r
287 $filesize = $uploadInfo['size'];
\r
288 $filetempname = $uploadInfo['tmp_name'];
\r
290 if ($filesize > $CONF['MaxUploadSize'])
\r
291 media_doError(_ERROR_FILE_TOO_BIG);
\r
293 // check file type against allowed types
\r
295 $allowedtypes = explode (',', $CONF['AllowedTypes']);
\r
296 foreach ( $allowedtypes as $type )
\r
297 if (eregi("\." .$type. "$",$filename)) $ok = 1;
\r
298 if (!$ok) media_doError(_ERROR_BADFILETYPE);
\r
300 if (!is_uploaded_file($filetempname))
\r
301 media_doError(_ERROR_BADREQUEST);
\r
303 // prefix filename with current date (YYYY-MM-DD-)
\r
304 // this to avoid nameclashes
\r
305 if ($CONF['MediaPrefix'])
\r
306 $filename = strftime("%Y%m%d-", time()) . $filename;
\r
308 $collection = requestVar('collection');
\r
309 $res = MEDIA::addMediaObject($collection, $filetempname, $filename);
\r
312 media_doError($res);
\r
314 // shows updated list afterwards
\r
318 function media_loginAndPassThrough() {
\r
321 <h1><?php echo _LOGIN_PLEASE?></h1>
\r
323 <form method="post" action="media.php">
\r
325 <input name="action" value="login" type="hidden" />
\r
326 <input name="collection" value="<?php echo htmlspecialchars(requestVar('collection'))?>" type="hidden" />
\r
327 <?php echo _LOGINFORM_NAME?>: <input name="login" />
\r
328 <br /><?php echo _LOGINFORM_PWD?>: <input name="password" type="password" />
\r
329 <br /><input type="submit" value="<?php echo _LOGIN?>" />
\r
332 <p><a href="media.php" onclick="window.close();"><?php echo _POPUP_CLOSE?></a></p>
\r
333 <?php media_foot();
\r
337 function media_doError($msg) {
\r
340 <h1><?php echo _ERROR?></h1>
\r
341 <p><?php echo $msg?></p>
\r
342 <p><a href="media.php" onclick="history.back()"><?php echo _BACK?></a></p>
\r
343 <?php media_foot();
\r
348 function media_head() {
\r
350 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
\r
351 <html xmlns="http://www.w3.org/1999/xhtml">
\r
353 <meta http-equiv="Content-Type" content="text/html; charset=<?php echo _CHARSET ?>" />
\r
354 <title>Nucleus Media</title>
\r
355 <link rel="stylesheet" type="text/css" href="styles/popups.css" />
\r
356 <script type="text/javascript">
\r
358 function setType(val) { type = val; }
\r
360 function chooseImage(collection, filename, width, height) {
\r
361 window.opener.focus();
\r
362 window.opener.includeImage(collection,
\r
364 type == 0 ? 'inline' : 'popup',
\r
371 function chooseOther(collection, filename) {
\r
372 window.opener.focus();
\r
373 window.opener.includeOtherMedia(collection, filename);
\r
382 function media_foot() {
\r