2007-01-06 12:13:08 +01:00
|
|
|
<?php
|
|
|
|
// +-----------------------------------------------------------------------+
|
2008-04-05 00:57:23 +02:00
|
|
|
// | Piwigo - a PHP based picture gallery |
|
|
|
|
// +-----------------------------------------------------------------------+
|
2009-01-05 00:28:36 +01:00
|
|
|
// | Copyright(C) 2008-2009 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']) )
|
|
|
|
{
|
|
|
|
$clauses[] = $tbl_name.'average_rate>'.$params['f_min_rate'];
|
|
|
|
}
|
|
|
|
if ( is_numeric($params['f_max_rate']) )
|
|
|
|
{
|
|
|
|
$clauses[] = $tbl_name.'average_rate<='.$params['f_max_rate'];
|
|
|
|
}
|
|
|
|
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'];
|
|
|
|
}
|
|
|
|
if ( isset($params['f_min_date_posted']) )
|
|
|
|
{
|
|
|
|
$clauses[] = $tbl_name."date_available>='".$params['f_min_date_posted']."'";
|
|
|
|
}
|
|
|
|
if ( isset($params['f_max_date_posted']) )
|
|
|
|
{
|
|
|
|
$clauses[] = $tbl_name."date_available<'".$params['f_max_date_posted']."'";
|
|
|
|
}
|
|
|
|
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'];
|
|
|
|
}
|
|
|
|
if ( $params['f_with_thumbnail'] )
|
|
|
|
{
|
|
|
|
$clauses[] = $tbl_name.'tn_ext IS NOT NULL';
|
|
|
|
}
|
|
|
|
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':
|
|
|
|
$matches[1][$i] = 'RAND()'; break;
|
|
|
|
}
|
2007-01-11 06:10:16 +01:00
|
|
|
$sortable_fields = array('id', 'file', 'name', 'hit', 'average_rate',
|
2007-01-06 12:13:08 +01:00
|
|
|
'date_creation', 'date_available', 'RAND()' );
|
|
|
|
if ( in_array($matches[1][$i], $sortable_fields) )
|
|
|
|
{
|
|
|
|
if (!empty($ret))
|
|
|
|
$ret .= ', ';
|
|
|
|
if ($matches[1][$i] != 'RAND()' )
|
|
|
|
{
|
|
|
|
$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)
|
|
|
|
{
|
|
|
|
$ret = array(
|
2007-01-11 06:10:16 +01:00
|
|
|
'tn_url' => get_thumbnail_url($image_row),
|
2007-01-06 12:13:08 +01:00
|
|
|
'element_url' => get_element_url($image_row)
|
|
|
|
);
|
|
|
|
global $user;
|
|
|
|
if ($user['enabled_high'] and $image_row['has_high'] )
|
|
|
|
{
|
|
|
|
$ret['high_url'] = get_high_url($image_row);
|
|
|
|
}
|
|
|
|
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(
|
|
|
|
'id','tn_url','element_url','high_url', 'file','width','height','hit'
|
|
|
|
);
|
|
|
|
}
|
2007-01-06 12:13:08 +01:00
|
|
|
|
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;
|
|
|
|
if ($conf['show_version'])
|
|
|
|
return PHPWG_VERSION;
|
|
|
|
else
|
|
|
|
return new PwgError(403, 'Forbidden');
|
2007-01-06 12:13:08 +01:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
@include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
|
|
|
|
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'])
|
|
|
|
{
|
|
|
|
$where_clauses[] = 'uppercats REGEXP \'(^|,)'.$cat_id.'(,|$)\'';
|
|
|
|
}
|
|
|
|
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 = '
|
|
|
|
SELECT i.*, GROUP_CONCAT(category_id) cat_ids
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
}
|
2007-03-08 02:55:49 +01:00
|
|
|
foreach ( array('file', 'name', 'comment') 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
|
|
|
|
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
|
|
|
|
|
|
|
$where = array();
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
$where[] = 'uppercats REGEXP \'(^|,)'.
|
|
|
|
(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"';
|
2007-02-15 01:10:41 +01:00
|
|
|
$where[]= 'user_id='.$conf['guest_id'];
|
2007-01-06 12:13:08 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-02-15 01:10:41 +01:00
|
|
|
$where[]= 'user_id='.$user['id'];
|
2007-01-06 12:13:08 +01:00
|
|
|
}
|
|
|
|
|
2007-01-11 06:10:16 +01:00
|
|
|
$query = '
|
2007-02-28 04:07:12 +01:00
|
|
|
SELECT id, name, permalink, uppercats, global_rank,
|
2007-02-21 01:20:02 +01:00
|
|
|
nb_images, count_images AS total_nb_images,
|
|
|
|
date_last, max_date_last, count_categories AS nb_categories
|
2007-01-11 06:10:16 +01:00
|
|
|
FROM '.CATEGORIES_TABLE.'
|
|
|
|
INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' ON id=cat_id
|
2007-01-06 12:13:08 +01:00
|
|
|
WHERE '. implode('
|
|
|
|
AND ', $where);
|
|
|
|
|
|
|
|
$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['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
|
|
|
|
2007-01-06 12:13:08 +01:00
|
|
|
array_push($cats, $row);
|
|
|
|
}
|
|
|
|
usort($cats, 'global_rank_compare');
|
|
|
|
return array(
|
2008-09-17 23:42:50 +02:00
|
|
|
'categories' => new PwgNamedArray(
|
|
|
|
$cats,
|
|
|
|
'category',
|
|
|
|
array(
|
|
|
|
'id',
|
|
|
|
'url',
|
|
|
|
'nb_images',
|
|
|
|
'total_nb_images',
|
|
|
|
'nb_categories',
|
|
|
|
'date_last',
|
|
|
|
'max_date_last',
|
|
|
|
)
|
|
|
|
)
|
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,
|
|
|
|
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;
|
|
|
|
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(
|
2009-11-18 21:07:20 +01:00
|
|
|
'author' => trim( stripslashes($params['author']) ),
|
|
|
|
'content' => trim( stripslashes($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':
|
|
|
|
array_push($infos, l10n('comment_not_added') );
|
|
|
|
return new PwgError(403, implode("\n", $infos) );
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
@include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
|
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
|
|
|
|
$query = '
|
|
|
|
SELECT COUNT(rate) AS count
|
|
|
|
, ROUND(AVG(rate),2) AS average
|
|
|
|
, ROUND(STD(rate),2) AS stdev
|
|
|
|
FROM '.RATE_TABLE.'
|
|
|
|
WHERE element_id = '.$image_row['id'].'
|
|
|
|
;';
|
2009-11-20 15:17:04 +01:00
|
|
|
$rating = pwg_db_fetch_assoc(pwg_query($query));
|
2007-02-22 02:12:32 +01:00
|
|
|
$rating['count'] = (int)$rating['count'];
|
|
|
|
|
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 = '
|
|
|
|
SELECT COUNT(id) nb_comments
|
|
|
|
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']);
|
2007-02-22 02:12:32 +01:00
|
|
|
$comment_post_data['key'] = get_comment_post_key($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' );
|
|
|
|
include_once(PHPWG_ROOT_PATH.'include/functions_picture.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];
|
|
|
|
}
|
|
|
|
}
|
2007-03-08 02:55:49 +01:00
|
|
|
foreach ( array('file', 'name', 'comment') 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)
|
|
|
|
{
|
|
|
|
if (!is_admin() || is_adviser() )
|
|
|
|
{
|
|
|
|
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-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");
|
|
|
|
}
|
|
|
|
$query = '
|
|
|
|
UPDATE '.IMAGES_TABLE.'
|
|
|
|
SET level='.(int)$params['level'].'
|
|
|
|
WHERE id IN ('.implode(',',$params['image_id']).')';
|
|
|
|
$result = pwg_query($query);
|
2009-11-20 15:17:04 +01:00
|
|
|
$affected_rows = pwg_db_affected_rows();
|
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;
|
|
|
|
}
|
|
|
|
|
2009-03-13 00:14:50 +01:00
|
|
|
function ws_images_add_chunk($params, &$service)
|
|
|
|
{
|
|
|
|
// data
|
|
|
|
// original_sum
|
|
|
|
// type {thumb, file, high}
|
|
|
|
// position
|
2009-07-01 22:56:41 +02:00
|
|
|
|
2009-03-13 00:14:50 +01:00
|
|
|
if (!is_admin() || is_adviser() )
|
|
|
|
{
|
|
|
|
return new PwgError(401, 'Access denied');
|
|
|
|
}
|
|
|
|
|
|
|
|
$upload_dir = PHPWG_ROOT_PATH.'upload/buffer';
|
|
|
|
|
|
|
|
// create the upload directory tree if not exists
|
|
|
|
if (!is_dir($upload_dir)) {
|
|
|
|
umask(0000);
|
|
|
|
$recursive = true;
|
|
|
|
if (!@mkdir($upload_dir, 0777, $recursive))
|
|
|
|
{
|
|
|
|
return new PwgError(500, 'error during buffer directory creation');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_writable($upload_dir))
|
|
|
|
{
|
|
|
|
// last chance to make the directory writable
|
|
|
|
@chmod($upload_dir, 0777);
|
|
|
|
|
|
|
|
if (!is_writable($upload_dir))
|
|
|
|
{
|
|
|
|
return new PwgError(500, 'buffer directory has no write access');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
secure_directory($upload_dir);
|
|
|
|
|
|
|
|
$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)
|
|
|
|
{
|
|
|
|
ws_logfile('[merge_chunks] input parameter $output_filepath : '.$output_filepath);
|
|
|
|
|
|
|
|
$upload_dir = PHPWG_ROOT_PATH.'upload/buffer';
|
|
|
|
$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
|
|
|
|
|
|
|
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-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-04-15 00:54:39 +02:00
|
|
|
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))
|
|
|
|
{
|
2009-11-23 00:57:44 +01:00
|
|
|
new PwgError(500, '[merge_chunks] error while writting chunks for '.$output_filepath);
|
|
|
|
exit();
|
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
|
|
|
|
|
|
|
ws_logfile('[merge_chunks] memory_get_usage after loading chunks: '.memory_get_usage());
|
2009-03-13 00:14:50 +01:00
|
|
|
}
|
|
|
|
|
2009-11-23 00:57:44 +01:00
|
|
|
/*
|
|
|
|
* The $file_path must be the path of the basic "web sized" photo
|
|
|
|
* The $type value will automatically modify the $file_path to the corresponding file
|
|
|
|
*/
|
|
|
|
function add_file($file_path, $type, $original_sum, $file_sum)
|
|
|
|
{
|
|
|
|
// resolve the $file_path depending on the $type
|
|
|
|
if ('thumb' == $type) {
|
|
|
|
$file_path = get_thumbnail_location(
|
|
|
|
array(
|
|
|
|
'path' => $file_path,
|
|
|
|
'tn_ext' => 'jpg',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ('high' == $type) {
|
|
|
|
@include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
|
|
|
|
$file_path = get_high_location(
|
|
|
|
array(
|
|
|
|
'path' => $file_path,
|
|
|
|
'has_high' => 'true'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$upload_dir = dirname($file_path);
|
|
|
|
|
|
|
|
if (!is_dir($upload_dir)) {
|
|
|
|
umask(0000);
|
|
|
|
$recursive = true;
|
|
|
|
if (!@mkdir($upload_dir, 0777, $recursive))
|
|
|
|
{
|
|
|
|
new PwgError(500, '[add_file] error during '.$type.' directory creation');
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_writable($upload_dir))
|
|
|
|
{
|
|
|
|
// last chance to make the directory writable
|
|
|
|
@chmod($upload_dir, 0777);
|
|
|
|
|
|
|
|
if (!is_writable($upload_dir))
|
|
|
|
{
|
|
|
|
new PwgError(500, '[add_file] '.$type.' directory has no write access');
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
secure_directory($upload_dir);
|
|
|
|
|
|
|
|
// merge the thumbnail
|
|
|
|
merge_chunks($file_path, $original_sum, $type);
|
|
|
|
chmod($file_path, 0644);
|
|
|
|
|
|
|
|
// check dumped thumbnail md5
|
|
|
|
$dumped_md5 = md5_file($file_path);
|
|
|
|
if ($dumped_md5 != $file_sum) {
|
|
|
|
new PwgError(500, '[add_file] '.$type.' transfer failed');
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
list($width, $height) = getimagesize($file_path);
|
|
|
|
$filesize = floor(filesize($file_path)/1024);
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'width' => $width,
|
|
|
|
'height' => $height,
|
|
|
|
'filesize' => $filesize,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2008-07-30 23:53:00 +02:00
|
|
|
function ws_images_add($params, &$service)
|
|
|
|
{
|
|
|
|
global $conf;
|
2008-09-04 02:57:55 +02:00
|
|
|
if (!is_admin() || is_adviser() )
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2008-09-26 01:01:35 +02:00
|
|
|
// does the image already exists ?
|
|
|
|
$query = '
|
|
|
|
SELECT
|
|
|
|
COUNT(*) AS counter
|
|
|
|
FROM '.IMAGES_TABLE.'
|
2009-01-09 00:33:35 +01:00
|
|
|
WHERE md5sum = \''.$params['original_sum'].'\'
|
2008-09-26 01:01:35 +02:00
|
|
|
;';
|
2009-11-20 15:17:04 +01:00
|
|
|
list($counter) = pwg_db_fetch_row(pwg_query($query));
|
2008-09-26 01:01:35 +02:00
|
|
|
if ($counter != 0) {
|
|
|
|
return new PwgError(500, 'file already exists');
|
|
|
|
}
|
|
|
|
|
2008-07-30 23:53:00 +02:00
|
|
|
// current date
|
2009-11-20 15:17:04 +01:00
|
|
|
list($dbnow) = pwg_db_fetch_row(pwg_query('SELECT NOW();'));
|
2008-07-30 23:53:00 +02:00
|
|
|
list($year, $month, $day) = preg_split('/[^\d]/', $dbnow, 4);
|
2008-09-04 02:57:55 +02:00
|
|
|
|
2008-09-05 00:45:27 +02:00
|
|
|
// upload directory hierarchy
|
2008-07-30 23:53:00 +02:00
|
|
|
$upload_dir = sprintf(
|
|
|
|
PHPWG_ROOT_PATH.'upload/%s/%s/%s',
|
|
|
|
$year,
|
|
|
|
$month,
|
|
|
|
$day
|
|
|
|
);
|
|
|
|
|
2008-09-05 00:45:27 +02:00
|
|
|
// compute file path
|
2008-07-30 23:53:00 +02:00
|
|
|
$date_string = preg_replace('/[^\d]/', '', $dbnow);
|
|
|
|
$random_string = substr($params['file_sum'], 0, 8);
|
|
|
|
$filename_wo_ext = $date_string.'-'.$random_string;
|
|
|
|
$file_path = $upload_dir.'/'.$filename_wo_ext.'.jpg';
|
2008-09-05 00:45:27 +02:00
|
|
|
|
2009-11-23 00:57:44 +01:00
|
|
|
// add files
|
|
|
|
$file_infos = add_file($file_path, 'file', $params['original_sum'], $params['file_sum']);
|
|
|
|
$thumb_infos = add_file($file_path, 'thumb', $params['original_sum'], $params['thumbnail_sum']);
|
2008-07-30 23:53:00 +02:00
|
|
|
|
2009-03-13 00:14:50 +01:00
|
|
|
if (isset($params['high_sum']))
|
2008-10-05 23:22:57 +02:00
|
|
|
{
|
2009-11-23 00:57:44 +01:00
|
|
|
$high_infos = add_file($file_path, 'high', $params['original_sum'], $params['high_sum']);
|
2008-10-05 23:22:57 +02:00
|
|
|
}
|
2008-07-30 23:53:00 +02:00
|
|
|
|
|
|
|
// database registration
|
|
|
|
$insert = array(
|
|
|
|
'file' => $filename_wo_ext.'.jpg',
|
|
|
|
'date_available' => $dbnow,
|
|
|
|
'tn_ext' => 'jpg',
|
|
|
|
'name' => $params['name'],
|
|
|
|
'path' => $file_path,
|
2009-11-23 00:57:44 +01:00
|
|
|
'filesize' => $file_infos['filesize'],
|
|
|
|
'width' => $file_infos['width'],
|
|
|
|
'height' => $file_infos['height'],
|
2009-01-09 00:33:35 +01:00
|
|
|
'md5sum' => $params['original_sum'],
|
2008-09-22 23:47:03 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$info_columns = array(
|
|
|
|
'name',
|
|
|
|
'author',
|
|
|
|
'comment',
|
|
|
|
'level',
|
|
|
|
'date_creation',
|
2008-07-30 23:53:00 +02:00
|
|
|
);
|
|
|
|
|
2008-09-22 23:47:03 +02:00
|
|
|
foreach ($info_columns as $key)
|
|
|
|
{
|
|
|
|
if (isset($params[$key]))
|
|
|
|
{
|
|
|
|
$insert[$key] = $params[$key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-13 00:14:50 +01:00
|
|
|
if (isset($params['high_sum']))
|
2008-10-05 23:22:57 +02:00
|
|
|
{
|
|
|
|
$insert['has_high'] = 'true';
|
2009-11-23 00:57:44 +01:00
|
|
|
$insert['high_filesize'] = $high_infos['filesize'];
|
2008-10-05 23:22:57 +02:00
|
|
|
}
|
|
|
|
|
2008-07-30 23:53:00 +02:00
|
|
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
|
|
|
mass_inserts(
|
|
|
|
IMAGES_TABLE,
|
|
|
|
array_keys($insert),
|
|
|
|
array($insert)
|
|
|
|
);
|
|
|
|
|
2009-11-20 15:17:04 +01:00
|
|
|
$image_id = pwg_db_insert_id();
|
2008-07-30 23:53:00 +02: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']);
|
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();
|
2008-07-30 23:53:00 +02:00
|
|
|
}
|
|
|
|
|
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']);
|
2007-02-22 02:12:32 +01:00
|
|
|
foreach ( array('status', 'template', 'theme', 'language') as $k )
|
|
|
|
{
|
|
|
|
$res[$k] = $user[$k];
|
|
|
|
}
|
2007-10-09 01:46:09 +02:00
|
|
|
$res['charset'] = get_pwg_charset();
|
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)
|
|
|
|
{
|
|
|
|
@include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
|
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
|
|
|
|
|
|
|
|
|
|
|
$image_ids = array();
|
|
|
|
$image_tag_map = array();
|
2007-02-06 02:02:06 +01:00
|
|
|
|
2007-01-06 12:13:08 +01:00
|
|
|
if ( !empty($tag_ids) )
|
|
|
|
{ // build list of image ids with associated tags per image
|
|
|
|
if ($params['tag_mode_and'])
|
|
|
|
{
|
|
|
|
$image_ids = get_image_ids_for_tags( $tag_ids );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$query = '
|
|
|
|
SELECT image_id, GROUP_CONCAT(tag_id) tag_ids
|
|
|
|
FROM '.IMAGE_TAG_TABLE.'
|
|
|
|
WHERE tag_id IN ('.implode(',',$tag_ids).')
|
|
|
|
GROUP BY image_id';
|
|
|
|
$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
|
|
|
{
|
|
|
|
$row['image_id'] = (int)$row['image_id'];
|
|
|
|
array_push( $image_ids, $row['image_id'] );
|
|
|
|
$image_tag_map[ $row['image_id'] ] = explode(',', $row['tag_ids']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$images = array();
|
|
|
|
if ( !empty($image_ids))
|
|
|
|
{
|
|
|
|
$where_clauses = ws_std_image_sql_filter($params);
|
2007-01-11 06:10:16 +01:00
|
|
|
$where_clauses[] = get_sql_condition_FandF(
|
|
|
|
array
|
|
|
|
(
|
|
|
|
'forbidden_categories' => 'category_id',
|
|
|
|
'visible_categories' => 'category_id',
|
|
|
|
'visible_images' => 'i.id'
|
|
|
|
),
|
|
|
|
'', true
|
|
|
|
);
|
2007-01-06 12:13:08 +01:00
|
|
|
$where_clauses[] = 'id IN ('.implode(',',$image_ids).')';
|
2007-01-27 09:22:12 +01:00
|
|
|
|
2007-01-06 12:13:08 +01:00
|
|
|
$order_by = ws_std_image_sql_order($params);
|
|
|
|
if (empty($order_by))
|
|
|
|
{
|
|
|
|
$order_by = $conf['order_by'];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$order_by = 'ORDER BY '.$order_by;
|
|
|
|
}
|
|
|
|
|
|
|
|
$query = '
|
|
|
|
SELECT DISTINCT i.* FROM '.IMAGES_TABLE.' i
|
|
|
|
INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON i.id=image_id
|
|
|
|
WHERE '. implode('
|
|
|
|
AND ', $where_clauses).'
|
|
|
|
'.$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
|
|
|
{
|
2007-10-04 01:36:21 +02:00
|
|
|
$image = array();
|
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];
|
|
|
|
}
|
|
|
|
}
|
2007-03-08 02:55:49 +01:00
|
|
|
foreach ( array('file', 'name', 'comment') 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2008-09-25 02:30:42 +02:00
|
|
|
if (!is_admin() or is_adviser())
|
2008-09-24 22:25:39 +02:00
|
|
|
{
|
|
|
|
return new PwgError(401, 'Access denied');
|
|
|
|
}
|
|
|
|
|
|
|
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
|
|
|
|
|
|
|
$creation_output = create_virtual_category(
|
|
|
|
$params['name'],
|
|
|
|
$params['parent']
|
|
|
|
);
|
|
|
|
|
|
|
|
if (isset($creation_output['error']))
|
|
|
|
{
|
|
|
|
return new PwgError(500, $creation_output['error']);
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
if (!is_admin() or is_adviser())
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (!is_admin() or is_adviser())
|
|
|
|
{
|
|
|
|
return new PwgError(401, 'Access denied');
|
|
|
|
}
|
|
|
|
|
|
|
|
// search among photos the list of photos already added, based on md5sum
|
|
|
|
// list
|
|
|
|
$md5sums = preg_split(
|
|
|
|
'/[\s,;\|]/',
|
|
|
|
$params['md5sum_list'],
|
|
|
|
-1,
|
|
|
|
PREG_SPLIT_NO_EMPTY
|
|
|
|
);
|
2008-10-16 02:38:26 +02:00
|
|
|
|
2008-10-08 00:01:14 +02:00
|
|
|
$query = '
|
|
|
|
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
|
|
|
;';
|
|
|
|
$id_of_md5 = simple_hash_from_query($query, 'md5sum', 'id');
|
|
|
|
|
|
|
|
$result = array();
|
2008-10-16 02:38:26 +02:00
|
|
|
|
2008-10-08 00:01:14 +02:00
|
|
|
foreach ($md5sums as $md5sum)
|
|
|
|
{
|
|
|
|
$result[$md5sum] = null;
|
|
|
|
if (isset($id_of_md5[$md5sum]))
|
|
|
|
{
|
|
|
|
$result[$md5sum] = $id_of_md5[$md5sum];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
2008-12-03 23:55:17 +01:00
|
|
|
|
|
|
|
function ws_images_setInfo($params, &$service)
|
|
|
|
{
|
|
|
|
global $conf;
|
|
|
|
if (!is_admin() || is_adviser() )
|
|
|
|
{
|
|
|
|
return new PwgError(401, 'Access denied');
|
|
|
|
}
|
|
|
|
|
|
|
|
// name
|
|
|
|
// category_id
|
|
|
|
// file_content
|
|
|
|
// file_sum
|
|
|
|
// thumbnail_content
|
|
|
|
// thumbnail_sum
|
2009-02-14 03:24:10 +01:00
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
$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
|
|
|
|
$update = array(
|
|
|
|
'id' => $params['image_id'],
|
|
|
|
);
|
|
|
|
|
|
|
|
$info_columns = array(
|
|
|
|
'name',
|
|
|
|
'author',
|
|
|
|
'comment',
|
|
|
|
'level',
|
|
|
|
'date_creation',
|
|
|
|
);
|
|
|
|
|
|
|
|
$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(
|
|
|
|
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'],
|
|
|
|
$params['categories']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// and now, let's create tag associations
|
|
|
|
if (isset($params['tag_ids']))
|
|
|
|
{
|
|
|
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
|
|
|
add_tags(
|
|
|
|
explode(',', $params['tag_ids']),
|
|
|
|
array($params['image_id'])
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
invalidate_user_cache();
|
|
|
|
}
|
|
|
|
|
|
|
|
function ws_add_image_category_relations($image_id, $categories_string)
|
|
|
|
{
|
|
|
|
// 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
|
|
|
|
|
|
|
array_push($cat_ids, $cat_id);
|
|
|
|
|
|
|
|
if (!isset($rank))
|
|
|
|
{
|
|
|
|
$rank = 'auto';
|
|
|
|
}
|
|
|
|
$rank_on_category[$cat_id] = $rank;
|
|
|
|
|
|
|
|
if ($rank == 'auto')
|
|
|
|
{
|
|
|
|
$search_current_ranks = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$cat_ids = array_unique($cat_ids);
|
|
|
|
|
|
|
|
if (count($cat_ids) > 0)
|
|
|
|
{
|
|
|
|
if ($search_current_ranks)
|
|
|
|
{
|
|
|
|
$query = '
|
|
|
|
SELECT
|
|
|
|
category_id,
|
|
|
|
MAX(rank) AS max_rank
|
|
|
|
FROM '.IMAGE_CATEGORY_TABLE.'
|
|
|
|
WHERE rank IS NOT NULL
|
|
|
|
AND category_id IN ('.implode(',', $cat_ids).')
|
|
|
|
GROUP BY category_id
|
|
|
|
;';
|
|
|
|
$current_rank_of = simple_hash_from_query(
|
|
|
|
$query,
|
|
|
|
'category_id',
|
|
|
|
'max_rank'
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($cat_ids as $cat_id)
|
|
|
|
{
|
2008-12-04 00:29:08 +01:00
|
|
|
if (!isset($current_rank_of[$cat_id]))
|
|
|
|
{
|
|
|
|
$current_rank_of[$cat_id] = 0;
|
|
|
|
}
|
2009-02-14 03:24:10 +01:00
|
|
|
|
2008-12-03 23:55:17 +01:00
|
|
|
if ('auto' == $rank_on_category[$cat_id])
|
|
|
|
{
|
|
|
|
$rank_on_category[$cat_id] = $current_rank_of[$cat_id] + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$inserts = array();
|
|
|
|
|
|
|
|
foreach ($cat_ids as $cat_id)
|
|
|
|
{
|
|
|
|
array_push(
|
|
|
|
$inserts,
|
|
|
|
array(
|
|
|
|
'image_id' => $image_id,
|
|
|
|
'category_id' => $cat_id,
|
|
|
|
'rank' => $rank_on_category[$cat_id],
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
|
|
|
mass_inserts(
|
|
|
|
IMAGE_CATEGORY_TABLE,
|
|
|
|
array_keys($inserts[0]),
|
|
|
|
$inserts
|
|
|
|
);
|
|
|
|
|
|
|
|
update_category($cat_ids);
|
|
|
|
}
|
|
|
|
}
|
2009-03-13 00:14:50 +01:00
|
|
|
|
2009-06-25 01:01:35 +02:00
|
|
|
function ws_categories_setInfo($params, &$service)
|
|
|
|
{
|
|
|
|
global $conf;
|
|
|
|
if (!is_admin() || is_adviser() )
|
|
|
|
{
|
|
|
|
return new PwgError(401, 'Access denied');
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
);
|
|
|
|
}
|
2007-01-06 12:13:08 +01:00
|
|
|
?>
|