3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
4 * Copyright (C) 2002-2004 The Nucleus Group
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 * (see nucleus/documentation/index.html#license for more info)
12 * Media popup window for Nucleus
15 * - can be openen from an add-item form or bookmarklet popup
16 * - shows a list of recent files, allowing browsing, search and
18 * - close the popup by selecting a file in the list. The file gets
19 * passed through to the add-item form (linkto, popupimg or inline img)
21 * $Id: media.php,v 1.1.1.1 2005-02-28 07:14:31 kimitake Exp $
26 // defines how much media items will be shown per page. You can override this
27 // in config.php if you like. (changing it in config.php instead of here will
28 // allow your settings to be kept even after a Nucleus upgrade)
29 $CONF['MediaPerPage'] = 10;
31 // include all classes and config data
32 include('../config.php');
33 include($DIR_LIBS . 'MEDIA.php'); // media classes
35 sendContentType('application/xhtml+xml', 'media');
37 // user needs to be logged in to use this
38 if (!$member->isLoggedIn()) {
39 media_loginAndPassThrough();
43 // check if member is on at least one teamlist
44 $query = 'SELECT * FROM ' . sql_table('team'). ' WHERE tmember=' . $member->getID();
45 $teams = mysql_query($query);
46 if (mysql_num_rows($teams) == 0)
47 media_doError(_ERROR_DISALLOWEDUPLOAD);
50 $action = requestVar('action');
52 $action = 'selectmedia';
55 $aActionsNotToCheck = array('selectmedia', _MEDIA_FILTER_APPLY, _MEDIA_COLLECTION_SELECT);
56 if (!in_array($action, $aActionsNotToCheck))
58 if (!$manager->checkTicket())
59 media_doError(_ERROR_BADTICKET);
65 case _MEDIA_UPLOAD_TO:
66 case _MEDIA_UPLOAD_NEW:
72 case _MEDIA_FILTER_APPLY:
74 case _MEDIA_COLLECTION_SELECT:
81 function media_select() {
82 global $member, $CONF, $DIR_MEDIA, $manager;
86 // show 10 files + navigation buttons
87 // show msg when no files
89 // files sorted according to last modification date
91 // currently selected collection
92 $currentCollection = requestVar('collection');
93 if (!$currentCollection || !@is_dir($DIR_MEDIA . $currentCollection))
94 $currentCollection = $member->getID();
97 // get collection list
98 $collections = MEDIA::getCollectionList();
100 if (sizeof($collections) > 1) {
102 <form method="post" action="media.php"><div>
103 <label for="media_collection"><?php echo htmlspecialchars(_MEDIA_COLLECTION_LABEL)?></label>
104 <select name="collection" id="media_collection">
105 <?php foreach ($collections as $dirname => $description) {
106 echo '<option value="',htmlspecialchars($dirname),'"';
107 if ($dirname == $currentCollection) {
108 echo ' selected="selected"';
110 echo '>',htmlspecialchars($description),'</option>';
114 <input type="submit" name="action" value="<?php echo htmlspecialchars(_MEDIA_COLLECTION_SELECT) ?>" title="<?php echo htmlspecialchars(_MEDIA_COLLECTION_TT)?>" />
115 <input type="submit" name="action" value="<?php echo htmlspecialchars(_MEDIA_UPLOAD_TO) ?>" title="<?php echo htmlspecialchars(_MEDIA_UPLOADLINK) ?>" />
116 <?php $manager->addTicketHidden() ?>
120 <form method="post" action="media.php" style="float:right"><div>
121 <input type="hidden" name="collection" value="<?php echo htmlspecialchars($currentCollection)?>" />
122 <input type="submit" name="action" value="<?php echo htmlspecialchars(_MEDIA_UPLOAD_NEW) ?>" title="<?php echo htmlspecialchars(_MEDIA_UPLOADLINK) ?>" />
123 <?php $manager->addTicketHidden() ?>
127 $filter = requestVar('filter');
128 $offset = intRequestVar('offset');
129 $arr = MEDIA::getMediaListByCollection($currentCollection, $filter);
132 <form method="post" action="media.php"><div>
133 <label for="media_filter"><?php echo htmlspecialchars(_MEDIA_FILTER_LABEL)?></label>
134 <input id="media_filter" type="text" name="filter" value="<?php echo htmlspecialchars($filter)?>" />
135 <input type="submit" name="action" value="<?php echo htmlspecialchars(_MEDIA_FILTER_APPLY) ?>" />
136 <input type="hidden" name="collection" value="<?php echo htmlspecialchars($currentCollection)?>" />
137 <input type="hidden" name="offset" value="<?php echo intval($offset)?>" />
144 <caption><?php echo _MEDIA_COLLECTION_LABEL . htmlspecialchars($collections[$currentCollection])?></caption>
146 <th><?php echo _MEDIA_MODIFIED?></th><th><?php echo _MEDIA_FILENAME?></th><th><?php echo _MEDIA_DIMENSIONS?></th>
151 if (sizeof($arr)>0) {
153 if (($offset + $CONF['MediaPerPage']) >= sizeof($arr))
154 $offset = sizeof($arr) - $CONF['MediaPerPage'];
156 if ($offset < 0) $offset = 0;
159 $idxEnd = $offset + $CONF['MediaPerPage'];
161 $idxPrev = $idxStart - $CONF['MediaPerPage'];
163 if ($idxPrev < 0) $idxPrev = 0;
165 if ($idxEnd > sizeof($arr))
166 $idxEnd = sizeof($arr);
168 for($i=$idxStart;$i<$idxEnd;$i++) {
170 $filename = $DIR_MEDIA . $currentCollection . '/' . $obj->filename;
172 $old_level = error_reporting(0);
173 $size = @GetImageSize($filename);
174 error_reporting($old_level);
177 $filetype = $size[2];
180 echo "<td>". date("Y-m-d",$obj->timestamp) ."</td>";
182 if ($filetype != 0) {
183 // image (gif/jpg/png/swf)
184 echo "<td><a href='media.php' onclick='chooseImage(\"$currentCollection\",\"$obj->filename\","
185 . "\"$width\",\"$height\""
186 . ")' title='" . htmlspecialchars($obj->filename). "'>"
187 . htmlspecialchars(shorten($obj->filename,25,'...'))
189 echo ' (<a href="', htmlspecialchars($CONF['MediaURL'] . $currentCollection . '/' . $obj->filename), '" onclick="window.open(this.href); return false;" title="',htmlspecialchars(_MEDIA_VIEW_TT),'">',_MEDIA_VIEW,'</a>)';
192 // no image (e.g. mpg)
193 echo "<td><a href='media.php' onclick='chooseOther(\"$currentCollection\",\"$obj->filename\""
194 . ")' title='" . htmlspecialchars($obj->filename). "'>"
195 . htmlspecialchars(shorten($obj->filename,30,'...'))
199 echo '<td>' , $width , 'x' , $height , '</td>';
202 } // if (sizeof($arr)>0)
208 echo "<a href='media.php?offset=$idxPrev&collection=".urlencode($currentCollection)."'>". _LISTS_PREV."</a> ";
209 if ($idxEnd < sizeof($arr))
210 echo "<a href='media.php?offset=$idxNext&collection=".urlencode($currentCollection)."'>". _LISTS_NEXT."</a> ";
213 <input id="typeradio0" type="radio" name="typeradio" onclick="setType(0);" checked="checked" /><label for="typeradio0"><?php echo _MEDIA_INLINE?></label>
214 <input id="typeradio1" type="radio" name="typeradio" onclick="setType(1);" /><label for="typeradio1"><?php echo _MEDIA_POPUP?></label>
222 * Shows a screen where you can select the file to upload
224 function media_choose() {
225 global $CONF, $member, $manager;
227 $currentCollection = requestVar('collection');
229 $collections = MEDIA::getCollectionList();
233 <h1><?php echo _UPLOAD_TITLE?></h1>
235 <p><?php echo _UPLOAD_MSG?></p>
237 <form method="post" enctype="multipart/form-data" action="media.php">
239 <input type="hidden" name="action" value="uploadfile" />
240 <?php $manager->addTicketHidden() ?>
241 <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $CONF['MaxUploadSize']?>" />
244 <input name="uploadfile" type="file" size="40" />
245 <?php if (sizeof($collections) > 1) {
247 <br /><br /><label for="upload_collection">Collection:</label>
248 <br /><select name="collection" id="upload_collection">
249 <?php foreach ($collections as $dirname => $description) {
250 echo '<option value="',htmlspecialchars($dirname),'"';
251 if ($dirname == $currentCollection) {
252 echo ' selected="selected"';
254 echo '>',htmlspecialchars($description),'</option>';
260 <input name="collection" type="hidden" value="<?php echo htmlspecialchars(requestVar('collection'))?>" />
264 <input type="submit" value="<?php echo _UPLOAD_BUTTON?>" />
274 * accepts a file for upload
276 function media_upload() {
277 global $DIR_MEDIA, $member, $CONF;
279 $uploadInfo = postFileInfo('uploadfile');
281 $filename = $uploadInfo['name'];
282 $filetype = $uploadInfo['type'];
283 $filesize = $uploadInfo['size'];
284 $filetempname = $uploadInfo['tmp_name'];
286 if ($filesize > $CONF['MaxUploadSize'])
287 media_doError(_ERROR_FILE_TOO_BIG);
289 // check file type against allowed types
291 $allowedtypes = explode (',', $CONF['AllowedTypes']);
292 foreach ( $allowedtypes as $type )
293 if (eregi("\." .$type. "$",$filename)) $ok = 1;
294 if (!$ok) media_doError(_ERROR_BADFILETYPE);
296 if (!is_uploaded_file($filetempname))
297 media_doError(_ERROR_BADREQUEST);
299 // prefix filename with current date (YYYY-MM-DD-)
300 // this to avoid nameclashes
301 if ($CONF['MediaPrefix'])
302 $filename = strftime("%Y%m%d-", time()) . $filename;
304 $collection = requestVar('collection');
305 $res = MEDIA::addMediaObject($collection, $filetempname, $filename);
310 // shows updated list afterwards
314 function media_loginAndPassThrough() {
317 <h1><?php echo _LOGIN_PLEASE?></h1>
319 <form method="post" action="media.php">
321 <input name="action" value="login" type="hidden" />
322 <input name="collection" value="<?php echo htmlspecialchars(requestVar('collection'))?>" type="hidden" />
323 <?php echo _LOGINFORM_NAME?>: <input name="login" />
324 <br /><?php echo _LOGINFORM_PWD?>: <input name="password" type="password" />
325 <br /><input type="submit" value="<?php echo _LOGIN?>" />
328 <p><a href="media.php" onclick="window.close();"><?php echo _POPUP_CLOSE?></a></p>
333 function media_doError($msg) {
336 <h1><?php echo _ERROR?></h1>
337 <p><?php echo $msg?></p>
338 <p><a href="media.php" onclick="history.back()"><?php echo _BACK?></a></p>
344 function media_head() {
346 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
347 <html xmlns="http://www.w3.org/1999/xhtml">
349 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
350 <title>Nucleus Media</title>
351 <link rel="stylesheet" type="text/css" href="styles/popups.css" />
352 <script type="text/javascript">
354 function setType(val) { type = val; }
356 function chooseImage(collection, filename, width, height) {
357 window.opener.focus();
358 window.opener.includeImage(collection,
360 type == 0 ? 'inline' : 'popup',
367 function chooseOther(collection, filename) {
368 window.opener.focus();
369 window.opener.includeOtherMedia(collection, filename);
378 function media_foot() {