Example #1
0
 /**
  * @override
  */
 function PreRender($args = array())
 {
     if (!$this->CultureInfo) {
         $this->SetCulture(Localization::detectCulture());
     }
     if (isset($this->value)) {
         $this->value = get_class_simple($this) == "uiDatePicker" ? $this->CultureInfo->FormatDate($this->value, DateTimeFormat::DF_SHORTDATE) : $this->CultureInfo->FormatDateTime($this->value);
     }
     if (isset($this->Options['defaultDate'])) {
         $this->Options['defaultDate'] = get_class_simple($this) == "uiDatePicker" ? $this->CultureInfo->FormatDate($this->Options['defaultDate'], DateTimeFormat::DF_SHORTDATE) : $this->CultureInfo->FormatDateTime($this->Options['defaultDate']);
     }
     parent::PreRender($args);
 }
 /**
  * @override
  */
 function PreRender($args = array())
 {
     if (!$this->CultureInfo) {
         $this->SetCulture(Localization::detectCulture());
     }
     if (isset($this->value)) {
         $this->value = get_class_simple($this) == "uiDatePicker" ? $this->CultureInfo->FormatDate($this->value, DateTimeFormat::DF_SHORTDATE) : $this->CultureInfo->FormatDateTime($this->value);
     }
     if (isset($this->Options['defaultDate'])) {
         $this->Options['defaultDate'] = get_class_simple($this) == "uiDatePicker" ? $this->CultureInfo->FormatDate($this->Options['defaultDate'], DateTimeFormat::DF_SHORTDATE) : $this->CultureInfo->FormatDateTime($this->Options['defaultDate']);
     }
     $this->script("\$('#{$this->id}').{$this->init_code}(" . system_to_json($this->Options) . ");");
     parent::PreRender($args);
 }
 /**
  * @param mixed $current_language_code Currently selected language
  * @param type $current_region_code Currently selected region
  */
 function __initialize($current_language_code = false, $current_region_code = false)
 {
     parent::__initialize();
     $this->script("Locale_Settings_Init();");
     $this->setData('role', 'region');
     $this->setData('controller', buildQuery($this->id));
     if ($current_language_code) {
         if ($current_language_code instanceof CultureInfo) {
             $lang = $current_language_code->ResolveToLanguage();
         } else {
             $lang = Localization::getLanguageCulture($current_language_code);
         }
         if (!$lang) {
             $lang = Localization::detectCulture()->ResolveToLanguage();
         }
         $regions = $lang->GetRegions(false);
         if (!$current_region_code) {
             $current_region_code = $lang->DefaultRegion()->Code;
         }
     } else {
         $regions = Localization::get_all_regions(false);
     }
     if ($current_region_code) {
         if ($current_region_code instanceof CultureInfo) {
             $this->SetCurrentValue($current_region_code->DefaultRegion()->Code);
         } else {
             $this->SetCurrentValue($current_region_code);
         }
     }
     if (count($regions) > 0) {
         $cc = current_controller(false);
         $translations_active = $cc instanceof Renderable && $cc->_translate;
         $sorted = array();
         foreach ($regions as $reg) {
             if (!$reg) {
                 continue;
             }
             $code = $reg->Code;
             if ($translations_active) {
                 $sorted[$code] = array("name" => tds("TXT_COUNTRY_" . strtoupper($code), $reg->EnglishName), "code", $code);
             } else {
                 $sorted[$code] = array("name" => $reg->EnglishName, "code", $code);
             }
         }
         uasort($sorted, __CLASS__ . "::compareCountryNames");
         foreach ($sorted as $code => $item) {
             $this->AddOption($code, $item['name']);
         }
     }
 }
 /**
  * @param mixed $current_language_code Currently selected language
  */
 function __initialize($current_language_code = false)
 {
     parent::__initialize();
     $this->script("Locale_Settings_Init();");
     $this->setData('role', 'language');
     if ($current_language_code) {
         if ($current_language_code instanceof CultureInfo) {
             $lang = $current_language_code->ResolveToLanguage();
         } else {
             $lang = Localization::getLanguageCulture($current_language_code);
         }
         if (!$lang) {
             $lang = Localization::detectCulture()->ResolveToLanguage();
         }
         $this->SetCurrentValue($lang->Code);
     }
     foreach (getAvailableLanguages() as $code) {
         $lang = Localization::getLanguageCulture($code);
         $this->AddOption($code, "{$lang->NativeName} ({$lang->EnglishName})");
     }
 }
Example #5
0
/**
 * Detects the users supposed language.
 * 
 * Uses <Localization::detectCulture> to detect the users language.
 * @return string ISO2 code of detected language
 */
