| [ Index ] | PHP Cross Reference of Mambo 4.6.5 |
|
| [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @package Mambo 4 * @subpackage Media Manager 5 * @author Mambo Foundation Inc see README.php 6 * @copyright (C) 2000 - 2009 Mambo Foundation Inc. 7 * See COPYRIGHT.php for copyright notices and details. 8 * @license GNU/GPL Version 2, see LICENSE.php 9 * 10 * Redistributions of files must retain the above copyright notice. 11 * 12 * Mambo is free software; you can redistribute it and/or 13 * modify it under the terms of the GNU General Public License 14 * as published by the Free Software Foundation; version 2 of the License. 15 */ 16 17 /** ensure this file is being included by a parent file */ 18 defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' ); 19 20 // ensure user has access to this function 21 if (!($acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'components', 'all' ) 22 | $acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'components', 'com_media' ))) { 23 mosRedirect( 'index2.php', T_('You are not authorized to view this resource.') ); 24 } 25 26 require_once( $mainframe->getPath( 'admin_html' ) ); 27 //require_once( $mainframe->getPath( 'class' ) ); 28 29 $cid = mosGetParam( $_POST, 'cid', array(0) ); 30 $foldername = mosGetParam($_POST, 'foldername', ''); 31 $listdir = mosGetParam($_REQUEST, 'listdir', ''); 32 $dirPath = mosGetParam($_POST, 'dirPath', ''); 33 $task = mosGetParam($_REQUEST, 'task', ''); 34 $delFile = mosGetParam($_REQUEST, 'delFile', ''); 35 $delFolder = mosGetParam($_REQUEST, 'delFolder', ''); 36 37 if (!is_array( $cid )) { 38 $cid = array(0); 39 } 40 41 if (is_int(strpos ($listdir, "..")) && $listdir<>'') { 42 mosRedirect( "index2.php?option=com_media&listdir=".$_POST['dirPath'], T_("NO HACKING PLEASE") ); 43 } 44 45 switch ($task) { 46 47 case "upload": 48 upload(); 49 showMedia($dirPath); 50 break; 51 52 case "newdir": 53 if (ini_get('safe_mode')=="On") { 54 mosRedirect( "index2.php?option=com_media&listdir=".$_POST['dirPath'], T_("Directory creation not allowed while running in SAFE MODE as this can cause problems.") ); 55 } 56 else { 57 create_folder($foldername,$dirPath); 58 } 59 showMedia($dirPath); 60 break; 61 62 case "delete": 63 delete_file($delFile,$listdir); 64 showMedia($listdir); 65 break; 66 67 case "deletefolder": 68 delete_folder($delFolder,$listdir); 69 showMedia($listdir); 70 break; 71 72 case "list": 73 listImages($listdir); 74 break; 75 76 default: 77 showMedia($listdir); 78 break; 79 } 80 81 82 83 84 function delete_file($delfile, $listdir) 85 { 86 global $mosConfig_absolute_path; 87 $del_image = $mosConfig_absolute_path."/images/stories".$listdir."/".$delfile; 88 unlink($del_image); 89 } 90 91 function create_folder($folder_name,$dirPath) 92 { 93 global $mosConfig_absolute_path; 94 95 if(strlen($folder_name) >0) 96 { 97 if (eregi("[^0-9a-zA-Z_]", $folder_name)) { 98 mosRedirect( "index2.php?option=com_media&listdir=".$_POST['dirPath'], T_("Directory name must only contain alphanumeric characters and no spaces please.") ); 99 } 100 $folder = $mosConfig_absolute_path."/images/stories".$dirPath."/".$folder_name; 101 if(!is_dir($folder) && !is_file($folder)) 102 { 103 mosMakePath($folder); 104 $fp = fopen($folder."/index.html", "w" ); 105 fwrite( $fp, "<html>\n<body bgcolor=\"#FFFFFF\">\n</body>\n</html>" ); 106 fclose( $fp ); 107 mosChmod($folder."/index.html"); 108 $refresh_dirs = true; 109 } 110 } 111 } 112 113 function delete_folder($delFolder,$listdir) 114 { 115 global $mosConfig_absolute_path; 116 117 $del_html = $mosConfig_absolute_path.'/images/stories'.$listdir.$delFolder.'/index.html'; 118 $del_folder = $mosConfig_absolute_path.'/images/stories'.$listdir.$delFolder; 119 120 $entry_count = 0; 121 $dir = opendir( $del_folder ); 122 while ( false !== ($entry = readdir( $dir ))) 123 { 124 if( $entry != "." & $entry != ".." & strtolower($entry) != "index.html" ) 125 $entry_count++; 126 } 127 closedir( $dir ); 128 129 if( $entry_count < 1 ) 130 { 131 @unlink($del_html); 132 rmdir($del_folder); 133 } else { 134 echo '<font color="red">'.T_('Unable to delete: not empty!').'</font>'; 135 } 136 } 137 138 function upload(){ 139 140 global $mosConfig_absolute_path; 141 142 if(isset($_FILES['upload']) && is_array($_FILES['upload']) && isset($_POST['dirPath'])) 143 { 144 $dirPathPost = $_POST['dirPath']; 145 146 if(strlen($dirPathPost) > 0) 147 { 148 if(substr($dirPathPost,0,1)=='/') 149 $IMG_ROOT .= $dirPathPost; 150 else 151 $IMG_ROOT = $dirPathPost; 152 } 153 154 if(strrpos($IMG_ROOT, '/')!= strlen($IMG_ROOT)-1) 155 $IMG_ROOT .= '/'; 156 157 do_upload( $_FILES['upload'], $mosConfig_absolute_path.'/images/stories/'.$dirPathPost.'/'); 158 } 159 } 160 161 function do_upload($file, $dest_dir) 162 { 163 global $clearUploads; 164 165 if (file_exists($dest_dir.$file['name'])) { 166 mosRedirect( "index2.php?option=com_media&listdir=".$_POST['dirPath'], T_("Upload FAILED. File already exists") ); 167 } 168 if (!eregi( ".bmp$|.gif$|.jpg$|.png$|.ppt$|.doc$|.xls$|.swf$|.pdf$", $file['name'] )){ 169 mosRedirect( "index2.php?option=com_media&listdir=".$_POST['dirPath'], T_("Only files of type gif, png, jpg, bmp, pdf, swf, doc, xls or ppt can be uploaded") ); 170 } 171 if (!move_uploaded_file($file['tmp_name'], $dest_dir.strtolower($file['name']))){ 172 mosRedirect( "index2.php?option=com_media&listdir=".$_POST['dirPath'], T_("Upload FAILED") ); 173 } 174 else { 175 mosChmod($dest_dir.strtolower($file['name'])); 176 mosRedirect( "index2.php?option=com_media&listdir=".$_POST['dirPath'], T_("Upload complete") ); 177 } 178 179 $clearUploads = true; 180 } 181 182 function recursive_listdir($base) { 183 static $filelist = array(); 184 static $dirlist = array(); 185 186 if(is_dir($base)) { 187 $dh = opendir($base); 188 while (false !== ($dir = readdir($dh))) { 189 if (is_dir($base ."/". $dir) && $dir !== '.' && $dir !== '..' && strtolower($dir) !== 'cvs') { 190 $subbase = $base ."/". $dir; 191 $dirlist[] = $subbase; 192 $subdirlist = recursive_listdir($subbase); 193 } 194 } 195 closedir($dh); 196 } 197 return $dirlist; 198 } 199 200 201 /** 202 * Show media manager 203 * @param string The image directory to display 204 */ 205 function showMedia($listdir) { 206 207 global $mosConfig_absolute_path, $mosConfig_live_site; 208 209 // get list of directories 210 $imgFiles = recursive_listdir( $mosConfig_absolute_path."/images/stories" ); 211 $images = array(); 212 $folders = array(); 213 $folders[] = mosHTML::makeOption( "/" ); 214 foreach ($imgFiles as $file) { 215 $folders[] = mosHTML::makeOption( substr($file,strlen($mosConfig_absolute_path."/images/stories")) ); 216 } 217 if (is_array($folders)) { 218 sort( $folders ); 219 } 220 // create folder selectlist 221 $dirPath = mosHTML::selectList( $folders, 'dirPath', "class=\"inputbox\" size=\"1\" " 222 ."onchange=\"goUpDir()\" ", 223 'value', 'text', $listdir ); 224 225 HTML_Media::showMedia($dirPath,$listdir); 226 } 227 228 229 /** 230 * Build imagelist 231 * @param string The image directory to display 232 */ 233 function listImages($listdir) { 234 global $mosConfig_absolute_path, $mosConfig_live_site; 235 236 // get list of images 237 $d = @dir($mosConfig_absolute_path."/images/stories/".$listdir); 238 239 if($d) 240 { 241 242 //var_dump($d); 243 $images = array(); 244 $folders = array(); 245 $docs = array(); 246 247 while (false !== ($entry = $d->read())) 248 { 249 $img_file = $entry; 250 if(is_file($mosConfig_absolute_path."/images/stories".$listdir.'/'.$img_file) && substr($entry,0,1) != '.' && strtolower($entry) !== 'index.html') 251 { 252 if (eregi( ".bmp$|.gif$|.jpg$|.png$", $img_file )) { 253 $image_info = @getimagesize($mosConfig_absolute_path."/images/stories/".$listdir.'/'.$img_file); 254 $file_details['file'] = $mosConfig_absolute_path."/images/stories".$listdir."/".$img_file; 255 $file_details['img_info'] = $image_info; 256 $file_details['size'] = filesize($mosConfig_absolute_path."/images/stories".$listdir."/".$img_file); 257 $images[$entry] = $file_details; 258 } 259 else { 260 // file is document 261 $docs[$entry] = $img_file; 262 } 263 } 264 else if(is_dir($mosConfig_absolute_path."/images/stories/".$listdir.'/'.$img_file) && substr($entry,0,1) != '.' && strtolower($entry) !== 'cvs') 265 { 266 $folders[$entry] = $img_file; 267 } 268 } 269 $d->close(); 270 271 HTML_Media::imageStyle($listdir); 272 273 if(count($images) > 0 || count($folders) > 0 || count($docs) > 0) 274 { 275 //now sort the folders and images by name. 276 ksort($images); 277 ksort($folders); 278 ksort($docs); 279 280 281 HTML_Media::draw_table_header(); 282 283 for($i=0; $i<count($folders); $i++) 284 { 285 $folder_name = key($folders); 286 HTML_Media::show_dir('/'.$folders[$folder_name], $folder_name,$listdir); 287 next($folders); 288 } 289 for($i=0; $i<count($docs); $i++) 290 { 291 $doc_name = key($docs); 292 $iconfile= $mosConfig_absolute_path."/administrator/components/com_media/images/".substr($doc_name,-3)."_16.png"; 293 if (file_exists($iconfile)) { 294 $icon = "components/com_media/images/".(substr($doc_name,-3))."_16.png" ; } 295 else { 296 $icon = "components/com_media/images/con_info.png"; 297 } 298 HTML_Media::show_doc($docs[$doc_name], $listdir, $icon); 299 next($docs); 300 } 301 for($i=0; $i<count($images); $i++) 302 { 303 $image_name = key($images); 304 HTML_Media::show_image($images[$image_name]['file'], $image_name, $images[$image_name]['img_info'], $images[$image_name]['size'],$listdir); 305 next($images); 306 } 307 HTML_Media::draw_table_footer(); 308 } 309 else 310 { 311 HTML_Media::draw_no_results(); 312 } 313 } 314 else 315 { 316 HTML_Media::draw_no_dir(); 317 } 318 319 320 321 function rm_all_dir($dir) 322 { 323 //$dir = dir_name($dir); 324 //echo "OPEN:".$dir.'<Br>'; 325 if(is_dir($dir)) 326 { 327 $d = @dir($dir); 328 329 while (false !== ($entry = $d->read())) 330 { 331 //echo "#".$entry.'<br>'; 332 if($entry != '.' && $entry != '..') 333 { 334 $node = $dir.'/'.$entry; 335 //echo "NODE:".$node; 336 if(is_file($node)) { 337 //echo " - is file<br>"; 338 unlink($node); 339 } 340 else if(is_dir($node)) { 341 //echo " - is Dir<br>"; 342 rm_all_dir($node); 343 } 344 } 345 } 346 $d->close(); 347 348 rmdir($dir); 349 } 350 //echo "RM: $dir <br>"; 351 } 352 353 354 355 356 357 } 358 359 360 361 362 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Feb 8 00:05:01 2012 | Cross-referenced by PHPXref 0.7 |
| Mambo API: Mambo is Free software released under the GNU/General Public License, Version 2 |