INSTALL_DIR)); } } else { define('TYPE_UPDATE',0); define('TYPE_SYSTEM',0); if (file_exists('./eyeOS/')) { define('TYPE_INSTALL',2); } else { define('TYPE_INSTALL',1); } } // Check file permissions if (file_exists(INSTALL_INDEX) && (!is_readable(INSTALL_INDEX) || !is_writable(INSTALL_INDEX)) && !@chmod(INSTALL_INDEX,0777)) { $errors[] = lang_translate('installer-lib-check-permissions','Warning: Please, give full permissions (CHMOD 777) to "[file]".',array('[file]' => INSTALL_INDEX)); } unset($array); if (TYPE_INSTALL == 2 || TYPE_UPDATE == 2) { $array[] = './eyeOS/'; } $array[] = INSTALL_DIR; if (TYPE_INSTALL === 1 || TYPE_UPDATE === 1) { $array[] = INSTALL_PACKAGE; } if (TYPE_UPDATE || TYPE_SYSTEM) { $array[] = INSTALL_PACKAGE; $array[] = './settings.php'; } $checked = check_permissions($array); if (is_array($checked) && is_array($errors)) { $errors = array_merge($errors,$checked); } elseif (is_array($checked)) { $errors = $checked; } // Check gzip support if (!function_exists('gzopen') && (TYPE_INSTALL === 1 || TYPE_UPDATE === 1)) { $errors[] = lang_translate('installer-lib-check-gzip','Your server does not seem to have gzip support. To install eyeOS manually, rename "[package]" to "package.tar.gz" and extract the contents into the same directory.',array('[package]' => INSTALL_PACKAGE)); } // Output errors if ($errors) { output_errors($errors); } else { return true; } } function check_permissions($files) { foreach ($files as $file) { if ($file == INSTALL_PACKAGE) { if (md5_file(INSTALL_PACKAGE) != INSTALL_MD5){ $errors[] = lang_translate('installer-lib-check-md5','Warning: Please, check "[package]" since it seems to be corrupted.',array('[package]' => INSTALL_PACKAGE)); } } if (!file_exists($file)) { $errors[] = lang_translate('installer-lib-check-notexist','Error: "[file]" does not exist.',array('[file]' => $file)); } elseif (!is_readable($file) || !is_writable($file)) { if (!@chmod($file,0777)) { $errors[] = lang_translate('installer-lib-check-permissions','Warning: Please, give full permissions (CHMOD 777) to "[file]".',array('[file]' => $file)); } } } if ($errors) { return $errors; } else { return true; } } function check_utf8() { $UTF8array = array(); if (extension_loaded('mbstring') || function_exists('mb_substr') || preg_match('/^.{1}$/u',"ñ",$UTF8array) != 1) { return true; } else { return false; } } function check_version($one) { if (strrchr($one,'preview')) { $a[5] = substr(strrchr($one,'preview'),7); $one = substr($one,0,- strlen(strrchr($one,'preview'))); } elseif (!$a[5]) { $a[5] = 9999; } if (strrpos($one,'-')) { $a[4] = substr(strrchr($one,'-'),1); $one = substr($one,0,- strlen(strrchr($one,'-'))); } $one .= '.'; if (strpos($one,'.') !== false) { $a[0] = substr($one,0,strpos($one,'.')); $one = substr($one,1 + strpos($one,'.')); } if (strpos($one,'.') !== false) { $a[1] = substr($one,0,strpos($one,'.')); $one = substr($one,1 + strpos($one,'.')); } if (strpos($one,'.') !== false) { $a[2] = substr($one,0,strpos($one,'.')); $one = substr($one,1 + strpos($one,'.')); } $a[3] = $one; for ($i = 0;$i < 6;$i++) { if ($a[$i] == 'x') { $a[$i] = 9999; } else { $a[$i] = floatval($a[$i]); } } ksort($a); return $a; } function check_versions($one,$two) { $one = check_version($one); $two = check_version($two); for ($i = 0;$i < 6;$i++) { if (intval($one[$i]) > intval($two[$i])) { return 1; } elseif (intval($one[$i]) < intval($two[$i])) { return 2; } } return 0; } function check_version_uasort($one,$two) { $checked = check_versions($one,$two); if ($checked == 2) { return -1; } else { return $checked; } } function lang_init() { if (!$_SESSION['lang'] || $_REQUEST['lang']) { $langs = lang_getAll(1); // Use lang from URL $request_lang = htmlspecialchars($_REQUEST['lang'],ENT_QUOTES,'UTF-8'); if ($request_lang) { if (in_array($request_lang,$langs)) { $_SESSION['lang'] = $request_lang; } elseif (in_array(substr($request_lang,0,2),$langs)) { $_SESSION['lang'] = substr($request_lang,0,2); } } // Use lang from the user's browser if (!$_SESSION['lang']) { $temp_user_langs = explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']); foreach ($temp_user_langs as $user_lang) { $user_lang = substr($user_lang,0,strlen($user_lang) - strlen(strstr($user_lang,';'))); $user_langs[] = substr($user_lang,0,strlen($user_lang) - strlen(strstr($user_lang,'-'))); } foreach ($user_langs as $user_lang) { if (!$_SESSION['lang'] && in_array($user_lang,$langs)) { $_SESSION['lang'] = $user_lang; } } if (!$_SESSION['lang']) { foreach ($user_langs as $user_lang) { if (!$_SESSION['lang'] && in_array(substr($user_lang,0,2),$langs)) { $_SESSION['lang'] = substr($user_lang,0,2); } } // If the current session doesn't have a lang, set the default if (!$_SESSION['lang']) { $_SESSION['lang'] = 'en'; } } } } global $translation; $translation = array(); if (file_exists(INSTALL_DIR . 'langs/' . $_SESSION['lang'] . '/default.xml')) { $xml = xml_xml2array(file_get_contents(INSTALL_DIR . 'langs/' . $_SESSION['lang'] . '/default.xml')); foreach ($xml['translation'][0] as $key => $value) { $translation[$key] = $value[0]; } } } function lang_getAll($easy = 0) { if ($easy) { $langs[] = 'en'; } else { $temp_en['en']['author'] = 'eyeOS Team'; $temp_en['en']['name'] = 'English'; } if ($handler = @opendir(INSTALL_DIR . 'langs/')) { while (($folder = readdir($handler)) !== false) { if ($folder != '.' && $folder != '..' && $folder != 'en' && file_exists(INSTALL_DIR . 'langs/' . $folder . '.xml')) { if ($easy) { $langs[] = $folder; } else { $xml = xml_xml2array(file_get_contents(INSTALL_DIR . 'langs/' . $folder . '.xml')); $temp_langs[$folder]['author'] = $xml['lang'][0]['author'][0]; $temp_langs[$folder]['name'] = $xml['lang'][0]['name'][0]; } } } closedir($handler); } if ($easy) { sort($langs); return $langs; } else { ksort($temp_langs); return array_merge($temp_en,$temp_langs); } } function lang_translate($key,$value,$tokens = array()) { global $translation; if (isset($translation[$key])) { $return = $translation[$key]; } else { $return = $value; } foreach ($tokens as $key_array => $value_array) { $return = str_replace($key_array,$value_array,$return); } return $return; } function output_do($content,$style,$title = '',$langselector = 1) { header('Vary: Accept'); if (!$_SERVER['HTTP_ACCEPT'] || stristr($_SERVER['HTTP_ACCEPT'],'application/xhtml+xml')) { header('Content-Type: application/xhtml+xml; charset=UTF-8'); } else { header('Content-Type: text/html; charset=UTF-8'); } echo '
'; if ($style) { echo ''; } if (in_array($_SESSION['lang'],array('fa'))) { echo ''; } echo '