3 * Simply stores all pingbacks in the database.
5 require_once __DIR__ . '/../data/config.php';
7 function __autoload($className)
9 $className = ltrim($className, '\\');
12 if ($lastNsPos = strripos($className, '\\')) {
13 $namespace = substr($className, 0, $lastNsPos);
14 $className = substr($className, $lastNsPos + 1);
15 $fileName = str_replace('\\', '/', $namespace) . '/';
17 $fileName .= str_replace('_', '/', $className) . '.php';
22 $db = new PDO($dbdsn, $dbuser, $dbpass);
25 implements \PEAR2\Services\Pingback2\Server_Callback_IStorage,
26 \PEAR2\Services\Pingback2\Server_Callback_ILink
28 public function __construct(PDO $db)
33 public function storePingback(
34 $target, $source, $sourceBody, \HTTP_Request2_Response $res
36 $stmt = $this->db->prepare(
37 'INSERT INTO pingbacks'
38 . ' (p_source, p_target, p_time, p_client_ip, p_client_agent, p_client_referer)'
39 . ' VALUES(:source, :target, NOW(), :ip, :agent, :referer)'
45 ':ip' => isset($_SERVER['REMOTE_ADDR'])
46 ? $_SERVER['REMOTE_ADDR'] : '',
47 ':agent' => isset($_SERVER['HTTP_USER_AGENT'])
48 ? $_SERVER['HTTP_USER_AGENT'] : '',
49 ':referer' => isset($_SERVER['HTTP_REFERER'])
50 ? $_SERVER['HTTP_REFERER'] : '',
55 * Verifies that a link from $source to $target exists.
57 * @param string $target Target URI that should be linked in $source
58 * @param string $source Pingback source URI that should link to target
59 * @param string $sourceBody Content of $source URI
60 * @param object $res HTTP response from fetching $source
62 * @return boolean True if $source links to $target
64 * @throws Exception When something fatally fails
66 public function verifyLinkExists(
67 $target, $source, $sourceBody, \HTTP_Request2_Response $res
73 $s = new \PEAR2\Services\Pingback2\Server();
74 $s->addCallback(new PingbackStorage($db));