aboutsummaryrefslogtreecommitdiffstats
path: root/admin
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2012-01-17 21:02:16 +0000
committerrvelices <rv-github@modusoptimus.com>2012-01-17 21:02:16 +0000
commitc6265c515df3901e3ce4d2e0f006de84dc7d2ebc (patch)
tree84c327912cfc9293b633ed8537247bb580a35f36 /admin
parent89933672f26976d5313c5fedda8bef38db7d2c9e (diff)
feature 2548 multisize - implement delete_element_derivatives
git-svn-id: http://piwigo.org/svn/trunk@12917 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--admin/include/functions.php63
-rw-r--r--admin/include/functions_upload.inc.php54
2 files changed, 59 insertions, 58 deletions
diff --git a/admin/include/functions.php b/admin/include/functions.php
index 1f09d69df..a863d6679 100644
--- a/admin/include/functions.php
+++ b/admin/include/functions.php
@@ -2,7 +2,7 @@
// +-----------------------------------------------------------------------+
// | Piwigo - a PHP based photo gallery |
// +-----------------------------------------------------------------------+
-// | Copyright(C) 2008-2011 Piwigo Team http://piwigo.org |
+// | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org |
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
// +-----------------------------------------------------------------------+
@@ -175,16 +175,12 @@ function delete_element_files($ids)
return 0;
}
- include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
-
$new_ids = array();
$query = '
SELECT
id,
path,
- tn_ext,
- has_high,
representative_ext
FROM '.IMAGES_TABLE.'
WHERE id IN ('.implode(',', $ids).')
@@ -196,7 +192,7 @@ SELECT
{
continue;
}
-
+
$files = array();
$files[] = get_element_path($row);
@@ -215,9 +211,10 @@ SELECT
break;
}
}
-
+
if ($ok)
{
+ delete_element_derivatives($row);
$new_ids[] += $row['id'];
}
else
@@ -388,7 +385,7 @@ DELETE FROM '.USERS_TABLE.'
function delete_orphan_tags()
{
$orphan_tags = get_orphan_tags();
-
+
if (count($orphan_tags) > 0)
{
$orphan_tag_ids = array();
@@ -412,7 +409,7 @@ DELETE
function get_orphan_tags()
{
$orphan_tags = array();
-
+
$query = '
SELECT
id,
@@ -1389,14 +1386,14 @@ function delete_tags($tag_ids)
{
return false;
}
-
+
$query = '
DELETE
FROM '.IMAGE_TAG_TABLE.'
WHERE tag_id IN ('.implode(',', $tag_ids).')
;';
pwg_query($query);
-
+
$query = '
DELETE
FROM '.TAGS_TABLE.'
@@ -2038,7 +2035,7 @@ function get_active_menu($menu_page)
function get_taglist($query, $only_user_language=true)
{
$result = pwg_query($query);
-
+
$taglist = array();
while ($row = pwg_db_fetch_assoc($result))
{
@@ -2057,7 +2054,7 @@ function get_taglist($query, $only_user_language=true)
$row['name'] = preg_replace('#\[lang=(.*?)\](.*?)\[/lang\]#is', null, $row['name']);
}
-
+
if (strlen($row['name']) > 0)
{
array_push(
@@ -2069,7 +2066,7 @@ function get_taglist($query, $only_user_language=true)
);
}
}
-
+
$cmp = create_function('$a,$b', 'return strcasecmp($a["name"], $b["name"]);');
usort($taglist, $cmp);
@@ -2136,7 +2133,7 @@ function add_permission_on_category($category_ids, $user_ids)
{
return;
}
-
+
// make sure categories are private and select uppercats or subcats
$cat_ids = (isset($_POST['apply_on_sub'])) ? implode(',', get_subcat_ids($category_ids)).",".implode(',', get_uppercat_ids($category_ids)) : implode(',', get_uppercat_ids($category_ids));
$query = '
@@ -2152,14 +2149,14 @@ SELECT
{
return;
}
-
+
// We must not reinsert already existing lines in user_access table
$granteds = array();
foreach ($private_cats as $cat_id)
{
$granteds[$cat_id] = array();
}
-
+
$query = '
SELECT
user_id,
@@ -2175,11 +2172,11 @@ SELECT
}
$inserts = array();
-
+
foreach ($private_cats as $cat_id)
{
$grant_to_users = array_diff($user_ids, $granteds[$cat_id]);
-
+
foreach ($grant_to_users as $user_id)
{
array_push(
@@ -2207,7 +2204,7 @@ function get_admins($include_webmaster=true)
{
$status_list[] = 'webmaster';
}
-
+
$query = '
SELECT
user_id
@@ -2245,7 +2242,7 @@ function clear_derivative_cache($types='all')
{
$pattern .= derivative_to_url($types[0]);
}
-
+
$pattern.='(_[a-zA-Z0-9]+)*\.[a-zA-Z0-9]{3,4}$#';
if ($contents = opendir(PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR))
{
@@ -2294,7 +2291,7 @@ function clear_derivative_cache_rec($path, $pattern)
}
}
closedir($contents);
-
+
if ($rmdir)
{
if ($rm_index)
@@ -2308,16 +2305,22 @@ function clear_derivative_cache_rec($path, $pattern)
}
}
-function delete_element_derivatives($ids)
+function delete_element_derivatives($infos)
{
- // todo
- if (!is_array($ids))
+ $path = $infos['path'];
+ if (!empty($infos['representative_ext']))
{
- $ids = array($ids);
+ $path = original_to_representative( $path, $infos['representative_ext']);
+ }
+ if (substr_compare($path, '../', 0, 3)==0)
+ {
+ $path = substr($path, 3);
+ }
+ $dot = strpos($path, '.');
+ $path = substr_replace($path, '-*', $dot, 0);
+ foreach( glob(PHPWG_ROOT_PATH.PWG_DERIVATIVE_DIR.$path) as $file)
+ {
+ @unlink($file);
}
-
- // for now I do a massive clear, to be removed once the function is
- // properly implemented
- clear_derivative_cache();
}
?> \ No newline at end of file
diff --git a/admin/include/functions_upload.inc.php b/admin/include/functions_upload.inc.php
index 88440476a..bfe972d25 100644
--- a/admin/include/functions_upload.inc.php
+++ b/admin/include/functions_upload.inc.php
@@ -2,7 +2,7 @@
// +-----------------------------------------------------------------------+
// | Piwigo - a PHP based photo gallery |
// +-----------------------------------------------------------------------+
-// | Copyright(C) 2008-2011 Piwigo Team http://piwigo.org |
+// | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org |
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
// +-----------------------------------------------------------------------+
@@ -36,7 +36,7 @@ function get_upload_form_config()
'default' => false,
'can_be_null' => false,
),
-
+
'original_resize_maxwidth' => array(
'default' => 2000,
'min' => 500,
@@ -45,7 +45,7 @@ function get_upload_form_config()
'can_be_null' => false,
'error_message' => l10n('The original maximum width must be a number between %d and %d'),
),
-
+
'original_resize_maxheight' => array(
'default' => 2000,
'min' => 300,
@@ -54,7 +54,7 @@ function get_upload_form_config()
'can_be_null' => false,
'error_message' => l10n('The original maximum height must be a number between %d and %d'),
),
-
+
'original_resize_quality' => array(
'default' => 95,
'min' => 50,
@@ -112,7 +112,7 @@ function save_upload_form_config($data, &$errors=array())
$min = $upload_form_config[$field]['min'];
$max = $upload_form_config[$field]['max'];
$pattern = $upload_form_config[$field]['pattern'];
-
+
if (preg_match($pattern, $value) and $value >= $min and $value <= $max)
{
$updates[] = array(
@@ -157,10 +157,10 @@ function add_uploaded_file($source_filepath, $original_filename=null, $categorie
// 2) keep/resize original
//
// 3) register in database
-
+
// TODO
// * check md5sum (already exists?)
-
+
global $conf, $user;
if (isset($original_md5sum))
@@ -171,9 +171,9 @@ function add_uploaded_file($source_filepath, $original_filename=null, $categorie
{
$md5sum = md5_file($source_filepath);
}
-
+
$file_path = null;
-
+
if (isset($image_id))
{
// this photo already exists, we update it
@@ -188,7 +188,7 @@ SELECT
{
$file_path = $row['path'];
}
-
+
if (!isset($file_path))
{
die('['.__FUNCTION__.'] this photo does not exist in the database');
@@ -200,11 +200,11 @@ SELECT
else
{
// this photo is new
-
+
// current date
list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
list($year, $month, $day) = preg_split('/[^\d]/', $dbnow, 4);
-
+
// upload directory hierarchy
$upload_dir = sprintf(
PHPWG_ROOT_PATH.$conf['upload_dir'].'/%s/%s/%s',
@@ -250,11 +250,11 @@ SELECT
if ($conf['original_resize'])
{
$need_resize = need_resize($file_path, $conf['original_resize_maxwidth'], $conf['original_resize_maxheight']);
-
+
if ($need_resize)
{
$img = new pwg_image($file_path);
-
+
$img->pwg_resize(
$file_path,
$conf['original_resize_maxwidth'],
@@ -263,14 +263,14 @@ SELECT
$conf['upload_form_automatic_rotation'],
false
);
-
+
$img->destroy();
}
}
}
$file_infos = pwg_image_infos($file_path);
-
+
if (isset($image_id))
{
$update = array(
@@ -281,7 +281,7 @@ SELECT
'md5sum' => $md5sum,
'added_by' => $user['id'],
);
-
+
if (isset($level))
{
$update['level'] = $level;
@@ -292,8 +292,6 @@ SELECT
$update,
array('id' => $image_id)
);
-
- delete_element_derivatives($image_id);
}
else
{
@@ -308,14 +306,14 @@ SELECT
'md5sum' => $md5sum,
'added_by' => $user['id'],
);
-
+
if (isset($level))
{
$insert['level'] = $level;
}
single_insert(IMAGES_TABLE, $insert);
-
+
$image_id = pwg_db_insert_id(IMAGES_TABLE);
}
@@ -326,7 +324,7 @@ SELECT
$categories
);
}
-
+
// update metadata from the uploaded file (exif/iptc)
if ($conf['use_exif'] and !function_exists('read_exif_data'))
{
@@ -374,7 +372,7 @@ function need_resize($image_filepath, $max_width, $max_height)
// rotation must be applied to the resized photo, then we should test
// invert width and height.
list($width, $height) = getimagesize($image_filepath);
-
+
if ($width > $max_width or $height > $max_height)
{
return true;
@@ -387,7 +385,7 @@ function pwg_image_infos($path)
{
list($width, $height) = getimagesize($path);
$filesize = floor(filesize($path)/1024);
-
+
return array(
'width' => $width,
'height' => $height,
@@ -433,7 +431,7 @@ function get_ini_size($ini_key, $in_bytes=true)
{
$size = convert_shorthand_notation_to_bytes($size);
}
-
+
return $size;
}
@@ -441,7 +439,7 @@ function convert_shorthand_notation_to_bytes($value)
{
$suffix = substr($value, -1);
$multiply_by = null;
-
+
if ('K' == $suffix)
{
$multiply_by = 1024;
@@ -454,7 +452,7 @@ function convert_shorthand_notation_to_bytes($value)
{
$multiply_by = 1024*1024*1024;
}
-
+
if (isset($multiply_by))
{
$value = substr($value, 0, -1);
@@ -499,7 +497,7 @@ function ready_for_upload_message()
if (!is_writable($conf['upload_dir']))
{
@chmod($conf['upload_dir'], 0777);
-
+
if (!is_writable($conf['upload_dir']))
{
return sprintf(