Example #1
0
 public static function setupSiteInterfaceLocalization(Page $c = null)
 {
     if (!$c) {
         $c = Page::getCurrentPage();
     }
     $app = Facade::getFacadeApplication();
     // don't translate dashboard pages
     $dh = $app->make('helper/concrete/dashboard');
     if ($dh->inDashboard($c)) {
         return;
     }
     $ms = Section::getBySectionOfSite($c);
     if (!is_object($ms)) {
         $ms = static::getPreferredSection();
     }
     if (!$ms) {
         return;
     }
     $locale = $ms->getLocale();
     if ($locale) {
         $app->make('session')->set('multilingual_default_locale', $locale);
         $loc = Localization::getInstance();
         $loc->setContextLocale('site', $locale);
     }
 }
Example #2
0
 public static function setupSiteInterfaceLocalization(Page $c = null)
 {
     if (\User::isLoggedIn() && Config::get('concrete.multilingual.keep_users_locale')) {
         return;
     }
     if (!$c) {
         $c = Page::getCurrentPage();
     }
     // don't translate dashboard pages
     $dh = \Core::make('helper/concrete/dashboard');
     if ($dh->inDashboard($c)) {
         return;
     }
     $ms = Section::getBySectionOfSite($c);
     if (!is_object($ms)) {
         $ms = static::getPreferredSection();
     }
     if (!$ms) {
         return;
     }
     $locale = $ms->getLocale();
     if (strlen($locale)) {
         \Localization::changeLocale($locale);
     }
 }
Example #3
0
 public static function setupSiteInterfaceLocalization(Page $c = null)
 {
     $loc = \Localization::getInstance();
     if (!(\User::isLoggedIn() && Config::get('concrete.multilingual.keep_users_locale'))) {
         if (!$c) {
             $c = Page::getCurrentPage();
         }
         // don't translate dashboard pages
         $dh = \Core::make('helper/concrete/dashboard');
         if ($dh->inDashboard($c)) {
             return;
         }
         $locale = null;
         $ms = Section::getBySectionOfSite($c);
         if ($ms) {
             $locale = $ms->getLocale();
         }
         if (!$locale) {
             if (Config::get('concrete.multilingual.use_previous_locale') && Session::has('previous_locale')) {
                 $locale = Session::get('previous_locale');
             }
             if (!$locale) {
                 $ms = static::getPreferredSection();
                 if ($ms) {
                     $locale = $ms->getLocale();
                 }
             }
         }
         if ($locale) {
             $loc->setLocale($locale);
         }
     }
     Session::set('previous_locale', $loc->getLocale());
 }
 public function registerEvents()
 {
     $app = $this->app;
     $events = $this->app->make('director');
     // Add the sitemap icons listener
     $events->addListener('on_before_render', function ($event) use($app) {
         $c = Page::getCurrentPage();
         $view = $event->getArgument('view');
         $assets = $app->make('asset_pipeline/helper/assets');
         $theme = null;
         if (is_object($c)) {
             $theme = $c->getCollectionThemeObject();
         } else {
             $theme = Theme::getSiteTheme();
         }
         // TODO: If there are page-specific styles set, should we use
         //       this one instead:
         //$style = $c->getCustomStyleObject();
         $style = $theme->getThemeCustomStyleObject();
         if (is_object($style)) {
             $valueList = $style->getValueList();
             if ($valueList instanceof \Concrete\Core\StyleCustomizer\Style\ValueList) {
                 $variables = array();
                 foreach ($valueList->getValues() as $value) {
                     $variables = array_merge($value->toLessVariablesArray(), $variables);
                 }
                 $assets->setStylesheetVariables('theme', $variables);
             }
         }
         $view->addScopeItems(array('assets' => $assets));
     });
 }
Example #5
0
 public function on_start()
 {
     Events::addListener('on_before_render', function () {
         $c = Page::getCurrentPage();
         if (is_object($c) && $c->isEditMode()) {
             $view = View::getInstance();
             $html = new Html();
             $view->addHeaderItem($html->css('area_hints.css', 'area_hints'));
         }
     });
 }
 /**
  * On CMS boot.
  *
  * @return void
  */
 public function on_start()
 {
     $this->registerAssets();
     Events::addListener('on_before_render', function ($e) {
         $c = Page::getCurrentPage();
         if ($c instanceof Page) {
             $r = ResponseAssetGroup::get();
             if (!$c->isEditMode()) {
                 $r->requireAsset('smooth-scrolling');
             }
         }
     });
 }
Example #7
0
 /**
  * @return bool|null
  */
 public function view()
 {
     // Check for a valid File in the view
     $f = $this->getFileObject();
     $this->set('f', $f);
     // On-State image available
     $foS = $this->getFileOnstateObject();
     $this->set('foS', $foS);
     $imgPaths = [];
     $imgPaths['hover'] = File::getRelativePathFromID($this->fOnstateID);
     $imgPaths['default'] = File::getRelativePathFromID($this->getFileID());
     $this->set('imgPaths', $imgPaths);
     $this->set('altText', $this->getAltText());
     $this->set('title', $this->getTitle());
     $this->set('linkURL', $this->getLinkURL());
     $this->set('c', Page::getCurrentPage());
 }
Example #8
0
 public function setThemeContext($theme = null)
 {
     if ($theme === null) {
         $c = Page::getCurrentPage();
         if (is_object($c)) {
             $theme = $c->getCollectionThemeObject();
         } else {
             $theme = Theme::getSiteTheme();
         }
     }
     if (!is_object($theme)) {
         // TODO: Check whether this can happen or not...
         throw new Exception(t("No theme available for the page!"));
     }
     $env = Environment::get();
     $r = $env->getRecord(DIRNAME_THEMES . '/' . $theme->getThemeHandle(), $theme->getPackageHandle());
     $this->themeBasePath = $r->file;
 }
