Skip to content

Commit

Permalink
- bug 755: admin permalinks page - fix category field sort
Browse files Browse the repository at this point in the history
- web service functions: 1 fix and 3 optimizations

git-svn-id: http://piwigo.org/svn/trunk@2119 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
rvelices committed Oct 3, 2007
1 parent 2889cbc commit fb9abe8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 36 deletions.
26 changes: 15 additions & 11 deletions admin/permalinks.php
Expand Up @@ -30,11 +30,11 @@ function parse_sort_variables(
$anchor = '' )
{
global $template;

$url_components = parse_url( $_SERVER['REQUEST_URI'] );

$base_url = $url_components['path'];

parse_str($url_components['query'], $vars);
$is_first = true;
foreach ($vars as $key => $value)
Expand All @@ -51,18 +51,24 @@ function parse_sort_variables(
foreach( $sortable_by as $field)
{
$url = $base_url;
$disp = '⇓'; // TODO: an small image is better

if ( $field !== @$_GET[$get_param] )
{
if ( !isset($default_field) or $default_field!=$field )
{ // the first should be the default
$url = add_url_params($url, array($get_param=>$field) );
}
$disp = '⇓'; // TODO: an small image is better
elseif (isset($default_field) and !isset($_GET[$get_param]) )
{
array_push($ret, $field);
$disp = '<em>'.$disp.'</em>';
}
}
else
{
array_push($ret, $field);
$disp = '<em>&dArr;</em>'; // TODO: an small image is better
$disp = '<em>'.$disp.'</em>';
}
if ( isset($template_var) )
{
Expand Down Expand Up @@ -103,10 +109,10 @@ function parse_sort_variables(
$template->set_filename('permalinks', 'admin/permalinks.tpl' );

$query = '
SELECT
id,
SELECT
id,
CONCAT(id, " - ", name, IF(permalink IS NULL, "", " &radic;") ) AS name,
uppercats, global_rank
uppercats, global_rank
FROM '.CATEGORIES_TABLE;

display_select_cat_wrapper( $query, $selected_cat, 'categories', false );
Expand All @@ -124,9 +130,7 @@ function parse_sort_variables(
FROM '.CATEGORIES_TABLE.'
WHERE permalink IS NOT NULL
';
if ( count($sort_by) and
($sort_by[0]=='id' or $sort_by[0]=='permalink')
)
if ( $sort_by[0]=='id' or $sort_by[0]=='permalink' )
{
$query .= ' ORDER BY '.$sort_by[0];
}
Expand All @@ -138,7 +142,7 @@ function parse_sort_variables(
$categories[] = $row;
}

if ( !count($sort_by) or $sort_by[0]=='name')
if ( $sort_by[0]=='name')
{
usort($categories, 'global_rank_compare');
}
Expand Down
54 changes: 29 additions & 25 deletions include/ws_functions.inc.php
Expand Up @@ -32,18 +32,18 @@
function ws_isInvokeAllowed($res, $methodName, $params)
{
global $conf, $calling_partner_id;

if ( strpos($methodName,'reflection.')===0 )
{ // OK for reflection
return $res;
}

if ( !is_autorize_status(ACCESS_GUEST) and
strpos($methodName,'pwg.session.')!==0 )
{
return new PwgError(401, 'Access denied');
}

if ( !$conf['ws_access_control'] )
{
return $res; // No controls are requested
Expand Down Expand Up @@ -316,7 +316,10 @@ function ws_categories_getImages($params, &$service)
OR ', $where_clauses) . ')'
);
}
$where_clauses[] = 'id NOT IN ('.$user['forbidden_categories'].')';
$where_clauses[] = get_sql_condition_FandF(
array('forbidden_categories' => 'id'),
NULL, true
);

$query = '
SELECT id, name, permalink, image_order
Expand Down Expand Up @@ -460,7 +463,6 @@ function ws_categories_getList($params, &$service)
}
else
{
$where[] = 'id NOT IN ('.$user['forbidden_categories'].')';
$where[]= 'user_id='.$user['id'];
}

Expand All @@ -472,8 +474,6 @@ function ws_categories_getList($params, &$service)
INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' ON id=cat_id
WHERE '. implode('
AND ', $where);
$query .= '
ORDER BY global_rank';

$result = pwg_query($query);

Expand Down Expand Up @@ -512,9 +512,9 @@ function ws_images_addComment($params, &$service)
}
$params['image_id'] = (int)$params['image_id'];
$query = '
SELECT DISTINCT image_id
SELECT DISTINCT image_id
FROM '.IMAGE_CATEGORY_TABLE.' INNER JOIN '.CATEGORIES_TABLE.' ON category_id=id
WHERE commentable="true"
WHERE commentable="true"
AND image_id='.$params['image_id'].
get_sql_condition_FandF(
array(
Expand All @@ -528,18 +528,18 @@ function ws_images_addComment($params, &$service)
{
return new PwgError(WS_ERR_INVALID_PARAM, "Invalid image_id");
}

include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');

$comm = array(
'author' => trim( stripslashes($params['author']) ),
'content' => trim( stripslashes($params['content']) ),
'image_id' => $params['image_id'],
);

include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
$comment_action = insert_user_comment(

$comment_action = insert_user_comment(
$comm, $params['key'], $infos
);

Expand All @@ -550,14 +550,14 @@ function ws_images_addComment($params, &$service)
return new PwgError(403, implode("\n", $infos) );
case 'validate':
case 'moderate':
$ret = array(
$ret = array(
'id' => $comm['id'],
'validation' => $comment_action=='validate',
);
return new PwgNamedStruct(
'comment',
$ret,
null, array()
$ret,
null, array()
);
default:
return new PwgError(500, "Unknown comment action ".$comment_action );
Expand Down Expand Up @@ -599,8 +599,11 @@ function ws_images_getInfo($params, &$service)
SELECT id, name, permalink, uppercats, global_rank, commentable
FROM '.IMAGE_CATEGORY_TABLE.'
INNER JOIN '.CATEGORIES_TABLE.' ON category_id = id
WHERE image_id = '.$image_row['id'].'
AND category_id NOT IN ('.$user['forbidden_categories'].')
WHERE image_id = '.$image_row['id'].
get_sql_condition_FandF(
array( 'forbidden_categories' => 'category_id' ),
' AND'
).'
;';
$result = pwg_query($query);
$is_commentable = false;
Expand Down Expand Up @@ -667,7 +670,7 @@ function ws_images_getInfo($params, &$service)

//---------------------------------------------------------- related comments
$related_comments = array();

$where_comments = 'image_id = '.$image_row['id'];
if ( !is_admin() )
{
Expand Down Expand Up @@ -699,16 +702,16 @@ function ws_images_getInfo($params, &$service)
array_push($related_comments, $row);
}
}

$comment_post_data = null;
if ($is_commentable and
if ($is_commentable and
(!is_a_guest()
or (is_a_guest() and $conf['comments_forall'] )
)
)
{
include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
$comment_post_data['author'] = $user['username'];
$comment_post_data['author'] = $user['username'];
$comment_post_data['key'] = get_comment_post_key($params['image_id']);
}

Expand All @@ -733,7 +736,7 @@ function ws_images_getInfo($params, &$service)
$ret['comment_post'] = array( WS_XML_ATTRIBUTES => $comment_post_data );
}
$ret['comments'] = array(
WS_XML_ATTRIBUTES =>
WS_XML_ATTRIBUTES =>
array(
'page' => $params['comments_page'],
'per_page' => $params['comments_per_page'],
Expand Down Expand Up @@ -805,7 +808,7 @@ function ws_images_search($params, &$service)
{
$image_ids = $search_result['items'];
}

$image_ids = array_slice($image_ids,
$params['page']*$params['per_page'],
$params['per_page'] );
Expand Down Expand Up @@ -951,7 +954,7 @@ function ws_tags_getImages($params, &$service)
{
@include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
global $conf;

// first build all the tag_ids we are interested in
$params['tag_id'] = array_map( 'intval',$params['tag_id'] );
$tags = find_tags($params['tag_id'], $params['tag_url_name'], $params['tag_name']);
Expand Down Expand Up @@ -1028,6 +1031,7 @@ function ws_tags_getImages($params, &$service)
$result = pwg_query($query);
while ($row = mysql_fetch_assoc($result))
{
$image = array();
foreach ( array('id', 'width', 'height', 'hit') as $k )
{
if (isset($row[$k]))
Expand Down

0 comments on commit fb9abe8

Please sign in to comment.