[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/components/com_media/helpers/ -> media.php (source)

   1  <?php
   2  /**
   3   * @version        $Id: media.php 15177 2010-03-04 21:54:31Z ian $
   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  // no direct access
  16  defined('_JEXEC') or die('Restricted access');
  17  
  18  /**
  19   * @package        Joomla
  20   * @subpackage    Media
  21   */
  22  class MediaHelper
  23  {
  24      /**
  25       * Checks if the file is an image
  26       * @param string The filename
  27       * @return boolean
  28       */
  29  	function isImage( $fileName )
  30      {
  31          static $imageTypes = 'xcf|odg|gif|jpg|png|bmp';
  32          return preg_match("/$imageTypes/i",$fileName);
  33      }
  34  
  35      /**
  36       * Checks if the file is an image
  37       * @param string The filename
  38       * @return boolean
  39       */
  40  	function getTypeIcon( $fileName )
  41      {
  42          // Get file extension
  43          return strtolower(substr($fileName, strrpos($fileName, '.') + 1));
  44      }
  45  
  46      /**
  47       * Checks if the file can be uploaded
  48       * @param array File information
  49       * @param string An error message to be returned
  50       * @return boolean
  51       */
  52  	function canUpload( $file, &$err )
  53      {
  54          $params = &JComponentHelper::getParams( 'com_media' );
  55  
  56          jimport('joomla.filesystem.file');
  57          $format = JFile::getExt($file['name']);
  58  
  59          $allowable = explode( ',', $params->get( 'upload_extensions' ));
  60  
  61          if (!in_array($format, $allowable))
  62          {
  63              $err = 'This file type is not supported';
  64              return false;
  65          }
  66          $maxSize = (int) $params->get( 'upload_maxsize', 0 );
  67          if ($maxSize > 0 && (int) $file['size'] > $maxSize)
  68          {
  69              $err = 'This file is too large to upload';
  70              return false;
  71          }
  72          return true;
  73      }
  74  
  75  	function parseSize($size)
  76      {
  77          if ($size < 1024) {
  78              return $size . ' bytes';
  79          }
  80          else
  81          {
  82              if ($size >= 1024 && $size < 1024 * 1024) {
  83                  return sprintf('%01.2f', $size / 1024.0) . ' Kb';
  84              } else {
  85                  return sprintf('%01.2f', $size / (1024.0 * 1024)) . ' Mb';
  86              }
  87          }
  88      }
  89  
  90  	function imageResize($width, $height, $target)
  91      {
  92          //takes the larger size of the width and height and applies the
  93          //formula accordingly...this is so this script will work
  94          //dynamically with any size image
  95          if ($width > $height) {
  96              $percentage = ($target / $width);
  97          } else {
  98              $percentage = ($target / $height);
  99          }
 100  
 101          //gets the new value and applies the percentage, then rounds the value
 102          $width = round($width * $percentage);
 103          $height = round($height * $percentage);
 104  
 105          //returns the new sizes in html image tag format...this is so you
 106          //can plug this function inside an image tag and just get the
 107          return "width=\"$width\" height=\"$height\"";
 108      }
 109  
 110  	function countFiles( $dir )
 111      {
 112          $total_file = 0;
 113          $total_dir = 0;
 114  
 115          if (is_dir($dir)) {
 116              $d = dir($dir);
 117  
 118              while (false !== ($entry = $d->read())) {
 119                  if (substr($entry, 0, 1) != '.' && is_file($dir . DIRECTORY_SEPARATOR . $entry) && strpos($entry, '.html') === false && strpos($entry, '.php') === false) {
 120                      $total_file++;
 121                  }
 122                  if (substr($entry, 0, 1) != '.' && is_dir($dir . DIRECTORY_SEPARATOR . $entry)) {
 123                      $total_dir++;
 124                  }
 125              }
 126  
 127              $d->close();
 128          }
 129  
 130          return array ( $total_file, $total_dir );
 131      }
 132  
 133  }
 134  ?>


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1