public function getLocale()
 {
     $locale = $this->factory->getStoredOptions('locale');
     if (!$locale) {
         return I2CE_Locales::getPreferredLocale();
     } else {
         return $locale;
     }
 }
 public function displayValues($contentNode, $trasient_options, $action)
 {
     if (!($mainNode = $this->template->appendFileByNode('locale_' . $action . '.html', 'span', $contentNode) instanceof DOMNode)) {
         return false;
     }
     $this->template->setDisplayDataImmediate('displayName', $this->getDisplayName());
     $this->template->setDisplayDataImmediate('description', $this->getDescription());
     $this->template->setDisplayDataImmediate('locale_default', I2CE_Locales::DEFAULT_LOCALE, $mainNode);
     if (($pos = strpos($this->name, '_')) !== false) {
         $lang = substr($this->name, 0, $pos);
     } else {
         $lang = $this->name;
     }
     $this->template->setDisplayDataImmediate('locale_language', $lang, $mainNode);
     $this->template->setDisplayDataImmediate('resolution', implode(',', I2CE_Locales::ensureValidResolution($this->name, $this->storage->getAsArray('resolution'))), $mainNode);
     if ($action === 'edit') {
         $this->renameInputs('resolution', $mainNode);
     }
     return true;
 }
Esempio n. 3
0
 public static function dumpCacheFileLocation($prefix, $file_name)
 {
     if (!function_exists('apc_fetch')) {
         return false;
     }
     $locales = I2CE_Locales::getPreferredLocales();
     foreach ($locales as $locale) {
         $file_loc = apc_fetch("I2CE_Dumper_{$prefix}_Location:{$locale}:{$file_name}");
         if ($file_loc) {
             break;
         }
     }
     if (!$file_loc) {
         return false;
     }
     $headers = apc_fetch("I2CE_Dumper_{$prefix}_Headers:{$file_name}");
     if (!$headers) {
         return false;
     }
     $cacheTime = apc_fetch("I2CE_Dumper_{$prefix}_CacheTime");
     return self::dumpContents($file_loc, $headers, $cacheTime);
 }
 public function __construct()
 {
     parent::__construct();
     $this->date_pickers = array();
     if (class_exists('IntlDateFormatter')) {
         $locale = I2CE_Locales::getPreferredLocale();
         $config = I2CE::getConfig()->modules->DatePicker;
         $intl_setup = false;
         $config->setIfIsSet($intl_setup, "intl_setup/{$locale}");
         if (!$intl_setup) {
             $formatter = array('months' => new IntlDateFormatter($locale, null, null, 'UTC', null, 'MMMM'), 'days' => new IntlDateFormatter($locale, null, null, 'UTC', null, 'EEEE'));
             foreach (self::$intl_times as $type => $times) {
                 foreach ($times as $idx => $time) {
                     if (!$config->is_translated($locale, "options/{$type}/{$idx}")) {
                         $config->setTranslatable("options/{$type}/{$idx}");
                         $config->setTranslation($locale, $formatter[$type]->format($time), "options/{$type}/{$idx}");
                     }
                 }
             }
         }
         $config->intl_setup->{$locale} = 1;
     }
 }
Esempio n. 5
0
 public static function setSitePreferredLocale($locale)
 {
     $locale = self::ensureSelectableLocale($locale, false);
     self::$preferred_locale = $locale;
     I2CE::getConfig()->__set("/locales/preferred_locale", $locale);
     return $locale;
 }
Esempio n. 6
0
 /**
  * Magic method to get user details
  * @param string $detail
  * @returns mixed. false on failure
  */
 public function __get($detail)
 {
     if (array_key_exists($detail, $this->details)) {
         if ($detail == 'locale') {
             return I2CE_Locales::ensureSelectableLocale($this->details['locale']);
         } else {
             return $this->details[$detail];
         }
     } else {
         if ($detail == 'locale') {
             return $this->getPreferedLocale();
         } else {
             return false;
         }
     }
 }
 public function processValues($vals)
 {
     $desired_locales = array();
     if (array_key_exists('def_locale', $vals)) {
         $desired_locales[] = $vals['def_locale'];
     }
     if (array_key_exists('new_locale', $vals)) {
         $desired_locales[] = $vals['new_locale'];
     }
     $success = true;
     foreach ($desired_locales as $locale) {
         if (!$locale) {
             continue;
         }
         if (!preg_match('/^(\\w+)_(\\w+)$/', $locale, $matches)) {
             $msg = "Invalid Locale specified";
             $this->userMessage($msg, 'notice', false);
             I2CE::raiseError($msg);
             $success = false;
             continue;
         }
         $locale = strtolower($matches[1]) . '_' . strtoupper($matches[2]);
         $locales = I2CE_Locales::validateLocales($this->getChildNames());
         if (!$locale) {
             $msg = "Invalid Locale specified";
             $this->userMessage($msg, 'notice', false);
             I2CE::raiseError($msg);
             $success = false;
             continue;
         }
         if (in_array($locale, $locales)) {
             $msg = "Locale {$locale} is already used";
             $this->userMessage($msg, 'notice', false);
             I2CE::raiseError($msg);
             continue;
         }
         $child = $this->getChild($locale, true);
         if (!$child instanceof I2CE_Swiss_Locale) {
             $msg = "Could not add locale {$locale}";
             $this->userMessage($msg, 'notice', false);
             $success = false;
             continue;
         }
     }
     return $success;
 }
 protected function actionTasksSave()
 {
     if (count($this->request_remainder) == 0) {
         //adding new task
         if (!$this->post_exists('task_short_name')) {
             $this->userMessage("No task short name set", 'notice', false);
             return;
         }
         $task = $this->post('task_short_name');
         if (!$task || !I2CE_MagicDataNode::checkKey($task) || I2CE::getConfig()->__isset("/I2CE/tasks/task_description/{$task}") || I2CE::getConfig()->__isset("/I2CE/tasks/task_trickle_down/{$task}")) {
             $this->userMessage("Bad task short name", 'notice', false);
             return;
         }
         if (!$this->post_exists('task_description') || !$this->post('task_description')) {
             $this->userMessage("No task description set", 'notice', false);
             return;
         }
         //we are good to go.
         I2CE::getConfig()->I2CE->tasks->task_description->{$task} = $this->post('task_description');
     } else {
         if (count($this->request_remainder) == 1) {
             $task = $this->request_remainder[0];
             $taskConfig = I2CE::getConfig()->traverse("/I2CE/tasks");
             if (!$taskConfig->__isset("task_description/{$task}")) {
                 $this->userMessage("Invalid Task {$task} specified", 'notice', false);
                 return;
             }
             $post = $this->post();
             if (!array_key_exists('task_description', $post) || !$post['task_description']) {
                 $this->userMessage("No task description set", 'notice', false);
                 return;
             }
             if ($taskConfig->is_translatable("task_description/{$task}")) {
                 $locale = I2CE_Locales::getPreferredLocale();
                 $taskConfig->task_description->setTranslation($locale, $post['task_description'], $task);
                 if ($locale == I2CE_Locales::DEFAULT_LOCALE) {
                     $taskConfig->task_description->{$task} = $post['task_description'];
                 }
             } else {
                 $taskConfig->task_description->{$task} = $post['task_description'];
             }
             if (array_key_exists('task_tasks', $post) && is_array($post['task_tasks'])) {
                 //make sure the tasks are valid.
                 $tasks = $post['task_tasks'];
                 foreach ($tasks as $i => $r) {
                     if (!$taskConfig->__isset("task_description/{$r}")) {
                         unset($tasks[$i]);
                     }
                 }
                 $taskConfig->task_trickle_down->{$task}->erase();
                 $taskConfig->traverse("task_trickle_down/{$task}", true, false);
                 //recreate what we just erased
                 $taskConfig->task_trickle_down->{$task} = $tasks;
             }
         }
     }
     $this->setRedirect('tasks-roles/tasks');
 }
