Navigation Menu

Skip to content

Commit

Permalink
merge-r17295 from branch 2.4 feature 2708: in admin, display allowed …
Browse files Browse the repository at this point in the history
…custom derivatives and ability to delete them

git-svn-id: http://piwigo.org/svn/trunk@17302 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
rvelices committed Aug 1, 2012
1 parent 56a395e commit 92049de
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 41 deletions.
54 changes: 31 additions & 23 deletions admin/configuration.php
Expand Up @@ -106,7 +106,7 @@
'rating_score',
'privacy_level',
);

// image order management
$sort_fields = array(
'' => '',
Expand All @@ -126,7 +126,7 @@
'id DESC' => l10n('Numeric identifier, 9 → 1'),
'rank ASC' => l10n('Manual sort order'),
);

$comments_order = array(
'ASC' => l10n('Show oldest comments first'),
'DESC' => l10n('Show latest comments first'),
Expand All @@ -141,7 +141,7 @@
switch ($page['section'])
{
case 'main' :
{
{
if ( !isset($conf['order_by_custom']) and !isset($conf['order_by_inside_category_custom']) )
{
if ( !empty($_POST['order_by']) )
Expand All @@ -158,19 +158,19 @@
{
// limit to the number of available parameters
$order_by = $order_by_inside_category = array_slice($_POST['order_by'], 0, ceil(count($sort_fields)/2));

// there is no rank outside categories
if ( ($i = array_search('rank ASC', $order_by)) !== false)
{
unset($order_by[$i]);
}

// must define a default order_by if user want to order by rank only
if ( count($order_by) == 0 )
{
$order_by = array('id ASC');
}

$_POST['order_by'] = 'ORDER BY '.implode(', ', $order_by);
$_POST['order_by_inside_category'] = 'ORDER BY '.implode(', ', $order_by_inside_category);
}
Expand All @@ -180,7 +180,7 @@
array_push($page['errors'], l10n('No order field selected'));
}
}

foreach( $main_checkboxes as $checkbox)
{
$_POST[$checkbox] = empty($_POST[$checkbox])?'false':'true';
Expand All @@ -189,12 +189,12 @@
}
case 'watermark' :
{
include(PHPWG_ROOT_PATH.'admin/include/configuration_watermark_process.inc.php');
include(PHPWG_ROOT_PATH.'admin/include/configuration_watermark_process.inc.php');
break;
}
case 'sizes' :
{
include(PHPWG_ROOT_PATH.'admin/include/configuration_sizes_process.inc.php');
include(PHPWG_ROOT_PATH.'admin/include/configuration_sizes_process.inc.php');
break;
}
case 'comments' :
Expand Down Expand Up @@ -302,24 +302,24 @@
switch ($page['section'])
{
case 'main' :
{
{

function order_by_is_local()
{
@include(PHPWG_ROOT_PATH. 'local/config/config.inc.php');
if (isset($conf['local_dir_site']))
{
@include(PHPWG_ROOT_PATH.PWG_LOCAL_DIR. 'config/config.inc.php');
}

return isset($conf['order_by']) or isset($conf['order_by_inside_category']);
}

if (order_by_is_local())
{
array_push($page['warnings'], l10n('You have specified <i>$conf[\'order_by\']</i> in your local configuration file, this parameter in deprecated, please remove it or rename it into <i>$conf[\'order_by_custom\']</i> !'));
}

if ( isset($conf['order_by_custom']) or isset($conf['order_by_inside_category_custom']) )
{
$order_by = array('');
Expand All @@ -332,7 +332,7 @@ function order_by_is_local()
$order_by = str_replace('ORDER BY ', null, $order_by);
$order_by = explode(', ', $order_by);
}

$template->assign(
'main',
array(
Expand Down Expand Up @@ -440,7 +440,7 @@ function order_by_is_local()
'original_resize_quality' => $conf['original_resize_quality'],
)
);

foreach ($sizes_checkboxes as $checkbox)
{
$template->append(
Expand All @@ -451,7 +451,7 @@ function order_by_is_local()
true
);
}

// derivatives = multiple size
$enabled = ImageStdParams::get_defined_type_map();
$disabled = @unserialize(@$conf['disabled_derivatives']);
Expand All @@ -464,10 +464,10 @@ function order_by_is_local()
foreach(ImageStdParams::get_all_types() as $type)
{
$tpl_var = array();

$tpl_var['must_square'] = ($type==IMG_SQUARE ? true : false);
$tpl_var['must_enable'] = ($type==IMG_SQUARE || $type==IMG_THUMB)? true : false;

if ($params = @$enabled[$type])
{
$tpl_var['enabled'] = true;
Expand All @@ -477,7 +477,7 @@ function order_by_is_local()
$tpl_var['enabled']=false;
$params=@$disabled[$type];
}

if ($params)
{
list($tpl_var['w'],$tpl_var['h']) = $params->sizing->ideal_size;
Expand All @@ -495,6 +495,14 @@ function order_by_is_local()
}
$template->assign('derivatives', $tpl_vars);
$template->assign('resize_quality', ImageStdParams::$quality);

$tpl_vars = array();
$now = time();
foreach(ImageStdParams::$custom as $custom=>$time)
{
$tpl_vars[$custom] = ($now-$time<=24*3600) ? l10n('today') : time_since($time, 'day');
}
$template->assign('custom_derivatives', $tpl_vars);
}

break;
Expand Down Expand Up @@ -546,12 +554,12 @@ function order_by_is_local()
{
$position = 'bottomright';
}

if ($wm->xrepeat != 0)
{
$position = 'custom';
}

$template->assign(
'watermark',
array(
Expand All @@ -566,7 +574,7 @@ function order_by_is_local()
)
);
}

break;
}
}
Expand Down
9 changes: 9 additions & 0 deletions admin/include/configuration_sizes_process.inc.php
Expand Up @@ -228,6 +228,15 @@
}
}

foreach( array_keys(ImageStdParams::$custom) as $custom)
{
if (isset($_POST['delete_custom_derivative_'.$custom]))
{
$changed_types[] = $custom;
unset(ImageStdParams::$custom[$custom]);
}
}

ImageStdParams::set_and_save($enabled_by);
if (count($disabled) == 0)
{
Expand Down
23 changes: 17 additions & 6 deletions admin/include/configuration_watermark_process.inc.php
Expand Up @@ -48,10 +48,10 @@
prepare_directory($upload_dir);

$new_name = get_filename_wo_extension($_FILES['watermarkImage']['name']).'.png';
$file_path = $upload_dir.'/'.$new_name;
$file_path = $upload_dir.'/'.$new_name;

move_uploaded_file($_FILES['watermarkImage']['tmp_name'], $file_path);

$pwatermark['file'] = substr($file_path, strlen(PHPWG_ROOT_PATH));
}
}
Expand Down Expand Up @@ -134,14 +134,25 @@

