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
|
|
|
// +-----------------------------------------------------------------------+
|
2014-01-05 01:19:25 +01:00
|
|
|
// | Copyright(C) 2008-2014 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. |
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
|
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']) )
|
|
|
|
{
|
2013-03-23 10:32:25 +01: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']) )
|
|
|
|
{
|
2013-03-23 10:32:25 +01:00
|
|
|
$clauses[] = $tbl_name.'hit>='.$params['f_min_hit'];
|
2007-01-06 12:13:08 +01:00
|
|
|
}
|
|
|
|
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']) )
|
|
|
|
{
|
2013-03-23 10:32:25 +01:00
|
|
|
$clauses[] = $tbl_name.'width/'.$tbl_name.'height>='.$params['f_min_ratio'];
|
2007-01-06 12:13:08 +01:00
|
|
|
}
|
|
|
|
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-10-24 22:24:44 +02:00
|
|
|
$ret['page_url'] = make_picture_url( array(
|
|
|
|
'image_id' => $image_row['id'],
|
|
|
|
'image_file' => $image_row['file'],
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
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(
|
2012-10-24 22:24:44 +02:00
|
|
|
'id','element_url', 'page_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
|
|
|
|
2013-05-18 05:58:36 +02:00
|
|
|
function ws_std_get_category_xml_attributes()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
'id', 'url', 'nb_images', 'total_nb_images', 'nb_categories', 'date_last', 'max_date_last',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function ws_std_get_tag_xml_attributes()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
'id', 'name', 'url_name', 'counter', 'url', 'page_url',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2007-02-06 02:02:06 +01:00
|
|
|
/**
|
2013-11-01 12:03:10 +01:00
|
|
|
* Writes info to the log file
|
2007-02-06 02:02:06 +01:00
|
|
|
*/
|
2013-11-01 12:03:10 +01:00
|
|
|
function ws_logfile($string)
|
2007-01-06 12:13:08 +01:00
|
|
|
{
|
2007-02-23 14:18:34 +01:00
|
|
|
global $conf;
|
2011-04-03 14:36:32 +02:00
|
|
|
|
2013-11-01 12:03:10 +01:00
|
|
|
if (!$conf['ws_enable_log'])
|
2011-04-03 14:36:32 +02:00
|
|
|
{
|
2013-11-01 12:03:10 +01:00
|
|
|
return true;
|
2007-01-06 12:13:08 +01:00
|
|
|
}
|
|
|
|
|
2013-11-01 12:03:10 +01:00
|
|
|
file_put_contents(
|
|
|
|
$conf['ws_log_filepath'],
|
|
|
|
'['.date('c').'] '.$string."\n",
|
|
|
|
FILE_APPEND
|
2007-01-06 12:13:08 +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']))
|
|
|
|
{
|
2013-05-18 05:58:36 +02:00
|
|
|
$tree[] = &$node;
|
2012-02-09 22:11:34 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!isset($categories[ $key_of_cat[ $node['id_uppercat'] ] ]['sub_categories']))
|
|
|
|
{
|
2013-11-01 12:03:10 +01:00
|
|
|
$categories[ $key_of_cat[ $node['id_uppercat'] ] ]['sub_categories'] =
|
|
|
|
new PwgNamedArray(array(), 'category', ws_std_get_category_xml_attributes());
|
2012-02-09 22:11:34 +01:00
|
|
|
}
|
|
|
|
|
2013-05-18 05:58:36 +02:00
|
|
|
$categories[ $key_of_cat[ $node['id_uppercat'] ] ]['sub_categories']->_content[] = &$node;
|
2012-02-09 22:11:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $tree;
|
|
|
|
}
|
|
|
|
|
2013-10-24 15:38:12 +02:00
|
|
|
?>
|