Example #1
0
 /**
  * Get meta description of the table and generate fields array
  * @return array
  */
 public function getMetadata()
 {
     if ($this->table && !$this->fields) {
         $runtime_cache = new waRuntimeCache('db/' . $this->table);
         if ($this->fields = $runtime_cache->get()) {
             return $this->fields;
         }
         if (SystemConfig::isDebug()) {
             $this->fields = $this->getFields();
         } else {
             $cache = new waSystemCache('db/' . $this->table);
             if (!($this->fields = $cache->get())) {
                 $this->fields = $this->getFields();
                 $cache->set($this->fields);
             }
         }
         $runtime_cache->set($this->fields);
     }
     return $this->fields;
 }
 public static function getAll($type = false)
 {
     $locale_config = waSystem::getInstance()->getConfigPath() . '/locale.php';
     if (file_exists($locale_config)) {
         $cache = new waSystemCache('config/locale', time() - filemtime($locale_config));
         if ($cache->isCached()) {
             $data = $cache->get();
         } else {
             $data = array();
             $locales = (include $locale_config);
             foreach ($locales as $locale) {
                 if ($info = self::getInfo($locale)) {
                     $data[$locale] = $info;
                 }
             }
             $cache->set($data);
         }
     } else {
         $data = array('en_US' => self::getInfo('en_US'), 'ru_RU' => self::getInfo('ru_RU'));
     }
     if ($type === true) {
         $type = 'all';
     }
     switch ($type) {
         case 'name_region':
             foreach ($data as &$d) {
                 $d = $d['name'] . " (" . $d['region'] . ')';
             }
             asort($data);
             break;
         case 'name':
             foreach ($data as &$d) {
                 $d = $d['name'];
             }
             asort($data);
             break;
         case false:
             return array_keys($data);
         default:
             return $data;
     }
     return $data;
 }
 /**
  * @param bool $type
  * @param bool $enabled_only
  * @return array|null
  * @throws waException
  */
 public static function getAll($type = false, $enabled_only = true)
 {
     $locale_config = waSystem::getInstance()->getConfigPath() . '/locale.php';
     if (file_exists($locale_config)) {
         $enabled_locales = (include $locale_config);
         $ttl = time() - filemtime($locale_config);
     } else {
         $enabled_locales = array('en_US', 'ru_RU');
         $ttl = 86400;
     }
     $cache = new waSystemCache('config/locale', $ttl);
     if ($cache->isCached()) {
         $data = $cache->get();
     } else {
         $data = array();
         foreach ($enabled_locales as $locale) {
             if ($info = self::getInfo($locale)) {
                 $data[$locale] = $info;
             }
         }
         $files = waFiles::listdir(dirname(__FILE__) . "/data/");
         foreach ($files as $file) {
             if (preg_match('/^([a-zA-Z_]+)\\.php$/', $file, $matches)) {
                 $locale = $matches[1];
                 if (!isset($data[$locale]) && ($info = self::getInfo($locale))) {
                     $data[$locale] = $info;
                 }
             }
         }
         $cache->set($data);
     }
     if ($enabled_only) {
         $result = array();
         foreach ($enabled_locales as $locale) {
             if (isset($data[$locale])) {
                 $result[$locale] = $data[$locale];
             }
         }
         $data = $result;
     }
     if ($type === true) {
         $type = 'all';
     }
     switch ($type) {
         case 'name_region':
             foreach ($data as &$d) {
                 $d = $d['name'] . " (" . $d['region'] . ')';
             }
             asort($data);
             break;
         case 'name':
             foreach ($data as &$d) {
                 $d = $d['name'];
             }
             asort($data);
             break;
         case false:
             return array_keys($data);
         default:
             return $data;
     }
     return $data;
 }
 protected static function getData()
 {
     if (self::$data === null) {
         $config = wa()->getConfig()->getConfigFile('currency');
         $config_path = wa()->getConfig()->getPath('config') . '/currency.php';
         $cache = new waSystemCache('config/currency' . wa()->getLocale());
         if ($config && filemtime($config_path) > $cache->getFilemtime()) {
             self::$data = array();
         } else {
             self::$data = $cache->get();
         }
         if (!self::$data) {
             self::$data = array();
             $files = waFiles::listdir(dirname(__FILE__) . "/data/");
             foreach ($files as $file) {
                 if (preg_match('/^([A-Z]{3})\\.php$/', $file, $matches)) {
                     $currency = $matches[1];
                     $file = wa()->getConfig()->getPath('system') . "/currency/data/" . $currency . ".php";
                     if (file_exists($file)) {
                         $info = (include $file);
                         $info['title'] = _ws($info['title']);
                     } else {
                         $info = array('sign' => $currency, 'title' => $currency);
                     }
                     self::$data[$currency] = $info;
                 }
             }
             foreach ($config as $cur => $info) {
                 if (!isset(self::$data[$cur])) {
                     self::$data[$cur] = $info;
                 } else {
                     foreach ($info as $k => $v) {
                         self::$data[$cur][$k] = $v;
                     }
                 }
             }
             $cache->set(self::$data);
         }
     }
     return self::$data;
 }