Esempio n. 9
0
 public function generateListData($lang = 'en-US')
 {
     I2CE_Locales::setPreferredLocale(strtr($lang, '-', '_'));
     $display_style = 'default';
     I2CE::getConfig()->setIfIsSet($display_style, "/modules/SVS/lists/" . $this->oid . "/meta/display_style");
     $code_style = 'code';
     I2CE::getConfig()->setIfIsSet($code_style, "/modules/SVS/lists/" . $this->oid . "/meta/code_style");
     $code_system_style = false;
     I2CE::getConfig()->setIfIsSet($code_system_style, "/modules/SVS/lists/" . $this->oid . "/meta/code_system_style");
     $meta = $this->getMeta();
     $code_system = $meta['Source'];
     I2CE::getConfig()->setIfIsSet($code_system, "/modules/SVS/lists/" . $this->oid . "/meta/code_system");
     $where = I2CE::getConfig()->getAsArray("/modules/SVS/lists/" . $this->oid . "/where");
     if (!is_array($where)) {
         $where = array();
     }
     $inc_hidden = false;
     I2CE::getConfig()->setIfIsSet($inc_hidden, "/modules/SVS/lists/" . $this->oid . "/hidden");
     //include hidden
     if (!$inc_hidden) {
         $nohidden = array('operator' => 'OR', 'operand' => array(array('operator' => 'FIELD_LIMIT', 'field' => 'i2ce_hidden', 'style' => 'no', 'data' => array()), array('operator' => 'FIELD_LIMIT', 'field' => 'i2ce_hidden', 'style' => 'null', 'data' => array())));
         if (count($where) > 0) {
             $where = array('operator' => 'AND', 'operand' => array(0 => $where, 1 => $nohidden));
         } else {
             $where = $nohidden;
         }
     }
     $styles = array('displayName' => $display_style, 'code' => $code_style);
     if ($code_system_style) {
         $styles['codeSystem'] = $code_system_style;
     }
     $all_fields = array();
     $disp_strings = array();
     $disp_fields = array();
     foreach ($styles as $out => $style) {
         if ($style == 'id') {
             continue;
         }
         $disp_strings[$out] = I2CE_List::getDisplayString($this->list, $style);
         $disp_fields[$out] = I2CE_List::getDisplayFields($this->list, $style);
         ksort($disp_fields[$out]);
         $all_fields = array_merge($all_fields, $disp_fields[$out]);
     }
     $all_fields = array_unique($all_fields);
     $field_data = I2CE_FormStorage::listDisplayFields($this->list, $all_fields, false, $where, array());
     $data = array();
     foreach ($field_data as $id => $fields) {
         $data[$id] = array();
         foreach ($styles as $out => $style) {
             if ($style == 'id') {
                 $data[$id][$out] = $id;
             } else {
                 $values = array();
                 foreach ($disp_fields[$out] as $field) {
                     if (array_key_exists($field, $fields)) {
                         $val = $fields[$field];
                     } else {
                         $val = '';
                     }
                     $values[] = $val;
                 }
                 $data[$id][$out] = @vsprintf($disp_strings[$out], $values);
             }
         }
         if (!in_array('codeSystem', $styles)) {
             $data[$id]['codeSystem'] = $code_system;
         }
     }
     return $data;
 }
 protected function setSitePreferred()
 {
     if ($this->request_exists('locale')) {
         I2CE_Locales::setSitePreferredLocale($this->request('locale'));
     }
     if ($this->get_exists('redirect')) {
         $this->setRedirect($this->get('redirect'));
     } else {
         $this->setRedirect('./');
         //go home as I don't know what to do
     }
     return true;
 }
 /**
  * The business method if this page is called from the commmand line
  * @param array $request_remainder the remainder of the request after the page specfication.  
  * @param array $args the array of unix style command line arguments 
  */
 protected function actionCommandLine($args, $request_remainder)
 {
     $config = I2CE::getConfig();
     if (!$config->is_parent("/modules/forms/forms")) {
         I2CE::raiseError("No Forms", E_USER_ERROR);
     }
     $config = I2CE::getConfig();
     $module = $config->config->site->module;
     if (!$module) {
         I2CE::raiseError("No site module");
     }
     $formConfig = $config->modules->forms->forms;
     $this->locale = I2CE::getRuntimeVariable('locale', false);
     if (!$this->locale) {
         $this->locale = I2CE_Locales::DEFAULT_LOCALE;
     }
     $this->locale = I2CE_Locales::ensureSelectableLocale($this->locale);
     I2CE_Locales::setPreferredLocale($this->locale);
     $forms = I2CE::getRuntimeVariable('forms', false);
     if ($forms) {
         $forms = explode(',', $forms);
     } else {
         $forms = $formConfig->getKeys('/modules/forms/forms');
         $cli = new I2CE_CLI();
         $forms = $cli->chooseMenuValues("Select Forms:", $forms);
     }
     if ($skipforms = I2CE::getRuntimeVariable('skipforms', false)) {
         $skipforms = explode('#', $skipforms);
         $t_forms = array();
         foreach ($forms as $form) {
             foreach ($skipforms as $skipform) {
                 if (preg_match('/' . $skipform . '/', $form)) {
                     continue 2;
                 }
             }
             $t_forms[] = $form;
         }
         $forms = $t_forms;
     }
     sort($forms, SORT_STRING);
     switch ($this->page) {
         case 'wiki':
             $this->wiki($forms);
             break;
         case 'dot':
             $this->dot($forms);
             break;
         case 'text':
         default:
             $this->text($forms);
             break;
     }
 }
