2 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 $r = 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));
27 if (preg_match_all("/\<(.*?)\>/ism", $message["file"], $files))
28 foreach ($files[1] as $file)
29 $r = q("INSERT INTO `term` (`uid`, `oid`, `otype`, `type`, `term`) VALUES (%d, %d, %d, %d, '%s')",
30 intval($message["uid"]), intval($itemid), intval(TERM_OBJ_POST), intval(TERM_CATEGORY), dbesc($file));
33 function create_files_from_itemuri($itemuri, $uid) {
34 $messages = q("SELECT `id` FROM `item` WHERE uri ='%s' AND uid=%d", dbesc($itemuri), intval($uid));
36 if(count($messages)) {
37 foreach ($messages as $message)
38 create_files_from_item($message["id"]);
42 function update_files_for_items() {
43 $messages = q("SELECT `id` FROM `item` where file !=''");
45 foreach ($messages as $message) {
46 echo $message["id"]."\n";
47 create_files_from_item($message["id"]);