Ignore:
Timestamp:
May 27, 2011, 11:02:05 PM (13 years ago)
Author:
nikrou
Message:

Fix incompatibility with piwigo 2.2
Change jquery plugin from fcbkcomplete to tokeninput

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/user_tags/include/t4u_admin_action.inc.php

    r9037 r11081  
    2525
    2626if (!empty($_GET['action']) && ($_GET['action']=='add')
    27     && isset($_POST['tags']) && $plugin_config->getPermission('add') ) {
     27    && isset($_POST['tags']) && $me->getPermission('add')) {
    2828  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
    2929
     
    3131    $_POST['tags'] = array();
    3232  }
    33   $tag_ids = get_fckb_tag_ids($_POST['tags']);
     33  $tag_ids = __get_tag_ids($_POST['tags']);
    3434  set_tags($tag_ids, $_POST['image_id']);
    3535
    3636  if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) {
    3737    header("Content-Type: application/json");
    38     $message['info'] = 'Tags updated';
     38    $message['info'] = l10n('Tags updated');
    3939
    4040    echo json_encode($message);
    4141    exit();
    4242  } else {
    43     redirect(get_absolute_root_url().$_POST['referer']);
     43    redirect(get_root_url().$_POST['referer']);
    4444  }
    45 } elseif (!empty($_GET['action']) && $_GET['action']=='get' && $plugin_config->getPermission('add') ) {
    46   include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
    47      
     45} elseif (!empty($_GET['action']) && $_GET['action']=='get' && $me->getPermission('add')) {
    4846  $query = '
    4947SELECT
    5048    id AS tag_id,
    5149    name AS tag_name
    52   FROM '.TAGS_TABLE.'
    53 ;';
     50  FROM '.TAGS_TABLE;
     51
     52  if (!empty($_GET['q'])) {
     53    $query .= ' WHERE url_name like \'%'.pwg_db_real_escape_string($_GET['q']).'%\';';
     54  } else {
     55    $query .= ';';
     56  }
    5457  header("Content-Type: application/json");
    55   echo json_encode(get_fckb_taglist($query));
     58  echo json_encode(__get_taglist($query));
    5659  exit();
    5760}
     61
     62/*
     63 * temporary functions before piwigo 2.3
     64 * See admin/include/functions.php in piwigo core
     65 */
     66function __get_taglist($query) {
     67  $result = pwg_query($query);
     68
     69  $taglist = array();
     70  while ($row = pwg_db_fetch_assoc($result)) {
     71    $taglist[] = array('name' => $row['tag_name'],
     72                       'id' => '~~'.$row['tag_id'].'~~'
     73                       );
     74  }
     75
     76  $cmp = create_function('$a,$b', 'return strcasecmp($a[\'name\'], $b[\'name\']);');
     77  usort($taglist, $cmp);
     78
     79  return $taglist;
     80}
     81
     82function __get_tag_ids($raw_tags) {
     83  $tag_ids = array();
     84  $raw_tags = explode(',',$raw_tags);
     85
     86  foreach ($raw_tags as $raw_tag) {
     87    if (preg_match('/^~~(\d+)~~$/', $raw_tag, $matches)) {
     88      $tag_ids[] = $matches[1];
     89    } else {
     90      $tag_ids[] = tag_id_from_tag_name($raw_tag);
     91    }
     92  }
     93
     94  return $tag_ids;
     95}
    5896?>
Note: See TracChangeset for help on using the changeset viewer.