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