Ejemplo n.º 1
0
 /**
  * post
  */
 function post()
 {
     parent::post();
     /* we need to include config, can be removed when we initialize all conf on beggining */
     require_once 'models/common/common_image.php';
     $common_image_conf = common_image::initConfiguration();
     $this->tpl->assign('IMAGE_CONF', $common_image_conf);
     //TODO?: images size can be extracted from COMMON_IMAGE_THUMBNAIL
     /**
      * cycle gallery options
      */
     if ($this->node_data['component']['template'] == 'cycle') {
         if (!$this->node_data['component']['cycle']['fx']) {
             $this->node_data['component']['cycle']['fx'] = $common_image_conf['common_image']['cycle_fx'];
         }
         if (!$this->node_data['component']['cycle']['easing']) {
             $this->node_data['component']['cycle']['easing'] = $common_image_conf['common_image']['cycle_easing'];
         }
         if (!is_numeric($this->node_data['component']['cycle']['timeout']) || $this->node_data['component']['cycle']['timeout'] < 0) {
             $this->node_data['component']['cycle']['timeout'] = $common_image_conf['common_image']['cycle_timeout'];
         }
         if (!is_numeric($this->node_data['component']['cycle']['speed']) || $this->node_data['component']['cycle']['speed'] < 0) {
             $this->node_data['component']['cycle']['speed'] = $common_image_conf['common_image']['cycle_speed'];
         }
         $this->tpl->assign("SELECTED_cycle_fx_{$this->node_data['component']['cycle']['fx']}", "selected='selected'");
         $this->tpl->assign("SELECTED_cycle_easing_{$this->node_data['component']['cycle']['easing']}", "selected='selected'");
         //must assign NODE before parsing
         $this->tpl->assign("NODE", $this->node_data);
         $this->tpl->parse('content.cycle_options');
     }
     /**
      * local templates
      */
     $this->displayLocalImageGalleryTemplates();
     /**
      * template selected
      */
     $this->tpl->assign("SELECTED_template_{$this->node_data['component']['template']}", "selected='selected'");
 }
