--- /dev/null
+CREATE TABLE IF NOT EXISTS `pingbacks` (
+ `p_id` int(11) NOT NULL AUTO_INCREMENT,
+ `p_source` varchar(1024) NOT NULL,
+ `p_target` varchar(1024) NOT NULL,
+ `p_time` datetime NOT NULL,
+ `p_client_ip` varchar(40) NOT NULL,
+ `p_client_agent` varchar(128) NOT NULL,
+ `p_client_referer` varchar(1024) NOT NULL,
+ PRIMARY KEY (`p_id`),
+ UNIQUE KEY `p_id` (`p_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--- /dev/null
+<?php
+/**
+ * Simply stores all pingbacks in the database.
+ */
+require_once __DIR__ . '/../data/config.php';
+
+function __autoload($className)
+{
+ $className = ltrim($className, '\\');
+ $fileName = '';
+ $namespace = '';
+ if ($lastNsPos = strripos($className, '\\')) {
+ $namespace = substr($className, 0, $lastNsPos);
+ $className = substr($className, $lastNsPos + 1);
+ $fileName = str_replace('\\', '/', $namespace) . '/';
+ }
+ $fileName .= str_replace('_', '/', $className) . '.php';
+
+ require $fileName;
+}
+
+$db = new PDO($dbdsn, $dbuser, $dbpass);
+
+class PingbackStorage
+ implements \PEAR2\Services\Pingback2\Server_Callback_IStorage,
+ \PEAR2\Services\Pingback2\Server_Callback_ILink
+{
+ public function __construct(PDO $db)
+ {
+ $this->db = $db;
+ }
+
+ public function storePingback(
+ $target, $source, $sourceBody, \HTTP_Request2_Response $res
+ ) {
+ $stmt = $this->db->prepare(
+ 'INSERT INTO pingbacks'
+ . ' (p_source, p_target, p_time, p_client_ip, p_client_agent, p_client_referer)'
+ . ' VALUES(:source, :target, NOW(), :ip, :agent, :referer)'
+ );
+ $stmt->execute(
+ array(
+ ':source' => $source,
+ ':target' => $target,
+ ':ip' => isset($_SERVER['REMOTE_ADDR'])
+ ? $_SERVER['REMOTE_ADDR'] : '',
+ ':agent' => isset($_SERVER['HTTP_USER_AGENT'])
+ ? $_SERVER['HTTP_USER_AGENT'] : '',
+ ':referer' => isset($_SERVER['HTTP_REFERER'])
+ ? $_SERVER['HTTP_REFERER'] : '',
+ )
+ );
+ }
+ /**
+ * 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 $sourceBody Content of $source URI
+ * @param object $res HTTP response from fetching $source
+ *
+ * @return boolean True if $source links to $target
+ *
+ * @throws Exception When something fatally fails
+ */
+ public function verifyLinkExists(
+ $target, $source, $sourceBody, \HTTP_Request2_Response $res
+ ) {
+ return false;
+ }
+}
+
+$s = new \PEAR2\Services\Pingback2\Server();
+$s->addCallback(new PingbackStorage($db));
+$s->run();
+?>