]> git.mxchange.org Git - friendica.git/blob - include/files.php
Adding functions for the file- and category handling
[friendica.git] / include / files.php
1 <?php
2 function create_files_from_item($itemid) {
3         global $a;
4
5         $messages = q("SELECT `guid`, `uid`, `id`, `edited`, `deleted`, `file`, `parent` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid));
6
7         if (!$messages)
8                 return;
9
10         $message = $messages[0];
11
12         // Clean up all tags
13         q("DELETE FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d)",
14                 intval(TERM_OBJ_POST),
15                 intval($itemid),
16                 intval(TERM_FILE),
17                 intval(TERM_CATEGORY));
18
19         if ($message["deleted"])
20                 return;
21
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));
26
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));
31 }
32
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));
35
36         if(count($messages)) {
37                 foreach ($messages as $message)
38                         create_files_from_item($message["id"]);
39         }
40 }
41
42 function update_files_for_items() {
43         $messages = q("SELECT `id` FROM `item` where file !=''");
44
45         foreach ($messages as $message) {
46                 echo $message["id"]."\n";
47                 create_files_from_item($message["id"]);
48         }
49 }
50 ?>