Example #1
0
            $I18N->redirectTo($Tool->generatePermalink(array('msg' => 3)), 302);
            break;
    }
}
/**
 * Custom return to
 * -------------------------------------------------
 */
// Tools can pass returnto and returntoquery parameters
// to redirect visitors back to them after setting, changing
// or doing something (eg. clearcookies, renewcookies or prefset)
if ($I18N->isRedirecting()) {
    $returnTo = $kgReq->getVal('returnto');
    $returnToQuery = $kgReq->getVal('returntoquery');
    if (IntuitionUtil::nonEmptyStr($returnTo)) {
        if (IntuitionUtil::nonEmptyStr($returnToQuery)) {
            $returnToQuery = '?' . urldecode($returnToQuery);
        } else {
            $returnToQuery = '';
        }
        $I18N->redirectTo("//{$_SERVER['SERVER_NAME']}{$returnTo}{$returnToQuery}", 302);
    }
}
$I18N->doRedirect();
/**
 * Main content output
 * -------------------------------------------------
 */
$Tool->setLayout('header', array('captionHtml' => $I18N->msg('fullname')));
$Tool->addOut('<div class="container">');
$Tool->addOut(_g('welcome'), 'h2');
Example #2
0
 /**
  * Check language choice tree in the following order:
  * - First: Construct override
  * - Second: Parameter override
  * - Third: Saved cookie
  * - Fourth: Preferences from Accept-Language header
  * - Fifth: A language which is a prefix for one of the
  * Accept-Language preferences.
  * - Sixth: English (default stays)
  *
  * @return true
  */
 protected function initLangSelect($option)
 {
     $set = false;
     if (isset($option) && !empty($option)) {
         $set = $this->setLang($option);
     }
     if (!$set && $this->getUseRequestParam() === true && isset($_GET[$this->paramNames['userlang']])) {
         $set = $this->setLang($_GET[$this->paramNames['userlang']]);
     }
     if (!$set && isset($_COOKIE[$this->cookieNames['userlang']])) {
         $set = $this->setLang($_COOKIE[$this->cookieNames['userlang']]);
     }
     if (!$set) {
         $acceptableLanguages = IntuitionUtil::getAcceptableLanguages();
         $availableLanguages = $this->getAvailableLangs();
         foreach ($acceptableLanguages as $acceptLang => $qVal) {
             if ($acceptLang === '*') {
                 /**
                  * We pick the first available language which is not in $acceptableLanguages.
                  * The special * range matches every tag not matched by any other range.
                  * Other language codes in $acceptableLanguages will either have a lower q-value,
                  * or be missing from availableLanguages.
                  * The order will be the one in the i18n file: en, af, ar...
                  */
                 foreach ($availableLanguages as $langCode => $langName) {
                     if (!isset($acceptableLanguages[$langCode])) {
                         $n = strstr($langCode, '-');
                         // Assumption: We won't have translations for languages with more than
                         // 1 dashe on the language tag
                         if ($n !== false && !isset($acceptableLanguages[substr($langCode, 0, $n - 1)])) {
                             // if we have non-Chinese translations, zh-hans should not be
                             // picked for "fr,*;q=0.3,zh;q=0.1".
                             continue;
                         }
                         $set = $this->setLang($langCode);
                         break;
                     }
                 }
                 if ($set) {
                     break;
                 }
             } elseif (isset($availableLanguages[$acceptLang])) {
                 $set = $this->setLang($acceptLang);
                 break;
             }
         }
     }
     /* From this point on, we are choosing amongst languages with a $qVal of 0 */
     if (!$set) {
         /**
          * Some browsers show (apparently by default) only a tag,
          * such as "ru-RU", "fr-FR" or "es-mx".
          * This is broken behavior! The browser should be providing
          * appropriate guidance.
          * Providing only a full tag is doing a disservice.
          * See RFC 2616 section 1.4 - http://tools.ietf.org/html/rfc2616#page-105
          */
         foreach ($acceptableLanguages as $acceptLang => $qVal) {
             if (!$qVal) {
                 continue;
             }
             while (($n = strstr($acceptLang, '-')) !== false) {
                 $acceptLang = substr($acceptLang, 0, $n - 1);
                 if (isset($availableLanguages[$acceptLang])) {
                     $set = $this->setLang($acceptLang);
                     break 2;
                 }
             }
         }
     }
     if (!$set) {
         $set = $this->setLang('en');
     }
     return $set;
 }
Example #3
0
/* Config */
require_once 'demoBase.php';
/* Demonstration */
// 1) Init
$I18N = new Intuition('general');
// 2) Do it
// Simple parentheses
echo $I18N->parentheses('hello');
// Variables
echo '<br/>' . $I18N->msg('toolversionstamp', array('variables' => array('1.0', $I18N->dateFormatted('2001-01-15'))));
// msgExists
echo '<br/>msgExists: ';
var_dump($I18N->msgExists('welcome'));
var_dump($I18N->msgExists('foobar'));
// nonEmptyStr
echo '<br/>nonEmptyStr: ';
var_dump(IntuitionUtil::nonEmptyStr('one'));
// nonEmptyStrs
echo '<br/>nonEmptyStrs: ';
var_dump(IntuitionUtil::nonEmptyStrs('one', '', 'three'));
var_dump(IntuitionUtil::nonEmptyStrs('one', 'three'));
// GetAcceptableLanguages
$acceptLang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : '';
echo "<br/>getAcceptableLanguages: (default: \$_SERVER['HTTP_ACCEPT_LANGUAGE']: " . htmlspecialchars($acceptLang) . "):<br/>";
var_dump(IntuitionUtil::getAcceptableLanguages($acceptLang));
$acceptLang = 'nl-be,nl;q=0.7,en-us,en;q=0.3';
echo "<br/>getAcceptableLanguages: ( '{$acceptLang}' ):<br/>";
var_dump(IntuitionUtil::getAcceptableLanguages($acceptLang));
/* View source */
closeDemo(__FILE__);
Example #4
0
 private function gender($user, $parameters, $msg)
 {
     switch (count($parameters)) {
         case 0:
             $this->addParseError("{{GENDER:}} with no variants");
             return '';
         case 1:
             return $parameters[0];
         case 2:
             return IntuitionUtil::tag($parameters[0], 'span', array('class' => 'gender-male gender-neutral')) . IntuitionUtil::tag($parameters[1], 'span', array('class' => 'gender-female'));
         default:
             $this->addParseError("{{GENDER:}} given too many variants");
         case 3:
             return IntuitionUtil::tag($parameters[2], 'span', array('class' => 'gender-neutral')) . IntuitionUtil::tag($parameters[0], 'span', array('class' => 'gender-male')) . IntuitionUtil::tag($parameters[1], 'span', array('class' => 'gender-female'));
     }
 }
Example #5
0
 /**
  * Given a text already html-escaped which contains wiki links, convert them to html.
  * @param $text
  * @param $articlePath
  * @return string
  */
 public static function parseWikiLinks($text, $articlePath)
 {
     self::$articlePath = $articlePath;
     return preg_replace_callback('/\\[\\[:?([^]|]+)(?:\\|([^]]*))?\\]\\]/', 'self::parseWikiLinkArray', $text);
 }
Example #6
0
 /**
  * @dataProvider provideAcceptLanguages
  */
 public function testGetAcceptableLanguages($data, $result, $message)
 {
     $this->assertEquals(IntuitionUtil::getAcceptableLanguages($data), $result, $message);
 }