mirror of
https://github.com/Piwigo/Piwigo.git
synced 2025-04-27 19:59:56 +03:00
feature 2541 multisize
- core implementation + usage on most public/admin pages - still to do: sync process, upload, gui/persistence for size parameters, migration script, center of interest ... git-svn-id: http://piwigo.org/svn/trunk@12796 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
parent
e77e68b7db
commit
753f58d6a9
27 changed files with 1113 additions and 208 deletions
|
@ -711,7 +711,7 @@ if (count($page['cat_elements_id']) > 0)
|
|||
|
||||
|
||||
$query = '
|
||||
SELECT id,path,tn_ext,file,filesize,level,name
|
||||
SELECT id,path,representative_ext,file,filesize,level,name
|
||||
FROM '.IMAGES_TABLE;
|
||||
|
||||
if ($is_category)
|
||||
|
@ -747,7 +747,7 @@ SELECT id,path,tn_ext,file,filesize,level,name
|
|||
while ($row = pwg_db_fetch_assoc($result))
|
||||
{
|
||||
$nb_thumbs_page++;
|
||||
$src = get_thumbnail_url($row);
|
||||
$src = DerivativeImage::thumb_url($row);
|
||||
|
||||
$title = $row['name'];
|
||||
if (empty($title))
|
||||
|
|
|
@ -201,7 +201,7 @@ if (count($page['cat_elements_id']) > 0)
|
|||
|
||||
|
||||
$query = '
|
||||
SELECT id,path,tn_ext,name,date_creation,comment,author,level,file
|
||||
SELECT id,path,representative_ext,name,date_creation,comment,author,level,file
|
||||
FROM '.IMAGES_TABLE;
|
||||
|
||||
if ($is_category)
|
||||
|
@ -237,7 +237,7 @@ SELECT id,path,tn_ext,name,date_creation,comment,author,level,file
|
|||
{
|
||||
array_push($element_ids, $row['id']);
|
||||
|
||||
$src = get_thumbnail_url($row);
|
||||
$src = DerivativeImage::thumb_url($row);
|
||||
|
||||
// creation date
|
||||
if (!empty($row['date_creation']))
|
||||
|
|
|
@ -301,12 +301,12 @@ if ($category['has_images']
|
|||
if (!empty($category['representative_picture_id']))
|
||||
{
|
||||
$query = '
|
||||
SELECT id,tn_ext,path
|
||||
SELECT id,representative_ext,path
|
||||
FROM '.IMAGES_TABLE.'
|
||||
WHERE id = '.$category['representative_picture_id'].'
|
||||
;';
|
||||
$row = pwg_db_fetch_assoc(pwg_query($query));
|
||||
$src = get_thumbnail_url($row);
|
||||
$src = DerivativeImage::thumb_url($row);
|
||||
$url = get_root_url().'admin.php?page=picture_modify';
|
||||
$url.= '&image_id='.$category['representative_picture_id'];
|
||||
|
||||
|
@ -387,7 +387,7 @@ if (isset($_POST['submitEmail']) and !empty($_POST['group']))
|
|||
if (!empty($category['representative_picture_id']))
|
||||
{
|
||||
$query = '
|
||||
SELECT id, file, path, tn_ext
|
||||
SELECT id, file, path, representative_ext
|
||||
FROM '.IMAGES_TABLE.'
|
||||
WHERE id = '.$category['representative_picture_id'].'
|
||||
;';
|
||||
|
@ -403,7 +403,7 @@ SELECT id, file, path, tn_ext
|
|||
'image_file' => $element['file'],
|
||||
'category' => $category
|
||||
))
|
||||
.'" class="thumblnk"><img src="'.get_thumbnail_url($element).'"></a>';
|
||||
.'" class="thumblnk"><img src="'.DerivativeImage::thumb_url($element).'"></a>';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ $list = array();
|
|||
|
||||
$query = '
|
||||
SELECT c.id, c.image_id, c.date, c.author, '.
|
||||
$conf['user_fields']['username'].' AS username, c.content, i.path, i.tn_ext
|
||||
$conf['user_fields']['username'].' AS username, c.content, i.path, i.representative_ext
|
||||
FROM '.COMMENTS_TABLE.' AS c
|
||||
INNER JOIN '.IMAGES_TABLE.' AS i
|
||||
ON i.id = c.image_id
|
||||
|
@ -111,7 +111,7 @@ $conf['user_fields']['username'].' AS username, c.content, i.path, i.tn_ext
|
|||
$result = pwg_query($query);
|
||||
while ($row = pwg_db_fetch_assoc($result))
|
||||
{
|
||||
$thumb = get_thumbnail_url(
|
||||
$thumb = DerivativeImage::thumb_url(
|
||||
array(
|
||||
'id'=>$row['image_id'],
|
||||
'path'=>$row['path'],
|
||||
|
|
|
@ -199,7 +199,8 @@ SELECT
|
|||
id,
|
||||
file,
|
||||
path,
|
||||
tn_ext,
|
||||
representative_ext,
|
||||
width, height,
|
||||
name,
|
||||
rank
|
||||
FROM '.IMAGES_TABLE.'
|
||||
|
@ -214,11 +215,12 @@ if (pwg_db_num_rows($result) > 0)
|
|||
$current_rank = 1;
|
||||
$thumbnail_info=array();
|
||||
$clipping=array();
|
||||
$derivativeParams = ImageStdParams::get_by_type(IMG_SQUARE);
|
||||
while ($row = pwg_db_fetch_assoc($result))
|
||||
{
|
||||
$src = get_thumbnail_url($row);
|
||||
$derivative = new DerivativeImage($derivativeParams, new SrcImage($row));
|
||||
|
||||
$thumbnail_size = getimagesize($src);
|
||||
$thumbnail_size = $derivative->get_size();
|
||||
if ( !empty( $row['name'] ) )
|
||||
{
|
||||
$thumbnail_name = $row['name'];
|
||||
|
@ -233,7 +235,7 @@ if (pwg_db_num_rows($result) > 0)
|
|||
'width' => $thumbnail_size[0],
|
||||
'height' => $thumbnail_size[1],
|
||||
'id' => $row['id'],
|
||||
'tn_src' => $src,
|
||||
'tn_src' => $derivative->get_url(),
|
||||
'rank' => $current_rank * 10,
|
||||
);
|
||||
if ($thumbnail_size[0]<=128 and $thumbnail_size[1]<=128)
|
||||
|
|
|
@ -303,7 +303,7 @@ SELECT
|
|||
high_filesize,
|
||||
file,
|
||||
path,
|
||||
tn_ext
|
||||
representative_ext
|
||||
FROM '.IMAGES_TABLE.'
|
||||
WHERE id IN ('.implode(',', array_keys($image_ids)).')
|
||||
;';
|
||||
|
@ -313,7 +313,7 @@ SELECT
|
|||
$high_filesize_of_image = array();
|
||||
$file_of_image = array();
|
||||
$path_of_image = array();
|
||||
$tn_ext_of_image = array();
|
||||
$representative_ext_of_image = array();
|
||||
|
||||
$result = pwg_query($query);
|
||||
while ($row = pwg_db_fetch_assoc($result))
|
||||
|
@ -332,7 +332,7 @@ SELECT
|
|||
|
||||
$file_of_image[ $row['id'] ] = $row['file'];
|
||||
$path_of_image[ $row['id'] ] = $row['path'];
|
||||
$tn_ext_of_image[ $row['id'] ] = $row['tn_ext'];
|
||||
$representative_ext_of_image[ $row['id'] ] = $row['representative_ext'];
|
||||
}
|
||||
|
||||
// echo '<pre>'; print_r($high_filesize_of_image); echo '</pre>';
|
||||
|
@ -454,7 +454,7 @@ SELECT
|
|||
'id' => $line['image_id'],
|
||||
'file' => $file_of_image[$line['image_id']],
|
||||
'path' => $path_of_image[$line['image_id']],
|
||||
'tn_ext' => $tn_ext_of_image[$line['image_id']],
|
||||
'representative_ext' => $representative_ext_of_image[$line['image_id']],
|
||||
);
|
||||
$thumbnail_display = $page['search']['fields']['display_thumbnail'];
|
||||
}
|
||||
|
@ -487,7 +487,7 @@ SELECT
|
|||
{
|
||||
$image_string =
|
||||
'<a class="thumbnail" href="'.$picture_url.'">'
|
||||
.'<span><img src="'.get_thumbnail_url($element)
|
||||
.'<span><img src="'.DerivativeImage::thumb_url($element)
|
||||
.'" alt="'.$image_title.'" title="'.$image_title.'">'
|
||||
.'</span></a>';
|
||||
break;
|
||||
|
@ -496,7 +496,7 @@ SELECT
|
|||
{
|
||||
$image_string =
|
||||
'<a class="over" href="'.$picture_url.'">'
|
||||
.'<span><img src="'.get_thumbnail_url($element)
|
||||
.'<span><img src="'.DerivativeImage::thumb_url($element)
|
||||
.'" alt="'.$image_title.'" title="'.$image_title.'">'
|
||||
.'</span>'.$image_title.'</a>';
|
||||
break;
|
||||
|
|
|
@ -282,7 +282,7 @@ $template->assign(
|
|||
|
||||
'PATH'=>$row['path'],
|
||||
|
||||
'TN_SRC' => get_thumbnail_url($row),
|
||||
'TN_SRC' => DerivativeImage::thumb_url($row),
|
||||
|
||||
'NAME' =>
|
||||
isset($_POST['name']) ?
|
||||
|
|
|
@ -184,7 +184,7 @@ SELECT i.id,
|
|||
GROUP BY i.id,
|
||||
i.path,
|
||||
i.file,
|
||||
i.tn_ext,
|
||||
i.representative_ext,
|
||||
i.rating_score,
|
||||
r.element_id
|
||||
ORDER BY ' . $available_order_by[$order_by_index][1] .'
|
||||
|
@ -201,7 +201,7 @@ while ($row = pwg_db_fetch_assoc($result))
|
|||
$template->assign( 'images', array() );
|
||||
foreach ($images as $image)
|
||||
{
|
||||
$thumbnail_src = get_thumbnail_url($image);
|
||||
$thumbnail_src = DerivativeImage::thumb_url($image);
|
||||
|
||||
$image_url = PHPWG_ROOT_PATH.'admin.php?page=picture_modify'.
|
||||
'&image_id='.$image['id'];
|
||||
|
|
|
@ -101,14 +101,14 @@ while ($row = pwg_db_fetch_assoc($result))
|
|||
$image_urls = array();
|
||||
if (count($image_ids) > 0 )
|
||||
{
|
||||
$query = 'SELECT id, name, file, path, tn_ext
|
||||
$query = 'SELECT id, name, file, path, representative_ext
|
||||
FROM '.IMAGES_TABLE.'
|
||||
WHERE id IN ('.implode(',', array_keys($image_ids)).')';
|
||||
$result = pwg_query($query);
|
||||
while ($row = pwg_db_fetch_assoc($result))
|
||||
{
|
||||
$image_urls[ $row['id'] ] = array(
|
||||
'tn' => get_thumbnail_url($row),
|
||||
'tn' => DerivativeImage::thumb_url($row),
|
||||
'page' => make_picture_url( array('image_id'=>$row['id'], 'image_file'=>$row['file']) ),
|
||||
);
|
||||
}
|
||||
|
@ -217,7 +217,7 @@ $template->assign( array(
|
|||
'available_rates' => $conf['rate_items'],
|
||||
'ratings' => $by_user_ratings,
|
||||
'image_urls' => $image_urls,
|
||||
'TN_WIDTH' => 20+2*$conf['upload_form_thumb_maxwidth'],
|
||||
'TN_WIDTH' => 28+2*ImageStdParams::get_by_type(IMG_THUMB)->sizing->ideal_size[0],
|
||||
) );
|
||||
$template->set_filename('rating', 'rating_user.tpl');
|
||||
$template->assign_var_from_handle('ADMIN_CONTENT', 'rating');
|
||||
|
|
|
@ -59,7 +59,7 @@ function del(elt,uid,aid)
|
|||
<td>{if !empty($rates)}
|
||||
{capture assign=rate_over}{foreach from=$rates item=rate_arr}<img src="{$image_urls[$rate_arr.id].tn}" alt="thumb-{$rate_arr.id}" title="{$rate_arr.date}"></img>
|
||||
{/foreach}{/capture}
|
||||
<a class="cluetip" title="{$rate_over|@htmlspecialchars}">{$rates|@count}</a>
|
||||
<a class="cluetip" title="|{$rate_over|@htmlspecialchars}">{$rates|@count}</a>
|
||||
{/if}</td>
|
||||
{/foreach}
|
||||
<td><a onclick="return del(this,{$rating.uid},'{$rating.aid}');"><img src="{$themeconf.admin_icon_dir}/delete.png" alt="[{'Delete'|@translate}]"></a></td>
|
||||
|
@ -71,7 +71,7 @@ function del(elt,uid,aid)
|
|||
{footer_script require='jquery.cluetip'}
|
||||
jQuery(document).ready(function(){ldelim}
|
||||
jQuery('.cluetip').cluetip({ldelim}
|
||||
width: {$TN_WIDTH}, splitTitle: '|'
|
||||
width: {$TN_WIDTH}, showTitle:false, splitTitle: '|'
|
||||
});
|
||||
})
|
||||
{/footer_script}
|
|
@ -408,7 +408,7 @@ if (count($comments) > 0)
|
|||
// retrieving element informations
|
||||
$elements = array();
|
||||
$query = '
|
||||
SELECT id, name, file, path, tn_ext
|
||||
SELECT id, name, file, path, representative_ext
|
||||
FROM '.IMAGES_TABLE.'
|
||||
WHERE id IN ('.implode(',', $element_ids).')
|
||||
;';
|
||||
|
@ -450,7 +450,7 @@ SELECT c.id, name, permalink, uppercats, com.id as comment_id
|
|||
}
|
||||
|
||||
// source of the thumbnail picture
|
||||
$thumbnail_src = get_thumbnail_url( $elements[$comment['image_id']] );
|
||||
$thumbnail_src = DerivativeImage::thumb_url( $elements[$comment['image_id']] );
|
||||
|
||||
// link to the full size picture
|
||||
$url = make_picture_url(
|
||||
|
|
292
i.php
Normal file
292
i.php
Normal file
|
@ -0,0 +1,292 @@
|
|||
<?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('PHPWG_ROOT_PATH','');
|
||||
|
||||
// fast bootstrap - no db connection
|
||||
include(PHPWG_ROOT_PATH . 'include/config_default.inc.php');
|
||||
@include(PHPWG_ROOT_PATH. 'local/config/config.inc.php');
|
||||
|
||||
defined('PWG_LOCAL_DIR') or define('PWG_LOCAL_DIR', 'local/');
|
||||
defined('PWG_DERIVATIVE_DIR') or define('PWG_DERIVATIVE_DIR', PWG_LOCAL_DIR.'i/');
|
||||
|
||||
function trigger_action() {}
|
||||
function get_extension( $filename )
|
||||
{
|
||||
return substr( strrchr( $filename, '.' ), 1, strlen ( $filename ) );
|
||||
}
|
||||
|
||||
function mkgetdir($dir)
|
||||
{
|
||||
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, $conf['chmod_value'], true);
|
||||
umask($umask);
|
||||
if ($mkd==false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$file = $dir.'/index.htm';
|
||||
file_exists($file) or @file_put_contents( $file, 'Not allowed!' );
|
||||
}
|
||||
if ( !is_writable($dir) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// end fast bootstrap
|
||||
|
||||
|
||||
function ierror($msg, $code)
|
||||
{
|
||||
if ($code==301 || $code==302)
|
||||
{
|
||||
if (ob_get_length () !== FALSE)
|
||||
{
|
||||
ob_clean();
|
||||
}
|
||||
// default url is on html format
|
||||
$url = html_entity_decode($msg);
|
||||
header('Request-URI: '.$url);
|
||||
header('Content-Location: '.$url);
|
||||
header('Location: '.$url);
|
||||
exit;
|
||||
}
|
||||
if ($code>=400)
|
||||
{
|
||||
$protocol = $_SERVER["SERVER_PROTOCOL"];
|
||||
if ( ('HTTP/1.1' != $protocol) && ('HTTP/1.0' != $protocol) )
|
||||
$protocol = 'HTTP/1.0';
|
||||
|
||||
header( "$protocol $code $msg", true, $code );
|
||||
}
|
||||
//todo improve
|
||||
echo $msg;
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
function parse_request()
|
||||
{
|
||||
global $conf, $page;
|
||||
|
||||
if ( $conf['question_mark_in_urls']==false and
|
||||
isset($_SERVER["PATH_INFO"]) and !empty($_SERVER["PATH_INFO"]) )
|
||||
{
|
||||
$req = $_SERVER["PATH_INFO"];
|
||||
$req = str_replace('//', '/', $req);
|
||||
$path_count = count( explode('/', $req) );
|
||||
$page['root_path'] = PHPWG_ROOT_PATH.str_repeat('../', $path_count-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
$req = $_SERVER["QUERY_STRING"];
|
||||
/*foreach (array_keys($_GET) as $keynum => $key)
|
||||
{
|
||||
$req = $key;
|
||||
break;
|
||||
}*/
|
||||
$page['root_path'] = PHPWG_ROOT_PATH;
|
||||
}
|
||||
|
||||
$req = ltrim($req, '/');
|
||||
!preg_match('#[^a-zA-Z0-9/_.-]#', $req) or ierror('Invalid chars in request', 400);
|
||||
|
||||
$page['derivative_path'] = PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR.$req;
|
||||
|
||||
$pos = strrpos($req, '.');
|
||||
$pos!== false || ierror('Missing .', 400);
|
||||
$ext = substr($req, $pos);
|
||||
$page['derivative_ext'] = $ext;
|
||||
$req = substr($req, 0, $pos);
|
||||
|
||||
$pos = strrpos($req, '-');
|
||||
$pos!== false || ierror('Missing -', 400);
|
||||
$deriv = substr($req, $pos+1);
|
||||
$req = substr($req, 0, $pos);
|
||||
|
||||
$deriv = explode('_', $deriv);
|
||||
foreach (ImageStdParams::get_defined_type_map() as $type => $params)
|
||||
{
|
||||
if (substr($type,0,2) == $deriv[0])
|
||||
{
|
||||
$page['derivative_type'] = $type;
|
||||
$page['derivative_params'] = $params;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($page['derivative_type']))
|
||||
{
|
||||
if (substr(IMG_CUSTOM,0,2) == $deriv[0])
|
||||
{
|
||||
$page['derivative_type'] = IMG_CUSTOM;
|
||||
}
|
||||
else
|
||||
{
|
||||
ierror('Unknown parsing type', 400);
|
||||
}
|
||||
}
|
||||
array_shift($deriv);
|
||||
|
||||
$page['coi'] = '';
|
||||
if (count($deriv) && $deriv[0][0]=='c' && $deriv[0][1]=='i')
|
||||
{
|
||||
$page['coi'] = substr(array_shift($deriv), 2);
|
||||
preg_match('#^[a-z]{4}$#', $page['coi']) or ierror('Invalid center of interest', 400);
|
||||
}
|
||||
|
||||
if ($page['derivative_type'] == IMG_CUSTOM)
|
||||
{
|
||||
try
|
||||
{
|
||||
$page['derivative_params'] = ImageParams::from_url_tokens($deriv);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
ierror($e->getMessage(), 400);
|
||||
}
|
||||
}
|
||||
|
||||
if ($req[0]!='g' && $req[0]!='u')
|
||||
$req = '../'.$req;
|
||||
|
||||
$page['src_location'] = $req.$ext;
|
||||
$page['src_path'] = PHPWG_ROOT_PATH.$page['src_location'];
|
||||
$page['src_url'] = $page['root_path'].$page['src_location'];
|
||||
}
|
||||
|
||||
|
||||
|
||||
$page=array();
|
||||
|
||||
include_once( PHPWG_ROOT_PATH .'/include/derivative_params.inc.php');
|
||||
include_once( PHPWG_ROOT_PATH .'/include/derivative_std_params.inc.php');
|
||||
|
||||
ImageStdParams::load_from_file();
|
||||
|
||||
|
||||
parse_request();
|
||||
//var_export($page);
|
||||
|
||||
$params = $page['derivative_params'];
|
||||
if ($params->sizing->ideal_size[0] < 20 or $params->sizing->ideal_size[1] < 20)
|
||||
{
|
||||
ierror('Invalid size', 400);
|
||||
}
|
||||
if ($params->sizing->max_crop < 0 or $params->sizing->max_crop > 1)
|
||||
{
|
||||
ierror('Invalid crop', 400);
|
||||
}
|
||||
|
||||
$src_mtime = @filemtime($page['src_path']);
|
||||
if ($src_mtime === false)
|
||||
{
|
||||
ierror('Source not found', 404);
|
||||
}
|
||||
|
||||
$need_generate = false;
|
||||
$derivative_mtime = @filemtime($page['derivative_path']);
|
||||
if ($derivative_mtime === false or
|
||||
$derivative_mtime < $src_mtime or
|
||||
$derivative_mtime < $params->last_mod_time)
|
||||
{
|
||||
$need_generate = true;
|
||||
}
|
||||
|
||||
if (!$need_generate)
|
||||
{
|
||||
if ( isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] )
|
||||
and strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $derivative_mtime)
|
||||
{// send the last mod time of the file back
|
||||
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $derivative_mtime).' GMT', true, 304);
|
||||
header('Expires: '.gmdate('D, d M Y H:i:s', time()+10*24*3600).' GMT', true, 304);
|
||||
exit;
|
||||
}
|
||||
// todo send pass-through
|
||||
}
|
||||
|
||||
|
||||
include_once(PHPWG_ROOT_PATH . 'admin/include/image.class.php');
|
||||
$image = new pwg_image($page['src_path']);
|
||||
|
||||
if (!mkgetdir(dirname($page['derivative_path'])))
|
||||
{
|
||||
ierror("dir create error", 500);
|
||||
}
|
||||
|
||||
$changes = 0;
|
||||
|
||||
// todo rotate
|
||||
|
||||
// Crop & scale
|
||||
$params->sizing->compute( array($image->get_width(),$image->get_height()), $page['coi'], $crop_rect, $scale_width );
|
||||
if ($crop_rect)
|
||||
{
|
||||
$changes++;
|
||||
$image->crop( $crop_rect->width(), $crop_rect->height(), $crop_rect->l, $crop_rect->t);
|
||||
}
|
||||
|
||||
if ($scale_width)
|
||||
{
|
||||
$changes++;
|
||||
$image->resize( $scale_width[0], $scale_width[1] );
|
||||
}
|
||||
|
||||
// no change required - redirect to source
|
||||
if (!$changes)
|
||||
{
|
||||
header("X-i: No change");
|
||||
ierror( $page['src_url'], 301);
|
||||
}
|
||||
|
||||
$image->write( $page['derivative_path'] );
|
||||
$image->destroy();
|
||||
|
||||
$fp = fopen($page['derivative_path'], 'rb');
|
||||
|
||||
$fstat = fstat($fp);
|
||||
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $fstat['mtime']).' GMT');
|
||||
header('Expires: '.gmdate('D, d M Y H:i:s', time()+10*24*3600).' GMT');
|
||||
header('Content-length: '.$fstat['size']);
|
||||
header('Connection: close');
|
||||
|
||||
$ctype="application/octet-stream";
|
||||
switch (strtolower($page['derivative_ext']))
|
||||
{
|
||||
case ".jpe": case ".jpeg": case ".jpg": $ctype="image/jpeg"; break;
|
||||
case ".png": $ctype="image/png"; break;
|
||||
case ".gif": $ctype="image/gif"; break;
|
||||
}
|
||||
header("Content-Type: $ctype");
|
||||
|
||||
fpassthru($fp);
|
||||
exit;
|
||||
?>
|
|
@ -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'],
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
||||
?>
|
|
@ -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');
|
||||
|
|
239
include/derivative.inc.php
Normal file
239
include/derivative.inc.php
Normal file
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
315
include/derivative_params.inc.php
Normal file
315
include/derivative_params.inc.php
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
||||
?>
|
116
include/derivative_std_params.inc.php
Normal file
116
include/derivative_std_params.inc.php
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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'],
|
||||
|
|
|
@ -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'])
|
|||
}
|
||||
|
||||
|
||||
?>
|
||||
?>
|
|
@ -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['high_url'] = get_high_url($image_row);
|
||||
$ret['element_url'] = get_element_url($image_row);
|
||||
}
|
||||
|
||||
$derivatives = DerivativeImage::get_all($image_row);
|
||||
$derivatives_arr = array();
|
||||
foreach($derivatives as $type=>$derivative)
|
||||
{
|
||||
$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();
|
||||
|
|
112
picture.php
112
picture.php
|
@ -21,7 +21,7 @@
|
|||
// | USA. |
|
||||
// +-----------------------------------------------------------------------+
|
||||
|
||||
define('PHPWG_ROOT_PATH','./');
|
||||
define('PHPWG_ROOT_PATH','');
|
||||
include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
|
||||
include(PHPWG_ROOT_PATH.'include/section_init.inc.php');
|
||||
include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
|
||||
|
@ -153,33 +153,40 @@ function default_picture_content($content, $element_info)
|
|||
{// someone hooked us - so we skip;
|
||||
return $content;
|
||||
}
|
||||
if (!isset($element_info['image_url']))
|
||||
{ // nothing to do
|
||||
return $content;
|
||||
|
||||
if (isset($_COOKIE['picture_deriv']))
|
||||
{
|
||||
pwg_set_session_var('picture_deriv', $_COOKIE['picture_deriv']);
|
||||
setcookie('picture_deriv', false, 0);
|
||||
}
|
||||
$deriv_type = pwg_get_session_var('picture_deriv', IMG_LARGE);
|
||||
$selected_derivative = $element_info['derivatives'][$deriv_type];
|
||||
|
||||
$available_derivatives = array();
|
||||
$added = array();
|
||||
foreach($element_info['derivatives'] as $type => $derivative)
|
||||
{
|
||||
$url = $derivative->get_url();
|
||||
if (isset($added[$url]))
|
||||
continue;
|
||||
$added[$url] = 1;
|
||||
$available_derivatives[] = $type;
|
||||
}
|
||||
|
||||
global $user, $page, $template;
|
||||
|
||||
$template->append('current', array(
|
||||
'selected_derivative' => $selected_derivative,
|
||||
'available_derivative_types' => $available_derivatives,
|
||||
), true);
|
||||
|
||||
|
||||
$template->set_filenames(
|
||||
array('default_content'=>'picture_content.tpl')
|
||||
);
|
||||
|
||||
if ( !$page['slideshow'] and isset($element_info['high_url']) )
|
||||
{
|
||||
$uuid = uniqid(rand());
|
||||
$template->assign(
|
||||
'high',
|
||||
array(
|
||||
'U_HIGH' => $element_info['high_url'],
|
||||
'UUID' => $uuid,
|
||||
)
|
||||
);
|
||||
}
|
||||
$template->assign( array(
|
||||
'SRC_IMG' => $element_info['image_url'],
|
||||
'ALT_IMG' => $element_info['file'],
|
||||
'WIDTH_IMG' => @$element_info['scaled_width'],
|
||||
'HEIGHT_IMG' => @$element_info['scaled_height'],
|
||||
)
|
||||
);
|
||||
return $template->parse( 'default_content', true);
|
||||
|
@ -403,7 +410,7 @@ UPDATE '.USER_CACHE_CATEGORIES_TABLE.'
|
|||
}
|
||||
}
|
||||
|
||||
// incrementation of the number of hits, we do this only if no action
|
||||
//---------- incrementation of the number of hits, we do this only if no action
|
||||
if (trigger_event('allow_increment_element_hit_count', !isset($_POST['content']) ) )
|
||||
{
|
||||
$query = '
|
||||
|
@ -492,6 +499,10 @@ while ($row = pwg_db_fetch_assoc($result))
|
|||
$picture[$i]['is_picture'] = true;
|
||||
}
|
||||
|
||||
$picture[$i]['derivatives'] = DerivativeImage::get_all($row);
|
||||
$picture[$i]['src_image'] = $picture[$i]['derivatives'][IMG_THUMB]->src_image;
|
||||
$picture[$i]['thumbnail'] = $picture[$i]['derivatives'][IMG_THUMB]->get_url();
|
||||
|
||||
// ------ build element_path and element_url
|
||||
$picture[$i]['element_path'] = get_element_path($picture[$i]);
|
||||
$picture[$i]['element_url'] = get_element_url($picture[$i]);
|
||||
|
@ -509,12 +520,7 @@ while ($row = pwg_db_fetch_assoc($result))
|
|||
{
|
||||
if ( $user['enabled_high']=='true' )
|
||||
{
|
||||
$hi_url=get_high_url($picture[$i]);
|
||||
if ( !empty($hi_url) )
|
||||
{
|
||||
$picture[$i]['high_url'] = $hi_url;
|
||||
$picture[$i]['download_url'] = get_download_url('h',$picture[$i]);
|
||||
}
|
||||
$picture[$i]['download_url'] = get_download_url('e',$picture[$i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -523,7 +529,6 @@ while ($row = pwg_db_fetch_assoc($result))
|
|||
}
|
||||
}
|
||||
|
||||
$picture[$i]['thumbnail'] = get_thumbnail_url($row);
|
||||
|
||||
if ( !empty( $row['name'] ) )
|
||||
{
|
||||
|
@ -568,19 +573,6 @@ if (empty($picture['current']['width']))
|
|||
}
|
||||
}
|
||||
|
||||
if (!empty($picture['current']['width']))
|
||||
{
|
||||
list(
|
||||
$picture['current']['scaled_width'],
|
||||
$picture['current']['scaled_height']
|
||||
) = get_picture_size(
|
||||
$picture['current']['width'],
|
||||
$picture['current']['height'],
|
||||
@$user['maxwidth'],
|
||||
@$user['maxheight']
|
||||
);
|
||||
}
|
||||
|
||||
$slideshow_params = array();
|
||||
$slideshow_url_params = array();
|
||||
|
||||
|
@ -896,48 +888,14 @@ $url = make_index_url(
|
|||
$infos['INFO_POSTED_DATE'] = '<a href="'.$url.'" rel="nofollow">'.$val.'</a>';
|
||||
|
||||
// size in pixels
|
||||
if ($picture['current']['is_picture'] AND $picture['current']['has_high'])
|
||||
if ($picture['current']['is_picture'] and isset($picture['current']['width']) )
|
||||
{
|
||||
if (!empty($picture['current']['high_width']))
|
||||
{
|
||||
$infos['INFO_DIMENSIONS'] = $picture['current']['high_width'].'*'.$picture['current']['high_height'];
|
||||
}
|
||||
else if ($hi_size = @getimagesize($hi_url))
|
||||
{
|
||||
pwg_query('
|
||||
UPDATE ' . IMAGES_TABLE . '
|
||||
SET
|
||||
high_width = \'' . $hi_size[0].'\',
|
||||
high_height = \''.$hi_size[1] .'\'
|
||||
WHERE id = ' . $picture['current']['id'] . ';
|
||||
');
|
||||
|
||||
$infos['INFO_DIMENSIONS'] = $hi_size[0].'*'.$hi_size[1];
|
||||
}
|
||||
}
|
||||
else if ($picture['current']['is_picture'] and isset($picture['current']['width']) )
|
||||
{
|
||||
if ($picture['current']['scaled_width'] !== $picture['current']['width'] )
|
||||
{
|
||||
$infos['INFO_DIMENSIONS'] =
|
||||
'<a href="'.$picture['current']['image_url'].'" title="'.
|
||||
l10n('Original dimensions').'">'.
|
||||
$picture['current']['width'].'*'.$picture['current']['height'].'</a>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$infos['INFO_DIMENSIONS'] =
|
||||
$picture['current']['width'].'*'.$picture['current']['height'];
|
||||
}
|
||||
$infos['INFO_DIMENSIONS'] =
|
||||
$picture['current']['width'].'*'.$picture['current']['height'];
|
||||
}
|
||||
|
||||
// filesize
|
||||
if ($picture['current']['has_high'] and !empty($picture['current']['high_filesize']))
|
||||
{
|
||||
$infos['INFO_FILESIZE'] =
|
||||
sprintf(l10n('%d Kb'), $picture['current']['high_filesize']);
|
||||
}
|
||||
else if (!empty($picture['current']['filesize']))
|
||||
if (!empty($picture['current']['filesize']))
|
||||
{
|
||||
$infos['INFO_FILESIZE'] =
|
||||
sprintf(l10n('%d Kb'), $picture['current']['filesize']);
|
||||
|
|
|
@ -1,12 +1,23 @@
|
|||
{if isset($high)}
|
||||
{combine_script id='core.scripts' load='async' path='themes/default/js/scripts.js'}
|
||||
<a href="javascript:phpWGOpenWindow('{$high.U_HIGH}','{$high.UUID}','scrollbars=yes,toolbar=no,status=no,resizable=yes')">
|
||||
{/if}
|
||||
<img src="{$SRC_IMG}" style="width:{$WIDTH_IMG}px;height:{$HEIGHT_IMG}px;" alt="{$ALT_IMG}" id="theMainImage"
|
||||
{if isset($COMMENT_IMG)}
|
||||
title="{$COMMENT_IMG|@strip_tags:false|@replace:'"':' '}" {else} title="{$current.TITLE|@replace:'"':' '} - {$ALT_IMG}"
|
||||
{/if}>
|
||||
{if isset($high) }
|
||||
</a>
|
||||
<p>{'Click on the photo to see it in high definition'|@translate}</p>
|
||||
{/if}
|
||||
<img src="{$current.selected_derivative->get_url()}" {$current.selected_derivative->get_size_htm()} alt="{$ALT_IMG}" id="theMainImage"
|
||||
{if isset($COMMENT_IMG)}
|
||||
title="{$COMMENT_IMG|@strip_tags:false|@replace:'"':' '}" {else} title="{$current.TITLE|@replace:'"':' '} - {$ALT_IMG}"
|
||||
{/if}>
|
||||
{if count($current.available_derivative_types)>1}
|
||||
{footer_script}{literal}
|
||||
function changeImgSrc(url,type)
|
||||
{
|
||||
var theImg = document.getElementById("theMainImage");
|
||||
if (theImg)
|
||||
{
|
||||
theImg.removeAttribute("width");theImg.removeAttribute("height");
|
||||
theImg.src = url;
|
||||
}
|
||||
document.cookie = 'picture_deriv=' + type;
|
||||
}
|
||||
{/literal}{/footer_script}
|
||||
<p>
|
||||
{foreach from=$current.available_derivative_types item=derivative_type}
|
||||
<a onclick="changeImgSrc('{$current.derivatives[$derivative_type]->get_url()|@escape:javascript}', '{$derivative_type}')" title="{$current.derivatives[$derivative_type]->get_size_hr()}">{$derivative_type}</a>
|
||||
{/foreach}
|
||||
</p>
|
||||
{/if}
|
Loading…
Add table
Add a link
Reference in a new issue