public function getTranslatedPages($page = false, $sans = false) { $langms = new MultilingualSection(); if ($page) { $ms = MultilingualSection::getByID($page->getCollectionID()); } else { $page = Page::getCurrentPage(); $ms = MultilingualSection::getCurrentSection(); } if (is_object($ms)) { $lang = $ms->getLocale(); } if ($sans) { $locales = self::getLocales($sans); } else { $locales = self::getLocales($lang); } $tpages = array(); foreach ($locales as $locale) { $langms->msLocale = $locale; $id = $langms->getTranslatedPageID($page); $transPage = Page::getByID($id); $transPage->locale = $locale; if ($id > 0) { $tpages[$locale] = $transPage; } } return $tpages; }
public function view() { $uh = Loader::helper('concrete/urls'); $bt = BlockType::getByHandle('switch_language'); Loader::model('section', 'multilingual'); $ml = MultilingualSection::getList(); $c = Page::getCurrentPage(); $al = MultilingualSection::getBySectionOfSite($c); $languages = array(); $locale = ACTIVE_LOCALE; if (is_object($al)) { $locale = $al->getLanguage(); } foreach ($ml as $m) { $languages[$m->getCollectionID()] = $m->getLanguageText($locale) . ' ' . (strlen($m->msIcon) ? '(' . $m->msIcon . ')' : ''); } $this->set('languages', $languages); $this->set('languageSections', $ml); $this->set('action', $uh->getBlockTypeToolsURL($bt) . '/switch'); if (is_object($al)) { $this->set('activeLanguage', $al->getCollectionID()); } $pkg = Package::getByHandle('multilingual'); $mdl = Loader::helper('default_language', 'multilingual'); $this->set('defaultLanguage', $mdl->getSessionDefaultLocale()); $this->set('cID', $c->getCollectionID()); }
public function getDashboardSitemapIconSRC($page) { $ids = MultilingualSection::getIDList(); if (in_array($page->getCollectionID(), $ids)) { return self::getSectionFlagIcon($page, true); } }
public function __construct() { $mslist = MultilingualSection::getList(); $query = ', (select mpRelationID from MultilingualPageRelations where cID = p1.cID LIMIT 1) as mpr'; foreach ($mslist as $ms) { $query .= ', (select count(mpRelationID) from MultilingualPageRelations where MultilingualPageRelations.mpRelationID = mpr and mpLocale = \'' . $ms->getLocale() . '\') as relationCount' . $ms->getCollectionID(); } $this->setBaseQuery($query); }
/** * gets the locale string for the current page * based first on path within the site (section) or session if not available * @return string */ public function getLocale() { $ms = MultilingualSection::getCurrentSection(); if (is_object($ms)) { $lang = $ms->getLocale(); } else { $lang = Loader::helper('default_language', 'multilingual')->getSessionDefaultLocale(); } $_SESSION['DEFAULT_LOCALE'] = (string) $lang; return (string) $lang; }
public function getMenuLinkHTML() { $sect = MultilingualSection::getCurrentSection(); $ih = Loader::helper('interface/flag', 'multilingual'); $icon = $ih->getFlagIcon($sect->getIcon(), true); $class = 'ccm-page-edit-nav-multilingual-flag'; if (!$icon) { $icon = $this->menuItem->getMenuItemFileURL('generic_language.png'); $class = 'ccm-page-edit-nav-multilingual-no-flag'; } $page = Page::getCurrentPage(); $this->menuItem->linkAttributes['href'] .= '?cID=' . $page->getCollectionID(); $this->menuItem->linkAttributes['class'] = $class; $this->menuItem->linkAttributes['style'] = 'background-image: url(' . $icon . ')'; $this->menuItem->setName($sect->getLanguageText()); return parent::getMenuLinkHTML(); }
<?php defined('C5_EXECUTE') or die("Access Denied."); if (Loader::helper('validation/token')->validate('get_url_slug', $_REQUEST['token'])) { $lang = LANGUAGE; if (isset($_REQUEST['parentID']) && ($multilingual = Package::getByHandle('multilingual'))) { $ms = MultilingualSection::getBySectionOfSite(Page::getByID($_REQUEST['parentID'])); if (is_object($ms)) { $lang = $ms->getLanguage(); } } $text = Loader::helper('text'); $name = $text->urlify($_REQUEST['name'], PAGE_PATH_SEGMENT_MAX_LENGTH, $lang); $ret = Events::fire('on_page_urlify', $_REQUEST['name']); if ($ret) { $name = $ret; } echo $name; }
<p><?php echo t('Since one of your multilingual sections is the home page, you may not duplicate your site tree using this tool. You must manually assign pages using the page report.'); ?> </p> <?php } } } ?> <?php if (count($pages) > 0) { $defaultLanguages = array('' => t('** None Set')); foreach ($pages as $pc) { $pcl = MultilingualSection::getByID($pc->getCollectionID()); $defaultLanguages[$pcl->getLocale()] = $pcl->getLanguageText(); } $defaultLanguagesSelect = $form->select('defaultLanguage', $defaultLanguages, $defaultLanguage); ?> <br/> <h3><?php echo t('Multilingual Settings'); ?> </h3> <form method="post" action="<?php echo $this->action('set_default'); ?>
public function create_page() { Loader::model('section', 'multilingual'); if (Loader::helper('validation/token')->validate('create_page', $_POST['token'])) { $ms = MultilingualSection::getByLocale($_POST['locale']); $page = Page::getByID($_POST['sourceID']); if (is_object($page) && !$page->isError()) { // we get the related parent id $cParentID = $page->getCollectionParentID(); $cParent = Page::getByID($cParentID); $cParentRelatedID = $ms->getTranslatedPageID($cParent); if ($cParentRelatedID > 0) { // we copy the page underneath it and store it $newParent = Page::getByID($cParentRelatedID); $ct = CollectionType::getByID($page->getCollectionTypeID()); $cp = new Permissions($newParent); if ($cp->canAddSubCollection($ct) && $page->canMoveCopyTo($newParent)) { $newPage = $page->duplicate($newParent); if (is_object($newPage)) { print '<a href="' . Loader::helper("navigation")->getLinkToCollection($newPage) . '">' . $newPage->getCollectionName() . '</a>'; } } else { print '<span class="ccm-error">' . t("Insufficient permissions.") . '</span>'; } } } } exit; }
public function add_content_section() { if (Loader::helper('validation/token')->validate('add_content_section')) { if (!Loader::helper('validation/numbers')->integer($this->post('pageID')) || $this->post('pageID') < 1) { $this->error->add(t('You must specify a page for this multilingual content section.')); } else { $pc = Page::getByID($this->post('pageID')); } if (!$this->error->has()) { $lc = MultilingualSection::getByID($this->post('pageID')); if (is_object($lc)) { $this->error->add(t('A language section page at this location already exists.')); } } if (!$this->error->has()) { if ($this->post('msIcon')) { $combination = $this->post('msLanguage') . '_' . $this->post('msIcon'); $locale = MultilingualSection::getByLocale($combination); if (is_object($locale)) { $this->error->add(t('This language/region combination already exists.')); } } } if (!$this->error->has()) { MultilingualSection::assign($pc, $this->post('msLanguage'), $this->post('msIcon')); $this->redirect('/dashboard/multilingual/setup', 'multilingual_content_updated'); } } else { $this->error->add(Loader::helper('validation/token')->getErrorMessage()); } $this->view(); }
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); Loader::model('section', 'multilingual'); // first we get the selected language if (isset($_POST['ccmMultilingualSiteDefaultLanguage'])) { // this is coming from "set default" custom template if (isset($_POST['ccmMultilingualSiteRememberDefault']) && $_POST['ccmMultilingualSiteRememberDefault']) { setcookie('DEFAULT_LOCALE', $_POST['ccmMultilingualSiteDefaultLanguage'], time() + 60 * 60 * 24 * 365, DIR_REL . '/'); } if (empty($_POST['ccmMultilingualSiteRememberDefault'])) { setcookie('DEFAULT_LOCALE', '', time() - 3600, DIR_REL . '/'); } $lang = MultilingualSection::getByLocale($_REQUEST['ccmMultilingualSiteDefaultLanguage']); } else { $lang = MultilingualSection::getByID($_REQUEST['ccmMultilingualChooseLanguage']); } if (is_object($lang)) { if (isset($_REQUEST['ccmMultilingualCurrentPageID'])) { $page = Page::getByID($_REQUEST['ccmMultilingualCurrentPageID']); if (!$page->isError()) { $relatedID = $lang->getTranslatedPageID($page); if ($relatedID) { $pc = Page::getByID($relatedID); header('Location: ' . Loader::helper('navigation')->getLinkToCollection($pc, true)); exit; } elseif ($page->isGeneratedCollection()) { $_SESSION['DEFAULT_LOCALE'] = (string) $lang->getLocale(); header('Location: ' . Loader::helper('navigation')->getLinkToCollection($page, true)); exit; }
/** * Receives a page in a different language tree, and tries to return the corresponding page in the current language tree */ public function getTranslatedPageID($page) { $db = Loader::db(); $ids = MultilingualSection::getIDList(); if (in_array($page->getCollectionID(), $ids)) { $cID = $db->GetOne('select cID from MultilingualSections where msLocale = ?', array($this->getLocale())); return $cID; } $mpRelationID = $db->GetOne('select mpRelationID from MultilingualPageRelations where cID = ?', array($page->getCollectionID())); if ($mpRelationID) { $cID = $db->GetOne('select cID from MultilingualPageRelations where mpRelationID = ? and mpLocale = ?', array($mpRelationID, $this->getLocale())); return $cID; } }
public static function setupSiteInterfaceLocalization() { // don't translate dashboard pages $c = Page::getCurrentPage(); if ($c instanceof Page && Loader::helper('section', 'multilingual')->section('dashboard')) { return; } $ms = MultilingualSection::getCurrentSection(); if (is_object($ms)) { $locale = $ms->getLocale(); } else { $locale = DefaultLanguageHelper::getSessionDefaultLocale(); } // change core language to translate e.g. core blocks/themes if (strlen($locale)) { Localization::changeLocale($locale); } // site translations if (is_dir(DIR_LANGUAGES_SITE_INTERFACE)) { if (file_exists(DIR_LANGUAGES_SITE_INTERFACE . '/' . $locale . '.mo')) { $loc = Localization::getInstance(); $loc->addSiteInterfaceLanguage($locale); } } // add package translations if (strlen($locale)) { $ms = MultilingualSection::getByLocale($locale); if ($ms instanceof MultilingualSection) { $pl = PackageList::get(); $installed = $pl->getPackages(); foreach ($installed as $pkg) { if ($pkg instanceof Package) { $pkg->setupPackageLocalization($ms->getLocale()); } } } } }
$class2 = 'icon-select-page'; if (version_compare(APP_VERSION, '5.5.2.2', '>')) { $class1 = 'item-select-list'; $class2 = 'item-select-page'; } $c = Page::getByID($_REQUEST['cID'], 'RECENT'); $cp = new Permissions($c); $pc = Page::getByPath('/dashboard/multilingual'); $pcp = new Permissions($pc); $nav = Loader::helper('navigation'); $ih = Loader::helper('interface/flag', 'multilingual'); if ($cp->canRead() && $pcp->canRead()) { // grab all languages Loader::model('section', 'multilingual'); $mlist = MultilingualSection::getList(); $currentSection = MultilingualSection::getCurrentSection(); $ml[] = $currentSection; foreach ($mlist as $m) { if ($m->getCollectionID() != $currentSection->getCollectionID()) { $ml[] = $m; } } // then loop through them and show if a page exists ?> <ul class="<?php echo $class1; ?> "> <?php foreach ($ml as $m) {
/** Adds the link rel="alternate" hreflang=".." href=".." tag to the specified page. * @param Page $page */ public function addAlternateHrefLang($page) { if ($page || ($page = Page::getCurrentPage())) { if (!$page->isAdminArea()) { if ($lang = MultilingualSection::getBySectionOfSite($page)) { if (!is_array(self::$_allLanguages)) { self::$_allLanguages = MultilingualSection::getList(); } $html = Loader::helper('html'); $navigation = Loader::helper('navigation'); $v = View::getInstance(); if (!$page->isAlias() && $page->cID == $lang->cID) { $isRoot = true; } else { $isRoot = false; } foreach (self::$_allLanguages as $otherLang) { if ($otherLang->msLocale != $lang->msLocale) { if ($isRoot) { $otherPage = $otherLang; } else { $otherPage = $this->getTranslatedPageWithAliasSupport($page, $otherLang, false); } if ($otherPage) { $v->addHeaderItem('<link rel="alternate" hreflang="' . $otherLang->msLocale . '" href="' . $navigation->getLinkToCollection($otherPage) . '" />'); } } } } } } }
<?php if (count($pages) > 0) { ?> <?php echo $pl->displaySummary(); ?> <?php } ?> <table class="ccm-results-list" cellspacing="0" cellpadding="0" border="0" id="ccm-multilingual-page-report-results"> <thead> <tr> <th><?php $sourceMS = MultilingualSection::getByID($sectionID); print $sourceMS->getLanguageText(); echo " (" . $sourceMS->getLocale() . ")"; ?> </th> <?php foreach ($targetList as $sc) { ?> <?php if ($section->getCollectionID() != $sc->getCollectionID()) { ?> <th><?php print $sc->getLanguageText(); echo " (" . $sc->getLocale() . ")"; ?> </th>