コード例 #1
0
 public function quoteString($oTemplateIdentifier, &$iFlags)
 {
     $iFlags |= Template::NO_HTML_ESCAPE;
     if (!$oTemplateIdentifier->getValue()) {
         return $oTemplateIdentifier->hasParameter('defaultValue') ? $oTemplateIdentifier->getParameter('defaultValue') : null;
     }
     $sLocale = LocaleUtil::getLocaleId();
     $sStyle = 'double';
     if ($oTemplateIdentifier->hasParameter('style')) {
         $sStyle = $oTemplateIdentifier->getParameter('style');
     }
     $bAlternate = $oTemplateIdentifier->hasParameter('alternate') && $oTemplateIdentifier->getParameter('alternate') === 'true';
     if (StringUtil::startsWith($sLocale, 'en_')) {
         if ($sStyle === 'single') {
             return "‘{$oTemplateIdentifier->getValue()}’";
         }
         return "“{$oTemplateIdentifier->getValue()}”";
     }
     if (StringUtil::startsWith($sLocale, 'fr_') || $sLocale === 'de_CH') {
         if ($sStyle === 'single') {
             return "‹{$oTemplateIdentifier->getValue()}›";
         }
         return "«{$oTemplateIdentifier->getValue()}»";
     }
     if (StringUtil::startsWith($sLocale, 'de_') || StringUtil::startsWith($sLocale, 'nl_')) {
         if ($bAlternate) {
             if ($sStyle === 'single') {
                 return "›{$oTemplateIdentifier->getValue()}‹";
             }
             return "»{$oTemplateIdentifier->getValue()}«";
         }
         if ($sStyle === 'single') {
             return "‚{$oTemplateIdentifier->getValue()}‘";
         }
         return "„{$oTemplateIdentifier->getValue()}“";
     }
     if ($sStyle === 'single') {
         return "'{$oTemplateIdentifier->getValue()}'";
     }
     return '"' . $oTemplateIdentifier->getValue() . '"';
 }
コード例 #2
0
 public function testGetLocaleIdDE()
 {
     $_SERVER['HTTP_ACCEPT_LANGUAGE'] = "en-US,de-AT";
     $this->assertSame("de_AT", LocaleUtil::getLocaleId("de"));
 }
