use new linkback request template api
[stapibas.git] / src / stapibas / Feed / PingUrls.php
index 1e98f0a4ea53bf9167cd5cc1e361f1c758b821db..926dd8ce4a1735c356670a45b69dbd5127d72702 100644 (file)
@@ -16,16 +16,18 @@ class Feed_PingUrls
         $this->db   = $deps->db;
         $this->log  = $deps->log;
 
-        $this->pbc = new \PEAR2\Services\Pingback\Client();
-
-        $req = new \HTTP_Request2();
+        $this->pbc = new \PEAR2\Services\Linkback\Client();
+        $req = $this->pbc->getRequest();
         $req->setConfig(
             array(
                 'ssl_verify_peer' => false,
                 'ssl_verify_host' => false
             )
         );
-        $this->pbc->setRequest($req);
+        $this->pbc->setRequestTemplate($req);
+        $headers = $req->getHeaders();
+        $req->setHeader('user-agent', 'stapibas / ' . $headers['user-agent']);
+
         $this->pbc->setDebug(true);
     }
 
@@ -61,7 +63,8 @@ class Feed_PingUrls
 
         $this->log->info('Pinging %d URLs..', count($options));
         $res = $this->db->query(
-            'SELECT fe_url, feu_id, feu_url FROM feedentries, feedentryurls'
+            'SELECT fe_url, feu_id, feu_url, feu_tries'
+            . ' FROM feedentries, feedentryurls'
             . ' WHERE fe_id = feu_fe_id'
             . $this->sqlNeedsUpdate()
             . ' AND (' . implode(' OR ', $options) . ')'
@@ -116,14 +119,17 @@ class Feed_PingUrls
             );
         } else {
             //error
-            $this->log->err('Error: ' . $res->getCode() . ': ' . $res->getMessage());
+            $code = $res->getCode();
+            $this->log->err('Error: ' . $code . ': ' . $res->getMessage());
             $httpRes = $res->getResponse();
             if ($httpRes) {
                 $this->log->info(
                     'Pingback response: Status code ' . $httpRes->getStatus()
                     . ', headers: ' . print_r($httpRes->getHeader(), true)
                 );
-                //. ', body: ' .$httpRes->getBody()
+                if ($code == 100 || $code == 101 || $code == -32600) {
+                    $this->log->info('HTTP body: ' . $httpRes->getBody());
+                }
             }
             $this->db->exec(
                 'UPDATE feedentryurls SET'