- md5
- 41529d0e2b8c4132471c51ff36803a7b
- sha1
- 099b6af3ca82e6bb58d01ab8906bf16b994848d8
- sha256
- d11a137d151f6bbf6d85d0f9ca30240aac5961499f421b0d6b8017216684f414
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
<?php
/**
* @package Joomla.Administrator
* @subpackage com_media
*
* @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.file');
/**
* Media Component List Model
*
* @since 1.5
*/
class MediaModelList extends JModelLegacy
{
/**
* Method to get model state variables
*
* @param string $property Optional parameter name
* @param mixed $default Optional default value
*
* @return object The property where specified, the state object where omitted
*
* @since 1.5
*/
public function getState($property = null, $default = null)
{
static $set;
if (!$set)
{
$input = JFactory::getApplication()->input;
$folder = $input->get('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, $default);
}
/**
* Get the images on the current folder
*
* @return array
*
* @since 1.5
*/
public function getImages()
{
$list = $this->getList();
return $list['images'];
}
/**
* Get the folders on the current folder
*
* @return array
*
* @since 1.5
*/
public function getFolders()
{
$list = $this->getList();
return $list['folders'];
}
/**
* Get the documents on the current folder
*
* @return array
*
* @since 1.5
*/
public function getDocuments()
{
$list = $this->getList();
return $list['docs'];
}
/**
* Build imagelist
*
* @return array
*
* @since 1.5
*/
public function getList()
{
static $list;
// Only process the list once per request
if (is_array($list))
{
return $list;
}
// Get current path from request
$current = (string) $this->getState('folder');
$basePath = COM_MEDIA_BASE . ((strlen($current) > 0) ? '/' . $current : '');
$mediaBase = str_replace(DIRECTORY_SEPARATOR, '/', COM_MEDIA_BASE . '/');
// Reset base path
if (strpos(realpath($basePath), JPath::clean(realpath(COM_MEDIA_BASE))) !== 0)
{
$basePath = COM_MEDIA_BASE;
}
$images = array ();
$folders = array ();
$docs = array ();
$videos = array ();
$fileList = false;
$folderList = false;
if (file_exists($basePath))
{
// 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)
{
$tmpBaseObject = new JObject;
foreach ($fileList as $file)
{
if (is_file($basePath . '/' . $file) && substr($file, 0, 1) != '.' && strtolower($file) !== 'index.html')
{
$tmp = clone $tmpBaseObject;
$tmp->name = $file;
$tmp->title = $file;
$tmp->path = str_replace(DIRECTORY_SEPARATOR, '/', JPath::clean($basePath . '/' . $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':
case 'ico':
$info = @getimagesize($tmp->path);
$tmp->width = @$info[0];
$tmp->height = @$info[1];
$tmp->type = @$info[2];
$tmp->mime = @$info['mime'];
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;
// Video
case 'mp4':
$tmp->icon_32 = 'media/mime-icon-32/' . $ext . '.png';
$tmp->icon_16 = 'media/mime-icon-16/' . $ext . '.png';
$videos[] = $tmp;
break;
// Non-image document
default:
$tmp->icon_32 = 'media/mime-icon-32/' . $ext . '.png';
$tmp->icon_16 = 'media/mime-icon-16/' . $ext . '.png';
$docs[] = $tmp;
break;
}
}
}
}
// Iterate over the folders if they exist
if ($folderList !== false)
{
$tmpBaseObject = new JObject;
foreach ($folderList as $folder)
{
$tmp = clone $tmpBaseObject;
$tmp->name = basename($folder);
$tmp->path = str_replace(DIRECTORY_SEPARATOR, '/', JPath::clean($basePath . '/' . $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, 'videos' => $videos);
return $list;
}
/**
* Get the videos on the current folder
*
* @return array
*
* @since 3.5
*/
public function getVideos()
{
$list = $this->getList();
return $list['videos'];
}
}
The same content is in 30 releases, Joomla 3.9.15-rc to 3.10.0-alpha1. See them all, or every version of this file.