Esempio n. 12
0
 /**
  * Displays the date in a readable format.
  */
 public function displayDate()
 {
     if (!$this->isValid()) {
         return "";
     }
     $dateTimeObj = $this->getDateTimeObj();
     if ($dateTimeObj === false) {
         return "";
     }
     $formatter = self::getIntlFormatter(I2CE_Locales::getPreferredLocale(), $this->type);
     if ($formatter !== null) {
         return $formatter->format($dateTimeObj->getTimestamp());
     } else {
         $format = self::$date_formats[$this->type];
         I2CE::getConfig()->setIfIsSet($format, "/I2CE/date/format/" . $this->type);
         return $dateTimeObj->format($format);
     }
     /*
     switch( $this->type ) {
     case self::YEAR_ONLY :
         return $this->year;
         break;
     case self::MONTH_DAY :
         if ( (int)$this->month == 0 ) {
             return "";
         } else {
             return sprintf( "%d %s", $this->day, self::$months[ (int)$this->month ] );
         }
         break;
     case self::DATE_TIME :
         if ( (int)$this->month == 0 ) {
             return "";
         } else { 
             return sprintf( "%d %s %d %d:%02d:%02d", $this->day, self::$months[ (int)$this->month ], $this->year, $this->hour, $this->minute, $this->second );
         }
         break;
     case self::TIME_ONLY :
     
         return sprintf( "%d:%02d:%02d", $this->hour, $this->minute, $this->second );                
         break;
     case self::DATE :
         if ( (int)$this->month == 0 ) {
             return "";
         } else { 
             return sprintf( "%d %s %d", $this->day, self::$months[ (int)$this->month ], $this->year );
         }
         break;
     default :
         I2CE::raiseError( "An invalid date type was used for I2CE_Date::displayDate.", E_USER_WARNING );
         return "";
     }
     */
 }
 /**
  * Find a file (or directory) of a certain category
  * @param string $category  the category of the file
  * @param string $file_name the file name of the file we wish to find
  * @param boolean $find_all Defatults to false
  * @returns mixed.  Returns either a string which is the path and file name of the file 
  * we found, or null if we did not find the file.
  */
 public function search($category, $file_name, $find_all = false)
 {
     if (!array_key_exists($category, $this->ordered_paths)) {
         $factory = I2CE_ModuleFactory::instance();
         $factory->loadPaths(null, $category, false, $this);
     }
     if ($find_all || $this->stale_time < 0) {
         return parent::search($category, $file_name, $find_all);
     }
     if (array_key_exists($category, $this->preferred_locales) && is_array($this->preferred_locales[$category])) {
         $locales = $this->preferred_locales[$category];
     } else {
         $locales = I2CE_Locales::getPreferredLocales();
     }
     if (array_key_exists('I2CE_FileSearch_Caching', $_SESSION) && is_array($_SESSION['I2CE_FileSearch_Caching']) && array_key_exists($category, $_SESSION['I2CE_FileSearch_Caching']) && is_array($_SESSION['I2CE_FileSearch_Caching'][$category]) && array_key_exists($file_name, $_SESSION['I2CE_FileSearch_Caching'][$category]) && is_array($_SESSION['I2CE_FileSearch_Caching'][$category][$file_name])) {
         $data = $_SESSION['I2CE_FileSearch_Caching'][$category][$file_name];
         if (array_key_exists('time', $data) && array_key_exists('location', $data) && array_key_exists('locale', $data)) {
             if (is_readable($data['location']) && time() - $data['time'] < $this->stale_time) {
                 $this->found_locales = $data['locale'];
                 return $data['location'];
             } else {
                 unset($_SESSION['I2CE_FileSearch_Caching'][$category][$file_name]);
             }
         }
     }
     //did not find the file
     $location = parent::search($category, $file_name, false);
     if (!is_string($location) || strlen($location) == 0) {
         return null;
     }
     $_SESSION['I2CE_FileSearch_Caching'][$category][$file_name] = array('time' => time(), 'location' => $location, 'locale' => $this->found_locales);
     return $location;
 }