コード例 #3
0
ファイル: Template.php プロジェクト: rapila/cms-base
 /**
  * @param string $sTemplateName template name
  * @param string|array $mPath template dir path
  * @param boolean $bTemplateIsTextOnly template is text only (name will be used as content, path can be used to decide origin [null=filesystem, "db"=database, "browser"=request])
  * @param boolean $bDirectOutput template will output directly to stream? only one the main template should have set this to true
  * @param string $sTargetEncoding target encoding. usually the browser encoding. text will be converted from the source encoding (default is utf-8, at the moment only changed when using text-only templates) into the target encoding
  * @param string $sRootTemplateName root template name, used internally when including subtemplates, default=null
  * @param int $iDefaultFlags default flags, will be ORed to the flags you provide when calling {@link replaceIdentifier()} and {@link replaceIdentifierMultiple()}
  */
 public function __construct($sTemplateName, $mPath = null, $bTemplateIsTextOnly = false, $bDirectOutput = false, $sTargetEncoding = null, $sRootTemplateName = null, $iDefaultFlags = 0)
 {
     if ($sTargetEncoding === null) {
         $sTargetEncoding = Settings::getSetting("encoding", "browser", "utf-8");
     }
     if ($mPath === "db") {
         $this->sEncoding = Settings::getSetting("encoding", "db", "utf-8");
     } else {
         if ($mPath === "browser") {
             $this->sEncoding = Settings::getSetting("encoding", "browser", "utf-8");
         }
     }
     if ($mPath === null || $mPath === "db" || $mPath === "browser") {
         $mPath = DIRNAME_TEMPLATES;
     }
     $sTemplateText = "";
     $this->aTemplateContents = array();
     $oCache = null;
     $bCacheIsCurrent = false;
     if ($bTemplateIsTextOnly) {
         $sTemplateText = $sTemplateName;
         $sTemplateName = $sRootTemplateName;
     } else {
         if ($sTemplateName instanceof FileResource) {
             $oPath = $sTemplateName;
             $aPath = explode('/', $oPath->getRelativePath());
             $sTemplateName = $oPath->getFileName(self::$SUFFIX);
         } else {
             $aPath = ResourceFinder::parsePathArguments(null, $mPath, $sTemplateName . self::$SUFFIX);
             $oPath = ResourceFinder::findResourceObject($aPath);
         }
         if ($oPath === null) {
             throw new Exception("Error in Template construct: Template file " . implode("/", $aPath + array($sTemplateName . self::$SUFFIX)) . " does not exist");
         }
         if (Settings::getSetting('general', 'template_caching', false)) {
             $oCache = new Cache($oPath->getFullPath() . "_" . LocaleUtil::getLocaleId() . "_" . $sTargetEncoding . "_" . $sRootTemplateName, DIRNAME_TEMPLATES);
             $bCacheIsCurrent = $oCache->entryExists() && !$oCache->isOutdated($oPath->getFullPath());
         }
         if (!$bCacheIsCurrent) {
             $sTemplateText = file_get_contents($oPath->getFullPath());
         }
         $mPath = $aPath;
         array_pop($mPath);
     }
     if ($sRootTemplateName === null && !$bTemplateIsTextOnly) {
         $sRootTemplateName = $sTemplateName;
     }
     if ($sRootTemplateName === null) {
         $sRootTemplateName = '';
     }
     $this->sTemplateName = $sRootTemplateName;
     if (StringUtil::startsWith($sTemplateName, 'e_mail_') || StringUtil::startsWith($sTemplateName, 'email_')) {
         $iDefaultFlags |= self::NO_HTML_ESCAPE;
     } else {
         if (StringUtil::endsWith($sTemplateName, '.js') || StringUtil::endsWith($sTemplateName, '.css')) {
             $iDefaultFlags |= self::NO_HTML_ESCAPE | self::ESCAPE;
         } else {
             if (StringUtil::endsWith($this->sTemplateName, '.js') || StringUtil::endsWith($this->sTemplateName, '.css')) {
                 //I’m not a js template but my parent is
                 $iDefaultFlags &= ~(self::NO_HTML_ESCAPE | self::ESCAPE);
             }
         }
     }
     $this->mPath = $mPath;
     $this->oSpecialTemplateIdentifierActions = new SpecialTemplateIdentifierActions($this);
     $this->iDefaultFlags = $iDefaultFlags;
     if ($bCacheIsCurrent) {
         $this->aTemplateContents = $oCache->getContentsAsVariable();
         foreach ($this->aTemplateContents as &$mContent) {
             if ($mContent instanceof TemplatePart) {
                 $mContent->setTemplate($this);
             }
         }
     } else {
         if (is_array($sTemplateText)) {
             $this->aTemplateContents = $sTemplateText;
         } else {
             $sTemplateText = StringUtil::encode($sTemplateText, $this->sEncoding, $sTargetEncoding);
             $this->aTemplateContents = self::templateContentsFromText($sTemplateText, $this);
             $this->replaceConditionals(true);
             $this->renderDirectOutput();
         }
         $this->replaceSpecialIdentifiersOnStart();
         if ($oCache !== null) {
             $oCache->setContents($this->aTemplateContents);
         }
     }
     $this->sEncoding = $sTargetEncoding;
     $this->bDirectOutput = $bDirectOutput;
     $this->replaceConditionals(true);
     $this->renderDirectOutput();
 }
コード例 #4
0
ファイル: UtilLocaleTests.php プロジェクト: rapila/cms-base
 public function testGetLocaleId()
 {
     Session::getSession()->resetAttribute("preferred_user_language");
     $_SERVER['HTTP_ACCEPT_LANGUAGE'] = "en,en-us;q=0.7,en-uk;q=0.3";
     $this->assertSame("en_EN", LocaleUtil::getLocaleId("en"));
 }