Changeset 2634


Ignore:
Timestamp:
Oct 1, 2008, 11:08:51 PM (16 years ago)
Author:
plg
Message:

feature 874 added: new Web API method pwg.tags.add.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions.php

    r2588 r2634  
    18171817}
    18181818
     1819function create_tag($tag_name)
     1820{
     1821  $tag_name = mysql_real_escape_string($tag_name);
     1822 
     1823  // does the tag already exists?
     1824  $query = '
     1825SELECT id
     1826  FROM '.TAGS_TABLE.'
     1827  WHERE name = \''.$tag_name.'\'
     1828;';
     1829  $existing_tags = array_from_query($query, 'id');
     1830
     1831  if (count($existing_tags) == 0)
     1832  {
     1833    mass_inserts(
     1834      TAGS_TABLE,
     1835      array('name', 'url_name'),
     1836      array(
     1837        array(
     1838          'name' => $tag_name,
     1839          'url_name' => str2url($tag_name),
     1840          )
     1841        )
     1842      );
     1843
     1844    $inserted_id = mysql_insert_id();
     1845
     1846    return array(
     1847      'info' => sprintf(
     1848        l10n('Tag "%s" was added'),
     1849        stripslashes($tag_name)
     1850        ),
     1851      'id' => $inserted_id,
     1852      );
     1853  }
     1854  else
     1855  {
     1856    return array(
     1857      'error' => sprintf(
     1858        l10n('Tag "%s" already exists'),
     1859        stripslashes($tag_name)
     1860        )
     1861      );
     1862  }
     1863}
    18191864?>
  • trunk/include/ws_functions.inc.php

    r2592 r2634  
    13981398  return $creation_output;
    13991399}
     1400
     1401function ws_tags_add($params, &$service)
     1402{
     1403  if (!is_admin() or is_adviser())
     1404  {
     1405    return new PwgError(401, 'Access denied');
     1406  }
     1407
     1408  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
     1409
     1410  $creation_output = create_tag($params['name']);
     1411
     1412  if (isset($creation_output['error']))
     1413  {
     1414    return new PwgError(500, $creation_output['error']);
     1415  }
     1416
     1417  return $creation_output;
     1418}
    14001419?>
  • trunk/tools/piwigo_remote.pl

    r2584 r2634  
    153153}
    154154
     155if ($opt{action} eq 'pwg.tags.add') {
     156    $form = {
     157        method => 'pwg.tags.add',
     158        name => $opt{define}{name},
     159    };
     160
     161    my $response = $ua->post(
     162        $conf{base_url}.'/ws.php?format=json',
     163        $form
     164    );
     165
     166    use Data::Dumper;
     167    print Dumper(from_json($response->content));
     168}
     169
    155170$query = pwg_ws_get_query(
    156171    method => 'pwg.session.logout'
  • trunk/ws.php

    r2584 r2634  
    219219    'administration method only'
    220220    );
     221
     222  $service->addMethod(
     223    'pwg.tags.add',
     224    'ws_tags_add',
     225    array(
     226      'name' => array(),
     227      ),
     228    'administration method only'
     229    );
    221230}
    222231
Note: See TracChangeset for help on using the changeset viewer.