/**
  * Lists currently installed languages
  *
  * @return	@e void
  */
 public function languagesList()
 {
     /* Do we have a valid translation session? */
     $sessionData = $this->cache->getCache('translate_session');
     $hasTranslate = false;
     /* Check */
     if (!empty($sessionData['lang_id']) and count($sessionData['files'])) {
         $hasTranslate = true;
     }
     /* Fallback for the recache all button */
     $forceEnglish = IPSCookie::get('forceEnglish');
     if (!$this->lang->words['language_list_recache'] || $forceEnglish) {
         $this->lang->words['language_list_recache'] = 'Recache all...';
     }
     //-----------------------------------------
     // Get languages
     //-----------------------------------------
     $rows = array();
     $this->DB->build(array('select' => '*', 'from' => 'core_sys_lang'));
     $this->DB->execute();
     while ($r = $this->DB->fetch()) {
         /* Get Local Data */
         //setlocale( LC_ALL, $r['lang_short'] );
         IPSLib::setlocale($r['lang_short']);
         $this->registry->class_localization->local_data = localeconv();
         $_menu = array();
         if ($r['lang_protected'] && !IN_DEV) {
             $_menu[] = array("", $this->lang->words['lang_pack_protected'], 'edit');
         } else {
             $_menu[] = array("{$this->settings['base_url']}{$this->form_code}&do=list_word_packs&id={$r['lang_id']}", $this->lang->words['language_list_translate'], 'info');
             /* If we don't have a current session... */
             if (!$hasTranslate) {
                 $_menu[] = array("{$this->settings['base_url']}{$this->form_code}&do=translateExtSplash&id={$r['lang_id']}", $this->lang->words['language_list_translate_ext'], 'info');
             }
         }
         $_menu[] = array("{$this->settings['base_url']}{$this->form_code}&do=copy_lang_pack&id={$r['lang_id']}", $this->lang->words['language_list_copy']);
         $_menu[] = array("{$this->settings['base_url']}{$this->form_code}&do=export&id={$r['lang_id']}", $this->lang->words['l_xmlexportfull'], 'export');
         if ($r['lang_id']) {
             $_menu[] = array("{$this->settings['base_url']}{$this->form_code}&do=rebuildFromXml&id={$r['lang_id']}&type=public", $this->lang->words['rebuild_lang_from_xml']);
         }
         foreach (ipsRegistry::$applications as $app_dir => $app_data) {
             $_menu[] = array("{$this->settings['base_url']}{$this->form_code}&do=export&id={$r['lang_id']}&app_dir={$app_dir}", $this->lang->words['l_xmlexport'] . $app_data['app_title'], 'export');
         }
         //-----------------------------------------
         // Data for output
         //-----------------------------------------
         $rows[] = array('title' => $r['lang_title'], 'local' => $r['lang_short'], 'date' => $this->registry->class_localization->getDate(time(), 'long', 1) . '<br />' . $this->registry->class_localization->getDate(time(), 'short', 1), 'money' => $this->registry->class_localization->formatMoney('12345231.12', 0), 'default' => $r['lang_default'], 'menu' => $_menu, 'id' => $r['lang_id'], 'protected' => $r['lang_protected']);
     }
     //-----------------------------------------
     // Reset locale
     //-----------------------------------------
     IPSLib::setlocale($this->registry->class_localization->local);
     //setlocale( LC_ALL, $this->registry->class_localization->local );
     $this->registry->class_localization->local_data = localeconv();
     //-----------------------------------------
     // Output
     //-----------------------------------------
     $this->registry->output->html .= $this->html->languages_list($rows, $hasTranslate);
 }
 /**
  * Constructor
  * 
  * @access	public
  * @param	string	[$lang]		Language file to load, english by default
  * @return	@e void
  */
 public function __construct(ipsRegistry $registry)
 {
     /* Make objects */
     $this->DB = $registry->DB();
     $this->settings = $registry->fetchSettings();
     $this->member = $registry->member();
     $this->cache = $registry->cache();
     $this->caches =& $registry->cache()->fetchCaches();
     $this->request = $registry->fetchRequest();
     $this->memberData =& $registry->member()->fetchMemberData();
     /* Prevent notices */
     $this->memberData['member_id'] = !isset($this->memberData['member_id']) ? 0 : $this->memberData['member_id'];
     /* Load from database */
     if ($this->settings['safe_mode_skins'] && !IN_DEV) {
         $this->load_from_db = true;
     }
     /* Rebuild the cache if needed */
     if (!$this->caches['lang_data']) {
         $this->rebuildLanguagesCache();
     }
     /* Find the lang we need */
     if ($this->caches['lang_data']) {
         foreach ($this->caches['lang_data'] as $_lang) {
             $this->languages[] = $_lang;
             if ($_lang['lang_default']) {
                 $this->local = $_lang['lang_short'];
                 $this->lang_id = $_lang['lang_id'];
                 $this->language_dir = $_lang['lang_id'];
                 $this->_isRtl = intval($_lang['lang_isrtl']);
                 /* Guests get the default */
                 if (!$this->memberData['member_id']) {
                     $this->member->language_id = $this->lang_id;
                 }
             }
         }
     }
     /* Got a guest cookie? */
     if (!$this->memberData['member_id']) {
         $langCookie = IPSCookie::get('language');
         if ($langCookie) {
             $this->member->language_id = trim(IPSText::parseCleanValue($langCookie));
         }
     }
     /* Forcing Engrish? */
     if ($forceCookie = IPSCookie::get('forceEnglish')) {
         if ($forceCookie) {
             $this->_forceEnglish = true;
         }
     }
     //-----------------------------------------
     // Time options
     //-----------------------------------------
     /* 	%b is month abbr
     			%B is full month
     			%d is date 01-31
     			%Y is 4 digit year
     			%g is 2 digit year
     			%I is hour 01-12
     			%H - hour as a decimal number using a 24-hour clock (range 00 to 23) 
     			%M is min 01-59
     			%p is am/pm */
     $this->time_options = array('JOINED' => $this->settings['clock_joined'] ? $this->settings['clock_joined'] : '%d-%B %y', 'SHORT' => $this->settings['clock_short'] ? $this->settings['clock_short'] : '%b %d %Y %I:%M %p', 'LONG' => $this->settings['clock_long'] ? $this->settings['clock_long'] : '%d %B %Y - %I:%M %p', 'TINY' => $this->settings['clock_tiny'] ? $this->settings['clock_tiny'] : '%d %b %Y - %H:%M', 'DATE' => $this->settings['clock_date'] ? $this->settings['clock_date'] : '%d %b %Y', 'SHORT2' => $this->settings['clock_short2'] ? $this->settings['clock_short2'] : '%d %B %Y', 'TIME' => '%I:%M %p', 'ACP' => '%d %B %Y, %H:%M', 'ACP2' => '%d %B %Y, %H:%M', 'YMD' => '%Y-%m-%d');
     //--------------------------------
     // Did we choose a language?
     //--------------------------------
     if (!empty($this->request['setlanguage']) and $this->request['langid']) {
         /* Forcing english? */
         if ($this->request['langid'] == '__english__') {
             IPSDebug::addMessage("forceEnglish cookie written");
             IPSCookie::set('forceEnglish', 1, 0);
             $this->_forceEnglish = true;
         } else {
             if ($this->request['k'] == $this->member->form_hash and is_array(ipsRegistry::cache()->getCache('lang_data')) and count(ipsRegistry::cache()->getCache('lang_data'))) {
                 foreach (ipsRegistry::cache()->getCache('lang_data') as $data) {
                     if ($data['lang_id'] == $this->request['langid']) {
                         if ($this->memberData['member_id']) {
                             /* Rest variables to prevent loop when this class is next constructed */
                             unset(ipsRegistry::$request['langid']);
                             unset(ipsRegistry::$request['setlanguage']);
                             IPSMember::save($this->memberData['member_id'], array('core' => array('language' => $data['lang_id'])));
                         } else {
                             IPSCookie::set('language', $data['lang_id']);
                         }
                         $this->member->language_id = $data['lang_id'];
                         $this->member->setProperty('language', $data['lang_id']);
                         break;
                     }
                 }
             }
         }
     }
     //--------------------------------
     // Now set it
     //--------------------------------
     if ($this->member->language_id) {
         foreach ($this->caches['lang_data'] as $_lang) {
             if ($_lang['lang_id'] == $this->member->language_id) {
                 $this->local = $_lang['lang_short'];
                 $this->lang_id = $_lang['lang_id'];
                 $this->language_dir = $_lang['lang_id'];
                 $this->_isRtl = intval($_lang['lang_isrtl']);
                 break;
             }
         }
     }
     //-----------------------------------------
     // Set locale
     //-----------------------------------------
     //setlocale( LC_ALL, $this->local );
     IPSLib::setlocale($this->local);
     $this->local_data = localeconv();
     //-----------------------------------------
     // Using in_dev override
     //-----------------------------------------
     if (IN_DEV and !$this->_forceEnglish) {
         if (is_dir(IPS_CACHE_PATH . 'cache/lang_cache/master_lang')) {
             $this->lang_id = 'master_lang';
         }
     }
 }