Ignore:
Timestamp:
Feb 22, 2007, 2:12:32 AM (17 years ago)
Author:
rvelices
Message:
  • user comments are not saved in the database with htmlspecialchars anymore
  • web service: added the possibility to enter a user comment using the service...
  • new comment functions from picture_comment.inc.php
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/ws_functions.inc.php

    r1845 r1849  
    3333{
    3434  global $conf, $calling_partner_id;
    35   if ( !$conf['ws_access_control']
    36        or strpos($methodName,'reflection.')===0 )
     35 
     36  if ( strpos($methodName,'reflection.')===0 )
     37  { // OK for reflection
     38    return $res;
     39  }
     40 
     41  if ( !is_autorize_status(ACCESS_GUEST) and
     42      strpos($methodName,'pwg.session.')!==0 )
     43  {
     44    return new PwgError(401, 'Access denied');
     45  }
     46 
     47  if ( !$conf['ws_access_control'] )
    3748  {
    3849    return $res; // No controls are requested
     
    487498 * returns detailed information for an element (web service method)
    488499 */
     500function ws_images_addComment($params, &$service)
     501{
     502  $params['image_id'] = (int)$params['image_id'];
     503  $query = '
     504SELECT DISTINCT image_id
     505  FROM '.IMAGE_CATEGORY_TABLE.' INNER JOIN '.CATEGORIES_TABLE.' ON category_id=id
     506  WHERE commentable="true"
     507    AND image_id='.$params['image_id'].
     508    get_sql_condition_FandF(
     509      array(
     510        'forbidden_categories' => 'id',
     511        'visible_categories' => 'id',
     512        'visible_images' => 'image_id'
     513      ),
     514      ' AND'
     515    );
     516  if ( !mysql_num_rows( pwg_query( $query ) ) )
     517  {
     518    return new PwgError(WS_ERR_INVALID_PARAM, "Invalid image_id");
     519  }
     520 
     521  include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
     522 
     523  $comm = array(
     524    'author' => trim( stripslashes($params['author']) ),
     525    'content' => trim( stripslashes($params['content']) ),
     526    'image_id' => $params['image_id'],
     527   );
     528
     529  include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
     530 
     531  $comment_action = insert_user_comment(
     532      $comm, $params['key'], $infos
     533    );
     534
     535  switch ($comment_action)
     536  {
     537    case 'reject':
     538      array_push($infos, l10n('comment_not_added') );
     539      return new PwgError(403, implode("\n", $infos) );
     540    case 'validate':
     541    case 'moderate':
     542      $ret = array(
     543          'id' => $comm['id'],
     544          'validation' => $comment_action=='validate',
     545        );
     546      return new PwgNamedStruct(
     547          'comment',
     548          $ret,
     549          null, array()
     550        );
     551    default:
     552      return new PwgError(500, "Unknown comment action ".$comment_action );
     553  }
     554}
     555
     556/**
     557 * returns detailed information for an element (web service method)
     558 */
    489559function ws_images_getInfo($params, &$service)
    490560{
    491561  @include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
    492   global $user;
     562  global $user, $conf;
    493563  $params['image_id'] = (int)$params['image_id'];
    494564  if ( $params['image_id']<=0 )
     
    516586  //-------------------------------------------------------- related categories
    517587  $query = '
    518 SELECT c.id,c.name,c.uppercats,c.global_rank
     588SELECT id,name,uppercats,global_rank,commentable
    519589  FROM '.IMAGE_CATEGORY_TABLE.'
    520     INNER JOIN '.CATEGORIES_TABLE.' c ON category_id = id
     590    INNER JOIN '.CATEGORIES_TABLE.' ON category_id = id
    521591  WHERE image_id = '.$image_row['id'].'
    522592    AND category_id NOT IN ('.$user['forbidden_categories'].')
    523593;';
    524594  $result = pwg_query($query);
     595  $is_commentable = false;
    525596  $related_categories = array();
    526597  while ($row = mysql_fetch_assoc($result))
    527598  {
     599    if ($row['commentable']=='true')
     600    {
     601      $is_commentable = true;
     602    }
     603    unset($row['commentable']);
    528604    $row['url'] = make_index_url(
    529605        array(
     
    541617          )
    542618      );
     619    $row['id']=(int)$row['id'];
    543620    array_push($related_categories, $row);
    544621  }
     
    566643      );
    567644    unset($tag['counter']);
     645    $tag['id']=(int)$tag['id'];
    568646    $related_tags[$i]=$tag;
    569647  }
    570   //---------------------------------------------------------- related comments
    571   $query = '
    572 SELECT COUNT(id) nb_comments
    573   FROM '.COMMENTS_TABLE.'
    574   WHERE image_id = '.$image_row['id'];
    575   list($nb_comments) = array_from_query($query, 'nb_comments');
    576 
    577   $query = '
    578 SELECT id, date, author, content
    579   FROM '.COMMENTS_TABLE.'
    580   WHERE image_id = '.$image_row['id'].'
    581     AND validated="true"';
    582   $query .= '
    583   ORDER BY date DESC
    584   LIMIT 0, 5';
    585 
    586   $result = pwg_query($query);
    587   $related_comments = array();
    588   while ($row = mysql_fetch_assoc($result))
    589   {
    590     array_push($related_comments, $row);
    591   }
    592 
    593648  //------------------------------------------------------------- related rates
    594649  $query = '
     
    599654  WHERE element_id = '.$image_row['id'].'
    600655;';
    601   $row = mysql_fetch_assoc(pwg_query($query));
     656  $rating = mysql_fetch_assoc(pwg_query($query));
     657  $rating['count'] = (int)$rating['count'];
     658
     659  //---------------------------------------------------------- related comments
     660  $related_comments = array();
     661 
     662  $where_comments = 'image_id = '.$image_row['id'];
     663  if ( !is_admin() )
     664  {
     665    $where_comments .= '
     666    AND validated="true"';
     667  }
     668
     669  $query = '
     670SELECT COUNT(id) nb_comments
     671  FROM '.COMMENTS_TABLE.'
     672  WHERE '.$where_comments;
     673  list($nb_comments) = array_from_query($query, 'nb_comments');
     674  $nb_comments = (int)$nb_comments;
     675
     676  if ( $nb_comments>0 and $params['comments_per_page']>0 )
     677  {
     678    $query = '
     679SELECT id, date, author, content
     680  FROM '.COMMENTS_TABLE.'
     681  WHERE '.$where_comments.'
     682  ORDER BY date
     683  LIMIT '.$params['comments_per_page']*(int)$params['comments_page'].
     684    ','.$params['comments_per_page'];
     685
     686    $result = pwg_query($query);
     687    while ($row = mysql_fetch_assoc($result))
     688    {
     689      $row['id']=(int)$row['id'];
     690      array_push($related_comments, $row);
     691    }
     692  }
     693 
     694  $comment_post_data = null;
     695  if ($is_commentable and
     696      (!$user['is_the_guest']
     697        or ($user['is_the_guest'] and $conf['comments_forall'] )
     698      )
     699      )
     700  {
     701    include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
     702    $comment_post_data['author'] = $user['username'];   
     703    $comment_post_data['key'] = get_comment_post_key($params['image_id']);
     704  }
    602705
    603706  $ret = $image_row;
    604   $ret['rates'] = array( WS_XML_ATTRIBUTES => $row );
     707  foreach ( array('id','width','height','hit','filesize') as $k )
     708  {
     709    if (isset($ret[$k]))
     710    {
     711      $ret[$k] = (int)$ret[$k];
     712    }
     713  }
     714  foreach ( array('path', 'storage_category_id') as $k )
     715  {
     716    unset($ret[$k]);
     717  }
     718
     719  $ret['rates'] = array( WS_XML_ATTRIBUTES => $rating );
    605720  $ret['categories'] = new PwgNamedArray($related_categories, 'category', array('id','url', 'page_url') );
    606721  $ret['tags'] = new PwgNamedArray($related_tags, 'tag', array('id','url_name','url','page_url') );
     722  if ( isset($comment_post_data) )
     723  {
     724    $ret['comment_post'] = array( WS_XML_ATTRIBUTES => $comment_post_data );
     725  }
    607726  $ret['comments'] = array(
    608      WS_XML_ATTRIBUTES => array('nb_comments' => $nb_comments),
    609      WS_XML_CONTENT => new PwgNamedArray($related_comments, 'comment', array('id') )
    610       );
    611   unset($ret['path']);
    612   unset($ret['storage_category_id']);
     727     WS_XML_ATTRIBUTES =>
     728        array(
     729          'page' => $params['comments_page'],
     730          'per_page' => $params['comments_per_page'],
     731          'count' => count($related_comments),
     732          'nb_comments' => $nb_comments,
     733        ),
     734     WS_XML_CONTENT => new PwgNamedArray($related_comments, 'comment', array('id','date') )
     735      );
    613736
    614737  return new PwgNamedStruct('image',$ret, null, array('name','comment') );
     
    769892function ws_session_getStatus($params, &$service)
    770893{
    771   global $user;
     894  global $user, $lang_info;
    772895  $res = array();
    773896  $res['username'] = $user['is_the_guest'] ? 'guest' : $user['username'];
    774   $res['status'] = $user['status'];
     897  foreach ( array('status', 'template', 'theme', 'language') as $k )
     898  {
     899    $res[$k] = $user[$k];
     900  }
     901  foreach ( array('charset') as $k )
     902  {
     903    $res[$k] = $lang_info[$k];
     904  }
    775905  return $res;
    776906}
Note: See TracChangeset for help on using the changeset viewer.