<?php
class TagService {
- var $db;
- var $tablename;
-
- function &getInstance(&$db) {
- static $instance;
- if (!isset($instance))
- $instance =& new TagService($db);
- return $instance;
- }
+ var $db;
+ var $tablename;
- function TagService(&$db) {
- $this->db =& $db;
- $this->tablename = $GLOBALS['tableprefix'] .'tags';
+ function &getInstance(&$db) {
+ static $instance;
+ if (!isset($instance)) {
+ $instance = new TagService($db);
}
+ return $instance;
+ }
- function isNotSystemTag($var) {
- if (utf8_substr($var, 0, 7) == 'system:')
- return false;
- else
- return true;
- }
+ function __construct(&$db) {
+ $this->db =& $db;
+ $this->tablename = $GLOBALS['tableprefix'] .'tags';
+ }
+
+ function isNotSystemTag($var) {
+ return !(utf8_substr($var, 0, 7) == 'system:');
+ }
function attachTags($bookmarkid, $tags, $fromApi = false, $extension = NULL, $replace = true, $fromImport = false) {
// Make sure that categories is an array of trimmed strings, and that if the categories are
for ($i = 0; $i < $tags_count; $i++) {
$tags[$i] = trim(strtolower($tags[$i]));
if ($fromApi) {
- include_once(dirname(__FILE__) .'/../functions.inc.php');
+ include_once dirname(__FILE__) .'/../functions.inc.php';
$tags[$i] = convertTag($tags[$i], 'in');
}
}
// Media and file types
if (!is_null($extension)) {
- include_once(dirname(__FILE__) .'/../functions.inc.php');
+ include_once dirname(__FILE__) .'/../functions.inc.php';
if ($keys = multi_array_search($extension, $GLOBALS['filetypes'])) {
$tags[] = 'system:filetype:'. $extension;
$tags[] = 'system:media:'. array_shift($keys);
}
function deleteTag($tag) {
- $userservice =& ServiceFactory::getServiceInstance('UserService');
+ $userservice =& (new ServiceFactory())->getServiceInstance('UserService');
$logged_on_user = $userservice->getCurrentUserId();
$query = 'DELETE FROM '. $this->getTableName() .' USING '. $GLOBALS['tableprefix'] .'tags, '. $GLOBALS['tableprefix'] .'bookmarks WHERE '. $GLOBALS['tableprefix'] .'tags.bId = '. $GLOBALS['tableprefix'] .'bookmarks.bId AND '. $GLOBALS['tableprefix'] .'bookmarks.uId = '. $logged_on_user .' AND '. $GLOBALS['tableprefix'] .'tags.tag = "'. $this->db->sql_escape($tag) .'"';
}
function &getTags($userid = NULL) {
- $userservice =& ServiceFactory::getServiceInstance('UserService');
+ $userservice =& (new ServiceFactory())->getServiceInstance('UserService');
$logged_on_user = $userservice->getCurrentUserId();
$query = 'SELECT T.tag, COUNT(B.bId) AS bCount FROM '. $GLOBALS['tableprefix'] .'bookmarks AS B INNER JOIN '. $userservice->getTableName() .' AS U ON B.uId = U.'. $userservice->getFieldName('primary') .' INNER JOIN '. $GLOBALS['tableprefix'] .'tags AS T ON B.bId = T.bId';
// Returns the most popular tags used for a particular bookmark hash
function &getRelatedTagsByHash($hash, $limit = 20) {
- $userservice = & ServiceFactory :: getServiceInstance('UserService');
+ $userservice = & (new ServiceFactory())->getServiceInstance('UserService');
$sId = $userservice->getCurrentUserId();
// Logged in
if ($userservice->isLoggedOn()) {
}
function renameTag($userid, $old, $new, $fromApi = false) {
- $bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
+ $bookmarkservice =& (new ServiceFactory())->getServiceInstance('BookmarkService');
if (is_null($userid) || is_null($old) || is_null($new))
return false;
}
if ($sortOrder == 'alphabet_asc') {
- usort($output, create_function('$a,$b','return strcasecmp(utf8_deaccent($a["tag"]), utf8_deaccent($b["tag"]));'));
+ usort($output, function($a, $b) { return strcmp(utf8_strtolower($a["tag"]), utf8_strtolower($b["tag"])); });
}
-
return $output;
}
function getTableName() { return $this->tablename; }
function setTableName($value) { $this->tablename = $value; }
}
-?>
\ No newline at end of file