/** * {@inheritdoc} */ public function bindTextDomain($textDomain, $codeSet = null) { $this->bendTextDomains[$textDomain] = array(); $textDomainDir = bindtextdomain($textDomain, $this->directory); $translationFileDir = $textDomainDir . DIRECTORY_SEPARATOR . StringUtils::beforeFirst(setlocale(LC_MESSAGES, '0'), '.') . DIRECTORY_SEPARATOR . 'LC_MESSAGES'; $moFilePath = $translationFileDir . DIRECTORY_SEPARATOR . $textDomain . '.mo'; $poFilePath = $translationFileDir . DIRECTORY_SEPARATOR . $textDomain . '.po'; if (file_exists($moFilePath) === true) { $this->bendTextDomains[$textDomain]['file_path'] = $moFilePath; $this->bendTextDomains[$textDomain]['type'] = 'mo'; } elseif (file_exists($poFilePath) === true && $this->poParserInterface instanceof PoParserInterface === true) { $this->bendTextDomains[$textDomain]['file_path'] = $poFilePath; $this->bendTextDomains[$textDomain]['type'] = 'po'; $this->bendTextDomains[$textDomain]['plural_expr'] = false; $this->bendTextDomains[$textDomain]['entries'] = $this->poParserInterface->extract($poFilePath); $this->bendTextDomains[$textDomain]['plural_expr'] = '$' . $this->defaultPluralRule . ';'; // Default plural rule $this->bendTextDomains[$textDomain]['plurals'] = 2; if (isset($this->bendTextDomains[$textDomain]['entries']['']) === true) { foreach ($this->bendTextDomains[$textDomain]['entries']['']['msgstr'] as $meta) { if (preg_match('/Plural-Forms:\\s+nplurals=(\\d+);\\s+(plural=[^;]+)/', $meta, $matches) === 0) { continue; } $this->bendTextDomains[$textDomain]['plurals'] = (int) $matches[1]; $this->bendTextDomains[$textDomain]['plural_expr'] = '$' . $matches[2] . ';'; } } } else { return; } $textDomainCodeSet = $codeSet !== null ? $codeSet : $this->defaultCodeSet; if (bind_textdomain_codeset($textDomain, $textDomainCodeSet) === $textDomainCodeSet) { $this->bendTextDomains[$textDomain]['code_set'] = $textDomainCodeSet; } }
public function testBeforeFirst() { $this->assertSame(StringUtils::beforeFirst('foo/bar', '/'), 'foo', 'Test 1'); $this->assertSame(StringUtils::beforeFirst('/bar', '/'), '', 'Test 2'); }
/** * @return HttpResponse * @throws CMSException * @throws HttpException * @throws \Exception */ public function restoreElementAjax() { list($elementType, $elementID, $elementPageID) = explode('-', $this->httpRequest->getVar('module', 'strip_tags')); $revisionFile = $this->httpRequest->getVar('revision', 'strip_tags'); $cmsPage = $this->pageModel->getPageByID($elementPageID); $moduleModel = new ModuleModel($this->db); $modInstance = $moduleModel->getElementInstanceByID($elementID, $cmsPage); try { $this->db->setListenersMute(true); $this->db->beginTransaction(); $revisionControl = new RevisionControl($this->db); $revisionControl->restoreFromFile($revisionFile); $fileNameParts = explode('.', StringUtils::afterLast($revisionFile, '/')); $this->updateElementRevision($modInstance, $fileNameParts[2]); $this->db->commit(); $this->db->setListenersMute(false); } catch (\Exception $e) { $this->db->setListenersMute(false); $this->db->rollBack(); $this->logger->error('Could not restore element ' . $e->getMessage()); return new HttpResponse(500, 'Could not restore element: ' . $e->getMessage()); } // RENDER ELEMENT AGAIN, SEND BACK if ($modInstance instanceof CmsElementSettingsLoadable) { /** @var CmsElement $modInstance */ $moduleModel->reloadSettings($modInstance, $cmsPage); } $referrerPath = StringUtils::beforeFirst($this->httpRequest->getVar('referrer', 'strip_tags'), '?'); $httpRequestFrontend = clone $this->httpRequest; $httpRequestFrontend->setPath($referrerPath); $httpRequestFrontend->setRequestMethod('GET'); $frontendController = new FrontendController($this->core, $httpRequestFrontend, $this->route); $frontendController->deliverCMSPage(); // @TODO render and replace parent module of this one $newModuleHtml = $modInstance->render($frontendController, $this->moduleView); return new HttpResponse(200, $newModuleHtml); }