4 class Pingback_DbStorage
5 implements \PEAR2\Services\Pingback\Server\Callback\IStorage,
6 \PEAR2\Services\Pingback\Server\Callback\ILink,
7 \PEAR2\Services\Pingback\Server\Callback\ITarget
9 public function __construct(PDO $db)
15 * Verifies that the given target URI exists in our system.
17 * @param string $target Target URI that got linked to
19 * @return boolean True if the target URI exists, false if not
21 * @throws Exception When something fatally fails
23 public function verifyTargetExists($target)
25 $res = $this->db->query(
26 'SELECT COUNT(*) as count FROM pingbacktargets'
27 . ' WHERE ' . $this->db->quote($target) . ' LIKE pt_url'
29 $answer = $res->fetch(\PDO::FETCH_OBJ);
30 if ($answer->count == 0) {
32 'The specified target URI cannot be used as a target.',
40 public function storePingback(
41 $target, $source, $sourceBody, \HTTP_Request2_Response $res
43 if ($this->alreadyExists($target, $source)) {
45 'Pingback from ' . $source . ' to ' . $target
46 . ' has already been registered.',
50 $stmt = $this->db->prepare(
51 'INSERT INTO pingbacks SET'
52 . ' p_source = :source'
53 . ', p_target = :target'
55 . ', p_client_ip = :ip'
56 . ', p_client_agent = :agent'
57 . ', p_client_referer = :referer'
58 . ', p_needs_review = 1'
60 . ', p_needs_update = 1'
66 ':ip' => isset($_SERVER['REMOTE_ADDR'])
67 ? $_SERVER['REMOTE_ADDR'] : '',
68 ':agent' => isset($_SERVER['HTTP_USER_AGENT'])
69 ? $_SERVER['HTTP_USER_AGENT'] : '',
70 ':referer' => isset($_SERVER['HTTP_REFERER'])
71 ? $_SERVER['HTTP_REFERER'] : '',
76 protected function alreadyExists($target, $source)
78 $res = $this->db->query(
79 'SELECT COUNT(*) as count FROM pingbacks'
80 . ' WHERE p_source = ' . $this->db->quote($source)
81 . ' AND p_target = ' . $this->db->quote($target)
83 $answer = $res->fetch(\PDO::FETCH_OBJ);
84 return $answer->count > 0;
88 * Verifies that a link from $source to $target exists.
90 * @param string $target Target URI that should be linked in $source
91 * @param string $source Pingback source URI that should link to target
92 * @param string $sourceBody Content of $source URI
93 * @param object $res HTTP response from fetching $source
95 * @return boolean True if $source links to $target
97 * @throws Exception When something fatally fails
99 public function verifyLinkExists(
100 $target, $source, $sourceBody, \HTTP_Request2_Response $res