Esempio n. 14
0
 public function __construct()
 {
     $this->command_line = !array_key_exists('HTTP_HOST', $_SERVER);
     I2CE_Locales::setPreferredLocale(I2CE_Locales::getPreferredLocale());
 }
 protected function displayConfig($config, $magicNode, $full)
 {
     foreach ($config as $key => $child) {
         if ($config->is_parent($key)) {
             $path = 'magicDataBrowser/show/' . $config->getPath(false);
             $node = $this->template->loadFile("browser_node.html", 'li');
             $magicNode->appendChild($node);
             $this->template->setDisplayDataImmediate('erase_action', 'magicDataBrowser/erase/' . $config->getPath(false) . "/{$key}", $node);
             $this->template->setDisplayDataImmediate('trans_action', 'magicDataBrowser/trans/' . $config->getPath(false) . "/{$key}", $node);
             $subNode = $this->template->query("./descendant-or-self::node()[@name='magic_data_list']", $node);
             $this->template->setDisplayDataImmediate('browser_magic_data_key_path', $path . '/' . $key, $node);
             $this->template->setDisplayDataImmediate('browser_magic_data_key', $key, $node);
             if ($full && $subNode->length > 0) {
                 $this->displayConfig($child, $subNode->item(0), $full);
             } else {
                 $valueNode = $this->template->getElementById('browser_magic_data_value', $node);
                 if (!$valueNode instanceof DOMElement) {
                     continue;
                 }
                 if ($this->hasAjax()) {
                     $replacementNode = $this->template->createElement('span', array('class' => 'clickable', 'id' => "magic_data_list_{$path}/{$key}"), 'show values');
                     $this->addAjaxUpdate("magic_data_list_{$path}/{$key}", "magic_data_list_{$path}/{$key}", 'click', "{$path}/{$key}", 'magic_data_list');
                     $this->addAjaxCompleteFunction("magic_data_list_{$path}/{$key}", "\$('magic_data_list_{$path}/{$key}').removeClass('clickable')");
                 } else {
                     $replacementNode = $this->template->createTextNode('*******');
                 }
                 $valueNode->parentNode->replaceChild($replacementNode, $valueNode);
             }
         } else {
             if ($config->is_scalar($key)) {
                 //just display the value
                 $locale = '';
                 if ($config->traverse($key, false, false)->hasAttribute('binary') && $config->traverse($key, false, false)->getAttribute('binary')) {
                     $bin = 1;
                     $valueNode = $this->template->loadFile("browser_binary_node.html", 'li');
                     $this->template->setDisplayDataImmediate('browser_magic_data_value_binary_link', 'magicDataBrowser/download/' . $config->getPath(false) . "/{$key}", $valueNode);
                 } else {
                     $bin = 0;
                     $valueNode = $this->template->loadFile("browser_value_node.html", 'li');
                     if ($config->is_translatable($key)) {
                         if ($this->request_exists('locale')) {
                             $locale = $this->request('locale');
                         } else {
                             $locales = I2CE_Locales::getPreferredLocales();
                             reset($locales);
                             $locale = current($locales);
                         }
                         $child = $config->getTranslation($locale, false, $key);
                         $locale = ' [' . $locale . ']';
                     }
                     $this->template->setDisplayDataImmediate('browser_magic_data_key', $key, $valueNode);
                     $this->template->setDisplayDataImmediate('browser_magic_data_value', $child, $valueNode);
                 }
                 $this->template->setDisplayDataImmediate('bin_node', $bin, $valueNode);
                 $magicNode->appendChild($valueNode);
                 $this->template->setDisplayDataImmediate('browser_magic_data_key_label', $key . $locale, $valueNode);
                 $change_value_action = 'index.php/magicDataBrowser/set/' . $config->getPath(false);
                 $this->template->setDisplayDataImmediate('change_value_action', $change_value_action, $valueNode);
                 if (!$bin && ($vNode = $this->template->getElementByName('browser_magic_data_value', 0, $valueNode)) instanceof DOMNode) {
                     //if ($this->post_exists('browser_magic_data_value') && $this->post_exists('browser_magic_data_key')) {
                     $js = "var e = \$(this); \ne.setStyle('background-color','yellow');\nnew Request({\n'useSpinner':true,\nurl: '{$change_value_action}',\nmethod: 'post',\n'data':{'browser_magic_data_value': e.get('value'),'browser_magic_data_key':'{$key}'},\nonComplete: function(response) { \n e.setStyle('background-color','white');\n}\n}).send();";
                     $vNode->setAttribute('onchange', $js);
                 }
                 $this->template->setDisplayDataImmediate('erase_action', 'magicDataBrowser/erase/' . $config->getPath(false) . "/{$key}", $valueNode);
                 $this->template->setDisplayDataImmediate('trans_action', 'magicDataBrowser/trans/' . $config->getPath(false) . "/{$key}", $valueNode);
                 $this->template->setDisplayDataImmediate('upload_action', 'magicDataBrowser/upload/' . $config->getPath(false) . "/{$key}", $valueNode);
                 $this->template->setDisplayDataImmediate('upload_binary_action', 'magicDataBrowser/upload_binary/' . $config->getPath(false) . "/{$key}", $valueNode);
                 $this->template->setDisplayDataImmediate('load_action', 'magicDataBrowser/load/' . $config->getPath(false) . "/{$key}", $valueNode);
                 $keys = array();
                 foreach (I2CE::getConfig()->getKeys("/modules/magicDataBrowser/transforms") as $key) {
                     $keys[$key] = $key;
                 }
                 $this->template->setDisplayDataImmediate('transform_key', $keys, $valueNode);
                 $this->useDropDown();
             } else {
                 if ($config->is_indeterminate($key)) {
                     $valueNode = $this->template->loadFile("browser_value_node_notset.html", 'li');
                     $magicNode->appendChild($valueNode);
                     $this->template->setDisplayDataImmediate('browser_magic_data_key', $key, $valueNode);
                     $this->template->setDisplayDataImmediate('upload_action', 'magicDataBrowser/upload/' . $config->getPath(false) . "/{$key}", $valueNode);
                     $this->template->setDisplayDataImmediate('upload_binary_action', 'magicDataBrowser/upload_binary/' . $config->getPath(false) . "/{$key}", $valueNode);
                     $this->template->setDisplayDataImmediate('load_action', 'magicDataBrowser/load/' . $config->getPath(false) . "/{$key}", $valueNode);
                     $this->template->setDisplayDataImmediate('erase_action', 'magicDataBrowser/erase/' . $config->getPath(false) . "/{$key}", $valueNode);
                     $this->template->setDisplayDataImmediate('trans_action', 'magicDataBrowser/trans/' . $config->getPath(false) . "/{$key}", $valueNode);
                     $this->template->setDisplayDataImmediate('parent_action', 'magicDataBrowser/parent/' . $config->getPath(false) . "/{$key}", $valueNode);
                     $this->template->setDisplayDataImmediate('scalar_action', 'magicDataBrowser/scalar/' . $config->getPath(false) . "/{$key}", $valueNode);
                     $keys = array();
                     foreach (I2CE::getConfig()->getKeys("/modules/magicDataBrowser/transforms") as $key) {
                         $keys[$key] = $key;
                     }
                     $this->template->setDisplayDataImmediate('transform_key', $keys, $valueNode);
                     $this->useDropDown();
                 } else {
                     //echo "weird $key\n";
                 }
             }
         }
     }
     $valueNode = $this->template->loadFile("browser_add_node.html", 'li');
     if ($valueNode instanceof DOMElement) {
         $magicNode->appendChild($valueNode);
         $this->template->setDisplayDataImmediate('add_key_action', 'magicDataBrowser/add/' . $config->getPath(false), $valueNode);
         $this->template->setDisplayDataImmediate('add_scalar_key_action', 'magicDataBrowser/add_scalar/' . $config->getPath(false), $valueNode);
         $this->template->setDisplayDataImmediate('add_parent_key_action', 'magicDataBrowser/add_parent/' . $config->getPath(false), $valueNode);
     }
     $url_tail = implode('/', $this->config_path);
     if ($this->get_exists('full')) {
         $url_tail .= '?full';
     }
     $this->template->setDisplayDataImmediate('caller', $url_tail, $magicNode);
 }
