]> git.mxchange.org Git - friendica.git/blob - include/queue.php
ability to hide profile and wall from unknown people
[friendica.git] / include / queue.php
1 <?php
2 require_once("boot.php");
3
4 function update_queue_time($id) {
5         logger('queue: requeue item ' . $id);
6         q("UPDATE `queue` SET `last` = '%s' WHERE `id` = %d LIMIT 1",
7                 dbesc(datetime_convert()),
8                 intval($id)
9         );
10 }
11
12 function remove_queue_item($id) {
13         logger('queue: remove queue item ' . $id);
14         q("DELETE FROM `queue` WHERE `id` = %d LIMIT 1",
15                 intval($id)
16         );
17 }
18
19 function queue_run($argv, $argc){
20   global $a, $db;
21
22   if(is_null($a)){
23     $a = new App;
24   }
25   
26   if(is_null($db)){
27     @include(".htconfig.php");
28     require_once("dba.php");
29     $db = new dba($db_host, $db_user, $db_pass, $db_data);
30     unset($db_host, $db_user, $db_pass, $db_data);
31   };
32
33
34         require_once("session.php");
35         require_once("datetime.php");
36         require_once('include/items.php');
37         require_once('include/bbcode.php');
38
39         $a->set_baseurl(get_config('system','url'));
40
41         $deadguys = array();
42
43         logger('queue: start');
44
45         $r = q("SELECT `queue`.*, `contact`.`name`, `contact`.`uid` FROM `queue` 
46                 LEFT JOIN `contact` ON `queue`.`cid` = `contact`.`id` 
47                 WHERE `queue`.`created` < UTC_TIMESTAMP() - INTERVAL 3 DAY");
48         if(count($r)) {
49                 foreach($r as $rr) {
50                         logger('Removing expired queue item for ' . $rr['name'] . ', uid=' . $rr['uid']);
51                         logger('Expired queue data :' . $rr['content'], LOGGER_DATA);
52                 }
53                 q("DELETE FROM `queue` WHERE `created` < UTC_TIMESTAMP() - INTERVAL 3 DAY");
54         }
55                 
56         $r = q("SELECT `id` FROM `queue` WHERE `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE ");
57
58         if(! count($r)){
59                 return;
60         }
61         // delivery loop
62
63         require_once('include/salmon.php');
64
65         foreach($r as $q_item) {
66                 $qi = q("SELECT * FROM `queue` WHERE `id` = %d LIMIT 1",
67                         intval($q_item['id'])
68                 );
69                 if(! count($qi))
70                         continue;
71
72                 $c = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
73                         intval($qi[0]['cid'])
74                 );
75                 if(! count($c)) {
76                         remove_queue_item($q_item['id']);
77                         continue;
78                 }
79                 if(in_array($c[0]['notify'],$deadguys)) {
80                                 logger('queue: skipping known dead url: ' . $c[0]['notify']);
81                                 update_queue_time($q_item['id']);
82                                 continue;
83                 }
84
85                 $u = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
86                         intval($c[0]['uid'])
87                 );
88                 if(! count($u)) {
89                         remove_queue_item($q_item['id']);
90                         continue;
91                 }
92
93                 $data      = $qi[0]['content'];
94                 $contact   = $c[0];
95                 $owner     = $u[0];
96
97                 $deliver_status = 0;
98
99                 switch($contact['network']) {
100                         case 'dfrn':
101                                 logger('queue: dfrndelivery: item ' . $q_item['id'] . ' for ' . $contact['name']);
102                                 $deliver_status = dfrn_deliver($owner,$contact,$data);
103
104                                 if($deliver_status == (-1)) {
105                                         update_queue_time($q_item['id']);
106                                         $deadguys[] = $contact['notify'];
107                                 }
108                                 else {
109                                         remove_queue_item($q_item['id']);
110                                 }
111                                 break;
112                         default:
113                                 if($contact['notify']) {
114                                         logger('queue: slapdelivery: item ' . $q_item['id'] . ' for ' . $contact['name']);
115                                         $deliver_status = slapper($owner,$contact['notify'],$data);
116
117                                         if($deliver_status == (-1))
118                                                 update_queue_time($q_item['id']);
119                                         else
120                                                 remove_queue_item($q_item['id']);
121                                 }
122                                 break;
123                 }
124         }
125                 
126         return;
127
128 }
129
130 if (array_search(__file__,get_included_files())===0){
131   queue_run($argv,$argc);
132   killme();
133 }