]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/ping.php
Forgot to commit the JS for ModPlus. :)
[quix0rs-gnu-social.git] / lib / ping.php
index 48b4fa18f6fdc9fe8fba937ba70d889485464d86..abf1c4048edddb5a6c3f1bcbd783d75d9b4c9abe 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-if (!defined('STATUSNET')) { exit(1); }
+if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
 
 function ping_broadcast_notice($notice) {
 
-       if (!$notice->is_local) {
+       if ($notice->is_local != Notice::LOCAL_PUBLIC && $notice->is_local != Notice::LOCAL_NONPUBLIC) {
                return true;
        }
 
        # Array of servers, URL => type
        $notify = common_config('ping', 'notify');
-       $profile = $notice->getProfile();
+    try {
+        $profile = $notice->getProfile();
+    } catch (Exception $e) {
+        // @todo: distinguish the 'broken notice/profile' case from more general
+        //        transitory errors.
+        common_log(LOG_ERR, "Exception getting notice profile: " . $e->getMessage());
+        return true;
+    }
        $tags = ping_notice_tags($notice);
 
        foreach ($notify as $notify_url => $type) {
@@ -44,20 +51,24 @@ function ping_broadcast_notice($notice) {
                                                                                                                                array('nickname' => $profile->nickname)),
                                                                                           $tags));
 
-            $context = stream_context_create(array('http' => array('method' => "POST",
-                                                                   'header' =>
-                                                                   "Content-Type: text/xml\r\n".
-                                                                   "User-Agent: StatusNet/".STATUSNET_VERSION."\r\n",
-                                                                   'content' => $req)));
-            $file = file_get_contents($notify_url, false, $context);
+            $request = HTTPClient::start();
+            $request->setConfig('connect_timeout', common_config('ping', 'timeout'));
+            $request->setConfig('timeout', common_config('ping', 'timeout'));
+            try {
+                $httpResponse = $request->post($notify_url, array('Content-Type: text/xml'), $req);
+            } catch (Exception $e) {
+                common_log(LOG_ERR,
+                           "Exception pinging $notify_url: " . $e->getMessage());
+                continue;
+            }
 
-            if ($file === false || mb_strlen($file) == 0) {
+            if (!$httpResponse || mb_strlen($httpResponse->getBody()) == 0) {
                 common_log(LOG_WARNING,
                            "XML-RPC empty results for ping ($notify_url, $notice->id) ");
                 continue;
             }
 
-            $response = xmlrpc_decode($file);
+            $response = xmlrpc_decode($httpResponse->getBody());
 
             if (is_array($response) && xmlrpc_is_fault($response)) {
                 common_log(LOG_WARNING,
@@ -119,4 +130,4 @@ function ping_notice_tags($notice) {
                return implode('|', $tags);
        }
        return NULL;
-}
\ No newline at end of file
+}