Esempio n. 16
0
 protected static function loadModuleMagicData($shortname, $file, $old_vers, $new_vers, $mod_configurator)
 {
     $mod_storage = $mod_configurator->getStorage();
     if (!$mod_storage instanceof I2CE_MagicDataNode) {
         I2CE::raiseError("Expecting magic data");
         return false;
     }
     $storage = I2CE::getConfig();
     $processed = '0';
     //$processed = $old_vers;
     $storage->setIfIsSet($processed, "/config/status/config_processed/{$shortname}");
     I2CE::raiseError("Previously processed config data for {$shortname} with version <= {$processed}. New version is {$new_vers}");
     $uptodate = I2CE_Validate::checkVersion($processed, '>=', $new_vers);
     $localized = array();
     $storage->setIfIsSet($localized, "/config/status/localized/{$shortname}", true);
     $mod_configurator->setLocales(I2CE_Locales::getAvailableLocales());
     $imported = $mod_configurator->importLocalizedTemplates($localized);
     //I2CE::raiseError("Imported for $shortname:" . print_r($imported,true) . "\nfrom available locales:" . implode(',',I2CE_Locales::getAvailableLocales()) . "\nWith:" . print_r($localized,true));
     $outofdate_locales = array();
     foreach ($imported as $locale => $data) {
         if (I2CE_Validate::checkVersion($data['old_vers'], '<', $data['vers'])) {
             $uptodate = false;
             $outofdate_locales[$locale] = $data;
         }
     }
     if ($uptodate && count($outofdate_locales) == 0) {
         I2CE::raiseError("Main config is up to date form {$shortname} and there are no out of date locales");
         $storage->config->status->localized->{$shortname} = $imported;
         return true;
         //main config is up to date, and there are no imported configs which are out of date
     }
     if ($shortname != $mod_configurator->processConfig($processed, true, false, $outofdate_locales)) {
         I2CE::raiseError("Unable to process config data for {$shortname} with locales: " . implode(',', $outofdate_locales));
         return false;
     }
     foreach ($imported as $locale => &$data) {
         unset($data['old_vers']);
     }
     if (count($mod_storage) == 0 || count($mod_storage) == 1 && isset($mod_storage->config)) {
         I2CE::raiseError("No data to update for {$shortname}");
         $storage->config->status->localized->{$shortname} = $imported;
         //no new data was loaded in the config files.  so we wont need to store magic data
         return true;
     }
     //there is stuff to store in magic data and we are good to go
     $msg = "Loaded in magic data for {$shortname} to memory";
     if (count($outofdate_locales) > 0) {
         $msg .= "\nThe data for locale(s) " . implode(',', array_keys($outofdate_locales)) . " was out of date";
     }
     I2CE::raiseError($msg);
     $storage->config->status->localized->{$shortname} = $imported;
     return $imported;
 }
Esempio n. 17
0
 public function setLocales($locales)
 {
     $locales = I2CE_Locales::validateLocales($locales);
     $this->locales = $locales;
 }
