/** * Set the base URL. This is the URL used when converting relative urls to absolute paths. * * @param string|array $baseUrl */ public static function setDefaultBaseUrl($baseUrl) { self::$defaultBaseUrl = is_array($baseUrl) ? $baseUrl : self::parse($baseUrl); // Add default components self::$defaultBaseUrl += array('scheme' => '', 'user' => '', 'pass' => '', 'host' => '', 'port' => '', 'path' => ''); }
protected function getRequestUri() { // separate path and query-string $requestUri = explode('?', rawurldecode(Curry_URL::getRequestUri()), 2); // remove matching base path $baseUrl = Curry_URL::getDefaultBaseUrl(); $basePath = $baseUrl['path']; if ($basePath === $requestUri[0]) { $requestUri[0] = '/'; } else { if (Curry_String::startsWith($requestUri[0], $basePath)) { $requestUri[0] = substr($requestUri[0], strlen($basePath)); } } return join('?', $requestUri); }
public function testNoScheme() { $url = new \Curry_URL(str_replace('http:', '', self::TEST_URL)); $this->assertEquals('', $url->getScheme()); }
/** * Send error notification email. * * @param Exception $e */ public static function sendErrorNotification(Exception $e) { try { // Create form to recreate error $method = strtoupper($_SERVER['REQUEST_METHOD']); $hidden = Curry_Html::createHiddenFields($method == 'POST' ? $_POST : $_GET); $action = url(Curry_URL::getRequestUri())->getAbsolute(); $form = '<form action="' . $action . '" method="' . $method . '">' . $hidden . '<button type="submit">Execute</button></form>'; // Create mail $mail = new Curry_Mail(); $mail->addTo(Curry_Core::$config->curry->adminEmail); $mail->setSubject('Error on ' . Curry_Core::$config->curry->name); $mail->setBodyHtml('<html><body>' . '<h1>' . get_class($e) . '</h1>' . '<h2>' . htmlspecialchars($e->getMessage()) . '</h2>' . '<p><strong>Method:</strong> ' . $method . '<br/>' . '<strong>URL:</strong> ' . $action . '<br/>' . '<strong>File:</strong> ' . htmlspecialchars($e->getFile()) . '(' . $e->getLine() . ')</p>' . '<h2>Recreate</h2>' . $form . '<h2>Trace</h2>' . '<pre>' . htmlspecialchars($e->getTraceAsString()) . '</pre>' . '<h2>Variables</h2>' . '<h3>$_GET</h3>' . '<pre>' . htmlspecialchars(print_r($_GET, true)) . '</pre>' . '<h3>$_POST</h3>' . '<pre>' . htmlspecialchars(print_r($_POST, true)) . '</pre>' . '<h3>$_SERVER</h3>' . '<pre>' . htmlspecialchars(print_r($_SERVER, true)) . '</pre>' . '</body></html>'); $mail->send(); trace_notice('Sent error notification'); } catch (Exception $e) { trace_warning('Failed to send error notification'); } }
protected function getConfigureForm() { $contentTemplates = array('empty' => 'Empty page'); if (file_exists('db.txt')) { $contentTemplates = array('backup' => '[ Restore from backup ]') + $contentTemplates; } $scriptPath = Curry_URL::getScriptPath(); if (($pos = strrpos($scriptPath, '/')) !== false) { $scriptPath = substr($scriptPath, 0, $pos + 1); } else { $scriptPath = ''; } $form = new Curry_Form(array('csrfCheck' => false, 'elements' => array('name' => array('text', array('label' => 'Project name', 'value' => Curry_Core::$config->curry->name)), 'email' => array('text', array('label' => 'Webmaster email', 'value' => Curry_Core::$config->curry->adminEmail)), 'base_url' => array('text', array('label' => 'Base URL', 'value' => $scriptPath == '/' ? '' : $scriptPath, 'placeholder' => 'auto-detect')), 'template' => array('select', array('label' => 'Content template', 'multiOptions' => $contentTemplates)), 'development_mode' => array('checkbox', array('label' => 'Development mode', 'value' => Curry_Core::$config->curry->developmentMode)), 'save' => array('submit', array('label' => 'Save'))))); $form->addSubForm(new Curry_Form_SubForm(array('legend' => 'Create administrator account', 'elements' => array('username' => array('text', array('label' => 'Username', 'value' => 'admin')), 'password' => array('password', array('label' => 'Password', 'renderPassword' => true)), 'password_confirm' => array('password', array('label' => 'Confirm password', 'renderPassword' => true, 'validators' => array(array('identical', false, array('token' => 'password')))))))), 'admin', 5); $form->addSubForm(new Curry_Form_SubForm(array('legend' => 'Create user account', 'elements' => array('username' => array('text', array('label' => 'Username', 'value' => 'user')), 'password' => array('password', array('label' => 'Password', 'renderPassword' => true)), 'password_confirm' => array('password', array('label' => 'Confirm password', 'renderPassword' => true, 'validators' => array(array('identical', false, array('token' => 'password')))))))), 'user', 6); return $form; }
/** * Restore from file, using _GET request. * * @todo Verify this is working and that it's secure. Can we do this using session variables instead? */ public function showContinueRestore() { if (!Curry_URL::validate()) { throw new Exception('Invalid hash'); } Curry_Backend_DatabaseHelper::restoreFromFile($_GET['file'], $_GET['tables'], $_GET['max_execution_time'], $_GET['line'], $this); }
/** * Rebuild search index using a single request. * * @throws Exception */ public function showRebuildAll() { if (Curry_URL::validate()) { // Override and increase max execution time if set $timeLimit = ini_get('max_execution_time'); if ($timeLimit && $timeLimit < 250) { @set_time_limit(250); } Curry_Backend_Indexer::initRebuild(); Curry_Backend_Indexer::doRebuild(); $ses = new Zend_Session_Namespace(__CLASS__); if ($ses->failed) { $this->addMessage($ses->failed . ' entries failed indexing.', self::MSG_WARNING); } $this->addMainMenu(); $this->addMessage('Search index rebuilt, ' . $ses->success . ' entries updated successfully.', self::MSG_SUCCESS); } else { throw new Exception('Invalid rebuild link!'); } }
/** * Create a mail from a URL, Page or PageRevision. * * @param string|Page|PageRevision $page * @param Curry_Request $request * @param array $variables Additional template variables. * @return Curry_Mail */ public static function createFromPage($page, $request = null, array $variables = array()) { $app = Curry_Application::getInstance(); // If a URL is provided, attempt to find page using route if (is_string($page)) { $r = new Curry_Request('GET', (string) url($page)); $page = $app->findPage($r); if (!$request) { $request = $r; } } // Find PageRevision if ($page instanceof PageRevision) { $pageRevision = $page; } elseif ($page instanceof Page) { $pageRevision = $page->getPageRevision(); if (!$pageRevision) { throw new Exception('Page has no active revision.'); } } else { throw new Exception('$page is of invalid type, expected Page or PageRevision.'); } // Create Curry_Request object if not provided $oldVal = Curry_URL::setPreventRedirect(true); if (!$request) { $url = (string) url($pageRevision->getPage()->getUrl()); $request = new Curry_Request('GET', $url); } // Generate page $pageGenerator = $app->createPageGenerator($pageRevision, $request); $content = $pageGenerator->render($variables); // Create email $mail = new Curry_Mail(); $mail->setBodyHtml($content); $mail->setBodyText(strip_tags($content)); // restore redirect status Curry_URL::setPreventRedirect($oldVal); return $mail; }