function renameTag($blogid, $id, $name) { // 1. If tag with new name already exists, skip the tag creation process. // 2. If tag with new name does not exist in this service, create new tag. // 3. Modify the tag relation information // 4. If older tag is not used anymore, drop the tag. $oldTagId = $id; $newTagId = addTag($blogid, $name); $query = DBModel::getInstance(); $query->reset("TagRelations"); $query->setAttribute('tag', $newTagId); $query->setQualifier('blogid', 'equals', $blogid); $query->setQualifier('tag', 'equals', $oldTagId); $query->update(); deleteTagById($blogid, $oldTagId); return $newTagId; }
<?php /// Copyright (c) 2004-2015, Needlworks / Tatter Network Foundation /// All rights reserved. Licensed under the GPL. /// See the GNU General Public License for more details. (/documents/LICENSE, /documents/COPYRIGHT) if (count($_POST) > 0) { $IV = array('POST' => array('deleteTag' => array('id', 'mandatory' => false), 'modifyTag' => array('id', 'mandatory' => false), 'newName' => array('string', 'mandatory' => false))); } require ROOT . '/library/preprocessor.php'; importlib('model.blog.tag'); importlib('model.blog.entry'); $blogid = getBlogId(); if (!empty($_POST['deleteTag'])) { deleteTagById($blogid, $_POST['deleteTag']); Respond::ResultPage(0); exit; } if (!empty($_POST['modifyTag']) && !empty($_POST['newName'])) { $newTagId = renameTag($blogid, $_POST['modifyTag'], $_POST['newName']); $newTagList = getTagListTemplate(getSiteTags($blogid)); $newEntryList = '<a href="' . $context->getProperty('uri.blog') . '/owner/entry/?tagId=' . $newTagId . '">' . _f('"%1" 태그를 갖는 모든 글의 목록을 봅니다', $_POST['newName']) . '</a>'; $result = array('error' => 0, 'tagId' => $newTagId, 'entryList' => $newEntryList, 'tagList' => $newTagList); Respond::PrintResult($result); exit; } if (!empty($_POST['id']) && !empty($_POST['category'])) { $entries = array(); foreach (getEntriesByTagId($blogid, $_POST['id']) as $entry) { $entries[] = $entry['id']; } changeCategoryOfEntries($blogid, implode(',', $entries), $_POST['category']);