WEB Service: Some corrections again but still an incomplete version.

git-svn-id: http://piwigo.org/svn/trunk@1675 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
vdigital
2006-12-19 07:32:50 +00:00
parent 37032d453c
commit a65dbaa784
3 changed files with 157 additions and 15 deletions
+55
View File
@@ -0,0 +1,55 @@
<?php
$where = ( $user['forbidden_categories'] == '') ? '' :
'ic.`category_id` NOT IN ('.$user['forbidden_categories'].')';
$list = implode(',', $final);
if ( $where !== '' and $list !== '' )
{
$where .= ' AND ';
}
$where .= ( $list == '') ? '' :
'i.`id` IN ('. $list .')';
$query='
SELECT DISTINCT (i.`id`),
i.`path` , i.`file` , i.`date_available` ,
i.`date_creation`, i.`tn_ext` , i.`name` ,
i.`filesize` , i.`storage_category_id` , i.`average_rate`,
i.`comment` , i.`author` , i.`hit` ,i.`width` ,
i.`height`
FROM `'.IMAGES_TABLE.'` AS i
INNER JOIN `'.IMAGE_CATEGORY_TABLE.'`
AS ic ON i.`id` = ic.`image_id`
WHERE '. $where .'
';
/* recent = Date_available desc order */
$query .= ' ORDER BY i.`date_available` DESC, RAND() DESC ';
$query .= ' LIMIT 0 , '. $limit .';';
// echo $query . '<br />';
$result = pwg_query( $query );
$template->assign_vars(
array(
'TITLE' => 'recent',
)
);
$template->assign_block_vars(
'row', array()
);
$template->assign_block_vars(
'row.Normal',
array(
'WIDTH'=> 682,
'HEIGH'=> 682,
'URL'=> 'http://www.monsite.com/pwg/galleries/shared/cat/image.jpg',
)
);
$template->assign_block_vars(
'row',
array(
'ID'=> 22,
'CAPTION'=> 'L\'image que je veux',
'DATE'=> '18/12/2006',
'COMMENT'=> 'Voila voili voilou ! Voila voili voilou !',
)
);
?>
+25
View File
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Just a sample right now -->
<group>
<title>PhpWebGallery - Web Service</title>
<text>default.tpl: To be customized.</text>
<!-- BEGIN row -->
<picture id="{row.ID}">
<caption>{row.CAPTION}</caption>
<date>{row.DATE}</date>
<text>{row.COMMENT}</text>
<!-- BEGIN High -->
<full-image width="{row.High.WIDTH}" height="{row.High.HEIGHT}">{row.High.URL}</full-image>
<!-- END High -->
<!-- BEGIN Normal -->
<image width="{row.Normal.WIDTH}" height="{row.Normal.HEIGHT}">{row.Normal.URL}</image>
<!-- END Normal -->
<!-- BEGIN Thumbnail -->
<small-image width="{row.Thumbnail.WIDTH}" height="{row.Thumbnail.HEIGHT}">{row.Thumbnail.URL}</small-image>
<!-- END Thumbnail -->
</picture>
<!-- END row -->
<group>
+77 -15
View File
@@ -126,6 +126,11 @@ if (isset($_SERVER["HTTP_REFERER"]) and
// Check keywords
// Key and pos are correct
// &acc=cat/23,25-32&req=landscape&lim=5&tpl=myxml
// Requested id list and authorized id list
// Both may empty
// Both can be build on differents basis cat/tag/list
// Both have to be convert in id list format
$req_access ='';
if (isset($_GET['pos']))
{
@@ -143,7 +148,7 @@ if ($req_type[0]=='tag')
{
$req_list = get_image_ids_for_tags($req_list);
}
echo $def['name'].'<br />';
// echo $def['name'].'<br />';
// on the other hand $def['access'], authorized default ids
$def_type = explode('/',$def['access']);
$def_ids = explode( ',',$def_type[1] );
@@ -157,8 +162,8 @@ if ($def_type[0]=='tag')
$def_list = get_image_ids_for_tags($def_list);
}
// could be no necessary, a surplus but
// Filter on forbidden_categories
// could be no necessary, a surplus but we are obliged to
// Filter on forbidden_categories (default can have change from creation time)
$list = implode(',',$def_list);
$ret_ids = array();
@@ -173,27 +178,84 @@ while ($row = mysql_fetch_array($result))
{
$ret_ids[] = $row['image_id'];
}
$def_ids = $ret_ids;
// Notice: Filtering on forbidden_categories (from requested id list)
// is completely superfluous (see few lines below).
$req_ids = $req_list;
// if no requested ids then is the complete default
if (count($req_ids)==0)
{
$req_ids = $def_ids;
}
// Removing requested ids not in authorized access list
// if requested ids they must be in the complete default and only those
// will be assumed. (Including forbidden... )
$final = array();
foreach ( $req_ids as $req_id )
{
if ( in_array($req_id, $def_ids) )
{
$final[] = $req_id;
}
}
$final = array_unique ($final);
sort ($final);
// 77f1180bd215a0edf66939
// web_service.php?key=77f1180bd215&pos=3&acc=list/41,73,142,178,190,204,235-238&req=recent&lim=1&tpl=myxml
echo 'temporaire<br />';
echo '$req_list' . var_dump($req_list);
$request = (isset($_GET['req']))? $_GET['req']:$def['request'];
// if type of request is different from the authorized type then force it
if ( $def['request'] !== '' and $request !== $def['request'] )
if (count($req_list)==0)
{
$req_list = $def_list;
}
$request = $def['request'];
}
// if it is not an official request then force it
// (remark that default request can no longer exist
// (later an Upgrade, or a remove) so...
$official = official_req();
if ( !in_array($request, $official ) )
{
$request = $official[0]; // default request is the first one
}
// limit belong default (remember $def['limit'] is always set)
$limit = (isset($_GET['limit']))? $_GET['limit']:$def['limit'];
$limit = (is_numeric($limit))? $limit:$def['limit'];
$limit = ( $limit < $def['limit'] ) ? $limit:$def['limit'];
// XML template
$tplfile = (isset($_GET['tpl']))? $_GET['tpl']:'default';
// FIXME additional controls are maybe needed on $tplfile
trigger_action('loc_begin_'.$request);
$template->set_filenames(array( $tplfile => 'XML/'. $tplfile .'.tpl'));
// Generate the request
include(PHPWG_ROOT_PATH. 'services/' .$request. '.php');
// +-----------------------------------------------------------------------+
// | XML/xhtml code display |
// +-----------------------------------------------------------------------+
header('Content-Type: text/xml; charset=UTF-8');
//header('Content-Type: text/html; charset='.$lang_info['charset']);
$template->parse($tplfile);
// echo '<strong>Trace temporaire<strong><br />';
// echo '$final:<br />' . var_dump($final);
//
die('FIXME!');
die('');
// FIXME// FIXME// FIXME// FIXME// FIXME// FIXME// FIXME// FIXME
// Both may empty
// Both can be build on differents basis cat/tag/list
// Both have to be convert in list
// if no requested ids then is the complete default
// if some requested ids they must be in the complete default and only those
// will be transmitted.
//------------------------------------------------------------ log informations
pwg_log($request, $stats_id, $tplfile); // or something like that