aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--admin/include/functions.php79
-rw-r--r--admin/maintenance.php8
-rw-r--r--admin/rating.php2
-rw-r--r--admin/themes/default/template/maintenance.tpl1
-rw-r--r--i.php6
-rw-r--r--include/derivative.inc.php45
-rw-r--r--include/derivative_params.inc.php5
-rw-r--r--include/picture_metadata.inc.php4
-rw-r--r--picture.php90
-rw-r--r--themes/clear/theme.css4
-rw-r--r--themes/dark/theme.css4
-rw-r--r--themes/default/template/picture_content.tpl26
-rw-r--r--themes/default/theme.css13
13 files changed, 210 insertions, 77 deletions
diff --git a/admin/include/functions.php b/admin/include/functions.php
index 6acc7ab98..85ee0f4f2 100644
--- a/admin/include/functions.php
+++ b/admin/include/functions.php
@@ -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;
+ }
+}
?> \ No newline at end of file
diff --git a/admin/maintenance.php b/admin/maintenance.php
index 886739efc..65cb125fa 100644
--- a/admin/maintenance.php
+++ b/admin/maintenance.php
@@ -121,12 +121,17 @@ DELETE
pwg_query($query);
break;
}
- case 'compiled-templates' :
+ case 'compiled-templates':
{
$template->delete_compiled_templates();
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',
)
);
diff --git a/admin/rating.php b/admin/rating.php
index 559d48523..91b0ab8da 100644
--- a/admin/rating.php
+++ b/admin/rating.php
@@ -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,
diff --git a/admin/themes/default/template/maintenance.tpl b/admin/themes/default/template/maintenance.tpl
index 3b61eb0af..2c5f59713 100644
--- a/admin/themes/default/template/maintenance.tpl
+++ b/admin/themes/default/template/maintenance.tpl
@@ -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>
diff --git a/i.php b/i.php
index 9f5463601..ff539bdf8 100644
--- a/i.php
+++ b/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);
?> \ No newline at end of file
diff --git a/include/derivative.inc.php b/include/derivative.inc.php
index 11f1ebb76..c22e27573 100644
--- a/include/derivative.inc.php
+++ b/include/derivative.inc.php
@@ -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;
@@ -126,7 +154,7 @@ final class DerivativeImage
{
$ret[$type] = $ret[$type2];
}
-
+
return $ret;
}
@@ -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()
{
diff --git a/include/derivative_params.inc.php b/include/derivative_params.inc.php
index 9fe76cd43..a84c0f854 100644
--- a/include/derivative_params.inc.php
+++ b/include/derivative_params.inc.php
@@ -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])
diff --git a/include/picture_metadata.inc.php b/include/picture_metadata.inc.php
index db0aff887..49bb9f011 100644
--- a/include/picture_metadata.inc.php
+++ b/include/picture_metadata.inc.php
@@ -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)
{
diff --git a/picture.php b/picture.php
index 589d9e105..e59eda086 100644
--- a/picture.php
+++ b/picture.php
@@ -474,15 +474,15 @@ while ($row = pwg_db_fetch_assoc($result))
{
$i = 'previous';
}
- else if (isset($page['next_item']) and $row['id'] == $page['next_item'])
+ elseif (isset($page['next_item']) and $row['id'] == $page['next_item'])
{
$i = 'next';
}
- else if (isset($page['first_item']) and $row['id'] == $page['first_item'])
+ elseif (isset($page['first_item']) and $row['id'] == $page['first_item'])
{
$i = 'first';
}
- else if (isset($page['last_item']) and $row['id'] == $page['last_item'])
+ elseif (isset($page['last_item']) and $row['id'] == $page['last_item'])
{
$i = 'last';
}
@@ -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 |
// +-----------------------------------------------------------------------+
diff --git a/themes/clear/theme.css b/themes/clear/theme.css
index 838f33980..258d8b57c 100644
--- a/themes/clear/theme.css
+++ b/themes/clear/theme.css
@@ -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;
}
diff --git a/themes/dark/theme.css b/themes/dark/theme.css
index aa3975b43..eca78dc9a 100644
--- a/themes/dark/theme.css
+++ b/themes/dark/theme.css
@@ -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;
}
diff --git a/themes/default/template/picture_content.tpl b/themes/default/template/picture_content.tpl
index a4a9b4760..6fc743a02 100644
--- a/themes/default/template/picture_content.tpl
+++ b/themes/default/template/picture_content.tpl
@@ -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} \ No newline at end of file
diff --git a/themes/default/theme.css b/themes/default/theme.css
index 73a2e0d20..dfdb2f40e 100644
--- a/themes/default/theme.css
+++ b/themes/default/theme.css
@@ -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;