]> projects.mako.cc - scuttle/blobdiff - services/tagservice.php
initial patch to cause scuttle to work with PHP 8.2
[scuttle] / services / tagservice.php
index 6bfbf151d582a24401c121697832a5c14df9b2ca..f749f9552e8b9a76acf9a4389ef8da8d9a3d10fa 100644 (file)
@@ -1,26 +1,24 @@
 <?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
@@ -45,7 +43,7 @@ class TagService {
         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');
             }
         }
@@ -64,7 +62,7 @@ class TagService {
 
         // 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);
@@ -109,7 +107,7 @@ class TagService {
     } 
     
     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) .'"';
@@ -160,7 +158,7 @@ class TagService {
     }
 
     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';
@@ -230,7 +228,7 @@ class TagService {
 
     // 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()) {
@@ -301,7 +299,7 @@ class TagService {
     }
 
     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;
@@ -350,9 +348,8 @@ class TagService {
         }
 
         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;
     }
 
@@ -360,4 +357,3 @@ class TagService {
     function getTableName()       { return $this->tablename; }
     function setTableName($value) { $this->tablename = $value; }
 }
-?>
\ No newline at end of file

Benjamin Mako Hill || Want to submit a patch?