3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Model\Post;
24 use Friendica\Database\DBA;
25 use Friendica\Model\Item;
26 use Friendica\Model\Tag;
31 * This Model class handles category table interactions.
32 * This tables stores user-applied categories related to posts.
41 * Generates the legacy item.file field string from an item ID.
42 * Includes only file and category terms.
48 public static function getTextByURIId(int $uri_id, int $uid)
52 $tags = DBA::selectToArray('category-view', ['type', 'name'], ['uri-id' => $uri_id, 'uid' => $uid]);
53 foreach ($tags as $tag) {
54 if ($tag['type'] == self::CATEGORY) {
55 $file_text .= '<' . $tag['name'] . '>';
57 $file_text .= '[' . $tag['name'] . ']';
65 * Inserts new terms for the provided item ID based on the legacy item.file field BBCode content.
66 * Deletes all previous file terms for the same item ID.
68 * @param integer $item_id item id
73 public static function storeTextByURIId(int $uri_id, int $uid, string $files)
75 $message = Item::selectFirst(['deleted'], ['uri-id' => $uri_id, 'uid' => $uid]);
76 if (!DBA::isResult($message)) {
81 DBA::delete('post-category', ['uri-id' => $uri_id, 'uid' => $uid]);
83 if ($message['deleted']) {
87 if (preg_match_all("/\[(.*?)\]/ism", $files, $result)) {
88 foreach ($result[1] as $file) {
89 $tagid = Tag::getID($file);
94 DBA::insert('post-category', [
103 if (preg_match_all("/\<(.*?)\>/ism", $files, $result)) {
104 foreach ($result[1] as $file) {
105 $tagid = Tag::getID($file);
110 DBA::insert('post-category', [
113 'type' => self::CATEGORY,