aboutsummaryrefslogtreecommitdiffstats
path: root/include/ws_functions.inc.php
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2009-11-22 23:58:44 +0000
committerplegall <plg@piwigo.org>2009-11-22 23:58:44 +0000
commit858b43e87a9911269505c1fbc9036b374e89a565 (patch)
treedf2111e1a2efca092cb83c3e66ab181577b48ed8 /include/ws_functions.inc.php
parent7ee33e9c0c790a47ea57785472a16ed47c1feb65 (diff)
merge r4344 from branch 2.0 to trunk
feature 1051: new API method pwg.images.checkFiles. This method will be useful before asking for an update on photo files. Enhancement in code factorization. git-svn-id: http://piwigo.org/svn/trunk@4347 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include/ws_functions.inc.php')
-rw-r--r--include/ws_functions.inc.php104
1 files changed, 85 insertions, 19 deletions
diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php
index d6ea4f668..9e2040b96 100644
--- a/include/ws_functions.inc.php
+++ b/include/ws_functions.inc.php
@@ -989,25 +989,7 @@ function merge_chunks($output_filepath, $original_sum, $type)
*/
function add_file($file_path, $type, $original_sum, $file_sum)
{
- // resolve the $file_path depending on the $type
- if ('thumb' == $type) {
- $file_path = get_thumbnail_location(
- array(
- 'path' => $file_path,
- 'tn_ext' => 'jpg',
- )
- );
- }
-
- if ('high' == $type) {
- @include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
- $file_path = get_high_location(
- array(
- 'path' => $file_path,
- 'has_high' => 'true'
- )
- );
- }
+ $file_path = file_path_for_type($file_path, $type);
$upload_dir = dirname($file_path);
@@ -1501,6 +1483,90 @@ SELECT
return $result;
}
+function ws_images_checkFiles($params, &$service)
+{
+ if (!is_admin() or is_adviser())
+ {
+ return new PwgError(401, 'Access denied');
+ }
+
+ // input parameters
+ //
+ // image_id
+ // thumbnail_sum
+ // file_sum
+ // high_sum
+
+ $params['image_id'] = (int)$params['image_id'];
+ if ($params['image_id'] <= 0)
+ {
+ return new PwgError(WS_ERR_INVALID_PARAM, "Invalid image_id");
+ }
+
+ $query = '
+SELECT
+ path
+ FROM '.IMAGES_TABLE.'
+ WHERE id = '.$params['image_id'].'
+;';
+ $result = pwg_query($query);
+ if (mysql_num_rows($result) == 0) {
+ return new PwgError(404, "image_id not found");
+ }
+ list($path) = mysql_fetch_row($result);
+
+ $ret = array();
+
+ foreach (array('thumb', 'file', 'high') as $type) {
+ $param_name = $type;
+ if ('thumb' == $type) {
+ $param_name = 'thumbnail';
+ }
+
+ if (isset($params[$param_name.'_sum'])) {
+ $type_path = file_path_for_type($path, $type);
+ if (!is_file($type_path)) {
+ $ret[$param_name] = 'missing';
+ }
+ else {
+ if (md5_file($type_path) != $params[$param_name.'_sum']) {
+ $ret[$param_name] = 'differs';
+ }
+ else {
+ $ret[$param_name] = 'equals';
+ }
+ }
+ }
+ }
+
+ return $ret;
+}
+
+function file_path_for_type($file_path, $type='thumb')
+{
+ // resolve the $file_path depending on the $type
+ if ('thumb' == $type) {
+ $file_path = get_thumbnail_location(
+ array(
+ 'path' => $file_path,
+ 'tn_ext' => 'jpg',
+ )
+ );
+ }
+
+ if ('high' == $type) {
+ @include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
+ $file_path = get_high_location(
+ array(
+ 'path' => $file_path,
+ 'has_high' => 'true'
+ )
+ );
+ }
+
+ return $file_path;
+}
+
function ws_images_setInfo($params, &$service)
{
global $conf;