Esempio n. 18
0
 /**
  * A path to search for a category of files.
  * @param string $category the category of files.
  * @param string $path the parh (or glob pattern for a path) to add.  There a a few modifications to the globbing...
  *        A trailing '**' means that the paths should be added recursivley
  *        Paths are automatically checked for localized version by the presence of a 'en_US' subdirectory.
  *        specifically, if a path is added such as /my/path  and there is a subdir called /my/path/en_US  then
  *        all subdirectories which are in the preffered locales (or $locales below) are added.
  *
  *      Examples:  /usr/share/fonts/      adds in this directory to the search paths
  *                 /usr/share/fonts/*  adds in all subdirectories
  *                 /usr/share/fonts/**  recusively adds in all subdirecties
  *                 /usr/share/fonts/truetype/ttf*  adds in all directories begining with ttf
  * @param mixed $order.  If it is a  number, then it indicates the order in which this path is  searched.
  *         The lower the number, the higher the priority.
  *         If multiple paths share the same order, the order in which they are searched is not specfied
  *         The are also special string values of $order (all are relative to the category specified):
  *         <ul>
  *         <li>'LAST' -- add at the last added order </li>
  *         <li>'LOWEST' -- add so it has the lowest order thus far  </li>
  *         <li>'HIGHEST' -- add so it has the highest order thus far </li>
  *         <li>'EVEN_LOWER' -- add so it has lower order than anything thus far.  This is the default behavior </li>
  *         <li>'EVEN_HIGHER' -- add so it has higher  order than anything thus far </li>
  *         </ul>
  * @param boolean $absolut whether or not to try to make a relative path absolut.  It will
  *         overide (but not change) the global behaviour of this instance.
  * @param string $path_prefix.  Defaults to null.  Any prefix to add to a local class path (if we do make absolute)
  * @param mixed $locales null(default) , string or array of string.  Used to override the default locale settings when not the defaults of null.  
  * It is the list of localized sub-directories to search for, if the given glob is a subdirectory.
  */
 public function addPath($category, $path, $order = 'EVEN_LOWER', $absolut = null, $path_prefix = null, $locales = null)
 {
     $path = self::convertPath($path);
     $path_prefix = self::convertPath($path_prefix);
     if (!is_string($path) || strlen($path) == 0) {
         return FALSE;
     }
     if ($absolut === null) {
         $absolut = $this->absolut;
     }
     $recurse = false;
     if (strlen($path) >= 2 && substr($path, strlen($path) - 2) == '**') {
         $recurse = true;
         $path = substr($path, 0, -1);
     }
     if ($absolut && !$this->isAbsolut($path)) {
         //relative directorty which we need to change to a absolut directory
         if ($path_prefix === null || is_string($path_prefix) && strlen($path_prefix) == 0) {
             $path_prefix = $this->absolut('.' . DIRECTORY_SEPARATOR, 1);
         }
         /* see  http://us.php.net/manual/en/function.glob.php#86425 for glob and preg_replace */
         $path = preg_replace('/(\\*|\\?|\\[)/', '[$1]', $path_prefix) . DIRECTORY_SEPARATOR . $path;
     }
     $path = self::convertPath($path, true);
     if (strlen($path) == 0) {
         return false;
     }
     $t_locales = null;
     $found_dirs = array();
     $globs = array($path => I2CE_Locales::DEFAULT_LOCALE);
     if (!is_array($locales)) {
         if (is_string($locales)) {
             $locales = array($locales);
             $locales = I2CE_Locales::validateLocales($t_locales);
         } else {
             if (array_key_exists($category, $this->preferred_locales) && is_array($this->preferred_locales[$category])) {
                 $locales = $this->preferred_locales[$category];
                 $locales = I2CE_Locales::validateLocales($locales);
             } else {
                 $locales = I2CE_Locales::getPreferredLocales();
             }
         }
     } else {
         $locales = I2CE_Locales::validateLocales($locales);
     }
     while (count($globs) > 0) {
         end($globs);
         $glob = key($globs);
         $locale = array_pop($globs);
         $dirs = glob($glob, GLOB_ONLYDIR | GLOB_NOSORT);
         if ($dirs === false) {
             continue;
         }
         foreach ($dirs as $dir) {
             if ($locale == I2CE_Locales::DEFAULT_LOCALE && is_dir($dir . DIRECTORY_SEPARATOR . I2CE_Locales::DEFAULT_LOCALE . DIRECTORY_SEPARATOR . '.')) {
                 //this directory is localized.
                 foreach ($locales as $t_locale) {
                     $l_dir = $dir . DIRECTORY_SEPARATOR . $t_locale;
                     if (is_dir($l_dir)) {
                         $found_dirs[$l_dir] = $t_locale;
                         if ($recurse) {
                             $globs[preg_replace('/(\\*|\\?|\\[)/', '[$1]', $l_dir) . DIRECTORY_SEPARATOR . '*'] = $t_locale;
                         }
                     }
                 }
             } else {
                 //this directory is not localized
                 $found_dirs[$dir] = $locale;
                 if ($recurse) {
                     $globs[preg_replace('/(\\*|\\?|\\[)/', '[$1]', $dir) . DIRECTORY_SEPARATOR . '*'] = $locale;
                 }
             }
         }
     }
     if (count($found_dirs) == 0) {
         return FALSE;
     }
     if (is_string($order)) {
         if (!array_key_exists($category, $this->ordered_paths) || !is_array($this->ordered_paths[$category]) || count($this->ordered_paths[$category]) == 0) {
             //nothing added yet.
             $order = 0;
         } else {
             $order = strtoupper($order);
             switch ($order) {
                 case 'LAST':
                     $order = $this->last_order[$category];
                     if ($order == null) {
                         //this should not happen but we are being safe
                         $order = 0;
                     }
                     break;
                 case 'LOWEST':
                     $keys = array_keys($this->ordered_paths[$category]);
                     $order = $keys[count($keys) - 1];
                     break;
                 case 'HIGHEST':
                     $keys = array_keys($this->ordered_paths[$category]);
                     $order = $keys[0];
                     break;
                 case 'EVEN_HIGHER':
                     $keys = array_keys($this->ordered_paths[$category]);
                     $order = $keys[0] - 1;
                     break;
                 default:
                     // 'EVEN_LOWER'
                     $keys = array_keys($this->ordered_paths[$category]);
                     $order = $keys[count($keys) - 1] + 1;
                     break;
             }
         }
     } else {
         if (!is_int($order)) {
             if (class_exists('I2CE', true)) {
                 I2CE::raiseError("Invalid order ({$order}) when setting path ({$path})", E_USER_NOTICE);
                 return FALSE;
             } else {
                 I2CE::raiseError("Invalid order ({$order}) when setting path ({$path})", E_USER_ERROR);
                 return false;
             }
         }
     }
     foreach ($found_dirs as $dir => $locale) {
         $this->ordered_paths[$category][$order][realpath($dir)] = $locale;
     }
     ksort($this->ordered_paths[$category]);
     $this->last_order[$category] = $order;
     return TRUE;
 }
 protected function localeMenu($node, $template, $locales, $update_link_base, $selected = null)
 {
     $iconConfig = I2CE::getConfig()->traverse("/locales/icons", true, false);
     if (!$iconConfig instanceof I2CE_MagicDataNode) {
         return false;
     }
     if ($selected === null) {
         $selected = I2CE_Locales::getPreferredLocale();
     }
     if (($pos = strpos($selected, '_')) !== false) {
         $selected_lang = substr($selected, 0, $pos);
     } else {
         $selected_lang = $selected;
     }
     foreach ($locales as $locale) {
         $name = $this->getLocaleName($locale);
         if (($pos = strpos($locale, '_')) !== false) {
             $lang = substr($locale, 0, $pos);
             $region = strtolower(substr($locale, $pos + 1));
         } else {
             $lang = $locale;
             $region = $locale;
         }
         $icon = false;
         foreach (array($locale, $region) as $key) {
             if ($iconConfig->setIfIsSet($icon, $key)) {
                 break;
             }
         }
         if (is_string($icon) && strlen(trim($icon)) > 0) {
             $icon = array('src' => 'file/' . trim($icon), 'alt_text' => $name);
         } else {
             $icon = false;
         }
         if ($icon) {
             $choice_file = 'language_choice_icon.html';
         } else {
             $choice_file = 'language_choice.html';
         }
         $choiceNode = $template->appendFileByNode($choice_file, '//body/*', $node);
         if (!$choiceNode instanceof DOMNode) {
             continue;
         }
         if ($selected == $locale) {
             $name = '[' . $name . ']';
         }
         $template->setDisplayDataImmediate('language_choice_text', $name, $choiceNode);
         $template->setDisplayDataImmediate('language_choice_link', $update_link_base . $locale, $choiceNode);
         if ($icon) {
             $template->setDisplayDataImmediate('language_choice_icon', $icon, $choiceNode);
         }
     }
 }
Esempio n. 20
0
 /**
  * Populate the member variables of this object.
  * 
  * This will also update the user log to show the latest activity for this login.
  * @param boolean $update_log
  * @global array
  */
 public function populate($repopulate = false)
 {
     if ($this->id == '0') {
         return;
     }
     $this->user->populate();
     foreach ($this->allowedDetails as $detail) {
         if ($detail == 'locale') {
             $locale = I2CE_Locales::ensureSelectableLocale($this->user->locale);
             $this->fields[$detail]->setFromDB('locale|' . $locale);
         } else {
             $this->fields[$detail]->setFromDB($this->user->{$detail});
         }
     }
     $this->fields['username']->setValue($this->user->username);
     //$this->fields['role']->setValue(array('role' , $this->user->role));
     $this->fields['role']->setFromDB('role|' . $this->user->role);
 }
 /**
  * construct a swiss swiss factory and create it if it doesn't exist.
  * @param I2CE_MagicDataNode $storage.  The root of the magic data we will be operating on
  * @param string  $swissName.  The classname for the root swiss object.
  * @throws Exception
  */
 public function __construct($page, $options = array())
 {
     $this->child_node_cache = array();
     $this->child_node_cache_index = array();
     parent::__construct($page);
     if (!array_key_exists('module', $options) || !$options['module']) {
         throw new Exception("No modules specified");
     }
     $this->module = $options['module'];
     $config_file = null;
     if (!I2CE::getConfig()->setIfIsSet($config_file, "/config/data/{$options['module']}/file")) {
         throw new Exception("No magic data template found for {$options['module']}");
     }
     $this->configTemplate = new I2CE_MagicDataTemplate();
     if (!$this->configTemplate->loadRootFile($config_file)) {
         throw new Exception("Invalid magic data template found for {$options['module']}");
     }
     $this->xpath = new DOMXPath($this->configTemplate->getDoc());
     $this->configNodes = array();
     $nodes = $this->xpath->query('/I2CEConfiguration/configurationGroup');
     if ($nodes->length != 1) {
         throw new Exception("No or invalid configuration data for {$options['module']}");
     }
     $this->configNodes['/'] = $nodes->item(0);
     $this->statii['/'] = $this->configTemplate->getDefaultStatus();
     if (!array_key_exists('version', $this->statii['/'])) {
         if (array_key_exists('version', $options)) {
             $this->statii['/']['version'] = $options['version'];
         } else {
             $this->statii['/']['version'] = 0;
         }
     }
     $file_search = new I2CE_FileSearch();
     $mod_factory = I2CE_ModuleFactory::instance();
     $mod_factory->loadPaths($this->module, 'CONFIGS', true, $file_search);
     $translated = $file_search->search('CONFIGS', $config_file, true);
     $translated_locales = $file_search->getLocaleOfLastSearch();
     $preferred_locales = I2CE_Locales::getPreferredLocales();
     $this->translatedConfigs = array();
     foreach ($preferred_locales as $locale) {
         if (($index = array_search($locale, $translated_locales)) === false) {
             continue;
         }
         $trans_file = $translated[$index];
         $trans_template = new I2CE_MagicDataTemplate();
         if (!$trans_template->loadRootFile($trans_file)) {
             continue;
         }
         $this->translatedConfigs[$locale] = $trans_template;
     }
 }
 /**
  * Checks to see if the locales for a given module are up to date
  * @param string $shortname  The module
  * @param string $file  -- defaults to null which means use the currently loaded file location for the config file
  * @returns booolean.  True if all is up to date.
  */
 public function checkLocalesUptoDate($shortname, $file = null)
 {
     if ($file == null) {
         if (!$this->config->setIfIsSet($file, "data/{$shortname}/file")) {
             return false;
             // the module has never been loaded
         }
         $r_file = I2CE_FileSearch::realPath($file);
         if (!file_exists($r_file) || !is_readable($r_file)) {
             return false;
             // the friggin file does not even exist.  why are you asking me?
         }
     } else {
         $r_file = I2CE_FileSearch::realPath($file);
         if (!$r_file) {
             return false;
             //invalid file was set.
         }
         if (!$this->config->setIfIsSet($saved_file, "data/{$shortname}/file")) {
             return false;
             // the module has never been loaded
         }
         if (I2CE_FileSearch::realPath($saved_file) != $r_file) {
             //the loaded config file is different than the one we are looking at
             return false;
         }
     }
     $locales = I2CE_Locales::getAvailableLocales();
     $dirs = array();
     if (!$this->config->setIfIsSet($dirs, "data/{$shortname}/paths/CONFIGS", true)) {
         return true;
     }
     $localized = array();
     $this->config->setIfIsSet($localized, "status/localized/{$shortname}", true);
     $basename = basename($r_file);
     $dirname = dirname($r_file);
     //I2CE::raiseError("Checking $shortname in  " . implode(',',$dirs) . " for locales " . implode(',',$locales) );
     foreach ($dirs as $dir) {
         foreach ($locales as $locale) {
             if (I2CE_FileSearch::isAbsolut($dir)) {
                 //the config path in theconfig file is absolut.
                 $t_file = $dir . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . $basename;
                 $localized_file = I2CE_FileSearch::realPath($t_file);
                 $dir = I2CE_FileSearch::relativePath($dir);
             } else {
                 //the config path in theconfig file is relative to the module file
                 $t_file = $dirname . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . $basename;
                 $localized_file = I2CE_FileSearch::realPath($t_file);
             }
             if (!$localized_file || !is_file($localized_file) || !is_readable($localized_file)) {
                 continue;
             }
             if (!array_key_exists($locale, $localized) || !is_array($localized[$locale])) {
                 I2CE::raiseError("Localization data {$locale} for module {$shortname} has never been loaded");
                 return false;
                 //we have never examined this one before
             }
             foreach (array('file', 'mtime', 'hash') as $key) {
                 if (!array_key_exists($key, $localized[$locale])) {
                     return false;
                 }
             }
             //we have examined this one before.
             $l_file = I2CE_FileSearch::realPath($localized[$locale]['file']);
             if ($localized_file !== $l_file) {
                 return false;
             }
             @($mtime = filemtime($localized_file));
             if (!$mtime || !$localized[$locale]['mtime']) {
                 return false;
             }
             if ($mtime > $localized[$locale]['mtime']) {
                 return false;
             }
             $contents = file_get_contents($localized_file);
             if (!$contents) {
                 return false;
             }
             if ($localized[$locale]['hash'] != md5($contents)) {
                 return false;
             }
         }
     }
     return true;
 }
Esempio n. 23
0
 /**
  * Perform the main actions of the page.
  * @global array Get the home page from the global configuration
  */
 protected function action()
 {
     if ($this->request_exists('message') && $this->request('message')) {
         $this->template->userMessage($this->request('message'), 'default', false);
     }
     $i2ce_config = I2CE::getConfig()->I2CE;
     parent::action();
     $this->template->setBodyId("loginPage");
     if ($this->isPost()) {
         if ($this->post('submit') == "Login as Guest") {
             $this->post['username'] = $i2ce_config->guest->account;
             $this->post['password'] = $i2ce_config->guest->password;
         }
         $message = $this->user->login($this->post('username'), $this->post('password'));
         if (is_string($message)) {
             $this->template->setDisplayDataImmediate('error_message', $message);
         } else {
             if ($message === true) {
                 //the user was logged in
                 if (I2CE_Locales::getPreferredLocale() != I2CE_Locales::getBrowserPreferredLocale()) {
                     $this->user->setPreferredLocale(I2CE_Locales::getPreferredLocale());
                 }
             }
         }
     }
     if ($this->user->logged_in()) {
         if (array_key_exists('referal', $_SESSION) && $_SESSION['referal']) {
             $site_url = $this->getAccessedBaseURL();
             $referal = $_SESSION['referal'];
             unset($_SESSION['referal']);
             if ($site_url . $this->page == $referal) {
                 //there is an off chance that we are redirect from the login page.  this can happen if we initialize the site by accessing the login page
                 $referal = $this->getHome();
             }
             if (preg_match('/login/', $referal) || preg_match('/logout/', $referal)) {
                 $referal = $this->getHome();
             }
         } else {
             $referal = $this->getHome();
         }
         if ($this->user->username != 'i2ce_admin' && I2CE_User::userHasDefaultPassword($this->user->username)) {
             $this->userMessage("Please you must change your default password before you continue using the system!", "notice");
             $this->setRedirect('password');
         } else {
             $this->setRedirect($referal);
         }
         return true;
     }
     if ($default_password = I2CE_User::userHasPassword('administrator', 'administrator')) {
         $username = $this->template->query('//input[@name="username"]');
         if ($username->length == 1) {
             $username->item(0)->setAttribute('value', 'administrator');
         }
         $password = $this->template->query('//input[@name="password"]');
         if ($password->length == 1) {
             $password->item(0)->setAttribute('value', 'administrator');
         }
     } else {
         if (($autologinuser = I2CE_User::getAutoLoginUser()) !== false) {
             $username = $this->template->query('//input[@name="username"]');
             if ($username->length == 1) {
                 $username->item(0)->setAttribute('value', $autologinuser);
             }
         }
     }
     $this->template->addHeaderLink("welcomeText.css");
     if ($this->user->logged_in() && $this->user->username == 'administrator' && $default_password) {
         $this->userMessage("Your password is currently set to the default password, administrator.  Please change this by clicking on the \"Change Password\" link  below.", "notice");
         $this->userMessage("If you have not already done so, please create a new user with a non-administrative role for everyday use.", "notice");
     }
 }
 public function getTranslation($locale, $resolve = true, $path = null)
 {
     if ($path !== null) {
         $data = $this->traverse($path, false, false);
         if (!$data instanceof I2CE_MagicDataNode) {
             return false;
         }
     } else {
         if ($this->type == self::TYPE_NOT_POPULATED) {
             if (!$this->populate()) {
                 I2CE::raiseError("Could not populate at " . $this->getPath(false));
                 return false;
             }
         }
         $data = $this;
     }
     if (!$data->type > 0) {
         return false;
     }
     if (!$data->is_translatable()) {
         $resolution = array(I2CE_Locales::DEFAULT_LOCALE);
     } else {
         if ($resolve) {
             if ($this->top instanceof I2CE_MagicData) {
                 $resolution = $this->top->locales;
             } else {
                 $resolution = I2CE_Locales::getLocaleResolution($locale);
             }
         } else {
             $resolution = array($locale);
         }
     }
     foreach ($resolution as $locale) {
         if ($locale == I2CE_Locales::DEFAULT_LOCALE) {
             if ($data->_hasAttribute($locale, 'T')) {
                 $val = $data->_getAttribute($locale, 'T');
                 if (strlen($val) > 0) {
                     return $val;
                 }
             }
             return $data->value;
         } else {
             if ($data->_hasAttribute($locale, 'T')) {
                 return $data->_getAttribute($locale, 'T');
             }
         }
     }
     return $data->value;
 }
Esempio n. 25
0
 /**
  * Create a new instance of a page.
  * 
  * The default constructor should be called by any pages extending this object.  It creates the
  * {@link I2CE_Template} and {@link I2CE_User} objects and sets up the basic member variables.
  * @param array $args
  * @param array $request_remainder The remainder of the request path
  */
 public function __construct($args, $request_remainder, $get = null, $post = null)
 {
     if (array_key_exists('root_url', $args) && $args['root_url']) {
         $this->root_url = $args['root_url'];
         unset($args['root_url']);
     }
     $this->setIsPost(array_key_exists('REQUEST_METHOD', $_SERVER) && $_SERVER['REQUEST_METHOD'] == "POST");
     $this->user = new I2CE_User();
     if (function_exists('apache_note')) {
         apache_note("iHRIS-username", $this->user->username == '0' ? '-' : $this->user->username);
     } elseif (array_key_exists('HTTP_HOST', $_SERVER) && !headers_sent()) {
         header('X-iHRIS-username', $this->user->username == '0' ? '-' : $this->user->username);
     }
     I2CE_Locales::setPreferredLocale($this->user->getPreferredLocale());
     $this->args = $args;
     $this->request_remainder = $request_remainder;
     $i2ce_config = I2CE::getConfig()->I2CE;
     if (!array_key_exists('access', $args)) {
         if (array_key_exists('HTTP_HOST', $_SERVER)) {
             $args['access'] = array('any');
             //default is anyone logged in.
         } else {
             $args['access'] = array('all');
         }
     }
     $this->access = $args['access'];
     $this->setupGetPost($get, $post);
     $this->template = null;
     if (!$this->initializeTemplate()) {
         I2CE::raiseError("Could not setup templates");
     }
     $this->redirect = "";
     $this->permissionParser = new I2CE_PermissionParser($this->template);
     I2CE_ModuleFactory::callHooks('page_constructor', array('page' => $this, 'args' => $args, 'request_remainder' => $request_remainder));
 }