Changeset 12032


Ignore:
Timestamp:
Sep 2, 2011, 10:37:21 AM (9 years ago)
Author:
plg
Message:

feature 1078 added: ability to merge tags

Location:
trunk
Files:
6 edited

Legend:

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

    r12030 r12032  
    13951395}
    13961396
     1397/**
     1398 *
     1399 */
     1400function delete_tags($tag_ids)
     1401{
     1402  if (is_numeric($tag_ids))
     1403  {
     1404    $tag_ids = array($tag_ids);
     1405  }
     1406
     1407  if (!is_array($tag_ids))
     1408  {
     1409    return false;
     1410  }
     1411 
     1412  $query = '
     1413DELETE
     1414  FROM '.IMAGE_TAG_TABLE.'
     1415  WHERE tag_id IN ('.implode(',', $tag_ids).')
     1416;';
     1417  pwg_query($query);
     1418 
     1419  $query = '
     1420DELETE
     1421  FROM '.TAGS_TABLE.'
     1422  WHERE id IN ('.implode(',', $tag_ids).')
     1423;';
     1424  pwg_query($query);
     1425}
     1426
    13971427function tag_id_from_tag_name($tag_name)
    13981428{
  • trunk/admin/tags.php

    r11487 r12032  
    102102
    103103// +-----------------------------------------------------------------------+
     104// |                               merge tags                              |
     105// +-----------------------------------------------------------------------+
     106
     107if (isset($_POST['confirm_merge']))
     108{
     109  if (!isset($_POST['destination_tag']))
     110  {
     111    array_push(
     112      $page['errors'],
     113      l10n('No destination tag selected')
     114      );
     115  }
     116  else
     117  {
     118    $destination_tag_id = $_POST['destination_tag'];
     119    $tag_ids = explode(',', $_POST['merge_list']);
     120   
     121    if (is_array($tag_ids) and count($tag_ids) > 1)
     122    {
     123      $name_of_tag = array();
     124      $query = '
     125SELECT
     126    id,
     127    name
     128  FROM '.TAGS_TABLE.'
     129  WHERE id IN ('.implode(',', $tag_ids).')
     130;';
     131      $result = pwg_query($query);
     132      while ($row = pwg_db_fetch_assoc($result))
     133      {
     134        $name_of_tag[ $row['id'] ] = trigger_event('render_tag_name', $row['name']);
     135      }
     136     
     137      $tag_ids_to_delete = array_diff(
     138        $tag_ids,
     139        array($destination_tag_id)
     140        );
     141
     142      $query = '
     143SELECT
     144    DISTINCT(image_id)
     145  FROM '.IMAGE_TAG_TABLE.'
     146  WHERE tag_id IN ('.implode(',', $tag_ids_to_delete).')
     147;';
     148      $image_ids = array_from_query($query, 'image_id');
     149
     150      delete_tags($tag_ids_to_delete);
     151
     152      $query = '
     153SELECT
     154    image_id
     155  FROM '.IMAGE_TAG_TABLE.'
     156  WHERE tag_id = '.$destination_tag_id.'
     157;';
     158      $destination_tag_image_ids = array_from_query($query, 'image_id');
     159
     160      $image_ids_to_link = array_diff(
     161        $image_ids,
     162        $destination_tag_image_ids
     163        );
     164
     165      $inserts = array();
     166      foreach ($image_ids_to_link as $image_id)
     167      {
     168        array_push(
     169          $inserts,
     170          array(
     171            'tag_id' => $destination_tag_id,
     172            'image_id' => $image_id
     173            )
     174          );
     175      }
     176
     177      if (count($inserts) > 0)
     178      {
     179        mass_inserts(
     180          IMAGE_TAG_TABLE,
     181          array_keys($inserts[0]),
     182          $inserts
     183          );
     184      }
     185
     186      $tags_deleted = array();
     187      foreach ($tag_ids_to_delete as $tag_id)
     188      {
     189        $tags_deleted[] = $name_of_tag[$tag_id];
     190      }
     191     
     192      array_push(
     193        $page['infos'],
     194        sprintf(
     195          l10n('Tags <em>%s</em> merged into tag <em>%s</em>'),
     196          implode(', ', $tags_deleted),
     197          $name_of_tag[$destination_tag_id]
     198          )
     199        );
     200    }
     201  }
     202}
     203
     204
     205// +-----------------------------------------------------------------------+
    104206// |                               delete tags                             |
    105207// +-----------------------------------------------------------------------+
     
    113215;';
    114216  $tag_names = array_from_query($query, 'name');
    115  
    116   $query = '
    117 DELETE
    118   FROM '.IMAGE_TAG_TABLE.'
    119   WHERE tag_id IN ('.implode(',', $_POST['tags']).')
    120 ;';
    121   pwg_query($query);
    122  
    123   $query = '
    124 DELETE
    125   FROM '.TAGS_TABLE.'
    126   WHERE id IN ('.implode(',', $_POST['tags']).')
    127 ;';
    128   pwg_query($query);
     217
     218  delete_tags($_POST['tags']);
    129219 
    130220  array_push(
     
    251341  );
    252342
    253 if (isset($_POST['edit']) and isset($_POST['tags']))
    254 {
     343if ((isset($_POST['edit']) or isset($_POST['merge'])) and isset($_POST['tags']))
     344{
     345  $list_name = 'EDIT_TAGS_LIST';
     346  if (isset($_POST['merge']))
     347  {
     348    $list_name = 'MERGE_TAGS_LIST';
     349  }
     350 
    255351  $template->assign(
    256352    array(
    257       'EDIT_TAGS_LIST' => implode(',', $_POST['tags']),
     353      $list_name => implode(',', $_POST['tags']),
    258354      )
    259355    );
  • trunk/admin/themes/default/template/tags.tpl

    r11317 r12032  
    11{include file='include/tag_selection.inc.tpl'}
     2
     3{footer_script}{literal}
     4jQuery(document).ready(function(){
     5  function displayDeletionWarnings() {
     6    jQuery(".warningDeletion").show();
     7    jQuery("input[name=destination_tag]:checked").parent("label").children(".warningDeletion").hide();
     8  }
     9
     10  displayDeletionWarnings();
     11
     12  jQuery("#mergeTags label").click(function() {
     13    displayDeletionWarnings();
     14  });
     15
     16  jQuery("input[name=merge]").click(function() {
     17    if (jQuery("ul.tagSelection input[type=checkbox]:checked").length < 2) {
     18      alert("{/literal}{'Select at least two tags for merging'|@translate}{literal}");
     19      return false;
     20    }
     21  });
     22});
     23{/literal}{/footer_script}
     24
    225
    326<div class="titrePage">
     
    3154  {/if}
    3255
     56  {if isset($MERGE_TAGS_LIST)}
     57  <input type="hidden" name="merge_list" value="{$MERGE_TAGS_LIST}">
     58
     59  <fieldset id="mergeTags">
     60    <legend>{'Merge tags'|@translate}</legend>
     61    {'Select the destination tag'|@translate}<br><br>
     62    {foreach from=$tags item=tag name=tagloop}
     63    <label><input type="radio" name="destination_tag" value="{$tag.ID}"{if $smarty.foreach.tagloop.index == 0} checked="checked"{/if}> {$tag.NAME}<span class="warningDeletion"> {'(this tag will be deleted)'|@translate}</span></label><br>
     64    {/foreach}
     65    <br><input type="submit" name="confirm_merge" value="{'Confirm merge'|@translate}">
     66  </fieldset>
     67  {/if}
     68
    3369  <fieldset>
    3470    <legend>{'Add a tag'|@translate}</legend>
     
    5086      <input type="hidden" name="pwg_token" value="{$PWG_TOKEN}">
    5187      <input class="submit" type="submit" name="edit" value="{'Edit selected tags'|@translate}">
     88      <input class="submit" type="submit" name="merge" value="{'Merge selected tags'|@translate}">
    5289      <input class="submit" type="submit" name="delete" value="{'Delete selected tags'|@translate}" onclick="return confirm('{'Are you sure?'|@translate}');">
    5390    </p>
  • trunk/admin/themes/default/theme.css

    r12029 r12032  
    10791079.ui-progressbar-value { background-image: url(images/pbar-ani.gif); height:10px;margin:-1px;border:1px solid #E78F08;}
    10801080
     1081/* Tag Manager */
     1082.warningDeletion {display:none;font-style:italic;}
  • trunk/language/en_UK/admin.lang.php

    r12029 r12032  
    850850$lang['show details'] = 'show details';
    851851$lang['hide details'] = 'hide details';
     852$lang['Merge tags'] = 'Merge tags';
     853$lang['Select the destination tag'] = 'Select the destination tag';
     854$lang['(this tag will be deleted)'] = '(this tag will be deleted)';
     855$lang['Confirm merge'] = 'Confirm merge';
     856$lang['Merge selected tags'] = 'Merge selected tags';
     857$lang['No destination tag selected'] = 'No destination tag selected';
     858$lang['Tags <em>%s</em> merged into tag <em>%s</em>'] = 'Tags <em>%s</em> merged into tag <em>%s</em>';
     859$lang['Select at least two tags for merging'] = 'Select at least two tags for merging';
    852860?>
  • trunk/language/fr_FR/admin.lang.php

    r12029 r12032  
    859859$lang['show details'] = 'montrer les détails';
    860860$lang['hide details'] = 'cacher les détails';
     861$lang['Merge tags'] = 'Fusionner les tags';
     862$lang['Select the destination tag'] = 'Sélectionnez le tag de destination';
     863$lang['(this tag will be deleted)'] = '(ce tag sera supprimé)';
     864$lang['Confirm merge'] = 'Confirmez la fusion';
     865$lang['Merge selected tags'] = 'Fusionner les tags sélectionnés';
     866$lang['No destination tag selected'] = 'Vous n\'avez pas sélectionné de tag de destination';
     867$lang['Tags <em>%s</em> merged into tag <em>%s</em>'] = 'Les tags <em>%s</em> ont été fusionnés dans le tag <em>%s</em>';
     868$lang['Select at least two tags for merging'] = 'Sélectionnez au moins deux tags pour la fusion';
    861869?>
Note: See TracChangeset for help on using the changeset viewer.