コード例 #1
0
ファイル: language.php プロジェクト: siddht1/abantecart-src
 /**
  * load language
  * @param string $filename
  * @param string $mode
  * @return array|null
  */
 public function _load($filename, $mode = '')
 {
     if (empty($filename)) {
         return null;
     }
     $load_data = null;
     //Check if we already have language loaded. Skip and return the language set
     if ($this->_is_loaded($filename)) {
         $load_data = $this->_get_language_set($filename);
         return $load_data;
     }
     $cache_key = 'localization.lang.' . $this->code . '.' . ($this->is_admin ? 'a' : 's') . '.' . $filename;
     $cache_key = str_replace('/', '_', $cache_key);
     if ($this->cache) {
         $load_data = $this->cache->pull($cache_key);
     }
     if ($load_data === false) {
         //Check that filename has proper name with no other special characters.
         $block_name = str_replace('/', '_', $filename);
         if (preg_match("/[\\W]+/", $block_name)) {
             $error = new AError('Error! Trying to load language with invalid path: "' . $filename . '"!');
             $error->toLog()->toDebug()->toMessages();
             return array();
         }
         $directory = $this->language_details['directory'];
         // nothing in cache. Start loading
         ADebug::checkpoint('ALanguage ' . $this->language_details['name'] . ' ' . $filename . ' no cache, so loading');
         $_ = $this->_load_from_db($this->language_details['language_id'], $filename, $this->is_admin);
         if (!$_) {
             // nothing in the database. This block (rt) was never accessed before for this language. Need to load definitions
             $_ = $this->_load_from_xml($filename, $directory, $mode);
             $this->_save_to_db($filename, $_);
         } else {
             //We have something in database, look for missing or new values.
             //Do this silently in case language file is misssing, Not a big problem
             $xml_vals = $this->_load_from_xml($filename, $directory, 'silent');
             if (count($xml_vals) > count($_)) {
                 //we have missing value in language XML. Probably newly added
                 foreach ($xml_vals as $key => $value) {
                     //missing value for $key
                     if (empty($_[$key])) {
                         $_[$key] = $value;
                         $this->_write_missing_definition(array('language_id' => $this->language_details['language_id'], 'section' => $this->is_admin, 'block' => $block_name, 'language_key' => $key, 'language_value' => $value));
                     }
                 }
             }
         }
         $load_data = $_;
         if ($this->cache) {
             $this->cache->push($cache_key, $load_data);
         }
     }
     ADebug::checkpoint('ALanguage ' . $this->language_details['name'] . ' ' . $filename . ' is loaded');
     $this->entries[$filename] = $load_data;
     //add 	filename to scope
     $this->current_languages_scope[] = $filename;
     return $this->entries[$filename];
 }