Файл: adultscript-2.0.3-pro/files/install/functions.php
Строк: 101
<?php
defined('_VALID') or die('Restricted Access!');
function get_uri($strip=FALSE)
{
$request = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : NULL;
$query = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : NULL;
if (!isset($query)) {
$query = array_pad(explode('?', $request), 2, false);
$query = isset($query['1']) ? $query['1'] : NULL;
}
if (isset($_SERVER['SERVER_NAME'])) {
$domain = $_SERVER['SERVER_NAME'];
} elseif (isset($_SERVER['HTTP_HOST'])) {
$domain = $_SERVER['HTTP_HOST'];
} elseif (isset($_SERVER['SERVER_ADDR'])) {
$domain = $_SERVER['SERVER_ADDR'];
} else {
$domain = 'localhost';
}
$domain = strtolower($domain);
if (!preg_match('/^[?(?:[a-z0-9-:]_]+.?)+$/', $domain)) {
header('HTTP/1.1 400 Bad Request');
exit;
}
$scheme = 'http';
if (isset($_SERVER['SERVER_PROTOCOL'])) {
$scheme = explode('/', $_SERVER['SERVER_PROTOCOL']);
$scheme = strtolower($scheme['0']);
}
$port = NULL;
if (isset($_SERVER['SERVER_PORT']) && !strpos($domain, ':') &&
($scheme == 'http' && $_SERVER['SERVER_PORT'] != 80) &&
($scheme == 'https' && $_SERVER['SERVER_PORT'] != 443)) {
$port = (int) $_SERVER['SERVER_PORT'];
}
$path = isset($_SERVER['SCRIPT_NAME']) ? trim($_SERVER['SCRIPT_NAME']) : NULL;
if (!isset($path)) {
$path = isset($_SERVER['PHP_SELF']) ? trim($_SERVER['PHP_SELF']) : NULL;
}
if (isset($path)) {
if ($path != '/') {
$path = dirname($path);
}
if (strpos($path, '/admin') !== FALSE) {
$path = str_replace('/admin', '', $path);
}
if (strpos($path, '/install') !== FALSE) {
$path = str_replace('/install', '', $path);
}
if ($strip !== FALSE) {
$path = str_replace($strip, '', $path);
}
}
$base = (isset($path) && $path != '/') ? $path : '';
$port = (isset($port)) ? ':' .$port : '';
$url = $scheme. '://'.$domain.$port.$request;
$url = urldecode($url);
$url = htmlspecialchars($url, ENT_QUOTES, 'UTF-8');
$url = preg_replace('/eval((.*))/', '', $url);
$url = str_replace('javascript:', '', $url);
$uri = array();
$uri['current_url'] = $url;
$uri['base_url'] = $scheme. '://'.$domain.$port.$base;
$uri['relative_url'] = ($base != '') ? $base : '';
$uri['admin_url'] = $uri['base_url']. '/admin';
if (!parse_url($url)) {
die('Failed to cache uri! Aborting!');
}
return $uri;
}
function language_add($code, $type, $name, $key, $value)
{
$db = VF::factory('database');
$db->query("SELECT file
FROM #__language_files
WHERE code = '".$db->escape($code)."'
AND name = '".$db->escape($name)."'
AND type = '".$db->escape($type)."'
LIMIT 1");
if ($db->affected_rows()) {
$file = unserialize($db->fetch_field('file'));
if (is_array($key)) {
foreach ($key as $index => $translation) {
$file[$index] = $translation;
}
} else {
$file[$key] = $value;
}
$db->query("UPDATE #__language_files
SET file = '".$db->escape(serialize($file))."'
WHERE code = '".$db->escape($code)."'
AND name = '".$db->escape($name)."'
AND type = '".$db->escape($type)."'
LIMIT 1");
} else {
$file = array();
foreach ($key as $index => $translation) {
$file[$index] = $translation;
}
$db->query("INSERT INTO #__language_files
SET file = '".$db->escape(serialize($file))."',
code = '".$db->escape($code)."',
name = '".$db->escape($name)."',
type = '".$db->escape($type)."'");
}
}
function language_del($code, $type, $name, $key)
{
$db = VF::factory('database');
$db->query("SELECT file
FROM #__language_files
WHERE code = '".$db->escape($code)."'
AND name = '".$db->escape($name)."'
AND type = '".$db->escape($type)."'
LIMIT 1");
if ($db->affected_rows()) {
$file = unserialize($db->fetch_field('file'));
if (is_array($key)) {
foreach ($key as $item) {
if (isset($file[$item])) {
unset($file[$item]);
}
}
} else {
if (isset($file[$key])) {
unset($file[$key]);
}
}
$db->query("UPDATE #__language_files
SET file = '".$db->escape(serialize($file))."'
WHERE code = '".$db->escape($code)."'
AND name = '".$db->escape($name)."'
AND type = '".$db->escape($type)."'
LIMIT 1");
}
}
function get_domain($domain)
{
$domain = str_replace('http://', '', $domain);
if (strpos($domain, '/') !== false) {
$domain = substr($domain, 0, strrpos($domain, '/'));
}
if (preg_match('/(?P<domain>[a-z0-9][a-z0-9-]{1,63}.[a-z.]{2,6})$/i', $domain, $regs)) {
return $regs['domain'];
}
return false;
}
function generate_license()
{
$key = '';
for ($i=0; $i<=11; $i++) {
$key .= rand(0, 9);
}
return $key;
}
function update_config($option, $value = null)
{
$cfg = VCfg::group('core.config');
$cfg_file = require BASE_DIR.'/config.php';
foreach ($cfg_file as $key => $val) {
if (isset($cfg[$key])) {
unset($cfg['key']);
}
}
if (is_array($option)) {
foreach ($option as $key => $value) {
$cfg[$key] = $value;
}
} else {
$cfg[$option] = $value;
}
$db = VF::factory('database');
$db->query("UPDATE #__config
SET config_cache = '".$db->escape(serialize($cfg))."'
WHERE name = '".$db->escape($cfg_file['default'])."'
LIMIT 1");
VCfg::cache_del('config', 'config');
}