Example #9
0
 /**
  * @param string $stackName
  * @param string $cvID
  * @param int $multilingualContentSource
  *
  * @return Page
  */
 public static function getByName($stackName, $cvID = 'RECENT', Site $site = null, $multilingualContentSource = self::MULTILINGUAL_CONTENT_SOURCE_CURRENT)
 {
     $c = Page::getCurrentPage();
     if (is_object($c) && !$c->isError()) {
         $identifier = sprintf('/stack/name/%s/%s/%s/%s', $stackName, $c->getCollectionID(), $cvID, $multilingualContentSource);
         $cache = Core::make('cache/request');
         $item = $cache->getItem($identifier);
         if (!$item->isMiss()) {
             $cID = $item->get();
         } else {
             $item->lock();
             $db = Database::connection();
             $ms = false;
             $detector = Core::make('multilingual/detector');
             if ($detector->isEnabled()) {
                 $ms = self::getMultilingualSectionFromType($multilingualContentSource);
             }
             $sql = 'select cID from Stacks where stName = ?';
             $q = array($stackName);
             if ($ms) {
                 $sql .= ' and (stMultilingualSection = ? or stMultilingualSection = 0)';
                 $q[] = $ms->getCollectionID();
             } else {
                 $sql .= ' and stMultilingualSection = 0';
             }
             $sql .= ' and siteTreeID = ?';
             if ($ms) {
                 $sql .= ' order by stMultilingualSection desc';
             }
             $sql .= ' limit 1';
             if (!is_object($site)) {
                 $site = \Core::make('site')->getSite();
             }
             $q[] = $site->getDefaultLocale()->getSiteTree()->getSiteTreeID();
             $cID = $db->fetchColumn($sql, $q);
             $cache->save($item->set($cID));
         }
     } else {
         $db = Database::connection();
         $cID = $db->fetchColumn('select cID from Stacks where stName = ? and stMultilingualSection = 0', array($stackName));
     }
     return $cID ? static::getByID($cID, $cvID) : null;
 }
Example #10
0
 /**
  * Gets the MultilingualSection object for the current section of the site.
  *
  * @return Section
  */
 public static function getCurrentSection()
 {
     static $lang;
     if (!isset($lang)) {
         $c = Page::getCurrentPage();
         if ($c instanceof Page) {
             $lang = self::getBySectionOfSite($c);
         }
     }
     return $lang;
 }
 /**
  * Get the Concrete5 permission object for the given page.
  * @return Permissions
  */
 protected function pagePermissionObject()
 {
     if ($this->_pagePermissionObj === null) {
         $this->_pagePermissionObj = new \Concrete\Core\Permission\Checker(\Concrete\Core\Page\Page::getCurrentPage());
     }
     return $this->_pagePermissionObj;
 }
Example #12
0
 /**
  * @return bool|Page
  */
 public function getPreviousCollection()
 {
     $page = false;
     $app = Facade::getFacadeApplication();
     $db = $app->make('database')->connection();
     $cID = 1;
     $currentPage = Page::getCurrentPage();
     while ($cID > 0) {
         switch ($this->orderBy) {
             case 'chrono_desc':
                 $cID = $db->GetOne('select Pages.cID from Pages inner join CollectionVersions cv on Pages.cID = cv.cID where cvIsApproved = 1 and cvDatePublic < ? and cParentID = ?  order by cvDatePublic desc', [$currentPage->getCollectionDatePublic(), $currentPage->getCollectionParentID()]);
                 break;
             case 'chrono_asc':
                 $cID = $db->GetOne('select Pages.cID from Pages inner join CollectionVersions cv on Pages.cID = cv.cID where cvIsApproved = 1 and cvDatePublic > ? and cParentID = ?  order by cvDatePublic asc', [$currentPage->getCollectionDatePublic(), $currentPage->getCollectionParentID()]);
                 break;
             case 'display_desc':
                 $cID = $db->GetOne('select cID from Pages where cDisplayOrder > ? and cParentID = ? order by cDisplayOrder asc', [$currentPage->getCollectionDisplayOrder(), $currentPage->getCollectionParentID()]);
                 break;
             case 'display_asc':
             default:
                 $cID = $db->GetOne('select cID from Pages where cDisplayOrder < ? and cParentID = ? order by cDisplayOrder desc', [$currentPage->getCollectionDisplayOrder(), $currentPage->getCollectionParentID()]);
                 break;
         }
         if ($cID > 0) {
             $page = Page::getByID($cID, 'RECENT');
             $currentPage = $page;
             $cp = new Permissions($page);
             if ($cp->canRead() && $page->getAttribute('exclude_nav') != 1) {
                 break;
             } else {
                 $page = false;
                 //avoid accidentally returning this $page if we're on last loop iteration
             }
         }
     }
     if (!is_object($page) && $this->loopSequence) {
         $c = Page::getCurrentPage();
         $parent = Page::getByID($c->getCollectionParentID(), 'ACTIVE');
         switch ($this->orderBy) {
             case 'chrono_desc':
                 return $parent->getFirstChild('cvDatePublic desc');
                 break;
             case 'chrono_asc':
                 return $parent->getFirstChild('cvDatePublic asc');
                 break;
             case 'display_desc':
                 return $parent->getFirstChild('cDisplayOrder asc');
                 break;
             case 'display_asc':
             default:
                 return $parent->getFirstChild('cDisplayOrder desc');
                 break;
         }
     }
     return $page;
 }
 public function __construct()
 {
     $c = Page::getCurrentPage();
     $this->currentTheme = $c->getCollectionThemeObject();
 }