// do we have to regenerate the derivatives (and which types)?
$changed_types = array();

foreach (ImageStdParams::get_defined_type_map() as $type => $params)
{
$old_use_watermark = $params->use_watermark;
ImageStdParams::apply_global($params);

if ($params->use_watermark != $old_use_watermark
or $params->use_watermark and $watermark_changed)
$changed = $params->use_watermark != $old_use_watermark;
if (!$changed and $params->use_watermark)
{
$changed = $watermark_changed;
}
if (!$changed and $params->use_watermark)
{
// if thresholds change and before/after the threshold is lower than the corresponding derivative side -> some derivatives might switch the watermark
$changed |= $watermark->min_size[0]!=$old_watermark->min_size[0] and ($watermark->min_size[0]<$params->max_width() or $old_watermark->min_size[0]<$params->max_width());
$changed |= $watermark->min_size[1]!=$old_watermark->min_size[1] and ($watermark->min_size[1]<$params->max_height() or $old_watermark->min_size[1]<$params->max_height());
}

if ($changed)
{
$params->last_mod_time = time();
$changed_types[] = $type;
Expand Down
35 changes: 24 additions & 11 deletions admin/include/functions.php
Expand Up @@ -1569,7 +1569,7 @@ function move_images_to_categories($images, $categories)
{
return false;
}

// let's first break links with all albums but their "storage album"
$query = '
DELETE '.IMAGE_CATEGORY_TABLE.'.*
Expand All @@ -1579,7 +1579,7 @@ function move_images_to_categories($images, $categories)
AND (storage_category_id IS NULL OR storage_category_id != category_id)
;';
pwg_query($query);

if (is_array($categories) and count($categories) > 0)
{
associate_images_to_categories($images, $categories);
Expand Down Expand Up @@ -2276,8 +2276,7 @@ function get_admins($include_webmaster=true)
/** delete all derivative files for one or several types */
function clear_derivative_cache($types='all')
{
$pattern='#.*-';
if ($types == 'all')
if ($types === 'all')
{
$types = ImageStdParams::get_all_types();
$types[] = IMG_CUSTOM;
Expand All @@ -2287,21 +2286,35 @@ function clear_derivative_cache($types='all')
$types = array($types);
}

if (count($types)>1)
for ($i=0; $i<count($types); $i++)
{
$type_urls = array();
foreach($types as $dtype)
$type = $types[$i];
if ($type == IMG_CUSTOM)
{
$type_urls[] = derivative_to_url($dtype);
$type = derivative_to_url($type).'[a-zA-Z0-9]+';
}
$pattern .= '(' . implode('|',$type_urls) . ')';
elseif (in_array($type, ImageStdParams::get_all_types()))
{
$type = derivative_to_url($type);
}
else
{//assume a custom type
$type = derivative_to_url(IMG_CUSTOM).'_'.$type;
}
$types[$i] = $type;
}

$pattern='#.*-';
if (count($types)>1)
{
$pattern .= '(' . implode('|',$types) . ')';
}
else
{
$pattern .= derivative_to_url($types[0]);
$pattern .= $types[0];
}
$pattern.='\.[a-zA-Z0-9]{3,4}$#';

$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)
Expand Down
9 changes: 9 additions & 0 deletions admin/themes/default/template/configuration.tpl
Expand Up @@ -454,6 +454,15 @@ jQuery(document).ready(function(){
<p style="margin:10px 0 0 0;{if isset($ferrors)} display:block;{/if}" class="sizeDetails">
<a href="{$F_ACTION}&action=restore_settings" onclick="return confirm('{'Are you sure?'|@translate|@escape:javascript}');">{'Reset to default values'|@translate}</a>
</p>

{if !empty($custom_derivatives)}
<fieldset class="sizeDetails"><legend>{'custom'|@translate}</legend><table style="margin:0">
{foreach from=$custom_derivatives item=time key=custom}
<tr><td><label><input type="checkbox" name="delete_custom_derivative_{$custom}"> {'Delete'|@translate} {$custom} ({'Last hit'|@translate}: {$time})</label></td></tr>
{/foreach}
</table></fieldset>
{/if}

</fieldset>
{/if}

Expand Down
2 changes: 1 addition & 1 deletion themes/default/template/picture.tpl
Expand Up @@ -18,7 +18,7 @@
<div class="imageNumber">{$PHOTO}</div>
{include file='picture_nav_buttons.tpl'|@get_extent:'picture_nav_buttons'}
<div class="actionButtons">
{if count($current.unique_derivatives)>1}
{if isset($current.unique_derivatives) && count($current.unique_derivatives)>1}
{footer_script require='jquery'}{literal}
function changeImgSrc(url,typeSave,typeMap)
{
Expand Down

0 comments on commit 92049de

Please sign in to comment.