public static function respondToPingRequest($remote, $local) { $remote = addslashes($remote); $local = addslashes($local); if (strpos(addslashes($local), preg_replace('|https?://|', '', BASE_URL)) === false) { return new IXR_Error(33, 'Target does not exist on this server.'); } if ($remote == $local) { return new IXR_Error(33, 'Remote and local must be distinct urls.'); } if (!self::getURL(addslashes($local))) { return new IXR_Error(33, 'Target does not exist on this server.'); } $ping = PicoraActiveRecord::find('PicoraPing', array('where' => array('local' => $local, 'remote' => $remote))); if ($ping) { return new IXR_Error(48, 'The pingback is already registered.'); } sleep(1); $remote_content = self::getURL($remote); if (!$remote_content) { return new IXR_Error(16, 'The source URL could not be found.'); } if (!in_array($local, self::scrape($remote_content))) { return new IXR_Error(17, 'The source URL does not contain a link to the target URI.'); } PicoraActiveRecord::create('PicoraPing', array('name' => preg_match('/<title>([^<]*?)<\\/title>/is', $remote_content, $m) ? $m[1] : $remote, 'local' => $local, 'remote' => $remote)); return "Ping recorded."; }
public function testHasOneRelationship() { $cure = PicoraActiveRecord::create('Artist', array('name' => 'The Cure', 'bio_id' => 0)); $this->assertEqual(0, $cure->bio_id); $cureBio = $cure->createBio(array('text' => 'The Bio')); $this->assertEqual(1, $cure->bio_id); $this->assertEqual($cureBio, $cure->getBio()); $cure->delete(); $this->assertFalse(PicoraActiveRecord::find('Bio', $cureBio->id)); $this->assertFalse($cureBio->reload()); }
protected static function challengeCookie($cookie) { $params = self::explodeCookie($cookie); if (isset($params['exp'], $params[self::PRIMARY_KEY], $params['digest'])) { $user = PicoraActiveRecord::find('PicoraUser', $params['id']); if (!$user) { return false; } if (self::bakeUserCookie($params['exp'], $params[self::PRIMARY_KEY], $user->name) == $cookie && $params['exp'] > time()) { return $user; } } return false; }