public function view() { $this->requireAsset('javascript', 'jquery'); $ml = Section::getList(); $c = \Page::getCurrentPage(); $al = Section::getBySectionOfSite($c); $languages = []; $locale = null; if ($al !== null) { $locale = $al->getLanguage(); } if (!$locale) { $locale = \Localization::activeLocale(); $al = Section::getByLocale($locale); } foreach ($ml as $m) { $languages[$m->getCollectionID()] = $m->getLanguageText($m->getLocale()); } $this->set('languages', $languages); $this->set('languageSections', $ml); $this->set('activeLanguage', $al ? $al->getCollectionID() : null); $dl = $this->app->make('multilingual/detector'); $this->set('defaultLocale', $dl->getPreferredSection()); $this->set('locale', $locale); $this->set('cID', $c->getCollectionID()); }
public function view() { $ll = Core::make('localization/languages'); $cl = Core::make('lists/countries'); $languages = $ll->getLanguageList(); $this->set('pages', Section::getList()); $this->set('languages', $languages); $this->set('countries', $cl->getCountries()); $this->set('ch', Core::make('multilingual/interface/flag')); $this->set('defaultLocale', Config::get('concrete.multilingual.default_locale')); $defaultSourceLanguage = ''; $defaultSourceCountry = ''; $defaultSourceLocale = Config::get('concrete.multilingual.default_source_locale'); if ($defaultSourceLocale) { if (strpos($defaultSourceLocale, '_') === false) { $defaultSourceLanguage = $defaultSourceLocale; } else { list($defaultSourceLanguage, $defaultSourceCountry) = explode('_', $defaultSourceLocale); } } $this->set('defaultSourceLanguage', $defaultSourceLanguage); $this->set('defaultSourceCountry', $defaultSourceCountry); $this->set('redirectHomeToDefaultLocale', Config::get('concrete.multilingual.redirect_home_to_default_locale')); $this->set('useBrowserDetectedLocale', Config::get('concrete.multilingual.use_browser_detected_locale')); $this->set('keepUsersLocale', Config::get('concrete.multilingual.keep_users_locale') ? 1 : 0); }
/** Executes the job. * @throws \Exception Throws an exception in case of errors. * * @return string Returns a string describing the job result in case of success. */ public function run() { Cache::disableAll(); try { $instances = array('navigation' => Core::make('helper/navigation'), 'dashboard' => Core::make('helper/concrete/dashboard'), 'view_page' => PermissionKey::getByHandle('view_page'), 'guestGroup' => Group::getByID(GUEST_GROUP_ID), 'now' => new DateTime('now'), 'ak_exclude_sitemapxml' => CollectionAttributeKey::getByHandle('exclude_sitemapxml'), 'ak_sitemap_changefreq' => CollectionAttributeKey::getByHandle('sitemap_changefreq'), 'ak_sitemap_priority' => CollectionAttributeKey::getByHandle('sitemap_priority')); $instances['guestGroupAE'] = array(GroupPermissionAccessEntity::getOrCreate($instances['guestGroup'])); if (\Core::make('multilingual/detector')->isEnabled()) { $instances['multilingualSections'] = MultilingualSection::getList(); } else { $instances['multilingualSections'] = array(); } $xml = '<?xml version="1.0" encoding="' . APP_CHARSET . '"?>'; $xml .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"'; if ($instances['multilingualSections']) { $xml .= ' xmlns:x="http://www.w3.org/1999/xhtml"'; } $xml .= ' />'; $xmlDoc = new SimpleXMLElement($xml); $rs = Database::get()->query('SELECT cID FROM Pages'); while ($row = $rs->FetchRow()) { self::addPage($xmlDoc, intval($row['cID']), $instances); } $rs->Close(); $event = new \Symfony\Component\EventDispatcher\GenericEvent(); $event->setArgument('xmlDoc', $xmlDoc); Events::dispatch('on_sitemap_xml_ready', $event); $dom = dom_import_simplexml($xmlDoc)->ownerDocument; $dom->formatOutput = true; $addedPages = count($xmlDoc->url); $relName = ltrim(Config::get('concrete.sitemap_xml.file'), '\\/'); $osName = rtrim(DIR_BASE, '\\/') . '/' . $relName; $urlName = rtrim(\Core::getApplicationURL(), '\\/') . '/' . $relName; if (!file_exists($osName)) { @touch($osName); } if (!is_writable($osName)) { throw new \Exception(t('The file %s is not writable', $osName)); } if (!($hFile = @fopen($osName, 'w'))) { throw new \Exception(t('Cannot open file %s', $osName)); } if (!@fwrite($hFile, $dom->saveXML())) { throw new \Exception(t('Error writing to file %s', $osName)); } @fflush($hFile); @fclose($hFile); unset($hFile); return t('%1$s file saved (%2$d pages).', sprintf('<a href="%s" target="_blank">%s</a>', $urlName, preg_replace('/^https?:\\/\\//i', '', $urlName)), $addedPages); } catch (\Exception $x) { if (isset($hFile) && $hFile) { @fflush($hFile); @ftruncate($hFile, 0); @fclose($hFile); $hFile = null; } throw $x; } }
public function on_start() { parent::on_start(); if (\Core::make('multilingual/detector')->isEnabled()) { $list = array(); $this->multilingualSections = Section::getList(); $this->set('multilingualSections', $this->multilingualSections); $this->set('defaultLanguage', $this->getSelectedLanguage()); } }
public function finalizeQuery(QueryBuilder $query) { $query = parent::finalizeQuery($query); $mslist = Section::getList(); $relation = Database::get()->createQueryBuilder(); $relation->select('mpRelationID')->from('MultilingualPageRelations', 'mppr')->where('cID = p.cID')->setMaxResults(1); $query->addSelect('(' . $relation . ') as mpr'); foreach ($mslist as $ms) { $section = Database::get()->createQueryBuilder(); $section->select('count(mpRelationID)')->from('MultilingualPageRelations', 'mppr')->where('mpRelationID = mpr')->andWhere($section->expr()->comparison('mpLocale', '=', $query->createNamedParameter($ms->getLocale()))); $query->addSelect('(' . $section . ') as relationCount' . $ms->getCollectionID()); } return $query; }
public function finalizeQuery(QueryBuilder $query) { $db = Database::connection(); $query = parent::finalizeQuery($query); $mainRelation = $db->createQueryBuilder(); $mainRelation->select('mpr0.cID')->addSelect('MIN(mpr0.mpRelationID) as mpr')->from('MultilingualPageRelations', 'mpr0')->groupBy('mpr0.cID'); $query->addSelect('mppr.mpr')->leftJoin('p', '(' . $mainRelation . ')', 'mppr', 'p.cID = mppr.cID'); $mslist = Section::getList(); foreach ($mslist as $ms) { $cID = (int) $ms->getCollectionID(); $cLocale = (string) $ms->getLocale(); $query->addSelect("count(mppr{$cID}.mpRelationID) as relationCount{$cID}")->leftJoin('mppr', 'MultilingualPageRelations', "mppr{$cID}", "mppr.mpr = mppr{$cID}.mpRelationID AND " . $db->quote($cLocale) . " = mppr{$cID}.mpLocale"); } $query->addGroupBy(['p.cID', 'mppr.mpr']); return $query; }
public function view() { $this->requireAsset('core/sitemap'); $mlist = Section::getList(); $ml = array(); $currentSection = Section::getCurrentSection(); foreach ($mlist as $m) { if ($m->getCollectionID() != $currentSection->getCollectionID()) { $ml[] = $m; } } $this->set('list', $ml); $this->set('currentSection', $currentSection); $this->set('ih', Core::make('multilingual/interface/flag')); $multilingualController = Core::make('\\Concrete\\Controller\\Backend\\Page\\Multilingual'); $multilingualController->setPageObject($this->page); $this->set('multilingualController', $multilingualController); }
public function view() { $this->requireAsset('core/sitemap'); $list = MultilingualSection::getList(); $sections = array(); usort($list, function ($item) { if ($item->getLocale() == \Config::get('concrete.multilingual.default_locale')) { return -1; } else { return 1; } }); foreach ($list as $pc) { $sections[$pc->getCollectionID()] = $pc->getLanguageText() . " (" . $pc->getLocale() . ")"; } $this->set('sections', $sections); $this->set('sectionList', $list); if (!isset($_REQUEST['sectionID']) && count($sections) > 0) { foreach ($sections as $key => $value) { $sectionID = $key; break; } } else { $sectionID = $_REQUEST['sectionID']; } if (!isset($_REQUEST['targets']) && count($sections) > 1) { $i = 0; foreach ($sections as $key => $value) { if ($key != $sectionID) { $targets[$key] = $key; break; } $i++; } } else { $targets = $_REQUEST['targets']; } if (!isset($targets) || !is_array($targets)) { $targets = array(); } $targetList = array(); foreach ($targets as $key => $value) { $targetList[] = MultilingualSection::getByID($key); } $this->set('targets', $targets); $this->set('targetList', $targetList); $this->set('sectionID', $sectionID); $this->set('fh', \Core::make('multilingual/interface/flag')); if (isset($sectionID) && $sectionID > 0) { $pl = new MultilingualPageList(); $pc = \Page::getByID($sectionID); $path = $pc->getCollectionPath(); if (strlen($path) > 1) { $pl->filterByPath($path); } if ($_REQUEST['keywords']) { $pl->filterByName($_REQUEST['keywords']); } $pl->setItemsPerPage(25); if (!$_REQUEST['showAllPages']) { $pl->filterByMissingTargets($targetList); } $pagination = $pl->getPagination(); $this->set('pagination', $pagination); $this->set('pages', $pagination->getCurrentPageResults()); $this->set('section', MultilingualSection::getByID($sectionID)); $this->set('pl', $pl); } }
/** * @param string $stackName * @param int $type * * @return Page */ public static function addStack($stackName, $type = 0) { $data = array(); $parent = Page::getByPath(STACKS_PAGE_PATH); $data = array(); $data['name'] = $stackName; if (!$stackName) { $data['name'] = t('No Name'); } $pagetype = PageType::getByHandle(STACKS_PAGE_TYPE); $page = $parent->add($pagetype, $data); // we have to do this because we need the area to exist before we try and add something to it. Area::getOrCreate($page, STACKS_AREA_NAME); // finally we add the row to the stacks table $db = Database::connection(); $stackCID = $page->getCollectionID(); $v = array($stackName, $stackCID, $type); $db->Execute('insert into Stacks (stName, cID, stType) values (?, ?, ?)', $v); $stack = static::getByID($stackCID); // If the multilingual add-on is enabled, we need to take this stack and copy it into all non-default stack categories. if (Core::make('multilingual/detector')->isEnabled()) { $list = Section::getList(); foreach ($list as $section) { if (!$section->isDefaultMultilingualSection()) { $category = StackCategory::getCategoryFromMultilingualSection($section); if (!is_object($category)) { $category = StackCategory::createFromMultilingualSection($section); } $stack->duplicate($category->getPage()); } } StackList::rescanMultilingualStacks(); } return $stack; }
public function view() { $this->set('pages', Section::getList()); }
<a href="javascript:void(0)" class="btn btn-primary ccm-save-to-file"><?php echo t('Save to file'); ?> </a> </div> <?php } else { if (!is_dir(DIR_LANGUAGES_SITE_INTERFACE) || !is_writable(DIR_LANGUAGES_SITE_INTERFACE)) { ?> <div class="alert alert-warning"><?php echo t('You must create the directory %s and make it writable before you may run this tool. Additionally, all files within this directory must be writable.', DIRNAME_APPLICATION . '/' . DIRNAME_LANGUAGES . '/' . DIRNAME_LANGUAGES_SITE_INTERFACE); ?> </div><?php } $nav = $app->make('helper/navigation'); $pages = \Concrete\Core\Multilingual\Page\Section\Section::getList($site); $defaultSourceLocale = $site->getConfigRepository()->get('multilingual.default_source_locale'); $ch = $app->make('multilingual/interface/flag'); $dh = $app->make('helper/date'); if (count($pages) > 0) { ?> <div class="ccm-dashboard-content-full"> <div class="table-responsive"> <table class="ccm-search-results-table"> <thead> <tr> <th> </th> <th><span><?php echo t('Name'); ?> </span></th>
/** * @param string $stackName * @param int $type * * @return Page */ public static function addStack($stackName, $type = 0, $multilingualStackToReturn = self::MULTILINGUAL_CONTENT_SOURCE_CURRENT) { $return = false; $db = \Database::connection(); if (Core::make('multilingual/detector')->isEnabled()) { $returnFromSection = Stack::getMultilingualSectionFromType($multilingualStackToReturn); $list = Section::getList(); foreach ($list as $section) { $cID = $db->GetOne('select cID from Stacks where stName = ? and stMultilingualSection = ?', array($stackName, $section->getCollectionID())); if (!$cID) { $category = StackCategory::getCategoryFromMultilingualSection($section); if (!is_object($category)) { $category = StackCategory::createFromMultilingualSection($section); } $stack = Stack::addStackToCategory($category->getPage(), $stackName, $type); if (is_object($returnFromSection) && $returnFromSection->getCollectionID() == $section->getCollectionID()) { $return = $stack; } } } StackList::rescanMultilingualStacks(); } else { $parent = \Page::getByPath(STACKS_PAGE_PATH); $return = Stack::addStackToCategory($parent, $stackName, $type); } return $return; }
public function submit() { $extractor = Core::make('multilingual/extractor'); if ($this->post('action') == 'reload') { if (Core::make('token')->validate()) { // First, we look in all the site sources for PHP code with GetText $baseTranslations = $extractor->extractTranslatableSiteStrings(); // $translations contains all of our site translations. $list = Section::getList(); $defaultSourceLocale = Config::get('concrete.multilingual.default_source_locale'); foreach ($list as $section) { /* @var $section \Concrete\Core\Multilingual\Page\Section\Section */ if ($section->getLocale() != $defaultSourceLocale) { $localeTranslations = clone $baseTranslations; /* @var $localeTranslations \Gettext\Translations */ $localeTranslations->setLanguage($section->getLocale()); $localeTranslations->setPluralForms($section->getNumberOfPluralForms(), $section->getPluralsRule()); // now we load the translations that currently exist for each section $extractor->mergeTranslationsWithSectionFile($section, $localeTranslations); $extractor->mergeTranslationsWithCore($section, $localeTranslations); $extractor->mergeTranslationsWithPackages($section, $localeTranslations); $extractor->saveSectionTranslationsToFile($section, $localeTranslations); // now that we've updated the translation file, we take all the translations and // we insert them into the database so we can update our counts, and give the users // a web interface $extractor->saveSectionTranslationsToDatabase($section, $localeTranslations); } } $this->redirect('/dashboard/system/multilingual/translate_interface', 'reloaded'); } else { $this->error->add(Core::make('token')->getErrorMessage()); } } if ($this->post('action') == 'export') { if (Core::make('token')->validate()) { $defaultSourceLocale = Config::get('concrete.multilingual.default_source_locale'); $list = Section::getList(); foreach ($list as $section) { if ($section->getLocale() != $defaultSourceLocale) { $translations = $section->getSectionInterfaceTranslations(); $extractor->mergeTranslationsWithSectionFile($section, $translations); $extractor->saveSectionTranslationsToFile($section, $translations); } } \Localization::clearCache(); $this->redirect('/dashboard/system/multilingual/translate_interface', 'exported'); } else { $this->error->add(Core::make('token')->getErrorMessage()); } } $this->view(); }
/** * @return bool */ public function delete() { if ($this->getStackType() == static::ST_TYPE_GLOBAL_AREA) { GlobalArea::deleteByName($this->getStackName()); } if ($this->isNeutralStack()) { foreach (Section::getList() as $section) { $localized = $this->getLocalizedStack($section); if ($localized !== null) { $localized->delete(); } } } parent::delete(); $db = Database::connection(); return $db->Execute('delete from Stacks where cID = ?', array($this->getCollectionID())); }