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."; }
/** * Example connection strings: * * <pre class="highlighted"><code class="php">PicoraActiveRecord::connect('sqlite://relative_path_to_sqlite_database'); * PicoraActiveRecord::connect('mysql://*****:*****@host/database_name');</code></pre> * * @param string $connection_string * @return bool */ public static final function connect($connection_string, $username = false, $password = false, $driver_options = false) { if (preg_match('|sqlite\\://(.+)|', $connection_string)) { self::$__connection_type__ = 'sqlite'; if (!preg_match('|sqlite\\://(.+)|', $connection_string, $match)) { throw new Exception('SQLite connection string should be in the following format: sqlite://path/to/file.db'); } $file = $match[1]; $error = ''; if (!is_writable($file) || !is_readable($file)) { throw new Exception($file . " must be writable."); } if (!is_writable(dirname($file)) || !is_readable(dirname($file))) { throw new Exception(dirname($file) . "/ must be writable."); } self::$__connection__ = new SQLiteDatabase($file, 0666, $error); if (!self::$__connection__) { throw new Exception($error); } self::$__connection__->busyTimeout(30000); self::$__connection__->query('PRAGMA short_column_names = 1;'); return true; } elseif (preg_match('|mysql\\://(.+)|', $connection_string)) { self::$__connection_type__ = 'mysql'; if (!preg_match('|mysql\\://([^:]+):?([^@]*)@([^/]+)/(.+)|', $connection_string, $match)) { throw new Exception('MySql connection string should be in the following format: mysql://username:password@host/database_name'); } self::$__connection__ = mysql_connect($match[3], $match[1], $match[2], true); if (!self::$__connection__) { throw new Exception('Could not connect to MySQL. Tried to connect to MySQL at ' . $match[3] . '. MySQL issued this error: "' . mysql_error() . '"'); } if (!mysql_select_db($match[4], self::$__connection__)) { throw new Exception('Could not Select Database. Tried to select the database ' . $match[4] . '. MySQL issued this error: "' . mysql_error() . '"'); } @mysql_query("SET NAMES 'utf8';", self::$__connection__); return true; } else { self::$__connection_type__ = 'pdo'; self::$__connection__ = new PDO($connection_string, $username, $password, $driver_options); return true; } }
* The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. * * @author Ryan Johnson <*****@*****.**> * @copyright 2007 LivePipe LLC * @license MIT */ $path = dirname(__FILE__); require_once $path . '/classes/PicoraSupport.php'; require_once $path . '/classes/PicoraEvent.php'; require_once $path . '/classes/PicoraAutoLoader.php'; require_once $path . '/classes/PicoraDispatcher.php'; require_once $path . '/classes/PicoraController.php'; require_once $path . '/classes/PicoraView.php'; require_once $path . '/config.php'; require_once $path . '/functions.php'; PicoraAutoLoader::addFolder($path . '/classes/'); PicoraAutoLoader::addFolder($path . '/controllers/'); PicoraAutoLoader::addFolder($path . '/models/'); if (defined('CONNECTION_STRING')) { PicoraActiveRecord::connect(CONNECTION_STRING); } print PicoraDispatcher::dispatch($path, BASE_URL, isset($_GET['__route__']) ? '/' . $_GET['__route__'] : '/');
public function teardown() { $this->assertTrue(PicoraActiveRecord::executeQuery('DROP TABLE albums')); }
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; }