]> git.mxchange.org Git - friendica.git/commitdiff
Move files to src
authorAdam Magness <adam.magness@gmail.com>
Wed, 10 Jan 2018 16:46:05 +0000 (11:46 -0500)
committerAdam Magness <adam.magness@gmail.com>
Wed, 10 Jan 2018 16:46:05 +0000 (11:46 -0500)
Move files.php and create Term class

include/files.php [deleted file]
src/Model/Term.php [new file with mode: 0644]

diff --git a/include/files.php b/include/files.php
deleted file mode 100644 (file)
index 64fe6a3..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-<?php
-
-function create_files_from_item($itemid)
-{
-       $messages = q("SELECT `guid`, `uid`, `id`, `edited`, `deleted`, `file`, `parent` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid));
-       if (!$messages) {
-               return;
-       }
-
-       $message = $messages[0];
-
-       // Clean up all tags
-       q("DELETE FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d)",
-               intval(TERM_OBJ_POST),
-               intval($itemid),
-               intval(TERM_FILE),
-               intval(TERM_CATEGORY));
-
-       if ($message["deleted"])
-               return;
-
-       if (preg_match_all("/\[(.*?)\]/ism", $message["file"], $files)) {
-               foreach ($files[1] as $file) {
-                       q("INSERT INTO `term` (`uid`, `oid`, `otype`, `type`, `term`) VALUES (%d, %d, %d, %d, '%s')",
-                               intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval(TERM_FILE), dbesc($file));
-               }
-       }
-
-       if (preg_match_all("/\<(.*?)\>/ism", $message["file"], $files)) {
-               foreach ($files[1] as $file) {
-                       q("INSERT INTO `term` (`uid`, `oid`, `otype`, `type`, `term`) VALUES (%d, %d, %d, %d, '%s')",
-                               intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval(TERM_CATEGORY), dbesc($file));
-               }
-       }
-}
-
-function create_files_from_itemuri($itemuri, $uid)
-{
-       $messages = q("SELECT `id` FROM `item` WHERE uri ='%s' AND uid=%d", dbesc($itemuri), intval($uid));
-
-       if (count($messages)) {
-               foreach ($messages as $message)
-                       create_files_from_item($message["id"]);
-       }
-}
-
-function update_files_for_items()
-{
-       $messages = q("SELECT `id` FROM `item` where file !=''");
-
-       foreach ($messages as $message) {
-               echo $message["id"] . "\n";
-               create_files_from_item($message["id"]);
-       }
-}
diff --git a/src/Model/Term.php b/src/Model/Term.php
new file mode 100644 (file)
index 0000000..3b327b5
--- /dev/null
@@ -0,0 +1,74 @@
+<?php
+/**
+ * @file src/Model/Term
+ */
+namespace Friendica\Model;
+
+class Term
+{
+       /**
+        * @param integer $itemid item id
+        * @return void
+        */
+       function create_files_from_item($itemid)
+       {
+               $messages = q("SELECT `guid`, `uid`, `id`, `edited`, `deleted`, `file`, `parent` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid));
+               if (!$messages) {
+                       return;
+               }
+
+               $message = $messages[0];
+
+               // Clean up all tags
+               q("DELETE FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d)",
+                       intval(TERM_OBJ_POST),
+                       intval($itemid),
+                       intval(TERM_FILE),
+                       intval(TERM_CATEGORY));
+
+               if ($message["deleted"])
+                       return;
+
+               if (preg_match_all("/\[(.*?)\]/ism", $message["file"], $files)) {
+                       foreach ($files[1] as $file) {
+                               q("INSERT INTO `term` (`uid`, `oid`, `otype`, `type`, `term`) VALUES (%d, %d, %d, %d, '%s')",
+                                       intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval(TERM_FILE), dbesc($file));
+                       }
+               }
+
+               if (preg_match_all("/\<(.*?)\>/ism", $message["file"], $files)) {
+                       foreach ($files[1] as $file) {
+                               q("INSERT INTO `term` (`uid`, `oid`, `otype`, `type`, `term`) VALUES (%d, %d, %d, %d, '%s')",
+                                       intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval(TERM_CATEGORY), dbesc($file));
+                       }
+               }
+       }
+
+       /**
+        * @param string  $itemuri item uri
+        * @param integer $uid     uid
+        * @return void
+        */
+       function create_files_from_itemuri($itemuri, $uid)
+       {
+               $messages = q("SELECT `id` FROM `item` WHERE uri ='%s' AND uid=%d", dbesc($itemuri), intval($uid));
+
+               if (count($messages)) {
+                       foreach ($messages as $message)
+                               create_files_from_item($message["id"]);
+               }
+       }
+
+       /**
+        * @return void
+        */
+       function update_files_for_items()
+       {
+               $messages = q("SELECT `id` FROM `item` where file !=''");
+
+               foreach ($messages as $message) {
+                       echo $message["id"] . "\n";
+                       create_files_from_item($message["id"]);
+               }
+       }
+}
\ No newline at end of file