/** * Send API Call * * @param string Method * @param array Arguments * @return stdClass Object from returned JSON */ public function __call($method, $args) { $send = array_merge(array('key' => $this->api_key), (isset($args[0]) and is_array($args[0])) ? $args[0] : array()); if (IPS_DOC_CHAR_SET != 'UTF-8') { $send['message']['html'] = IPSText::convertCharsets($send['message']['html'], IPS_DOC_CHAR_SET, 'utf-8'); } $response = $this->cfm->postFileContents(self::URL . str_replace('_', '/', $method) . '.json', json_encode($send)); if ($json = json_decode($response)) { return $json; } return NULL; }
/** * Fetch an RSS feed's encoding, if possible * * @access protected * @return void */ protected function _fetchEncoding() { $url = $this->request['url']; if (!$url) { $this->returnJsonError($this->lang->words['ajax__no_url']); } require_once IPS_KERNEL_PATH . '/classFileManagement.php'; $fileManagement = new classFileManagement(); $xmlDocument = $fileManagement->getFileContents($url); if (!$xmlDocument) { $this->returnJsonError($this->lang->words['ajax__no_doc']); } if (preg_match("#encoding=['\"](.+?)[\"']#i", $xmlDocument, $matches)) { $this->returnJsonArray(array('encoding' => $matches[1])); } else { $this->returnJsonError($this->lang->words['ajax__no_charset']); } }
/** * Check License Key * * @access public * @return bool */ private function check() { $this->request['lkey'] = trim($this->request['lkey']); // License key is optional if (!$this->request['lkey']) { return true; } $url = IPSSetup::getSavedData('install_url'); require_once IPS_KERNEL_PATH . 'classFileManagement.php'; /*noLibHook*/ $query = new classFileManagement(); $response = $query->getFileContents("http://license.invisionpower.com/?a=check&key={$this->request['lkey']}&url={$url}"); $response = json_decode($response, true); if ($response['result'] != 'ok') { return "Your license key could not be activated. Please check your key and try again. If the problem persists, please contact technical support."; } else { IPSSetup::setSavedData('lkey', $this->request['lkey']); return TRUE; } }
/** * Check License Key * * @access public * @return bool */ private function check($init = FALSE) { $this->request['lkey'] = $init ? ipsRegistry::$settings['ipb_reg_number'] : trim($this->request['lkey']); if (!$this->request['lkey'] and !$init) { return true; } $url = ipsRegistry::$settings['board_url'] ? ipsRegistry::$settings['board_url'] : ipsRegistry::$settings['base_url']; require_once IPS_KERNEL_PATH . 'classFileManagement.php'; /*noLibHook*/ $query = new classFileManagement(); $response = $query->getFileContents("http://license.invisionpower.com/?a=check&key={$this->request['lkey']}&url={$url}"); $response = json_decode($response, true); if ($response['result'] != 'ok') { if ($this->request['ignoreError']) { return TRUE; } else { return "License key check failed. Click next to continue anyway."; } } else { IPSLib::updateSettings(array('ipb_reg_number' => $this->request['lkey'])); return TRUE; } }
/** * Fetches the JSON from the remote server and writes it */ public function buildLocalJsonCache() { /* Now fetch JSON data from the server and write it */ require_once IPS_KERNEL_PATH . 'classFileManagement.php'; /*noLibHook*/ $files = new classFileManagement(); $json = $files->getFileContents($this->getJsonUrl()); if ($json) { $cacheFile = IPS_CACHE_PATH . 'cache/skinGenJsonCache.js'; if (file_exists($cacheFile)) { @unlink($cacheFile); } file_put_contents($cacheFile, $json); @chmod($cacheFile, 0777); } else { throw new Exception("JSON_NOT_RETURNED"); } return true; }
/** * Send batch to the backup server */ public function sendBatch() { /* Fetch kernel class */ require_once IPS_KERNEL_PATH . 'classFileManagement.php'; $cfm = new classFileManagement(); /* Fetch DB data */ $tables = $this->_getDatabaseSchematics(); $sqlRows = array(); $touchedTables = array(); $bytesUsed = ''; $topId = 0; $delIds = array(); /* Do we need to restart? */ if ($this->checkForRestart()) { $this->populateLogWithAllTables(); return true; } /* Little short cut */ $p = $this->registry->dbFunctions()->getPrefix(); /* Start looping on the table */ $this->DB->build(array('select' => '*', 'from' => 'backup_queue', 'order' => 'queue_id', 'limit' => array(0, $this->Limits['rows']))); $o = $this->DB->execute(); while ($row = $this->DB->fetch($o)) { $tbl = $this->_stripPrefix($row['queue_entry_table']); $sql = ''; $fields = array(); $touchedTables[$tbl] = $tbl; if ($row['queue_entry_sql']) { $sql = $row['queue_entry_sql']; } else { /* Get fields */ foreach ($tables[$row['queue_entry_table']]['cols'] as $col) { $fields[] = $col['Field']; } if (!count($fields)) { /* Empty - so remove this queue row or we'll never progress */ $delIds[] = $row['queue_id']; continue; } /* INSERT */ if ($row['queue_entry_type'] == 1) { /* Get data */ $pKey = $row['queue_entry_key']; $pKeyVal = $this->_isConcat($pKey) ? addslashes($row['queue_entry_value']) : $row['queue_entry_value']; $data = array(); $vals = array(); $data = $this->DB->buildAndFetch(array('select' => '`' . implode("`, `", $fields) . '`', 'from' => $tbl, 'where' => $pKey . "='" . $pKeyVal . "'")); if (!is_array($data) or !count($data)) { /* Empty - so remove this queue row or we'll never progress */ $delIds[] = $row['queue_id']; continue; } foreach ($data as $k => $v) { $vals[] = $this->_makeValueSafeForQuery($v); } $sql = "INSERT INTO " . $p . $tbl . "(`" . implode("`, `", $fields) . "`) " . "VALUES( '" . implode("', '", $vals) . "');"; } } /* Got anything? */ if (!$sql) { /* Empty - so remove this queue row or we'll never progress */ $delIds[] = $row['queue_id']; continue; } /* check size */ $bytesUsed += IPSLib::strlenToBytes(strlen($sql)); /* Truth time! */ if ($bytesUsed >= $this->Limits['bytes']) { break; } else { $sqlRows[] = $sql; /* top id to remove */ $topId = $row['queue_id']; } } /* Anything to delete? */ if (count($delIds)) { $this->DB->delete('backup_queue', 'queue_id IN (' . implode(',', array_values($delIds)) . ')'); } /* What do we have? */ if ($topId && count($sqlRows)) { $dataToSend = $this->_createTextToSend($sqlRows, array_keys($touchedTables)); $returnedData = $cfm->postFileContents($this->_getBackupServerUrl(), array('backup_data' => @gzcompress($dataToSend), 'lkey' => ipsRegistry::$settings['ipb_reg_number'])); $test = json_decode(trim($returnedData), true); if (is_array($test) && $test['status'] == 'ok') { $this->DB->delete('backup_queue', 'queue_id <= ' . intval($topId)); $this->_addLog(intval($test['rows']), $test['status']); $this->Vars['rows_sent'] = intval($this->Vars['rows_sent']) + count($sqlRows); $this->Vars['rows_total'] = $this->_getStoredRowCount(); $this->_setVars(); } else { # Fail lol $this->_addLog(0, $test['status']); } } }
/** * Sends a query to the IPS Spam Service * * @access public * @param string $email Email address to check/report * @param string [$ip] IP Address to check report, ipsRegistry::member()->ip_address will be used if the address is not specified * @param string [$type] Either register or markspam, register is default * @return string */ public static function querySpamService($email, $ip = '', $type = 'register', $test = 0) { /* Get the response */ $key = ipsRegistry::$settings['spam_service_api_key']; $domain = ipsRegistry::$settings['board_url']; $ip = ip2long($ip) ? $ip : ipsRegistry::member()->ip_address; $response = false; $testConn = $test ? '&debug_mode=1' : ''; /* Get the file managemnet class */ require_once IPS_KERNEL_PATH . 'classFileManagement.php'; $query = new classFileManagement(); $query->use_sockets = 1; $query->timeout = ipsRegistry::$settings['spam_service_timeout']; /* Query the service */ $response = $query->getFileContents("http://ips-spam-service.com/api/index.php?key={$key}&domain={$domain}&type={$type}&email={$email}&ip={$ip}{$testConn}"); if (!$response) { return 'timeout'; } $response = explode("\n", $response); $responseCode = $response[0]; $responseMsg = $response[1]; if ($test) { return $responseMsg; } /* Log Request */ if ($type == 'register') { ipsRegistry::DB()->insert('spam_service_log', array('log_date' => time(), 'log_code' => $responseCode, 'log_msg' => $responseMsg, 'email_address' => $email, 'ip_address' => $ip)); } return intval($responseCode); }
/** * Make call to IPS to get API keys * * @return array */ private function _makeApiCall() { $subId = NULL; if (ipsRegistry::$settings['ipb_reg_number']) { $exploded = explode('-', ipsRegistry::$settings['ipb_reg_number']); if (isset($exploded[3])) { $subId = $exploded[3]; } } if ($subId === NULL) { $subId = ipsRegistry::$settings['board_url']; if (strlen($subId) > 32) { $subId = str_replace(array('http://', 'https://'), '', $subId); } if (strlen($subId) > 32) { $subId = md5($subId); } } require_once IPS_KERNEL_PATH . 'classFileManagement.php'; $cfm = new classFileManagement(); $return = $cfm->getFileContents("http://license.invisionpower.com/viglink/?subId=" . urlencode($subId)); if ($return and $json = @json_decode($return, TRUE) and $json['SUCCESS'] == TRUE) { return $json; } else { ipsRegistry::getClass('output')->showError(ipsRegistry::getClass('class_localization')->words['enhancements_viglink_error']); } }
/** * Delete a folder * * @access protected * @param string Path * @param bool Return instead of output * @return void */ protected function _deleteFolder($path = '', $return = false) { //----------------------------------------- // Check permissions //----------------------------------------- $this->_checkPath($path); //----------------------------------------- // Delete files and folders //----------------------------------------- require_once IPS_KERNEL_PATH . '/classFileManagement.php'; $fileManagement = new classFileManagement(); $fileManagement->removeDirectory($path); if ($return) { return true; } $this->registry->output->global_message = $this->lang->words['folder_removed']; //----------------------------------------- // Send back to the folder //----------------------------------------- $pathBits = explode('/', $folder); array_pop($pathBits); $this->registry->output->silentRedirectWithMessage($this->settings['base_url'] . 'module=media§ion=list&do=viewdir&dir=' . urlencode(implode('/', $pathBits))); }
/** * Check if there is an update for a hook * * @access private * @param string URL to check * @param string Long version number * @return bool */ private function _updateAvailable($url, $version) { if (!$version) { return false; } require_once IPS_KERNEL_PATH . '/classFileManagement.php'; $checker = new classFileManagement(); $checker->use_sockets = $this->settings['enable_sockets']; //----------------------------------------- // This is a low timeout to prevent page from taking too long //----------------------------------------- $checker->timeout = 5; $return = $checker->getFileContents(str_replace('php&', 'php?', $url . '&version=' . $version)); return $return == 1 ? true : false; }
/** * Extract: Parse RSS document from URL * * @param string URI * @return @e boolean */ public function parseFeedFromUrl($feed_location) { //----------------------------------------- // Load file management class //----------------------------------------- require_once IPS_KERNEL_PATH . '/classFileManagement.php'; /*noLibHook*/ $this->classFileManagement = new classFileManagement(); $this->classFileManagement->use_sockets = $this->use_sockets; $this->classFileManagement->auth_req = $this->auth_req; $this->classFileManagement->auth_user = $this->auth_user; $this->classFileManagement->auth_pass = $this->auth_pass; $this->classFileManagement->userAgent = $this->userAgent; //------------------------------- // Reset arrays //------------------------------- $this->rss_items = array(); $this->rss_channels = array(); //------------------------------- // Get data //------------------------------- $data = $this->classFileManagement->getFileContents($feed_location); if (count($this->classFileManagement->errors)) { $this->errors = $this->classFileManagement->errors; return FALSE; } $_foundIn = ''; if (preg_match("#encoding=[\"'](\\S+?)[\"']#si", $data, $matches)) { $this->orig_doc_type = strtoupper($matches[1]); $_foundIn = 'encoding'; } if (!$this->orig_doc_type and preg_match("#charset=(\\S+?)#si", $data, $matches)) { $this->orig_doc_type = strtoupper($matches[1]); $_foundIn = 'charset'; } //----------------------------------------- // If feed charset isn't supportd by XML lib, // convert to UTF-8 // Edit - ALWAYS use utf-8. A wide html entity (‘) is // valid in iso-8859-1 output because it is an entity, however // the XML library tries to convert all entities to their appropriate // character which corrupts it. // @link http://community.invisionpower.com/tracker/issue-33588-rss-import-character-issue // @link http://us.php.net/manual/en/function.xml-set-character-data-handler.php#35065 //----------------------------------------- $supported_encodings = array("UTF-8"); $charset = ($this->orig_doc_type and in_array($this->orig_doc_type, $supported_encodings)) ? $this->orig_doc_type : "UTF-8"; if ($this->convert_charset and $data) { if ($charset != $this->orig_doc_type) { $data = IPSText::convertCharsets($data, $this->orig_doc_type, $charset); # Replace any char-set= data if ($_foundIn == 'encoding') { $data = preg_replace("#encoding=[\"'](\\S+?)[\"']#si", "encoding=\"" . $charset . "\"", $data); } else { $data = preg_replace("#charset=(\\S+?)#si", "charset=" . $charset, $data); } } } /* Parse */ $this->_parse($data, $charset); return TRUE; }
/** * Constructor :: Authorizes the session * * @param boolean $noAutoParsingSessions No auto parsing of sessions - set as true when using API-like methods * @return @e mixed Void normally, but can print error message */ public function __construct($noAutoParsingSessions = false) { /* Make object */ $this->registry = ipsRegistry::instance(); $this->DB = $this->registry->DB(); $this->settings =& $this->registry->fetchSettings(); $this->request =& $this->registry->fetchRequest(); $this->cache = $this->registry->cache(); $this->caches =& $this->registry->cache()->fetchCaches(); $this->_member = self::instance(); $this->_memberData =& self::instance()->fetchMemberData(); /* Delete immediately */ $this->_deleteNow = true; /** * If the sso.php file is present in this folder, we'll load it. * This file can be used to easily integrate single-sign on in * situations where you need to check session data */ if (is_file(IPS_ROOT_PATH . '/sources/classes/session/sso.php')) { $classToLoad = IPSLib::loadLibrary(IPS_ROOT_PATH . '/sources/classes/session/sso.php', 'ssoSessionExtension'); if (class_exists($classToLoad)) { $this->sso = new $classToLoad($this->registry); } } //----------------------------------------- // INIT //----------------------------------------- $cookie = array(); $this->_userAgent = substr($this->_member->user_agent, 0, 200); //----------------------------------------- // Fix up app / section / module //----------------------------------------- $this->current_appcomponent = IPS_APP_COMPONENT; $this->current_module = IPSText::alphanumericalClean($this->request['module']); $this->current_section = IPSText::alphanumericalClean($this->request['section']); $this->settings['session_expiration'] = $this->settings['session_expiration'] ? $this->settings['session_expiration'] : 3600; //----------------------------------------- // Return as guest if running a task //----------------------------------------- if (IPS_IS_TASK) { self::$data_store = IPSMember::setUpGuest(); self::$data_store['last_activity'] = time(); self::$data_store['last_visit'] = time(); return true; } /* Not auto parsing sessions? */ if ($noAutoParsingSessions === true) { return true; } //----------------------------------------- // no new headers if we're simply viewing an attachment.. //----------------------------------------- if ($this->request['section'] == 'attach') { $this->settings['no_print_header'] = 1; } //----------------------------------------- // no new headers if we're updating chat //----------------------------------------- if (IPS_IS_AJAX && ($this->request['section'] != 'login' && $this->request['section'] != 'skin') or $this->request['section'] == 'attach' or $this->request['section'] == 'captcha') { $this->settings['no_print_header'] = 1; $this->do_update = 0; } //----------------------------------------- // IPS Connect //----------------------------------------- $ipsConnectEnabled = FALSE; foreach ($this->caches['login_methods'] as $k => $data) { if ($data['login_folder_name'] == 'ipsconnect' and $data['login_enabled']) { $ipsConnectEnabled = TRUE; $ipsConnectSettings = unserialize($data['login_custom_config']); } } //----------------------------------------- // Continue! //----------------------------------------- $cookie['session_id'] = IPSCookie::get('session_id'); $cookie['member_id'] = IPSCookie::get('member_id'); $cookie['pass_hash'] = IPSCookie::get('pass_hash'); if ($cookie['session_id'] && empty($this->request['_nsc'])) { $this->getSession($cookie['session_id']); $this->session_type = 'cookie'; } elseif (!empty($this->request['s'])) { $this->getSession($this->request['s']); $this->session_type = 'url'; } else { $this->session_id = 0; $this->session_type = 'url'; } //----------------------------------------- // Do we have a valid session ID? //----------------------------------------- if ($this->session_id) { $haveMember = FALSE; $forceNoMember = FALSE; /* Check we're not specifically logged out of IPS Connect */ if ($ipsConnectEnabled and isset($_COOKIE['ipsconnect_' . md5($ipsConnectSettings['master_url'])]) and !$_COOKIE['ipsconnect_' . md5($ipsConnectSettings['master_url'])]) { $forceNoMember = TRUE; } /* Check Local */ if (!empty($this->session_user_id) and !$forceNoMember) { self::setMember($this->session_user_id); if (self::$data_store['member_id'] and self::$data_store['member_id'] != 0) { $haveMember = TRUE; } } /* Check IPS Connect */ if (!$haveMember and !$forceNoMember) { if ($ipsConnectEnabled and isset($_COOKIE['ipsconnect_' . md5($ipsConnectSettings['master_url'])])) { if ($_COOKIE['ipsconnect_' . md5($ipsConnectSettings['master_url'])]) { require_once IPS_KERNEL_PATH . 'classFileManagement.php'; $cfm = new classFileManagement(); $return = $cfm->getFileContents($ipsConnectSettings['master_url'] . '?' . http_build_query(array('act' => 'cookies', 'data' => json_encode($_COOKIE)))); if ($return = @json_decode($return, TRUE)) { if ($return['connect_status'] == 'SUCCESS') { $this->_handleIpsConnect($return); $haveMember = TRUE; } } } } } /* Handle */ if ($haveMember) { $this->_updateMemberSession(); /** * If we have an SSO object, run it for the update member call */ if (is_object($this->sso) and method_exists($this->sso, 'checkSSOForMember')) { $this->sso->checkSSOForMember('update'); } } else { $this->_updateGuestSession(); /** * If we have an SSO object, run it for the update guest session call */ if (is_object($this->sso) and method_exists($this->sso, 'checkSSOForGuest')) { $this->sso->checkSSOForGuest('update'); } } } else { //----------------------------------------- // We didn't have a session, or the session didn't validate // Do we have cookies stored? //----------------------------------------- $haveMember = FALSE; if ($ipsConnectEnabled and isset($_COOKIE['ipsconnect_' . md5($ipsConnectSettings['master_url'])])) { if ($_COOKIE['ipsconnect_' . md5($ipsConnectSettings['master_url'])]) { require_once IPS_KERNEL_PATH . 'classFileManagement.php'; $cfm = new classFileManagement(); $return = $cfm->getFileContents($ipsConnectSettings['master_url'] . '?' . http_build_query(array('act' => 'cookies', 'data' => json_encode($_COOKIE)))); if ($return = @json_decode($return, TRUE)) { if ($return['connect_status'] == 'SUCCESS') { $this->_handleIpsConnect($return); $haveMember = TRUE; } } } } elseif ($cookie['member_id'] != "" and $cookie['pass_hash'] != "") { self::setMember($cookie['member_id']); if (self::$data_store['member_id'] and self::$data_store['member_login_key'] == $cookie['pass_hash'] and (!$this->settings['login_key_expire'] or time() <= self::$data_store['member_login_key_expire'])) { $haveMember = TRUE; } } //----------------------------------------- // Handle //----------------------------------------- if ($haveMember) { $this->_createMemberSession(); /** * If we have an SSO object, run it for the create member call */ if (is_object($this->sso) and method_exists($this->sso, 'checkSSOForMember')) { $this->sso->checkSSOForMember('create'); } } else { self::setMember(0); $this->_createGuestSession(); /** * If we have an SSO object, run it for the create guest call */ if (is_object($this->sso) and method_exists($this->sso, 'checkSSOForGuest')) { $this->sso->checkSSOForGuest('create'); } } } //----------------------------------------- // Knock out Google Web Accelerator //----------------------------------------- if (ipsRegistry::$settings['disable_prefetching']) { if (my_getenv('HTTP_X_MOZ') and strstr(strtolower(my_getenv('HTTP_X_MOZ')), 'prefetch') and self::$data_store['member_id']) { if (isset($_SERVER['SERVER_PROTOCOL']) and strstr($_SERVER['SERVER_PROTOCOL'], '/1.0')) { @header('HTTP/1.0 403 Forbidden'); } else { @header('HTTP/1.1 403 Forbidden'); } @header("Cache-Control: no-cache, must-revalidate, max-age=0"); @header("Expires: 0"); @header("Pragma: no-cache"); print "Prefetching or precaching is not allowed. If you have Google Accelerator enabled, please disable"; exit; } } //----------------------------------------- // Still no member id and not a bot? //----------------------------------------- if (empty(self::$data_store['member_id']) and !$this->_member->is_not_human) { self::setMember(0); self::$data_store['last_activity'] = time(); $this->request['last_visit'] = time(); } //----------------------------------------- // Set a session ID cookie //----------------------------------------- $this->_member->session_type = $this->session_type; $this->_member->session_id = $this->session_id; IPSCookie::set("session_id", $this->session_id, -1); }
/** * Flush IPS CDN Cache */ public function flushipscdn() { if (ipsRegistry::$settings['ips_cdn']) { require_once IPS_KERNEL_PATH . 'classFileManagement.php'; $cfm = new classFileManagement(); $cfm->timeout = 1; $cfm->getFileContents("http://license.invisionpower.com/?a=cdnflush&key=" . ipsRegistry::$settings['ipb_reg_number'] . "&version=" . IPB_LONG_VERSION); } }
/** * Translate externally splash * * @access public * @return void */ public function translateExtSplash() { /* INIT */ $langId = intval($this->request['id']); $mainDir = DOC_IPS_ROOT_PATH . 'translate'; $words_by_file = array(); $errors = array(); /* Start top message */ if (!is_dir($mainDir)) { /* Just bounce back asking them to create translate */ $this->registry->output->global_error = $this->lang->words['ext_no_translate_dir']; $this->languagesList(); return; } if (!is_writeable($mainDir)) { /* Just bounce back asking them to chmod translate */ $this->registry->output->global_error = $this->lang->words['ext_chmod_translate_dir']; $this->languagesList(); return; } /* Load kernel class for file management */ require_once IPS_KERNEL_PATH . 'classFileManagement.php'; $classFileManagement = new classFileManagement(); /* Get lang */ $lang = $this->DB->buildAndFetch(array('select' => '*', 'from' => 'core_sys_lang', 'where' => 'lang_id=' . $langId)); /* Get current session if one */ $session = $this->DB->buildandFetch(array('select' => '*', 'from' => 'cache_store', 'where' => 'cs_key=\'translate_session\'')); $sessionData = strstr($session['cs_value'], 'a:') ? unserialize($session['cs_value']) : array(); /* No current session? */ if (empty($sessionData['lang_id']) or !count($sessionData['files'])) { /* Ensure directory is empty */ $classFileManagement->emptyDirectory($mainDir); /* Ensure it's gone, gone */ $this->DB->delete('cache_store', 'cs_key=\'translate_session\''); $sessionData = $lang; $sessionData['files'] = array(); $header = "/*******************************************************\nNOTE: This is a translatable file generated by IP.Board " . IPB_VERSION . " (" . IPB_LONG_VERSION . ") on " . date("r") . " by " . $this->memberData['members_display_name'] . "\nPLEASE set your text editor to save this document as UTF-8 regardless of your board's character-set\n*******************************************************/\n\n"; /* Export all the languages into flat files */ $this->DB->build(array('select' => '*', 'from' => 'core_sys_lang_words', 'where' => 'lang_id=' . $langId, 'order' => 'word_custom_version DESC, word_default_version DESC')); $this->DB->execute(); while ($r = $this->DB->fetch()) { $_text = $r['word_custom'] ? $r['word_custom'] : $r['word_default']; $_version = $r['word_custom_version'] ? $r['word_custom_version'] : $r['word_default_version']; $words_by_file[$r['word_app']][$r['word_pack']][] = array($r['word_key'], $_text); } //----------------------------------------- // Now loop and write to file //----------------------------------------- foreach ($words_by_file as $app => $word_packs) { foreach ($word_packs as $pack => $words) { if ($pack == 'public_js') { $to_write = ''; $_file = 'ipb.lang.js'; foreach ($words as $word) { $word[1] = str_replace('"', '\\"', $word[1]); $to_write .= "ipb.lang['{$word[0]}']\t= \"{$word[1]}\";\n"; } } else { if ($pack == 'admin_js') { $to_write = ''; $_file = 'acp.lang.js'; foreach ($words as $word) { $word[1] = str_replace('"', '\\"', $word[1]); $to_write .= "ipb.lang['{$word[0]}']\t= \"{$word[1]}\";\n"; } } else { //----------------------------------------- // Build cache file contents //----------------------------------------- $to_write = "<?php\n\n{$header}\n\n\$lang = array( \n"; $_file = $app . '_' . $pack . '.php'; foreach ($words as $word) { $word[1] = str_replace('"', '\\"', $word[1]); $to_write .= "'{$word[0]}'\t\t\t\t=> \"{$word[1]}\",\n"; } $to_write .= " ); \n"; } } //----------------------------------------- // Convert data //----------------------------------------- $to_write = IPSText::convertCharsets($to_write, IPS_DOC_CHAR_SET, 'UTF-8'); //----------------------------------------- // Write the file //----------------------------------------- @unlink($mainDir . '/' . $_file); if ($fh = @fopen($mainDir . '/' . $_file, 'wb')) { fwrite($fh, $to_write, strlen($to_write)); fclose($fh); @chmod($mainDir . '/' . $_file, 0777); $mtime = @filemtime($mainDir . '/' . $_file); $sessionData['files'][$_file] = array('mtime' => $mtime, 'dbtime' => $mtime); } else { $errors[] = $this->lang->words['l_nowrite'] . $mainDir . '/' . $_file; } } } /* Sort files */ ksort($sessionData['files']); /* Save session */ $this->DB->insert('cache_store', array('cs_key' => 'translate_session', 'cs_value' => serialize($sessionData), 'cs_extra' => '', 'cs_array' => 1, 'cs_updated' => time())); } else { /* Update mtime */ foreach ($sessionData['files'] as $file => $data) { $sessionData['files'][$file]['mtime'] = @filemtime($mainDir . '/' . $file); } } //----------------------------------------- // Output //----------------------------------------- $this->registry->output->extra_nav[] = array("{$this->settings['base_url']}&{$this->form_code}&do=translateExtSplash&id={$sessionData['lang_id']}", "{$this->lang->words['ext_title_for']} {$sessionData['lang_title']}"); $this->registry->output->html .= $this->html->languages_translateExt($sessionData, $lang); }