1f61105deSAdrian Lang<?php 2f61105deSAdrian Lang 30cfde7e9SMichael Großeif (!defined('DOKU_INC')) { 40cfde7e9SMichael Große die(); 50cfde7e9SMichael Große} 63496cc8aSAndreas Gohr 7e4543b6dSAdrian Langclass helper_plugin_tagging extends DokuWiki_Plugin { 8f61105deSAdrian Lang 9289f50bdSAndreas Gohr /** 10b12334e1SAndreas Gohr * Gives access to the database 11b12334e1SAndreas Gohr * 12b12334e1SAndreas Gohr * Initializes the SQLite helper and register the CLEANTAG function 13b12334e1SAndreas Gohr * 14b12334e1SAndreas Gohr * @return helper_plugin_sqlite|bool false if initialization fails 15289f50bdSAndreas Gohr */ 16289f50bdSAndreas Gohr public function getDB() { 17302a38efSAndreas Gohr static $db = null; 18f61105deSAdrian Lang if (!is_null($db)) { 19f61105deSAdrian Lang return $db; 20f61105deSAdrian Lang } 21f61105deSAdrian Lang 22302a38efSAndreas Gohr /** @var helper_plugin_sqlite $db */ 23f61105deSAdrian Lang $db = plugin_load('helper', 'sqlite'); 24f61105deSAdrian Lang if (is_null($db)) { 25f61105deSAdrian Lang msg('The tagging plugin needs the sqlite plugin', -1); 26f61105deSAdrian Lang return false; 27f61105deSAdrian Lang } 287e6afce6SAndreas Gohr $db->init('tagging', dirname(__FILE__) . '/db/'); 29302a38efSAndreas Gohr $db->create_function('CLEANTAG', array($this, 'cleanTag'), 1); 30f61105deSAdrian Lang return $db; 31f61105deSAdrian Lang } 32f61105deSAdrian Lang 33302a38efSAndreas Gohr /** 342ace74f4SAndreas Gohr * Return the user to use for accessing tags 352ace74f4SAndreas Gohr * 362ace74f4SAndreas Gohr * Handles the singleuser mode by returning 'auto' as user. Returnes false when no user is logged in. 372ace74f4SAndreas Gohr * 382ace74f4SAndreas Gohr * @return bool|string 392ace74f4SAndreas Gohr */ 402ace74f4SAndreas Gohr public function getUser() { 410cfde7e9SMichael Große if (!isset($_SERVER['REMOTE_USER'])) { 420cfde7e9SMichael Große return false; 430cfde7e9SMichael Große } 440cfde7e9SMichael Große if ($this->getConf('singleusermode')) { 450cfde7e9SMichael Große return 'auto'; 460cfde7e9SMichael Große } 472ace74f4SAndreas Gohr return $_SERVER['REMOTE_USER']; 482ace74f4SAndreas Gohr } 492ace74f4SAndreas Gohr 502ace74f4SAndreas Gohr /** 51302a38efSAndreas Gohr * Canonicalizes the tag to its lower case nospace form 52302a38efSAndreas Gohr * 53302a38efSAndreas Gohr * @param $tag 540cfde7e9SMichael Große * 55302a38efSAndreas Gohr * @return string 56302a38efSAndreas Gohr */ 57302a38efSAndreas Gohr public function cleanTag($tag) { 58302a38efSAndreas Gohr $tag = str_replace(' ', '', $tag); 5950547994SMichael Große $tag = str_replace('-', '', $tag); 6050547994SMichael Große $tag = str_replace('_', '', $tag); 61302a38efSAndreas Gohr $tag = utf8_strtolower($tag); 62302a38efSAndreas Gohr return $tag; 63302a38efSAndreas Gohr } 64302a38efSAndreas Gohr 6556d82720SAndreas Gohr /** 6631396860SSzymon Olewniczak * Canonicalizes the namespace, remove the first colon and add glob 6731396860SSzymon Olewniczak * 6831396860SSzymon Olewniczak * @param $namespace 6931396860SSzymon Olewniczak * 7031396860SSzymon Olewniczak * @return string 7131396860SSzymon Olewniczak */ 7231396860SSzymon Olewniczak public function globNamespace($namespace) { 7331396860SSzymon Olewniczak return cleanId($namespace) . '%'; 7431396860SSzymon Olewniczak } 7531396860SSzymon Olewniczak 7631396860SSzymon Olewniczak /** 7756d82720SAndreas Gohr * Create or Update tags of a page 7856d82720SAndreas Gohr * 7956d82720SAndreas Gohr * Uses the translation plugin to store the language of a page (if available) 8056d82720SAndreas Gohr * 8156d82720SAndreas Gohr * @param string $id The page ID 8256d82720SAndreas Gohr * @param string $user 8356d82720SAndreas Gohr * @param array $tags 840cfde7e9SMichael Große * 8556d82720SAndreas Gohr * @return bool|SQLiteResult 8656d82720SAndreas Gohr */ 87f61105deSAdrian Lang public function replaceTags($id, $user, $tags) { 8856d82720SAndreas Gohr global $conf; 8956d82720SAndreas Gohr /** @var helper_plugin_translation $trans */ 9056d82720SAndreas Gohr $trans = plugin_load('helper', 'translation'); 9156d82720SAndreas Gohr if ($trans) { 9256d82720SAndreas Gohr $lang = $trans->realLC($trans->getLangPart($id)); 9356d82720SAndreas Gohr } else { 9456d82720SAndreas Gohr $lang = $conf['lang']; 9556d82720SAndreas Gohr } 9656d82720SAndreas Gohr 97f61105deSAdrian Lang $db = $this->getDB(); 98f61105deSAdrian Lang $db->query('BEGIN TRANSACTION'); 99f61105deSAdrian Lang $queries = array(array('DELETE FROM taggings WHERE pid = ? AND tagger = ?', $id, $user)); 100f61105deSAdrian Lang foreach ($tags as $tag) { 10156d82720SAndreas Gohr $queries[] = array('INSERT INTO taggings (pid, tagger, tag, lang) VALUES(?, ?, ?, ?)', $id, $user, $tag, $lang); 102f61105deSAdrian Lang } 103f61105deSAdrian Lang 104f61105deSAdrian Lang foreach ($queries as $query) { 105f61105deSAdrian Lang if (!call_user_func_array(array($db, 'query'), $query)) { 106f61105deSAdrian Lang $db->query('ROLLBACK TRANSACTION'); 107f61105deSAdrian Lang return false; 108f61105deSAdrian Lang } 109f61105deSAdrian Lang } 110f61105deSAdrian Lang return $db->query('COMMIT TRANSACTION'); 111f61105deSAdrian Lang } 112f61105deSAdrian Lang 1130a518a11SAndreas Gohr /** 114b12334e1SAndreas Gohr * Get a list of Tags or Pages matching search criteria 1150a518a11SAndreas Gohr * 116b12334e1SAndreas Gohr * @param array $filter What to search for array('field' => 'searchterm') 117b12334e1SAndreas Gohr * @param string $type What field to return 'tag'|'pid' 118077ff864SAndreas Gohr * @param int $limit Limit to this many results, 0 for all 1190cfde7e9SMichael Große * 1200a518a11SAndreas Gohr * @return array associative array in form of value => count 1210a518a11SAndreas Gohr */ 122077ff864SAndreas Gohr public function findItems($filter, $type, $limit = 0) { 123f61105deSAdrian Lang $db = $this->getDB(); 1240cfde7e9SMichael Große if (!$db) { 1250cfde7e9SMichael Große return array(); 1260cfde7e9SMichael Große } 127f61105deSAdrian Lang 128b12334e1SAndreas Gohr // create WHERE clause 129b12334e1SAndreas Gohr $where = '1=1'; 130b12334e1SAndreas Gohr foreach ($filter as $field => $value) { 131b12334e1SAndreas Gohr // compare clean tags only 132b12334e1SAndreas Gohr if ($field === 'tag') { 133b12334e1SAndreas Gohr $field = 'CLEANTAG(tag)'; 134b12334e1SAndreas Gohr $q = 'CLEANTAG(?)'; 135b12334e1SAndreas Gohr } else { 136b12334e1SAndreas Gohr $q = '?'; 137b12334e1SAndreas Gohr } 138204c069bSMichael Große 139204c069bSMichael Große if (substr($field, 0, 6) === 'notpid') { 140204c069bSMichael Große $field = 'pid'; 141204c069bSMichael Große 142204c069bSMichael Große // detect LIKE filters 143204c069bSMichael Große if ($this->useLike($value)) { 144204c069bSMichael Große $where .= " AND $field NOT LIKE $q"; 145204c069bSMichael Große } else { 146204c069bSMichael Große $where .= " AND $field != $q"; 147204c069bSMichael Große } 148204c069bSMichael Große } else { 149b12334e1SAndreas Gohr // detect LIKE filters 150b12334e1SAndreas Gohr if ($this->useLike($value)) { 151b12334e1SAndreas Gohr $where .= " AND $field LIKE $q"; 152b12334e1SAndreas Gohr } else { 153b12334e1SAndreas Gohr $where .= " AND $field = $q"; 154b12334e1SAndreas Gohr } 155b12334e1SAndreas Gohr } 156204c069bSMichael Große } 1576c37861bSJulian Einwag $where .= ' AND GETACCESSLEVEL(pid) >= ' . AUTH_READ; 15859a953ffSMichael Große 159b12334e1SAndreas Gohr // group and order 160b12334e1SAndreas Gohr if ($type == 'tag') { 161b12334e1SAndreas Gohr $groupby = 'CLEANTAG(tag)'; 162b12334e1SAndreas Gohr $orderby = 'CLEANTAG(tag)'; 163b12334e1SAndreas Gohr } else { 164b12334e1SAndreas Gohr $groupby = $type; 165466524f5SAndreas Gohr $orderby = "cnt DESC, $type"; 166b12334e1SAndreas Gohr } 167b12334e1SAndreas Gohr 168077ff864SAndreas Gohr // limit results 169077ff864SAndreas Gohr if ($limit) { 170077ff864SAndreas Gohr $limit = " LIMIT $limit"; 171077ff864SAndreas Gohr } else { 172077ff864SAndreas Gohr $limit = ''; 173077ff864SAndreas Gohr } 174077ff864SAndreas Gohr 175b12334e1SAndreas Gohr // create SQL 176b12334e1SAndreas Gohr $sql = "SELECT $type AS item, COUNT(*) AS cnt 177b12334e1SAndreas Gohr FROM taggings 178b12334e1SAndreas Gohr WHERE $where 179b12334e1SAndreas Gohr GROUP BY $groupby 180077ff864SAndreas Gohr ORDER BY $orderby 181077ff864SAndreas Gohr $limit 182077ff864SAndreas Gohr "; 183b12334e1SAndreas Gohr 184b12334e1SAndreas Gohr // run query and turn into associative array 185b12334e1SAndreas Gohr $res = $db->query($sql, array_values($filter)); 186f61105deSAdrian Lang $res = $db->res2arr($res); 187b12334e1SAndreas Gohr 188f61105deSAdrian Lang $ret = array(); 189b12334e1SAndreas Gohr foreach ($res as $row) { 190b12334e1SAndreas Gohr $ret[$row['item']] = $row['cnt']; 191f61105deSAdrian Lang } 192f61105deSAdrian Lang return $ret; 193f61105deSAdrian Lang } 194f61105deSAdrian Lang 195b12334e1SAndreas Gohr /** 196b12334e1SAndreas Gohr * Check if the given string is a LIKE statement 197b12334e1SAndreas Gohr * 198b12334e1SAndreas Gohr * @param string $value 1990cfde7e9SMichael Große * 200b12334e1SAndreas Gohr * @return bool 201b12334e1SAndreas Gohr */ 202b12334e1SAndreas Gohr private function useLike($value) { 203b12334e1SAndreas Gohr return strpos($value, '%') === 0 || strrpos($value, '%') === strlen($value) - 1; 204b2073787SDominik Eckelmann } 205b2073787SDominik Eckelmann 206302a38efSAndreas Gohr /** 207302a38efSAndreas Gohr * Constructs the URL to search for a tag 208302a38efSAndreas Gohr * 2095540f91dSAndreas Gohr * @param string $tag 2105540f91dSAndreas Gohr * @param string $ns 2110cfde7e9SMichael Große * 212302a38efSAndreas Gohr * @return string 213302a38efSAndreas Gohr */ 2145540f91dSAndreas Gohr public function getTagSearchURL($tag, $ns = '') { 215bed9f360SAndreas Gohr // wrap tag in quotes if non clean 2162cb25ec1SAndreas Gohr $ctag = utf8_stripspecials($this->cleanTag($tag)); 2170cfde7e9SMichael Große if ($ctag != utf8_strtolower($tag)) { 2180cfde7e9SMichael Große $tag = '"' . $tag . '"'; 2190cfde7e9SMichael Große } 220bed9f360SAndreas Gohr 221bed9f360SAndreas Gohr $ret = '?do=search&id=' . rawurlencode($tag); 2220cfde7e9SMichael Große if ($ns) { 2230cfde7e9SMichael Große $ret .= rawurlencode(' @' . $ns); 2240cfde7e9SMichael Große } 2255540f91dSAndreas Gohr 2265540f91dSAndreas Gohr return $ret; 227f61105deSAdrian Lang } 228f61105deSAdrian Lang 2295540f91dSAndreas Gohr /** 2305540f91dSAndreas Gohr * Calculates the size levels for the given list of clouds 2315540f91dSAndreas Gohr * 2325540f91dSAndreas Gohr * Automatically determines sensible tresholds 2335540f91dSAndreas Gohr * 2345540f91dSAndreas Gohr * @param array $tags list of tags => count 2355540f91dSAndreas Gohr * @param int $levels 2360cfde7e9SMichael Große * 2375540f91dSAndreas Gohr * @return mixed 2385540f91dSAndreas Gohr */ 239f61105deSAdrian Lang public function cloudData($tags, $levels = 10) { 240f61105deSAdrian Lang $min = min($tags); 241f61105deSAdrian Lang $max = max($tags); 242f61105deSAdrian Lang 243f61105deSAdrian Lang // calculate tresholds 244f61105deSAdrian Lang $tresholds = array(); 245f61105deSAdrian Lang for ($i = 0; $i <= $levels; $i++) { 246f61105deSAdrian Lang $tresholds[$i] = pow($max - $min + 1, $i / $levels) + $min - 1; 247f61105deSAdrian Lang } 248f61105deSAdrian Lang 249f61105deSAdrian Lang // assign weights 250f61105deSAdrian Lang foreach ($tags as $tag => $cnt) { 251f61105deSAdrian Lang foreach ($tresholds as $tresh => $val) { 252f61105deSAdrian Lang if ($cnt <= $val) { 253f61105deSAdrian Lang $tags[$tag] = $tresh; 254f61105deSAdrian Lang break; 255f61105deSAdrian Lang } 256f61105deSAdrian Lang $tags[$tag] = $levels; 257f61105deSAdrian Lang } 258f61105deSAdrian Lang } 259f61105deSAdrian Lang return $tags; 260f61105deSAdrian Lang } 261f61105deSAdrian Lang 2625540f91dSAndreas Gohr /** 2635540f91dSAndreas Gohr * Display a tag cloud 2645540f91dSAndreas Gohr * 2655540f91dSAndreas Gohr * @param array $tags list of tags => count 2665540f91dSAndreas Gohr * @param string $type 'tag' 2675540f91dSAndreas Gohr * @param Callable $func The function to print the link (gets tag and ns) 2685540f91dSAndreas Gohr * @param bool $wrap wrap cloud in UL tags? 2695540f91dSAndreas Gohr * @param bool $return returnn HTML instead of printing? 2705540f91dSAndreas Gohr * @param string $ns Add this namespace to search links 2710cfde7e9SMichael Große * 2725540f91dSAndreas Gohr * @return string 2735540f91dSAndreas Gohr */ 2745540f91dSAndreas Gohr public function html_cloud($tags, $type, $func, $wrap = true, $return = false, $ns = '') { 275a66f6715SAndreas Gohr global $INFO; 276a66f6715SAndreas Gohr 277a66f6715SAndreas Gohr $hidden_str = $this->getConf('hiddenprefix'); 278a66f6715SAndreas Gohr $hidden_len = strlen($hidden_str); 279a66f6715SAndreas Gohr 280f61105deSAdrian Lang $ret = ''; 2810cfde7e9SMichael Große if ($wrap) { 2820cfde7e9SMichael Große $ret .= '<ul class="tagging_cloud clearfix">'; 2830cfde7e9SMichael Große } 284f61105deSAdrian Lang if (count($tags) === 0) { 285f61105deSAdrian Lang // Produce valid XHTML (ul needs a child) 286f61105deSAdrian Lang $this->setupLocale(); 287f61105deSAdrian Lang $ret .= '<li><div class="li">' . $this->lang['js']['no' . $type . 's'] . '</div></li>'; 288f61105deSAdrian Lang } else { 289f61105deSAdrian Lang $tags = $this->cloudData($tags); 290f61105deSAdrian Lang foreach ($tags as $val => $size) { 291a66f6715SAndreas Gohr // skip hidden tags for users that can't edit 292a66f6715SAndreas Gohr if ($type == 'tag' and 293a66f6715SAndreas Gohr $hidden_len and 294a66f6715SAndreas Gohr substr($val, 0, $hidden_len) == $hidden_str and 295a66f6715SAndreas Gohr !($this->getUser() && $INFO['writable']) 296a66f6715SAndreas Gohr ) { 297a66f6715SAndreas Gohr continue; 298a66f6715SAndreas Gohr } 299a66f6715SAndreas Gohr 300f61105deSAdrian Lang $ret .= '<li class="t' . $size . '"><div class="li">'; 3015540f91dSAndreas Gohr $ret .= call_user_func($func, $val, $ns); 302f61105deSAdrian Lang $ret .= '</div></li>'; 303f61105deSAdrian Lang } 304f61105deSAdrian Lang } 3050cfde7e9SMichael Große if ($wrap) { 3060cfde7e9SMichael Große $ret .= '</ul>'; 3070cfde7e9SMichael Große } 3080cfde7e9SMichael Große if ($return) { 3090cfde7e9SMichael Große return $ret; 3100cfde7e9SMichael Große } 311f61105deSAdrian Lang echo $ret; 3125540f91dSAndreas Gohr return ''; 313f61105deSAdrian Lang } 314f61105deSAdrian Lang 3155540f91dSAndreas Gohr /** 3165540f91dSAndreas Gohr * Get the link to a search for the given tag 3175540f91dSAndreas Gohr * 3185540f91dSAndreas Gohr * @param string $tag search for this tag 3195540f91dSAndreas Gohr * @param string $ns limit search to this namespace 3200cfde7e9SMichael Große * 3215540f91dSAndreas Gohr * @return string 3225540f91dSAndreas Gohr */ 3235540f91dSAndreas Gohr protected function linkToSearch($tag, $ns = '') { 3245540f91dSAndreas Gohr return '<a href="' . hsc($this->getTagSearchURL($tag, $ns)) . '">' . $tag . '</a>'; 325f61105deSAdrian Lang } 326f61105deSAdrian Lang 327fb1d0583SAndreas Gohr /** 328fb1d0583SAndreas Gohr * Display the Tags for the current page and prepare the tag editing form 3293496cc8aSAndreas Gohr * 3303496cc8aSAndreas Gohr * @param bool $print Should the HTML be printed or returned? 3310cfde7e9SMichael Große * 3323496cc8aSAndreas Gohr * @return string 333fb1d0583SAndreas Gohr */ 3343496cc8aSAndreas Gohr public function tpl_tags($print = true) { 335f61105deSAdrian Lang global $INFO; 336f61105deSAdrian Lang global $lang; 3373bf0e2f1SMichael Große 3383bf0e2f1SMichael Große $filter = array('pid' => $INFO['id']); 3393bf0e2f1SMichael Große if ($this->getConf('singleusermode')) { 3403bf0e2f1SMichael Große $filter['tagger'] = 'auto'; 3413bf0e2f1SMichael Große } 3423bf0e2f1SMichael Große 3433bf0e2f1SMichael Große $tags = $this->findItems($filter, 'tag'); 3443496cc8aSAndreas Gohr 3453496cc8aSAndreas Gohr $ret = ''; 3463496cc8aSAndreas Gohr 3473496cc8aSAndreas Gohr $ret .= '<div class="plugin_tagging_edit">'; 3483496cc8aSAndreas Gohr $ret .= $this->html_cloud($tags, 'tag', array($this, 'linkToSearch'), true, true); 349f61105deSAdrian Lang 3502ace74f4SAndreas Gohr if ($this->getUser() && $INFO['writable']) { 351f61105deSAdrian Lang $lang['btn_tagging_edit'] = $lang['btn_secedit']; 3523496cc8aSAndreas Gohr $ret .= html_btn('tagging_edit', $INFO['id'], '', array()); 353289f50bdSAndreas Gohr $form = new Doku_Form(array('id' => 'tagging__edit')); 354fbf38c5bSAndreas Gohr $form->addHidden('tagging[id]', $INFO['id']); 355289f50bdSAndreas Gohr $form->addHidden('call', 'plugin_tagging_save'); 3562ace74f4SAndreas Gohr $form->addElement(form_makeTextField('tagging[tags]', implode(', ', array_keys($this->findItems(array('pid' => $INFO['id'], 'tagger' => $this->getUser()), 'tag'))))); 357289f50bdSAndreas Gohr $form->addElement(form_makeButton('submit', 'save', $lang['btn_save'], array('id' => 'tagging__edit_save'))); 358289f50bdSAndreas Gohr $form->addElement(form_makeButton('submit', 'cancel', $lang['btn_cancel'], array('id' => 'tagging__edit_cancel'))); 3593496cc8aSAndreas Gohr $ret .= $form->getForm(); 360f61105deSAdrian Lang } 3613496cc8aSAndreas Gohr $ret .= '</div>'; 3623496cc8aSAndreas Gohr 3630cfde7e9SMichael Große if ($print) { 3640cfde7e9SMichael Große echo $ret; 3650cfde7e9SMichael Große } 3663496cc8aSAndreas Gohr return $ret; 367f61105deSAdrian Lang } 368872edc7cSRené Corinth 3698a1a3846SAndreas Gohr /** 370a99b66c1SSzymon Olewniczak * @param string $namespace empty for entire wiki 371a99b66c1SSzymon Olewniczak * 3728a1a3846SAndreas Gohr * @return array 3738a1a3846SAndreas Gohr */ 374a99b66c1SSzymon Olewniczak public function getAllTags($namespace='') { 375872edc7cSRené Corinth 376872edc7cSRené Corinth $db = $this->getDb(); 377872edc7cSRené Corinth 378*193a767dSSzymon Olewniczak $query = 'SELECT pid, 379*193a767dSSzymon Olewniczak CLEANTAG(tag) as tid, 380*193a767dSSzymon Olewniczak GROUP_CONCAT(tag, ", ") AS orig, 381*193a767dSSzymon Olewniczak GROUP_CONCAT(tagger, ", ") AS taggers, 382*193a767dSSzymon Olewniczak COUNT(*) AS "count" 383*193a767dSSzymon Olewniczak FROM (SELECT * FROM "taggings" ORDER BY tagger) /*sort taggers inside GROUP_CONCAT*/ 384*193a767dSSzymon Olewniczak WHERE pid LIKE ? 385*193a767dSSzymon Olewniczak GROUP BY tid 386*193a767dSSzymon Olewniczak ORDER BY tag'; 387*193a767dSSzymon Olewniczak $res = $db->query($query, $this->globNamespace($namespace)); 388872edc7cSRené Corinth 389*193a767dSSzymon Olewniczak return $db->res2arr($res); 390872edc7cSRené Corinth } 391872edc7cSRené Corinth 3928a1a3846SAndreas Gohr /** 3938a1a3846SAndreas Gohr * Renames a tag 3948a1a3846SAndreas Gohr * 3958a1a3846SAndreas Gohr * @param string $formerTagName 3968a1a3846SAndreas Gohr * @param string $newTagName 3978a1a3846SAndreas Gohr */ 398872edc7cSRené Corinth public function renameTag($formerTagName, $newTagName) { 399872edc7cSRené Corinth 400872edc7cSRené Corinth if (empty($formerTagName) || empty($newTagName)) { 4018a1a3846SAndreas Gohr msg($this->getLang("admin enter tag names"), -1); 4028a1a3846SAndreas Gohr return; 403872edc7cSRené Corinth } 404872edc7cSRené Corinth 405872edc7cSRené Corinth $db = $this->getDb(); 406872edc7cSRené Corinth 407fb1d0583SAndreas Gohr $res = $db->query('SELECT pid FROM taggings WHERE CLEANTAG(tag) = ?', $this->cleanTag($formerTagName)); 408872edc7cSRené Corinth $check = $db->res2arr($res); 409872edc7cSRené Corinth 410872edc7cSRené Corinth if (empty($check)) { 4118a1a3846SAndreas Gohr msg($this->getLang("admin tag does not exists"), -1); 4128a1a3846SAndreas Gohr return; 413872edc7cSRené Corinth } 414872edc7cSRené Corinth 415fb1d0583SAndreas Gohr $res = $db->query("UPDATE taggings SET tag = ? WHERE CLEANTAG(tag) = ?", $newTagName, $this->cleanTag($formerTagName)); 416872edc7cSRené Corinth $db->res2arr($res); 417872edc7cSRené Corinth 418fb1d0583SAndreas Gohr msg($this->getLang("admin renamed"), 1); 4198a1a3846SAndreas Gohr return; 420872edc7cSRené Corinth } 421872edc7cSRené Corinth 4228f630140SSzymon Olewniczak /** 4238f630140SSzymon Olewniczak * Deletes a tag 4248f630140SSzymon Olewniczak * 4258f630140SSzymon Olewniczak * @param array $tags 42631396860SSzymon Olewniczak * @param string $namespace current namespace context as in getAllTags() 4278f630140SSzymon Olewniczak */ 42831396860SSzymon Olewniczak public function deleteTags($tags, $namespace='') { 4298f630140SSzymon Olewniczak if (empty($tags)) return; 4308f630140SSzymon Olewniczak 43131396860SSzymon Olewniczak $namespace = cleanId($namespace); 43231396860SSzymon Olewniczak 4338f630140SSzymon Olewniczak $db = $this->getDb(); 4348f630140SSzymon Olewniczak 43531396860SSzymon Olewniczak $query = 'DELETE FROM taggings WHERE pid LIKE ? AND (' . 43631396860SSzymon Olewniczak implode(' OR ', array_fill(0, count($tags), 'CLEANTAG(tag) = ?')).')'; 43731396860SSzymon Olewniczak 43831396860SSzymon Olewniczak $args = array_map(array($this, 'cleanTag'), $tags); 43931396860SSzymon Olewniczak array_unshift($args, $this->globNamespace($namespace)); 44031396860SSzymon Olewniczak $res = $db->query($query, $args); 4418f630140SSzymon Olewniczak 4428f630140SSzymon Olewniczak msg(sprintf($this->getLang("admin deleted"), count($tags), $res->rowCount()), 1); 4438f630140SSzymon Olewniczak return; 4448f630140SSzymon Olewniczak } 445f61105deSAdrian Lang} 446