3 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
4 * Copyright (C) 2002-2004 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
24 // defines how much media items will be shown per page. You can override this
\r
25 // in config.php if you like. (changing it in config.php instead of here will
\r
26 // allow your settings to be kept even after a Nucleus upgrade)
\r
27 $CONF['MediaPerPage'] = 10;
\r
29 // include all classes and config data
\r
30 include('../config.php');
\r
31 include($DIR_LIBS . 'MEDIA.php'); // media classes
\r
33 sendContentType('application/xhtml+xml', 'media');
\r
35 // user needs to be logged in to use this
\r
36 if (!$member->isLoggedIn()) {
\r
37 media_loginAndPassThrough();
\r
41 // check if member is on at least one teamlist
\r
42 $query = 'SELECT * FROM ' . sql_table('team'). ' WHERE tmember=' . $member->getID();
\r
43 $teams = mysql_query($query);
\r
44 if (mysql_num_rows($teams) == 0)
\r
45 media_doError(_ERROR_DISALLOWEDUPLOAD);
\r
48 $action = requestVar('action');
\r
50 case 'chooseupload':
\r
51 case _MEDIA_UPLOAD_TO:
\r
52 case _MEDIA_UPLOAD_NEW:
\r
58 case _MEDIA_FILTER_APPLY:
\r
60 case _MEDIA_COLLECTION_SELECT:
\r
67 function media_select() {
\r
68 global $member, $CONF, $DIR_MEDIA;
\r
72 // show 10 files + navigation buttons
\r
73 // show msg when no files
\r
75 // files sorted according to last modification date
\r
77 // currently selected collection
\r
78 $currentCollection = requestVar('collection');
\r
79 if (!$currentCollection || !@is_dir($DIR_MEDIA . $currentCollection))
\r
80 $currentCollection = $member->getID();
\r
83 // get collection list
\r
84 $collections = MEDIA::getCollectionList();
\r
86 if (sizeof($collections) > 1) {
\r
88 <form method="post" action="media.php"><div>
\r
89 <label for="media_collection"><?php echo htmlspecialchars(_MEDIA_COLLECTION_LABEL)?></label>
\r
90 <select name="collection" id="media_collection">
\r
91 <?php foreach ($collections as $dirname => $description) {
\r
92 echo '<option value="',htmlspecialchars($dirname),'"';
\r
93 if ($dirname == $currentCollection) {
\r
94 echo ' selected="selected"';
\r
96 echo '>',htmlspecialchars($description),'</option>';
\r
100 <input type="submit" name="action" value="<?php echo htmlspecialchars(_MEDIA_COLLECTION_SELECT) ?>" title="<?php echo htmlspecialchars(_MEDIA_COLLECTION_TT)?>" />
\r
101 <input type="submit" name="action" value="<?php echo htmlspecialchars(_MEDIA_UPLOAD_TO) ?>" title="<?php echo htmlspecialchars(_MEDIA_UPLOADLINK) ?>" />
\r
105 <form method="post" action="media.php" style="float:right"><div>
\r
106 <input type="hidden" name="collection" value="<?php echo htmlspecialchars($currentCollection)?>" />
\r
107 <input type="submit" name="action" value="<?php echo htmlspecialchars(_MEDIA_UPLOAD_NEW) ?>" title="<?php echo htmlspecialchars(_MEDIA_UPLOADLINK) ?>" />
\r
109 <?php } // if sizeof
\r
111 $filter = requestVar('filter');
\r
112 $offset = intRequestVar('offset');
\r
113 $arr = MEDIA::getMediaListByCollection($currentCollection, $filter);
\r
116 <form method="post" action="media.php"><div>
\r
117 <label for="media_filter"><?php echo htmlspecialchars(_MEDIA_FILTER_LABEL)?></label>
\r
118 <input id="media_filter" type="text" name="filter" value="<?php echo htmlspecialchars($filter)?>" />
\r
119 <input type="submit" name="action" value="<?php echo htmlspecialchars(_MEDIA_FILTER_APPLY) ?>" />
\r
120 <input type="hidden" name="collection" value="<?php echo htmlspecialchars($currentCollection)?>" />
\r
121 <input type="hidden" name="offset" value="<?php echo intval($offset)?>" />
\r
127 <table width="100%">
\r
128 <caption><?php echo _MEDIA_COLLECTION_LABEL . htmlspecialchars($collections[$currentCollection])?></caption>
\r
130 <th><?php echo _MEDIA_MODIFIED?></th><th><?php echo _MEDIA_FILENAME?></th><th><?php echo _MEDIA_DIMENSIONS?></th>
\r
135 if (sizeof($arr)>0) {
\r
137 if (($offset + $CONF['MediaPerPage']) >= sizeof($arr))
\r
138 $offset = sizeof($arr) - $CONF['MediaPerPage'];
\r
140 if ($offset < 0) $offset = 0;
\r
142 $idxStart = $offset;
\r
143 $idxEnd = $offset + $CONF['MediaPerPage'];
\r
144 $idxNext = $idxEnd;
\r
145 $idxPrev = $idxStart - $CONF['MediaPerPage'];
\r
147 if ($idxPrev < 0) $idxPrev = 0;
\r
149 if ($idxEnd > sizeof($arr))
\r
150 $idxEnd = sizeof($arr);
\r
152 for($i=$idxStart;$i<$idxEnd;$i++) {
\r
154 $filename = $DIR_MEDIA . $currentCollection . '/' . $obj->filename;
\r
156 $old_level = error_reporting(0);
\r
157 $size = @GetImageSize($filename);
\r
158 error_reporting($old_level);
\r
160 $height = $size[1];
\r
161 $filetype = $size[2];
\r
164 echo "<td>". date("Y-m-d",$obj->timestamp) ."</td>";
\r
166 if ($filetype != 0) {
\r
167 // image (gif/jpg/png/swf)
\r
168 echo "<td><a href='media.php' onclick='chooseImage(\"$currentCollection\",\"$obj->filename\","
\r
169 . "\"$width\",\"$height\""
\r
170 . ")' title='" . htmlspecialchars($obj->filename). "'>"
\r
171 . htmlspecialchars(shorten($obj->filename,25,'...'))
\r
173 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
176 // no image (e.g. mpg)
\r
177 echo "<td><a href='media.php' onclick='chooseOther(\"$currentCollection\",\"$obj->filename\""
\r
178 . ")' title='" . htmlspecialchars($obj->filename). "'>"
\r
179 . htmlspecialchars(shorten($obj->filename,30,'...'))
\r
183 echo '<td>' , $width , 'x' , $height , '</td>';
\r
186 } // if (sizeof($arr)>0)
\r
192 echo "<a href='media.php?offset=$idxPrev&collection=".urlencode($currentCollection)."'>". _LISTS_PREV."</a> ";
\r
193 if ($idxEnd < sizeof($arr))
\r
194 echo "<a href='media.php?offset=$idxNext&collection=".urlencode($currentCollection)."'>". _LISTS_NEXT."</a> ";
\r
197 <input id="typeradio0" type="radio" name="typeradio" onclick="setType(0);" checked="checked" /><label for="typeradio0"><?php echo _MEDIA_INLINE?></label>
\r
198 <input id="typeradio1" type="radio" name="typeradio" onclick="setType(1);" /><label for="typeradio1"><?php echo _MEDIA_POPUP?></label>
\r
206 * Shows a screen where you can select the file to upload
\r
208 function media_choose() {
\r
209 global $CONF, $member;
\r
211 $currentCollection = requestVar('collection');
\r
213 $collections = MEDIA::getCollectionList();
\r
217 <h1><?php echo _UPLOAD_TITLE?></h1>
\r
219 <p><?php echo _UPLOAD_MSG?></p>
\r
221 <form method="post" enctype="multipart/form-data" action="media.php">
\r
223 <input type="hidden" name="action" value="uploadfile" />
\r
224 <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $CONF['MaxUploadSize']?>" />
\r
227 <input name="uploadfile" type="file" size="40" />
\r
228 <?php if (sizeof($collections) > 1) {
\r
230 <br /><br /><label for="upload_collection">Collection:</label>
\r
231 <br /><select name="collection" id="upload_collection">
\r
232 <?php foreach ($collections as $dirname => $description) {
\r
233 echo '<option value="',htmlspecialchars($dirname),'"';
\r
234 if ($dirname == $currentCollection) {
\r
235 echo ' selected="selected"';
\r
237 echo '>',htmlspecialchars($description),'</option>';
\r
243 <input name="collection" type="hidden" value="<?php echo htmlspecialchars(requestVar('collection'))?>" />
\r
244 <?php } // if sizeof
\r
247 <input type="submit" value="<?php echo _UPLOAD_BUTTON?>" />
\r
257 * accepts a file for upload
\r
259 function media_upload() {
\r
260 global $DIR_MEDIA, $member, $CONF;
\r
262 $uploadInfo = postFileInfo('uploadfile');
\r
264 $filename = $uploadInfo['name'];
\r
265 $filetype = $uploadInfo['type'];
\r
266 $filesize = $uploadInfo['size'];
\r
267 $filetempname = $uploadInfo['tmp_name'];
\r
269 if ($filesize > $CONF['MaxUploadSize'])
\r
270 media_doError(_ERROR_FILE_TOO_BIG);
\r
272 // check file type against allowed types
\r
274 $allowedtypes = explode (',', $CONF['AllowedTypes']);
\r
275 foreach ( $allowedtypes as $type )
\r
276 if (eregi("\." .$type. "$",$filename)) $ok = 1;
\r
277 if (!$ok) media_doError(_ERROR_BADFILETYPE);
\r
279 if (!is_uploaded_file($filetempname))
\r
280 media_doError(_ERROR_BADREQUEST);
\r
282 // prefix filename with current date (YYYY-MM-DD-)
\r
283 // this to avoid nameclashes
\r
284 if ($CONF['MediaPrefix'])
\r
285 $filename = strftime("%Y%m%d-", time()) . $filename;
\r
287 $collection = requestVar('collection');
\r
288 $res = MEDIA::addMediaObject($collection, $filetempname, $filename);
\r
291 media_doError($res);
\r
293 // shows updated list afterwards
\r
297 function media_loginAndPassThrough() {
\r
300 <h1><?php echo _LOGIN_PLEASE?></h1>
\r
302 <form method="post" action="media.php">
\r
304 <input name="action" value="login" type="hidden" />
\r
305 <input name="collection" value="<?php echo htmlspecialchars(requestVar('collection'))?>" type="hidden" />
\r
306 <?php echo _LOGINFORM_NAME?>: <input name="login" />
\r
307 <br /><?php echo _LOGINFORM_PWD?>: <input name="password" type="password" />
\r
308 <br /><input type="submit" value="<?php echo _LOGIN?>" />
\r
311 <p><a href="media.php" onclick="window.close();"><?php echo _POPUP_CLOSE?></a></p>
\r
312 <?php media_foot();
\r
316 function media_doError($msg) {
\r
319 <h1><?php echo _ERROR?></h1>
\r
320 <p><?php echo $msg?></p>
\r
321 <p><a href="media.php" onclick="history.back()"><?php echo _BACK?></a></p>
\r
322 <?php media_foot();
\r
327 function media_head() {
\r
329 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
\r
330 <html xmlns="http://www.w3.org/1999/xhtml">
\r
332 <meta http-equiv="Content-Type" content="text/html; charset=<?php echo _CHARSET ?>" />
\r
333 <title>Nucleus Media</title>
\r
334 <link rel="stylesheet" type="text/css" href="styles/popups.css" />
\r
335 <script type="text/javascript">
\r
337 function setType(val) { type = val; }
\r
339 function chooseImage(collection, filename, width, height) {
\r
340 window.opener.focus();
\r
341 window.opener.includeImage(collection,
\r
343 type == 0 ? 'inline' : 'popup',
\r
350 function chooseOther(collection, filename) {
\r
351 window.opener.focus();
\r
352 window.opener.includeOtherMedia(collection, filename);
\r
361 function media_foot() {
\r