Ejemplo n.º 2
0
 /**
  * resize
  */
 static function resize($file, $required_width, $required_height = false, $method = 'extent', $gravity = 'center', $fill = false)
 {
     //first check file exists and is readable
     if (!is_readable(ONXSHOP_PROJECT_DIR . $file)) {
         return false;
     }
     //prepare variables
     if (is_numeric($required_height)) {
         $directory = ONXSHOP_PROJECT_DIR . "var/thumbnails/{$required_width}x{$required_height}";
         $thumb_file = "var/thumbnails/{$required_width}x{$required_height}/" . md5($file);
     } else {
         $directory = ONXSHOP_PROJECT_DIR . "var/thumbnails/{$required_width}";
         $thumb_file = "var/thumbnails/{$required_width}/" . md5($file);
     }
     $file_rp = ONXSHOP_PROJECT_DIR . $file;
     $image_resize_options = "_{$method}_{$gravity}_{$fill}";
     // TODO check valid options
     if ($image_resize_options == "___") {
         $image_resize_options = "";
     }
     if ($image_resize_options) {
         $thumb_file = $thumb_file . $image_resize_options;
     }
     $thumb_file_rp = ONXSHOP_PROJECT_DIR . $thumb_file;
     //check if the destination directory exits
     if (!is_readable($directory)) {
         if (!mkdir($directory)) {
             msg("common_image.resize(): Cannot create folder {$directory}", 'error');
         }
     }
     //determinate real image size
     $size = common_image::getImageSize($file_rp);
     $width = $required_width;
     $height = round($required_width / $size['proportion']);
     msg("Thumbnail will have size {$width} x {$height}", 'ok', 3);
     /**
      * resize method option
      */
     if (!in_array(strtolower($method), array('crop', 'extent'))) {
         $method = 'extent';
     }
     /**
      * gravity option
      * NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast
      */
     if (!in_array(strtolower($gravity), array('northwest', 'north', 'northeast', 'west', 'center', 'east', 'southwest', 'south', 'southeast'))) {
         $gravity = 'center';
     }
     /**
      * fill option
      */
     if ($fill == true) {
         $fill = '^';
     } else {
         $fill = '';
     }
     /**
      * if height is specified align in center and allow to fill the space
      * see  http://www.imagemagick.org/Usage/thumbnails/#cut
      *      http://www.imagemagick.org/Usage/resize/#shrink
      */
     if (is_numeric($required_height)) {
         $background = common_image::supportsTransparency($file_rp) ? 'none' : 'white';
         $other_im_params = "-background {$background} -alpha background -gravity {$gravity} -{$method} {$width}x{$required_height}";
         $height = $required_height;
     } else {
         $other_im_params = '';
     }
     /**
      * return cached file or create with ImageMagick
      */
     if (is_readable($thumb_file_rp)) {
         return $thumb_file;
     } else {
         $image_configuration = common_image::initConfiguration();
         $jpeg_quality = $image_configuration['jpeg_quality'];
         $file_rp_escaped = escapeshellarg($file_rp);
         $width = (int) $width;
         $height = (int) $height;
         $jpeg_quality = (int) $jpeg_quality;
         $thumb_file_rp_escaped = escapeshellarg($thumb_file_rp);
         //usage: resize $filename $width $height $target_filename $quality $other_options
         ///usr/bin/convert "$1" -colorspace RGB -depth 8 -quality $QUALITY -thumbnail $2x$3^ $6 "$4"
         $colorspace = self::isOldImageMagickVersion() ? 'RGB' : 'sRGB';
         $shell_command = "convert {$file_rp_escaped} -colorspace {$colorspace} -depth 8 -quality {$jpeg_quality} -thumbnail {$width}x{$height}{$fill} {$other_im_params} {$thumb_file_rp_escaped}";
         $result = local_exec($shell_command);
         if (is_readable($thumb_file_rp)) {
             return $thumb_file;
         } else {
             return false;
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * main action
  */
 public function mainAction()
 {
     /* we need to include config, can be removed when we initialize all conf on beginning */
     require_once 'models/common/common_image.php';
     $common_image_conf = common_image::initConfiguration();
     /**
      * Set input variables
      */
     $relation = preg_replace('/[^a-zA-Z_-]/', '', $this->GET['relation']);
     $role = preg_replace('/[^a-zA-Z_-]/', '', $this->GET['role']);
     if (is_numeric($this->GET['node_id'])) {
         $node_id = $this->GET['node_id'];
     } else {
         $node_id = 0;
     }
     if ($this->GET['limit']) {
         $limit = $this->GET['limit'];
     } else {
         $limit = "";
     }
     /**
      * cycle conf
      */
     $cycle = array();
     if ($this->GET['cycle_fx']) {
         $cycle['fx'] = $this->GET['cycle_fx'];
     } else {
         $cycle['fx'] = 'fade';
     }
     //"'disable'" value must be interpreted as "null"
     if ($this->GET['cycle_easing'] && $this->GET['cycle_easing'] != 'disable') {
         $cycle['easing'] = "'{$this->GET['cycle_easing']}'";
     } else {
         $cycle['easing'] = 'null';
     }
     if (is_numeric($this->GET['cycle_timeout'])) {
         $cycle['timeout'] = $this->GET['cycle_timeout'];
     } else {
         $cycle['timeout'] = 0;
     }
     if (is_numeric($this->GET['cycle_speed'])) {
         $cycle['speed'] = $this->GET['cycle_speed'];
     } else {
         $cycle['speed'] = 2000;
     }
     //cycle_link_to_node_id
     $cycle['link_to_node_id'] = array();
     if ($this->GET['cycle_link_to_node_id'] != '') {
         $cycle_link_to_node_id_items = explode(',', $this->GET['cycle_link_to_node_id']);
         foreach ($cycle_link_to_node_id_items as $cycle_link_to_node_id_item) {
             if (is_numeric($cycle_link_to_node_id_item)) {
                 $cycle['link_to_node_id'][] = $cycle_link_to_node_id_item;
             }
         }
     }
     /**
      * image path
      */
     $img_path = $this->getImagePath();
     /**
      * Find what object we need
      */
     $Image = $this->createImageObject($this->GET['relation']);
     if (is_numeric($this->GET['width'])) {
         $width = $this->GET['width'];
     } else {
         $width = 100;
     }
     if (is_numeric($this->GET['height'])) {
         $height = $this->GET['height'];
     } else {
         $height = false;
     }
     /**
      * initialize variables for extreme dimensions
      */
     $dimension_extreme['width_max'] = 0;
     $dimension_extreme['width_min'] = 0;
     $dimension_extreme['height_max'] = 0;
     $dimension_extreme['height_min'] = 0;
     $dimension_extreme['proportion_max'] = 0;
     $dimension_extreme['proportion_min'] = 10;
     /**
      * Prepare query
      */
     $role = $this->GET['role'] ? "role='{$this->GET['role']}' AND " : '';
     $image_get_query = "{$role} node_id={$node_id}";
     /**
      * Get the list
      */
     $images = $Image->listing($image_get_query, "priority DESC, id ASC", $limit);
     /**
      * Loop through the list
      */
     if (is_array($images)) {
         foreach ($images as $i => $img) {
             $img['path'] = $img_path;
             $img['first_id'] = $images[0]['id'];
             $size = $Image->getImageSize(ONXSHOP_PROJECT_DIR . $img['src']);
             if ($size) {
                 if ($size['width'] > $dimension_extreme['width_max']) {
                     $dimension_extreme['width_max'] = $size['width'];
                 }
                 if ($size['width'] < $dimension_extreme['width_min']) {
                     $dimension_extreme['width_min'] = $size['width'];
                 }
                 if ($size['height'] > $dimension_extreme['height_max']) {
                     $dimension_extreme['height_max'] = $size['height'];
                 }
                 if ($size['height'] < $dimension_extreme['height_min']) {
                     $dimension_extreme['height_min'] = $size['height'];
                 }
                 if ($size['proportion'] > $dimension_extreme['proportion_max']) {
                     $dimension_extreme['proportion_max'] = $size['proportion'];
                 }
                 if ($size['proportion'] < $dimension_extreme['proportion_min']) {
                     $dimension_extreme['proportion_min'] = $size['proportion'];
                 }
                 // deprecated, keep for backward compatibility
                 if (is_numeric($cycle['link_to_node_id'][$i])) {
                     $img['link_to_node_id'] = $cycle['link_to_node_id'][$i];
                 }
                 $this->assignAndParseItem($img);
             }
         }
         $images_count = count($images);
     }
     /**
      * Calculate relative height
      */
     if ($width > 0) {
         $dimension_max['width'] = $width;
         $dimension_max['height'] = $width / $dimension_extreme['proportion_min'];
     } else {
         $dimension_max['width'] = $dimension_extreme['width_max'];
         $dimension_max['height'] = $dimension_extreme['height_max'];
     }
     /**
      * overwrite when fixed height requested
      */
     if ($height) {
         $dimension_max['height'] = $height;
     }
     /**
      * round
      */
     $dimension_max['width'] = round($dimension_max['width']);
     $dimension_max['height'] = round($dimension_max['height']);
     $this->tpl->assign("DIMENSION_MAX", $dimension_max);
     $this->tpl->assign("CYCLE", $cycle);
     /**
      * show control and placeholder only if multiple images
      */
     if ($images_count > 1) {
         $this->tpl->parse('content.control');
         $this->tpl->parse('content.placeholder');
     }
     return true;
 }
Ejemplo n.º 4
0
 /**
  * initiateImagePropertiesItem
  */
 public function initiateImagePropertiesItem()
 {
     require_once 'models/common/common_image.php';
     $common_image_conf = common_image::initConfiguration();
     $this->tpl->assign('IMAGE_CONF', $common_image_conf);
     /**
      * image width
      */
     if ($this->node_data['component']['image_width'] == 0) {
         $this->tpl->assign("SELECTED_image_width_original", "selected='selected'");
         $this->node_data['component']['image_width'] = $this->getLargestAssociatedImageWidth($this->node_data['id']);
     } else {
         $this->tpl->assign("SELECTED_image_width_custom", "selected='selected'");
     }
     /**
      * image ratio constrain
      */
     $this->tpl->assign("SELECTED_image_constrain_{$this->node_data['component']['image_constrain']}", "selected='selected'");
     /**
      * main image width (TODO merge with image_width)
      */
     if ($this->node_data['component']['main_image_width'] == 0) {
         $this->tpl->assign("SELECTED_main_image_width_original", "selected='selected'");
         $this->node_data['component']['main_image_width'] = $this->getLargestAssociatedImageWidth($this->node_data['id']);
     } else {
         $this->tpl->assign("SELECTED_main_image_width_custom", "selected='selected'");
     }
     /**
      * main image ratio constrain (TODO: merge with image_width)
      */
     $this->tpl->assign("SELECTED_main_image_constrain_{$this->node_data['component']['main_image_constrain']}", "selected='selected'");
     /**
      * fill option
      */
     $this->tpl->assign("SELECTED_image_fill_{$this->node_data['component']['image_fill']}", "selected='selected'");
 }
Ejemplo n.º 5
0
 /**
  * main action
  */
 public function mainAction()
 {
     /* we need to include config*/
     require_once 'models/common/common_image.php';
     $common_image_conf = common_image::initConfiguration();
     require_once 'models/common/common_node.php';
     $Node = new common_node();
     $node_data = $Node->nodeDetail($this->GET['id']);
     if ($node_data['component']['template'] == '') {
         $node_data['component']['template'] = 'single';
     }
     /**
      * image size: set width
      */
     if (is_numeric($node_data['component']['main_image_width']) && $node_data['component']['main_image_width'] > 0) {
         $image_width = $node_data['component']['main_image_width'];
     } else {
         if ($node_data['component']['main_image_constrain']) {
             $Image = new common_image();
             $image_list = $Image->listFiles($node_data['id']);
             $image_width = 9999;
             foreach ($image_list as $item) {
                 if ($item['imagesize']['width'] < $image_width) {
                     $image_width = $item['imagesize']['width'] - $item['imagesize']['width'] % 5;
                 }
             }
             if ($image_width == 9999) {
                 $image_width = 0;
             }
         } else {
             $image_width = 0;
         }
     }
     /**
      * image size: check constrain and set appropriate height
      */
     switch ($node_data['component']['main_image_constrain']) {
         case '1-1':
             $image_height = $image_width;
             break;
         case '2_39-1':
             // 2.39:1
             $image_height = (int) ($image_width / 2.39 * 1);
             break;
         case '16-9':
             $image_height = (int) ($image_width / 16 * 9);
             break;
         case '4-3':
             $image_height = (int) ($image_width / 16 * 9);
             break;
         case '0':
         default:
             $image_height = 0;
             break;
     }
     /**
      * image size: fill cropping option
      * 
      */
     if (is_numeric($node_data['component']['image_fill'])) {
         $fill = $node_data['component']['image_fill'];
     } else {
         $fill = 1;
     }
     /**
      * what controller
      */
     if (file_exists(ONXSHOP_PROJECT_DIR . "controllers/component/image_gallery/{$node_data['component']['template']}.php") || file_exists(ONXSHOP_DIR . "controllers/component/image_gallery/{$node_data['component']['template']}.php")) {
         $image_controller = 'component/image_gallery/' . $node_data['component']['template'];
     } else {
         $image_controller = 'component/image_gallery';
     }
     /**
      * what template
      */
     if (file_exists(ONXSHOP_PROJECT_DIR . "templates/component/image_gallery/{$node_data['component']['template']}.html") || file_exists(ONXSHOP_DIR . "templates/component/image_gallery/{$node_data['component']['template']}.html")) {
         $image_template = 'component/image_gallery/' . $node_data['component']['template'];
     } else {
         $image_template = 'component/image_gallery';
     }
     /**
      * check cycle link_to_node_id
      */
     if ($node_data['component']['cycle']['link_to_node_id']) {
         $cycle['link_to_node_id'] = $node_data['component']['cycle']['link_to_node_id'];
     } else {
         $cycle['link_to_node_id'] = '';
     }
     /**
      * timeout for slideshow
      */
     if ($node_data['component']['cycle']['fx']) {
         $cycle['fx'] = $node_data['component']['cycle']['fx'];
     } else {
         $cycle['fx'] = $common_image_conf['cycle_fx'];
     }
     if ($node_data['component']['cycle']['easing']) {
         $cycle['easing'] = $node_data['component']['cycle']['easing'];
     } else {
         $cycle['easing'] = $common_image_conf['cycle_easing'];
     }
     if (is_numeric($node_data['component']['cycle']['speed'])) {
         $cycle['speed'] = $node_data['component']['cycle']['speed'];
     } else {
         $cycle['speed'] = $common_image_conf['cycle_speed'];
     }
     if (is_numeric($node_data['component']['cycle']['timeout'])) {
         $cycle['timeout'] = $node_data['component']['cycle']['timeout'];
     } else {
         $cycle['timeout'] = $common_image_conf['cycle_timeout'];
     }
     /**
      * disable limit
      */
     $image_limit = '';
     /**
      * call controller
      */
     $Onxshop_Request = new Onxshop_Request("{$image_controller}@{$image_template}~relation=node:role=main:width={$image_width}:height={$image_height}:fill={$fill}:node_id={$node_data['id']}:limit={$image_limit}:cycle_fx={$cycle['fx']}:cycle_easing={$cycle['easing']}:cycle_timeout={$cycle['timeout']}:cycle_speed={$cycle['speed']}:cycle_link_to_node_id={$cycle['link_to_node_id']}~");
     $this->tpl->assign("CONTENT", $Onxshop_Request->getContent());
     $this->tpl->assign('NODE', $node_data);
     $this->tpl->assign('IMAGE_CONF', $common_image_conf);
     /**
      * display title
      */
     $this->displayTitle($node_data);
     return true;
 }
Ejemplo n.º 6
0
require_once 'lib/onxshop.functions.php';
require_once 'model.php';
/**
 * onxshop_conf local overwrite due to missing database connection
 * See https://github.com/laposa/onxshop/issues/8
 */
$GLOBALS['onxshop_conf'] = array();
$local_configuration_overwrite_file = ONXSHOP_PROJECT_DIR . 'conf/common_image.php';
if (file_exists($local_configuration_overwrite_file)) {
    include_once $local_configuration_overwrite_file;
}
/**
 * get common_image configuration
 */
require_once ONXSHOP_DIR . "models/common/common_image.php";
$image_configuration = common_image::initConfiguration();
/**
 * check requested width
 */
if ($width > $image_configuration['width_max']) {
    $image_file = null;
} else {
    if ($width < $image_configuration['thumbnail_width_min']) {
        $image_file = null;
    }
    if ($width > $image_configuration['thumbnail_width_max']) {
        $image_file = null;
    }
    if ($width % $image_configuration['thumbnail_step'] > 0) {
        $image_file = null;
    }