]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/ping.php
Merge branch '0.7.x' of git@gitorious.org:laconica/dev into 0.7.x
[quix0rs-gnu-social.git] / lib / ping.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 function ping_broadcast_notice($notice) {
23         if (!$notice->is_local) {
24                 return;
25         }
26         
27         # Array of servers, URL => type
28         $notify = common_config('ping', 'notify');
29         $profile = $notice->getProfile();
30         $tags = ping_notice_tags($notice);
31         
32         foreach ($notify as $notify_url => $type) {
33                 switch ($type) {
34                  case 'xmlrpc':
35                  case 'extended':
36                         $req = xmlrpc_encode_request('weblogUpdates.ping',
37                                                                                  array($profile->nickname, # site name
38                                                                                            common_local_url('showstream', 
39                                                                                                                                 array('nickname' => $profile->nickname)),
40                                                                                            common_local_url('shownotice',
41                                                                                                                                 array('notice' => $notice->id)),
42                                                                                            common_local_url('userrss', 
43                                                                                                                                 array('nickname' => $profile->nickname)),
44                                                                                            $tags));
45                         
46                         # We re-use this tool's fetcher, since it's pretty good
47         
48                         $fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
49
50                         if (!$fetcher) {
51                                 common_log(LOG_WARNING, 'Failed to initialize Yadis fetcher.', __FILE__);
52                                 return false;
53                         }
54         
55                         $result = $fetcher->post($notify_url,
56                                                                          $req);
57                                                                                            
58                  case 'get':
59                  case 'post':                   
60                  default:
61                         common_log(LOG_WARNING, 'Unknown notify type for ' . $notify_url . ': ' . $type);
62                                                                                    }
63         }
64 }
65                 
66 function ping_notice_tags($notice) {
67         $tag = new Notice_tag();
68         $tag->notice_id = $notice->id;
69         $tags = array();
70         if ($tag->find()) {
71                 while ($tag->fetch()) {
72                         $tags[] = $tag->tag;
73                 }
74                 $tag->free();
75                 unset($tag);
76                 return implode('|', $tags);
77         }
78         return NULL;
79 }