3 function create_files_from_item($itemid)
5 $messages = q("SELECT `guid`, `uid`, `id`, `edited`, `deleted`, `file`, `parent` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid));
10 $message = $messages[0];
13 q("DELETE FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d)",
14 intval(TERM_OBJ_POST),
17 intval(TERM_CATEGORY));
19 if ($message["deleted"])
22 if (preg_match_all("/\[(.*?)\]/ism", $message["file"], $files)) {
23 foreach ($files[1] as $file) {
24 q("INSERT INTO `term` (`uid`, `oid`, `otype`, `type`, `term`) VALUES (%d, %d, %d, %d, '%s')",
25 intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval(TERM_FILE), dbesc($file));
29 if (preg_match_all("/\<(.*?)\>/ism", $message["file"], $files)) {
30 foreach ($files[1] as $file) {
31 q("INSERT INTO `term` (`uid`, `oid`, `otype`, `type`, `term`) VALUES (%d, %d, %d, %d, '%s')",
32 intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval(TERM_CATEGORY), dbesc($file));
37 function create_files_from_itemuri($itemuri, $uid)
39 $messages = q("SELECT `id` FROM `item` WHERE uri ='%s' AND uid=%d", dbesc($itemuri), intval($uid));
41 if (count($messages)) {
42 foreach ($messages as $message)
43 create_files_from_item($message["id"]);
47 function update_files_for_items()
49 $messages = q("SELECT `id` FROM `item` where file !=''");
51 foreach ($messages as $message) {
52 echo $message["id"] . "\n";
53 create_files_from_item($message["id"]);