Ejemplo n.º 1
0
 /**
  * Returns a list of types
  * @param mixed Boolean
  * @param mixed Boolean
  * @return array
  */
 function setDirectory($dir = null, $protect = true)
 {
     $success = false;
     // checks to confirm existence of directory
     // then confirms directory is writeable
     if ($dir === null) {
         $dir = $this->getDirectory();
     }
     if ($protect) {
         $helper = new DSCHelper();
         $helper->checkDirectory($dir);
         // then confirms existence of htaccess file
         $htaccess = $dir . DS . '.htaccess';
         if (!($fileexists = JFile::exists($htaccess))) {
             $destination = $htaccess;
             $text = "deny from all";
             if (!JFile::write($destination, $text)) {
                 $this->setError(JText::_('STORAGE DIRECTORY IS UNPROTECTED'));
                 return $success;
             }
         }
     }
     $this->_directory = $dir;
     return $this->_directory;
 }
Ejemplo n.º 2
0
 /**
  * Batch actions for saving a thumb of an image
  *
  * @param image	string	filename of the image
  * @param options	array	array of options: width, height, thumb_path
  * @return thumb full path
  */
 function saveThumb($img, $options = array())
 {
     $thumb_path = $img->getDirectory() . DS . 'thumbs';
     $img_width = 'thumb_width';
     $img_height = 'thumb_height';
     $img->load();
     // Default width or options width?
     if (!empty($options['width']) && is_numeric($options['width'])) {
         $width = $options['width'];
     } else {
         $width = $this->{$img_width};
     }
     // Default height or options height?
     if (!empty($options['height']) && is_numeric($options['height'])) {
         $height = $options['height'];
     } else {
         $height = $this->{$img_height};
     }
     // Default thumb path or options thumb path?
     if (!empty($options['thumb_path'])) {
         $dest_dir = $options['thumb_path'];
     } else {
         $dest_dir = $thumb_path;
     }
     $helper = new DSCHelper();
     $helper->checkDirectory($dest_dir);
     if ($width >= $height) {
         $img->resizeToWidth($width);
     } else {
         $img->resizeToHeight($height);
     }
     $dest_path = $dest_dir . DS . $img->getPhysicalName();
     if (!$img->save($dest_path)) {
         $this->setError($img->getError());
         return false;
     }
     return $dest_path;
 }