/** * Resolve url's from any type of input. * * This method MUST either return a `\League\URL\URL` when a url is resolved * or null when a url cannot be resolved. * * @param array $arguments A list of the arguments * @param \League\URL\URLInterface $resolved * * @return \League\URL\URLInterface */ public function resolve(array $arguments, $resolved = null) { if ($this->cached) { return $this->cached; } $url = Url::createFromUrl(''); $url->setHost(null); $url->setScheme(null); if (\Config::get('concrete.seo.canonical_url')) { $canonical = UrlImmutable::createFromUrl(Config::get('concrete.seo.canonical_url')); // If the request is over https and the canonical url is http, lets just say https for the canonical url. if (strtolower($canonical->getScheme()) == 'http' && strtolower($this->request->getScheme()) == 'https') { $url->setScheme('https'); } else { $url->setScheme($canonical->getScheme()); } $url->setHost($canonical->getHost()); if (intval($canonical->getPort()->get()) > 0) { $url->setPort($canonical->getPort()); } } else { $host = $this->request->getHost(); $scheme = $this->request->getScheme(); if ($scheme && $host) { $url->setScheme($scheme)->setHost($host)->setPortIfNecessary(Request::getInstance()->getPort()); } } if ($relative_path = \Core::getApplicationRelativePath()) { $url = $url->setPath($relative_path); } $this->cached = UrlImmutable::createFromUrl($url); return $this->cached; }
/** * Resolve url's from any type of input. * * This method MUST either return a `\League\URL\URL` when a url is resolved * or null when a url cannot be resolved. * * @param array $arguments A list of the arguments * @param \League\URL\URLInterface $resolved * * @return \League\URL\URLInterface */ public function resolve(array $arguments, $resolved = null) { $url = Url::createFromUrl(''); $url->setHost(null); $url->setScheme(null); if (\Config::get('concrete.seo.canonical_url')) { $canonical = UrlImmutable::createFromUrl(\Config::get('concrete.seo.canonical_url')); $url->getHost()->set($canonical->getHost()); $url->getScheme()->set($canonical->getScheme()); if (intval($canonical->getPort()->get()) > 0) { $url->getPort()->set($canonical->getPort()); } } else { $scheme = Request::getInstance()->getScheme(); $host = Request::getInstance()->getHost(); if ($scheme && $host) { $url->setScheme($scheme)->setHost($host)->setPortIfNecessary(Request::getInstance()->getPort()); } } if ($relative_path = \Core::getApplicationRelativePath()) { $url = $url->setPath($relative_path); } return UrlImmutable::createFromUrl($url); }
/** * Resolve url's from any type of input. * * This method MUST either return a `\League\URL\URL` when a url is resolved * or null when a url cannot be resolved. * * @param array $arguments A list of the arguments * @param \League\URL\URLInterface $resolved * * @return \League\URL\URLInterface */ public function resolve(array $arguments, $resolved = null) { if ($this->cached) { return $this->cached; } $config = $this->app['config']; // Determine trailing slash setting $trailing_slashes = $config->get('concrete.seo.trailing_slash') ? Url::TRAILING_SLASHES_ENABLED : Url::TRAILING_SLASHES_DISABLED; $url = Url::createFromUrl('', $trailing_slashes); $url->setHost(null); $url->setScheme(null); if ($config->get('concrete.seo.canonical_url')) { $canonical = UrlImmutable::createFromUrl($config->get('concrete.seo.canonical_url'), $trailing_slashes); // If the request is over https and the canonical url is http, lets just say https for the canonical url. if (strtolower($canonical->getScheme()) == 'http' && strtolower($this->request->getScheme()) == 'https') { $url->setScheme('https'); } else { $url->setScheme($canonical->getScheme()); } $url->setHost($canonical->getHost()); if (intval($canonical->getPort()->get()) > 0) { $url->setPort($canonical->getPort()); } } else { $host = $this->request->getHost(); $scheme = $this->request->getScheme(); if ($scheme && $host) { $url->setScheme($scheme)->setHost($host)->setPort($this->request->getPort()); } } if ($relative_path = $this->app['app_relative_path']) { $url = $url->setPath($relative_path); } $this->cached = UrlImmutable::createFromUrl($url, $trailing_slashes); return $this->cached; }
/** * @return \Concrete\Core\Error\Error */ public function configure() { $error = $this->app->make('helper/validation/error'); /* @var $error \Concrete\Core\Error\ErrorList\ErrorList */ try { $val = $this->app->make('helper/validation/form'); /* @var \Concrete\Core\Form\Service\Validation $val */ $val->setData($this->post()); $val->addRequired("SITE", t("Please specify your site's name")); $val->addRequiredEmail("uEmail", t('Please specify a valid email address')); $val->addRequired("DB_DATABASE", t('You must specify a valid database name')); $val->addRequired("DB_SERVER", t('You must specify a valid database server')); $password = $_POST['uPassword']; $passwordConfirm = $_POST['uPasswordConfirm']; $this->app->make('validator/password')->isValid($password, $error); if ($password) { if ($password != $passwordConfirm) { $error->add(t('The two passwords provided do not match.')); } } if (is_object($this->fileWriteErrors)) { foreach ($this->fileWriteErrors->getList() as $msg) { $error->add($msg); } } $error = $this->validateDatabase($error); $error = $this->validateSampleContent($error); if ($this->post('canonicalUrlChecked') === '1') { try { $url = UrlImmutable::createFromUrl($this->post('canonicalUrl')); if (strcasecmp('http', $url->getScheme()) !== 0) { throw new Exception('The HTTP canonical URL must have the http:// scheme'); } $canonicalUrl = (string) $url; } catch (Exception $x) { $error->add($x); } } else { $canonicalUrl = ''; } if ($this->post('canonicalSSLUrlChecked') === '1') { $url = UrlImmutable::createFromUrl($this->post('canonicalSSLUrl')); if (strcasecmp('https', $url->getScheme()) !== 0) { throw new Exception('The SSL canonical URL must have the https:// scheme'); } $canonicalSSLUrl = (string) $url; } else { $canonicalSSLUrl = ''; } if ($val->test() && !$error->has()) { // write the config file $vh = $this->app->make('helper/validation/identifier'); $this->fp = @fopen(DIR_CONFIG_SITE . '/site_install.php', 'w+'); $this->fpu = @fopen(DIR_CONFIG_SITE . '/site_install_user.php', 'w+'); if ($this->fp) { $config = isset($_POST['SITE_CONFIG']) ? (array) $_POST['SITE_CONFIG'] : []; $config['database'] = ['default-connection' => 'concrete', 'connections' => ['concrete' => ['driver' => 'c5_pdo_mysql', 'server' => $_POST['DB_SERVER'], 'database' => $_POST['DB_DATABASE'], 'username' => $_POST['DB_USERNAME'], 'password' => $_POST['DB_PASSWORD'], 'charset' => 'utf8']]]; $config['canonical-url'] = $canonicalUrl; $config['canonical-ssl-url'] = $canonicalSSLUrl; $config['session-handler'] = $_POST['sessionHandler']; $renderer = new Renderer($config); fwrite($this->fp, $renderer->render()); fclose($this->fp); chmod(DIR_CONFIG_SITE . '/site_install.php', 0700); } else { throw new Exception(t('Unable to open config/app.php for writing.')); } if ($this->fpu) { $config = $this->app->make('config'); $hasher = new PasswordHash($config->get('concrete.user.password.hash_cost_log2'), $config->get('concrete.user.password.hash_portable')); $configuration = "<?php\n"; $configuration .= "define('INSTALL_USER_EMAIL', " . var_export((string) $_POST['uEmail'], true) . ");\n"; $configuration .= "define('INSTALL_USER_PASSWORD_HASH', " . var_export((string) $hasher->HashPassword($_POST['uPassword']), true) . ");\n"; $configuration .= "define('INSTALL_STARTING_POINT', " . var_export((string) $this->post('SAMPLE_CONTENT'), true) . ");\n"; $configuration .= "define('SITE', " . var_export((string) $_POST['SITE'], true) . ");\n"; $locale = $this->post('siteLocaleLanguage') . '_' . $this->post('siteLocaleCountry'); $configuration .= "define('SITE_INSTALL_LOCALE', " . var_export($locale, true) . ");\n"; $configuration .= "define('APP_INSTALL_LANGUAGE', " . var_export($this->post('locale'), true) . ");\n"; $res = fwrite($this->fpu, $configuration); fclose($this->fpu); chmod(DIR_CONFIG_SITE . '/site_install_user.php', 0700); if (PHP_SAPI != 'cli') { $this->redirect('/'); } } else { throw new Exception(t('Unable to open config/site_user.php for writing.')); } } else { if ($error->has()) { $this->set('error', $error); } else { $error = $val->getError(); $this->set('error', $val->getError()); } } } catch (Exception $ex) { $this->reset(); $this->set('error', $ex); $error->add($ex); } $this->setup(); return $error; }
/** * If we have redirect to canonical host enabled, we need to honor it here. * * @return \Concrete\Core\Routing\RedirectResponse */ public function handleCanonicalURLRedirection(SymfonyRequest $r) { $config = $this['config']; if ($config->get('concrete.seo.redirect_to_canonical_url') && $config->get('concrete.seo.canonical_url')) { $url = UrlImmutable::createFromUrl($r->getUri()); $canonical = UrlImmutable::createFromUrl($config->get('concrete.seo.canonical_url'), (bool) $config->get('concrete.seo.trailing_slash')); // Set the parts of the current URL that are specified in the canonical URL, including host, // port, scheme. Set scheme first so that our port can use the magic "set if necessary" method. $new = $url->setScheme($canonical->getScheme()->get()); $new = $new->setHost($canonical->getHost()->get()); $new = $new->setPortIfNecessary($canonical->getPort()->get()); // Now we have our current url, swapped out with the important parts of the canonical URL. // If it matches, we're good. if ($new == $url) { return null; } // Uh oh, it didn't match. before we redirect to the canonical URL, let's check to see if we have an SSL // URL if ($config->get('concrete.seo.canonical_ssl_url')) { $ssl = UrlImmutable::createFromUrl($config->get('concrete.seo.canonical_ssl_url')); $new = $url->setScheme($ssl->getScheme()->get()); $new = $new->setHost($ssl->getHost()->get()); $new = $new->setPortIfNecessary($ssl->getPort()->get()); // Now we have our current url, swapped out with the important parts of the canonical URL. // If it matches, we're good. if ($new == $url) { return null; } } $response = new RedirectResponse($new, '301'); return $response; } }
/** * Resolve url's from any type of input. * * This method MUST either return a `\League\URL\URL` when a url is resolved * or null when a url cannot be resolved. * * If the first argument provided is a page object, we will use that object to determine the site tree * (and thus the canonical url) to use. * * @param array $arguments A list of the arguments * @param \League\URL\URLInterface $resolved * * @return \League\URL\URLInterface */ public function resolve(array $arguments, $resolved = null) { $config = null; $page = null; // Canonical urls for pages can be different than for the entire site if (count($arguments) && head($arguments) instanceof Page) { /** @var Page $page */ $page = head($arguments); $tree = $page->getSiteTreeObject(); if ($tree instanceof SiteTree && ($site = $tree->getSite())) { $config = $site->getConfigRepository(); } } elseif ($this->cached) { return $this->cached; } // Get the config from the current site tree if ($config === null && $this->app->isInstalled()) { $site = $this->app['site']->getSite(); if (is_object($site)) { $config = $site->getConfigRepository(); } } // Determine trailing slash setting $trailing_slashes = $config && $config->get('seo.trailing_slash') ? Url::TRAILING_SLASHES_ENABLED : Url::TRAILING_SLASHES_DISABLED; $url = UrlImmutable::createFromUrl('', $trailing_slashes); $url = $url->setHost(null); $url = $url->setScheme(null); if ($config && ($configUrl = $site->getSiteCanonicalURL())) { $canonical = UrlImmutable::createFromUrl($configUrl, $trailing_slashes); if ($configSslUrl = $config->get('seo.canonical_ssl_url')) { $canonical_ssl = UrlImmutable::createFromUrl($configSslUrl, $trailing_slashes); } $url = $url->setHost($canonical->getHost()); $url = $url->setScheme($canonical->getScheme()); // If the request is over https if (strtolower($this->request->getScheme()) == 'https') { // If the canonical ssl url is set, respect the canonical ssl url. if (isset($canonical_ssl)) { $url = $url->setHost($canonical_ssl->getHost()); $url = $url->setScheme($canonical_ssl->getScheme()); if (intval($canonical_ssl->getPort()->get()) > 0) { $url = $url->setPort($canonical_ssl->getPort()); } } else { // If the canonical url is http, lets just say https for the canonical url. if (strtolower($canonical->getScheme()) == 'http') { $url = $url->setScheme('https'); } if (intval($canonical->getPort()->get()) > 0) { $url = $url->setPort($canonical->getPort()); } } } elseif (intval($canonical->getPort()->get()) > 0) { $url = $url->setPort($canonical->getPort()); } } if ($relative_path = $this->app['app_relative_path']) { $url = $url->setPath($relative_path); } // Don't cache page specific canonical urls if (!$page) { $this->cached = $url; } return $url; }
public function __construct($name = null, array $data = array(), $dataName = '') { parent::__construct($name, $data, $dataName); $url = \Concrete\Core\Url\UrlImmutable::createFromUrl(\Core::make('url/canonical')); $this->canonicalUrl = $url; }