/** * 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; }
public function resolve(array $arguments, $resolved = null) { if ($resolved) { // We don't need to do any post processing on urls. return $resolved; } if ($arguments) { $page = head($arguments); } if (isset($page) && $page instanceof \Concrete\Core\Page\Page) { if ($externalUrl = $page->getCollectionPointerExternalLink()) { return Url::createFromUrl($externalUrl); } if ($path = $page->getCollectionPath()) { return $this->resolveWithResolver($path, $arguments); } // if there's no path but it's the home page if ($page->isHomePage()) { return $this->resolveWithResolver("/", $arguments); } // otherwise, it's a page object with no path yet, which happens when pages aren't yet approved return $this->resolveWithResolver('/?cID=' . $page->getCollectionID(), $arguments); } return null; }
public function save($data) { if (isset($data['host'])) { $url = Url::createFromUrl($data['host']); $host = $url->getHost(); $data['host'] = (string) $host; } parent::save($data); }
public function testFromRequest() { $mock = $this->getMock('Concrete\\Core\\Http\\Request'); $mock->expects($this->once())->method('getScheme')->willReturn('http'); $mock->expects($this->once())->method('getHost')->willReturn('somehost'); $resolver = new \Concrete\Core\Url\Resolver\CanonicalUrlResolver(\Core::getFacadeApplication(), $mock); $old_value = \Config::get('concrete.seo.canonical_url'); \Config::set('concrete.seo.canonical_url', null); $this->assertEquals((string) \Concrete\Core\Url\Url::createFromUrl("http://somehost")->setPath(\Core::getApplicationRelativePath()), (string) $resolver->resolve(array())); \Config::set('concrete.seo.canonical_url', $old_value); }
public function on_start() { Events::addListener('on_page_view', function ($event) { $request = $event->getRequest(); $url = Url::createFromUrl($request->getUri()); $isSSL = false; $pathMatcher = new PathRequestMatcher(); if ($pathMatcher->matches($request)) { $isSSL = true; } if (!$pathMatcher->matches($request)) { $isSSL = false; } $userMatcher = new UserRequestMatcher(); if ($userMatcher->matches($request)) { $isSSL = true; } if (!$userMatcher->matches($request) && $isSSL === false) { $isSSL = false; } if ($isSSL === true && $request->getScheme() == 'http') { $config_canonical_ssl_url = Config::get('concrete.seo.canonical_ssl_url'); if (strlen($config_canonical_ssl_url)) { $canonical_ssl_url = Url::createFromUrl($config_canonical_ssl_url); $url->setHost($canonical_ssl_url->getHost()); } $url->setScheme('https'); $response = new RedirectResponse($url); } elseif ($isSSL === false && $request->getScheme() == 'https') { $config_canonical_url = Config::get('concrete.seo.canonical_url'); if (strlen($config_canonical_url)) { $canonical_url = Url::createFromUrl($config_canonical_url); $url->setHost($canonical_url->getHost()); } $url->setScheme('http'); $response = new RedirectResponse($url); } if (isset($response)) { $response->send(); exit; } }); }
/** * 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; }
public function createGatheringItems(GatheringDataSourceConfiguration $configuration) { $twitter = $this->getTwitterService(); $url = Url::createFromUrl(''); $url->setPath('/statuses/user_timeline.json'); $url->setQuery(array('screen_name' => $configuration->getTwitterUsername(), 'count' => 50)); $tweets = json_decode($twitter->request($url)); if (!empty($tweets->errors[0])) { throw new Exception($tweets->errors[0]->message); } $gathering = $configuration->getGatheringObject(); $lastupdated = 0; if ($gathering->getGatheringDateLastUpdated()) { $lastupdated = strtotime($gathering->getGatheringDateLastUpdated()); } $items = array(); foreach ($tweets as $tweet) { $item = TwitterGatheringItem::add($configuration, $tweet); if (is_object($item)) { $items[] = $item; } } return $items; }
</td> <td><?php echo number_format($up->getUserPointEntryValue()); ?> </td> <td><?php echo $dh->formatDateTime($up->getUserPointEntryTimestamp()); ?> </td> <td><?php echo h($up->getUserPointEntryDescription()); ?> </td> <td style="Text-align: right"> <?php $delete = \Concrete\Core\Url\Url::createFromUrl($view->action('deleteEntry', $up->getUserPointEntryID())); $delete->setQuery(array('ccm_token' => \Core::make('helper/validation/token')->generate('delete_community_points'))); ?> <a href="<?php echo $delete; ?> " class="btn btn-sm btn-danger"><?php echo t('Delete'); ?> </a> </td> </tr> <?php } ?> </table>
/** * Using the configuration value, determines whether we need to redirect to a URL with * a trailing slash or not. * * @return \Concrete\Core\Routing\RedirectResponse */ public function handleURLSlashes(SymfonyRequest $request) { $trailing_slashes = $this['config']['concrete.seo.trailing_slash']; $path = $request->getPathInfo(); // If this isn't the homepage if ($path && $path != '/') { // If the trailing slash doesn't match the config, return a redirect response if ($trailing_slashes && substr($path, -1) != '/' || !$trailing_slashes && substr($path, -1) == '/') { $parsed_url = Url::createFromUrl($request->getUri(), $trailing_slashes ? Url::TRAILING_SLASHES_ENABLED : Url::TRAILING_SLASHES_DISABLED); $response = new RedirectResponse($parsed_url, 301); $response->setRequest($request); return $response; } } }
<?php use Concrete\Core\Url\Url; defined('C5_EXECUTE') or die('Access Denied.'); $app = Concrete\Core\Support\Facade\Application::getFacadeApplication(); $valt = $app->make('helper/validation/token'); if ($this->controller->getTask() == 'translate_po') { $url = Url::createFromUrl($this->controller->action('save_translation')); $url = $url->setQuery(['ccm_token' => $app->make('token')->generate('translate/save')]); /* @var $section \Concrete\Core\Multilingual\Page\Section\Section */ ?> <script> $(document).ready(function() { ccmTranslator.initialize({ container: '#ccm-translator-interface', height: $(window).height() - 300, saveAction: <?php echo json_encode((string) $url); ?> , plurals: <?php echo json_encode($section->getPluralsCases()); ?> , translations: <?php echo json_encode($translations); ?> , approvalSupport: false }); var saveToFileToken = <?php
<?php defined('C5_EXECUTE') or die("Access Denied."); $save_url = \Concrete\Core\Url\Url::createFromUrl($view->action('save_thumb')); $save_url = $save_url->setQuery(array('ccm_token' => \Core::make('token')->generate('avatar/save_thumb'))); ?> <div class="row"> <div class="col-sm-8 col-sm-offset-2"> <h1 class="page-header"><?php echo t('User Avatar'); ?> </h1> <p><?php echo t('Change the picture attached to my posts.'); ?> </p> <div id="profile-avatar"> <?php echo t('You need the Adobe Flash plugin installed on your computer to upload and crop your user profile picture.'); ?> <br /><br /> <a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash">Download the Flash Player here</a>. </div> <?php if ($profile->hasAvatar()) { ?> <form method="post" action="<?php echo $view->action('delete');
/** * Using the configuration value, determines whether we need to redirect to a URL with * a trailing slash or not. * * @return \Concrete\Core\Routing\RedirectResponse */ public function handleURLSlashes(SymfonyRequest $request) { $request_path = $request->getRequestUri(); $parsed_url = Url::createFromUrl($request->getUri()); $url_path = ltrim(parse_url($request_path, PHP_URL_PATH), '/'); if ($url_path != (string) $parsed_url->getPath()) { $response = new RedirectResponse($parsed_url, 301); $response->setRequest($request); return $response; } }
/** * Using the configuration value, determines whether we need to redirect to a URL with * a trailing slash or not. * * @return \Concrete\Core\Routing\RedirectResponse */ public function handleURLSlashes(SymfonyRequest $request) { $url = Url::createFromUrl($request->getUri()); if ($request->getPathInfo() != '/') { if (urldecode((string) $url) != urldecode($request->getUri())) { $response = new RedirectResponse((string) $url, 301); $response->setRequest($request); return $response; } } }
/** * Using the configuration value, determines whether we need to redirect to a URL with * a trailing slash or not. * * @return \Concrete\Core\Routing\RedirectResponse */ public function handleURLSlashes(SymfonyRequest $request) { $parsedUrl = (string) Url::createFromUrl($request->getUri()); if ($request->getPathInfo() != '/') { $parsedUrlWithoutQueryString = strstr($parsedUrl, '?', true) ?: $parsedUrl; $requestUrl = $request->getUri(); $requestUrlWithoutQueryString = strstr($requestUrl, '?', true) ?: $requestUrl; if (urldecode($parsedUrlWithoutQueryString) != urldecode($requestUrlWithoutQueryString)) { $response = new RedirectResponse($parsedUrl, 301); $response->setRequest($request); return $response; } } }