- md5
- 75c7d5dee33ff4f6bd895c72486dcd97
- sha1
- 4daba58e3903aa2db35fa9cea1ca26937819fc37
- sha256
- abd7c6ea0a038116769eadd88dff761db1e27ef1cd62b374d514b02843e5ced6
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
<?php
/**
* @package Joomla.Site
* @subpackage com_media
* @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
/**
* @package Joomla.Site
* @subpackage com_media
*/
class MediaHelper
{
/**
* Checks if the file is an image
* @param string The filename
* @return boolean
*/
function isImage($fileName)
{
static $imageTypes = 'xcf|odg|gif|jpg|png|bmp';
return preg_match("/$imageTypes/i", $fileName);
}
/**
* Checks if the file is an image
* @param string The filename
* @return boolean
*/
function getTypeIcon($fileName)
{
// Get file extension
return strtolower(substr($fileName, strrpos($fileName, '.') + 1));
}
/**
* Checks if the file can be uploaded
* @param array File information
* @param string An error message to be returned
* @return boolean
*/
function canUpload($file, &$err)
{
$params = JComponentHelper::getParams('com_media');
jimport('joomla.filesystem.file');
$format = JFile::getExt($file['name']);
$allowable = explode(',', $params->get('upload_extensions'));
if (!in_array($format, $allowable)) {
$err = JText('COM_MEDIA_ERROR_WARNFILETYPE');
return false;
}
$maxSize = (int) ($params->get('upload_maxsize', 0) * 1024 * 1024);
if ($maxSize > 0 && (int) $file['size'] > $maxSize) {
$err = JText('COM_MEDIA_ERROR_WARNFILETOOLARGE');
return false;
}
return true;
}
public static function parseSize($size)
{
if ($size < 1024) {
return JText::sprintf('COM_MEDIA_FILESIZE_BYTES', $size);
}
elseif ($size < 1024 * 1024) {
return JText::sprintf('COM_MEDIA_FILESIZE_KILOBYTES', sprintf('%01.2f', $size / 1024.0));
}
else {
return JText::sprintf('COM_MEDIA_FILESIZE_MEGABYTES', sprintf('%01.2f', $size / (1024.0 * 1024)));
}
}
function imageResize($width, $height, $target)
{
//takes the larger size of the width and height and applies the
//formula accordingly...this is so this script will work
//dynamically with any size image
if ($width > $height) {
$percentage = ($target / $width);
}
else {
$percentage = ($target / $height);
}
//gets the new value and applies the percentage, then rounds the value
$width = round($width * $percentage);
$height = round($height * $percentage);
//returns the new sizes in html image tag format...this is so you
//can plug this function inside an image tag and just get the
return "width=\"$width\" height=\"$height\"";
}
function countFiles($dir)
{
$total_file = 0;
$total_dir = 0;
if (is_dir($dir)) {
$d = dir($dir);
while (false !== ($entry = $d->read()))
{
if (substr($entry, 0, 1) != '.' && is_file($dir . DIRECTORY_SEPARATOR . $entry) && strpos($entry, '.html') === false && strpos($entry, '.php') === false) {
$total_file++;
}
if (substr($entry, 0, 1) != '.' && is_dir($dir . DIRECTORY_SEPARATOR . $entry)) {
$total_dir++;
}
}
$d->close();
}
return array ($total_file, $total_dir);
}
}
The same content is in 11 releases, Joomla 2.5.18 to 2.5.28. See them all, or every version of this file.