Files
@ f43d1a4680a9
Branch filter:
Location: hot67beta/administrator/components/com_media/models/list.php
f43d1a4680a9
5.1 KiB
text/x-php
menubar 0 to 10
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 | <?php
/**
* @version $Id: list.php 10381 2008-06-01 03:35:53Z pasamio $
* @package Joomla
* @subpackage Media
* @copyright Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant to the
* GNU General Public License, and as distributed it includes or is derivative
* of works licensed under the GNU General Public License or other free or open
* source software licenses. See COPYRIGHT.php for copyright notices and
* details.
*/
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );
jimport('joomla.application.component.model');
jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.file');
/**
* Media Component List Model
*
* @package Joomla
* @subpackage Media
* @since 1.5
*/
class MediaModelList extends JModel
{
function getState($property = null)
{
static $set;
if (!$set) {
$folder = JRequest::getVar( 'folder', '', '', 'path' );
$this->setState('folder', $folder);
$parent = str_replace("\\", "/", dirname($folder));
$parent = ($parent == '.') ? null : $parent;
$this->setState('parent', $parent);
$set = true;
}
return parent::getState($property);
}
function getImages()
{
$list = $this->getList();
return $list['images'];
}
function getFolders()
{
$list = $this->getList();
return $list['folders'];
}
function getDocuments()
{
$list = $this->getList();
return $list['docs'];
}
/**
* Build imagelist
*
* @param string $listFolder The image directory to display
* @since 1.5
*/
function getList()
{
static $list;
// Only process the list once per request
if (is_array($list)) {
return $list;
}
// Get current path from request
$current = $this->getState('folder');
// If undefined, set to empty
if ($current == 'undefined') {
$current = '';
}
// Initialize variables
if (strlen($current) > 0) {
$basePath = COM_MEDIA_BASE.DS.$current;
} else {
$basePath = COM_MEDIA_BASE;
}
$mediaBase = str_replace(DS, '/', COM_MEDIA_BASE.'/');
$images = array ();
$folders = array ();
$docs = array ();
// Get the list of files and folders from the given folder
$fileList = JFolder::files($basePath);
$folderList = JFolder::folders($basePath);
// Iterate over the files if they exist
if ($fileList !== false) {
foreach ($fileList as $file)
{
if (is_file($basePath.DS.$file) && substr($file, 0, 1) != '.' && strtolower($file) !== 'index.html') {
$tmp = new JObject();
$tmp->name = $file;
$tmp->path = str_replace(DS, '/', JPath::clean($basePath.DS.$file));
$tmp->path_relative = str_replace($mediaBase, '', $tmp->path);
$tmp->size = filesize($tmp->path);
$ext = strtolower(JFile::getExt($file));
switch ($ext)
{
// Image
case 'jpg':
case 'png':
case 'gif':
case 'xcf':
case 'odg':
case 'bmp':
case 'jpeg':
$info = @getimagesize($tmp->path);
$tmp->width = @$info[0];
$tmp->height = @$info[1];
$tmp->type = @$info[2];
$tmp->mime = @$info['mime'];
$filesize = MediaHelper::parseSize($tmp->size);
if (($info[0] > 60) || ($info[1] > 60)) {
$dimensions = MediaHelper::imageResize($info[0], $info[1], 60);
$tmp->width_60 = $dimensions[0];
$tmp->height_60 = $dimensions[1];
} else {
$tmp->width_60 = $tmp->width;
$tmp->height_60 = $tmp->height;
}
if (($info[0] > 16) || ($info[1] > 16)) {
$dimensions = MediaHelper::imageResize($info[0], $info[1], 16);
$tmp->width_16 = $dimensions[0];
$tmp->height_16 = $dimensions[1];
} else {
$tmp->width_16 = $tmp->width;
$tmp->height_16 = $tmp->height;
}
$images[] = $tmp;
break;
// Non-image document
default:
$iconfile_32 = JPATH_ADMINISTRATOR.DS."components".DS."com_media".DS."images".DS."mime-icon-32".DS.$ext.".png";
if (file_exists($iconfile_32)) {
$tmp->icon_32 = "components/com_media/images/mime-icon-32/".$ext.".png";
} else {
$tmp->icon_32 = "components/com_media/images/con_info.png";
}
$iconfile_16 = JPATH_ADMINISTRATOR.DS."components".DS."com_media".DS."images".DS."mime-icon-16".DS.$ext.".png";
if (file_exists($iconfile_16)) {
$tmp->icon_16 = "components/com_media/images/mime-icon-16/".$ext.".png";
} else {
$tmp->icon_16 = "components/com_media/images/con_info.png";
}
$docs[] = $tmp;
break;
}
}
}
}
// Iterate over the folders if they exist
if ($folderList !== false) {
foreach ($folderList as $folder) {
$tmp = new JObject();
$tmp->name = basename($folder);
$tmp->path = str_replace(DS, '/', JPath::clean($basePath.DS.$folder));
$tmp->path_relative = str_replace($mediaBase, '', $tmp->path);
$count = MediaHelper::countFiles($tmp->path);
$tmp->files = $count[0];
$tmp->folders = $count[1];
$folders[] = $tmp;
}
}
$list = array('folders' => $folders, 'docs' => $docs, 'images' => $images);
return $list;
}
}
|