diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/calendar_monthly.class.php | 24 | ||||
-rw-r--r-- | include/category_cats.inc.php | 4 | ||||
-rw-r--r-- | include/category_default.inc.php | 2 | ||||
-rw-r--r-- | include/common.inc.php | 4 | ||||
-rw-r--r-- | include/config_default.inc.php | 16 | ||||
-rw-r--r-- | include/constants.php | 3 | ||||
-rw-r--r-- | include/derivative.inc.php | 239 | ||||
-rw-r--r-- | include/derivative_params.inc.php | 315 | ||||
-rw-r--r-- | include/derivative_std_params.inc.php | 116 | ||||
-rw-r--r-- | include/functions.inc.php | 6 | ||||
-rw-r--r-- | include/functions_notification.inc.php | 4 | ||||
-rw-r--r-- | include/picture_metadata.inc.php | 22 | ||||
-rw-r--r-- | include/ws_functions.inc.php | 65 |
13 files changed, 731 insertions, 89 deletions
diff --git a/include/calendar_monthly.class.php b/include/calendar_monthly.class.php index 2c14088c9..556fd055c 100644 --- a/include/calendar_monthly.class.php +++ b/include/calendar_monthly.class.php @@ -350,7 +350,7 @@ function build_month_calendar(&$tpl_var) { $page['chronology_date'][CDAY]=$day; $query = ' -SELECT id, file,tn_ext,path, width, height, '.pwg_db_get_dayofweek($this->date_field).'-1 as dow'; +SELECT id, file,representative_ext,path,width, height, '.pwg_db_get_dayofweek($this->date_field).'-1 as dow'; $query.= $this->inner_sql; $query.= $this->get_date_where(); $query.= ' @@ -359,18 +359,13 @@ SELECT id, file,tn_ext,path, width, height, '.pwg_db_get_dayofweek($this->date_f unset ( $page['chronology_date'][CDAY] ); $row = pwg_db_fetch_assoc(pwg_query($query)); - $items[$day]['tn_url'] = get_thumbnail_url($row); + $derivative = new DerivativeImage(IMG_SQUARE, new SrcImage($row)); + $items[$day]['derivative'] = $derivative; $items[$day]['file'] = $row['file']; - $items[$day]['path'] = $row['path']; - $items[$day]['tn_ext'] = @$row['tn_ext']; - $items[$day]['width'] = $row['width']; - $items[$day]['height'] = $row['height']; $items[$day]['dow'] = $row['dow']; } - if ( !empty($items) - and $conf['calendar_month_cell_width']>0 - and $conf['calendar_month_cell_height']>0) + if ( !empty($items) ) { list($known_day) = array_keys($items); $known_dow = $items[$known_day]['dow']; @@ -396,8 +391,7 @@ SELECT id, file,tn_ext,path, width, height, '.pwg_db_get_dayofweek($this->date_f array_push( $wday_labels, array_shift($wday_labels) ); } - $cell_width = $conf['calendar_month_cell_width']; - $cell_height = $conf['calendar_month_cell_height']; + list($cell_width, $cell_height) = ImageStdParams::get_by_type(IMG_SQUARE)->sizing->ideal_size; $tpl_weeks = array(); $tpl_crt_week = array(); @@ -430,11 +424,7 @@ SELECT id, file,tn_ext,path, width, height, '.pwg_db_get_dayofweek($this->date_f } else { - $thumb = get_thumbnail_path($items[$day]); - $tn_size = @getimagesize($thumb); - - $tn_width = $tn_size[0]; - $tn_height = $tn_size[1]; + list($tn_width,$tn_height) = $items[$day]['derivative']->get_size(); // now need to fit the thumbnail of size tn_size within // a cell of size cell_size by playing with CSS position (left/top) @@ -491,7 +481,7 @@ SELECT id, file,tn_ext,path, width, height, '.pwg_db_get_dayofweek($this->date_f 'DAY' => $day, 'DOW' => $dow, 'NB_ELEMENTS' => $items[$day]['nb_images'], - 'IMAGE' => $items[$day]['tn_url'], + 'IMAGE' => $items[$day]['derivative']->get_url(), 'U_IMG_LINK' => $url, 'IMAGE_STYLE' => $css_style, 'IMAGE_ALT' => $items[$day]['file'], diff --git a/include/category_cats.inc.php b/include/category_cats.inc.php index a6a686477..2ecdf5ec2 100644 --- a/include/category_cats.inc.php +++ b/include/category_cats.inc.php @@ -189,7 +189,7 @@ SELECT * { if ($row['level'] <= $user['level']) { - $row['tn_src'] = get_thumbnail_url($row); + $row['tn_src'] = DerivativeImage::thumb_url($row); $infos_of_image[$row['id']] = $row; } else @@ -236,7 +236,7 @@ SELECT * $result = pwg_query($query); while ($row = pwg_db_fetch_assoc($result)) { - $row['tn_src'] = get_thumbnail_url($row); + $row['tn_src'] = DerivativeImage::thumb_url($row); $infos_of_image[$row['id']] = $row; } } diff --git a/include/category_default.inc.php b/include/category_default.inc.php index 7204e1b4b..61c81aa9e 100644 --- a/include/category_default.inc.php +++ b/include/category_default.inc.php @@ -113,7 +113,7 @@ foreach ($pictures as $row) $tpl_var = array( 'ID' => $row['id'], - 'TN_SRC' => get_thumbnail_url($row), + 'TN_SRC' => DerivativeImage::thumb_url($row), 'TN_ALT' => htmlspecialchars(strip_tags($name)), 'TN_TITLE' => get_thumbnail_title($row), 'URL' => $url, diff --git a/include/common.inc.php b/include/common.inc.php index 724fc83d3..5cc3317e7 100644 --- a/include/common.inc.php +++ b/include/common.inc.php @@ -107,7 +107,7 @@ if(isset($conf['show_php_errors']) && !empty($conf['show_php_errors'])) include(PHPWG_ROOT_PATH . 'include/constants.php'); include(PHPWG_ROOT_PATH . 'include/functions.inc.php'); -include( PHPWG_ROOT_PATH .'include/template.class.php'); +include(PHPWG_ROOT_PATH .'include/template.class.php'); // Database connection try @@ -132,6 +132,8 @@ if (!$conf['check_upgrade_feed']) } } +ImageStdParams::load_from_db(); + load_plugins(); // users can have defined a custom order pattern, incompatible with GUI form diff --git a/include/config_default.inc.php b/include/config_default.inc.php index 883018ed5..e01f3a7c8 100644 --- a/include/config_default.inc.php +++ b/include/config_default.inc.php @@ -89,14 +89,6 @@ $conf['calendar_show_any'] = true; //no elements for these $conf['calendar_show_empty'] = true; -// calendar_month_cell_width, calendar_month_cell_height : define the -// width and the height of a cell in the monthly calendar when viewing a -// given month. a value of 0 means that the pretty view is not shown. -// a good suggestion would be to have the width and the height equal -// and smaller than upload thumbnails configuration size. -$conf['calendar_month_cell_width'] =80; -$conf['calendar_month_cell_height']=80; - // newcat_default_commentable : at creation, must a category be commentable // or not ? $conf['newcat_default_commentable'] = true; @@ -760,4 +752,10 @@ $conf['alternative_pem_url'] = ''; // based on the EXIF "orientation" tag, should we rotate photos added in the // upload form or through pwg.images.addSimple web API method? $conf['upload_form_automatic_rotation'] = true; -?> + +// 0-'auto', 1-'derivative' 2-'script' +$conf['derivative_url_style']=0; + +$conf['chmod_value']=0777; + +?>
\ No newline at end of file diff --git a/include/constants.php b/include/constants.php index cfc7e9c87..f77bd739e 100644 --- a/include/constants.php +++ b/include/constants.php @@ -27,7 +27,8 @@ define('PHPWG_DEFAULT_LANGUAGE', 'en_UK'); define('PHPWG_DEFAULT_TEMPLATE', 'Sylvia'); define('PHPWG_THEMES_PATH', $conf['themes_dir'].'/'); -define('PWG_COMBINED_DIR', PWG_LOCAL_DIR.'combined/'); +defined('PWG_COMBINED_DIR') or define('PWG_COMBINED_DIR', PWG_LOCAL_DIR.'combined/'); +defined('PWG_DERIVATIVE_DIR') or define('PWG_DERIVATIVE_DIR', PWG_LOCAL_DIR.'i/'); // Required versions define('REQUIRED_PHP_VERSION', '5.0.0'); diff --git a/include/derivative.inc.php b/include/derivative.inc.php new file mode 100644 index 000000000..11f1ebb76 --- /dev/null +++ b/include/derivative.inc.php @@ -0,0 +1,239 @@ +<?php +// +-----------------------------------------------------------------------+ +// | Piwigo - a PHP based photo gallery | +// +-----------------------------------------------------------------------+ +// | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org | +// +-----------------------------------------------------------------------+ +// | This program is free software; you can redistribute it and/or modify | +// | it under the terms of the GNU General Public License as published by | +// | the Free Software Foundation | +// | | +// | This program is distributed in the hope that it will be useful, but | +// | WITHOUT ANY WARRANTY; without even the implied warranty of | +// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | +// | General Public License for more details. | +// | | +// | You should have received a copy of the GNU General Public License | +// | along with this program; if not, write to the Free Software | +// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | +// | USA. | +// +-----------------------------------------------------------------------+ + +final class SrcImage +{ + public $rel_path; + + public $coi=null; + private $size=null; + + function __construct($infos) + { + global $conf; + + $ext = get_extension($infos['path']); + if (in_array($ext, $conf['picture_ext'])) + { + $this->rel_path = $infos['path']; + } + elseif (!empty($infos['representative_ext'])) + { + $pi = pathinfo($infos['path']); + $file_wo_ext = get_filename_wo_extension($pi['basename']); + $this->rel_path = $pi['dirname'].'/pwg_representative/' + .$file_wo_ext.'.'.$infos['representative_ext']; + } + else + { + $this->rel_path = get_themeconf('mime_icon_dir').strtolower($ext).'.png'; + } + + $this->coi = @$infos['coi']; + if (isset($infos['width']) && isset($infos['height'])) + { + $this->size = array($infos['width'], $infos['height']); + } + } + + function has_size() + { + return $this->size != null; + } + + function get_size() + { + if ($this->size == null) + not_implemented(); // get size from file + return $this->size; + } +} + + + +final class DerivativeImage +{ + const SAME_AS_SRC = 0x10; + + public $src_image; + + private $requested_type; + + private $flags = 0; + private $params; + private $rel_path, $rel_url; + + function __construct($type, $src_image) + { + $this->src_image = $src_image; + if (is_string($type)) + { + $this->requested_type = $type; + $this->params = ImageStdParams::get_by_type($type); + } + else + { + $this->requested_type = IMG_CUSTOM; + $this->params = $type; + } + + self::build($src_image, $this->params, $this->rel_path, $this->rel_url, $this->flags); + } + + static function thumb_url($infos) + { + $src_image = new SrcImage($infos); + self::build($src_image, ImageStdParams::get_by_type(IMG_THUMB), $rel_path, $rel_url); + return get_root_url().$rel_url; + } + + static function url($type, $infos) + { + $src_image = new SrcImage($infos); + $params = is_string($type) ? ImageStdParams::get_by_type($type) : $type; + self::build($src_image, $params, $rel_path, $rel_url); + return get_root_url().$rel_url; + } + + static function get_all($infos) + { + $src_image = new SrcImage($infos); + $ret = array(); + foreach (ImageStdParams::get_defined_type_map() as $type => $params) + { + $derivative = new DerivativeImage($params, $src_image); + $ret[$type] = $derivative; + } + foreach (ImageStdParams::get_undefined_type_map() as $type => $type2) + { + $ret[$type] = $ret[$type2]; + } + + return $ret; + } + + private static function build($src, &$params, &$rel_path, &$rel_url, &$flags = null) + { + if ( $src->has_size() && $params->is_identity( $src->get_size() ) ) + { + // todo - what if we have a watermark maybe return a smaller size? + $flags |= self::SAME_AS_SRC; + $params = null; + $rel_path = $rel_url = $src->rel_path; + return; + } + + $tokens=array(); + $tokens[] = substr($params->type,0,2); + + if (!empty($src->coi)) + { + $tokens[] = 'ci'.$src->coi; + } + + if ($params->type==IMG_CUSTOM) + { + $params->add_url_tokens($tokens); + } + + $loc = $src->rel_path; + if (substr_compare($loc, './', 0, 2)==0) + { + $loc = substr($loc, 2); + } + elseif (substr_compare($loc, '../', 0, 3)==0) + { + $loc = substr($loc, 3); + } + $loc = substr_replace($loc, '-'.implode('_', $tokens), strrpos($loc, '.'), 0 ); + + $rel_path = PWG_DERIVATIVE_DIR.$loc; + + global $conf; + $url_style=$conf['derivative_url_style']; + if (!$url_style) + { + $mtime = @filemtime(PHPWG_ROOT_PATH.$rel_path); + if ($mtime===false or $mtime < $params->last_mod_time) + { + $url_style = 2; + } + else + { + $url_style = 1; + } + } + + if ($url_style == 2) + { + $rel_url = 'i'; + if ($conf['php_extension_in_urls']) $rel_url .= '.php'; + if ($conf['question_mark_in_urls']) $rel_url .= '?'; + $rel_url .= '/'.$loc; + } + else + { + $rel_url = $rel_path; + } + } + + function get_url() + { + return get_root_url().$this->rel_url; + } + + function same_as_source() + { + return $this->flags & self::SAME_AS_SRC; + } + + + /* returns the size of the derivative image*/ + function get_size() + { + if ($this->flags & self::SAME_AS_SRC) + { + return $this->src_image->get_size(); + } + return $this->params->compute_final_size($this->src_image->get_size(), $this->src_image->coi); + } + + function get_size_htm() + { + $size = $this->get_size(); + if ($size) + { + return 'width="'.$size[0].'" height="'.$size[1].'"'; + } + } + + function get_size_hr() + { + $size = $this->get_size(); + if ($size) + { + return $size[0].' x '.$size[1]; + } + } + +} + +?>
\ No newline at end of file diff --git a/include/derivative_params.inc.php b/include/derivative_params.inc.php new file mode 100644 index 000000000..9fe76cd43 --- /dev/null +++ b/include/derivative_params.inc.php @@ -0,0 +1,315 @@ +<?php +// +-----------------------------------------------------------------------+ +// | Piwigo - a PHP based photo gallery | +// +-----------------------------------------------------------------------+ +// | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org | +// +-----------------------------------------------------------------------+ +// | This program is free software; you can redistribute it and/or modify | +// | it under the terms of the GNU General Public License as published by | +// | the Free Software Foundation | +// | | +// | This program is distributed in the hope that it will be useful, but | +// | WITHOUT ANY WARRANTY; without even the implied warranty of | +// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | +// | General Public License for more details. | +// | | +// | You should have received a copy of the GNU General Public License | +// | along with this program; if not, write to the Free Software | +// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | +// | USA. | +// +-----------------------------------------------------------------------+ + +function size_to_url($s) +{ + if ($s[0]==$s[1]) + { + return $s[0]; + } + return $s[0].'x'.$s[1]; +} + +function url_to_size($s) +{ + $pos = strpos($s, 'x'); + if ($pos===false) + { + return array((int)$s, (int)$s); + } + return array((int)substr($s,0,$pos), (int)substr($s,$pos+1)); +} + +function size_equals($s1, $s2) +{ + return ($s1[0]==$s2[0] && $s1[1]==$s2[1]); +} + + +/** small utility to manipulate a 'rectangle'*/ +final class ImageRect +{ + public $l,$t,$r,$b; + + function __construct($l) + { + $this->l = $this->t = 0; + $this->r = $l[0]; + $this->b = $l[1]; + } + + function width() + { + return $this->r - $this->l; + } + + function height() + { + return $this->b - $this->t; + } + + function crop_h($pixels, $coi, $force) + { + if ($this->width() <= $pixels) + return; + $tlcrop = floor($pixels/2); + + if (!empty($coi)) + { + $coil = floor($this->r * (ord($coi[0]) - ord('a'))/25); + $coir = ceil($this->r * (ord($coi[2]) - ord('a'))/25); + $availableL = $coil > $this->l ? $coil - $this->l : 0; + $availableR = $coir < $this->r ? $this->r - $coir : 0; + if ($availableL + $availableR <= $pixels) + { + if (!$force) + { + $pixels = $availableL + $availableR; + $tlcrop = $availableL; + } + } + else + { + if ($availableL < $tlcrop) + { + $tlcrop = $availableL; + } + elseif ($availableR < $tlcrop) + { + $tlcrop = $pixels - $availableR; + } + } + } + $this->l += $tlcrop; + $this->r -= $pixels - $tlcrop; + } + + function crop_v($pixels, $coi, $force) + { + if ($this->height() <= $pixels) + return; + $tlcrop = floor($pixels/2); + + if (!empty($coi)) + { + $coit = floor($this->b * (ord($coi[1]) - ord('a'))/25); + $coib = ceil($this->b * (ord($coi[3]) - ord('a'))/25); + $availableT = $coit > $this->t ? $coit - $this->t : 0; + $availableB = $coib < $this->b ? $this->b - $coib : 0; + if ($availableT + $availableB <= $pixels) + { + if (!$force) + { + $pixels = $availableT + $availableB; + $tlcrop = $availableT; + } + } + else + { + if ($availableT < $tlcrop) + { + $tlcrop = $availableT; + } + elseif ($availableB < $tlcrop) + { + $tlcrop = $pixels - $availableB; + } + } + } + $this->t += $tlcrop; + $this->b -= $pixels - $tlcrop; + } + +} + + +/*how we crop and/or resize an image*/ +final class SizingParams +{ + function __construct($ideal_size, $max_crop = 0, $min_size = null) + { + $this->ideal_size = $ideal_size; + $this->max_crop = $max_crop; + $this->min_size = $min_size; + } + + static function classic($w, $h) + { + return new SizingParams( array($w,$h) ); + } + + static function square($w) + { + return new SizingParams( array($w,$w), 1, array($w,$w) ); + } + + function add_url_tokens(&$tokens) + { + if ($this->max_crop == 0) + { + $tokens[] = 's'.size_to_url($this->ideal_size); + } + elseif ($this->max_crop == 1 && size_equals($this->ideal_size, $this->min_size) ) + { + $tokens[] = 'e'.size_to_url($this->ideal_size); + } + else + { + $tokens[] = size_to_url($this->ideal_size); + $tokens[] = sprintf('%02x', round(100*$this->max_crop) ); + $tokens[] = size_to_url($this->min_size); + } + } + + static function from_url_tokens($tokens) + { + if (count($tokens)<1) + throw new Exception('Empty array while parsing Sizing'); + $token = array_shift($tokens); + if ($token[0]=='s') + { + return new SizingParams( url_to_size( substr($token,1) ) ); + } + if ($token[0]=='e') + { + $s = url_to_size( substr($token,1) ); + return new SizingParams($s, 1, $s); + } + + $ideal_size = url_to_size( $token ); + if (count($tokens)<2) + throw new Exception('Sizing arr'); + + $token = array_shift($tokens); + $crop = sscanf('%02x' , $token) / 100; + + $token = array_shift($tokens); + $min_size = url_to_size( $token ); + return new SizingParams($ideal_size, $crop, $min_size); + } + + + function compute($in_size, $coi, &$crop_rect, &$scale_size) + { + $destCrop = new ImageRect($in_size); + + if ($this->max_crop > 0) + { + $ratio_w = $destCrop->width() / $this->ideal_size[0]; + $ratio_h = $destCrop->height() / $this->ideal_size[1]; + if ($ratio_w>1 || $ratio_h>1) + { + if ($ratio_w > $ratio_h) + { + $h = $destCrop->height() / $ratio_w; + if ($h < $this->min_size[1]) + { + $idealCropPx = $destCrop->width() - round($destCrop->height() * $this->ideal_size[0] / $this->min_size[1], 0); + $maxCropPx = round($this->max_crop * $destCrop->width()); + $destCrop->crop_h( min($idealCropPx, $maxCropPx), $coi, false); + } + } + else + { + $w = $destCrop->width() / $ratio_h; + if ($w < $this->min_size[0]) + { + $idealCropPx = $destCrop->height() - round($destCrop->width() * $this->ideal_size[1] / $this->min_size[0], 0); + $maxCropPx = round($this->max_crop * $destCrop->height()); + $destCrop->crop_v( min($idealCropPx, $maxCropPx), $coi, false); + } + } + } + } + + $scale_size = array($destCrop->width(), $destCrop->height()); + + $ratio_w = $destCrop->width() / $this->ideal_size[0]; + $ratio_h = $destCrop->height() / $this->ideal_size[1]; + if ($ratio_w>1 || $ratio_h>1) + { + if ($ratio_w > $ratio_h) + { + $scale_size[0] = $this->ideal_size[0]; + $scale_size[1] = floor($scale_size[1] / $ratio_w); + } + else + { + $scale_size[0] = floor($scale_size[0] / $ratio_h); + $scale_size[1] = $this->ideal_size[1]; + } + } + else + { + $scale_size = null; + } + + $crop_rect = null; + if ($destCrop->width()!=$in_size[0] || $destCrop->height()!=$in_size[1] ) + { + $crop_rect = $destCrop; + } + } + +} + + +/*how we generate a derivative image*/ +final class ImageParams +{ + public $type = IMG_CUSTOM; + public $last_mod_time = 0; // used for non-custom images to regenerate the cached files + public $sizing; + + function __construct($sizing) + { + $this->sizing = $sizing; + } + + function add_url_tokens(&$tokens) + { + $this->sizing->add_url_tokens($tokens); + } + + static function from_url_tokens($tokens) + { + $sizing = SizingParams::from_url_tokens($tokens); + $ret = new ImageParams($sizing); + return $ret; + } + + function compute_final_size($in_size, $coi) + { + $this->sizing->compute( $in_size, $coi, $crop_rect, $scale_size ); + return $scale_size != null ? $scale_size : $in_size; + } + + function is_identity($in_size) + { + if ($in_size[0] > $this->sizing->ideal_size[0] or + $in_size[1] > $this->sizing->ideal_size[1] ) + { + return false; + } + return true; + } +} +?>
\ No newline at end of file diff --git a/include/derivative_std_params.inc.php b/include/derivative_std_params.inc.php new file mode 100644 index 000000000..3a6394886 --- /dev/null +++ b/include/derivative_std_params.inc.php @@ -0,0 +1,116 @@ +<?php +// +-----------------------------------------------------------------------+ +// | Piwigo - a PHP based photo gallery | +// +-----------------------------------------------------------------------+ +// | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org | +// +-----------------------------------------------------------------------+ +// | This program is free software; you can redistribute it and/or modify | +// | it under the terms of the GNU General Public License as published by | +// | the Free Software Foundation | +// | | +// | This program is distributed in the hope that it will be useful, but | +// | WITHOUT ANY WARRANTY; without even the implied warranty of | +// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | +// | General Public License for more details. | +// | | +// | You should have received a copy of the GNU General Public License | +// | along with this program; if not, write to the Free Software | +// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | +// | USA. | +// +-----------------------------------------------------------------------+ + +define('IMG_SQUARE', 'square'); +define('IMG_THUMB', 'thumb'); +define('IMG_SMALL', 'small'); +define('IMG_MEDIUM', 'medium'); +define('IMG_LARGE', 'large'); +define('IMG_XLARGE', 'xlarge'); +define('IMG_XXLARGE', 'xxlarge'); +define('IMG_CUSTOM', 'custom'); + +final class ImageStdParams +{ + private static $all_types = array(IMG_SQUARE,IMG_THUMB,IMG_SMALL,IMG_MEDIUM,IMG_LARGE,IMG_XLARGE,IMG_XXLARGE); + private static $all_type_map = array(); + private static $type_map = array(); + private static $undefined_type_map = array(); + + static function get_all_types() + { + return self::$all_types; + } + + static function get_all_type_map() + { + return self::$all_type_map; + } + + static function get_defined_type_map() + { + return self::$type_map; + } + + static function get_undefined_type_map() + { + return self::$undefined_type_map; + } + + static function get_by_type($type) + { + return self::$all_type_map[$type]; + } + + static function load_from_db() + { + self::make_default(); + self::build_maps(); + } + + static function load_from_file() + { + self::make_default(); + self::build_maps(); + } + + static function make_default() + { + //todo + self::$type_map[IMG_SQUARE] = new ImageParams( SizingParams::square(100,100) ); + self::$type_map[IMG_THUMB] = new ImageParams( SizingParams::classic(144,144) ); + self::$type_map[IMG_SMALL] = new ImageParams( SizingParams::classic(240,240) ); + self::$type_map[IMG_MEDIUM] = new ImageParams( SizingParams::classic(432,432) ); + self::$type_map[IMG_LARGE] = new ImageParams( SizingParams::classic(648,576) ); + self::$type_map[IMG_XLARGE] = new ImageParams( SizingParams::classic(864,648) ); + self::$type_map[IMG_XXLARGE] = new ImageParams( SizingParams::classic(1200,900) ); + } + + private static function build_maps() + { + foreach (self::$type_map as $type=>$params) + { + $params->type = $type; + } + self::$all_type_map = self::$type_map; + + for ($i=0; $i<count(self::$all_types); $i++) + { + $tocheck = self::$all_types[$i]; + if (!isset(self::$type_map[$tocheck])) + { + for ($j=$i-1; $j>=0; $j--) + { + $target = self::$all_types[$j]; + if (isset(self::$type_map[$target])) + { + self::$all_type_map[$tocheck] = self::$type_map[$target]; + self::$undefined_type_map[$tocheck] = $target; + break; + } + } + } + } + } + +} + +?>
\ No newline at end of file diff --git a/include/functions.inc.php b/include/functions.inc.php index e69d5ced6..f0a83d197 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -30,6 +30,9 @@ include_once( PHPWG_ROOT_PATH .'include/functions_html.inc.php' ); include_once( PHPWG_ROOT_PATH .'include/functions_tag.inc.php' ); include_once( PHPWG_ROOT_PATH .'include/functions_url.inc.php' ); include_once( PHPWG_ROOT_PATH .'include/functions_plugins.inc.php' ); +include_once( PHPWG_ROOT_PATH .'/include/derivative_params.inc.php'); +include_once( PHPWG_ROOT_PATH .'/include/derivative_std_params.inc.php'); +include_once( PHPWG_ROOT_PATH .'/include/derivative.inc.php'); //----------------------------------------------------------- generic functions @@ -167,12 +170,13 @@ function mkgetdir($dir, $flags=MKGETDIR_DEFAULT) { if ( !is_dir($dir) ) { + global $conf; if (substr(PHP_OS, 0, 3) == 'WIN') { $dir = str_replace('/', DIRECTORY_SEPARATOR, $dir); } $umask = umask(0); - $mkd = @mkdir($dir, 0755, ($flags&MKGETDIR_RECURSIVE) ? true:false ); + $mkd = @mkdir($dir, $conf['chmod_value'], ($flags&MKGETDIR_RECURSIVE) ? true:false ); umask($umask); if ($mkd==false) { diff --git a/include/functions_notification.inc.php b/include/functions_notification.inc.php index d7f7ea26e..06b9ce543 100644 --- a/include/functions_notification.inc.php +++ b/include/functions_notification.inc.php @@ -458,7 +458,7 @@ SELECT date_available, if ($max_elements>0) { // get some thumbnails ... $query = ' -SELECT DISTINCT id, path, name, tn_ext, file +SELECT DISTINCT id, path, name, representative_ext, file FROM '.IMAGES_TABLE.' i INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id=image_id '.$where_sql.' AND date_available=\''.$dates[$i]['date_available'].'\' @@ -535,7 +535,7 @@ function get_html_description_recent_post_date($date_detail) foreach($date_detail['elements'] as $element) { - $tn_src = get_thumbnail_url($element); + $tn_src = DerivativeImage::thumb_url($element); $description .= '<a href="'. make_picture_url(array( 'image_id' => $element['id'], diff --git a/include/picture_metadata.inc.php b/include/picture_metadata.inc.php index 59683ff01..db0aff887 100644 --- a/include/picture_metadata.inc.php +++ b/include/picture_metadata.inc.php @@ -26,18 +26,6 @@ * */ -// $picture['current']['high_url'] may not be set if the user has no access -// to the high definition, but we may want to display metadata and read the -// high definition is available -$high_url = null; -if (isset($picture['current']['high_url'])) -{ - $high_url = $picture['current']['high_url']; -} -else -{ - $high_url = get_high_url($picture['current']); -} include_once(PHPWG_ROOT_PATH.'/include/functions_metadata.inc.php'); if (($conf['show_exif']) and (function_exists('read_exif_data'))) @@ -49,10 +37,6 @@ if (($conf['show_exif']) and (function_exists('read_exif_data'))) } $exif = get_exif_data($picture['current']['image_path'], $exif_mapping); - if (count($exif) == 0 and $picture['current']['has_high']) - { - $exif = get_exif_data($high_url, $exif_mapping); - } if (count($exif) > 0) { @@ -96,10 +80,6 @@ if (($conf['show_exif']) and (function_exists('read_exif_data'))) if ($conf['show_iptc']) { $iptc = get_iptc_data($picture['current']['image_path'], $conf['show_iptc_mapping']); - if (count($iptc) == 0 and $picture['current']['has_high']) - { - $iptc = get_iptc_data($high_url, $conf['show_iptc_mapping']); - } if (count($iptc) > 0) { @@ -122,4 +102,4 @@ if ($conf['show_iptc']) } -?> +?>
\ No newline at end of file diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php index 6adbfa065..3213beb1c 100644 --- a/include/ws_functions.inc.php +++ b/include/ws_functions.inc.php @@ -146,15 +146,22 @@ function ws_std_image_sql_order( $params, $tbl_name='' ) */ function ws_std_get_urls($image_row) { - $ret = array( - 'tn_url' => get_thumbnail_url($image_row), - 'element_url' => get_element_url($image_row) - ); + $ret = array(); global $user; - if ($user['enabled_high'] and $image_row['has_high'] ) + if ($user['enabled_high']) + { + $ret['element_url'] = get_element_url($image_row); + } + + $derivatives = DerivativeImage::get_all($image_row); + $derivatives_arr = array(); + foreach($derivatives as $type=>$derivative) { - $ret['high_url'] = get_high_url($image_row); + $size = $derivative->get_size(); + $size != null or $size=array(null,null); + $derivatives_arr[$type] = array('url' => $derivative->get_url(), 'width'=>$size[0], 'height'=>$size[1] ); } + $ret['derivatives'] = $derivatives_arr;; return $ret; } @@ -165,7 +172,7 @@ function ws_std_get_urls($image_row) function ws_std_get_image_xml_attributes() { return array( - 'id','tn_url','element_url','high_url', 'file','width','height','hit','date_available','date_creation' + 'id','element_url', 'file','width','height','hit','date_available','date_creation' ); } @@ -620,7 +627,7 @@ SELECT id, name, permalink, uppercats, global_rank, id_uppercat, $new_image_ids = array(); $query = ' -SELECT id, path, tn_ext, level +SELECT id, path, representative_ext, level FROM '.IMAGES_TABLE.' WHERE id IN ('.implode(',', $image_ids).') ;'; @@ -629,7 +636,7 @@ SELECT id, path, tn_ext, level { if ($row['level'] <= $user['level']) { - $thumbnail_src_of[$row['id']] = get_thumbnail_url($row); + $thumbnail_src_of[$row['id']] = DerivativeImage::thumb_url($row); } else { @@ -668,14 +675,14 @@ SELECT id, path, tn_ext, level if (count($new_image_ids) > 0) { $query = ' -SELECT id, path, tn_ext +SELECT id, path, representative_ext FROM '.IMAGES_TABLE.' WHERE id IN ('.implode(',', $new_image_ids).') ;'; $result = pwg_query($query); while ($row = pwg_db_fetch_assoc($result)) { - $thumbnail_src_of[$row['id']] = get_thumbnail_url($row); + $thumbnail_src_of[$row['id']] = DerivativeImage::thumb_url($row); } } } @@ -1370,8 +1377,7 @@ function ws_images_add_chunk($params, &$service) // create the upload directory tree if not exists if (!is_dir($upload_dir)) { umask(0000); - $recursive = true; - if (!@mkdir($upload_dir, 0777, $recursive)) + if (!@mkdir($upload_dir, 0777, true)) { return new PwgError(500, 'error during buffer directory creation'); } @@ -1424,8 +1430,7 @@ function merge_chunks($output_filepath, $original_sum, $type) if (is_file($output_filepath)) { - new PwgError(500, '[merge_chunks] error while trying to remove existing '.$output_filepath); - exit(); + return new PwgError(500, '[merge_chunks] error while trying to remove existing '.$output_filepath); } } @@ -1464,8 +1469,7 @@ function merge_chunks($output_filepath, $original_sum, $type) if (!file_put_contents($output_filepath, $string, FILE_APPEND)) { - new PwgError(500, '[merge_chunks] error while writting chunks for '.$output_filepath); - exit(); + return new PwgError(500, '[merge_chunks] error while writting chunks for '.$output_filepath); } unlink($chunk); @@ -1500,8 +1504,7 @@ function add_file($file_path, $type, $original_sum, $file_sum) $recursive = true; if (!@mkdir($upload_dir, 0777, $recursive)) { - new PwgError(500, '[add_file] error during '.$type.' directory creation'); - exit(); + return new PwgError(500, '[add_file] error during '.$type.' directory creation'); } } @@ -1512,8 +1515,7 @@ function add_file($file_path, $type, $original_sum, $file_sum) if (!is_writable($upload_dir)) { - new PwgError(500, '[add_file] '.$type.' directory has no write access'); - exit(); + return new PwgError(500, '[add_file] '.$type.' directory has no write access'); } } @@ -1525,9 +1527,9 @@ function add_file($file_path, $type, $original_sum, $file_sum) // check dumped thumbnail md5 $dumped_md5 = md5_file($file_path); - if ($dumped_md5 != $file_sum) { - new PwgError(500, '[add_file] '.$type.' transfer failed'); - exit(); + if ($dumped_md5 != $file_sum) + { + return new PwgError(500, '[add_file] '.$type.' transfer failed'); } list($width, $height) = getimagesize($file_path); @@ -2451,13 +2453,12 @@ SELECT * } else { - new PwgError( + return new PwgError( 500, '[ws_images_setInfo]' .' invalid parameter single_value_mode "'.$params['single_value_mode'].'"' .', possible values are {fill_if_empty, replace}.' ); - exit(); } } } @@ -2466,8 +2467,7 @@ SELECT * { if (!empty($image_row['storage_category_id'])) { - new PwgError(500, '[ws_images_setInfo] updating "file" is forbidden on photos added by synchronization'); - exit(); + return new PwgError(500, '[ws_images_setInfo] updating "file" is forbidden on photos added by synchronization'); } $update['file'] = $params['file']; @@ -2517,13 +2517,12 @@ SELECT * } else { - new PwgError( + return new PwgError( 500, '[ws_images_setInfo]' .' invalid parameter multiple_value_mode "'.$params['multiple_value_mode'].'"' .', possible values are {replace, append}.' ); - exit(); } } @@ -2610,11 +2609,10 @@ function ws_add_image_category_relations($image_id, $categories_string, $replace if (count($cat_ids) == 0) { - new PwgError( + return new PwgError( 500, '[ws_add_image_category_relations] there is no category defined in "'.$categories_string.'"' ); - exit(); } $query = ' @@ -2628,11 +2626,10 @@ SELECT $unknown_cat_ids = array_diff($cat_ids, $db_cat_ids); if (count($unknown_cat_ids) != 0) { - new PwgError( + return new PwgError( 500, '[ws_add_image_category_relations] the following categories are unknown: '.implode(', ', $unknown_cat_ids) ); - exit(); } $to_update_cat_ids = array(); |