aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--admin/tags.php117
-rw-r--r--admin/themes/default/template/tags.tpl25
2 files changed, 140 insertions, 2 deletions
diff --git a/admin/tags.php b/admin/tags.php
index 077b3cd67..cf5b36fb6 100644
--- a/admin/tags.php
+++ b/admin/tags.php
@@ -99,6 +99,115 @@ SELECT id, name
$updates
);
}
+// +-----------------------------------------------------------------------+
+// | dulicate tags |
+// +-----------------------------------------------------------------------+
+
+if (isset($_POST['duplic_submit']))
+{
+ $query = '
+SELECT name
+ FROM '.TAGS_TABLE.'
+;';
+ $existing_names = array_from_query($query, 'name');
+
+
+ $current_name_of = array();
+ $query = '
+SELECT id, name
+ FROM '.TAGS_TABLE.'
+ WHERE id IN ('.$_POST['edit_list'].')
+;';
+ $result = pwg_query($query);
+ while ($row = pwg_db_fetch_assoc($result))
+ {
+ $current_name_of[ $row['id'] ] = $row['name'];
+ }
+
+ $updates = array();
+ // we must not rename tag with an already existing name
+ foreach (explode(',', $_POST['edit_list']) as $tag_id)
+ {
+ $tag_name = stripslashes($_POST['tag_name-'.$tag_id]);
+
+ if ($tag_name != $current_name_of[$tag_id])
+ {
+ if (in_array($tag_name, $existing_names))
+ {
+ array_push(
+ $page['errors'],
+ sprintf(
+ l10n('Tag "%s" already exists'),
+ $tag_name
+ )
+ );
+ }
+ else if (!empty($tag_name))
+ {
+ mass_inserts(
+ TAGS_TABLE,
+ array('name', 'url_name'),
+ array(
+ array(
+ 'name' => $tag_name,
+ 'url_name' => trigger_event('render_tag_url', $tag_name),
+ )
+ )
+ );
+ $query = '
+ SELECT id
+ FROM '.TAGS_TABLE.'
+ WHERE name = \''.$tag_name.'\'
+ ;';
+ $destination_tag = array_from_query($query, 'id');
+ $destination_tag_id = $destination_tag[0];
+ $query = '
+ SELECT
+ image_id
+ FROM '.IMAGE_TAG_TABLE.'
+ WHERE tag_id = '.$tag_id.'
+ ;';
+ $destination_tag_image_ids = array_from_query($query, 'image_id');
+ $inserts = array();
+ foreach ($destination_tag_image_ids as $image_id)
+ {
+ array_push(
+ $inserts,
+ array(
+ 'tag_id' => $destination_tag_id,
+ 'image_id' => $image_id
+ )
+ );
+ }
+
+ if (count($inserts) > 0)
+ {
+ mass_inserts(
+ IMAGE_TAG_TABLE,
+ array_keys($inserts[0]),
+ $inserts
+ );
+ }
+ array_push(
+ $page['infos'],
+ sprintf(
+ l10n('Tag "%s" is now a duplicate of "%s"'),
+ stripslashes($tag_name),
+ $current_name_of[$tag_id]
+ )
+ );
+ }
+ }
+ }
+ mass_updates(
+ TAGS_TABLE,
+ array(
+ 'primary' => array('id'),
+ 'update' => array('name', 'url_name'),
+ ),
+ $updates
+ );
+}
// +-----------------------------------------------------------------------+
// | merge tags |
@@ -340,10 +449,14 @@ $template->assign(
)
);
-if ((isset($_POST['edit']) or isset($_POST['merge'])) and isset($_POST['tags']))
+if ((isset($_POST['edit']) or isset($_POST['duplicate']) or isset($_POST['merge'])) and isset($_POST['tags']))
{
$list_name = 'EDIT_TAGS_LIST';
- if (isset($_POST['merge']))
+ if (isset($_POST['duplicate']))
+ {
+ $list_name = 'DUPLIC_TAGS_LIST';
+ }
+ elseif (isset($_POST['merge']))
{
$list_name = 'MERGE_TAGS_LIST';
}
diff --git a/admin/themes/default/template/tags.tpl b/admin/themes/default/template/tags.tpl
index 51b8c3614..a51b7d376 100644
--- a/admin/themes/default/template/tags.tpl
+++ b/admin/themes/default/template/tags.tpl
@@ -52,6 +52,30 @@ jQuery(document).ready(function(){
</p>
</fieldset>
{/if}
+ {if isset($DUPLIC_TAGS_LIST)}
+ <fieldset>
+ <legend>{'Edit tags'|@translate}</legend>
+ <input type="hidden" name="edit_list" value="{$DUPLIC_TAGS_LIST}">
+ <table class="table2">
+ <tr class="throw">
+ <th>{'Source tag'|@translate}</th>
+ <th>{'Name of the duplicate'|@translate}</th>
+ </tr>
+ {foreach from=$tags item=tag}
+ <tr>
+ <td>{$tag.NAME}</td>
+ <td><input type="text" name="tag_name-{$tag.ID}" value="{$tag.NAME}" size="30"></td>
+ </tr>
+ {/foreach}
+ </table>
+
+ <p>
+ <input type="hidden" name="pwg_token" value="{$PWG_TOKEN}">
+ <input class="submit" type="submit" name="duplic_submit" value="{'Submit'|@translate}">
+ <input class="submit" type="reset" value="{'Reset'|@translate}">
+ </p>
+ </fieldset>
+ {/if}
{if isset($MERGE_TAGS_LIST)}
<input type="hidden" name="merge_list" value="{$MERGE_TAGS_LIST}">
@@ -85,6 +109,7 @@ jQuery(document).ready(function(){
<p>
<input type="hidden" name="pwg_token" value="{$PWG_TOKEN}">
<input class="submit" type="submit" name="edit" value="{'Edit selected tags'|@translate}">
+ <input class="submit" type="submit" name="duplicate" value="{'Duplicate selected tags'|@translate}">
<input class="submit" type="submit" name="merge" value="{'Merge selected tags'|@translate}">
<input class="submit" type="submit" name="delete" value="{'Delete selected tags'|@translate}" onclick="return confirm('{'Are you sure?'|@translate}');">
</p>