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-16 08:04:14 kimitake Exp $
\r
27 // defines how much media items will be shown per page. You can override this
\r
28 // in config.php if you like. (changing it in config.php instead of here will
\r
29 // allow your settings to be kept even after a Nucleus upgrade)
\r
30 $CONF['MediaPerPage'] = 10;
\r
32 // include all classes and config data
\r
33 include('../config.php');
\r
34 include($DIR_LIBS . 'MEDIA.php'); // media classes
\r
36 sendContentType('application/xhtml+xml', 'media');
\r
38 // user needs to be logged in to use this
\r
39 if (!$member->isLoggedIn()) {
\r
40 media_loginAndPassThrough();
\r
44 // check if member is on at least one teamlist
\r
45 $query = 'SELECT * FROM ' . sql_table('team'). ' WHERE tmember=' . $member->getID();
\r
46 $teams = mysql_query($query);
\r
47 if (mysql_num_rows($teams) == 0)
\r
48 media_doError(_ERROR_DISALLOWEDUPLOAD);
\r
51 $action = requestVar('action');
\r
53 $action = 'selectmedia';
\r
56 $aActionsNotToCheck = array('selectmedia', _MEDIA_FILTER_APPLY, _MEDIA_COLLECTION_SELECT);
\r
57 if (!in_array($action, $aActionsNotToCheck))
\r
59 if (!$manager->checkTicket())
\r
60 media_doError(_ERROR_BADTICKET);
\r
65 case 'chooseupload':
\r
66 case _MEDIA_UPLOAD_TO:
\r
67 case _MEDIA_UPLOAD_NEW:
\r
73 case _MEDIA_FILTER_APPLY:
\r
75 case _MEDIA_COLLECTION_SELECT:
\r
82 function media_select() {
\r
83 global $member, $CONF, $DIR_MEDIA, $manager;
\r
87 // show 10 files + navigation buttons
\r
88 // show msg when no files
\r
90 // files sorted according to last modification date
\r
92 // currently selected collection
\r
93 $currentCollection = requestVar('collection');
\r
94 if (!$currentCollection || !@is_dir($DIR_MEDIA . $currentCollection))
\r
95 $currentCollection = $member->getID();
\r
98 // get collection list
\r
99 $collections = MEDIA::getCollectionList();
\r
101 if (sizeof($collections) > 1) {
\r
103 <form method="post" action="media.php"><div>
\r
104 <label for="media_collection"><?php echo htmlspecialchars(_MEDIA_COLLECTION_LABEL)?></label>
\r
105 <select name="collection" id="media_collection">
\r
106 <?php foreach ($collections as $dirname => $description) {
\r
107 echo '<option value="',htmlspecialchars($dirname),'"';
\r
108 if ($dirname == $currentCollection) {
\r
109 echo ' selected="selected"';
\r
111 echo '>',htmlspecialchars($description),'</option>';
\r
115 <input type="submit" name="action" value="<?php echo htmlspecialchars(_MEDIA_COLLECTION_SELECT) ?>" title="<?php echo htmlspecialchars(_MEDIA_COLLECTION_TT)?>" />
\r
116 <input type="submit" name="action" value="<?php echo htmlspecialchars(_MEDIA_UPLOAD_TO) ?>" title="<?php echo htmlspecialchars(_MEDIA_UPLOADLINK) ?>" />
\r
117 <?php $manager->addTicketHidden() ?>
\r
121 <form method="post" action="media.php" style="float:right"><div>
\r
122 <input type="hidden" name="collection" value="<?php echo htmlspecialchars($currentCollection)?>" />
\r
123 <input type="submit" name="action" value="<?php echo htmlspecialchars(_MEDIA_UPLOAD_NEW) ?>" title="<?php echo htmlspecialchars(_MEDIA_UPLOADLINK) ?>" />
\r
124 <?php $manager->addTicketHidden() ?>
\r
126 <?php } // if sizeof
\r
128 $filter = requestVar('filter');
\r
129 $offset = intRequestVar('offset');
\r
130 $arr = MEDIA::getMediaListByCollection($currentCollection, $filter);
\r
133 <form method="post" action="media.php"><div>
\r
134 <label for="media_filter"><?php echo htmlspecialchars(_MEDIA_FILTER_LABEL)?></label>
\r
135 <input id="media_filter" type="text" name="filter" value="<?php echo htmlspecialchars($filter)?>" />
\r
136 <input type="submit" name="action" value="<?php echo htmlspecialchars(_MEDIA_FILTER_APPLY) ?>" />
\r
137 <input type="hidden" name="collection" value="<?php echo htmlspecialchars($currentCollection)?>" />
\r
138 <input type="hidden" name="offset" value="<?php echo intval($offset)?>" />
\r
144 <table width="100%">
\r
145 <caption><?php echo _MEDIA_COLLECTION_LABEL . htmlspecialchars($collections[$currentCollection])?></caption>
\r
147 <th><?php echo _MEDIA_MODIFIED?></th><th><?php echo _MEDIA_FILENAME?></th><th><?php echo _MEDIA_DIMENSIONS?></th>
\r
152 if (sizeof($arr)>0) {
\r
154 if (($offset + $CONF['MediaPerPage']) >= sizeof($arr))
\r
155 $offset = sizeof($arr) - $CONF['MediaPerPage'];
\r
157 if ($offset < 0) $offset = 0;
\r
159 $idxStart = $offset;
\r
160 $idxEnd = $offset + $CONF['MediaPerPage'];
\r
161 $idxNext = $idxEnd;
\r
162 $idxPrev = $idxStart - $CONF['MediaPerPage'];
\r
164 if ($idxPrev < 0) $idxPrev = 0;
\r
166 if ($idxEnd > sizeof($arr))
\r
167 $idxEnd = sizeof($arr);
\r
169 for($i=$idxStart;$i<$idxEnd;$i++) {
\r
171 $filename = $DIR_MEDIA . $currentCollection . '/' . $obj->filename;
\r
173 $old_level = error_reporting(0);
\r
174 $size = @GetImageSize($filename);
\r
175 error_reporting($old_level);
\r
177 $height = $size[1];
\r
178 $filetype = $size[2];
\r
181 echo "<td>". date("Y-m-d",$obj->timestamp) ."</td>";
\r
183 // strings for javascript
\r
184 $jsCurrentCollection = str_replace("'","\\'",$currentCollection);
\r
185 $jsFileName = str_replace("'","\\'",$obj->filename);
\r
187 if ($filetype != 0) {
\r
188 // image (gif/jpg/png/swf)
\r
189 echo "<td><a href=\"media.php\" onclick=\"chooseImage('", htmlspecialchars($jsCurrentCollection), "','", htmlspecialchars($jsFileName), "',"
\r
190 . "'", htmlspecialchars($width), "','" , htmlspecialchars($height), "'"
\r
191 . ")\" title=\"" . htmlspecialchars($obj->filename). "\">"
\r
192 . htmlspecialchars(shorten($obj->filename,25,'...'))
\r
194 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
197 // no image (e.g. mpg)
\r
198 echo "<td><a href='media.php' onclick=\"chooseOther('" , htmlspecialchars($jsCurrentCollection), "','", htmlspecialchars($jsFileName), "'"
\r
199 . ")\" title=\"" . htmlspecialchars($obj->filename). "\">"
\r
200 . htmlspecialchars(shorten($obj->filename,30,'...'))
\r
204 echo '<td>' , htmlspecialchars($width) , 'x' , htmlspecialchars($height) , '</td>';
\r
207 } // if (sizeof($arr)>0)
\r
213 echo "<a href='media.php?offset=$idxPrev&collection=".urlencode($currentCollection)."'>". _LISTS_PREV."</a> ";
\r
214 if ($idxEnd < sizeof($arr))
\r
215 echo "<a href='media.php?offset=$idxNext&collection=".urlencode($currentCollection)."'>". _LISTS_NEXT."</a> ";
\r
218 <input id="typeradio0" type="radio" name="typeradio" onclick="setType(0);" checked="checked" /><label for="typeradio0"><?php echo _MEDIA_INLINE?></label>
\r
219 <input id="typeradio1" type="radio" name="typeradio" onclick="setType(1);" /><label for="typeradio1"><?php echo _MEDIA_POPUP?></label>
\r
227 * Shows a screen where you can select the file to upload
\r
229 function media_choose() {
\r
230 global $CONF, $member, $manager;
\r
232 $currentCollection = requestVar('collection');
\r
234 $collections = MEDIA::getCollectionList();
\r
238 <h1><?php echo _UPLOAD_TITLE?></h1>
\r
240 <p><?php echo _UPLOAD_MSG?></p>
\r
242 <form method="post" enctype="multipart/form-data" action="media.php">
\r
244 <input type="hidden" name="action" value="uploadfile" />
\r
245 <?php $manager->addTicketHidden() ?>
\r
246 <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $CONF['MaxUploadSize']?>" />
\r
249 <input name="uploadfile" type="file" size="40" />
\r
250 <?php if (sizeof($collections) > 1) {
\r
252 <br /><br /><label for="upload_collection">Collection:</label>
\r
253 <br /><select name="collection" id="upload_collection">
\r
254 <?php foreach ($collections as $dirname => $description) {
\r
255 echo '<option value="',htmlspecialchars($dirname),'"';
\r
256 if ($dirname == $currentCollection) {
\r
257 echo ' selected="selected"';
\r
259 echo '>',htmlspecialchars($description),'</option>';
\r
265 <input name="collection" type="hidden" value="<?php echo htmlspecialchars(requestVar('collection'))?>" />
\r
266 <?php } // if sizeof
\r
269 <input type="submit" value="<?php echo _UPLOAD_BUTTON?>" />
\r
279 * accepts a file for upload
\r
281 function media_upload() {
\r
282 global $DIR_MEDIA, $member, $CONF;
\r
284 $uploadInfo = postFileInfo('uploadfile');
\r
286 $filename = $uploadInfo['name'];
\r
287 $filetype = $uploadInfo['type'];
\r
288 $filesize = $uploadInfo['size'];
\r
289 $filetempname = $uploadInfo['tmp_name'];
\r
291 if ($filesize > $CONF['MaxUploadSize'])
\r
292 media_doError(_ERROR_FILE_TOO_BIG);
\r
294 // check file type against allowed types
\r
296 $allowedtypes = explode (',', $CONF['AllowedTypes']);
\r
297 foreach ( $allowedtypes as $type )
\r
298 if (eregi("\." .$type. "$",$filename)) $ok = 1;
\r
299 if (!$ok) media_doError(_ERROR_BADFILETYPE);
\r
301 if (!is_uploaded_file($filetempname))
\r
302 media_doError(_ERROR_BADREQUEST);
\r
304 // prefix filename with current date (YYYY-MM-DD-)
\r
305 // this to avoid nameclashes
\r
306 if ($CONF['MediaPrefix'])
\r
307 $filename = strftime("%Y%m%d-", time()) . $filename;
\r
309 $collection = requestVar('collection');
\r
310 $res = MEDIA::addMediaObject($collection, $filetempname, $filename);
\r
313 media_doError($res);
\r
315 // shows updated list afterwards
\r
319 function media_loginAndPassThrough() {
\r
322 <h1><?php echo _LOGIN_PLEASE?></h1>
\r
324 <form method="post" action="media.php">
\r
326 <input name="action" value="login" type="hidden" />
\r
327 <input name="collection" value="<?php echo htmlspecialchars(requestVar('collection'))?>" type="hidden" />
\r
328 <?php echo _LOGINFORM_NAME?>: <input name="login" />
\r
329 <br /><?php echo _LOGINFORM_PWD?>: <input name="password" type="password" />
\r
330 <br /><input type="submit" value="<?php echo _LOGIN?>" />
\r
333 <p><a href="media.php" onclick="window.close();"><?php echo _POPUP_CLOSE?></a></p>
\r
334 <?php media_foot();
\r
338 function media_doError($msg) {
\r
341 <h1><?php echo _ERROR?></h1>
\r
342 <p><?php echo $msg?></p>
\r
343 <p><a href="media.php" onclick="history.back()"><?php echo _BACK?></a></p>
\r
344 <?php media_foot();
\r
349 function media_head() {
\r
351 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
\r
352 <html xmlns="http://www.w3.org/1999/xhtml">
\r
354 <meta http-equiv="Content-Type" content="text/html; charset=<?php echo _CHARSET ?>" />
\r
355 <title>Nucleus Media</title>
\r
356 <link rel="stylesheet" type="text/css" href="styles/popups.css" />
\r
357 <script type="text/javascript">
\r
359 function setType(val) { type = val; }
\r
361 function chooseImage(collection, filename, width, height) {
\r
362 window.opener.focus();
\r
363 window.opener.includeImage(collection,
\r
365 type == 0 ? 'inline' : 'popup',
\r
372 function chooseOther(collection, filename) {
\r
373 window.opener.focus();
\r
374 window.opener.includeOtherMedia(collection, filename);
\r
383 function media_foot() {
\r