Files
Kleeja/install/includes/functions_install.php

239 lines
5.6 KiB
PHP
Raw Normal View History

2018-01-09 02:09:07 +03:00
<?php
/**
*
* @package install
* @copyright (c) 2007 Kleeja.com
* @license ./docs/license.txt
*
*/
2019-05-03 23:52:08 +03:00
// Requirements of Kleeja
2018-01-09 02:09:07 +03:00
define('MIN_PHP_VERSION', '7.0');
define('MIN_MYSQL_VERSION', '4.2.2');
//version of latest changes at db
2019-05-03 23:52:08 +03:00
define ('LAST_DB_VERSION', '9');
2018-01-09 02:09:07 +03:00
//set no errors
define('MYSQL_NO_ERRORS', true);
// Detect choosing another lang while installing
2019-05-03 23:52:08 +03:00
if (ig('change_lang'))
2018-01-09 02:09:07 +03:00
{
2019-05-03 23:52:08 +03:00
if (ip('lang'))
{
header('Location: ' . $_SERVER['PHP_SELF'] . '?step=' . p('step_is') . '&lang=' . p('lang'));
}
2018-01-09 02:09:07 +03:00
}
// Including current language
2019-05-08 02:07:47 +03:00
$lang = require PATH . 'lang/' . getlang() . '/common.php';
$lang = array_merge($lang, require PATH . 'lang/' . getlang() . '/install.php');
2018-01-09 02:09:07 +03:00
$IN_DEV = false;
// Exceptions for development
2019-05-08 02:07:47 +03:00
if (file_exists(PATH . '.svn/entries') || file_exists('dev.txt'))
2018-01-09 02:09:07 +03:00
{
2019-05-03 23:52:08 +03:00
define('DEV_STAGE', true);
$IN_DEV = true;
2018-01-09 02:09:07 +03:00
}
/**
* Return current language of installing wizard
2019-05-03 23:52:08 +03:00
* @param bool $link
2018-01-09 02:09:07 +03:00
* @return mixed|string
*/
function getlang ($link = false)
{
2019-05-03 23:52:08 +03:00
if (ig('lang'))
{
$lang = preg_replace('/[^a-z0-9]/i', '', g('lang', 'str', 'en'));
2018-01-09 02:09:07 +03:00
2019-05-08 02:07:47 +03:00
$ln = file_exists(PATH . 'lang/' . $lang . '/install.php') ? $lang : 'en';
2019-05-03 23:52:08 +03:00
}
else
{
$ln = 'en';
}
2018-01-09 02:09:07 +03:00
2019-05-03 23:52:08 +03:00
return $link ? 'lang=' . $ln : $ln;
2018-01-09 02:09:07 +03:00
}
function getjquerylink()
{
2019-05-08 02:07:47 +03:00
if (file_exists(PATH . 'admin/Masmak/js/jquery.min.js'))
2019-05-03 23:52:08 +03:00
{
2019-05-08 02:07:47 +03:00
return PATH . 'admin/Masmak/js/jquery.min.js';
2019-05-03 23:52:08 +03:00
}
else
{
return 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js';
}
2018-01-09 02:09:07 +03:00
}
/**
* Parsing installing templates
*/
function gettpl($tplname)
{
2019-05-08 02:07:47 +03:00
global $lang;
2018-01-09 02:09:07 +03:00
2019-05-03 23:52:08 +03:00
$tpl = preg_replace('/{{([^}]+)}}/', '<?php \\1 ?>', file_get_contents('style/' . $tplname));
ob_start();
eval('?> ' . $tpl . '<?php ');
$stpl = ob_get_contents();
ob_end_clean();
2018-01-09 02:09:07 +03:00
2019-05-03 23:52:08 +03:00
return $stpl;
2018-01-09 02:09:07 +03:00
}
/**
* Export config
*/
2019-05-08 02:07:47 +03:00
function do_config_export($srv, $usr, $pass, $nm, $prf)
2018-01-09 02:09:07 +03:00
{
$data = '<?php' . "\n\n" . '//fill these variables with your data' . "\n";
2019-05-03 23:52:08 +03:00
$data .= '$dbserver = \'' . str_replace("'", "\'", $srv) . "'; //database server \n";
$data .= '$dbuser = \'' . str_replace("'", "\'", $usr) . "' ; // database user \n";
$data .= '$dbpass = \'' . str_replace("'", "\'", $pass) . "'; // database password \n";
$data .= '$dbname = \'' . str_replace("'", "\'", $nm) . "'; // database name \n";
2018-01-09 02:09:07 +03:00
$data .= '$dbprefix = \'' . str_replace("'", "\'", $prf) . "'; // if you use prefix for tables , fill it \n";
2019-05-08 02:07:47 +03:00
2019-05-03 23:52:08 +03:00
$written = false;
2019-05-08 02:07:47 +03:00
if (is_writable(PATH))
2019-05-03 23:52:08 +03:00
{
2019-05-08 02:07:47 +03:00
$fh = @fopen(PATH . 'config.php', 'wb');
2019-05-03 23:52:08 +03:00
if ($fh)
{
fwrite($fh, $data);
fclose($fh);
$written = true;
}
}
if (! $written)
{
header('Content-Type: text/x-delimtext; name="config.php"');
header('Content-disposition: attachment; filename=config.php');
echo $data;
exit;
}
return true;
2018-01-09 02:09:07 +03:00
}
/**
* Usefull to caluculte time of execution
*/
function get_microtime()
{
2019-05-03 23:52:08 +03:00
list($usec, $sec) = explode(' ', microtime());
return ((float) $usec + (float) $sec);
2018-01-09 02:09:07 +03:00
}
/**
* Get config value from database directly, if not return false.
*/
function inst_get_config($name)
{
2019-05-03 23:52:08 +03:00
global $SQL, $dbprefix;
if (! $SQL)
{
global $dbserver, $dbuser, $dbpass, $dbname;
2018-01-09 02:09:07 +03:00
2019-05-03 23:52:08 +03:00
if (! isset($dbserver))
{
return false;
}
2018-01-09 02:09:07 +03:00
$SQL = new KleejaDatabase($dbserver, $dbuser, $dbpass, $dbname);
2019-05-03 23:52:08 +03:00
}
if (! $SQL)
{
return false;
}
$sql = "SELECT value FROM `{$dbprefix}config` WHERE `name` = '" . $name . "'";
$result = $SQL->query($sql);
if ($SQL->num_rows($result) == 0)
{
return false;
}
else
{
$current_ver = $SQL->fetch_array($result);
return $current_ver['value'];
}
2018-01-09 02:09:07 +03:00
}
/**
* trying to detect cookies settings
*/
function get_cookies_settings()
{
2019-05-03 23:52:08 +03:00
$server_port = ! empty($_SERVER['SERVER_PORT']) ? (int) $_SERVER['SERVER_PORT'] : (int) @getenv('SERVER_PORT');
$server_name = $server_name = (! empty($_SERVER['HTTP_HOST'])) ? strtolower($_SERVER['HTTP_HOST']) : ((! empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : @getenv('SERVER_NAME'));
// HTTP HOST can carry a port number...
if (strpos($server_name, ':') !== false)
{
$server_name = substr($server_name, 0, strpos($server_name, ':'));
}
2018-01-09 02:09:07 +03:00
2019-05-03 23:52:08 +03:00
$cookie_secure = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ? true : false;
$cookie_name = 'klj_' . strtolower(substr(str_replace('0', 'z', base_convert(md5(mt_rand()), 16, 35)), 0, 5));
2018-01-09 02:09:07 +03:00
2019-05-03 23:52:08 +03:00
$name = (! empty($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : getenv('PHP_SELF');
2018-01-09 02:09:07 +03:00
2019-05-03 23:52:08 +03:00
if (! $name)
{
$name = (! empty($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : @getenv('REQUEST_URI');
}
2018-01-09 02:09:07 +03:00
2019-05-03 23:52:08 +03:00
$script_path = trim(dirname(str_replace(['\\', '//'], '/', $name)));
2018-01-09 02:09:07 +03:00
2019-05-03 23:52:08 +03:00
if ($script_path !== '/')
{
if (substr($script_path, -1) == '/')
{
$script_path = substr($script_path, 0, -1);
}
2018-01-09 02:09:07 +03:00
2019-05-03 23:52:08 +03:00
$script_path = str_replace(['../', './'], '', $script_path);
2018-01-09 02:09:07 +03:00
2019-05-03 23:52:08 +03:00
if ($script_path[0] != '/')
{
$script_path = '/' . $script_path;
}
}
2018-01-09 02:09:07 +03:00
2019-05-03 23:52:08 +03:00
$cookie_domain = $server_name;
2018-01-09 02:09:07 +03:00
2019-05-03 23:52:08 +03:00
if (strpos($cookie_domain, 'www.') === 0)
{
$cookie_domain = str_replace('www.', '.', $cookie_domain);
}
2018-01-09 02:09:07 +03:00
2019-05-03 23:52:08 +03:00
return [
'server_name' => $server_name,
'cookie_secure' => $cookie_secure,
'cookie_name' => $cookie_name,
'cookie_domain' => $cookie_domain,
'cookie_path' => str_replace('/install', '', $script_path),
];
2018-01-09 02:09:07 +03:00
}