4 class Pingback_ContentFetcher
9 public function __construct(Dependencies $deps)
12 $this->db = $deps->db;
13 $this->log = $deps->log;
17 * Fetches HTML content of all pingbacks that are marked as "needs update"
19 public function updateAll()
21 $this->log->info('Fetching pingback content..');
22 $res = $this->db->query(
23 'SELECT * FROM pingbacks'
24 . ' WHERE p_use = 1' . $this->sqlNeedsUpdate()
27 while ($pingbackRow = $res->fetch(\PDO::FETCH_OBJ)) {
29 $this->updateContent($pingbackRow);
31 $this->log->info('Finished fetching %d pingback sources.', $items);
34 protected function updateContent($pingbackRow)
37 'Fetching pingback source #%d: %s',
38 $pingbackRow->p_id, $pingbackRow->p_source
41 $req = new \HTTP_Request2($pingbackRow->p_source);
42 $req->setHeader('User-Agent', 'stapibas');
45 'application/xhtml+xml; q=1'
46 . ', application/xml; q=0.9'
48 . ', text/html; q=0.5'
53 if (intval($res->getStatus() / 100) != 2) {
54 //no 2xx is an error for us
55 $this->log->err('Error fetching pingback source content');
60 'DELETE FROM pingbackcontent WHERE'
61 . ' pc_p_id = ' . $this->db->quote($pingbackRow->p_id)
64 'INSERT INTO pingbackcontent SET'
65 . ' pc_p_id = ' . $this->db->quote($pingbackRow->p_id)
67 . $this->db->quote($res->getHeader('content-type'))
68 . ', pc_fulltext = ' . $this->db->quote($res->getBody())
72 . ' SET p_needs_update = 0'
73 . ' WHERE p_id = ' . $this->db->quote($pingbackRow->p_id)
78 protected function sqlNeedsUpdate()
80 if ($this->deps->options['force']) {
83 return ' AND p_needs_update = 1';