| [ Index ] |
PHP Cross Reference of Joomla 1.5.26 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @version $Id: list.php 14401 2010-01-26 14:10:00Z louis $ 4 * @package Joomla 5 * @subpackage Media 6 * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved. 7 * @license GNU/GPL, see LICENSE.php 8 * Joomla! is free software. This version may have been modified pursuant to the 9 * GNU General Public License, and as distributed it includes or is derivative 10 * of works licensed under the GNU General Public License or other free or open 11 * source software licenses. See COPYRIGHT.php for copyright notices and 12 * details. 13 */ 14 15 // Check to ensure this file is included in Joomla! 16 defined('_JEXEC') or die( 'Restricted access' ); 17 18 jimport('joomla.application.component.model'); 19 jimport('joomla.filesystem.folder'); 20 jimport('joomla.filesystem.file'); 21 22 /** 23 * Media Component List Model 24 * 25 * @package Joomla 26 * @subpackage Media 27 * @since 1.5 28 */ 29 class MediaModelList extends JModel 30 { 31 32 function getState($property = null) 33 { 34 static $set; 35 36 if (!$set) { 37 $folder = JRequest::getVar( 'folder', '', '', 'path' ); 38 $this->setState('folder', $folder); 39 40 $parent = str_replace("\\", "/", dirname($folder)); 41 $parent = ($parent == '.') ? null : $parent; 42 $this->setState('parent', $parent); 43 $set = true; 44 } 45 return parent::getState($property); 46 } 47 48 function getImages() 49 { 50 $list = $this->getList(); 51 return $list['images']; 52 } 53 54 function getFolders() 55 { 56 $list = $this->getList(); 57 return $list['folders']; 58 } 59 60 function getDocuments() 61 { 62 $list = $this->getList(); 63 return $list['docs']; 64 } 65 66 /** 67 * Build imagelist 68 * 69 * @param string $listFolder The image directory to display 70 * @since 1.5 71 */ 72 function getList() 73 { 74 static $list; 75 76 // Only process the list once per request 77 if (is_array($list)) { 78 return $list; 79 } 80 81 // Get current path from request 82 $current = $this->getState('folder'); 83 84 // If undefined, set to empty 85 if ($current == 'undefined') { 86 $current = ''; 87 } 88 89 // Initialize variables 90 if (strlen($current) > 0) { 91 $basePath = COM_MEDIA_BASE.DS.$current; 92 } else { 93 $basePath = COM_MEDIA_BASE; 94 } 95 $mediaBase = str_replace(DS, '/', COM_MEDIA_BASE.'/'); 96 97 $images = array (); 98 $folders = array (); 99 $docs = array (); 100 101 // Get the list of files and folders from the given folder 102 $fileList = JFolder::files($basePath); 103 $folderList = JFolder::folders($basePath); 104 105 // Iterate over the files if they exist 106 if ($fileList !== false) { 107 foreach ($fileList as $file) 108 { 109 if (is_file($basePath.DS.$file) && substr($file, 0, 1) != '.' && strtolower($file) !== 'index.html') { 110 $tmp = new JObject(); 111 $tmp->name = $file; 112 $tmp->path = str_replace(DS, '/', JPath::clean($basePath.DS.$file)); 113 $tmp->path_relative = str_replace($mediaBase, '', $tmp->path); 114 $tmp->size = filesize($tmp->path); 115 116 $ext = strtolower(JFile::getExt($file)); 117 switch ($ext) 118 { 119 // Image 120 case 'jpg': 121 case 'png': 122 case 'gif': 123 case 'xcf': 124 case 'odg': 125 case 'bmp': 126 case 'jpeg': 127 $info = @getimagesize($tmp->path); 128 $tmp->width = @$info[0]; 129 $tmp->height = @$info[1]; 130 $tmp->type = @$info[2]; 131 $tmp->mime = @$info['mime']; 132 133 $filesize = MediaHelper::parseSize($tmp->size); 134 135 if (($info[0] > 60) || ($info[1] > 60)) { 136 $dimensions = MediaHelper::imageResize($info[0], $info[1], 60); 137 $tmp->width_60 = $dimensions[0]; 138 $tmp->height_60 = $dimensions[1]; 139 } else { 140 $tmp->width_60 = $tmp->width; 141 $tmp->height_60 = $tmp->height; 142 } 143 144 if (($info[0] > 16) || ($info[1] > 16)) { 145 $dimensions = MediaHelper::imageResize($info[0], $info[1], 16); 146 $tmp->width_16 = $dimensions[0]; 147 $tmp->height_16 = $dimensions[1]; 148 } else { 149 $tmp->width_16 = $tmp->width; 150 $tmp->height_16 = $tmp->height; 151 } 152 $images[] = $tmp; 153 break; 154 // Non-image document 155 default: 156 $iconfile_32 = JPATH_ADMINISTRATOR.DS."components".DS."com_media".DS."images".DS."mime-icon-32".DS.$ext.".png"; 157 if (file_exists($iconfile_32)) { 158 $tmp->icon_32 = "components/com_media/images/mime-icon-32/".$ext.".png"; 159 } else { 160 $tmp->icon_32 = "components/com_media/images/con_info.png"; 161 } 162 $iconfile_16 = JPATH_ADMINISTRATOR.DS."components".DS."com_media".DS."images".DS."mime-icon-16".DS.$ext.".png"; 163 if (file_exists($iconfile_16)) { 164 $tmp->icon_16 = "components/com_media/images/mime-icon-16/".$ext.".png"; 165 } else { 166 $tmp->icon_16 = "components/com_media/images/con_info.png"; 167 } 168 $docs[] = $tmp; 169 break; 170 } 171 } 172 } 173 } 174 175 // Iterate over the folders if they exist 176 if ($folderList !== false) { 177 foreach ($folderList as $folder) { 178 $tmp = new JObject(); 179 $tmp->name = basename($folder); 180 $tmp->path = str_replace(DS, '/', JPath::clean($basePath.DS.$folder)); 181 $tmp->path_relative = str_replace($mediaBase, '', $tmp->path); 182 $count = MediaHelper::countFiles($tmp->path); 183 $tmp->files = $count[0]; 184 $tmp->folders = $count[1]; 185 186 $folders[] = $tmp; 187 } 188 } 189 190 $list = array('folders' => $folders, 'docs' => $docs, 'images' => $images); 191 192 return $list; 193 } 194 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Mar 28 15:54:07 2012 | Cross-referenced by PHPXref 0.7.1 |