1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
|
<?php /* * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) * Copyright (C) 2002-2005 The Nucleus Group * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * (see nucleus/documentation/index.html#license for more info) */ /** * Media popup window for Nucleus * * Purpose: * - can be openen from an add-item form or bookmarklet popup * - shows a list of recent files, allowing browsing, search and * upload of new files * - close the popup by selecting a file in the list. The file gets * passed through to the add-item form (linkto, popupimg or inline img) * * @license http://nucleuscms.org/license.txt GNU General Public License * @copyright Copyright (C) 2002-2005 The Nucleus Group * @version $Id: media.php,v 1.18.2.1 2005/08/15 10:51:08 dekarma Exp $ * */ $CONF = array();
// defines how much media items will be shown per page. You can override this // in config.php if you like. (changing it in config.php instead of here will // allow your settings to be kept even after a Nucleus upgrade) $CONF['MediaPerPage'] = 10;
// include all classes and config data include('../config.php'); include($DIR_LIBS . 'MEDIA.php'); // media classes
sendContentType('application/xhtml+xml', 'media');
// user needs to be logged in to use this if (!$member->isLoggedIn()) { media_loginAndPassThrough(); exit; }
// check if member is on at least one teamlist $query = 'SELECT * FROM ' . sql_table('team'). ' WHERE tmember=' . $member->getID(); $teams = mysql_query($query); if (mysql_num_rows($teams) == 0) media_doError(_ERROR_DISALLOWEDUPLOAD); // get action $action = requestVar('action'); if ($action == '') $action = 'selectmedia'; // check ticket $aActionsNotToCheck = array('selectmedia', _MEDIA_FILTER_APPLY, _MEDIA_COLLECTION_SELECT); if (!in_array($action, $aActionsNotToCheck)) { if (!$manager->checkTicket()) media_doError(_ERROR_BADTICKET); }
switch($action) { case 'chooseupload': case _MEDIA_UPLOAD_TO: case _MEDIA_UPLOAD_NEW: media_choose(); break; case 'uploadfile': media_upload(); break; case _MEDIA_FILTER_APPLY: case 'selectmedia': case _MEDIA_COLLECTION_SELECT: default: media_select(); break; }
// select a file function media_select() { global $member, $CONF, $DIR_MEDIA, $manager; media_head(); // show 10 files + navigation buttons // show msg when no files // show upload form // files sorted according to last modification date
// currently selected collection $currentCollection = requestVar('collection'); if (!$currentCollection || !@is_dir($DIR_MEDIA . $currentCollection)) $currentCollection = $member->getID(); // get collection list $collections = MEDIA::getCollectionList();
if (sizeof($collections) > 1) { ?> <form method="post" action="media.php"><div> <label for="media_collection"><?php echo htmlspecialchars(_MEDIA_COLLECTION_LABEL)?></label> <select name="collection" id="media_collection"> <?php foreach ($collections as $dirname => $description) { echo '<option value="',htmlspecialchars($dirname),'"'; if ($dirname == $currentCollection) { echo ' selected="selected"'; } echo '>',htmlspecialchars($description),'</option>'; } ?> </select> <input type="submit" name="action" value="<?php echo htmlspecialchars(_MEDIA_COLLECTION_SELECT) ?>" title="<?php echo htmlspecialchars(_MEDIA_COLLECTION_TT)?>" /> <input type="submit" name="action" value="<?php echo htmlspecialchars(_MEDIA_UPLOAD_TO) ?>" title="<?php echo htmlspecialchars(_MEDIA_UPLOADLINK) ?>" /> <?php $manager->addTicketHidden() ?> </div></form> <?php } else { ?> <form method="post" action="media.php" style="float:right"><div> <input type="hidden" name="collection" value="<?php echo htmlspecialchars($currentCollection)?>" /> <input type="submit" name="action" value="<?php echo htmlspecialchars(_MEDIA_UPLOAD_NEW) ?>" title="<?php echo htmlspecialchars(_MEDIA_UPLOADLINK) ?>" /> <?php $manager->addTicketHidden() ?> </div></form> <?php } // if sizeof $filter = requestVar('filter'); $offset = intRequestVar('offset'); $arr = MEDIA::getMediaListByCollection($currentCollection, $filter);
?> <form method="post" action="media.php"><div> <label for="media_filter"><?php echo htmlspecialchars(_MEDIA_FILTER_LABEL)?></label> <input id="media_filter" type="text" name="filter" value="<?php echo htmlspecialchars($filter)?>" /> <input type="submit" name="action" value="<?php echo htmlspecialchars(_MEDIA_FILTER_APPLY) ?>" /> <input type="hidden" name="collection" value="<?php echo htmlspecialchars($currentCollection)?>" /> <input type="hidden" name="offset" value="<?php echo intval($offset)?>" /> </div></form> <?php ?> <table width="100%"> <caption><?php echo _MEDIA_COLLECTION_LABEL . htmlspecialchars($collections[$currentCollection])?></caption> <tr> <th><?php echo _MEDIA_MODIFIED?></th><th><?php echo _MEDIA_FILENAME?></th><th><?php echo _MEDIA_DIMENSIONS?></th> </tr> <?php if (sizeof($arr)>0) { if (($offset + $CONF['MediaPerPage']) >= sizeof($arr)) $offset = sizeof($arr) - $CONF['MediaPerPage'];
if ($offset < 0) $offset = 0; $idxStart = $offset; $idxEnd = $offset + $CONF['MediaPerPage']; $idxNext = $idxEnd; $idxPrev = $idxStart - $CONF['MediaPerPage'];
if ($idxPrev < 0) $idxPrev = 0;
if ($idxEnd > sizeof($arr)) $idxEnd = sizeof($arr);
for($i=$idxStart;$i<$idxEnd;$i++) { $obj = $arr[$i]; $filename = $DIR_MEDIA . $currentCollection . '/' . $obj->filename;
$old_level = error_reporting(0); $size = @GetImageSize($filename); error_reporting($old_level); $width = $size[0]; $height = $size[1]; $filetype = $size[2]; echo "<tr>"; echo "<td>". date("Y-m-d",$obj->timestamp) ."</td>"; // strings for javascript $jsCurrentCollection = str_replace("'","\\'",$currentCollection); $jsFileName = str_replace("'","\\'",$obj->filename);
if ($filetype != 0) { // image (gif/jpg/png/swf) echo "<td><a href=\"media.php\" onclick=\"chooseImage('", htmlspecialchars($jsCurrentCollection), "','", htmlspecialchars($jsFileName), "'," . "'", htmlspecialchars($width), "','" , htmlspecialchars($height), "'" . ")\" title=\"" . htmlspecialchars($obj->filename). "\">" . htmlspecialchars(shorten($obj->filename,25,'...')) ."</a>"; echo ' (<a href="', htmlspecialchars($CONF['MediaURL'] . $currentCollection . '/' . $obj->filename), '" onclick="window.open(this.href); return false;" title="',htmlspecialchars(_MEDIA_VIEW_TT),'">',_MEDIA_VIEW,'</a>)'; echo "</td>"; } else { // no image (e.g. mpg) echo "<td><a href='media.php' onclick=\"chooseOther('" , htmlspecialchars($jsCurrentCollection), "','", htmlspecialchars($jsFileName), "'" . ")\" title=\"" . htmlspecialchars($obj->filename). "\">" . htmlspecialchars(shorten($obj->filename,30,'...')) ."</a></td>";
} echo '<td>' , htmlspecialchars($width) , 'x' , htmlspecialchars($height) , '</td>'; echo '</tr>'; } } // if (sizeof($arr)>0) ?> </table> <?php if ($idxStart > 0) echo "<a href='media.php?offset=$idxPrev&collection=".urlencode($currentCollection)."'>". _LISTS_PREV."</a> "; if ($idxEnd < sizeof($arr)) echo "<a href='media.php?offset=$idxNext&collection=".urlencode($currentCollection)."'>". _LISTS_NEXT."</a> "; ?> <input id="typeradio0" type="radio" name="typeradio" onclick="setType(0);" checked="checked" /><label for="typeradio0"><?php echo _MEDIA_INLINE?></label> <input id="typeradio1" type="radio" name="typeradio" onclick="setType(1);" /><label for="typeradio1"><?php echo _MEDIA_POPUP?></label> <?php media_foot(); }
/** * Shows a screen where you can select the file to upload */ function media_choose() { global $CONF, $member, $manager;
$currentCollection = requestVar('collection'); $collections = MEDIA::getCollectionList();
media_head(); ?> <h1><?php echo _UPLOAD_TITLE?></h1> <p><?php echo _UPLOAD_MSG?></p> <form method="post" enctype="multipart/form-data" action="media.php"> <div> <input type="hidden" name="action" value="uploadfile" /> <?php $manager->addTicketHidden() ?> <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $CONF['MaxUploadSize']?>" /> File: <br /> <input name="uploadfile" type="file" size="40" /> <?php if (sizeof($collections) > 1) { ?> <br /><br /><label for="upload_collection">Collection:</label> <br /><select name="collection" id="upload_collection"> <?php foreach ($collections as $dirname => $description) { echo '<option value="',htmlspecialchars($dirname),'"'; if ($dirname == $currentCollection) { echo ' selected="selected"'; } echo '>',htmlspecialchars($description),'</option>'; } ?> </select> <?php } else { ?> <input name="collection" type="hidden" value="<?php echo htmlspecialchars(requestVar('collection'))?>" /> <?php } // if sizeof ?> <br /><br /> <input type="submit" value="<?php echo _UPLOAD_BUTTON?>" /> </div> </form> <?php media_foot(); }
/** * accepts a file for upload */ function media_upload() { global $DIR_MEDIA, $member, $CONF;
$uploadInfo = postFileInfo('uploadfile'); $filename = $uploadInfo['name']; $filetype = $uploadInfo['type']; $filesize = $uploadInfo['size']; $filetempname = $uploadInfo['tmp_name']; if ($filesize > $CONF['MaxUploadSize']) media_doError(_ERROR_FILE_TOO_BIG); // check file type against allowed types $ok = 0; $allowedtypes = explode (',', $CONF['AllowedTypes']); foreach ( $allowedtypes as $type ) if (eregi("\." .$type. "$",$filename)) $ok = 1; if (!$ok) media_doError(_ERROR_BADFILETYPE); if (!is_uploaded_file($filetempname)) media_doError(_ERROR_BADREQUEST);
// prefix filename with current date (YYYY-MM-DD-) // this to avoid nameclashes if ($CONF['MediaPrefix']) $filename = strftime("%Y%m%d-", time()) . $filename;
$collection = requestVar('collection'); $res = MEDIA::addMediaObject($collection, $filetempname, $filename);
if ($res != '') media_doError($res); // shows updated list afterwards media_select(); }
function media_loginAndPassThrough() { media_head(); ?> <h1><?php echo _LOGIN_PLEASE?></h1> <form method="post" action="media.php"> <div> <input name="action" value="login" type="hidden" /> <input name="collection" value="<?php echo htmlspecialchars(requestVar('collection'))?>" type="hidden" /> <?php echo _LOGINFORM_NAME?>: <input name="login" /> <br /><?php echo _LOGINFORM_PWD?>: <input name="password" type="password" /> <br /><input type="submit" value="<?php echo _LOGIN?>" /> </div> </form> <p><a href="media.php" onclick="window.close();"><?php echo _POPUP_CLOSE?></a></p> <?php media_foot(); exit; }
function media_doError($msg) { media_head(); ?> <h1><?php echo _ERROR?></h1> <p><?php echo $msg?></p> <p><a href="media.php" onclick="history.back()"><?php echo _BACK?></a></p> <?php media_foot(); exit; }
function media_head() { ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Nucleus Media</title> <link rel="stylesheet" type="text/css" href="styles/popups.css" /> <script type="text/javascript"> var type = 0; function setType(val) { type = val; } function chooseImage(collection, filename, width, height) { window.opener.focus(); window.opener.includeImage(collection, filename, type == 0 ? 'inline' : 'popup', width, height ); window.close(); } function chooseOther(collection, filename) { window.opener.focus(); window.opener.includeOtherMedia(collection, filename); window.close(); } </script> </head> <body> <?php }
function media_foot() { ?> </body> </html> <?php }
?>
|