2007-01-06 12:13:08 +01:00
|
|
|
<?php
|
|
|
|
// +-----------------------------------------------------------------------+
|
2011-01-18 01:02:52 +01:00
|
|
|
// | Piwigo - a PHP based photo gallery |
|
2008-04-05 00:57:23 +02:00
|
|
|
// +-----------------------------------------------------------------------+
|
2012-01-17 23:48:36 +01:00
|
|
|
// | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org |
|
2008-04-05 00:57:23 +02:00
|
|
|
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
|
|
|
|
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
|
|
|
|
// +-----------------------------------------------------------------------+
|
2007-01-06 12:13:08 +01:00
|
|
|
// | This program is free software; you can redistribute it and/or modify |
|
|
|
|
// | it under the terms of the GNU General Public License as published by |
|
|
|
|
// | the Free Software Foundation |
|
|
|
|
// | |
|
|
|
|
// | This program is distributed in the hope that it will be useful, but |
|
|
|
|
// | WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
|
|
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
|
|
|
// | General Public License for more details. |
|
|
|
|
// | |
|
|
|
|
// | You should have received a copy of the GNU General Public License |
|
|
|
|
// | along with this program; if not, write to the Free Software |
|
|
|
|
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
|
|
|
|
// | USA. |
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
|
|
|
|
/**** IMPLEMENTATION OF WEB SERVICE METHODS ***********************************/
|
|
|
|
|
2007-01-29 21:38:08 +01:00
|
|
|
/**
|
|
|
|
* Event handler for method invocation security check. Should return a PwgError
|
|
|
|
* if the preconditions are not satifsied for method invocation.
|
|
|
|
*/
|
|
|
|
function ws_isInvokeAllowed($res, $methodName, $params)
|
|
|
|
{
|
2008-09-23 03:04:41 +02:00
|
|
|
global $conf;
|
2007-10-04 01:36:21 +02:00
|
|
|
|
2007-02-22 02:12:32 +01:00
|
|
|
if ( strpos($methodName,'reflection.')===0 )
|
|
|
|
{ // OK for reflection
|
|
|
|
return $res;
|
|
|
|
}
|
2007-10-04 01:36:21 +02:00
|
|
|
|
2007-02-22 02:12:32 +01:00
|
|
|
if ( !is_autorize_status(ACCESS_GUEST) and
|
|
|
|
strpos($methodName,'pwg.session.')!==0 )
|
|
|
|
{
|
|
|
|
return new PwgError(401, 'Access denied');
|
|
|
|
}
|
2007-10-04 01:36:21 +02:00
|
|
|
|
2007-01-29 21:38:08 +01:00
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
2007-01-06 12:13:08 +01:00
|
|
|
/**
|
|
|
|
* returns a "standard" (for our web service) array of sql where clauses that
|
2007-01-11 06:10:16 +01:00
|
|
|
* filters the images (images table only)
|
|
|
|
*/
|
2007-01-06 12:13:08 +01:00
|
|
|
function ws_std_image_sql_filter( $params, $tbl_name='' )
|
|
|
|
{
|
|
|
|
$clauses = array();
|
|
|
|
if ( is_numeric($params['f_min_rate']) )
|
|
|
|
{
|
2011-08-02 21:20:50 +02:00
|
|
|
$clauses[] = $tbl_name.'rating_score>'.$params['f_min_rate'];
|
2007-01-06 12:13:08 +01:00
|
|
|
}
|
|
|
|
if ( is_numeric($params['f_max_rate']) )
|
|
|
|
{
|
2011-08-02 21:20:50 +02:00
|
|
|
$clauses[] = $tbl_name.'rating_score<='.$params['f_max_rate'];
|
2007-01-06 12:13:08 +01:00
|
|
|
}
|
|
|
|
if ( is_numeric($params['f_min_hit']) )
|
|
|
|
{
|
|
|
|
$clauses[] = $tbl_name.'hit>'.$params['f_min_hit'];
|
|
|
|
}
|
|
|
|
if ( is_numeric($params['f_max_hit']) )
|
|
|
|
{
|
|
|
|
$clauses[] = $tbl_name.'hit<='.$params['f_max_hit'];
|
|
|
|
}
|
2011-03-08 21:42:04 +01:00
|
|
|
if ( isset($params['f_min_date_available']) )
|
2007-01-06 12:13:08 +01:00
|
|
|
{
|
2011-03-08 21:42:04 +01:00
|
|
|
$clauses[] = $tbl_name."date_available>='".$params['f_min_date_available']."'";
|
2007-01-06 12:13:08 +01:00
|
|
|
}
|
2011-03-08 21:42:04 +01:00
|
|
|
if ( isset($params['f_max_date_available']) )
|
2007-01-06 12:13:08 +01:00
|
|
|
{
|
2011-03-08 21:42:04 +01:00
|
|
|
$clauses[] = $tbl_name."date_available<'".$params['f_max_date_available']."'";
|
2007-01-06 12:13:08 +01:00
|
|
|
}
|
|
|
|
if ( isset($params['f_min_date_created']) )
|
|
|
|
{
|
|
|
|
$clauses[] = $tbl_name."date_creation>='".$params['f_min_date_created']."'";
|
|
|
|
}
|
|
|
|
if ( isset($params['f_max_date_created']) )
|
|
|
|
{
|
|
|
|
$clauses[] = $tbl_name."date_creation<'".$params['f_max_date_created']."'";
|
|
|
|
}
|
|
|
|
if ( is_numeric($params['f_min_ratio']) )
|
|
|
|
{
|
|
|
|
$clauses[] = $tbl_name.'width/'.$tbl_name.'height>'.$params['f_min_ratio'];
|
|
|
|
}
|
|
|
|
if ( is_numeric($params['f_max_ratio']) )
|
|
|
|
{
|
|
|
|
$clauses[] = $tbl_name.'width/'.$tbl_name.'height<='.$params['f_max_ratio'];
|
|
|
|
}
|
2012-01-08 20:25:52 +01:00
|
|
|
if (is_numeric($params['f_max_level']) )
|
2007-01-06 12:13:08 +01:00
|
|
|
{
|
2012-01-08 20:25:52 +01:00
|
|
|
$clauses[] = $tbl_name.'level <= '.$params['f_max_level'];
|
2007-01-06 12:13:08 +01:00
|
|
|
}
|
|
|
|
return $clauses;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns a "standard" (for our web service) ORDER BY sql clause for images
|
2007-01-11 06:10:16 +01:00
|
|
|
*/
|
2007-01-06 12:13:08 +01:00
|
|
|
function ws_std_image_sql_order( $params, $tbl_name='' )
|
|
|
|
{
|
|
|
|
$ret = '';
|
|
|
|
if ( empty($params['order']) )
|
|
|
|
{
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
$matches = array();
|
|
|
|
preg_match_all('/([a-z_]+) *(?:(asc|desc)(?:ending)?)? *(?:, *|$)/i',
|
|
|
|
$params['order'], $matches);
|
|
|
|
for ($i=0; $i<count($matches[1]); $i++)
|
|
|
|
{
|
|
|
|
switch ($matches[1][$i])
|
|
|
|
{
|
|
|
|
case 'date_created':
|
|
|
|
$matches[1][$i] = 'date_creation'; break;
|
|
|
|
case 'date_posted':
|
|
|
|
$matches[1][$i] = 'date_available'; break;
|
|
|
|
case 'rand': case 'random':
|
2009-11-25 20:02:57 +01:00
|
|
|
$matches[1][$i] = DB_RANDOM_FUNCTION.'()'; break;
|
2007-01-06 12:13:08 +01:00
|
|
|
}
|
2011-08-02 21:20:50 +02:00
|
|
|
$sortable_fields = array('id', 'file', 'name', 'hit', 'rating_score',
|
2009-11-25 20:02:57 +01:00
|
|
|
'date_creation', 'date_available', DB_RANDOM_FUNCTION.'()' );
|
2007-01-06 12:13:08 +01:00
|
|
|
if ( in_array($matches[1][$i], $sortable_fields) )
|
|
|
|
{
|
|
|
|
if (!empty($ret))
|
|
|
|
$ret .= ', ';
|
2009-11-25 20:02:57 +01:00
|
|
|
if ($matches[1][$i] != DB_RANDOM_FUNCTION.'()' )
|
2007-01-06 12:13:08 +01:00
|
|
|
{
|
|
|
|
$ret .= $tbl_name;
|
|
|
|
}
|
|
|
|
$ret .= $matches[1][$i];
|
|
|
|
$ret .= ' '.$matches[2][$i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns an array map of urls (thumb/element) for image_row - to be returned
|
|
|
|
* in a standard way by different web service methods
|
2007-01-11 06:10:16 +01:00
|
|
|
*/
|
2007-01-06 12:13:08 +01:00
|
|
|
function ws_std_get_urls($image_row)
|
|
|
|
{
|
2011-12-27 06:26:44 +01:00
|
|
|
$ret = array();
|
2012-01-08 20:25:52 +01:00
|
|
|
|
2012-01-05 23:06:21 +01:00
|
|
|
$src_image = new SrcImage($image_row);
|
|
|
|
|
2012-08-07 21:52:37 +02:00
|
|
|
if ( $src_image->is_original() )
|
|
|
|
{// we have a photo
|
|
|
|
global $user;
|
|
|
|
if ($user['enabled_high'])
|
|
|
|
{
|
|
|
|
$ret['element_url'] = $src_image->get_url();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2007-01-06 12:13:08 +01:00
|
|
|
{
|
2011-12-27 06:26:44 +01:00
|
|
|
$ret['element_url'] = get_element_url($image_row);
|
2007-01-06 12:13:08 +01:00
|
|
|
}
|
2012-01-08 20:25:52 +01:00
|
|
|
|
2012-01-05 23:06:21 +01:00
|
|
|
$derivatives = DerivativeImage::get_all($src_image);
|
2011-12-27 06:26:44 +01:00
|
|
|
$derivatives_arr = array();
|
|
|
|
foreach($derivatives as $type=>$derivative)
|
|
|
|
{
|
|
|
|
$size = $derivative->get_size();
|
|
|
|
$size != null or $size=array(null,null);
|
|
|
|
$derivatives_arr[$type] = array('url' => $derivative->get_url(), 'width'=>$size[0], 'height'=>$size[1] );
|
|
|
|
}
|
|
|
|
$ret['derivatives'] = $derivatives_arr;;
|
2007-01-06 12:13:08 +01:00
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
2007-02-21 01:20:02 +01:00
|
|
|
/**
|
|
|
|
* returns an array of image attributes that are to be encoded as xml attributes
|
|
|
|
* instead of xml elements
|
|
|
|
*/
|
|
|
|
function ws_std_get_image_xml_attributes()
|
|
|
|
{
|
|
|
|
return array(
|
2011-12-27 06:26:44 +01:00
|
|
|
'id','element_url', 'file','width','height','hit','date_available','date_creation'
|
2007-02-21 01:20:02 +01:00
|
|
|
);
|
|
|
|
}
|
2007-01-06 12:13:08 +01:00
|
|
|
|
2012-01-08 20:25:52 +01:00
|
|
|
function ws_getMissingDerivatives($params, &$service)
|
|
|
|
{
|
|
|
|
if (!is_admin())
|
|
|
|
{
|
|
|
|
return new PwgError(403, 'Forbidden');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( empty($params['types']) )
|
|
|
|
{
|
|
|
|
$types = array_keys(ImageStdParams::get_defined_type_map());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$types = array_intersect(array_keys(ImageStdParams::get_defined_type_map()), $params['types']);
|
|
|
|
if (count($types)==0)
|
|
|
|
{
|
|
|
|
return new PwgError(WS_ERR_INVALID_PARAM, "Invalid types");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ($max_urls = intval($params['max_urls'])) <= 0)
|
|
|
|
{
|
|
|
|
return new PwgError(WS_ERR_INVALID_PARAM, "Invalid max_urls");
|
|
|
|
}
|
|
|
|
|
|
|
|
list($max_id, $image_count) = pwg_db_fetch_row( pwg_query('SELECT MAX(id)+1, COUNT(*) FROM '.IMAGES_TABLE) );
|
2012-07-25 17:14:04 +02:00
|
|
|
|
|
|
|
if (0 == $image_count)
|
|
|
|
{
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
2012-01-08 20:25:52 +01:00
|
|
|
$start_id = intval($params['prev_page']);
|
|
|
|
if ($start_id<=0)
|
|
|
|
{
|
|
|
|
$start_id = $max_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
$uid = '&b='.time();
|
|
|
|
global $conf;
|
|
|
|
$conf['question_mark_in_urls'] = $conf['php_extension_in_urls'] = true;
|
|
|
|
$conf['derivative_url_style']=2; //script
|
|
|
|
|
|
|
|
$qlimit = min(5000, ceil(max($image_count/500, $max_urls/count($types))));
|
|
|
|
$where_clauses = ws_std_image_sql_filter( $params, '' );
|
|
|
|
$where_clauses[] = 'id<start_id';
|
2012-03-13 22:13:17 +01:00
|
|
|
if ( !empty($params['ids']) )
|
|
|
|
{
|
|
|
|
$where_clauses[] = 'id IN ('.implode(',',$params['ids']).')';
|
|
|
|
}
|
2012-01-08 20:25:52 +01:00
|
|
|
|
2012-04-14 06:52:20 +02:00
|
|
|
$query_model = 'SELECT id, path, representative_ext, width,height,rotation
|
2012-01-08 20:25:52 +01:00
|
|
|
FROM '.IMAGES_TABLE.'
|
|
|
|
WHERE '.implode(' AND ', $where_clauses).'
|
|
|
|
ORDER BY id DESC
|
|
|
|
LIMIT '.$qlimit;
|
|
|
|
|
|
|
|
$urls=array();
|
|
|
|
do
|
|
|
|
{
|
|
|
|
$result = pwg_query( str_replace('start_id', $start_id, $query_model));
|
|
|
|
$is_last = pwg_db_num_rows($result) < $qlimit;
|
|
|
|
while ($row=pwg_db_fetch_assoc($result))
|
|
|
|
{
|
|
|
|
$start_id = $row['id'];
|
|
|
|
$src_image = new SrcImage($row);
|
|
|
|
if ($src_image->is_mimetype())
|
|
|
|
continue;
|
|
|
|
foreach($types as $type)
|
|
|
|
{
|
|
|
|
$derivative = new DerivativeImage($type, $src_image);
|
|
|
|
if ($type != $derivative->get_type())
|
|
|
|
continue;
|
|
|
|
if (@filemtime($derivative->get_path())===false)
|
|
|
|
{
|
|
|
|
$urls[] = $derivative->get_url().$uid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (count($urls)>=$max_urls && !$is_last)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ($is_last)
|
|
|
|
{
|
|
|
|
$start_id = 0;
|
|
|
|
}
|
|
|
|
}while (count($urls)<$max_urls && $start_id);
|
|
|
|
|
|
|
|
$ret = array();
|
|
|
|
if ($start_id)
|
|
|
|
{
|
|
|
|
$ret['next_page']=$start_id;
|
|
|
|
}
|
|
|
|
$ret['urls']=$urls;
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
2007-02-06 02:02:06 +01:00
|
|
|
/**
|
|
|
|
* returns PWG version (web service method)
|
|
|
|
*/
|
2007-01-06 12:13:08 +01:00
|
|
|
function ws_getVersion($params, &$service)
|
|
|
|
{
|
2007-02-23 14:18:34 +01:00
|
|
|
global $conf;
|
2011-03-17 15:40:26 +01:00
|
|
|
if ($conf['show_version'] or is_admin() )
|
2007-02-23 14:18:34 +01:00
|
|
|
return PHPWG_VERSION;
|
|
|
|
else
|
|
|
|
return new PwgError(403, 'Forbidden');
|
2007-01-06 12:13:08 +01:00
|
|
|
}
|
|
|
|
|
2011-04-03 14:36:32 +02:00
|
|
|
/**
|
|
|
|
* returns general informations (web service method)
|
|
|
|
*/
|
|
|
|
function ws_getInfos($params, &$service)
|
|
|
|
{
|
2011-04-05 15:10:52 +02:00
|
|
|
if (!is_admin())
|
2011-04-03 14:36:32 +02:00
|
|
|
{
|
2011-04-05 15:10:52 +02:00
|
|
|
return new PwgError(403, 'Forbidden');
|
2011-04-03 14:36:32 +02:00
|
|
|
}
|
2011-04-05 15:10:52 +02:00
|
|
|
|
|
|
|
$infos['version'] = PHPWG_VERSION;
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2011-04-03 14:36:32 +02:00
|
|
|
$query = 'SELECT COUNT(*) FROM '.IMAGES_TABLE.';';
|
|
|
|
list($infos['nb_elements']) = pwg_db_fetch_row(pwg_query($query));
|
|
|
|
|
|
|
|
$query = 'SELECT COUNT(*) FROM '.CATEGORIES_TABLE.';';
|
|
|
|
list($infos['nb_categories']) = pwg_db_fetch_row(pwg_query($query));
|
|
|
|
|
|
|
|
$query = 'SELECT COUNT(*) FROM '.CATEGORIES_TABLE.' WHERE dir IS NULL;';
|
|
|
|
list($infos['nb_virtual']) = pwg_db_fetch_row(pwg_query($query));
|
|
|
|
|
|
|
|
$query = 'SELECT COUNT(*) FROM '.CATEGORIES_TABLE.' WHERE dir IS NOT NULL;';
|
|
|
|
list($infos['nb_physical']) = pwg_db_fetch_row(pwg_query($query));
|
|
|
|
|
|
|
|
$query = 'SELECT COUNT(*) FROM '.IMAGE_CATEGORY_TABLE.';';
|
|
|
|
list($infos['nb_image_category']) = pwg_db_fetch_row(pwg_query($query));
|
|
|
|
|
|
|
|
$query = 'SELECT COUNT(*) FROM '.TAGS_TABLE.';';
|
|
|
|
list($infos['nb_tags']) = pwg_db_fetch_row(pwg_query($query));
|
|
|
|
|
|
|
|
$query = 'SELECT COUNT(*) FROM '.IMAGE_TAG_TABLE.';';
|
|
|
|
list($infos['nb_image_tag']) = pwg_db_fetch_row(pwg_query($query));
|
|
|
|
|
|
|
|
$query = 'SELECT COUNT(*) FROM '.USERS_TABLE.';';
|
|
|
|
list($infos['nb_users']) = pwg_db_fetch_row(pwg_query($query));
|
|
|
|
|
|
|
|
$query = 'SELECT COUNT(*) FROM '.GROUPS_TABLE.';';
|
|
|
|
list($infos['nb_groups']) = pwg_db_fetch_row(pwg_query($query));
|
|
|
|
|
|
|
|
$query = 'SELECT COUNT(*) FROM '.COMMENTS_TABLE.';';
|
|
|
|
list($infos['nb_comments']) = pwg_db_fetch_row(pwg_query($query));
|
|
|
|
|
|
|
|
// first element
|
|
|
|
if ($infos['nb_elements'] > 0)
|
|
|
|
{
|
|
|
|
$query = 'SELECT MIN(date_available) FROM '.IMAGES_TABLE.';';
|
|
|
|
list($infos['first_date']) = pwg_db_fetch_row(pwg_query($query));
|
|
|
|
}
|
|
|
|
|
|
|
|
// unvalidated comments
|
2011-04-05 15:10:52 +02:00
|
|
|
if ($infos['nb_comments'] > 0)
|
2011-04-03 14:36:32 +02:00
|
|
|
{
|
|
|
|
$query = 'SELECT COUNT(*) FROM '.COMMENTS_TABLE.' WHERE validated=\'false\';';
|
|
|
|
list($infos['nb_unvalidated_comments']) = pwg_db_fetch_row(pwg_query($query));
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($infos as $name => $value)
|
|
|
|
{
|
|
|
|
$output[] = array(
|
|
|
|
'name' => $name,
|
|
|
|
'value' => $value,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return array('infos' => new PwgNamedArray($output, 'item'));
|
|
|
|
}
|
|
|
|
|
2008-07-12 02:30:27 +02:00
|
|
|
function ws_caddie_add($params, &$service)
|
|
|
|
{
|
|
|
|
if (!is_admin())
|
|
|
|
{
|
|
|
|
return new PwgError(401, 'Access denied');
|
|
|
|
}
|
2008-10-18 02:45:45 +02:00
|
|
|
$params['image_id'] = array_map( 'intval',$params['image_id'] );
|
2008-07-12 02:30:27 +02:00
|
|
|
if ( empty($params['image_id']) )
|
|
|
|
{
|
|
|
|
return new PwgError(WS_ERR_INVALID_PARAM, "Invalid image_id");
|
|
|
|
}
|
|
|
|
global $user;
|
|
|
|
$query = '
|
|
|
|
SELECT id
|
|
|
|
FROM '.IMAGES_TABLE.' LEFT JOIN '.CADDIE_TABLE.' ON id=element_id AND user_id='.$user['id'].'
|
|
|
|
WHERE id IN ('.implode(',',$params['image_id']).')
|
|
|
|
AND element_id IS NULL';
|
|
|
|
$datas = array();
|
|
|
|
foreach ( array_from_query($query, 'id') as $id )
|
|
|
|
{
|
|
|
|
array_push($datas, array('element_id'=>$id, 'user_id'=>$user['id']) );
|
|
|
|
}
|
|
|
|
if (count($datas))
|
|
|
|
{
|
|
|
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
|
|
|
mass_inserts(CADDIE_TABLE, array('element_id','user_id'), $datas);
|
|
|
|
}
|
|
|
|
return count($datas);
|
|
|
|
}
|
2007-02-06 02:02:06 +01:00
|
|
|
|
2007-01-06 12:13:08 +01:00
|
|
|
/**
|
2007-02-06 02:02:06 +01:00
|
|
|
* returns images per category (web service method)
|
2007-01-11 06:10:16 +01:00
|
|
|
*/
|
2007-01-06 12:13:08 +01:00
|
|
|
function ws_categories_getImages($params, &$service)
|
|
|
|
{
|
|
|
|
global $user, $conf;
|
|
|
|
|
|
|
|
$images = array();
|
|
|
|
|
|
|
|
//------------------------------------------------- get the related categories
|
|
|
|
$where_clauses = array();
|
|
|
|
foreach($params['cat_id'] as $cat_id)
|
|
|
|
{
|
|
|
|
$cat_id = (int)$cat_id;
|
|
|
|
if ($cat_id<=0)
|
|
|
|
continue;
|
|
|
|
if ($params['recursive'])
|
|
|
|
{
|
2009-11-25 20:02:57 +01:00
|
|
|
$where_clauses[] = 'uppercats '.DB_REGEX_OPERATOR.' \'(^|,)'.$cat_id.'(,|$)\'';
|
2007-01-06 12:13:08 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$where_clauses[] = 'id='.$cat_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!empty($where_clauses))
|
|
|
|
{
|
|
|
|
$where_clauses = array( '('.
|
|
|
|
implode('
|
|
|
|
OR ', $where_clauses) . ')'
|
|
|
|
);
|
|
|
|
}
|
2007-10-04 01:36:21 +02:00
|
|
|
$where_clauses[] = get_sql_condition_FandF(
|
|
|
|
array('forbidden_categories' => 'id'),
|
|
|
|
NULL, true
|
|
|
|
);
|
2007-01-06 12:13:08 +01:00
|
|
|
|
|
|
|
$query = '
|
2007-02-28 04:07:12 +01:00
|
|
|
SELECT id, name, permalink, image_order
|
2007-01-06 12:13:08 +01:00
|
|
|
FROM '.CATEGORIES_TABLE.'
|
|
|
|
WHERE '. implode('
|
|
|
|
AND ', $where_clauses);
|
|
|
|
$result = pwg_query($query);
|
|
|
|
$cats = array();
|
2009-11-20 15:17:04 +01:00
|
|
|
while ($row = pwg_db_fetch_assoc($result))
|
2007-01-06 12:13:08 +01:00
|
|
|
{
|
|
|
|
$row['id'] = (int)$row['id'];
|
|
|
|
$cats[ $row['id'] ] = $row;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------- get the images
|
|
|
|
if ( !empty($cats) )
|
|
|
|
{
|
|
|
|
$where_clauses = ws_std_image_sql_filter( $params, 'i.' );
|
|
|
|
$where_clauses[] = 'category_id IN ('
|
|
|
|
.implode(',', array_keys($cats) )
|
|
|
|
.')';
|
2007-02-06 02:02:06 +01:00
|
|
|
$where_clauses[] = get_sql_condition_FandF( array(
|
|
|
|
'visible_images' => 'i.id'
|
|
|
|
), null, true
|
|
|
|
);
|
2007-01-25 22:14:35 +01:00
|
|
|
|
2007-01-06 12:13:08 +01:00
|
|
|
$order_by = ws_std_image_sql_order($params, 'i.');
|
2007-02-23 14:18:34 +01:00
|
|
|
if ( empty($order_by)
|
|
|
|
and count($params['cat_id'])==1
|
|
|
|
and isset($cats[ $params['cat_id'][0] ]['image_order'])
|
|
|
|
)
|
2007-01-06 12:13:08 +01:00
|
|
|
{
|
2007-02-23 14:18:34 +01:00
|
|
|
$order_by = $cats[ $params['cat_id'][0] ]['image_order'];
|
2007-01-06 12:13:08 +01:00
|
|
|
}
|
2007-02-23 14:18:34 +01:00
|
|
|
$order_by = empty($order_by) ? $conf['order_by'] : 'ORDER BY '.$order_by;
|
|
|
|
|
2007-01-06 12:13:08 +01:00
|
|
|
$query = '
|
2010-07-03 14:12:25 +02:00
|
|
|
SELECT i.*, GROUP_CONCAT(category_id) AS cat_ids
|
2007-01-06 12:13:08 +01:00
|
|
|
FROM '.IMAGES_TABLE.' i
|
|
|
|
INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON i.id=image_id
|
|
|
|
WHERE '. implode('
|
|
|
|
AND ', $where_clauses).'
|
|
|
|
GROUP BY i.id
|
|
|
|
'.$order_by.'
|
2009-11-21 20:52:50 +01:00
|
|
|
LIMIT '.(int)$params['per_page'].' OFFSET '.(int)($params['per_page']*$params['page']);
|
2007-01-06 12:13:08 +01:00
|
|
|
|
|
|
|
$result = pwg_query($query);
|
2009-11-20 15:17:04 +01:00
|
|
|
while ($row = pwg_db_fetch_assoc($result))
|
2007-01-06 12:13:08 +01:00
|
|
|
{
|
|
|
|
$image = array();
|
|
|
|
foreach ( array('id', 'width', 'height', 'hit') as $k )
|
|
|
|
{
|
|
|
|
if (isset($row[$k]))
|
|
|
|
{
|
|
|
|
$image[$k] = (int)$row[$k];
|
|
|
|
}
|
|
|
|
}
|
2011-05-30 23:32:10 +02:00
|
|
|
foreach ( array('file', 'name', 'comment', 'date_creation', 'date_available') as $k )
|
2007-01-06 12:13:08 +01:00
|
|
|
{
|
|
|
|
$image[$k] = $row[$k];
|
|
|
|
}
|
|
|
|
$image = array_merge( $image, ws_std_get_urls($row) );
|
|
|
|
|
|
|
|
$image_cats = array();
|
|
|
|
foreach ( explode(',', $row['cat_ids']) as $cat_id )
|
|
|
|
{
|
|
|
|
$url = make_index_url(
|
|
|
|
array(
|
2007-02-27 02:56:16 +01:00
|
|
|
'category' => $cats[$cat_id],
|
2007-01-06 12:13:08 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
$page_url = make_picture_url(
|
|
|
|
array(
|
2007-02-27 02:56:16 +01:00
|
|
|
'category' => $cats[$cat_id],
|
2007-01-06 12:13:08 +01:00
|
|
|
'image_id' => $row['id'],
|
|
|
|
'image_file' => $row['file'],
|
|
|
|
)
|
|
|
|
);
|
|
|
|
array_push( $image_cats, array(
|
|
|
|
WS_XML_ATTRIBUTES => array (
|
|
|
|
'id' => (int)$cat_id,
|
|
|
|
'url' => $url,
|
|
|
|
'page_url' => $page_url,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$image['categories'] = new PwgNamedArray(
|
|
|
|
$image_cats,'category', array('id','url','page_url')
|
|
|
|
);
|
|
|
|
array_push($images, $image);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return array( 'images' =>
|
|
|
|
array (
|
|
|
|
WS_XML_ATTRIBUTES =>
|
|
|
|
array(
|
|
|
|
'page' => $params['page'],
|
|
|
|
'per_page' => $params['per_page'],
|
|
|
|
'count' => count($images)
|
|
|
|
),
|
2007-01-11 06:10:16 +01:00
|
|
|
WS_XML_CONTENT => new PwgNamedArray($images, 'image',
|
2007-02-21 01:20:02 +01:00
|
|
|
ws_std_get_image_xml_attributes() )
|
2007-01-06 12:13:08 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2007-02-06 02:02:06 +01:00
|
|
|
|
2012-02-09 22:11:34 +01:00
|
|
|
/**
|
|
|
|
* create a tree from a flat list of categories, no recursivity for high speed
|
|
|
|
*/
|
|
|
|
function categories_flatlist_to_tree($categories)
|
|
|
|
{
|
|
|
|
$tree = array();
|
|
|
|
$key_of_cat = array();
|
|
|
|
|
|
|
|
foreach ($categories as $key => &$node)
|
|
|
|
{
|
|
|
|
$key_of_cat[$node['id']] = $key;
|
|
|
|
|
|
|
|
if (!isset($node['id_uppercat']))
|
|
|
|
{
|
|
|
|
$tree[$key] = &$node;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!isset($categories[ $key_of_cat[ $node['id_uppercat'] ] ]['sub_categories']))
|
|
|
|
{
|
|
|
|
$categories[ $key_of_cat[ $node['id_uppercat'] ] ]['sub_categories'] = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
$categories[ $key_of_cat[ $node['id_uppercat'] ] ]['sub_categories'][$key] = &$node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $tree;
|
|
|
|
}
|
|
|
|
|
2007-01-06 12:13:08 +01:00
|
|
|
/**
|
2007-02-06 02:02:06 +01:00
|
|
|
* returns a list of categories (web service method)
|
2007-01-06 12:13:08 +01:00
|
|
|
*/
|
|
|
|
function ws_categories_getList($params, &$service)
|
|
|
|
{
|
2007-02-15 01:10:41 +01:00
|
|
|
global $user,$conf;
|
2007-01-06 12:13:08 +01:00
|
|
|
|
2011-05-31 22:25:40 +02:00
|
|
|
if ($params['tree_output'])
|
|
|
|
{
|
|
|
|
if (!isset($_GET['format']) or !in_array($_GET['format'], array('php', 'json')))
|
|
|
|
{
|
|
|
|
// the algorithm used to build a tree from a flat list of categories
|
|
|
|
// keeps original array keys, which is not compatible with
|
|
|
|
// PwgNamedArray.
|
|
|
|
//
|
|
|
|
// PwgNamedArray is useful to define which data is an attribute and
|
|
|
|
// which is an element in the XML output. The "hierarchy" output is
|
|
|
|
// only compatible with json/php output.
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2011-05-31 22:25:40 +02:00
|
|
|
return new PwgError(405, "The tree_output option is only compatible with json/php output formats");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-13 00:05:37 +01:00
|
|
|
$where = array('1=1');
|
|
|
|
$join_type = 'INNER';
|
|
|
|
$join_user = $user['id'];
|
2007-01-06 12:13:08 +01:00
|
|
|
|
|
|
|
if (!$params['recursive'])
|
|
|
|
{
|
|
|
|
if ($params['cat_id']>0)
|
2007-02-15 01:10:41 +01:00
|
|
|
$where[] = '(id_uppercat='.(int)($params['cat_id']).'
|
|
|
|
OR id='.(int)($params['cat_id']).')';
|
2007-01-06 12:13:08 +01:00
|
|
|
else
|
|
|
|
$where[] = 'id_uppercat IS NULL';
|
|
|
|
}
|
2007-02-15 01:10:41 +01:00
|
|
|
else if ($params['cat_id']>0)
|
|
|
|
{
|
2009-11-25 20:02:57 +01:00
|
|
|
$where[] = 'uppercats '.DB_REGEX_OPERATOR.' \'(^|,)'.
|
2007-02-15 01:10:41 +01:00
|
|
|
(int)($params['cat_id'])
|
|
|
|
.'(,|$)\'';
|
|
|
|
}
|
2007-01-06 12:13:08 +01:00
|
|
|
|
|
|
|
if ($params['public'])
|
|
|
|
{
|
|
|
|
$where[] = 'status = "public"';
|
2007-01-11 06:10:16 +01:00
|
|
|
$where[] = 'visible = "true"';
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2010-02-13 00:05:37 +01:00
|
|
|
$join_user = $conf['guest_id'];
|
2007-01-06 12:13:08 +01:00
|
|
|
}
|
2010-02-13 00:05:37 +01:00
|
|
|
elseif (is_admin())
|
2007-01-06 12:13:08 +01:00
|
|
|
{
|
2010-02-13 00:05:37 +01:00
|
|
|
// in this very specific case, we don't want to hide empty
|
|
|
|
// categories. Function calculate_permissions will only return
|
|
|
|
// categories that are either locked or private and not permitted
|
2011-08-02 21:20:50 +02:00
|
|
|
//
|
2010-02-13 00:05:37 +01:00
|
|
|
// calculate_permissions does not consider empty categories as forbidden
|
|
|
|
$forbidden_categories = calculate_permissions($user['id'], $user['status']);
|
|
|
|
$where[]= 'id NOT IN ('.$forbidden_categories.')';
|
|
|
|
$join_type = 'LEFT';
|
2007-01-06 12:13:08 +01:00
|
|
|
}
|
|
|
|
|
2007-01-11 06:10:16 +01:00
|
|
|
$query = '
|
2011-05-31 22:25:40 +02:00
|
|
|
SELECT id, name, permalink, uppercats, global_rank, id_uppercat,
|
2010-11-01 20:30:59 +01:00
|
|
|
comment,
|
2007-02-21 01:20:02 +01:00
|
|
|
nb_images, count_images AS total_nb_images,
|
2011-12-30 22:25:32 +01:00
|
|
|
representative_picture_id, user_representative_picture_id, count_images, count_categories,
|
2007-02-21 01:20:02 +01:00
|
|
|
date_last, max_date_last, count_categories AS nb_categories
|
2007-01-11 06:10:16 +01:00
|
|
|
FROM '.CATEGORIES_TABLE.'
|
2010-02-13 00:05:37 +01:00
|
|
|
'.$join_type.' JOIN '.USER_CACHE_CATEGORIES_TABLE.' ON id=cat_id AND user_id='.$join_user.'
|
2007-01-06 12:13:08 +01:00
|
|
|
WHERE '. implode('
|
|
|
|
AND ', $where);
|
|
|
|
|
|
|
|
$result = pwg_query($query);
|
|
|
|
|
2011-11-04 22:22:55 +01:00
|
|
|
// management of the album thumbnail -- starts here
|
|
|
|
$image_ids = array();
|
|
|
|
$categories = array();
|
|
|
|
$user_representative_updates_for = array();
|
|
|
|
// management of the album thumbnail -- stops here
|
2012-01-08 20:25:52 +01:00
|
|
|
|
2007-01-06 12:13:08 +01:00
|
|
|
$cats = array();
|
2009-11-20 15:17:04 +01:00
|
|
|
while ($row = pwg_db_fetch_assoc($result))
|
2007-01-06 12:13:08 +01:00
|
|
|
{
|
|
|
|
$row['url'] = make_index_url(
|
|
|
|
array(
|
2007-02-27 02:56:16 +01:00
|
|
|
'category' => $row
|
2007-01-06 12:13:08 +01:00
|
|
|
)
|
|
|
|
);
|
2007-02-21 01:20:02 +01:00
|
|
|
foreach( array('id','nb_images','total_nb_images','nb_categories') as $key)
|
2007-01-06 12:13:08 +01:00
|
|
|
{
|
|
|
|
$row[$key] = (int)$row[$key];
|
|
|
|
}
|
2008-09-23 03:04:41 +02:00
|
|
|
|
feature 2406 added: if the user wants a new album in the upload form, the album
is created before the start of the upload. The ergonomy is now simpler, the
page is smaller and cleaner.
bug 2373 fixed: now that album is created before upload, uploadify.php gets the
category_id and the level: as soon as it is uploaded (function add_uploaded_file)
the photo gets its final privacy level and is directly associated to the album.
This way, we can have an error on a photo without making orphan all photos of
the same upload group.
feature 2405 added: as soon as a photo is uploaded, its thumbnail is displayed
in the "Uploaded Photos" fieldset, without waiting for other photos to be
uploaded. The latest photos comes first.
I have slighlty changed the integration of colorbox in core. Now we have 2
styles available and by default, we use style2 (overlay in black, title and
control icons outside the popup). It is also used for zooming on bulk manager
in unit mode.
display change: on each uploading photos, instead of showing the transfer
speed, we display the transfer progression in %
bug fixed: the color of the "Start Upload" button was not correct because the
button was not a submit button but a simple type=button.
language: "Upload" button becomes "Start Upload" button.
git-svn-id: http://piwigo.org/svn/trunk@11962 68402e56-0260-453c-a942-63ccdbb3a9ee
2011-08-17 21:56:07 +02:00
|
|
|
if ($params['fullname'])
|
|
|
|
{
|
|
|
|
$row['name'] = strip_tags(get_cat_display_name_cache($row['uppercats'], null, false));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$row['name'] = strip_tags(
|
|
|
|
trigger_event(
|
|
|
|
'render_category_name',
|
|
|
|
$row['name'],
|
|
|
|
'ws_categories_getList'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2010-11-01 20:30:59 +01:00
|
|
|
$row['comment'] = strip_tags(
|
|
|
|
trigger_event(
|
|
|
|
'render_category_description',
|
|
|
|
$row['comment'],
|
|
|
|
'ws_categories_getList'
|
|
|
|
)
|
|
|
|
);
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2011-11-04 22:22:55 +01:00
|
|
|
// management of the album thumbnail -- starts here
|
2012-01-08 20:25:52 +01:00
|
|
|
//
|
2011-11-04 22:22:55 +01:00
|
|
|
// on branch 2.3, the algorithm is duplicated from
|
|
|
|
// include/category_cats, but we should use a common code for Piwigo 2.4
|
|
|
|
//
|
|
|
|
// warning : if the API method is called with $params['public'], the
|
|
|
|
// album thumbnail may be not accurate. The thumbnail can be viewed by
|
|
|
|
// the connected user, but maybe not by the guest. Changing the
|
|
|
|
// filtering method would be too complicated for now. We will simply
|
|
|
|
// avoid to persist the user_representative_picture_id in the database
|
|
|
|
// if $params['public']
|
|
|
|
if (!empty($row['user_representative_picture_id']))
|
|
|
|
{
|
|
|
|
$image_id = $row['user_representative_picture_id'];
|
|
|
|
}
|
|
|
|
else if (!empty($row['representative_picture_id']))
|
|
|
|
{ // if a representative picture is set, it has priority
|
|
|
|
$image_id = $row['representative_picture_id'];
|
|
|
|
}
|
|
|
|
else if ($conf['allow_random_representative'])
|
|
|
|
{
|
|
|
|
// searching a random representant among elements in sub-categories
|
|
|
|
$image_id = get_random_image_in_category($row);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // searching a random representant among representant of sub-categories
|
|
|
|
if ($row['count_categories']>0 and $row['count_images']>0)
|
|
|
|
{
|
|
|
|
$query = '
|
|
|
|
SELECT representative_picture_id
|
|
|
|
FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
|
|
|
|
ON id = cat_id and user_id = '.$user['id'].'
|
|
|
|
WHERE uppercats LIKE \''.$row['uppercats'].',%\'
|
|
|
|
AND representative_picture_id IS NOT NULL'
|
|
|
|
.get_sql_condition_FandF
|
|
|
|
(
|
|
|
|
array
|
|
|
|
(
|
|
|
|
'visible_categories' => 'id',
|
|
|
|
),
|
|
|
|
"\n AND"
|
|
|
|
).'
|
|
|
|
ORDER BY '.DB_RANDOM_FUNCTION.'()
|
|
|
|
LIMIT 1
|
|
|
|
;';
|
|
|
|
$subresult = pwg_query($query);
|
|
|
|
if (pwg_db_num_rows($subresult) > 0)
|
|
|
|
{
|
|
|
|
list($image_id) = pwg_db_fetch_row($subresult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-01-08 20:25:52 +01:00
|
|
|
|
2011-11-04 22:22:55 +01:00
|
|
|
if (isset($image_id))
|
|
|
|
{
|
|
|
|
if ($conf['representative_cache_on_subcats'] and $row['user_representative_picture_id'] != $image_id)
|
|
|
|
{
|
|
|
|
$user_representative_updates_for[ $user['id'].'#'.$row['id'] ] = $image_id;
|
|
|
|
}
|
2012-01-08 20:25:52 +01:00
|
|
|
|
2011-11-04 22:22:55 +01:00
|
|
|
$row['representative_picture_id'] = $image_id;
|
|
|
|
array_push($image_ids, $image_id);
|
|
|
|
array_push($categories, $row);
|
|
|
|
}
|
|
|
|
unset($image_id);
|
|
|
|
// management of the album thumbnail -- stops here
|
|
|
|
|
|
|
|
|
2007-01-06 12:13:08 +01:00
|
|
|
array_push($cats, $row);
|
|
|
|
}
|
|
|
|
usort($cats, 'global_rank_compare');
|
2011-05-31 22:25:40 +02:00
|
|
|
|
2011-11-04 22:22:55 +01:00
|
|
|
// management of the album thumbnail -- starts here
|
|
|
|
if (count($categories) > 0)
|
|
|
|
{
|
|
|
|
$thumbnail_src_of = array();
|
|
|
|
$new_image_ids = array();
|
|
|
|
|
|
|
|
$query = '
|
2011-12-27 06:26:44 +01:00
|
|
|
SELECT id, path, representative_ext, level
|
2011-11-04 22:22:55 +01:00
|
|
|
FROM '.IMAGES_TABLE.'
|
|
|
|
WHERE id IN ('.implode(',', $image_ids).')
|
|
|
|
;';
|
|
|
|
$result = pwg_query($query);
|
|
|
|
while ($row = pwg_db_fetch_assoc($result))
|
|
|
|
{
|
|
|
|
if ($row['level'] <= $user['level'])
|
|
|
|
{
|
2011-12-27 06:26:44 +01:00
|
|
|
$thumbnail_src_of[$row['id']] = DerivativeImage::thumb_url($row);
|
2011-11-04 22:22:55 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// problem: we must not display the thumbnail of a photo which has a
|
|
|
|
// higher privacy level than user privacy level
|
|
|
|
//
|
|
|
|
// * what is the represented category?
|
|
|
|
// * find a random photo matching user permissions
|
|
|
|
// * register it at user_representative_picture_id
|
|
|
|
// * set it as the representative_picture_id for the category
|
2012-01-08 20:25:52 +01:00
|
|
|
|
2011-11-04 22:22:55 +01:00
|
|
|
foreach ($categories as &$category)
|
|
|
|
{
|
|
|
|
if ($row['id'] == $category['representative_picture_id'])
|
|
|
|
{
|
|
|
|
// searching a random representant among elements in sub-categories
|
|
|
|
$image_id = get_random_image_in_category($category);
|
2012-01-08 20:25:52 +01:00
|
|
|
|
2011-11-04 22:22:55 +01:00
|
|
|
if (isset($image_id) and !in_array($image_id, $image_ids))
|
|
|
|
{
|
|
|
|
array_push($new_image_ids, $image_id);
|
|
|
|
}
|
2012-01-08 20:25:52 +01:00
|
|
|
|
2011-11-04 22:22:55 +01:00
|
|
|
if ($conf['representative_cache_on_level'])
|
|
|
|
{
|
|
|
|
$user_representative_updates_for[ $user['id'].'#'.$category['id'] ] = $image_id;
|
|
|
|
}
|
2012-01-08 20:25:52 +01:00
|
|
|
|
2011-11-04 22:22:55 +01:00
|
|
|
$category['representative_picture_id'] = $image_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unset($category);
|
|
|
|
}
|
|
|
|
}
|
2012-01-08 20:25:52 +01:00
|
|
|
|
2011-11-04 22:22:55 +01:00
|
|
|
if (count($new_image_ids) > 0)
|
|
|
|
{
|
|
|
|
$query = '
|
2011-12-27 06:26:44 +01:00
|
|
|
SELECT id, path, representative_ext
|
2011-11-04 22:22:55 +01:00
|
|
|
FROM '.IMAGES_TABLE.'
|
|
|
|
WHERE id IN ('.implode(',', $new_image_ids).')
|
|
|
|
;';
|
|
|
|
$result = pwg_query($query);
|
|
|
|
while ($row = pwg_db_fetch_assoc($result))
|
|
|
|
{
|
2011-12-27 06:26:44 +01:00
|
|
|
$thumbnail_src_of[$row['id']] = DerivativeImage::thumb_url($row);
|
2011-11-04 22:22:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// compared to code in include/category_cats, we only persist the new
|
|
|
|
// user_representative if we have used $user['id'] and not the guest id,
|
|
|
|
// or else the real guest may see thumbnail that he should not
|
|
|
|
if (!$params['public'] and count($user_representative_updates_for))
|
|
|
|
{
|
|
|
|
$updates = array();
|
2012-01-08 20:25:52 +01:00
|
|
|
|
2011-11-04 22:22:55 +01:00
|
|
|
foreach ($user_representative_updates_for as $user_cat => $image_id)
|
|
|
|
{
|
|
|
|
list($user_id, $cat_id) = explode('#', $user_cat);
|
2012-01-08 20:25:52 +01:00
|
|
|
|
2011-11-04 22:22:55 +01:00
|
|
|
array_push(
|
|
|
|
$updates,
|
|
|
|
array(
|
|
|
|
'user_id' => $user_id,
|
|
|
|
'cat_id' => $cat_id,
|
|
|
|
'user_representative_picture_id' => $image_id,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
mass_updates(
|
|
|
|
USER_CACHE_CATEGORIES_TABLE,
|
|
|
|
array(
|
|
|
|
'primary' => array('user_id', 'cat_id'),
|
|
|
|
'update' => array('user_representative_picture_id')
|
|
|
|
),
|
|
|
|
$updates
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($cats as &$cat)
|
|
|
|
{
|
|
|
|
foreach ($categories as $category)
|
|
|
|
{
|
2012-06-07 15:09:17 +02:00
|
|
|
if ($category['id'] == $cat['id'] and isset($category['representative_picture_id']))
|
2011-11-04 22:22:55 +01:00
|
|
|
{
|
|
|
|
$cat['tn_url'] = $thumbnail_src_of[$category['representative_picture_id']];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// we don't want them in the output
|
|
|
|
unset($cat['user_representative_picture_id']);
|
|
|
|
unset($cat['count_images']);
|
2011-11-04 22:27:18 +01:00
|
|
|
unset($cat['count_categories']);
|
2011-11-04 22:22:55 +01:00
|
|
|
}
|
2012-01-08 20:25:52 +01:00
|
|
|
unset($cat);
|
2011-11-04 22:22:55 +01:00
|
|
|
// management of the album thumbnail -- stops here
|
|
|
|
|
2011-05-31 22:25:40 +02:00
|
|
|
if ($params['tree_output'])
|
2011-08-02 21:20:50 +02:00
|
|
|
{
|
2011-05-31 22:25:40 +02:00
|
|
|
return categories_flatlist_to_tree($cats);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
'categories' => new PwgNamedArray(
|
|
|
|
$cats,
|
|
|
|
'category',
|
|
|
|
array(
|
|
|
|
'id',
|
|
|
|
'url',
|
|
|
|
'nb_images',
|
|
|
|
'total_nb_images',
|
|
|
|
'nb_categories',
|
|
|
|
'date_last',
|
|
|
|
'max_date_last',
|
|
|
|
)
|
2008-09-17 23:42:50 +02:00
|
|
|
)
|
2011-05-31 22:25:40 +02:00
|
|
|
);
|
|
|
|
}
|
2007-01-06 12:13:08 +01:00
|
|
|
}
|
|
|
|
|
2008-09-21 22:42:17 +02:00
|
|
|
/**
|
|
|
|
* returns the list of categories as you can see them in administration (web
|
|
|
|
* service method).
|
|
|
|
*
|
|
|
|
* Only admin can run this method and permissions are not taken into
|
|
|
|
* account.
|
|
|
|
*/
|
|
|
|
function ws_categories_getAdminList($params, &$service)
|
|
|
|
{
|
|
|
|
if (!is_admin())
|
|
|
|
{
|
|
|
|
return new PwgError(401, 'Access denied');
|
|
|
|
}
|
|
|
|
|
|
|
|
$query = '
|
|
|
|
SELECT
|
|
|
|
category_id,
|
|
|
|
COUNT(*) AS counter
|
|
|
|
FROM '.IMAGE_CATEGORY_TABLE.'
|
|
|
|
GROUP BY category_id
|
|
|
|
;';
|
|
|
|
$nb_images_of = simple_hash_from_query($query, 'category_id', 'counter');
|
|
|
|
|
|
|
|
$query = '
|
|
|
|
SELECT
|
|
|
|
id,
|
|
|
|
name,
|
2010-11-01 20:30:59 +01:00
|
|
|
comment,
|
2008-09-21 22:42:17 +02:00
|
|
|
uppercats,
|
|
|
|
global_rank
|
|
|
|
FROM '.CATEGORIES_TABLE.'
|
|
|
|
;';
|
|
|
|
$result = pwg_query($query);
|
|
|
|
$cats = array();
|
|
|
|
|
2009-11-20 15:17:04 +01:00
|
|
|
while ($row = pwg_db_fetch_assoc($result))
|
2008-09-21 22:42:17 +02:00
|
|
|
{
|
|
|
|
$id = $row['id'];
|
|
|
|
$row['nb_images'] = isset($nb_images_of[$id]) ? $nb_images_of[$id] : 0;
|
2010-02-17 17:15:56 +01:00
|
|
|
$row['name'] = strip_tags(
|
|
|
|
trigger_event(
|
|
|
|
'render_category_name',
|
|
|
|
$row['name'],
|
|
|
|
'ws_categories_getAdminList'
|
|
|
|
)
|
|
|
|
);
|
2010-11-01 20:30:59 +01:00
|
|
|
$row['comment'] = strip_tags(
|
|
|
|
trigger_event(
|
|
|
|
'render_category_description',
|
|
|
|
$row['comment'],
|
|
|
|
'ws_categories_getAdminList'
|
|
|
|
)
|
|
|
|
);
|
2008-09-21 22:42:17 +02:00
|
|
|
array_push($cats, $row);
|
2008-09-25 02:30:42 +02:00
|
|
|
}
|
|
|
|
|
2008-09-21 22:42:17 +02:00
|
|
|
usort($cats, 'global_rank_compare');
|
|
|
|
return array(
|
|
|
|
'categories' => new PwgNamedArray(
|
|
|
|
$cats,
|
|
|
|
'category',
|
|
|
|
array(
|
|
|
|
'id',
|
|
|
|
'nb_images',
|
|
|
|
'name',
|
|
|
|
'uppercats',
|
|
|
|
'global_rank',
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2007-02-06 02:02:06 +01:00
|
|
|
|
2007-02-22 02:12:32 +01:00
|
|
|
/**
|
|
|
|
* returns detailed information for an element (web service method)
|
|
|
|
*/
|
|
|
|
function ws_images_addComment($params, &$service)
|
|
|
|
{
|
2007-02-23 14:18:34 +01:00
|
|
|
if (!$service->isPost())
|
|
|
|
{
|
|
|
|
return new PwgError(405, "This method requires HTTP POST");
|
|
|
|
}
|
2007-02-22 02:12:32 +01:00
|
|
|
$params['image_id'] = (int)$params['image_id'];
|
|
|
|
$query = '
|
2007-10-04 01:36:21 +02:00
|
|
|
SELECT DISTINCT image_id
|
2007-02-22 02:12:32 +01:00
|
|
|
FROM '.IMAGE_CATEGORY_TABLE.' INNER JOIN '.CATEGORIES_TABLE.' ON category_id=id
|
2007-10-04 01:36:21 +02:00
|
|
|
WHERE commentable="true"
|
2007-02-22 02:12:32 +01:00
|
|
|
AND image_id='.$params['image_id'].
|
|
|
|
get_sql_condition_FandF(
|
|
|
|
array(
|
|
|
|
'forbidden_categories' => 'id',
|
|
|
|
'visible_categories' => 'id',
|
|
|
|
'visible_images' => 'image_id'
|
|
|
|
),
|
|
|
|
' AND'
|
|
|
|
);
|
2009-11-20 15:17:04 +01:00
|
|
|
if ( !pwg_db_num_rows( pwg_query( $query ) ) )
|
2007-02-22 02:12:32 +01:00
|
|
|
{
|
|
|
|
return new PwgError(WS_ERR_INVALID_PARAM, "Invalid image_id");
|
|
|
|
}
|
2007-10-04 01:36:21 +02:00
|
|
|
|
2007-02-22 02:12:32 +01:00
|
|
|
$comm = array(
|
2010-06-01 21:52:44 +02:00
|
|
|
'author' => trim( $params['author'] ),
|
|
|
|
'content' => trim( $params['content'] ),
|
2007-02-22 02:12:32 +01:00
|
|
|
'image_id' => $params['image_id'],
|
|
|
|
);
|
|
|
|
|
|
|
|
include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
|
2007-10-04 01:36:21 +02:00
|
|
|
|
|
|
|
$comment_action = insert_user_comment(
|
2007-02-22 02:12:32 +01:00
|
|
|
$comm, $params['key'], $infos
|
|
|
|
);
|
|
|
|
|
|
|
|
switch ($comment_action)
|
|
|
|
{
|
|
|
|
case 'reject':
|
2010-03-02 15:54:22 +01:00
|
|
|
array_push($infos, l10n('Your comment has NOT been registered because it did not pass the validation rules') );
|
2010-11-15 10:48:47 +01:00
|
|
|
return new PwgError(403, implode("; ", $infos) );
|
2007-02-22 02:12:32 +01:00
|
|
|
case 'validate':
|
|
|
|
case 'moderate':
|
2007-10-04 01:36:21 +02:00
|
|
|
$ret = array(
|
2007-02-22 02:12:32 +01:00
|
|
|
'id' => $comm['id'],
|
|
|
|
'validation' => $comment_action=='validate',
|
|
|
|
);
|
|
|
|
return new PwgNamedStruct(
|
|
|
|
'comment',
|
2007-10-04 01:36:21 +02:00
|
|
|
$ret,
|
|
|
|
null, array()
|
2007-02-22 02:12:32 +01:00
|
|
|
);
|
|
|
|
default:
|
|
|
|
return new PwgError(500, "Unknown comment action ".$comment_action );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-06 02:02:06 +01:00
|
|
|
/**
|
|
|
|
* returns detailed information for an element (web service method)
|
|
|
|
*/
|
2007-01-06 12:13:08 +01:00
|
|
|
function ws_images_getInfo($params, &$service)
|
|
|
|
{
|
2007-02-22 02:12:32 +01:00
|
|
|
global $user, $conf;
|
2007-01-06 12:13:08 +01:00
|
|
|
$params['image_id'] = (int)$params['image_id'];
|
|
|
|
if ( $params['image_id']<=0 )
|
|
|
|
{
|
|
|
|
return new PwgError(WS_ERR_INVALID_PARAM, "Invalid image_id");
|
|
|
|
}
|
2007-02-06 02:02:06 +01:00
|
|
|
|
2007-01-06 12:13:08 +01:00
|
|
|
$query='
|
|
|
|
SELECT * FROM '.IMAGES_TABLE.'
|
2007-01-11 06:10:16 +01:00
|
|
|
WHERE id='.$params['image_id'].
|
|
|
|
get_sql_condition_FandF(
|
|
|
|
array('visible_images' => 'id'),
|
|
|
|
' AND'
|
2008-09-11 03:20:25 +02:00
|
|
|
).'
|
|
|
|
LIMIT 1';
|
2007-01-11 06:10:16 +01:00
|
|
|
|
2009-11-20 15:17:04 +01:00
|
|
|
$image_row = pwg_db_fetch_assoc(pwg_query($query));
|
2007-01-06 12:13:08 +01:00
|
|
|
if ($image_row==null)
|
|
|
|
{
|
2007-02-23 14:18:34 +01:00
|
|
|
return new PwgError(404, "image_id not found");
|
2007-01-06 12:13:08 +01:00
|
|
|
}
|
2007-02-21 01:20:02 +01:00
|
|
|
$image_row = array_merge( $image_row, ws_std_get_urls($image_row) );
|
2007-01-06 12:13:08 +01:00
|
|
|
|
|
|
|
//-------------------------------------------------------- related categories
|
|
|
|
$query = '
|
2007-02-28 04:07:12 +01:00
|
|
|
SELECT id, name, permalink, uppercats, global_rank, commentable
|
2007-01-06 12:13:08 +01:00
|
|
|
FROM '.IMAGE_CATEGORY_TABLE.'
|
2007-02-22 02:12:32 +01:00
|
|
|
INNER JOIN '.CATEGORIES_TABLE.' ON category_id = id
|
2007-10-04 01:36:21 +02:00
|
|
|
WHERE image_id = '.$image_row['id'].
|
|
|
|
get_sql_condition_FandF(
|
|
|
|
array( 'forbidden_categories' => 'category_id' ),
|
|
|
|
' AND'
|
|
|
|
).'
|
2007-01-06 12:13:08 +01:00
|
|
|
;';
|
|
|
|
$result = pwg_query($query);
|
2007-02-22 02:12:32 +01:00
|
|
|
$is_commentable = false;
|
2007-01-06 12:13:08 +01:00
|
|
|
$related_categories = array();
|
2009-11-20 15:17:04 +01:00
|
|
|
while ($row = pwg_db_fetch_assoc($result))
|
2007-01-06 12:13:08 +01:00
|
|
|
{
|
2007-02-22 02:12:32 +01:00
|
|
|
if ($row['commentable']=='true')
|
|
|
|
{
|
|
|
|
$is_commentable = true;
|
|
|
|
}
|
|
|
|
unset($row['commentable']);
|
2007-01-06 12:13:08 +01:00
|
|
|
$row['url'] = make_index_url(
|
|
|
|
array(
|
2007-02-27 02:56:16 +01:00
|
|
|
'category' => $row
|
2007-01-06 12:13:08 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$row['page_url'] = make_picture_url(
|
|
|
|
array(
|
|
|
|
'image_id' => $image_row['id'],
|
|
|
|
'image_file' => $image_row['file'],
|
2007-02-27 02:56:16 +01:00
|
|
|
'category' => $row
|
2007-01-06 12:13:08 +01:00
|
|
|
)
|
|
|
|
);
|
2007-02-22 02:12:32 +01:00
|
|
|
$row['id']=(int)$row['id'];
|
2007-01-06 12:13:08 +01:00
|
|
|
array_push($related_categories, $row);
|
|
|
|
}
|
|
|
|
usort($related_categories, 'global_rank_compare');
|
|
|
|
if ( empty($related_categories) )
|
|
|
|
{
|
|
|
|
return new PwgError(401, 'Access denied');
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------------------------------------------- related tags
|
2007-02-14 02:37:38 +01:00
|
|
|
$related_tags = get_common_tags( array($image_row['id']), -1 );
|
|
|
|
foreach( $related_tags as $i=>$tag)
|
2007-01-06 12:13:08 +01:00
|
|
|
{
|
2007-02-14 02:37:38 +01:00
|
|
|
$tag['url'] = make_index_url(
|
2007-01-06 12:13:08 +01:00
|
|
|
array(
|
2007-02-14 02:37:38 +01:00
|
|
|
'tags' => array($tag)
|
2007-01-06 12:13:08 +01:00
|
|
|
)
|
|
|
|
);
|
2007-02-14 02:37:38 +01:00
|
|
|
$tag['page_url'] = make_picture_url(
|
2007-01-06 12:13:08 +01:00
|
|
|
array(
|
|
|
|
'image_id' => $image_row['id'],
|
|
|
|
'image_file' => $image_row['file'],
|
2007-02-14 02:37:38 +01:00
|
|
|
'tags' => array($tag),
|
2007-01-06 12:13:08 +01:00
|
|
|
)
|
|
|
|
);
|
2007-02-14 02:37:38 +01:00
|
|
|
unset($tag['counter']);
|
2007-02-22 02:12:32 +01:00
|
|
|
$tag['id']=(int)$tag['id'];
|
2007-02-14 02:37:38 +01:00
|
|
|
$related_tags[$i]=$tag;
|
2007-01-06 12:13:08 +01:00
|
|
|
}
|
2007-02-22 02:12:32 +01:00
|
|
|
//------------------------------------------------------------- related rates
|
2011-08-02 21:20:50 +02:00
|
|
|
$rating = array('score'=>$image_row['rating_score'], 'count'=>0, 'average'=>null);
|
2011-07-25 20:04:50 +02:00
|
|
|
if (isset($rating['score']))
|
|
|
|
{
|
|
|
|
$query = '
|
2007-02-22 02:12:32 +01:00
|
|
|
SELECT COUNT(rate) AS count
|
|
|
|
, ROUND(AVG(rate),2) AS average
|
|
|
|
FROM '.RATE_TABLE.'
|
|
|
|
WHERE element_id = '.$image_row['id'].'
|
|
|
|
;';
|
2011-07-25 20:04:50 +02:00
|
|
|
$row = pwg_db_fetch_assoc(pwg_query($query));
|
|
|
|
$rating['score'] = (float)$rating['score'];
|
|
|
|
$rating['average'] = (float)$row['average'];
|
|
|
|
$rating['count'] = (int)$row['count'];
|
|
|
|
}
|
2007-02-22 02:12:32 +01:00
|
|
|
|
2007-01-06 12:13:08 +01:00
|
|
|
//---------------------------------------------------------- related comments
|
2007-02-22 02:12:32 +01:00
|
|
|
$related_comments = array();
|
2007-10-04 01:36:21 +02:00
|
|
|
|
2007-02-22 02:12:32 +01:00
|
|
|
$where_comments = 'image_id = '.$image_row['id'];
|
|
|
|
if ( !is_admin() )
|
|
|
|
{
|
|
|
|
$where_comments .= '
|
|
|
|
AND validated="true"';
|
|
|
|
}
|
|
|
|
|
2007-01-06 12:13:08 +01:00
|
|
|
$query = '
|
2010-07-03 14:12:25 +02:00
|
|
|
SELECT COUNT(id) AS nb_comments
|
2007-01-06 12:13:08 +01:00
|
|
|
FROM '.COMMENTS_TABLE.'
|
2007-02-22 02:12:32 +01:00
|
|
|
WHERE '.$where_comments;
|
2007-01-06 12:13:08 +01:00
|
|
|
list($nb_comments) = array_from_query($query, 'nb_comments');
|
2007-02-22 02:12:32 +01:00
|
|
|
$nb_comments = (int)$nb_comments;
|
2007-01-06 12:13:08 +01:00
|
|
|
|
2007-02-22 02:12:32 +01:00
|
|
|
if ( $nb_comments>0 and $params['comments_per_page']>0 )
|
|
|
|
{
|
|
|
|
$query = '
|
2007-01-06 12:13:08 +01:00
|
|
|
SELECT id, date, author, content
|
|
|
|
FROM '.COMMENTS_TABLE.'
|
2007-02-22 02:12:32 +01:00
|
|
|
WHERE '.$where_comments.'
|
|
|
|
ORDER BY date
|
2009-11-21 20:52:50 +01:00
|
|
|
LIMIT '.(int)$params['comments_per_page'].
|
|
|
|
' OFFSET '.(int)($params['comments_per_page']*$params['comments_page']);
|
2007-01-06 12:13:08 +01:00
|
|
|
|
2007-02-22 02:12:32 +01:00
|
|
|
$result = pwg_query($query);
|
2009-11-20 15:17:04 +01:00
|
|
|
while ($row = pwg_db_fetch_assoc($result))
|
2007-02-22 02:12:32 +01:00
|
|
|
{
|
|
|
|
$row['id']=(int)$row['id'];
|
|
|
|
array_push($related_comments, $row);
|
|
|
|
}
|
|
|
|
}
|
2007-10-04 01:36:21 +02:00
|
|
|
|
2007-02-22 02:12:32 +01:00
|
|
|
$comment_post_data = null;
|
2007-10-04 01:36:21 +02:00
|
|
|
if ($is_commentable and
|
2007-06-06 00:01:15 +02:00
|
|
|
(!is_a_guest()
|
|
|
|
or (is_a_guest() and $conf['comments_forall'] )
|
2007-02-22 02:12:32 +01:00
|
|
|
)
|
|
|
|
)
|
2007-01-06 12:13:08 +01:00
|
|
|
{
|
2009-11-18 21:07:20 +01:00
|
|
|
$comment_post_data['author'] = stripslashes($user['username']);
|
2010-10-30 13:32:11 +02:00
|
|
|
$comment_post_data['key'] = get_ephemeral_key(2, $params['image_id']);
|
2007-01-06 12:13:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$ret = $image_row;
|
2007-02-22 02:12:32 +01:00
|
|
|
foreach ( array('id','width','height','hit','filesize') as $k )
|
|
|
|
{
|
|
|
|
if (isset($ret[$k]))
|
|
|
|
{
|
|
|
|
$ret[$k] = (int)$ret[$k];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach ( array('path', 'storage_category_id') as $k )
|
|
|
|
{
|
|
|
|
unset($ret[$k]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$ret['rates'] = array( WS_XML_ATTRIBUTES => $rating );
|
2007-01-06 12:13:08 +01:00
|
|
|
$ret['categories'] = new PwgNamedArray($related_categories, 'category', array('id','url', 'page_url') );
|
2008-09-25 02:30:42 +02:00
|
|
|
$ret['tags'] = new PwgNamedArray($related_tags, 'tag', array('id','url_name','url','name','page_url') );
|
2007-02-22 02:12:32 +01:00
|
|
|
if ( isset($comment_post_data) )
|
|
|
|
{
|
|
|
|
$ret['comment_post'] = array( WS_XML_ATTRIBUTES => $comment_post_data );
|
|
|
|
}
|
2007-01-06 12:13:08 +01:00
|
|
|
$ret['comments'] = array(
|
2007-10-04 01:36:21 +02:00
|
|
|
WS_XML_ATTRIBUTES =>
|
2007-02-22 02:12:32 +01:00
|
|
|
array(
|
|
|
|
'page' => $params['comments_page'],
|
|
|
|
'per_page' => $params['comments_per_page'],
|
|
|
|
'count' => count($related_comments),
|
|
|
|
'nb_comments' => $nb_comments,
|
|
|
|
),
|
|
|
|
WS_XML_CONTENT => new PwgNamedArray($related_comments, 'comment', array('id','date') )
|
2007-01-06 12:13:08 +01:00
|
|
|
);
|
2007-02-21 01:20:02 +01:00
|
|
|
|
2007-01-06 12:13:08 +01:00
|
|
|
return new PwgNamedStruct('image',$ret, null, array('name','comment') );
|
|
|
|
}
|
|
|
|
|
2008-07-15 03:29:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* rates the image_id in the parameter
|
|
|
|
*/
|
|
|
|
function ws_images_Rate($params, &$service)
|
|
|
|
{
|
|
|
|
$image_id = (int)$params['image_id'];
|
|
|
|
$query = '
|
|
|
|
SELECT DISTINCT id FROM '.IMAGES_TABLE.'
|
|
|
|
INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id=image_id
|
|
|
|
WHERE id='.$image_id
|
|
|
|
.get_sql_condition_FandF(
|
|
|
|
array(
|
|
|
|
'forbidden_categories' => 'category_id',
|
|
|
|
'forbidden_images' => 'id',
|
|
|
|
),
|
|
|
|
' AND'
|
|
|
|
).'
|
|
|
|
LIMIT 1';
|
2009-11-20 15:17:04 +01:00
|
|
|
if ( pwg_db_num_rows( pwg_query($query) )==0 )
|
2008-07-15 03:29:23 +02:00
|
|
|
{
|
|
|
|
return new PwgError(404, "Invalid image_id or access denied" );
|
|
|
|
}
|
|
|
|
$rate = (int)$params['rate'];
|
|
|
|
include_once(PHPWG_ROOT_PATH.'include/functions_rate.inc.php');
|
|
|
|
$res = rate_picture( $image_id, $rate );
|
|
|
|
if ($res==false)
|
|
|
|
{
|
|
|
|
global $conf;
|
|
|
|
return new PwgError( 403, "Forbidden or rate not in ". implode(',',$conf['rate_items']));
|
|
|
|
}
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-19 17:25:47 +01:00
|
|
|
/**
|
|
|
|
* returns a list of elements corresponding to a query search
|
|
|
|
*/
|
|
|
|
function ws_images_search($params, &$service)
|
|
|
|
{
|
|
|
|
global $page;
|
|
|
|
$images = array();
|
|
|
|
include_once( PHPWG_ROOT_PATH .'include/functions_search.inc.php' );
|
|
|
|
|
2007-10-12 05:27:34 +02:00
|
|
|
$where_clauses = ws_std_image_sql_filter( $params, 'i.' );
|
|
|
|
$order_by = ws_std_image_sql_order($params, 'i.');
|
2007-02-19 17:25:47 +01:00
|
|
|
|
2008-07-23 02:56:22 +02:00
|
|
|
$super_order_by = false;
|
2007-10-12 05:27:34 +02:00
|
|
|
if ( !empty($order_by) )
|
2007-02-19 17:25:47 +01:00
|
|
|
{
|
2007-10-12 05:27:34 +02:00
|
|
|
global $conf;
|
|
|
|
$conf['order_by'] = 'ORDER BY '.$order_by;
|
2008-07-23 02:56:22 +02:00
|
|
|
$super_order_by=true; // quick_search_result might be faster
|
2007-02-19 17:25:47 +01:00
|
|
|
}
|
2007-10-12 05:27:34 +02:00
|
|
|
|
|
|
|
$search_result = get_quick_search_results($params['query'],
|
2008-07-23 02:56:22 +02:00
|
|
|
$super_order_by,
|
|
|
|
implode(',', $where_clauses)
|
|
|
|
);
|
2007-10-04 01:36:21 +02:00
|
|
|
|
2008-07-23 02:56:22 +02:00
|
|
|
$image_ids = array_slice(
|
|
|
|
$search_result['items'],
|
|
|
|
$params['page']*$params['per_page'],
|
|
|
|
$params['per_page']
|
|
|
|
);
|
2007-02-19 17:25:47 +01:00
|
|
|
|
|
|
|
if ( count($image_ids) )
|
|
|
|
{
|
|
|
|
$query = '
|
|
|
|
SELECT * FROM '.IMAGES_TABLE.'
|
2008-07-23 02:56:22 +02:00
|
|
|
WHERE id IN ('.implode(',', $image_ids).')';
|
2007-02-19 17:25:47 +01:00
|
|
|
|
2008-07-23 02:56:22 +02:00
|
|
|
$image_ids = array_flip($image_ids);
|
2007-02-19 17:25:47 +01:00
|
|
|
$result = pwg_query($query);
|
2009-11-20 15:17:04 +01:00
|
|
|
while ($row = pwg_db_fetch_assoc($result))
|
2007-02-19 17:25:47 +01:00
|
|
|
{
|
|
|
|
$image = array();
|
|
|
|
foreach ( array('id', 'width', 'height', 'hit') as $k )
|
|
|
|
{
|
|
|
|
if (isset($row[$k]))
|
|
|
|
{
|
|
|
|
$image[$k] = (int)$row[$k];
|
|
|
|
}
|
|
|
|
}
|
2011-05-30 23:32:10 +02:00
|
|
|
foreach ( array('file', 'name', 'comment', 'date_creation', 'date_available') as $k )
|
2007-02-19 17:25:47 +01:00
|
|
|
{
|
|
|
|
$image[$k] = $row[$k];
|
|
|
|
}
|
|
|
|
$image = array_merge( $image, ws_std_get_urls($row) );
|
2008-07-23 02:56:22 +02:00
|
|
|
$images[$image_ids[$image['id']]] = $image;
|
2007-02-19 17:25:47 +01:00
|
|
|
}
|
2008-07-23 02:56:22 +02:00
|
|
|
ksort($images, SORT_NUMERIC);
|
|
|
|
$images = array_values($images);
|
2007-02-19 17:25:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return array( 'images' =>
|
|
|
|
array (
|
|
|
|
WS_XML_ATTRIBUTES =>
|
|
|
|
array(
|
|
|
|
'page' => $params['page'],
|
|
|
|
'per_page' => $params['per_page'],
|
|
|
|
'count' => count($images)
|
|
|
|
),
|
|
|
|
WS_XML_CONTENT => new PwgNamedArray($images, 'image',
|
2007-02-21 01:20:02 +01:00
|
|
|
ws_std_get_image_xml_attributes() )
|
2007-02-19 17:25:47 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2007-01-06 12:13:08 +01:00
|
|
|
|
2008-07-02 03:11:26 +02:00
|
|
|
function ws_images_setPrivacyLevel($params, &$service)
|
|
|
|
{
|
2010-12-14 14:47:24 +01:00
|
|
|
if (!is_admin())
|
2008-07-02 03:11:26 +02:00
|
|
|
{
|
|
|
|
return new PwgError(401, 'Access denied');
|
|
|
|
}
|
2009-12-18 22:12:41 +01:00
|
|
|
if (!$service->isPost())
|
|
|
|
{
|
|
|
|
return new PwgError(405, "This method requires HTTP POST");
|
|
|
|
}
|
2008-10-18 02:45:45 +02:00
|
|
|
$params['image_id'] = array_map( 'intval',$params['image_id'] );
|
2008-07-02 03:11:26 +02:00
|
|
|
if ( empty($params['image_id']) )
|
|
|
|
{
|
|
|
|
return new PwgError(WS_ERR_INVALID_PARAM, "Invalid image_id");
|
|
|
|
}
|
|
|
|
global $conf;
|
|
|
|
if ( !in_array( (int)$params['level'], $conf['available_permission_levels']) )
|
|
|
|
{
|
|
|
|
return new PwgError(WS_ERR_INVALID_PARAM, "Invalid level");
|
|
|
|
}
|
2009-12-18 22:12:41 +01:00
|
|
|
|
2008-07-02 03:11:26 +02:00
|
|
|
$query = '
|
|
|
|
UPDATE '.IMAGES_TABLE.'
|
|
|
|
SET level='.(int)$params['level'].'
|
|
|
|
WHERE id IN ('.implode(',',$params['image_id']).')';
|
|
|
|
$result = pwg_query($query);
|
2010-04-20 23:08:48 +02:00
|
|
|
$affected_rows = pwg_db_changes($result);
|
2008-07-02 03:11:26 +02:00
|
|
|
if ($affected_rows)
|
|
|
|
{
|
|
|
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
|
|
|
invalidate_user_cache();
|
|
|
|
}
|
|
|
|
return $affected_rows;
|
|
|
|
}
|
|
|
|
|
2011-06-14 15:54:05 +02:00
|
|
|
function ws_images_setRank($params, &$service)
|
|
|
|
{
|
|
|
|
if (!is_admin())
|
|
|
|
{
|
|
|
|
return new PwgError(401, 'Access denied');
|
|
|
|
}
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2011-06-14 15:54:05 +02:00
|
|
|
if (!$service->isPost())
|
|
|
|
{
|
|
|
|
return new PwgError(405, "This method requires HTTP POST");
|
|
|
|
}
|
|
|
|
|
|
|
|
// is the image_id valid?
|
|
|
|
$params['image_id'] = (int)$params['image_id'];
|
|
|
|
if ($params['image_id'] <= 0)
|
|
|
|
{
|
|
|
|
return new PwgError(WS_ERR_INVALID_PARAM, "Invalid image_id");
|
|
|
|
}
|
|
|
|
|
|
|
|
// is the category valid?
|
|
|
|
$params['category_id'] = (int)$params['category_id'];
|
|
|
|
if ($params['category_id'] <= 0)
|
|
|
|
{
|
|
|
|
return new PwgError(WS_ERR_INVALID_PARAM, "Invalid category_id");
|
|
|
|
}
|
|
|
|
|
|
|
|
// is the rank valid?
|
|
|
|
$params['rank'] = (int)$params['rank'];
|
|
|
|
if ($params['rank'] <= 0)
|
|
|
|
{
|
|
|
|
return new PwgError(WS_ERR_INVALID_PARAM, "Invalid rank");
|
|
|
|
}
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2011-06-14 15:54:05 +02:00
|
|
|
// does the image really exist?
|
|
|
|
$query='
|
|
|
|
SELECT
|
|
|
|
*
|
|
|
|
FROM '.IMAGES_TABLE.'
|
|
|
|
WHERE id = '.$params['image_id'].'
|
|
|
|
;';
|
|
|
|
|
|
|
|
$image_row = pwg_db_fetch_assoc(pwg_query($query));
|
|
|
|
if ($image_row == null)
|
|
|
|
{
|
|
|
|
return new PwgError(404, "image_id not found");
|
|
|
|
}
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2011-06-14 15:54:05 +02:00
|
|
|
// is the image associated to this category?
|
|
|
|
$query = '
|
|
|
|
SELECT
|
|
|
|
image_id,
|
|
|
|
category_id,
|
|
|
|
rank
|
|
|
|
FROM '.IMAGE_CATEGORY_TABLE.'
|
|
|
|
WHERE image_id = '.$params['image_id'].'
|
|
|
|
AND category_id = '.$params['category_id'].'
|
|
|
|
;';
|
|
|
|
$category_row = pwg_db_fetch_assoc(pwg_query($query));
|
|
|
|
if ($category_row == null)
|
|
|
|
{
|
|
|
|
return new PwgError(404, "This image is not associated to this category");
|
|
|
|
}
|
|
|
|
|
|
|
|
// what is the current higher rank for this category?
|
|
|
|
$query = '
|
|
|
|
SELECT
|
|
|
|
MAX(rank) AS max_rank
|
|
|
|
FROM '.IMAGE_CATEGORY_TABLE.'
|
|
|
|
WHERE category_id = '.$params['category_id'].'
|
|
|
|
;';
|
|
|
|
$result = pwg_query($query);
|
|
|
|
$row = pwg_db_fetch_assoc($result);
|
|
|
|
|
|
|
|
if (is_numeric($row['max_rank']))
|
|
|
|
{
|
|
|
|
if ($params['rank'] > $row['max_rank'])
|
|
|
|
{
|
|
|
|
$params['rank'] = $row['max_rank'] + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$params['rank'] = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// update rank for all other photos in the same category
|
|
|
|
$query = '
|
|
|
|
UPDATE '.IMAGE_CATEGORY_TABLE.'
|
|
|
|
SET rank = rank + 1
|
|
|
|
WHERE category_id = '.$params['category_id'].'
|
|
|
|
AND rank IS NOT NULL
|
|
|
|
AND rank >= '.$params['rank'].'
|
|
|
|
;';
|
|
|
|
pwg_query($query);
|
|
|
|
|
|
|
|
// set the new rank for the photo
|
|
|
|
$query = '
|
|
|
|
UPDATE '.IMAGE_CATEGORY_TABLE.'
|
|
|
|
SET rank = '.$params['rank'].'
|
|
|
|
WHERE image_id = '.$params['image_id'].'
|
|
|
|
AND category_id = '.$params['category_id'].'
|
|
|
|
;';
|
|
|
|
pwg_query($query);
|
|
|
|
|
|
|
|
// return data for client
|
|
|
|
return array(
|
|
|
|
'image_id' => $params['image_id'],
|
|
|
|
'category_id' => $params['category_id'],
|
|
|
|
'rank' => $params['rank'],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2009-03-13 00:14:50 +01:00
|
|
|
function ws_images_add_chunk($params, &$service)
|
|
|
|
{
|
2010-03-01 17:22:34 +01:00
|
|
|
global $conf;
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2009-03-13 00:14:50 +01:00
|
|
|
// data
|
|
|
|
// original_sum
|
|
|
|
// type {thumb, file, high}
|
|
|
|
// position
|
2009-07-01 22:56:41 +02:00
|
|
|
|
2010-12-14 14:47:24 +01:00
|
|
|
if (!is_admin())
|
2009-03-13 00:14:50 +01:00
|
|
|
{
|
|
|
|
return new PwgError(401, 'Access denied');
|
|
|
|
}
|
|
|
|
|
2009-12-18 01:45:03 +01:00
|
|
|
if (!$service->isPost())
|
|
|
|
{
|
|
|
|
return new PwgError(405, "This method requires HTTP POST");
|
|
|
|
}
|
|
|
|
|
2010-02-17 16:09:44 +01:00
|
|
|
foreach ($params as $param_key => $param_value) {
|
|
|
|
if ('data' == $param_key) {
|
|
|
|
continue;
|
|
|
|
}
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2010-02-17 16:09:44 +01:00
|
|
|
ws_logfile(
|
|
|
|
sprintf(
|
|
|
|
'[ws_images_add_chunk] input param "%s" : "%s"',
|
|
|
|
$param_key,
|
|
|
|
is_null($param_value) ? 'NULL' : $param_value
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2010-03-01 17:22:34 +01:00
|
|
|
$upload_dir = $conf['upload_dir'].'/buffer';
|
2009-03-13 00:14:50 +01:00
|
|
|
|
|
|
|
// create the upload directory tree if not exists
|
2012-08-30 21:20:00 +02:00
|
|
|
if (!mkgetdir($upload_dir, MKGETDIR_DEFAULT&~MKGETDIR_DIE_ON_ERROR))
|
2009-03-13 00:14:50 +01:00
|
|
|
{
|
2012-08-30 21:20:00 +02:00
|
|
|
return new PwgError(500, 'error during buffer directory creation');
|
2009-03-13 00:14:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$filename = sprintf(
|
|
|
|
'%s-%s-%05u.block',
|
|
|
|
$params['original_sum'],
|
|
|
|
$params['type'],
|
|
|
|
$params['position']
|
|
|
|
);
|
|
|
|
|
2009-04-15 00:54:39 +02:00
|
|
|
ws_logfile('[ws_images_add_chunk] data length : '.strlen($params['data']));
|
|
|
|
|
2009-03-13 00:14:50 +01:00
|
|
|
$bytes_written = file_put_contents(
|
|
|
|
$upload_dir.'/'.$filename,
|
2009-04-15 00:54:39 +02:00
|
|
|
base64_decode($params['data'])
|
2009-03-13 00:14:50 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
if (false === $bytes_written) {
|
|
|
|
return new PwgError(
|
|
|
|
500,
|
|
|
|
'an error has occured while writting chunk '.$params['position'].' for '.$params['type']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function merge_chunks($output_filepath, $original_sum, $type)
|
|
|
|
{
|
2010-03-01 17:22:34 +01:00
|
|
|
global $conf;
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2009-03-13 00:14:50 +01:00
|
|
|
ws_logfile('[merge_chunks] input parameter $output_filepath : '.$output_filepath);
|
|
|
|
|
2009-11-23 00:59:14 +01:00
|
|
|
if (is_file($output_filepath))
|
|
|
|
{
|
|
|
|
unlink($output_filepath);
|
2009-12-18 22:12:41 +01:00
|
|
|
|
2009-11-23 00:59:14 +01:00
|
|
|
if (is_file($output_filepath))
|
|
|
|
{
|
2011-12-27 06:26:44 +01:00
|
|
|
return new PwgError(500, '[merge_chunks] error while trying to remove existing '.$output_filepath);
|
2009-11-23 00:59:14 +01:00
|
|
|
}
|
|
|
|
}
|
2009-12-18 22:12:41 +01:00
|
|
|
|
2010-03-01 17:22:34 +01:00
|
|
|
$upload_dir = $conf['upload_dir'].'/buffer';
|
2009-03-13 00:14:50 +01:00
|
|
|
$pattern = '/'.$original_sum.'-'.$type.'/';
|
|
|
|
$chunks = array();
|
2009-07-01 22:56:41 +02:00
|
|
|
|
2009-03-13 00:14:50 +01:00
|
|
|
if ($handle = opendir($upload_dir))
|
|
|
|
{
|
|
|
|
while (false !== ($file = readdir($handle)))
|
|
|
|
{
|
|
|
|
if (preg_match($pattern, $file))
|
|
|
|
{
|
|
|
|
ws_logfile($file);
|
|
|
|
array_push($chunks, $upload_dir.'/'.$file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir($handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
sort($chunks);
|
2009-04-15 00:54:39 +02:00
|
|
|
|
2009-12-04 22:57:50 +01:00
|
|
|
if (function_exists('memory_get_usage')) {
|
|
|
|
ws_logfile('[merge_chunks] memory_get_usage before loading chunks: '.memory_get_usage());
|
|
|
|
}
|
2009-07-01 22:56:41 +02:00
|
|
|
|
2009-07-04 01:03:30 +02:00
|
|
|
$i = 0;
|
2009-12-18 22:12:41 +01:00
|
|
|
|
2009-04-15 00:54:39 +02:00
|
|
|
foreach ($chunks as $chunk)
|
2009-03-13 00:14:50 +01:00
|
|
|
{
|
2009-04-15 00:54:39 +02:00
|
|
|
$string = file_get_contents($chunk);
|
2009-07-01 22:56:41 +02:00
|
|
|
|
2009-12-04 22:57:50 +01:00
|
|
|
if (function_exists('memory_get_usage')) {
|
|
|
|
ws_logfile('[merge_chunks] memory_get_usage on chunk '.++$i.': '.memory_get_usage());
|
|
|
|
}
|
2009-07-01 22:56:41 +02:00
|
|
|
|
2009-04-15 00:54:39 +02:00
|
|
|
if (!file_put_contents($output_filepath, $string, FILE_APPEND))
|
|
|
|
{
|
2011-12-27 06:26:44 +01:00
|
|
|
return new PwgError(500, '[merge_chunks] error while writting chunks for '.$output_filepath);
|
2009-04-15 00:54:39 +02:00
|
|
|
}
|
2009-07-01 22:56:41 +02:00
|
|
|
|
2009-04-15 00:54:39 +02:00
|
|
|
unlink($chunk);
|
2009-03-13 00:14:50 +01:00
|
|
|
}
|
2009-04-15 00:54:39 +02:00
|
|
|
|
2009-12-04 22:57:50 +01:00
|
|
|
if (function_exists('memory_get_usage')) {
|
|
|
|
ws_logfile('[merge_chunks] memory_get_usage after loading chunks: '.memory_get_usage());
|
|
|
|
}
|
2009-03-13 00:14:50 +01:00
|
|
|
}
|
|
|
|
|
2012-01-17 01:11:14 +01:00
|
|
|
/**
|
|
|
|
* Function introduced for Piwigo 2.4 and the new "multiple size"
|
|
|
|
* (derivatives) feature. As we only need the biggest sent photo as
|
|
|
|
* "original", we remove chunks for smaller sizes. We can't make it earlier
|
|
|
|
* in ws_images_add_chunk because at this moment we don't know which $type
|
|
|
|
* will be the biggest (we could remove the thumb, but let's use the same
|
|
|
|
* algorithm)
|
|
|
|
*/
|
|
|
|
function remove_chunks($original_sum, $type)
|
|
|
|
{
|
|
|
|
global $conf;
|
|
|
|
|
|
|
|
$upload_dir = $conf['upload_dir'].'/buffer';
|
|
|
|
$pattern = '/'.$original_sum.'-'.$type.'/';
|
|
|
|
$chunks = array();
|
|
|
|
|
|
|
|
if ($handle = opendir($upload_dir))
|
|
|
|
{
|
|
|
|
while (false !== ($file = readdir($handle)))
|
|
|
|
{
|
|
|
|
if (preg_match($pattern, $file))
|
|
|
|
{
|
|
|
|
array_push($chunks, $upload_dir.'/'.$file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir($handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($chunks as $chunk)
|
|
|
|
{
|
|
|
|
unlink($chunk);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-23 00:59:14 +01:00
|
|
|
function ws_images_addFile($params, &$service)
|
|
|
|
{
|
2012-01-17 01:11:14 +01:00
|
|
|
ws_logfile(__FUNCTION__.', input : '.var_export($params, true));
|
2009-11-23 00:59:14 +01:00
|
|
|
// image_id
|
|
|
|
// type {thumb, file, high}
|
2012-01-17 01:11:14 +01:00
|
|
|
// sum -> not used currently (Piwigo 2.4)
|
2009-11-23 00:59:14 +01:00
|
|
|
|
|
|
|
global $conf;
|
2010-12-14 14:47:24 +01:00
|
|
|
if (!is_admin())
|
2009-11-23 00:59:14 +01:00
|
|
|
{
|
|
|
|
return new PwgError(401, 'Access denied');
|
|
|
|
}
|
|
|
|
|
|
|
|
$params['image_id'] = (int)$params['image_id'];
|
|
|
|
if ($params['image_id'] <= 0)
|
|
|
|
{
|
|
|
|
return new PwgError(WS_ERR_INVALID_PARAM, "Invalid image_id");
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2012-01-17 01:11:14 +01:00
|
|
|
// what is the path and other infos about the photo?
|
2009-11-23 00:59:14 +01:00
|
|
|
//
|
|
|
|
$query = '
|
|
|
|
SELECT
|
|
|
|
path,
|
2012-01-17 01:11:14 +01:00
|
|
|
file,
|
|
|
|
md5sum,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
filesize
|
2009-11-23 00:59:14 +01:00
|
|
|
FROM '.IMAGES_TABLE.'
|
|
|
|
WHERE id = '.$params['image_id'].'
|
|
|
|
;';
|
2012-01-17 01:11:14 +01:00
|
|
|
$image = pwg_db_fetch_assoc(pwg_query($query));
|
2009-11-23 00:59:14 +01:00
|
|
|
|
2012-01-17 01:11:14 +01:00
|
|
|
if ($image == null)
|
|
|
|
{
|
|
|
|
return new PwgError(404, "image_id not found");
|
|
|
|
}
|
2009-11-23 00:59:14 +01:00
|
|
|
|
2012-01-17 01:11:14 +01:00
|
|
|
// since Piwigo 2.4 and derivatives, we do not take the imported "thumb"
|
|
|
|
// into account
|
|
|
|
if ('thumb' == $params['type'])
|
|
|
|
{
|
|
|
|
remove_chunks($image['md5sum'], $type);
|
|
|
|
return true;
|
|
|
|
}
|
2009-12-18 22:12:41 +01:00
|
|
|
|
2012-01-17 01:11:14 +01:00
|
|
|
// since Piwigo 2.4 and derivatives, we only care about the "original"
|
|
|
|
$original_type = 'file';
|
2009-11-23 00:59:14 +01:00
|
|
|
if ('high' == $params['type'])
|
|
|
|
{
|
2012-01-17 01:11:14 +01:00
|
|
|
$original_type = 'high';
|
2009-11-23 00:59:14 +01:00
|
|
|
}
|
|
|
|
|
2012-01-17 01:11:14 +01:00
|
|
|
$file_path = $conf['upload_dir'].'/buffer/'.$image['md5sum'].'-original';
|
|
|
|
|
|
|
|
merge_chunks($file_path, $image['md5sum'], $original_type);
|
|
|
|
chmod($file_path, 0644);
|
|
|
|
|
|
|
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
|
|
|
|
|
|
|
|
// if we receive the "file", we only update the original if the "file" is
|
|
|
|
// bigger than current original
|
2009-11-23 00:59:14 +01:00
|
|
|
if ('file' == $params['type'])
|
|
|
|
{
|
2012-01-17 01:11:14 +01:00
|
|
|
$do_update = false;
|
2012-02-09 22:11:34 +01:00
|
|
|
|
2012-01-17 01:11:14 +01:00
|
|
|
$infos = pwg_image_infos($file_path);
|
2012-02-09 22:11:34 +01:00
|
|
|
|
2012-01-17 01:11:14 +01:00
|
|
|
foreach (array('width', 'height', 'filesize') as $image_info)
|
|
|
|
{
|
|
|
|
if ($infos[$image_info] > $image[$image_info])
|
|
|
|
{
|
|
|
|
$do_update = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$do_update)
|
|
|
|
{
|
|
|
|
unlink($file_path);
|
|
|
|
return true;
|
|
|
|
}
|
2009-11-23 00:59:14 +01:00
|
|
|
}
|
|
|
|
|
2012-01-17 01:11:14 +01:00
|
|
|
$image_id = add_uploaded_file(
|
|
|
|
$file_path,
|
|
|
|
$image['file'],
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
$params['image_id'],
|
|
|
|
$image['md5sum'] // we force the md5sum to remain the same
|
|
|
|
);
|
2009-11-23 00:59:14 +01:00
|
|
|
}
|
|
|
|
|
2008-07-30 23:53:00 +02:00
|
|
|
function ws_images_add($params, &$service)
|
|
|
|
{
|
2011-01-04 11:55:08 +01:00
|
|
|
global $conf, $user;
|
2010-12-14 14:47:24 +01:00
|
|
|
if (!is_admin())
|
2008-09-04 02:57:55 +02:00
|
|
|
{
|
|
|
|
return new PwgError(401, 'Access denied');
|
|
|
|
}
|
|
|
|
|
2009-07-21 23:41:31 +02:00
|
|
|
foreach ($params as $param_key => $param_value) {
|
|
|
|
ws_logfile(
|
|
|
|
sprintf(
|
|
|
|
'[pwg.images.add] input param "%s" : "%s"',
|
|
|
|
$param_key,
|
|
|
|
is_null($param_value) ? 'NULL' : $param_value
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2008-07-30 23:53:00 +02:00
|
|
|
|
2012-02-11 00:48:55 +01:00
|
|
|
$params['image_id'] = (int)$params['image_id'];
|
|
|
|
if ($params['image_id'] > 0)
|
|
|
|
{
|
|
|
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
|
|
|
|
|
|
|
$query='
|
|
|
|
SELECT *
|
|
|
|
FROM '.IMAGES_TABLE.'
|
|
|
|
WHERE id = '.$params['image_id'].'
|
|
|
|
;';
|
|
|
|
|
|
|
|
$image_row = pwg_db_fetch_assoc(pwg_query($query));
|
|
|
|
if ($image_row == null)
|
|
|
|
{
|
|
|
|
return new PwgError(404, "image_id not found");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-26 01:01:35 +02:00
|
|
|
// does the image already exists ?
|
2011-12-13 15:42:54 +01:00
|
|
|
if ($params['check_uniqueness'])
|
2010-02-23 15:41:45 +01:00
|
|
|
{
|
2011-12-13 15:42:54 +01:00
|
|
|
if ('md5sum' == $conf['uniqueness_mode'])
|
|
|
|
{
|
|
|
|
$where_clause = "md5sum = '".$params['original_sum']."'";
|
|
|
|
}
|
|
|
|
if ('filename' == $conf['uniqueness_mode'])
|
|
|
|
{
|
|
|
|
$where_clause = "file = '".$params['original_filename']."'";
|
|
|
|
}
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2011-12-13 15:42:54 +01:00
|
|
|
$query = '
|
2008-09-26 01:01:35 +02:00
|
|
|
SELECT
|
|
|
|
COUNT(*) AS counter
|
|
|
|
FROM '.IMAGES_TABLE.'
|
2010-02-23 15:41:45 +01:00
|
|
|
WHERE '.$where_clause.'
|
2008-09-26 01:01:35 +02:00
|
|
|
;';
|
2011-12-13 15:42:54 +01:00
|
|
|
list($counter) = pwg_db_fetch_row(pwg_query($query));
|
|
|
|
if ($counter != 0) {
|
|
|
|
return new PwgError(500, 'file already exists');
|
|
|
|
}
|
2008-09-26 01:01:35 +02:00
|
|
|
}
|
|
|
|
|
2012-01-17 01:11:14 +01:00
|
|
|
// due to the new feature "derivatives" (multiple sizes) introduced for
|
|
|
|
// Piwigo 2.4, we only take the biggest photos sent on
|
|
|
|
// pwg.images.addChunk. If "high" is available we use it as "original"
|
|
|
|
// else we use "file".
|
|
|
|
remove_chunks($params['original_sum'], 'thumb');
|
2012-02-09 22:11:34 +01:00
|
|
|
|
2012-01-17 01:11:14 +01:00
|
|
|
if (isset($params['high_sum']))
|
2011-12-13 15:01:10 +01:00
|
|
|
{
|
2012-01-17 01:11:14 +01:00
|
|
|
$original_type = 'high';
|
|
|
|
remove_chunks($params['original_sum'], 'file');
|
2011-12-13 15:01:10 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-01-17 01:11:14 +01:00
|
|
|
$original_type = 'file';
|
|
|
|
}
|
2011-12-13 15:01:10 +01:00
|
|
|
|
2012-01-17 01:11:14 +01:00
|
|
|
$file_path = $conf['upload_dir'].'/buffer/'.$params['original_sum'].'-original';
|
2011-12-13 15:01:10 +01:00
|
|
|
|
2012-01-17 01:11:14 +01:00
|
|
|
merge_chunks($file_path, $params['original_sum'], $original_type);
|
|
|
|
chmod($file_path, 0644);
|
2011-12-13 15:01:10 +01:00
|
|
|
|
2012-01-17 01:11:14 +01:00
|
|
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
|
2011-12-13 15:01:10 +01:00
|
|
|
|
2012-01-17 01:11:14 +01:00
|
|
|
$image_id = add_uploaded_file(
|
|
|
|
$file_path,
|
|
|
|
$params['original_filename'],
|
|
|
|
null, // categories
|
|
|
|
isset($params['level']) ? $params['level'] : null,
|
2012-02-11 00:48:55 +01:00
|
|
|
$params['image_id'] > 0 ? $params['image_id'] : null,
|
2012-01-17 01:11:14 +01:00
|
|
|
$params['original_sum']
|
|
|
|
);
|
2008-09-22 23:47:03 +02:00
|
|
|
|
|
|
|
$info_columns = array(
|
|
|
|
'name',
|
|
|
|
'author',
|
|
|
|
'comment',
|
|
|
|
'date_creation',
|
2008-07-30 23:53:00 +02:00
|
|
|
);
|
|
|
|
|
2012-01-17 01:11:14 +01:00
|
|
|
$update = array();
|
|
|
|
|
2008-09-22 23:47:03 +02:00
|
|
|
foreach ($info_columns as $key)
|
|
|
|
{
|
|
|
|
if (isset($params[$key]))
|
|
|
|
{
|
2011-12-13 15:01:10 +01:00
|
|
|
$update[$key] = $params[$key];
|
2008-09-22 23:47:03 +02:00
|
|
|
}
|
|
|
|
}
|
2012-01-08 20:25:52 +01:00
|
|
|
|
2011-12-13 15:01:10 +01:00
|
|
|
if (count(array_keys($update)) > 0)
|
2008-10-05 23:22:57 +02:00
|
|
|
{
|
2011-12-13 15:01:10 +01:00
|
|
|
single_update(
|
|
|
|
IMAGES_TABLE,
|
|
|
|
$update,
|
|
|
|
array('id' => $image_id)
|
|
|
|
);
|
2008-10-05 23:22:57 +02:00
|
|
|
}
|
|
|
|
|
2011-12-13 16:00:32 +01:00
|
|
|
$url_params = array('image_id' => $image_id);
|
2012-01-08 20:25:52 +01:00
|
|
|
|
2008-09-22 23:47:03 +02:00
|
|
|
// let's add links between the image and the categories
|
|
|
|
if (isset($params['categories']))
|
|
|
|
{
|
2008-12-03 23:55:17 +01:00
|
|
|
ws_add_image_category_relations($image_id, $params['categories']);
|
2011-12-13 16:00:32 +01:00
|
|
|
|
|
|
|
if (preg_match('/^\d+/', $params['categories'], $matches)) {
|
|
|
|
$category_id = $matches[0];
|
2012-01-08 20:25:52 +01:00
|
|
|
|
2011-12-13 16:00:32 +01:00
|
|
|
$query = '
|
|
|
|
SELECT id, name, permalink
|
|
|
|
FROM '.CATEGORIES_TABLE.'
|
|
|
|
WHERE id = '.$category_id.'
|
|
|
|
;';
|
|
|
|
$result = pwg_query($query);
|
|
|
|
$category = pwg_db_fetch_assoc($result);
|
2012-01-08 20:25:52 +01:00
|
|
|
|
2011-12-13 16:00:32 +01:00
|
|
|
$url_params['section'] = 'categories';
|
|
|
|
$url_params['category'] = $category;
|
|
|
|
}
|
2008-09-20 00:59:41 +02:00
|
|
|
}
|
2008-09-22 23:47:03 +02:00
|
|
|
|
|
|
|
// and now, let's create tag associations
|
2009-07-21 23:19:53 +02:00
|
|
|
if (isset($params['tag_ids']) and !empty($params['tag_ids']))
|
2008-09-20 00:59:41 +02:00
|
|
|
{
|
2008-09-22 23:47:03 +02:00
|
|
|
set_tags(
|
|
|
|
explode(',', $params['tag_ids']),
|
|
|
|
$image_id
|
|
|
|
);
|
2008-09-20 00:59:41 +02:00
|
|
|
}
|
2008-09-25 02:30:42 +02:00
|
|
|
|
2008-09-05 00:45:27 +02:00
|
|
|
invalidate_user_cache();
|
2011-12-13 16:00:32 +01:00
|
|
|
|
|
|
|
return array(
|
|
|
|
'image_id' => $image_id,
|
|
|
|
'url' => make_picture_url($url_params),
|
|
|
|
);
|
2008-07-30 23:53:00 +02:00
|
|
|
}
|
|
|
|
|
2010-12-23 11:22:51 +01:00
|
|
|
function ws_images_addSimple($params, &$service)
|
|
|
|
{
|
|
|
|
global $conf;
|
2010-12-24 00:15:24 +01:00
|
|
|
if (!is_admin())
|
2010-12-23 11:22:51 +01:00
|
|
|
{
|
|
|
|
return new PwgError(401, 'Access denied');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$service->isPost())
|
|
|
|
{
|
|
|
|
return new PwgError(405, "This method requires HTTP POST");
|
|
|
|
}
|
2011-05-30 23:38:53 +02:00
|
|
|
|
|
|
|
if (!isset($_FILES['image']))
|
|
|
|
{
|
|
|
|
return new PwgError(405, "The image (file) parameter is missing");
|
|
|
|
}
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2011-02-11 23:57:23 +01:00
|
|
|
$params['image_id'] = (int)$params['image_id'];
|
|
|
|
if ($params['image_id'] > 0)
|
|
|
|
{
|
|
|
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
|
|
|
|
|
|
|
$query='
|
|
|
|
SELECT *
|
|
|
|
FROM '.IMAGES_TABLE.'
|
|
|
|
WHERE id = '.$params['image_id'].'
|
|
|
|
;';
|
|
|
|
|
|
|
|
$image_row = pwg_db_fetch_assoc(pwg_query($query));
|
|
|
|
if ($image_row == null)
|
|
|
|
{
|
|
|
|
return new PwgError(404, "image_id not found");
|
|
|
|
}
|
|
|
|
}
|
2010-12-23 11:22:51 +01:00
|
|
|
|
|
|
|
// category
|
|
|
|
$params['category'] = (int)$params['category'];
|
2011-02-11 23:57:23 +01:00
|
|
|
if ($params['category'] <= 0 and $params['image_id'] <= 0)
|
2010-12-23 11:22:51 +01:00
|
|
|
{
|
|
|
|
return new PwgError(WS_ERR_INVALID_PARAM, "Invalid category_id");
|
|
|
|
}
|
|
|
|
|
|
|
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
|
|
|
|
|
|
|
|
$image_id = add_uploaded_file(
|
|
|
|
$_FILES['image']['tmp_name'],
|
|
|
|
$_FILES['image']['name'],
|
2011-02-11 23:57:23 +01:00
|
|
|
$params['category'] > 0 ? array($params['category']) : null,
|
|
|
|
8,
|
|
|
|
$params['image_id'] > 0 ? $params['image_id'] : null
|
2010-12-23 11:22:51 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$info_columns = array(
|
|
|
|
'name',
|
|
|
|
'author',
|
|
|
|
'comment',
|
|
|
|
'level',
|
|
|
|
'date_creation',
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($info_columns as $key)
|
|
|
|
{
|
|
|
|
if (isset($params[$key]))
|
|
|
|
{
|
|
|
|
$update[$key] = $params[$key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count(array_keys($update)) > 0)
|
|
|
|
{
|
|
|
|
$update['id'] = $image_id;
|
|
|
|
|
|
|
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
|
|
|
mass_updates(
|
|
|
|
IMAGES_TABLE,
|
|
|
|
array(
|
|
|
|
'primary' => array('id'),
|
|
|
|
'update' => array_diff(array_keys($update), array('id'))
|
|
|
|
),
|
|
|
|
array($update)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (isset($params['tags']) and !empty($params['tags']))
|
|
|
|
{
|
|
|
|
$tag_ids = array();
|
|
|
|
$tag_names = explode(',', $params['tags']);
|
|
|
|
foreach ($tag_names as $tag_name)
|
|
|
|
{
|
|
|
|
$tag_id = tag_id_from_tag_name($tag_name);
|
|
|
|
array_push($tag_ids, $tag_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
add_tags($tag_ids, array($image_id));
|
|
|
|
}
|
|
|
|
|
2011-02-11 23:57:23 +01:00
|
|
|
$url_params = array('image_id' => $image_id);
|
|
|
|
|
|
|
|
if ($params['category'] > 0)
|
|
|
|
{
|
|
|
|
$query = '
|
2010-12-23 11:22:51 +01:00
|
|
|
SELECT id, name, permalink
|
|
|
|
FROM '.CATEGORIES_TABLE.'
|
|
|
|
WHERE id = '.$params['category'].'
|
|
|
|
;';
|
2011-02-11 23:57:23 +01:00
|
|
|
$result = pwg_query($query);
|
|
|
|
$category = pwg_db_fetch_assoc($result);
|
|
|
|
|
|
|
|
$url_params['section'] = 'categories';
|
|
|
|
$url_params['category'] = $category;
|
|
|
|
}
|
2010-12-23 11:22:51 +01:00
|
|
|
|
2011-03-30 23:25:32 +02:00
|
|
|
// update metadata from the uploaded file (exif/iptc), even if the sync
|
|
|
|
// was already performed by add_uploaded_file().
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2011-03-30 23:25:32 +02:00
|
|
|
require_once(PHPWG_ROOT_PATH.'admin/include/functions_metadata.php');
|
2012-01-03 21:21:13 +01:00
|
|
|
sync_metadata(array($image_id));
|
2011-03-30 23:25:32 +02:00
|
|
|
|
2010-12-23 11:22:51 +01:00
|
|
|
return array(
|
|
|
|
'image_id' => $image_id,
|
2011-02-11 23:57:23 +01:00
|
|
|
'url' => make_picture_url($url_params),
|
2010-12-23 11:22:51 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2011-11-14 21:10:37 +01:00
|
|
|
function ws_rates_delete($params, &$service)
|
|
|
|
{
|
|
|
|
global $conf;
|
|
|
|
|
|
|
|
if (!$service->isPost())
|
|
|
|
{
|
|
|
|
return new PwgError(405, 'This method requires HTTP POST');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_admin())
|
|
|
|
{
|
|
|
|
return new PwgError(401, 'Access denied');
|
|
|
|
}
|
|
|
|
|
|
|
|
$user_id = (int)$params['user_id'];
|
|
|
|
if ($user_id<=0)
|
|
|
|
{
|
|
|
|
return new PwgError(WS_ERR_INVALID_PARAM, 'Invalid user_id');
|
|
|
|
}
|
2012-01-08 20:25:52 +01:00
|
|
|
|
2011-11-14 21:10:37 +01:00
|
|
|
$query = '
|
|
|
|
DELETE FROM '.RATE_TABLE.'
|
|
|
|
WHERE user_id='.$user_id;
|
2012-01-08 20:25:52 +01:00
|
|
|
|
2011-11-14 21:10:37 +01:00
|
|
|
if (!empty($params['anonymous_id']))
|
|
|
|
{
|
|
|
|
$query .= ' AND anonymous_id=\''.$params['anonymous_id'].'\'';
|
|
|
|
}
|
2012-01-08 20:25:52 +01:00
|
|
|
|
2011-11-14 21:10:37 +01:00
|
|
|
$changes = pwg_db_changes(pwg_query($query));
|
|
|
|
if ($changes)
|
|
|
|
{
|
|
|
|
include_once(PHPWG_ROOT_PATH.'include/functions_rate.inc.php');
|
|
|
|
update_rating_score();
|
|
|
|
}
|
|
|
|
return $changes;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-06 02:02:06 +01:00
|
|
|
/**
|
|
|
|
* perform a login (web service method)
|
|
|
|
*/
|
2007-01-06 12:13:08 +01:00
|
|
|
function ws_session_login($params, &$service)
|
|
|
|
{
|
|
|
|
global $conf;
|
|
|
|
|
|
|
|
if (!$service->isPost())
|
|
|
|
{
|
2007-02-23 14:18:34 +01:00
|
|
|
return new PwgError(405, "This method requires HTTP POST");
|
2007-01-06 12:13:08 +01:00
|
|
|
}
|
2007-01-23 02:22:52 +01:00
|
|
|
if (try_log_user($params['username'], $params['password'],false))
|
2007-01-06 12:13:08 +01:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return new PwgError(999, 'Invalid username/password');
|
|
|
|
}
|
|
|
|
|
2007-02-06 02:02:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* performs a logout (web service method)
|
|
|
|
*/
|
2007-01-06 12:13:08 +01:00
|
|
|
function ws_session_logout($params, &$service)
|
|
|
|
{
|
2007-06-06 00:01:15 +02:00
|
|
|
if (!is_a_guest())
|
2007-01-06 12:13:08 +01:00
|
|
|
{
|
2008-10-16 02:38:26 +02:00
|
|
|
logout_user();
|
2007-01-06 12:13:08 +01:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function ws_session_getStatus($params, &$service)
|
|
|
|
{
|
2008-05-23 12:15:48 +02:00
|
|
|
global $user;
|
2007-01-06 12:13:08 +01:00
|
|
|
$res = array();
|
2009-11-18 21:07:20 +01:00
|
|
|
$res['username'] = is_a_guest() ? 'guest' : stripslashes($user['username']);
|
2010-06-01 21:52:44 +02:00
|
|
|
foreach ( array('status', 'theme', 'language') as $k )
|
2007-02-22 02:12:32 +01:00
|
|
|
{
|
|
|
|
$res[$k] = $user[$k];
|
|
|
|
}
|
2010-10-15 22:36:02 +02:00
|
|
|
$res['pwg_token'] = get_pwg_token();
|
2007-10-09 01:46:09 +02:00
|
|
|
$res['charset'] = get_pwg_charset();
|
2011-07-15 21:24:17 +02:00
|
|
|
|
|
|
|
list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
|
|
|
|
$res['current_datetime'] = $dbnow;
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2007-01-06 12:13:08 +01:00
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-06 02:02:06 +01:00
|
|
|
/**
|
|
|
|
* returns a list of tags (web service method)
|
|
|
|
*/
|
2007-01-06 12:13:08 +01:00
|
|
|
function ws_tags_getList($params, &$service)
|
|
|
|
{
|
2007-01-11 06:10:16 +01:00
|
|
|
$tags = get_available_tags();
|
2007-01-06 12:13:08 +01:00
|
|
|
if ($params['sort_by_counter'])
|
|
|
|
{
|
|
|
|
usort($tags, create_function('$a,$b', 'return -$a["counter"]+$b["counter"];') );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-07-01 04:09:21 +02:00
|
|
|
usort($tags, 'tag_alpha_compare');
|
2007-01-06 12:13:08 +01:00
|
|
|
}
|
|
|
|
for ($i=0; $i<count($tags); $i++)
|
|
|
|
{
|
2007-02-14 02:37:38 +01:00
|
|
|
$tags[$i]['id'] = (int)$tags[$i]['id'];
|
2007-01-06 12:13:08 +01:00
|
|
|
$tags[$i]['counter'] = (int)$tags[$i]['counter'];
|
|
|
|
$tags[$i]['url'] = make_index_url(
|
|
|
|
array(
|
|
|
|
'section'=>'tags',
|
|
|
|
'tags'=>array($tags[$i])
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2008-09-25 02:30:42 +02:00
|
|
|
return array('tags' => new PwgNamedArray($tags, 'tag', array('id','url_name','url', 'name', 'counter' )) );
|
2007-01-06 12:13:08 +01:00
|
|
|
}
|
|
|
|
|
2008-09-24 23:30:33 +02:00
|
|
|
/**
|
|
|
|
* returns the list of tags as you can see them in administration (web
|
|
|
|
* service method).
|
|
|
|
*
|
|
|
|
* Only admin can run this method and permissions are not taken into
|
|
|
|
* account.
|
|
|
|
*/
|
|
|
|
function ws_tags_getAdminList($params, &$service)
|
|
|
|
{
|
|
|
|
if (!is_admin())
|
|
|
|
{
|
|
|
|
return new PwgError(401, 'Access denied');
|
|
|
|
}
|
2008-09-25 02:30:42 +02:00
|
|
|
|
2008-09-24 23:30:33 +02:00
|
|
|
$tags = get_all_tags();
|
|
|
|
return array(
|
|
|
|
'tags' => new PwgNamedArray(
|
|
|
|
$tags,
|
|
|
|
'tag',
|
|
|
|
array(
|
|
|
|
'name',
|
|
|
|
'id',
|
|
|
|
'url_name',
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2007-02-06 02:02:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* returns a list of images for tags (web service method)
|
|
|
|
*/
|
2007-01-06 12:13:08 +01:00
|
|
|
function ws_tags_getImages($params, &$service)
|
|
|
|
{
|
2007-02-14 06:45:20 +01:00
|
|
|
global $conf;
|
2007-10-04 01:36:21 +02:00
|
|
|
|
2007-01-06 12:13:08 +01:00
|
|
|
// first build all the tag_ids we are interested in
|
2007-02-23 14:18:34 +01:00
|
|
|
$params['tag_id'] = array_map( 'intval',$params['tag_id'] );
|
|
|
|
$tags = find_tags($params['tag_id'], $params['tag_url_name'], $params['tag_name']);
|
2007-01-06 12:13:08 +01:00
|
|
|
$tags_by_id = array();
|
|
|
|
foreach( $tags as $tag )
|
|
|
|
{
|
2007-02-23 14:18:34 +01:00
|
|
|
$tags['id'] = (int)$tag['id'];
|
2007-02-14 02:37:38 +01:00
|
|
|
$tags_by_id[ $tag['id'] ] = $tag;
|
2007-01-06 12:13:08 +01:00
|
|
|
}
|
|
|
|
unset($tags);
|
2007-02-23 14:18:34 +01:00
|
|
|
$tag_ids = array_keys($tags_by_id);
|
2007-01-06 12:13:08 +01:00
|
|
|
|
|
|
|
|
2011-01-17 22:16:42 +01:00
|
|
|
$where_clauses = ws_std_image_sql_filter($params);
|
|
|
|
if (!empty($where_clauses))
|
|
|
|
{
|
|
|
|
$where_clauses = implode( ' AND ', $where_clauses);
|
|
|
|
}
|
|
|
|
$image_ids = get_image_ids_for_tags(
|
|
|
|
$tag_ids,
|
|
|
|
$params['tag_mode_and'] ? 'AND' : 'OR',
|
|
|
|
$where_clauses,
|
|
|
|
ws_std_image_sql_order($params) );
|
2007-02-06 02:02:06 +01:00
|
|
|
|
2011-01-17 22:16:42 +01:00
|
|
|
|
|
|
|
$image_ids = array_slice($image_ids, (int)($params['per_page']*$params['page']), (int)$params['per_page'] );
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2011-01-17 22:16:42 +01:00
|
|
|
$image_tag_map = array();
|
|
|
|
if ( !empty($image_ids) and !$params['tag_mode_and'] )
|
2007-01-06 12:13:08 +01:00
|
|
|
{ // build list of image ids with associated tags per image
|
2011-01-17 22:16:42 +01:00
|
|
|
$query = '
|
2010-07-03 14:12:25 +02:00
|
|
|
SELECT image_id, GROUP_CONCAT(tag_id) AS tag_ids
|
2007-01-06 12:13:08 +01:00
|
|
|
FROM '.IMAGE_TAG_TABLE.'
|
2011-01-17 22:16:42 +01:00
|
|
|
WHERE tag_id IN ('.implode(',',$tag_ids).') AND image_id IN ('.implode(',',$image_ids).')
|
2007-01-06 12:13:08 +01:00
|
|
|
GROUP BY image_id';
|
2011-01-17 22:16:42 +01:00
|
|
|
$result = pwg_query($query);
|
|
|
|
while ( $row=pwg_db_fetch_assoc($result) )
|
|
|
|
{
|
|
|
|
$row['image_id'] = (int)$row['image_id'];
|
|
|
|
array_push( $image_ids, $row['image_id'] );
|
|
|
|
$image_tag_map[ $row['image_id'] ] = explode(',', $row['tag_ids']);
|
2007-01-06 12:13:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$images = array();
|
2011-01-17 22:16:42 +01:00
|
|
|
if (!empty($image_ids))
|
|
|
|
{
|
|
|
|
$rank_of = array_flip($image_ids);
|
|
|
|
$result = pwg_query('
|
|
|
|
SELECT * FROM '.IMAGES_TABLE.'
|
|
|
|
WHERE id IN ('.implode(',',$image_ids).')');
|
2009-11-20 15:17:04 +01:00
|
|
|
while ($row = pwg_db_fetch_assoc($result))
|
2007-01-06 12:13:08 +01:00
|
|
|
{
|
2007-10-04 01:36:21 +02:00
|
|
|
$image = array();
|
2011-01-17 22:16:42 +01:00
|
|
|
$image['rank'] = $rank_of[ $row['id'] ];
|
2007-01-06 12:13:08 +01:00
|
|
|
foreach ( array('id', 'width', 'height', 'hit') as $k )
|
|
|
|
{
|
|
|
|
if (isset($row[$k]))
|
|
|
|
{
|
|
|
|
$image[$k] = (int)$row[$k];
|
|
|
|
}
|
|
|
|
}
|
2011-05-30 23:32:10 +02:00
|
|
|
foreach ( array('file', 'name', 'comment', 'date_creation', 'date_available') as $k )
|
2007-01-06 12:13:08 +01:00
|
|
|
{
|
|
|
|
$image[$k] = $row[$k];
|
|
|
|
}
|
|
|
|
$image = array_merge( $image, ws_std_get_urls($row) );
|
|
|
|
|
|
|
|
$image_tag_ids = ($params['tag_mode_and']) ? $tag_ids : $image_tag_map[$image['id']];
|
|
|
|
$image_tags = array();
|
|
|
|
foreach ($image_tag_ids as $tag_id)
|
|
|
|
{
|
|
|
|
$url = make_index_url(
|
|
|
|
array(
|
|
|
|
'section'=>'tags',
|
|
|
|
'tags'=> array($tags_by_id[$tag_id])
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$page_url = make_picture_url(
|
|
|
|
array(
|
|
|
|
'section'=>'tags',
|
|
|
|
'tags'=> array($tags_by_id[$tag_id]),
|
|
|
|
'image_id' => $row['id'],
|
|
|
|
'image_file' => $row['file'],
|
|
|
|
)
|
|
|
|
);
|
|
|
|
array_push($image_tags, array(
|
|
|
|
'id' => (int)$tag_id,
|
|
|
|
'url' => $url,
|
|
|
|
'page_url' => $page_url,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2007-01-11 06:10:16 +01:00
|
|
|
$image['tags'] = new PwgNamedArray($image_tags, 'tag',
|
|
|
|
array('id','url_name','url','page_url')
|
2007-01-06 12:13:08 +01:00
|
|
|
);
|
|
|
|
array_push($images, $image);
|
|
|
|
}
|
2011-01-17 22:16:42 +01:00
|
|
|
usort($images, 'rank_compare');
|
|
|
|
unset($rank_of);
|
2007-01-06 12:13:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return array( 'images' =>
|
|
|
|
array (
|
|
|
|
WS_XML_ATTRIBUTES =>
|
|
|
|
array(
|
|
|
|
'page' => $params['page'],
|
|
|
|
'per_page' => $params['per_page'],
|
|
|
|
'count' => count($images)
|
|
|
|
),
|
2007-01-11 06:10:16 +01:00
|
|
|
WS_XML_CONTENT => new PwgNamedArray($images, 'image',
|
2007-02-21 01:20:02 +01:00
|
|
|
ws_std_get_image_xml_attributes() )
|
2007-01-06 12:13:08 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2008-09-24 22:25:39 +02:00
|
|
|
|
|
|
|
function ws_categories_add($params, &$service)
|
|
|
|
{
|
2010-12-14 14:47:24 +01:00
|
|
|
if (!is_admin())
|
2008-09-24 22:25:39 +02:00
|
|
|
{
|
|
|
|
return new PwgError(401, 'Access denied');
|
|
|
|
}
|
|
|
|
|
|
|
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
|
|
|
|
2012-08-30 14:54:29 +02:00
|
|
|
$options = array();
|
|
|
|
if (!empty($params['status']) and in_array($params['status'], array('private','public')))
|
2008-09-24 22:25:39 +02:00
|
|
|
{
|
2012-08-30 14:54:29 +02:00
|
|
|
$options['status'] = $params['status'];
|
2008-09-24 22:25:39 +02:00
|
|
|
}
|
2012-06-20 17:41:31 +02:00
|
|
|
|
2012-08-30 14:54:29 +02:00
|
|
|
if (!empty($params['visible']) and in_array($params['visible'], array('true','false')))
|
2012-06-20 17:41:31 +02:00
|
|
|
{
|
2012-08-30 14:54:29 +02:00
|
|
|
$options['visible'] = get_boolean($params['visible']);
|
2012-06-20 17:41:31 +02:00
|
|
|
}
|
2012-08-30 14:54:29 +02:00
|
|
|
|
|
|
|
if (!empty($params['commentable']) and in_array($params['commentable'], array('true','false')) )
|
2012-06-20 17:41:31 +02:00
|
|
|
{
|
2012-08-30 14:54:29 +02:00
|
|
|
$options['commentable'] = get_boolean($params['commentable']);
|
2012-06-20 17:41:31 +02:00
|
|
|
}
|
2012-08-30 14:54:29 +02:00
|
|
|
|
|
|
|
if (!empty($params['comment']))
|
2012-06-20 17:41:31 +02:00
|
|
|
{
|
2012-08-30 14:54:29 +02:00
|
|
|
$options['comment'] = $params['comment'];
|
2012-06-20 17:41:31 +02:00
|
|
|
}
|
2012-06-20 18:05:27 +02:00
|
|
|
|
2012-08-30 14:54:29 +02:00
|
|
|
|
|
|
|
$creation_output = create_virtual_category(
|
|
|
|
$params['name'],
|
|
|
|
$params['parent'],
|
|
|
|
$options
|
|
|
|
);
|
|
|
|
|
|
|
|
if (isset($creation_output['error']))
|
2012-06-20 18:05:27 +02:00
|
|
|
{
|
2012-08-30 14:54:29 +02:00
|
|
|
return new PwgError(500, $creation_output['error']);
|
2012-06-20 18:05:27 +02:00
|
|
|
}
|
2008-09-25 02:30:42 +02:00
|
|
|
|
2008-10-03 22:38:12 +02:00
|
|
|
invalidate_user_cache();
|
2008-10-16 02:38:26 +02:00
|
|
|
|
2008-09-24 22:25:39 +02:00
|
|
|
return $creation_output;
|
|
|
|
}
|
2008-10-01 23:08:51 +02:00
|
|
|
|
|
|
|
function ws_tags_add($params, &$service)
|
|
|
|
{
|
2010-12-14 14:47:24 +01:00
|
|
|
if (!is_admin())
|
2008-10-01 23:08:51 +02:00
|
|
|
{
|
|
|
|
return new PwgError(401, 'Access denied');
|
|
|
|
}
|
|
|
|
|
|
|
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
|
|
|
|
|
|
|
$creation_output = create_tag($params['name']);
|
|
|
|
|
|
|
|
if (isset($creation_output['error']))
|
|
|
|
{
|
|
|
|
return new PwgError(500, $creation_output['error']);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $creation_output;
|
|
|
|
}
|
2008-10-08 00:01:14 +02:00
|
|
|
|
|
|
|
function ws_images_exist($params, &$service)
|
|
|
|
{
|
2012-01-17 01:11:14 +01:00
|
|
|
ws_logfile(__FUNCTION__.' '.var_export($params, true));
|
|
|
|
|
2010-02-23 15:41:45 +01:00
|
|
|
global $conf;
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2010-12-14 14:47:24 +01:00
|
|
|
if (!is_admin())
|
2008-10-08 00:01:14 +02:00
|
|
|
{
|
|
|
|
return new PwgError(401, 'Access denied');
|
|
|
|
}
|
|
|
|
|
2010-02-23 15:41:45 +01:00
|
|
|
$split_pattern = '/[\s,;\|]/';
|
|
|
|
|
|
|
|
if ('md5sum' == $conf['uniqueness_mode'])
|
|
|
|
{
|
|
|
|
// search among photos the list of photos already added, based on md5sum
|
|
|
|
// list
|
|
|
|
$md5sums = preg_split(
|
|
|
|
$split_pattern,
|
|
|
|
$params['md5sum_list'],
|
|
|
|
-1,
|
|
|
|
PREG_SPLIT_NO_EMPTY
|
2008-10-08 00:01:14 +02:00
|
|
|
);
|
2008-10-16 02:38:26 +02:00
|
|
|
|
2010-02-23 15:41:45 +01:00
|
|
|
$query = '
|
2008-10-08 00:01:14 +02:00
|
|
|
SELECT
|
|
|
|
id,
|
|
|
|
md5sum
|
|
|
|
FROM '.IMAGES_TABLE.'
|
2008-10-16 02:38:26 +02:00
|
|
|
WHERE md5sum IN (\''.implode("','", $md5sums).'\')
|
2008-10-08 00:01:14 +02:00
|
|
|
;';
|
2010-02-23 15:41:45 +01:00
|
|
|
$id_of_md5 = simple_hash_from_query($query, 'md5sum', 'id');
|
2008-10-08 00:01:14 +02:00
|
|
|
|
2010-02-23 15:41:45 +01:00
|
|
|
$result = array();
|
2008-10-16 02:38:26 +02:00
|
|
|
|
2010-02-23 15:41:45 +01:00
|
|
|
foreach ($md5sums as $md5sum)
|
2008-10-08 00:01:14 +02:00
|
|
|
{
|
2010-02-23 15:41:45 +01:00
|
|
|
$result[$md5sum] = null;
|
|
|
|
if (isset($id_of_md5[$md5sum]))
|
|
|
|
{
|
|
|
|
$result[$md5sum] = $id_of_md5[$md5sum];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2010-02-23 15:41:45 +01:00
|
|
|
if ('filename' == $conf['uniqueness_mode'])
|
|
|
|
{
|
|
|
|
// search among photos the list of photos already added, based on
|
|
|
|
// filename list
|
|
|
|
$filenames = preg_split(
|
|
|
|
$split_pattern,
|
|
|
|
$params['filename_list'],
|
|
|
|
-1,
|
|
|
|
PREG_SPLIT_NO_EMPTY
|
|
|
|
);
|
|
|
|
|
|
|
|
$query = '
|
|
|
|
SELECT
|
|
|
|
id,
|
|
|
|
file
|
|
|
|
FROM '.IMAGES_TABLE.'
|
|
|
|
WHERE file IN (\''.implode("','", $filenames).'\')
|
|
|
|
;';
|
|
|
|
$id_of_filename = simple_hash_from_query($query, 'file', 'id');
|
|
|
|
|
|
|
|
$result = array();
|
|
|
|
|
|
|
|
foreach ($filenames as $filename)
|
|
|
|
{
|
|
|
|
$result[$filename] = null;
|
|
|
|
if (isset($id_of_filename[$filename]))
|
|
|
|
{
|
|
|
|
$result[$filename] = $id_of_filename[$filename];
|
|
|
|
}
|
2008-10-08 00:01:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
2008-12-03 23:55:17 +01:00
|
|
|
|
2009-11-23 00:58:44 +01:00
|
|
|
function ws_images_checkFiles($params, &$service)
|
|
|
|
{
|
2012-01-17 01:11:14 +01:00
|
|
|
ws_logfile(__FUNCTION__.', input : '.var_export($params, true));
|
|
|
|
|
2010-12-14 14:47:24 +01:00
|
|
|
if (!is_admin())
|
2009-11-23 00:58:44 +01:00
|
|
|
{
|
|
|
|
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);
|
2012-01-17 01:11:14 +01:00
|
|
|
if (pwg_db_num_rows($result) == 0)
|
|
|
|
{
|
2009-11-23 00:58:44 +01:00
|
|
|
return new PwgError(404, "image_id not found");
|
|
|
|
}
|
2010-06-09 11:55:54 +02:00
|
|
|
list($path) = pwg_db_fetch_row($result);
|
2009-11-23 00:58:44 +01:00
|
|
|
|
|
|
|
$ret = array();
|
|
|
|
|
2012-01-17 01:11:14 +01:00
|
|
|
if (isset($params['thumbnail_sum']))
|
|
|
|
{
|
|
|
|
// We always say the thumbnail is equal to create no reaction on the
|
|
|
|
// other side. Since Piwigo 2.4 and derivatives, the thumbnails and web
|
|
|
|
// sizes are always generated by Piwigo
|
|
|
|
$ret['thumbnail'] = 'equals';
|
|
|
|
}
|
2009-11-23 00:58:44 +01:00
|
|
|
|
2012-01-17 01:11:14 +01:00
|
|
|
if (isset($params['high_sum']))
|
|
|
|
{
|
|
|
|
$ret['file'] = 'equals';
|
|
|
|
$compare_type = 'high';
|
|
|
|
}
|
|
|
|
elseif (isset($params['file_sum']))
|
|
|
|
{
|
|
|
|
$compare_type = 'file';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($compare_type))
|
|
|
|
{
|
|
|
|
ws_logfile(__FUNCTION__.', md5_file($path) = '.md5_file($path));
|
|
|
|
if (md5_file($path) != $params[$compare_type.'_sum'])
|
|
|
|
{
|
|
|
|
$ret[$compare_type] = 'differs';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$ret[$compare_type] = 'equals';
|
2009-11-23 00:58:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-17 01:11:14 +01:00
|
|
|
ws_logfile(__FUNCTION__.', output : '.var_export($ret, true));
|
|
|
|
|
2009-11-23 00:58:44 +01:00
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
2008-12-03 23:55:17 +01:00
|
|
|
function ws_images_setInfo($params, &$service)
|
|
|
|
{
|
|
|
|
global $conf;
|
2010-12-14 14:47:24 +01:00
|
|
|
if (!is_admin())
|
2008-12-03 23:55:17 +01:00
|
|
|
{
|
|
|
|
return new PwgError(401, 'Access denied');
|
|
|
|
}
|
|
|
|
|
2009-12-18 01:45:03 +01:00
|
|
|
if (!$service->isPost())
|
|
|
|
{
|
|
|
|
return new PwgError(405, "This method requires HTTP POST");
|
|
|
|
}
|
|
|
|
|
2008-12-03 23:55:17 +01:00
|
|
|
$params['image_id'] = (int)$params['image_id'];
|
|
|
|
if ($params['image_id'] <= 0)
|
|
|
|
{
|
|
|
|
return new PwgError(WS_ERR_INVALID_PARAM, "Invalid image_id");
|
|
|
|
}
|
|
|
|
|
2010-11-03 23:24:48 +01:00
|
|
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
|
|
|
|
2008-12-03 23:55:17 +01:00
|
|
|
$query='
|
|
|
|
SELECT *
|
|
|
|
FROM '.IMAGES_TABLE.'
|
|
|
|
WHERE id = '.$params['image_id'].'
|
|
|
|
;';
|
|
|
|
|
2009-11-20 15:17:04 +01:00
|
|
|
$image_row = pwg_db_fetch_assoc(pwg_query($query));
|
2008-12-03 23:55:17 +01:00
|
|
|
if ($image_row == null)
|
|
|
|
{
|
|
|
|
return new PwgError(404, "image_id not found");
|
|
|
|
}
|
|
|
|
|
|
|
|
// database registration
|
2009-12-09 23:19:06 +01:00
|
|
|
$update = array();
|
2008-12-03 23:55:17 +01:00
|
|
|
|
|
|
|
$info_columns = array(
|
|
|
|
'name',
|
|
|
|
'author',
|
|
|
|
'comment',
|
|
|
|
'level',
|
|
|
|
'date_creation',
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($info_columns as $key)
|
|
|
|
{
|
|
|
|
if (isset($params[$key]))
|
|
|
|
{
|
2009-12-09 23:19:06 +01:00
|
|
|
if ('fill_if_empty' == $params['single_value_mode'])
|
|
|
|
{
|
|
|
|
if (empty($image_row[$key]))
|
|
|
|
{
|
|
|
|
$update[$key] = $params[$key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elseif ('replace' == $params['single_value_mode'])
|
|
|
|
{
|
|
|
|
$update[$key] = $params[$key];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-27 06:26:44 +01:00
|
|
|
return new PwgError(
|
2009-12-09 23:19:06 +01:00
|
|
|
500,
|
|
|
|
'[ws_images_setInfo]'
|
|
|
|
.' invalid parameter single_value_mode "'.$params['single_value_mode'].'"'
|
|
|
|
.', possible values are {fill_if_empty, replace}.'
|
|
|
|
);
|
|
|
|
}
|
2008-12-03 23:55:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-16 10:10:30 +01:00
|
|
|
if (isset($params['file']))
|
|
|
|
{
|
|
|
|
if (!empty($image_row['storage_category_id']))
|
|
|
|
{
|
2011-12-27 06:26:44 +01:00
|
|
|
return new PwgError(500, '[ws_images_setInfo] updating "file" is forbidden on photos added by synchronization');
|
2011-12-16 10:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$update['file'] = $params['file'];
|
|
|
|
}
|
|
|
|
|
2009-12-09 23:19:06 +01:00
|
|
|
if (count(array_keys($update)) > 0)
|
2008-12-03 23:55:17 +01:00
|
|
|
{
|
2009-12-09 23:19:06 +01:00
|
|
|
$update['id'] = $params['image_id'];
|
|
|
|
|
2008-12-03 23:55:17 +01:00
|
|
|
mass_updates(
|
|
|
|
IMAGES_TABLE,
|
|
|
|
array(
|
|
|
|
'primary' => array('id'),
|
|
|
|
'update' => array_diff(array_keys($update), array('id'))
|
|
|
|
),
|
|
|
|
array($update)
|
|
|
|
);
|
|
|
|
}
|
2009-02-14 03:24:10 +01:00
|
|
|
|
2008-12-03 23:55:17 +01:00
|
|
|
if (isset($params['categories']))
|
|
|
|
{
|
|
|
|
ws_add_image_category_relations(
|
|
|
|
$params['image_id'],
|
2009-12-07 23:30:02 +01:00
|
|
|
$params['categories'],
|
2009-12-09 23:19:06 +01:00
|
|
|
('replace' == $params['multiple_value_mode'] ? true : false)
|
2008-12-03 23:55:17 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// and now, let's create tag associations
|
|
|
|
if (isset($params['tag_ids']))
|
|
|
|
{
|
2009-12-07 23:30:02 +01:00
|
|
|
$tag_ids = explode(',', $params['tag_ids']);
|
|
|
|
|
2009-12-09 23:19:06 +01:00
|
|
|
if ('replace' == $params['multiple_value_mode'])
|
2009-12-07 23:30:02 +01:00
|
|
|
{
|
|
|
|
set_tags(
|
|
|
|
$tag_ids,
|
|
|
|
$params['image_id']
|
|
|
|
);
|
|
|
|
}
|
2009-12-09 23:19:06 +01:00
|
|
|
elseif ('append' == $params['multiple_value_mode'])
|
2009-12-07 23:30:02 +01:00
|
|
|
{
|
|
|
|
add_tags(
|
|
|
|
$tag_ids,
|
|
|
|
array($params['image_id'])
|
|
|
|
);
|
|
|
|
}
|
2009-12-09 23:19:06 +01:00
|
|
|
else
|
|
|
|
{
|
2011-12-27 06:26:44 +01:00
|
|
|
return new PwgError(
|
2009-12-09 23:19:06 +01:00
|
|
|
500,
|
|
|
|
'[ws_images_setInfo]'
|
|
|
|
.' invalid parameter multiple_value_mode "'.$params['multiple_value_mode'].'"'
|
|
|
|
.', possible values are {replace, append}.'
|
|
|
|
);
|
|
|
|
}
|
2008-12-03 23:55:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
invalidate_user_cache();
|
|
|
|
}
|
|
|
|
|
2010-12-23 21:51:33 +01:00
|
|
|
function ws_images_delete($params, &$service)
|
|
|
|
{
|
|
|
|
global $conf;
|
2010-12-24 00:15:24 +01:00
|
|
|
if (!is_admin())
|
2010-12-23 21:51:33 +01:00
|
|
|
{
|
|
|
|
return new PwgError(401, 'Access denied');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$service->isPost())
|
|
|
|
{
|
|
|
|
return new PwgError(405, "This method requires HTTP POST");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token'])
|
|
|
|
{
|
|
|
|
return new PwgError(403, 'Invalid security token');
|
|
|
|
}
|
|
|
|
|
|
|
|
$params['image_id'] = preg_split(
|
|
|
|
'/[\s,;\|]/',
|
|
|
|
$params['image_id'],
|
|
|
|
-1,
|
|
|
|
PREG_SPLIT_NO_EMPTY
|
|
|
|
);
|
|
|
|
$params['image_id'] = array_map('intval', $params['image_id']);
|
|
|
|
|
|
|
|
$image_ids = array();
|
|
|
|
foreach ($params['image_id'] as $image_id)
|
|
|
|
{
|
|
|
|
if ($image_id > 0)
|
|
|
|
{
|
|
|
|
array_push($image_ids, $image_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
|
|
|
delete_elements($image_ids, true);
|
|
|
|
}
|
|
|
|
|
2009-12-07 23:30:02 +01:00
|
|
|
function ws_add_image_category_relations($image_id, $categories_string, $replace_mode=false)
|
2008-12-03 23:55:17 +01:00
|
|
|
{
|
|
|
|
// 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
|
|
|
|
$cat_ids = array();
|
|
|
|
$rank_on_category = array();
|
|
|
|
$search_current_ranks = false;
|
|
|
|
|
|
|
|
$tokens = explode(';', $categories_string);
|
|
|
|
foreach ($tokens as $token)
|
|
|
|
{
|
2008-12-03 23:56:24 +01:00
|
|
|
@list($cat_id, $rank) = explode(',', $token);
|
2008-12-03 23:55:17 +01:00
|
|
|
|
2009-12-07 23:30:02 +01:00
|
|
|
if (!preg_match('/^\d+$/', $cat_id))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-12-03 23:55:17 +01:00
|
|
|
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);
|
|
|
|
|
2009-12-07 23:30:02 +01:00
|
|
|
if (count($cat_ids) == 0)
|
|
|
|
{
|
2011-12-27 06:26:44 +01:00
|
|
|
return new PwgError(
|
2009-12-07 23:30:02 +01:00
|
|
|
500,
|
|
|
|
'[ws_add_image_category_relations] there is no category defined in "'.$categories_string.'"'
|
|
|
|
);
|
|
|
|
}
|
2009-12-18 22:12:41 +01:00
|
|
|
|
2009-12-07 23:30:02 +01:00
|
|
|
$query = '
|
|
|
|
SELECT
|
|
|
|
id
|
|
|
|
FROM '.CATEGORIES_TABLE.'
|
|
|
|
WHERE id IN ('.implode(',', $cat_ids).')
|
|
|
|
;';
|
|
|
|
$db_cat_ids = array_from_query($query, 'id');
|
|
|
|
|
|
|
|
$unknown_cat_ids = array_diff($cat_ids, $db_cat_ids);
|
|
|
|
if (count($unknown_cat_ids) != 0)
|
|
|
|
{
|
2011-12-27 06:26:44 +01:00
|
|
|
return new PwgError(
|
2009-12-07 23:30:02 +01:00
|
|
|
500,
|
|
|
|
'[ws_add_image_category_relations] the following categories are unknown: '.implode(', ', $unknown_cat_ids)
|
|
|
|
);
|
|
|
|
}
|
2009-12-18 22:12:41 +01:00
|
|
|
|
2009-12-07 23:30:02 +01:00
|
|
|
$to_update_cat_ids = array();
|
2009-12-18 22:12:41 +01:00
|
|
|
|
2009-12-07 23:30:02 +01:00
|
|
|
// in case of replace mode, we first check the existing associations
|
|
|
|
$query = '
|
|
|
|
SELECT
|
|
|
|
category_id
|
|
|
|
FROM '.IMAGE_CATEGORY_TABLE.'
|
|
|
|
WHERE image_id = '.$image_id.'
|
|
|
|
;';
|
|
|
|
$existing_cat_ids = array_from_query($query, 'category_id');
|
|
|
|
|
|
|
|
if ($replace_mode)
|
2008-12-03 23:55:17 +01:00
|
|
|
{
|
2009-12-07 23:30:02 +01:00
|
|
|
$to_remove_cat_ids = array_diff($existing_cat_ids, $cat_ids);
|
|
|
|
if (count($to_remove_cat_ids) > 0)
|
2008-12-03 23:55:17 +01:00
|
|
|
{
|
|
|
|
$query = '
|
2009-12-07 23:30:02 +01:00
|
|
|
DELETE
|
|
|
|
FROM '.IMAGE_CATEGORY_TABLE.'
|
|
|
|
WHERE image_id = '.$image_id.'
|
|
|
|
AND category_id IN ('.implode(', ', $to_remove_cat_ids).')
|
|
|
|
;';
|
|
|
|
pwg_query($query);
|
|
|
|
update_category($to_remove_cat_ids);
|
|
|
|
}
|
|
|
|
}
|
2009-12-18 22:12:41 +01:00
|
|
|
|
2009-12-07 23:30:02 +01:00
|
|
|
$new_cat_ids = array_diff($cat_ids, $existing_cat_ids);
|
|
|
|
if (count($new_cat_ids) == 0)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2009-12-18 22:12:41 +01:00
|
|
|
|
2009-12-07 23:30:02 +01:00
|
|
|
if ($search_current_ranks)
|
|
|
|
{
|
|
|
|
$query = '
|
2008-12-03 23:55:17 +01:00
|
|
|
SELECT
|
|
|
|
category_id,
|
|
|
|
MAX(rank) AS max_rank
|
|
|
|
FROM '.IMAGE_CATEGORY_TABLE.'
|
|
|
|
WHERE rank IS NOT NULL
|
2009-12-07 23:30:02 +01:00
|
|
|
AND category_id IN ('.implode(',', $new_cat_ids).')
|
2008-12-03 23:55:17 +01:00
|
|
|
GROUP BY category_id
|
|
|
|
;';
|
2009-12-07 23:30:02 +01:00
|
|
|
$current_rank_of = simple_hash_from_query(
|
|
|
|
$query,
|
|
|
|
'category_id',
|
|
|
|
'max_rank'
|
|
|
|
);
|
2008-12-03 23:55:17 +01:00
|
|
|
|
2009-12-07 23:30:02 +01:00
|
|
|
foreach ($new_cat_ids as $cat_id)
|
|
|
|
{
|
|
|
|
if (!isset($current_rank_of[$cat_id]))
|
2008-12-03 23:55:17 +01:00
|
|
|
{
|
2009-12-07 23:30:02 +01:00
|
|
|
$current_rank_of[$cat_id] = 0;
|
|
|
|
}
|
2009-12-18 22:12:41 +01:00
|
|
|
|
2009-12-07 23:30:02 +01:00
|
|
|
if ('auto' == $rank_on_category[$cat_id])
|
|
|
|
{
|
|
|
|
$rank_on_category[$cat_id] = $current_rank_of[$cat_id] + 1;
|
2008-12-03 23:55:17 +01:00
|
|
|
}
|
|
|
|
}
|
2009-12-07 23:30:02 +01:00
|
|
|
}
|
2009-12-18 22:12:41 +01:00
|
|
|
|
2009-12-07 23:30:02 +01:00
|
|
|
$inserts = array();
|
2009-12-18 22:12:41 +01:00
|
|
|
|
2009-12-07 23:30:02 +01:00
|
|
|
foreach ($new_cat_ids as $cat_id)
|
|
|
|
{
|
|
|
|
array_push(
|
|
|
|
$inserts,
|
|
|
|
array(
|
|
|
|
'image_id' => $image_id,
|
|
|
|
'category_id' => $cat_id,
|
|
|
|
'rank' => $rank_on_category[$cat_id],
|
|
|
|
)
|
2008-12-03 23:55:17 +01:00
|
|
|
);
|
|
|
|
}
|
2009-12-18 22:12:41 +01:00
|
|
|
|
2009-12-07 23:30:02 +01:00
|
|
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
|
|
|
mass_inserts(
|
|
|
|
IMAGE_CATEGORY_TABLE,
|
|
|
|
array_keys($inserts[0]),
|
|
|
|
$inserts
|
|
|
|
);
|
2009-12-18 22:12:41 +01:00
|
|
|
|
2009-12-07 23:30:02 +01:00
|
|
|
update_category($new_cat_ids);
|
2008-12-03 23:55:17 +01:00
|
|
|
}
|
2009-03-13 00:14:50 +01:00
|
|
|
|
2009-06-25 01:01:35 +02:00
|
|
|
function ws_categories_setInfo($params, &$service)
|
|
|
|
{
|
|
|
|
global $conf;
|
2010-12-14 14:47:24 +01:00
|
|
|
if (!is_admin())
|
2009-06-25 01:01:35 +02:00
|
|
|
{
|
|
|
|
return new PwgError(401, 'Access denied');
|
|
|
|
}
|
|
|
|
|
2009-12-18 01:45:03 +01:00
|
|
|
if (!$service->isPost())
|
|
|
|
{
|
|
|
|
return new PwgError(405, "This method requires HTTP POST");
|
|
|
|
}
|
|
|
|
|
2009-06-25 01:01:35 +02:00
|
|
|
// category_id
|
|
|
|
// name
|
|
|
|
// comment
|
|
|
|
|
|
|
|
$params['category_id'] = (int)$params['category_id'];
|
|
|
|
if ($params['category_id'] <= 0)
|
|
|
|
{
|
|
|
|
return new PwgError(WS_ERR_INVALID_PARAM, "Invalid category_id");
|
|
|
|
}
|
|
|
|
|
|
|
|
// database registration
|
|
|
|
$update = array(
|
|
|
|
'id' => $params['category_id'],
|
|
|
|
);
|
|
|
|
|
|
|
|
$info_columns = array(
|
|
|
|
'name',
|
|
|
|
'comment',
|
|
|
|
);
|
|
|
|
|
|
|
|
$perform_update = false;
|
|
|
|
foreach ($info_columns as $key)
|
|
|
|
{
|
|
|
|
if (isset($params[$key]))
|
|
|
|
{
|
|
|
|
$perform_update = true;
|
|
|
|
$update[$key] = $params[$key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($perform_update)
|
|
|
|
{
|
|
|
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
|
|
|
mass_updates(
|
|
|
|
CATEGORIES_TABLE,
|
|
|
|
array(
|
|
|
|
'primary' => array('id'),
|
|
|
|
'update' => array_diff(array_keys($update), array('id'))
|
|
|
|
),
|
|
|
|
array($update)
|
|
|
|
);
|
|
|
|
}
|
2009-07-01 22:56:41 +02:00
|
|
|
|
2009-06-25 01:01:35 +02:00
|
|
|
}
|
|
|
|
|
2011-07-14 23:44:14 +02:00
|
|
|
function ws_categories_setRepresentative($params, &$service)
|
|
|
|
{
|
|
|
|
global $conf;
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2011-07-14 23:44:14 +02:00
|
|
|
if (!is_admin())
|
|
|
|
{
|
|
|
|
return new PwgError(401, 'Access denied');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$service->isPost())
|
|
|
|
{
|
|
|
|
return new PwgError(405, "This method requires HTTP POST");
|
|
|
|
}
|
|
|
|
|
|
|
|
// category_id
|
|
|
|
// image_id
|
|
|
|
|
|
|
|
$params['category_id'] = (int)$params['category_id'];
|
|
|
|
if ($params['category_id'] <= 0)
|
|
|
|
{
|
|
|
|
return new PwgError(WS_ERR_INVALID_PARAM, "Invalid category_id");
|
|
|
|
}
|
|
|
|
|
|
|
|
// does the category really exist?
|
|
|
|
$query='
|
|
|
|
SELECT
|
|
|
|
*
|
|
|
|
FROM '.CATEGORIES_TABLE.'
|
|
|
|
WHERE id = '.$params['category_id'].'
|
|
|
|
;';
|
|
|
|
$row = pwg_db_fetch_assoc(pwg_query($query));
|
|
|
|
if ($row == null)
|
|
|
|
{
|
|
|
|
return new PwgError(404, "category_id not found");
|
|
|
|
}
|
|
|
|
|
|
|
|
$params['image_id'] = (int)$params['image_id'];
|
|
|
|
if ($params['image_id'] <= 0)
|
|
|
|
{
|
|
|
|
return new PwgError(WS_ERR_INVALID_PARAM, "Invalid image_id");
|
|
|
|
}
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2011-07-14 23:44:14 +02:00
|
|
|
// does the image really exist?
|
|
|
|
$query='
|
|
|
|
SELECT
|
|
|
|
*
|
|
|
|
FROM '.IMAGES_TABLE.'
|
|
|
|
WHERE id = '.$params['image_id'].'
|
|
|
|
;';
|
|
|
|
|
|
|
|
$row = pwg_db_fetch_assoc(pwg_query($query));
|
|
|
|
if ($row == null)
|
|
|
|
{
|
|
|
|
return new PwgError(404, "image_id not found");
|
|
|
|
}
|
|
|
|
|
|
|
|
// apply change
|
|
|
|
$query = '
|
|
|
|
UPDATE '.CATEGORIES_TABLE.'
|
|
|
|
SET representative_picture_id = '.$params['image_id'].'
|
|
|
|
WHERE id = '.$params['category_id'].'
|
|
|
|
;';
|
|
|
|
pwg_query($query);
|
|
|
|
|
|
|
|
$query = '
|
|
|
|
UPDATE '.USER_CACHE_CATEGORIES_TABLE.'
|
|
|
|
SET user_representative_picture_id = NULL
|
|
|
|
WHERE cat_id = '.$params['category_id'].'
|
|
|
|
;';
|
|
|
|
pwg_query($query);
|
|
|
|
}
|
|
|
|
|
2010-12-23 21:51:33 +01:00
|
|
|
function ws_categories_delete($params, &$service)
|
|
|
|
{
|
|
|
|
global $conf;
|
2010-12-24 00:15:24 +01:00
|
|
|
if (!is_admin())
|
2010-12-23 21:51:33 +01:00
|
|
|
{
|
|
|
|
return new PwgError(401, 'Access denied');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$service->isPost())
|
|
|
|
{
|
|
|
|
return new PwgError(405, "This method requires HTTP POST");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token'])
|
|
|
|
{
|
|
|
|
return new PwgError(403, 'Invalid security token');
|
|
|
|
}
|
|
|
|
|
|
|
|
$modes = array('no_delete', 'delete_orphans', 'force_delete');
|
|
|
|
if (!in_array($params['photo_deletion_mode'], $modes))
|
|
|
|
{
|
|
|
|
return new PwgError(
|
|
|
|
500,
|
|
|
|
'[ws_categories_delete]'
|
|
|
|
.' invalid parameter photo_deletion_mode "'.$params['photo_deletion_mode'].'"'
|
|
|
|
.', possible values are {'.implode(', ', $modes).'}.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$params['category_id'] = preg_split(
|
|
|
|
'/[\s,;\|]/',
|
|
|
|
$params['category_id'],
|
|
|
|
-1,
|
|
|
|
PREG_SPLIT_NO_EMPTY
|
|
|
|
);
|
|
|
|
$params['category_id'] = array_map('intval', $params['category_id']);
|
|
|
|
|
|
|
|
$category_ids = array();
|
|
|
|
foreach ($params['category_id'] as $category_id)
|
|
|
|
{
|
|
|
|
if ($category_id > 0)
|
|
|
|
{
|
|
|
|
array_push($category_ids, $category_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count($category_ids) == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$query = '
|
|
|
|
SELECT id
|
|
|
|
FROM '.CATEGORIES_TABLE.'
|
|
|
|
WHERE id IN ('.implode(',', $category_ids).')
|
|
|
|
;';
|
|
|
|
$category_ids = array_from_query($query, 'id');
|
|
|
|
|
|
|
|
if (count($category_ids) == 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2010-12-23 21:51:33 +01:00
|
|
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
|
|
|
delete_categories($category_ids, $params['photo_deletion_mode']);
|
|
|
|
update_global_rank();
|
|
|
|
}
|
|
|
|
|
2010-12-23 23:41:28 +01:00
|
|
|
function ws_categories_move($params, &$service)
|
|
|
|
{
|
|
|
|
global $conf, $page;
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2010-12-24 00:15:24 +01:00
|
|
|
if (!is_admin())
|
2010-12-23 23:41:28 +01:00
|
|
|
{
|
|
|
|
return new PwgError(401, 'Access denied');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$service->isPost())
|
|
|
|
{
|
|
|
|
return new PwgError(405, "This method requires HTTP POST");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token'])
|
|
|
|
{
|
|
|
|
return new PwgError(403, 'Invalid security token');
|
|
|
|
}
|
|
|
|
|
|
|
|
$params['category_id'] = preg_split(
|
|
|
|
'/[\s,;\|]/',
|
|
|
|
$params['category_id'],
|
|
|
|
-1,
|
|
|
|
PREG_SPLIT_NO_EMPTY
|
|
|
|
);
|
|
|
|
$params['category_id'] = array_map('intval', $params['category_id']);
|
|
|
|
|
|
|
|
$category_ids = array();
|
|
|
|
foreach ($params['category_id'] as $category_id)
|
|
|
|
{
|
|
|
|
if ($category_id > 0)
|
|
|
|
{
|
|
|
|
array_push($category_ids, $category_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count($category_ids) == 0)
|
|
|
|
{
|
|
|
|
return new PwgError(403, 'Invalid category_id input parameter, no category to move');
|
|
|
|
}
|
|
|
|
|
|
|
|
// we can't move physical categories
|
|
|
|
$categories_in_db = array();
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2010-12-23 23:41:28 +01:00
|
|
|
$query = '
|
|
|
|
SELECT
|
|
|
|
id,
|
|
|
|
name,
|
|
|
|
dir
|
|
|
|
FROM '.CATEGORIES_TABLE.'
|
|
|
|
WHERE id IN ('.implode(',', $category_ids).')
|
|
|
|
;';
|
|
|
|
$result = pwg_query($query);
|
|
|
|
while ($row = pwg_db_fetch_assoc($result))
|
|
|
|
{
|
|
|
|
$categories_in_db[$row['id']] = $row;
|
|
|
|
// we break on error at first physical category detected
|
|
|
|
if (!empty($row['dir']))
|
|
|
|
{
|
|
|
|
$row['name'] = strip_tags(
|
|
|
|
trigger_event(
|
|
|
|
'render_category_name',
|
|
|
|
$row['name'],
|
|
|
|
'ws_categories_move'
|
|
|
|
)
|
|
|
|
);
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2010-12-23 23:41:28 +01:00
|
|
|
return new PwgError(
|
|
|
|
403,
|
|
|
|
sprintf(
|
|
|
|
'Category %s (%u) is not a virtual category, you cannot move it',
|
|
|
|
$row['name'],
|
|
|
|
$row['id']
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count($categories_in_db) != count($category_ids))
|
|
|
|
{
|
|
|
|
$unknown_category_ids = array_diff($category_ids, array_keys($categories_in_db));
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2010-12-23 23:41:28 +01:00
|
|
|
return new PwgError(
|
|
|
|
403,
|
|
|
|
sprintf(
|
|
|
|
'Category %u does not exist',
|
|
|
|
$unknown_category_ids[0]
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// does this parent exists? This check should be made in the
|
|
|
|
// move_categories function, not here
|
|
|
|
//
|
|
|
|
// 0 as parent means "move categories at gallery root"
|
|
|
|
if (!is_numeric($params['parent']))
|
|
|
|
{
|
|
|
|
return new PwgError(403, 'Invalid parent input parameter');
|
|
|
|
}
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2010-12-23 23:41:28 +01:00
|
|
|
if (0 != $params['parent']) {
|
|
|
|
$params['parent'] = intval($params['parent']);
|
|
|
|
$subcat_ids = get_subcat_ids(array($params['parent']));
|
|
|
|
if (count($subcat_ids) == 0)
|
|
|
|
{
|
|
|
|
return new PwgError(403, 'Unknown parent category id');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$page['infos'] = array();
|
|
|
|
$page['errors'] = array();
|
|
|
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
|
|
|
move_categories($category_ids, $params['parent']);
|
|
|
|
invalidate_user_cache();
|
|
|
|
|
|
|
|
if (count($page['errors']) != 0)
|
|
|
|
{
|
|
|
|
return new PwgError(403, implode('; ', $page['errors']));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-13 00:14:50 +01:00
|
|
|
function ws_logfile($string)
|
|
|
|
{
|
2009-07-21 23:41:31 +02:00
|
|
|
global $conf;
|
|
|
|
|
|
|
|
if (!$conf['ws_enable_log']) {
|
|
|
|
return true;
|
|
|
|
}
|
2009-07-01 22:56:41 +02:00
|
|
|
|
2009-03-13 00:14:50 +01:00
|
|
|
file_put_contents(
|
2009-07-21 23:41:31 +02:00
|
|
|
$conf['ws_log_filepath'],
|
2009-03-13 00:14:50 +01:00
|
|
|
'['.date('c').'] '.$string."\n",
|
|
|
|
FILE_APPEND
|
|
|
|
);
|
|
|
|
}
|
2010-05-03 11:09:40 +02:00
|
|
|
|
|
|
|
function ws_images_checkUpload($params, &$service)
|
|
|
|
{
|
|
|
|
global $conf;
|
|
|
|
|
2010-12-14 14:47:24 +01:00
|
|
|
if (!is_admin())
|
2010-05-03 11:09:40 +02:00
|
|
|
{
|
|
|
|
return new PwgError(401, 'Access denied');
|
|
|
|
}
|
|
|
|
|
2010-12-23 11:22:51 +01:00
|
|
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
|
2010-05-03 11:56:22 +02:00
|
|
|
$ret['message'] = ready_for_upload_message();
|
2010-05-03 11:09:40 +02:00
|
|
|
$ret['ready_for_upload'] = true;
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2010-05-03 11:56:22 +02:00
|
|
|
if (!empty($ret['message']))
|
|
|
|
{
|
|
|
|
$ret['ready_for_upload'] = false;
|
|
|
|
}
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2010-05-03 11:56:22 +02:00
|
|
|
return $ret;
|
|
|
|
}
|
2010-12-24 00:12:03 +01:00
|
|
|
|
|
|
|
function ws_plugins_getList($params, &$service)
|
|
|
|
{
|
|
|
|
global $conf;
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2010-12-24 00:12:03 +01:00
|
|
|
if (!is_admin())
|
|
|
|
{
|
|
|
|
return new PwgError(401, 'Access denied');
|
|
|
|
}
|
|
|
|
|
|
|
|
include_once(PHPWG_ROOT_PATH.'admin/include/plugins.class.php');
|
|
|
|
$plugins = new plugins();
|
|
|
|
$plugins->sort_fs_plugins('name');
|
|
|
|
$plugin_list = array();
|
|
|
|
|
|
|
|
foreach($plugins->fs_plugins as $plugin_id => $fs_plugin)
|
|
|
|
{
|
|
|
|
if (isset($plugins->db_plugins_by_id[$plugin_id]))
|
|
|
|
{
|
|
|
|
$state = $plugins->db_plugins_by_id[$plugin_id]['state'];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$state = 'uninstalled';
|
|
|
|
}
|
|
|
|
|
|
|
|
array_push(
|
|
|
|
$plugin_list,
|
|
|
|
array(
|
|
|
|
'id' => $plugin_id,
|
|
|
|
'name' => $fs_plugin['name'],
|
|
|
|
'version' => $fs_plugin['version'],
|
|
|
|
'state' => $state,
|
|
|
|
'description' => $fs_plugin['description'],
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $plugin_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
function ws_plugins_performAction($params, &$service)
|
|
|
|
{
|
|
|
|
global $template;
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2010-12-24 00:12:03 +01:00
|
|
|
if (!is_admin())
|
|
|
|
{
|
|
|
|
return new PwgError(401, 'Access denied');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token'])
|
|
|
|
{
|
|
|
|
return new PwgError(403, 'Invalid security token');
|
|
|
|
}
|
|
|
|
|
|
|
|
define('IN_ADMIN', true);
|
|
|
|
include_once(PHPWG_ROOT_PATH.'admin/include/plugins.class.php');
|
|
|
|
$plugins = new plugins();
|
|
|
|
$errors = $plugins->perform_action($params['action'], $params['plugin']);
|
|
|
|
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2010-12-24 00:12:03 +01:00
|
|
|
if (!empty($errors))
|
|
|
|
{
|
|
|
|
return new PwgError(500, $errors);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (in_array($params['action'], array('activate', 'deactivate')))
|
|
|
|
{
|
|
|
|
$template->delete_compiled_templates();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-24 19:03:30 +01:00
|
|
|
function ws_themes_performAction($params, &$service)
|
|
|
|
{
|
|
|
|
global $template;
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2011-01-17 22:16:42 +01:00
|
|
|
if (!is_admin())
|
2010-12-24 19:03:30 +01:00
|
|
|
{
|
|
|
|
return new PwgError(401, 'Access denied');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token'])
|
|
|
|
{
|
|
|
|
return new PwgError(403, 'Invalid security token');
|
|
|
|
}
|
|
|
|
|
|
|
|
define('IN_ADMIN', true);
|
|
|
|
include_once(PHPWG_ROOT_PATH.'admin/include/themes.class.php');
|
|
|
|
$themes = new themes();
|
|
|
|
$errors = $themes->perform_action($params['action'], $params['theme']);
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2010-12-24 19:03:30 +01:00
|
|
|
if (!empty($errors))
|
|
|
|
{
|
|
|
|
return new PwgError(500, $errors);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (in_array($params['action'], array('activate', 'deactivate')))
|
|
|
|
{
|
|
|
|
$template->delete_compiled_templates();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2011-04-10 10:59:02 +02:00
|
|
|
|
2011-04-20 16:52:52 +02:00
|
|
|
function ws_extensions_update($params, &$service)
|
|
|
|
{
|
|
|
|
if (!is_webmaster())
|
|
|
|
{
|
|
|
|
return new PwgError(401, l10n('Webmaster status is required.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token'])
|
|
|
|
{
|
|
|
|
return new PwgError(403, 'Invalid security token');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($params['type']) or !in_array($params['type'], array('plugins', 'themes', 'languages')))
|
|
|
|
{
|
|
|
|
return new PwgError(403, "invalid extension type");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($params['id']) or empty($params['revision']))
|
|
|
|
{
|
|
|
|
return new PwgError(null, 'Wrong parameters');
|
|
|
|
}
|
|
|
|
|
|
|
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
|
|
|
include_once(PHPWG_ROOT_PATH.'admin/include/'.$params['type'].'.class.php');
|
|
|
|
|
|
|
|
$type = $params['type'];
|
|
|
|
$extension_id = $params['id'];
|
|
|
|
$revision = $params['revision'];
|
|
|
|
|
|
|
|
$extension = new $type();
|
|
|
|
|
|
|
|
if ($type == 'plugins')
|
|
|
|
{
|
|
|
|
if (isset($extension->db_plugins_by_id[$extension_id]) and $extension->db_plugins_by_id[$extension_id]['state'] == 'active')
|
|
|
|
{
|
|
|
|
$extension->perform_action('deactivate', $extension_id);
|
|
|
|
|
|
|
|
redirect(PHPWG_ROOT_PATH
|
|
|
|
. 'ws.php'
|
|
|
|
. '?method=pwg.extensions.update'
|
|
|
|
. '&type=plugins'
|
|
|
|
. '&id=' . $extension_id
|
|
|
|
. '&revision=' . $revision
|
|
|
|
. '&reactivate=true'
|
|
|
|
. '&pwg_token=' . get_pwg_token()
|
|
|
|
. '&format=json'
|
|
|
|
);
|
|
|
|
}
|
2011-08-02 21:20:50 +02:00
|
|
|
|
2011-04-20 16:52:52 +02:00
|
|
|
$upgrade_status = $extension->extract_plugin_files('upgrade', $revision, $extension_id);
|
|
|
|
$extension_name = $extension->fs_plugins[$extension_id]['name'];
|
|
|
|
|
|
|
|
if (isset($params['reactivate']))
|
|
|
|
{
|
|
|
|
$extension->perform_action('activate', $extension_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elseif ($type == 'themes')
|
|
|
|
{
|
|
|
|
$upgrade_status = $extension->extract_theme_files('upgrade', $revision, $extension_id);
|
|
|
|
$extension_name = $extension->fs_themes[$extension_id]['name'];
|
|
|
|
}
|
|
|
|
elseif ($type == 'languages')
|
|
|
|
{
|
|
|
|
$upgrade_status = $extension->extract_language_files('upgrade', $revision, $extension_id);
|
|
|
|
$extension_name = $extension->fs_languages[$extension_id]['name'];
|
|
|
|
}
|
|
|
|
|
|
|
|
global $template;
|
|
|
|
$template->delete_compiled_templates();
|
|
|
|
|
|
|
|
switch ($upgrade_status)
|
|
|
|
{
|
|
|
|
case 'ok':
|
|
|
|
return sprintf(l10n('%s has been successfully updated.'), $extension_name);
|
|
|
|
|
|
|
|
case 'temp_path_error':
|
|
|
|
return new PwgError(null, l10n('Can\'t create temporary file.'));
|
|
|
|
|
|
|
|
case 'dl_archive_error':
|
|
|
|
return new PwgError(null, l10n('Can\'t download archive.'));
|
|
|
|
|
|
|
|
case 'archive_error':
|
|
|
|
return new PwgError(null, l10n('Can\'t read or extract archive.'));
|
|
|
|
|
|
|
|
default:
|
|
|
|
return new PwgError(null, sprintf(l10n('An error occured during extraction (%s).'), $upgrade_status));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function ws_extensions_ignoreupdate($params, &$service)
|
|
|
|
{
|
|
|
|
global $conf;
|
|
|
|
|
|
|
|
define('IN_ADMIN', true);
|
|
|
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
|
|
|
|
|
|
|
if (!is_webmaster())
|
|
|
|
{
|
|
|
|
return new PwgError(401, 'Access denied');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($params['pwg_token']) or get_pwg_token() != $params['pwg_token'])
|
|
|
|
{
|
|
|
|
return new PwgError(403, 'Invalid security token');
|
|
|
|
}
|
|
|
|
|
|
|
|
$conf['updates_ignored'] = unserialize($conf['updates_ignored']);
|
|
|
|
|
2011-04-21 17:12:38 +02:00
|
|
|
// Reset ignored extension
|
2011-04-20 16:52:52 +02:00
|
|
|
if ($params['reset'])
|
|
|
|
{
|
2011-04-23 15:32:08 +02:00
|
|
|
if (!empty($params['type']) and isset($conf['updates_ignored'][$params['type']]))
|
|
|
|
{
|
|
|
|
$conf['updates_ignored'][$params['type']] = array();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$conf['updates_ignored'] = array(
|
|
|
|
'plugins'=>array(),
|
|
|
|
'themes'=>array(),
|
|
|
|
'languages'=>array()
|
|
|
|
);
|
|
|
|
}
|
2011-04-20 16:52:52 +02:00
|
|
|
conf_update_param('updates_ignored', pwg_db_real_escape_string(serialize($conf['updates_ignored'])));
|
|
|
|
unset($_SESSION['extensions_need_update']);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($params['id']) or empty($params['type']) or !in_array($params['type'], array('plugins', 'themes', 'languages')))
|
|
|
|
{
|
|
|
|
return new PwgError(403, 'Invalid parameters');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add or remove extension from ignore list
|
|
|
|
if (!in_array($params['id'], $conf['updates_ignored'][$params['type']]))
|
|
|
|
{
|
|
|
|
array_push($conf['updates_ignored'][$params['type']], $params['id']);
|
|
|
|
}
|
|
|
|
conf_update_param('updates_ignored', pwg_db_real_escape_string(serialize($conf['updates_ignored'])));
|
|
|
|
unset($_SESSION['extensions_need_update']);
|
|
|
|
return true;
|
|
|
|
}
|
2011-04-21 17:12:38 +02:00
|
|
|
|
|
|
|
function ws_extensions_checkupdates($params, &$service)
|
|
|
|
{
|
|
|
|
global $conf;
|
|
|
|
|
|
|
|
define('IN_ADMIN', true);
|
|
|
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
|
|
|
include_once(PHPWG_ROOT_PATH.'admin/include/updates.class.php');
|
|
|
|
$update = new updates();
|
|
|
|
|
|
|
|
if (!is_admin())
|
|
|
|
{
|
|
|
|
return new PwgError(401, 'Access denied');
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = array();
|
|
|
|
|
|
|
|
if (!isset($_SESSION['need_update']))
|
|
|
|
$update->check_piwigo_upgrade();
|
|
|
|
|
|
|
|
$result['piwigo_need_update'] = $_SESSION['need_update'];
|
|
|
|
|
|
|
|
$conf['updates_ignored'] = unserialize($conf['updates_ignored']);
|
|
|
|
|
|
|
|
if (!isset($_SESSION['extensions_need_update']))
|
|
|
|
$update->check_extensions();
|
|
|
|
else
|
|
|
|
$update->check_updated_extensions();
|
|
|
|
|
|
|
|
if (!is_array($_SESSION['extensions_need_update']))
|
|
|
|
$result['ext_need_update'] = null;
|
|
|
|
else
|
|
|
|
$result['ext_need_update'] = !empty($_SESSION['extensions_need_update']);
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
2011-12-13 16:00:32 +01:00
|
|
|
?>
|