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'] : '',
56 * Verifies that a link from $source to $target exists.
58 * @param string $target Target URI that should be linked in $source
59 * @param string $source Pingback source URI that should link to target
60 * @param string $sourceBody Content of $source URI
61 * @param object $res HTTP response from fetching $source
63 * @return boolean True if $source links to $target
65 * @throws Exception When something fatally fails
67 public function verifyLinkExists(
68 $target, $source, $sourceBody, \HTTP_Request2_Response $res
75 implements \PEAR2\Services\Pingback2\Server_Callback_IStorage
77 public function storePingback(
78 $target, $source, $sourceBody, \HTTP_Request2_Response $res
83 "A pingback just came in, for\n"
84 . '> ' . $target . "\n"
86 . '> ' . $source . "\n"
87 . "\n\nLove, stapibas",
88 "From: stapibas <server@cweiske.de>"
93 $s = new \PEAR2\Services\Pingback2\Server();
94 $s->addCallback(new PingbackStorage($db));
95 $s->addCallback(new PingbackMailer());