[ Index ]
 

Code source de Horde 3.1.3

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/services/images/ -> view.php (source)

   1  <?php
   2  /**
   3   * Displays an image and allows modifications if required.
   4   *
   5   * Copyright 2003-2006 Marko Djukic <marko@oblo.com>
   6   *
   7   * See the enclosed file COPYING for license information (LGPL). If you
   8   * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
   9   *
  10   * $Horde: horde/services/images/view.php,v 1.20.10.6 2006/05/24 02:22:03 selsky Exp $
  11   *
  12   * @author Marko Djukic <marko@oblo.com>
  13   */
  14  
  15  @define('HORDE_BASE', dirname(__FILE__) . '/../..');
  16  require_once  HORDE_BASE . '/lib/base.php';
  17  
  18  /* Get file info. The following parameters are available:
  19   *  'f' - the filename.
  20   *  's' - the source, either the 'tmp' directory or VFS.
  21   *  'c' - which app's config to use for VFS, defaults to Horde.
  22   *  'p' - the directory of the file.
  23   *  'n' - the name to set to the filename or default to same as filename.
  24   *  'a' - perform some action on the image, such as scaling. */
  25  $file = basename(Util::getFormData('f'));
  26  $source = strtolower(Util::getFormData('s', 'tmp'));
  27  $app_conf = strtolower(Util::getFormData('c', 'horde'));
  28  $name = Util::getFormData('n', $file);
  29  $action = strtolower(Util::getFormData('a'));
  30  
  31  switch ($source) {
  32  case 'vfs':
  33      /* Change app if needed to get the right VFS config. */
  34      $changed_conf = $registry->pushApp($app_conf);
  35  
  36      /* Getting a file from Horde's VFS. */
  37      require_once 'VFS.php';
  38      $vfs = &VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs', $conf['vfs']['type']));
  39      $path = Util::getFormData('p');
  40      $file_data = $vfs->read($path, $file);
  41      if (is_a($file_data, 'PEAR_Error')) {
  42          Horde::logMessage(sprintf('Error displaying image [%s]: %s', $path . '/' . $file, $file_data->getMessage()), __FILE__, __LINE__, PEAR_LOG_ERR);
  43          exit;
  44      }
  45  
  46      /* Return the original app if changed previously. */
  47      if ($changed_conf) {
  48          $registry->popApp($app_conf);
  49      }
  50      break;
  51  
  52  case 'tmp':
  53      /* Getting a file from Horde's temp dir. */
  54      $tmpdir = Horde::getTempDir();
  55      if (empty($action) || $action == 'resize') {
  56          /* Use original if no action or if resizing. */
  57          $file_name = $tmpdir . '/' . $file;
  58      } else {
  59          $file_name = $tmpdir . '/mod_' . $file;
  60          if (!file_exists($file_name)) {
  61              copy($tmpdir . '/' . $file, $file_name);
  62          }
  63      }
  64      if (!file_exists($file_name)) {
  65          Horde::logMessage(sprintf('Image not found [%s]', $file_name), __FILE__, __LINE__, PEAR_LOG_ERR);
  66          exit;
  67      }
  68      $file_data = file_get_contents($file_name);
  69      break;
  70  }
  71  
  72  /* Load the image object. */
  73  require_once 'Horde/Image.php';
  74  $params = array('temp' => Horde::getTempDir());
  75  if (!empty($conf['image']['convert'])) {
  76      $image = &Horde_Image::singleton('im', $params);
  77  } else {
  78      $image = &Horde_Image::singleton('gd', $params);
  79  }
  80  $image->loadString($file, $file_data);
  81  
  82  /* Check if no editing action required and send the image to browser. */
  83  if (empty($action)) {
  84      $image->display();
  85      exit;
  86  }
  87  
  88  /* Image editing required. */
  89  switch ($action) {
  90  case 'rotate':
  91      $image->rotate(Util::getFormData('v'));
  92      break;
  93  
  94  case 'flip':
  95      $image->flip();
  96      break;
  97  
  98  case 'mirror':
  99      $image->mirror();
 100      break;
 101  
 102  case 'grayscale':
 103      $image->grayscale();
 104      break;
 105  
 106  case 'resize':
 107      list($width, $height, $ratio) = explode('.', Util::getFormData('v'));
 108  
 109      /* If no width or height has been passed, get the original
 110       * ones. */
 111      if (empty($width) || empty($height)) {
 112          $orig = $image->getDimensions();
 113      }
 114      if (empty($width)) {
 115          $width = $orig['width'];
 116      }
 117      if (empty($height)) {
 118          $height = $orig['height'];
 119      }
 120  
 121      $image->resize($width, $height, $ratio);
 122  
 123      /* Since the original is always used for resizing make sure the
 124       * write is to 'mod_'. */
 125      $file_name = $tmpdir . '/mod_' . $file;
 126      break;
 127  }
 128  
 129  /* Write out any changes to the temporary file. */
 130  $fp = @fopen($file_name, 'wb');
 131  fwrite($fp, $image->raw());
 132  fclose($fp);
 133  
 134  $image->display();


Généré le : Sun Feb 25 18:01:28 2007 par Balluche grâce à PHPXref 0.7