From 5134a662fac865b8cc35b408f9f976b11a141c2e Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Mon, 21 Oct 2013 20:20:05 +0200 Subject: [PATCH] adapt to services_linkback --- data/tables.sql | 78 +++++++++---------- src/stapibas/Content/Extractor.php | 48 ++++++------ src/stapibas/Content/Fetcher.php | 43 +++++----- src/stapibas/Feed/PingUrls.php | 2 +- .../{Pingback => Linkback}/DbStorage.php | 46 +++++------ .../{Pingback => Linkback}/Mailer.php | 10 +-- src/stapibas/Renderer/Html.php | 24 +++--- www/xmlrpc.php | 6 +- 8 files changed, 127 insertions(+), 130 deletions(-) rename src/stapibas/{Pingback => Linkback}/DbStorage.php (67%) rename src/stapibas/{Pingback => Linkback}/Mailer.php (64%) diff --git a/data/tables.sql b/data/tables.sql index 096199f..bf79745 100644 --- a/data/tables.sql +++ b/data/tables.sql @@ -8,7 +8,7 @@ CREATE TABLE `feedentries` ( `fe_needs_update` tinyint(1) NOT NULL, PRIMARY KEY (`fe_id`), UNIQUE KEY `fe_id` (`fe_id`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `feedentryurls` ( @@ -25,7 +25,7 @@ CREATE TABLE `feedentryurls` ( `feu_retry` tinyint(1) NOT NULL, PRIMARY KEY (`feu_id`), UNIQUE KEY `feu_id` (`feu_id`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `feeds` ( @@ -35,61 +35,61 @@ CREATE TABLE `feeds` ( `f_needs_update` tinyint(1) NOT NULL, PRIMARY KEY (`f_id`), UNIQUE KEY `f_id` (`f_id`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; +) ENGINE=InnoDB DEFAULT CHARSET=utf8; -CREATE TABLE `pingbackcontent` ( - `pc_id` int(11) NOT NULL AUTO_INCREMENT, - `pc_p_id` int(11) NOT NULL, - `pc_mime_type` varchar(32) NOT NULL, - `pc_fulltext` text NOT NULL, - `pc_detected_type` varchar(16) NOT NULL, - PRIMARY KEY (`pc_id`), - UNIQUE KEY `pc_id` (`pc_id`) +CREATE TABLE `linkbackcontent` ( + `lc_id` int(11) NOT NULL AUTO_INCREMENT, + `lc_l_id` int(11) NOT NULL, + `lc_mime_type` varchar(32) NOT NULL, + `lc_fulltext` text NOT NULL, + `lc_detected_type` varchar(16) NOT NULL, + PRIMARY KEY (`lc_id`), + UNIQUE KEY `lc_id` (`lc_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -CREATE TABLE `pingbacks` ( - `p_id` int(11) NOT NULL AUTO_INCREMENT, - `p_source` varchar(1024) CHARACTER SET latin1 NOT NULL, - `p_target` varchar(1024) CHARACTER SET latin1 NOT NULL, - `p_time` datetime NOT NULL, - `p_client_ip` varchar(40) CHARACTER SET latin1 NOT NULL, - `p_client_agent` varchar(128) CHARACTER SET latin1 NOT NULL, - `p_client_referer` varchar(1024) CHARACTER SET latin1 NOT NULL, - `p_needs_review` tinyint(1) NOT NULL, - `p_use` tinyint(1) NOT NULL, - `p_needs_update` tinyint(1) NOT NULL, - PRIMARY KEY (`p_id`), - UNIQUE KEY `p_id` (`p_id`) +CREATE TABLE `linkbacks` ( + `l_id` int(11) NOT NULL AUTO_INCREMENT, + `l_source` varchar(1024) CHARACTER SET utf8 NOT NULL, + `l_target` varchar(1024) CHARACTER SET utf8 NOT NULL, + `l_time` datetime NOT NULL, + `l_client_ip` varchar(40) CHARACTER SET utf8 NOT NULL, + `l_client_agent` varchar(128) CHARACTER SET utf8 NOT NULL, + `l_client_referer` varchar(1024) CHARACTER SET utf8 NOT NULL, + `l_needs_review` tinyint(1) NOT NULL, + `l_use` tinyint(1) NOT NULL, + `l_needs_update` tinyint(1) NOT NULL, + PRIMARY KEY (`l_id`), + UNIQUE KEY `l_id` (`l_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -CREATE TABLE `pingbacktargets` ( - `pt_id` int(11) NOT NULL AUTO_INCREMENT, - `pt_url` varchar(2048) NOT NULL, - PRIMARY KEY (`pt_id`), - UNIQUE KEY `pt_id` (`pt_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='List of pages that may receive pingbacks'; +CREATE TABLE `linkbacktargets` ( + `lt_id` int(11) NOT NULL AUTO_INCREMENT, + `lt_url` varchar(2048) NOT NULL, + PRIMARY KEY (`lt_id`), + UNIQUE KEY `lt_id` (`lt_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='List of pages that may receive linkbacks'; CREATE TABLE `rbookmarks` ( `rb_id` int(11) NOT NULL AUTO_INCREMENT, - `rb_p_id` int(11) NOT NULL, - `rb_pc_id` int(11) NOT NULL, + `rb_l_id` int(11) NOT NULL, + `rb_lc_id` int(11) NOT NULL, `rb_target` varchar(2048) NOT NULL, `rb_source` varchar(2048) NOT NULL, `rb_source_title` varchar(256) NOT NULL, `rb_count` int(11) NOT NULL, PRIMARY KEY (`rb_id`), UNIQUE KEY `rb_id` (`rb_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Bookmarks, extracted from pingbackcontent'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Bookmarks, extracted from linkbackcontent'; CREATE TABLE `rcomments` ( `rc_id` int(11) NOT NULL AUTO_INCREMENT, - `rc_p_id` int(11) NOT NULL, - `rc_pc_id` int(11) NOT NULL, + `rc_l_id` int(11) NOT NULL, + `rc_lc_id` int(11) NOT NULL, `rc_target` varchar(2048) NOT NULL, `rc_source` varchar(2048) NOT NULL, `rc_title` varchar(256) NOT NULL, @@ -100,13 +100,13 @@ CREATE TABLE `rcomments` ( `rc_content` text NOT NULL, PRIMARY KEY (`rc_id`), UNIQUE KEY `rb_id` (`rc_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Bookmarks, extracted from pingbackcontent'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Bookmarks, extracted from linkbackcontent'; CREATE TABLE `rlinks` ( `rl_id` int(11) NOT NULL AUTO_INCREMENT, - `rl_p_id` int(11) NOT NULL, - `rl_pc_id` int(11) NOT NULL, + `rl_l_id` int(11) NOT NULL, + `rl_lc_id` int(11) NOT NULL, `rl_target` varchar(2048) NOT NULL, `rl_source` varchar(2048) NOT NULL, `rl_title` varchar(256) NOT NULL, @@ -116,6 +116,6 @@ CREATE TABLE `rlinks` ( `rl_author_image` varchar(2048) NOT NULL, PRIMARY KEY (`rl_id`), UNIQUE KEY `rb_id` (`rl_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Bookmarks, extracted from pingbackcontent'; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Bookmarks, extracted from linkbackcontent'; diff --git a/src/stapibas/Content/Extractor.php b/src/stapibas/Content/Extractor.php index af035b9..50d7915 100644 --- a/src/stapibas/Content/Extractor.php +++ b/src/stapibas/Content/Extractor.php @@ -19,58 +19,58 @@ class Content_Extractor */ public function updateAll() { - $this->log->info('Extracting pingback content..'); + $this->log->info('Extracting linkback content..'); $res = $this->db->query( - 'SELECT * FROM pingbackcontent, pingbacks' - . ' WHERE p_id = pc_p_id' . $this->sqlNeedsUpdate() + 'SELECT * FROM linkbackcontent, linkbacks' + . ' WHERE l_id = lc_l_id' . $this->sqlNeedsUpdate() ); $items = 0; while ($contentRow = $res->fetch(\PDO::FETCH_OBJ)) { ++$items; $this->extractContent($contentRow); } - $this->log->info('Finished extracting %d pingback contents.', $items); + $this->log->info('Finished extracting %d linkback contents.', $items); } protected function extractContent($contentRow) { $doc = new \DOMDocument(); - $typeParts = explode(';', $contentRow->pc_mime_type); + $typeParts = explode(';', $contentRow->lc_mime_type); $type = $typeParts[0]; if ($type == 'application/xhtml+xml' || $type == 'application/xml' || $type == 'text/xml' ) { - $doc->loadXML($contentRow->pc_fulltext); + $doc->loadXML($contentRow->lc_fulltext); } else { - $doc->loadHTML($contentRow->pc_fulltext); + $doc->loadHTML($contentRow->lc_fulltext); } //delete old content $this->db->exec( 'DELETE FROM rbookmarks WHERE' - . ' rb_pc_id = ' . $this->db->quote($contentRow->pc_id) + . ' rb_lc_id = ' . $this->db->quote($contentRow->lc_id) ); $this->db->exec( 'DELETE FROM rcomments WHERE' - . ' rc_pc_id = ' . $this->db->quote($contentRow->pc_id) + . ' rc_lc_id = ' . $this->db->quote($contentRow->lc_id) ); $this->db->exec( 'DELETE FROM rlinks WHERE' - . ' rl_pc_id = ' . $this->db->quote($contentRow->pc_id) + . ' rl_lc_id = ' . $this->db->quote($contentRow->lc_id) ); $ce = new Content_Extractor_Comment($this->deps->log); - $data = $ce->extract($doc, $contentRow->p_source, $contentRow->p_target); + $data = $ce->extract($doc, $contentRow->l_source, $contentRow->l_target); if ($data !== null) { $this->log->info('Comment found'); var_dump($data); $this->db->exec( 'INSERT INTO rcomments SET' - . ' rc_p_id = ' . $this->db->quote($contentRow->p_id) - . ', rc_pc_id = ' . $this->db->quote($contentRow->pc_id) - . ', rc_source = ' . $this->db->quote($contentRow->p_source) - . ', rc_target = ' . $this->db->quote($contentRow->p_target) + . ' rc_l_id = ' . $this->db->quote($contentRow->l_id) + . ', rc_lc_id = ' . $this->db->quote($contentRow->lc_id) + . ', rc_source = ' . $this->db->quote($contentRow->l_source) + . ', rc_target = ' . $this->db->quote($contentRow->l_target) . ', rc_title = ' . $this->db->quote($data['title']) . ', rc_author_name = ' . $this->db->quote($data['author_name']) . ', rc_author_url = ' . $this->db->quote($data['author_url']) @@ -85,15 +85,15 @@ class Content_Extractor //FIXME: bookmark $ce = new Content_Extractor_Link($this->deps->log); - $data = $ce->extract($doc, $contentRow->p_source, $contentRow->p_target); + $data = $ce->extract($doc, $contentRow->l_source, $contentRow->l_target); if ($data !== null) { $this->log->info('Link found'); $this->db->exec( 'INSERT INTO rlinks SET' - . ' rl_p_id = ' . $this->db->quote($contentRow->p_id) - . ', rl_pc_id = ' . $this->db->quote($contentRow->pc_id) - . ', rl_source = ' . $this->db->quote($contentRow->p_source) - . ', rl_target = ' . $this->db->quote($contentRow->p_target) + . ' rl_l_id = ' . $this->db->quote($contentRow->l_id) + . ', rl_lc_id = ' . $this->db->quote($contentRow->lc_id) + . ', rl_source = ' . $this->db->quote($contentRow->l_source) + . ', rl_target = ' . $this->db->quote($contentRow->l_target) . ', rl_title = ' . $this->db->quote($data['title']) . ', rl_author_name = ' . $this->db->quote($data['author_name']) . ', rl_author_url = ' . $this->db->quote($data['author_url']) @@ -111,9 +111,9 @@ class Content_Extractor protected function setDetectedType($contentRow, $type) { $this->db->exec( - 'UPDATE pingbackcontent' - . ' SET pc_detected_type = ' . $this->db->quote($type) - . ' WHERE pc_id = ' . $this->db->quote($contentRow->pc_id) + 'UPDATE linkbackcontent' + . ' SET lc_detected_type = ' . $this->db->quote($type) + . ' WHERE lc_id = ' . $this->db->quote($contentRow->lc_id) ); } @@ -123,7 +123,7 @@ class Content_Extractor if ($this->deps->options['force']) { return ''; } - return ' AND pc_detected_type = ""'; + return ' AND lc_detected_type = ""'; } } diff --git a/src/stapibas/Content/Fetcher.php b/src/stapibas/Content/Fetcher.php index de912c1..e1706f0 100644 --- a/src/stapibas/Content/Fetcher.php +++ b/src/stapibas/Content/Fetcher.php @@ -14,39 +14,36 @@ class Content_Fetcher } /** - * Fetches HTML content of all pingbacks that are marked as "needs update" + * Fetches HTML content of all linkbacks that are marked as "needs update" */ public function updateAll() { - $this->log->info('Fetching pingback content..'); + $this->log->info('Fetching linkback content..'); $res = $this->db->query( - 'SELECT * FROM pingbacks' - . ' WHERE p_use = 1' . $this->sqlNeedsUpdate() + 'SELECT * FROM linkbacks' + . ' WHERE l_use = 1' . $this->sqlNeedsUpdate() ); $items = 0; while ($pingbackRow = $res->fetch(\PDO::FETCH_OBJ)) { ++$items; $this->updateContent($pingbackRow); } - $this->log->info('Finished fetching %d pingback sources.', $items); + $this->log->info('Finished fetching %d linkback sources.', $items); } protected function updateContent($pingbackRow) { $this->log->info( 'Fetching pingback source #%d: %s', - $pingbackRow->p_id, $pingbackRow->p_source + $pingbackRow->l_id, $pingbackRow->l_source ); - $req = new \HTTP_Request2($pingbackRow->p_source); + $req = new \HTTP_Request2($pingbackRow->l_source); $req->setHeader('User-Agent', 'stapibas'); $req->setHeader( 'Accept', 'application/xhtml+xml; q=1' - . ', application/xml; q=0.9' - . ', text/xml; q=0.9' . ', text/html; q=0.5' - . ', */*; q=0.1' ); $res = $req->send(); @@ -56,23 +53,23 @@ class Content_Fetcher return; } - $qPid = $this->db->quote($pingbackRow->p_id); - $this->db->exec('DELETE FROM pingbackcontent WHERE pc_p_id = ' . $qPid); - $this->db->exec('DELETE FROM rbookmarks WHERE rb_p_id = ' . $qPid); - $this->db->exec('DELETE FROM rcomments WHERE rc_p_id = ' . $qPid); - $this->db->exec('DELETE FROM rlinks WHERE rl_p_id = ' . $qPid); + $qLid = $this->db->quote($pingbackRow->l_id); + $this->db->exec('DELETE FROM linkbackcontent WHERE lc_l_id = ' . $qLid); + $this->db->exec('DELETE FROM rbookmarks WHERE rb_l_id = ' . $qLid); + $this->db->exec('DELETE FROM rcomments WHERE rc_l_id = ' . $qLid); + $this->db->exec('DELETE FROM rlinks WHERE rl_l_id = ' . $qLid); $this->db->exec( - 'INSERT INTO pingbackcontent SET' - . ' pc_p_id = ' . $qPid - . ', pc_mime_type = ' + 'INSERT INTO linkbackcontent SET' + . ' lc_l_id = ' . $qLid + . ', lc_mime_type = ' . $this->db->quote($res->getHeader('content-type')) - . ', pc_fulltext = ' . $this->db->quote($res->getBody()) + . ', lc_fulltext = ' . $this->db->quote($res->getBody()) ); $this->db->exec( - 'UPDATE pingbacks' - . ' SET p_needs_update = 0' - . ' WHERE p_id = ' . $this->db->quote($pingbackRow->p_id) + 'UPDATE linkbacks' + . ' SET l_needs_update = 0' + . ' WHERE l_id = ' . $this->db->quote($pingbackRow->l_id) ); } @@ -82,7 +79,7 @@ class Content_Fetcher if ($this->deps->options['force']) { return ''; } - return ' AND p_needs_update = 1'; + return ' AND l_needs_update = 1'; } } diff --git a/src/stapibas/Feed/PingUrls.php b/src/stapibas/Feed/PingUrls.php index 69045b5..0812f0f 100644 --- a/src/stapibas/Feed/PingUrls.php +++ b/src/stapibas/Feed/PingUrls.php @@ -16,7 +16,7 @@ class Feed_PingUrls $this->db = $deps->db; $this->log = $deps->log; - $this->pbc = new \PEAR2\Services\Pingback\Client(); + $this->pbc = new \PEAR2\Services\Linkback\Client(); $req = new \HTTP_Request2(); $req->setConfig( diff --git a/src/stapibas/Pingback/DbStorage.php b/src/stapibas/Linkback/DbStorage.php similarity index 67% rename from src/stapibas/Pingback/DbStorage.php rename to src/stapibas/Linkback/DbStorage.php index 4fa45a6..36b7c06 100644 --- a/src/stapibas/Pingback/DbStorage.php +++ b/src/stapibas/Linkback/DbStorage.php @@ -1,10 +1,10 @@ db->query( - 'SELECT COUNT(*) as count FROM pingbacktargets' - . ' WHERE ' . $this->db->quote($target) . ' LIKE pt_url' + 'SELECT COUNT(*) as count FROM linkbacktargets' + . ' WHERE ' . $this->db->quote($target) . ' LIKE lt_url' ); $answer = $res->fetch(\PDO::FETCH_OBJ); if ($answer->count == 0) { throw new \Exception( - 'The specified target URI cannot be used as a target.', + 'The specified target URI is not allowed as target.', 33 ); } @@ -37,27 +37,27 @@ class Pingback_DbStorage return true; } - public function storePingback( + public function storeLinkback( $target, $source, $sourceBody, \HTTP_Request2_Response $res ) { if ($this->alreadyExists($target, $source)) { throw new \Exception( - 'Pingback from ' . $source . ' to ' . $target + 'Linkback from ' . $source . ' to ' . $target . ' has already been registered.', 48 ); } $stmt = $this->db->prepare( - 'INSERT INTO pingbacks SET' - . ' p_source = :source' - . ', p_target = :target' - . ', p_time = NOW()' - . ', p_client_ip = :ip' - . ', p_client_agent = :agent' - . ', p_client_referer = :referer' - . ', p_needs_review = 1' - . ', p_use = 1' - . ', p_needs_update = 1' + 'INSERT INTO linkbacks SET' + . ' l_source = :source' + . ', l_target = :target' + . ', l_time = NOW()' + . ', l_client_ip = :ip' + . ', l_client_agent = :agent' + . ', l_client_referer = :referer' + . ', l_needs_review = 1' + . ', l_use = 1' + . ', l_needs_update = 1' ); $stmt->execute( array( @@ -76,9 +76,9 @@ class Pingback_DbStorage protected function alreadyExists($target, $source) { $res = $this->db->query( - 'SELECT COUNT(*) as count FROM pingbacks' - . ' WHERE p_source = ' . $this->db->quote($source) - . ' AND p_target = ' . $this->db->quote($target) + 'SELECT COUNT(*) as count FROM linkbacks' + . ' WHERE l_source = ' . $this->db->quote($source) + . ' AND l_target = ' . $this->db->quote($target) ); $answer = $res->fetch(\PDO::FETCH_OBJ); return $answer->count > 0; @@ -88,7 +88,7 @@ class Pingback_DbStorage * Verifies that a link from $source to $target exists. * * @param string $target Target URI that should be linked in $source - * @param string $source Pingback source URI that should link to target + * @param string $source Linkback source URI that should link to target * @param string $sourceBody Content of $source URI * @param object $res HTTP response from fetching $source * diff --git a/src/stapibas/Pingback/Mailer.php b/src/stapibas/Linkback/Mailer.php similarity index 64% rename from src/stapibas/Pingback/Mailer.php rename to src/stapibas/Linkback/Mailer.php index 3b9e3ff..9a628f0 100644 --- a/src/stapibas/Pingback/Mailer.php +++ b/src/stapibas/Linkback/Mailer.php @@ -1,16 +1,16 @@ ' . $target . "\n" . "from\n" . '> ' . $source . "\n" diff --git a/src/stapibas/Renderer/Html.php b/src/stapibas/Renderer/Html.php index ca26584..620cad0 100644 --- a/src/stapibas/Renderer/Html.php +++ b/src/stapibas/Renderer/Html.php @@ -42,26 +42,26 @@ class Renderer_Html ); $stmt = $this->db->query( - 'SELECT * FROM pingbacks, rbookmarks' - . ' WHERE p_id = rb_p_id AND p_use = 1' - . ' AND p_target = ' . $this->db->quote($url) - . ' ORDER BY p_time ASC' + 'SELECT * FROM linkbacks, rbookmarks' + . ' WHERE l_id = rb_l_id AND l_use = 1' + . ' AND l_target = ' . $this->db->quote($url) + . ' ORDER BY l_time ASC' ); $arData['bookmarks'] = $stmt->fetchAll(); $stmt = $this->db->query( - 'SELECT * FROM pingbacks, rcomments' - . ' WHERE p_id = rc_p_id AND p_use = 1' - . ' AND p_target = ' . $this->db->quote($url) - . ' ORDER BY p_time ASC' + 'SELECT * FROM linkbacks, rcomments' + . ' WHERE l_id = rc_l_id AND l_use = 1' + . ' AND l_target = ' . $this->db->quote($url) + . ' ORDER BY l_time ASC' ); $arData['comments'] = $stmt->fetchAll(); $stmt = $this->db->query( - 'SELECT * FROM pingbacks, rlinks' - . ' WHERE p_id = rl_p_id AND p_use = 1' - . ' AND p_target = ' . $this->db->quote($url) - . ' ORDER BY p_time ASC' + 'SELECT * FROM linkbacks, rlinks' + . ' WHERE l_id = rl_l_id AND l_use = 1' + . ' AND l_target = ' . $this->db->quote($url) + . ' ORDER BY l_time ASC' ); $arData['links'] = $stmt->fetchAll(); diff --git a/www/xmlrpc.php b/www/xmlrpc.php index 2a2c674..e5c2755 100644 --- a/www/xmlrpc.php +++ b/www/xmlrpc.php @@ -12,8 +12,8 @@ require_once 'stapibas/autoloader.php'; $db = new PDO($dbdsn, $dbuser, $dbpass); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); -$s = new \PEAR2\Services\Pingback\Server(); -$s->addCallback(new Pingback_DbStorage($db)); -$s->addCallback(new Pingback_Mailer()); +$s = new \PEAR2\Services\Linkback\Server(); +$s->addCallback(new Linkback_DbStorage($db)); +$s->addCallback(new Linkback_Mailer()); $s->run(); ?> -- 2.30.2