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 testValidations() { $invalid = PicoraActiveRecord::create('Album', array('name' => '')); $this->assertFalse($invalid->isValid()); $list = $invalid->getErrorList(); $this->assertEqual(1, count($list)); }