5 namespace Friendica\Model;
12 * @param integer $itemid item id
15 public static function createFromItem($itemid)
17 $messages = dba::selectFirst('item', ['guid', 'uid', 'id', 'edited', 'deleted', 'file', 'parent'], ['id' => $itemid]);
22 $message = $messages[0];
25 q("DELETE FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d)",
26 intval(TERM_OBJ_POST),
29 intval(TERM_CATEGORY));
31 if ($message["deleted"])
34 if (preg_match_all("/\[(.*?)\]/ism", $message["file"], $files)) {
35 foreach ($files[1] as $file) {
36 dba::insert('term', ['uid' => $message["uid"], 'oid' => $itemid, 'otype' => TERM_OBJ_POST, 'type' => TERM_FILE, 'term' => $file]);
40 if (preg_match_all("/\<(.*?)\>/ism", $message["file"], $files)) {
41 foreach ($files[1] as $file) {
42 dba::insert('term', ['uid' => $message["uid"], 'oid' => $itemid, 'otype' => TERM_OBJ_POST, 'type' => TERM_CATEGORY, 'term' => $file]);
48 * @param string $itemuri item uri
49 * @param integer $uid uid
52 public static function createFromItemURI($itemuri, $uid)
54 $messages = q("SELECT `id` FROM `item` WHERE uri ='%s' AND uid=%d", dbesc($itemuri), intval($uid));
56 if (count($messages)) {
57 foreach ($messages as $message)
58 self::createFromItem($message["id"]);
65 private function update_files_for_items()
67 $messages = q("SELECT `id` FROM `item` where file !=''");
69 foreach ($messages as $message) {
70 echo $message["id"] . "\n";
71 self::createFromItem($message["id"]);