mirror of
https://github.com/Piwigo/Piwigo.git
synced 2025-04-26 19:29:58 +03:00
feature 2541 multisize
- nicer presentation on picture.php - added a maintenance purge derivatives action git-svn-id: http://piwigo.org/svn/trunk@12797 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
parent
753f58d6a9
commit
e42f791f52
13 changed files with 210 additions and 77 deletions
|
@ -2246,4 +2246,83 @@ SELECT
|
|||
|
||||
return array_from_query($query, 'user_id');
|
||||
}
|
||||
|
||||
function clear_derivative_cache($type='all')
|
||||
{
|
||||
$pattern='#.*-';
|
||||
if ($type == 'all')
|
||||
{
|
||||
$type_urls = array();
|
||||
foreach(ImageStdParams::get_all_types() as $dtype)
|
||||
{
|
||||
$type_urls[] = derivative_to_url($dtype);
|
||||
}
|
||||
$type_urls[] = derivative_to_url(IMG_CUSTOM);
|
||||
$pattern .= '(' . implode('|',$type_urls) . ')';
|
||||
}
|
||||
else
|
||||
{
|
||||
$pattern .= derivative_to_url($type);
|
||||
}
|
||||
$pattern.='(_[a-zA-Z0-9]+)*\.[a-zA-Z0-9]{3,4}$#';
|
||||
if ($contents = opendir(PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR))
|
||||
{
|
||||
while (($node = readdir($contents)) !== false)
|
||||
{
|
||||
if ($node != '.'
|
||||
and $node != '..'
|
||||
and is_dir(PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR.$node))
|
||||
{
|
||||
clear_derivative_cache_rec(PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR.$node, $pattern);
|
||||
}
|
||||
}
|
||||
closedir($contents);
|
||||
}
|
||||
}
|
||||
|
||||
function clear_derivative_cache_rec($path, $pattern)
|
||||
{
|
||||
$rmdir = true;
|
||||
$rm_index = false;
|
||||
|
||||
if ($contents = opendir($path))
|
||||
{
|
||||
while (($node = readdir($contents)) !== false)
|
||||
{
|
||||
if ($node == '.' or $node == '..')
|
||||
continue;
|
||||
if (is_dir($path.'/'.$node))
|
||||
{
|
||||
$rmdir &= clear_derivative_cache_rec($path.'/'.$node, $pattern);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (preg_match($pattern, $node))
|
||||
{
|
||||
unlink($path.'/'.$node);
|
||||
}
|
||||
elseif ($node=='index.htm')
|
||||
{
|
||||
$rm_index = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$rmdir = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($contents);
|
||||
|
||||
if ($rmdir)
|
||||
{
|
||||
if ($rm_index)
|
||||
{
|
||||
unlink($path.'/index.htm');
|
||||
}
|
||||
clearstatcache();
|
||||
rmdir($path);
|
||||
}
|
||||
return $rmdir;
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -127,6 +127,11 @@ DELETE
|
|||
FileCombiner::clear_combined_files();
|
||||
break;
|
||||
}
|
||||
case 'derivatives':
|
||||
{
|
||||
clear_derivative_cache();
|
||||
break;
|
||||
}
|
||||
default :
|
||||
{
|
||||
break;
|
||||
|
@ -154,6 +159,7 @@ $template->assign(
|
|||
'U_MAINT_C13Y' => sprintf($url_format, 'c13y'),
|
||||
'U_MAINT_SEARCH' => sprintf($url_format, 'search'),
|
||||
'U_MAINT_COMPILED_TEMPLATES' => sprintf($url_format, 'compiled-templates'),
|
||||
'U_MAINT_DERIVATIVES' => sprintf($url_format, 'derivatives'),
|
||||
'U_HELP' => get_root_url().'admin/popuphelp.php?page=maintenance',
|
||||
)
|
||||
);
|
||||
|
|
|
@ -172,7 +172,7 @@ $query = '
|
|||
SELECT i.id,
|
||||
i.path,
|
||||
i.file,
|
||||
i.tn_ext,
|
||||
i.representative_ext,
|
||||
i.rating_score AS score,
|
||||
MAX(r.date) AS recently_rated,
|
||||
ROUND(AVG(r.rate),2) AS avg_rates,
|
||||
|
|
|
@ -29,4 +29,5 @@
|
|||
<li><a href="{$U_MAINT_FEEDS}">{'Purge never used notification feeds'|@translate}</a></li>
|
||||
<li><a href="{$U_MAINT_SEARCH}"onclick="return confirm('{'Purge search history'|@translate|@escape:'javascript'}');">{'Purge search history'|@translate}</a></li>
|
||||
<li><a href="{$U_MAINT_COMPILED_TEMPLATES}">{'Purge compiled templates'|@translate}</a></li>
|
||||
<li><a href="{$U_MAINT_DERIVATIVES}">{'Purge derivative image cache'|@translate}</a></li>
|
||||
</ul>
|
||||
|
|
6
i.php
6
i.php
|
@ -135,7 +135,7 @@ function parse_request()
|
|||
$deriv = explode('_', $deriv);
|
||||
foreach (ImageStdParams::get_defined_type_map() as $type => $params)
|
||||
{
|
||||
if (substr($type,0,2) == $deriv[0])
|
||||
if ( derivative_to_url($type) == $deriv[0])
|
||||
{
|
||||
$page['derivative_type'] = $type;
|
||||
$page['derivative_params'] = $params;
|
||||
|
@ -145,7 +145,7 @@ function parse_request()
|
|||
|
||||
if (!isset($page['derivative_type']))
|
||||
{
|
||||
if (substr(IMG_CUSTOM,0,2) == $deriv[0])
|
||||
if (derivative_to_url(IMG_CUSTOM) == $deriv[0])
|
||||
{
|
||||
$page['derivative_type'] = IMG_CUSTOM;
|
||||
}
|
||||
|
@ -288,5 +288,5 @@ switch (strtolower($page['derivative_ext']))
|
|||
header("Content-Type: $ctype");
|
||||
|
||||
fpassthru($fp);
|
||||
exit;
|
||||
fclose($fp);
|
||||
?>
|
|
@ -21,10 +21,14 @@
|
|||
|
||||
final class SrcImage
|
||||
{
|
||||
const IS_ORIGINAL = 0x01;
|
||||
const IS_MIMETYPE = 0x02;
|
||||
|
||||
public $rel_path;
|
||||
|
||||
public $coi=null;
|
||||
private $size=null;
|
||||
private $flags=0;
|
||||
|
||||
function __construct($infos)
|
||||
{
|
||||
|
@ -34,6 +38,7 @@ final class SrcImage
|
|||
if (in_array($ext, $conf['picture_ext']))
|
||||
{
|
||||
$this->rel_path = $infos['path'];
|
||||
$this->flags |= self::IS_ORIGINAL;
|
||||
}
|
||||
elseif (!empty($infos['representative_ext']))
|
||||
{
|
||||
|
@ -44,16 +49,39 @@ final class SrcImage
|
|||
}
|
||||
else
|
||||
{
|
||||
$this->rel_path = get_themeconf('mime_icon_dir').strtolower($ext).'.png';
|
||||
$ext = strtolower($ext);
|
||||
$this->rel_path = trigger_event('get_mimetype_location', get_themeconf('mime_icon_dir').$ext.'.png', $ext );
|
||||
$this->flags |= self::IS_MIMETYPE;
|
||||
$this->size = @getimagesize(PHPWG_ROOT_PATH.$this->rel_path);
|
||||
}
|
||||
|
||||
$this->coi = @$infos['coi'];
|
||||
if (isset($infos['width']) && isset($infos['height']))
|
||||
if (!$this->size && isset($infos['width']) && isset($infos['height']))
|
||||
{
|
||||
$this->size = array($infos['width'], $infos['height']);
|
||||
}
|
||||
}
|
||||
|
||||
function is_original()
|
||||
{
|
||||
return $this->flags & self::IS_ORIGINAL;
|
||||
}
|
||||
|
||||
function is_mimetype()
|
||||
{
|
||||
return $this->flags & self::IS_MIMETYPE;
|
||||
}
|
||||
|
||||
function get_path()
|
||||
{
|
||||
return PHPWG_ROOT_PATH.$this->rel_path;
|
||||
}
|
||||
|
||||
function get_url()
|
||||
{
|
||||
return get_root_url().$this->rel_path;
|
||||
}
|
||||
|
||||
function has_size()
|
||||
{
|
||||
return $this->size != null;
|
||||
|
@ -144,7 +172,7 @@ final class DerivativeImage
|
|||
$tokens=array();
|
||||
$tokens[] = substr($params->type,0,2);
|
||||
|
||||
if (!empty($src->coi))
|
||||
if ($params->sizing->max_crop != 0 and !empty($src->coi))
|
||||
{
|
||||
$tokens[] = 'ci'.$src->coi;
|
||||
}
|
||||
|
@ -206,6 +234,13 @@ final class DerivativeImage
|
|||
}
|
||||
|
||||
|
||||
function get_type()
|
||||
{
|
||||
if ($this->flags & self::SAME_AS_SRC)
|
||||
return 'original';
|
||||
return $this->params->type;
|
||||
}
|
||||
|
||||
/* returns the size of the derivative image*/
|
||||
function get_size()
|
||||
{
|
||||
|
|
|
@ -19,6 +19,11 @@
|
|||
// | USA. |
|
||||
// +-----------------------------------------------------------------------+
|
||||
|
||||
function derivative_to_url($t)
|
||||
{
|
||||
return substr($t, 0, 2);
|
||||
}
|
||||
|
||||
function size_to_url($s)
|
||||
{
|
||||
if ($s[0]==$s[1])
|
||||
|
|
|
@ -36,7 +36,7 @@ if (($conf['show_exif']) and (function_exists('read_exif_data')))
|
|||
$exif_mapping[$field] = $field;
|
||||
}
|
||||
|
||||
$exif = get_exif_data($picture['current']['image_path'], $exif_mapping);
|
||||
$exif = get_exif_data($picture['current']['src_image']->get_path(), $exif_mapping);
|
||||
|
||||
if (count($exif) > 0)
|
||||
{
|
||||
|
@ -79,7 +79,7 @@ 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']);
|
||||
$iptc = get_iptc_data($picture['current']['src_image']->get_path(), $conf['show_iptc_mapping']);
|
||||
|
||||
if (count($iptc) > 0)
|
||||
{
|
||||
|
|
84
picture.php
84
picture.php
|
@ -491,44 +491,41 @@ while ($row = pwg_db_fetch_assoc($result))
|
|||
$i = 'current';
|
||||
}
|
||||
|
||||
$picture[$i] = $row;
|
||||
|
||||
$picture[$i]['is_picture'] = false;
|
||||
if (in_array(get_extension($row['file']), $conf['picture_ext']))
|
||||
{
|
||||
$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();
|
||||
$row['derivatives'] = DerivativeImage::get_all($row);
|
||||
$row['src_image'] = $row['derivatives'][IMG_THUMB]->src_image;
|
||||
|
||||
// ------ build element_path and element_url
|
||||
$picture[$i]['element_path'] = get_element_path($picture[$i]);
|
||||
$picture[$i]['element_url'] = get_element_url($picture[$i]);
|
||||
|
||||
// ------ build image_path and image_url
|
||||
if ($i=='current' or $i=='next')
|
||||
{
|
||||
$picture[$i]['image_path'] = get_image_path( $picture[$i] );
|
||||
$picture[$i]['image_url'] = get_image_url( $picture[$i] );
|
||||
}
|
||||
$row['element_path'] = get_element_path($row);
|
||||
$row['element_url'] = get_element_url($row);
|
||||
|
||||
if ($i=='current')
|
||||
{
|
||||
if ( $picture[$i]['is_picture'] )
|
||||
if ( $row['src_image']->is_original() )
|
||||
{
|
||||
if ( $user['enabled_high']=='true' )
|
||||
{
|
||||
$picture[$i]['download_url'] = get_download_url('e',$picture[$i]);
|
||||
$row['download_url'] = get_download_url('e',$row);
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // not a pic - need download link
|
||||
$picture[$i]['download_url'] = get_download_url('e',$picture[$i]);
|
||||
$row['download_url'] = $row['element_url'];
|
||||
}
|
||||
}
|
||||
|
||||
$row['url'] = duplicate_picture_url(
|
||||
array(
|
||||
'image_id' => $row['id'],
|
||||
'image_file' => $row['file'],
|
||||
),
|
||||
array(
|
||||
'start',
|
||||
)
|
||||
);
|
||||
|
||||
$picture[$i] = $row;
|
||||
|
||||
if ( !empty( $row['name'] ) )
|
||||
{
|
||||
|
@ -542,16 +539,6 @@ while ($row = pwg_db_fetch_assoc($result))
|
|||
|
||||
$picture[$i]['name'] = trigger_event('render_element_description', $picture[$i]['name']);
|
||||
|
||||
$picture[$i]['url'] = duplicate_picture_url(
|
||||
array(
|
||||
'image_id' => $row['id'],
|
||||
'image_file' => $row['file'],
|
||||
),
|
||||
array(
|
||||
'start',
|
||||
)
|
||||
);
|
||||
|
||||
if ('previous'==$i and $page['previous_item']==$page['first_item'])
|
||||
{
|
||||
$picture['first'] = $picture[$i];
|
||||
|
@ -562,17 +549,6 @@ while ($row = pwg_db_fetch_assoc($result))
|
|||
}
|
||||
}
|
||||
|
||||
// calculation of width and height for the current picture
|
||||
if (empty($picture['current']['width']))
|
||||
{
|
||||
$taille_image = @getimagesize($picture['current']['image_path']);
|
||||
if ($taille_image!==false)
|
||||
{
|
||||
$picture['current']['width'] = $taille_image[0];
|
||||
$picture['current']['height']= $taille_image[1];
|
||||
}
|
||||
}
|
||||
|
||||
$slideshow_params = array();
|
||||
$slideshow_url_params = array();
|
||||
|
||||
|
@ -637,9 +613,9 @@ $metadata_showable = trigger_event(
|
|||
'get_element_metadata_available',
|
||||
(
|
||||
($conf['show_exif'] or $conf['show_iptc'])
|
||||
and isset($picture['current']['image_path'])
|
||||
and !$picture['current']['src_image']->is_mimetype()
|
||||
),
|
||||
$picture['current']['path']
|
||||
$picture['current']
|
||||
);
|
||||
|
||||
if ( $metadata_showable and pwg_get_session_var('show_metadata') )
|
||||
|
@ -653,14 +629,6 @@ $page['body_id'] = 'thePicturePage';
|
|||
// allow plugins to change what we computed before passing data to template
|
||||
$picture = trigger_event('picture_pictures_data', $picture);
|
||||
|
||||
|
||||
if (isset($picture['next']['image_url'])
|
||||
and $picture['next']['is_picture']
|
||||
and strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome/') === false)
|
||||
{
|
||||
$template->assign('U_PREFETCH', $picture['next']['image_url'] );
|
||||
}
|
||||
|
||||
//------------------------------------------------------- navigation management
|
||||
foreach (array('first','previous','next','last', 'current') as $which_image)
|
||||
{
|
||||
|
@ -672,7 +640,7 @@ foreach (array('first','previous','next','last', 'current') as $which_image)
|
|||
$picture[$which_image],
|
||||
array(
|
||||
'TITLE' => $picture[$which_image]['name'],
|
||||
'THUMB_SRC' => $picture[$which_image]['thumbnail'],
|
||||
'THUMB_SRC' => $picture[$which_image]['derivatives'][IMG_THUMB]->get_url(),
|
||||
// Params slideshow was transmit to navigation buttons
|
||||
'U_IMG' =>
|
||||
add_url_params(
|
||||
|
@ -888,7 +856,7 @@ $url = make_index_url(
|
|||
$infos['INFO_POSTED_DATE'] = '<a href="'.$url.'" rel="nofollow">'.$val.'</a>';
|
||||
|
||||
// size in pixels
|
||||
if ($picture['current']['is_picture'] and isset($picture['current']['width']) )
|
||||
if ($picture['current']['src_image']->is_original() and isset($picture['current']['width']) )
|
||||
{
|
||||
$infos['INFO_DIMENSIONS'] =
|
||||
$picture['current']['width'].'*'.$picture['current']['height'];
|
||||
|
@ -980,6 +948,14 @@ $element_content = trigger_event(
|
|||
);
|
||||
$template->assign( 'ELEMENT_CONTENT', $element_content );
|
||||
|
||||
if (isset($picture['next'])
|
||||
and $picture['next']['src_image']->is_original()
|
||||
and strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome/') === false)
|
||||
{
|
||||
$template->assign('U_PREFETCH', $picture['next']['derivatives'][pwg_get_session_var('picture_deriv', IMG_LARGE)]->get_url() );
|
||||
}
|
||||
|
||||
|
||||
// +-----------------------------------------------------------------------+
|
||||
// | sub pages |
|
||||
// +-----------------------------------------------------------------------+
|
||||
|
|
|
@ -14,12 +14,12 @@ H2, #menubar DT, #imageHeaderBar, #imageToolBar A:hover {
|
|||
background-color: #d3d3d3;
|
||||
}
|
||||
|
||||
#menubar DL, .content, #imageToolBar, .header_notes {
|
||||
#menubar DL, .content, #imageToolBar, #derivativeSwitchLink, #derivativeSwitchBox, .header_notes {
|
||||
background-color: #eeeeee;
|
||||
}
|
||||
|
||||
/* borders */
|
||||
#menubar DL, .content, #imageToolBar {
|
||||
#menubar DL, .content, #imageToolBar, #derivativeSwitchLink, #derivativeSwitchBox {
|
||||
border: 1px solid #d3d3d3;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ BODY, H3, #imageToolBar A:hover {
|
|||
background-color: #2f2f2f;
|
||||
}
|
||||
|
||||
#menubar DL, .content, #imageToolBar, #imageHeaderBar, .header_notes {
|
||||
#menubar DL, .content, #imageToolBar, #imageHeaderBar, #derivativeSwitchLink, #derivativeSwitchBox, .header_notes {
|
||||
background-color: #505050;
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ H2, #menubar DT {
|
|||
}
|
||||
|
||||
/* borders */
|
||||
#menubar DL, .content{
|
||||
#menubar DL, .content, #derivativeSwitchLink, #derivativeSwitchBox{
|
||||
border: 1px solid #000;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,20 +4,38 @@
|
|||
{/if}>
|
||||
{if count($current.available_derivative_types)>1}
|
||||
{footer_script}{literal}
|
||||
function changeImgSrc(url,type)
|
||||
function changeImgSrc(url,type,display)
|
||||
{
|
||||
var theImg = document.getElementById("theMainImage");
|
||||
if (theImg)
|
||||
{
|
||||
theImg.removeAttribute("width");theImg.removeAttribute("height");
|
||||
theImg.src = url;
|
||||
var elt = document.getElementById("derivativeSwitchLink");
|
||||
if (elt) elt.innerHTML = display;
|
||||
}
|
||||
document.cookie = 'picture_deriv=' + type;
|
||||
}
|
||||
|
||||
function toggleDerivativeSwitchBox()
|
||||
{
|
||||
var elt = document.getElementById("derivativeSwitchBox"),
|
||||
ePos = document.getElementById("derivativeSwitchLink");
|
||||
if (elt.style.display==="none")
|
||||
{
|
||||
elt.style.position = "absolute";
|
||||
elt.style.left = (ePos.offsetLeft + 10) + "px";
|
||||
elt.style.top = (ePos.offsetTop + ePos.offsetHeight) + "px";
|
||||
elt.style.display="";
|
||||
}
|
||||
else
|
||||
elt.style.display="none";
|
||||
}
|
||||
{/literal}{/footer_script}
|
||||
<p>
|
||||
<a id="derivativeSwitchLink" onclick="toggleDerivativeSwitchBox()" style="cursor:pointer">{$current.selected_derivative->get_type()|@translate}</a>
|
||||
<div id="derivativeSwitchBox" onclick="toggleDerivativeSwitchBox()" style="display:none">
|
||||
{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>
|
||||
<a onclick="changeImgSrc('{$current.derivatives[$derivative_type]->get_url()|@escape:javascript}', '{$derivative_type}', '{$derivative_type|@translate|@escape:javascript}')" style="cursor:pointer">{$derivative_type|@translate} ({$current.derivatives[$derivative_type]->get_size_hr()})</a><br>
|
||||
{/foreach}
|
||||
</p>
|
||||
</div>
|
||||
{/if}
|
|
@ -338,6 +338,19 @@ TD.calDayHead {
|
|||
#imageToolBar .pwg-button {width:42px;}
|
||||
|
||||
|
||||
#derivativeSwitchLink {
|
||||
padding: 0.2em;
|
||||
position: absolute;
|
||||
left: 5px;
|
||||
top: 100px;
|
||||
}
|
||||
|
||||
#derivativeSwitchBox {
|
||||
padding: 0.5em;
|
||||
border-radius: 4px;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
#theImage {
|
||||
clear: left;
|
||||
text-align: center;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue