public function showAvailableLocales($node, $template, $update_link_base, $selected = null)
 {
     $this->localeMenu($node, $template, I2CE_Locales::getAvailableLocales(), $update_link_base, $selected);
 }
 /**
  * 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. 3
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;
 }