aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/ws_functions.inc.php123
-rw-r--r--tools/piwigo_remote.pl10
-rw-r--r--ws.php24
3 files changed, 126 insertions, 31 deletions
diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php
index 6b64f15ce..c3372396f 100644
--- a/include/ws_functions.inc.php
+++ b/include/ws_functions.inc.php
@@ -974,6 +974,8 @@ function ws_images_add($params, &$service)
// fwrite($fh_log, 'output: '.md5_file($file_path)."\n");
// fwrite($fh_log, 'output: '.md5_file($thumbnail_path)."\n");
+ list($width, $height) = getimagesize($file_path);
+
// database registration
$insert = array(
'file' => $filename_wo_ext.'.jpg',
@@ -981,8 +983,27 @@ function ws_images_add($params, &$service)
'tn_ext' => 'jpg',
'name' => $params['name'],
'path' => $file_path,
+ 'filesize' => floor(filesize($file_path)/1024),
+ 'width' => $width,
+ 'height' => $height,
+ );
+
+ $info_columns = array(
+ 'name',
+ 'author',
+ 'comment',
+ 'level',
+ 'date_creation',
);
+ foreach ($info_columns as $key)
+ {
+ if (isset($params[$key]))
+ {
+ $insert[$key] = $params[$key];
+ }
+ }
+
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
mass_inserts(
IMAGES_TABLE,
@@ -992,34 +1013,99 @@ function ws_images_add($params, &$service)
$image_id = mysql_insert_id();
- $insert = array(
- 'category_id' => $params['category_id'],
- 'image_id' => $image_id,
- );
+ // let's add links between the image and the categories
+ //
+ // $params['categories'] should look like 123,12;456,auto;789 which means:
+ //
+ // 1. associate with category 123 on rank 12
+ // 2. associate with category 456 on automatic rank
+ // 3. associate with category 789 on automatic rank
+ if (isset($params['categories']))
+ {
+ $cat_ids = array();
+ $rank_on_category = array();
+ $search_current_ranks = false;
+
+ $tokens = explode(';', $params['categories']);
+ foreach ($tokens as $token)
+ {
+ list($cat_id, $rank) = explode(',', $token);
- if ('auto' == $params['rank'])
- {
- $query = '
+ array_push($cat_ids, $cat_id);
+
+ if (!isset($rank))
+ {
+ $rank = 'auto';
+ }
+ $rank_on_category[$cat_id] = $rank;
+
+ if ($rank == 'auto')
+ {
+ $search_current_ranks = true;
+ }
+ }
+
+ $cat_ids = array_unique($cat_ids);
+
+ if (count($cat_ids) > 0)
+ {
+ if ($search_current_ranks)
+ {
+ $query = '
SELECT
+ category_id,
MAX(rank) AS max_rank
FROM '.IMAGE_CATEGORY_TABLE.'
WHERE rank IS NOT NULL
- AND category_id = '.$params['category_id'].'
+ AND category_id IN ('.implode(',', $cat_ids).')
+ GROUP BY category_id
;';
- $row = mysql_fetch_assoc(pwg_query($query));
- $insert['rank'] = isset($row['max_rank']) ? $row['max_rank']+1 : 1;
+ $current_rank_of = simple_hash_from_query(
+ $query,
+ 'category_id',
+ 'max_rank'
+ );
+
+ foreach ($cat_ids as $cat_id)
+ {
+ if ('auto' == $rank_on_category[$cat_id])
+ {
+ $rank_on_category[$cat_id] = $current_rank_of[$cat_id] + 1;
+ }
+ }
+ }
+
+ $inserts = array();
+
+ foreach ($cat_ids as $cat_id)
+ {
+ array_push(
+ $inserts,
+ array(
+ 'image_id' => $image_id,
+ 'category_id' => $cat_id,
+ 'rank' => $rank_on_category[$cat_id],
+ )
+ );
+ }
+
+ mass_inserts(
+ IMAGE_CATEGORY_TABLE,
+ array_keys($inserts[0]),
+ $inserts
+ );
+ }
}
- else if (is_numeric($params['rank']))
+
+ // and now, let's create tag associations
+ if (isset($params['tag_ids']))
{
- $insert['rank'] = (int)$params['rank'];
+ set_tags(
+ explode(',', $params['tag_ids']),
+ $image_id
+ );
}
- mass_inserts(
- IMAGE_CATEGORY_TABLE,
- array_keys($insert),
- array($insert)
- );
-
invalidate_user_cache();
// fclose($fh_log);
@@ -1249,5 +1335,4 @@ LIMIT '.$params['per_page']*$params['page'].','.$params['per_page'];
)
);
}
-
?>
diff --git a/tools/piwigo_remote.pl b/tools/piwigo_remote.pl
index dcc6ba2cd..30b8743b4 100644
--- a/tools/piwigo_remote.pl
+++ b/tools/piwigo_remote.pl
@@ -10,7 +10,7 @@ use Getopt::Long;
my %opt = ();
GetOptions(
\%opt,
- qw/action=s file=s thumbnail=s category_id=i name=s rank=s/
+ qw/action=s file=s thumbnail=s categories=s define=s%/
);
our $ua = LWP::UserAgent->new;
@@ -59,11 +59,13 @@ if ($opt{action} eq 'pwg.images.add') {
file_content => $file_content,
thumbnail_sum => $thumbnail_sum,
thumbnail_content => $thumbnail_content,
- category_id => $opt{category_id},
- name => $opt{name},
- rank => defined($opt{rank}) ? $opt{rank} : 'auto',
+ categories => $opt{categories},
};
+ foreach my $key (keys %{ $opt{define} }) {
+ $form->{$key} = $opt{define}{$key};
+ }
+
my $response = $ua->post(
$conf{base_url}.'/ws.php?format=json',
$form
diff --git a/ws.php b/ws.php
index 63f0d260d..6aa7b3f64 100644
--- a/ws.php
+++ b/ws.php
@@ -176,15 +176,23 @@ function ws_addDefaultMethods( $arr )
'pwg.images.add',
'ws_images_add',
array(
- 'name',
- 'category_id',
- 'file_content',
- 'file_sum',
- 'thumbnail_content',
- 'thumbnail_sum',
- 'rank',
+ 'file_content' => array(),
+ 'file_sum' => array(),
+ 'thumbnail_content' => array(),
+ 'thumbnail_sum' => array(),
+ 'name' => array('default' => null),
+ 'author' => array('default' => null),
+ 'date_creation' => array('default' => null),
+ 'comment' => array('default' => null),
+ 'categories' => array('default' => null),
+ 'tag_ids' => array('default' => null),
+ 'level' => array(
+ 'default' => 0,
+ 'maxValue' => $conf['available_permission_levels']
+ ),
),
- 'POST method only'
+ 'POST method only.
+<br/><b>categories</b> is a string list "category_id[,rank];category_id[,rank]" The rank is optional and is equivalent to "auto" if not given.'
);
$service->addMethod(