function detect_language()
{
    global $CONFIG;
    if (!$CONFIG['translation']['detect_ci_callback']) {
        $ci = Localization::detectCulture();
        $ci = $ci->ResolveToLanguage();
    } else {
        $ci = $CONFIG['translation']['detect_ci_callback']();
    }
    $GLOBALS['current_language'] = $ci instanceof CultureInfo ? $ci->Iso2 : $ci;
    return $GLOBALS['current_language'];
}
Example #6
0
 /**
  * @override
  */
 function WdfRender()
 {
     if (!$this->get('isrtl') && system_is_module_loaded('localization')) {
         $ci = Localization::detectCulture();
         if ($ci->IsRTL) {
             $this->set("isrtl", " dir='rtl'");
         }
     }
     $res = $this->__collectResources();
     $this->js = array_reverse($this->js, true);
     foreach (array_reverse($res) as $r) {
         if (starts_with(pathinfo($r, PATHINFO_EXTENSION), 'css')) {
             $this->addCss($r);
         } else {
             $this->addjs($r);
         }
     }
     $this->js = array_reverse($this->js, true);
     $this->set("css", $this->css);
     $this->set("js", $this->js);
     $this->set("meta", $this->meta);
     $this->set("content", $this->_content);
     return parent::WdfRender();
 }
 /**
  * Checks a given array for data for this and updates another array accordingly
  * 
  * This is kind of internal, so will not be documented further. Only that it ensures typed data in the $args argument
  * from the $data argument. We will most likely clean this procedure up in the future.
  * @param array $data Combined request data
  * @param array $args resulting typed values
  * @return boolean|string true if everything went fine, an error string if not
  */
 function UpdateArgs($data, &$args)
 {
     global $CONFIG;
     if ($CONFIG['requestparam']['ignore_case']) {
         $name = strtolower($this->Name);
         foreach ($data as $k => $v) {
             unset($data[$k]);
             $data[strtolower($k)] = $v;
         }
     } else {
         $name = $this->Name;
     }
     if (isset($GLOBALS['routing_args']) && count($GLOBALS['routing_args']) > 0 && !isset($data[$name])) {
         $data[$name] = array_shift($GLOBALS['routing_args']);
     }
     if (!isset($data[$name])) {
         if (!is_null($this->Default)) {
             $args[$this->Name] = $this->Default;
             return true;
         }
         $args[$this->Name] = null;
         return 'missing';
     }
     if (!isset($GLOBALS['request_param_detected_ci'])) {
         if (isset($CONFIG['requestparam']['ci_detection_func']) && function_exists($CONFIG['requestparam']['ci_detection_func'])) {
             $GLOBALS['request_param_detected_ci'] = $CONFIG['requestparam']['ci_detection_func']();
         } else {
             $GLOBALS['request_param_detected_ci'] = Localization::detectCulture();
         }
     }
     $ci = $GLOBALS['request_param_detected_ci'];
     if (!is_null($this->Type)) {
         switch (strtolower($this->Type)) {
             case 'object':
                 if (!in_object_storage($data[$name])) {
                     return 'object not found';
                 }
                 $args[$this->Name] = restore_object($data[$name]);
                 return true;
             case 'array':
             case 'file':
                 if (isset($data[$name]) && is_array($data[$name])) {
                     $args[$this->Name] = $data[$name];
                 }
                 return true;
             case 'string':
             case 'text':
                 if ($this->Filter) {
                     $args[$this->Name] = filter_var($data[$name], $this->Filter, FILTER_FLAG_NO_ENCODE_QUOTES);
                 } else {
                     $args[$this->Name] = $data[$name];
                 }
                 return true;
             case 'email':
                 $args[$this->Name] = filter_var($data[$name], FILTER_SANITIZE_EMAIL);
                 return true;
             case 'url':
             case 'uri':
                 $args[$this->Name] = filter_var($data[$name], FILTER_SANITIZE_URL);
                 return true;
             case 'int':
             case 'integer':
                 if (intval($data[$name]) . "" != $data[$name]) {
                     //						if( floatval($data[$name])."" != $data[$name] )
                     return 'invalid int value';
                 }
                 $args[$this->Name] = intval($data[$name]);
                 return true;
             case 'float':
             case 'double':
             case 'currency':
                 if ($data[$name] . "" == "" && $this->IsOptional()) {
                     $data[$name] = $this->Default;
                     $args[$this->Name] = $this->Default;
                     return true;
                 }
                 //					if( isset($CONFIG['localization']['float_conversion']) )
                 //						$data[$name] = call_user_func($CONFIG['localization']['float_conversion'],$data[$name]);
                 //					else if( !is_float(floatval($data[$name])) )
                 //						$data[$name] = false;
                 if (strtolower($this->Type) == 'currency') {
                     $data[$name] = $ci->CurrencyFormat->StrToCurrencyValue($data[$name]);
                 } else {
                     $data[$name] = $ci->NumberFormat->StrToNumber($data[$name]);
                 }
                 if ($data[$name] === false) {
                     return 'invalid float value';
                 } else {
                     $args[$this->Name] = $data[$name];
                 }
                 return true;
             case 'bool':
             case 'boolean':
                 if ($data[$name] == '' || $data[$name] == '0' || strtolower($data[$name]) == "false") {
                     $args[$this->Name] = false;
                 } else {
                     $args[$this->Name] = true;
                 }
                 return true;
         }
         return 'wrong type';
     }
     $args[$this->Name] = $data[$name];
     return true;
 }