mirror of
https://github.com/kleeja-official/kleeja.git
synced 2025-12-16 04:59:42 +01:00
coding style fixes
This commit is contained in:
@@ -7,55 +7,56 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#not for directly open
|
||||
if (!defined('IN_KLEEJA'))
|
||||
//not for directly open
|
||||
if (! defined('IN_KLEEJA'))
|
||||
{
|
||||
exit();
|
||||
exit();
|
||||
}
|
||||
|
||||
#we are in the common file
|
||||
//we are in the common file
|
||||
define('IN_COMMON', true);
|
||||
|
||||
|
||||
#filename of config.php
|
||||
//filename of config.php
|
||||
define('KLEEJA_CONFIG_FILE', 'config.php');
|
||||
|
||||
#plugins folder
|
||||
//plugins folder
|
||||
define('KLEEJA_PLUGINS_FOLDER', 'plugins');
|
||||
|
||||
|
||||
|
||||
if(@extension_loaded('apc'))
|
||||
if (@extension_loaded('apc'))
|
||||
{
|
||||
define('APC_CACHE', true);
|
||||
define('APC_CACHE', true);
|
||||
}
|
||||
|
||||
#path
|
||||
if(!defined('PATH'))
|
||||
//path
|
||||
if (! defined('PATH'))
|
||||
{
|
||||
if(!defined('__DIR__'))
|
||||
if (! defined('__DIR__'))
|
||||
{
|
||||
define('__DIR__', dirname(__FILE__));
|
||||
}
|
||||
define('PATH', str_replace(DIRECTORY_SEPARATOR . 'includes', '', __DIR__) . DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
#no config
|
||||
if (!file_exists(PATH . KLEEJA_CONFIG_FILE))
|
||||
//no config
|
||||
if (! file_exists(PATH . KLEEJA_CONFIG_FILE))
|
||||
{
|
||||
header('Location: ./install/index.php');
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
#there is a config
|
||||
//there is a config
|
||||
require_once PATH . KLEEJA_CONFIG_FILE;
|
||||
|
||||
|
||||
#admin files path
|
||||
//admin files path
|
||||
define('ADM_FILES_PATH', PATH . 'includes/adm');
|
||||
|
||||
#Report all errors, except notices
|
||||
//Report all errors, except notices
|
||||
error_reporting( defined('DEV_STAGE') ? E_ALL : E_ALL ^ E_NOTICE);
|
||||
|
||||
|
||||
@@ -64,50 +65,55 @@ error_reporting( defined('DEV_STAGE') ? E_ALL : E_ALL ^ E_NOTICE);
|
||||
*/
|
||||
function kleeja_show_error($error_number, $error_string = '', $error_file = '', $error_line = '')
|
||||
{
|
||||
switch ($error_number)
|
||||
{
|
||||
case E_NOTICE: case E_WARNING: case E_USER_WARNING: case E_USER_NOTICE: case E_STRICT: break;
|
||||
default:
|
||||
header('HTTP/1.1 503 Service Temporarily Unavailable');
|
||||
echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">' . "\n<head>\n";
|
||||
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />' . "\n";
|
||||
echo '<title>Kleeja Error</title>' . "\n" . '<style type="text/css">' . "\n\t";
|
||||
echo '.error {color: #333;background:#ffebe8;float:left;width:73%;text-align:left;margin-top:10px;border: 1px solid #dd3c10; padding: 10px;font-family:tahoma,arial;font-size: 12px;}' . "\n";
|
||||
echo "</style>\n</head>\n<body>\n\t" . '<div class="error">' . "\n\n\t\t<h2>Kleeja error : </h2><br />" . "\n";
|
||||
echo "\n\t\t<strong> [ " . $error_number . ':' . basename($error_file) . ':' . $error_line . ' ] </strong><br /><br />' . "\n\t\t" . $error_string . "\n\t";
|
||||
echo "\n\t\t" . '<br /><br /><small>Visit <a href="http://www.kleeja.com/" title="kleeja">Kleeja</a> Website for more details.</small>' . "\n\t";
|
||||
echo "</div>\n</body>\n</html>";
|
||||
global $SQL;
|
||||
if(isset($SQL))
|
||||
{
|
||||
@$SQL->close();
|
||||
}
|
||||
exit;
|
||||
break;
|
||||
switch ($error_number)
|
||||
{
|
||||
case E_NOTICE: case E_WARNING: case E_USER_WARNING: case E_USER_NOTICE: case E_STRICT: break;
|
||||
|
||||
default:
|
||||
header('HTTP/1.1 503 Service Temporarily Unavailable');
|
||||
echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">' . "\n<head>\n";
|
||||
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />' . "\n";
|
||||
echo '<title>Kleeja Error</title>' . "\n" . '<style type="text/css">' . "\n\t";
|
||||
echo '.error {color: #333;background:#ffebe8;float:left;width:73%;text-align:left;margin-top:10px;border: 1px solid #dd3c10; padding: 10px;font-family:tahoma,arial;font-size: 12px;}' . "\n";
|
||||
echo "</style>\n</head>\n<body>\n\t" . '<div class="error">' . "\n\n\t\t<h2>Kleeja error : </h2><br />" . "\n";
|
||||
echo "\n\t\t<strong> [ " . $error_number . ':' . basename($error_file) . ':' . $error_line . ' ] </strong><br /><br />' . "\n\t\t" . $error_string . "\n\t";
|
||||
echo "\n\t\t" . '<br /><br /><small>Visit <a href="http://www.kleeja.com/" title="kleeja">Kleeja</a> Website for more details.</small>' . "\n\t";
|
||||
echo "</div>\n</body>\n</html>";
|
||||
global $SQL;
|
||||
|
||||
if (isset($SQL))
|
||||
{
|
||||
@$SQL->close();
|
||||
}
|
||||
|
||||
exit;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
set_error_handler('kleeja_show_error');
|
||||
|
||||
#time of start and end and whatever
|
||||
//time of start and end and whatever
|
||||
function get_microtime()
|
||||
{
|
||||
list($usec, $sec) = explode(' ', microtime()); return ((float)$usec + (float)$sec);
|
||||
list($usec, $sec) = explode(' ', microtime());
|
||||
return ((float) $usec + (float) $sec);
|
||||
}
|
||||
|
||||
//is bot ?
|
||||
function is_bot($bots = array('googlebot', 'bing' ,'msnbot'))
|
||||
function is_bot($bots = ['googlebot', 'bing' ,'msnbot'])
|
||||
{
|
||||
if(isset($_SERVER['HTTP_USER_AGENT']))
|
||||
{
|
||||
return preg_match('/(' . implode('|', $bots) . ')/i', ($_SERVER['HTTP_USER_AGENT'] ? $_SERVER['HTTP_USER_AGENT'] : @getenv('HTTP_USER_AGENT'))) ? true : false;
|
||||
}
|
||||
return false;
|
||||
if (isset($_SERVER['HTTP_USER_AGENT']))
|
||||
{
|
||||
return preg_match('/(' . implode('|', $bots) . ')/i', ($_SERVER['HTTP_USER_AGENT'] ? $_SERVER['HTTP_USER_AGENT'] : @getenv('HTTP_USER_AGENT'))) ? true : false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
$starttm = get_microtime();
|
||||
|
||||
|
||||
if (!is_bot() && !isset($_SESSION))
|
||||
if (! is_bot() && ! isset($_SESSION))
|
||||
{
|
||||
session_start();
|
||||
}
|
||||
@@ -115,14 +121,15 @@ if (!is_bot() && !isset($_SESSION))
|
||||
|
||||
|
||||
|
||||
#no enough data
|
||||
//no enough data
|
||||
if (empty($dbname) || empty($dbuser))
|
||||
{
|
||||
header('Location: ./install/index.php');
|
||||
exit;
|
||||
header('Location: ./install/index.php');
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
#include files .. & classes ..
|
||||
//include files .. & classes ..
|
||||
$root_path = PATH;
|
||||
// $db_type = isset($db_type) ? $db_type : 'mysqli';
|
||||
|
||||
@@ -137,82 +144,82 @@ include PATH . 'includes/functions_display.php';
|
||||
include PATH . 'includes/plugins.php';
|
||||
|
||||
|
||||
if(defined('IN_ADMIN'))
|
||||
if (defined('IN_ADMIN'))
|
||||
{
|
||||
include PATH . 'includes/functions_adm.php';
|
||||
include PATH . 'includes/functions_adm.php';
|
||||
}
|
||||
|
||||
|
||||
#fix integration problems
|
||||
if(empty($script_encoding))
|
||||
//fix integration problems
|
||||
if (empty($script_encoding))
|
||||
{
|
||||
$script_encoding = 'utf-8';
|
||||
$script_encoding = 'utf-8';
|
||||
}
|
||||
|
||||
#start classes ..
|
||||
//start classes ..
|
||||
$SQL = new KleejaDatabase($dbserver, $dbuser, $dbpass, $dbname);
|
||||
#no need after now
|
||||
//no need after now
|
||||
unset($dbpass);
|
||||
|
||||
|
||||
|
||||
$tpl = new kleeja_style;
|
||||
$tpl = new kleeja_style;
|
||||
$usrcp = new usrcp;
|
||||
|
||||
//then get caches
|
||||
include PATH . 'includes/cache.php';
|
||||
|
||||
#getting dynamic configs
|
||||
$query = array(
|
||||
'SELECT' => 'c.name, c.value',
|
||||
'FROM' => "{$dbprefix}config c",
|
||||
'WHERE' => 'c.dynamic = 1',
|
||||
);
|
||||
//getting dynamic configs
|
||||
$query = [
|
||||
'SELECT' => 'c.name, c.value',
|
||||
'FROM' => "{$dbprefix}config c",
|
||||
'WHERE' => 'c.dynamic = 1',
|
||||
];
|
||||
|
||||
$result = $SQL->build($query);
|
||||
|
||||
while($row=$SQL->fetch_array($result))
|
||||
while ($row=$SQL->fetch_array($result))
|
||||
{
|
||||
$config[$row['name']] = $row['value'];
|
||||
$config[$row['name']] = $row['value'];
|
||||
}
|
||||
|
||||
$SQL->freeresult($result);
|
||||
|
||||
#check user or guest
|
||||
//check user or guest
|
||||
$usrcp->kleeja_check_user();
|
||||
|
||||
#+ configs of the current group
|
||||
//+ configs of the current group
|
||||
$config = array_merge($config, (array) $d_groups[$usrcp->group_id()]['configs']);
|
||||
|
||||
|
||||
#admin path
|
||||
//admin path
|
||||
define('ADMIN_PATH', rtrim($config['siteurl'], '/') . '/admin/index.php');
|
||||
|
||||
|
||||
//no tpl caching in dev stage
|
||||
if(defined('DEV_STAGE'))
|
||||
if (defined('DEV_STAGE'))
|
||||
{
|
||||
$tpl->caching = false;
|
||||
$tpl->caching = false;
|
||||
}
|
||||
|
||||
|
||||
if(isset($config['foldername']))
|
||||
if (isset($config['foldername']))
|
||||
{
|
||||
$config['foldername'] = str_replace(
|
||||
array(
|
||||
[
|
||||
'{year}',
|
||||
'{month}',
|
||||
'{week}',
|
||||
'{day}',
|
||||
'{username}',
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
date('Y'),
|
||||
date('m'),
|
||||
date('W'),
|
||||
date('d'),
|
||||
$usrcp->name() ? preg_replace('/[^a-z0-9\._-]/', '', strtolower($usrcp->name())) : 'guest'
|
||||
),
|
||||
],
|
||||
$config['foldername']
|
||||
);
|
||||
}
|
||||
@@ -234,145 +241,145 @@ $klj_session = $SQL->escape(session_id());
|
||||
|
||||
|
||||
//site url must end with /
|
||||
if($config['siteurl'])
|
||||
if ($config['siteurl'])
|
||||
{
|
||||
$config['siteurl'] = $config['siteurl'][strlen($config['siteurl'])-1] != '/'
|
||||
$config['siteurl'] = $config['siteurl'][strlen($config['siteurl'])-1] != '/'
|
||||
? $config['siteurl'] . '/'
|
||||
: $config['siteurl'];
|
||||
}
|
||||
|
||||
|
||||
#check lang
|
||||
if(!$config['language'] || empty($config['language']))
|
||||
//check lang
|
||||
if (! $config['language'] || empty($config['language']))
|
||||
{
|
||||
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && strlen($_SERVER['HTTP_ACCEPT_LANGUAGE']) > 2)
|
||||
{
|
||||
$config['language'] = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
|
||||
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && strlen($_SERVER['HTTP_ACCEPT_LANGUAGE']) > 2)
|
||||
{
|
||||
$config['language'] = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
|
||||
|
||||
if(!file_exists(PATH . 'lang/' . $config['language'] . '/common.php'))
|
||||
{
|
||||
$config['language'] = 'en';
|
||||
}
|
||||
}
|
||||
if (! file_exists(PATH . 'lang/' . $config['language'] . '/common.php'))
|
||||
{
|
||||
$config['language'] = 'en';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#check style
|
||||
if(is_null($config['style']) || empty($config['style']))
|
||||
//check style
|
||||
if (is_null($config['style']) || empty($config['style']))
|
||||
{
|
||||
$config['style'] = 'default';
|
||||
$config['style'] = 'default';
|
||||
}
|
||||
|
||||
#check h_kay, important for kleeja
|
||||
if(empty($config['h_key']))
|
||||
//check h_kay, important for kleeja
|
||||
if (empty($config['h_key']))
|
||||
{
|
||||
$h_k = sha1(microtime() . rand(0, 100));
|
||||
$h_k = sha1(microtime() . rand(0, 100));
|
||||
|
||||
if(!update_config('h_key', $h_k))
|
||||
{
|
||||
add_config('h_key', $h_k);
|
||||
}
|
||||
if (! update_config('h_key', $h_k))
|
||||
{
|
||||
add_config('h_key', $h_k);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#current Kleeja admin style
|
||||
//current Kleeja admin style
|
||||
define('ACP_STYLE_NAME', 'Masmak');
|
||||
|
||||
#path variables for Kleeja
|
||||
$STYLE_PATH = $config['siteurl'] . 'styles/' . (trim($config['style_depend_on']) == '' ? $config['style'] : $config['style_depend_on']) . '/';
|
||||
$THIS_STYLE_PATH = $config['siteurl'] . 'styles/' . $config['style'] . '/';
|
||||
$THIS_STYLE_PATH_ABS = PATH . 'styles/' . $config['style'] . '/';
|
||||
$STYLE_PATH_ADMIN = $config['siteurl'] . 'admin/'. (is_browser('mobile') || defined('IN_MOBILE') ? ACP_STYLE_NAME : ACP_STYLE_NAME) . '/';
|
||||
$STYLE_PATH_ADMIN_ABS = PATH . 'admin/'. (is_browser('mobile') || defined('IN_MOBILE') ? ACP_STYLE_NAME . '/' : ACP_STYLE_NAME . '/');
|
||||
//path variables for Kleeja
|
||||
$STYLE_PATH = $config['siteurl'] . 'styles/' . (trim($config['style_depend_on']) == '' ? $config['style'] : $config['style_depend_on']) . '/';
|
||||
$THIS_STYLE_PATH = $config['siteurl'] . 'styles/' . $config['style'] . '/';
|
||||
$THIS_STYLE_PATH_ABS = PATH . 'styles/' . $config['style'] . '/';
|
||||
$STYLE_PATH_ADMIN = $config['siteurl'] . 'admin/' . (is_browser('mobile') || defined('IN_MOBILE') ? ACP_STYLE_NAME : ACP_STYLE_NAME) . '/';
|
||||
$STYLE_PATH_ADMIN_ABS = PATH . 'admin/' . (is_browser('mobile') || defined('IN_MOBILE') ? ACP_STYLE_NAME . '/' : ACP_STYLE_NAME . '/');
|
||||
$DEFAULT_PATH_ADMIN_ABS = PATH . 'admin/' . ACP_STYLE_NAME . '/';
|
||||
$DEFAULT_PATH_ADMIN = $config['siteurl'] . 'admin/'. ACP_STYLE_NAME . '/';
|
||||
$DEFAULT_PATH_ADMIN = $config['siteurl'] . 'admin/' . ACP_STYLE_NAME . '/';
|
||||
|
||||
|
||||
#get languge of common
|
||||
//get languge of common
|
||||
get_lang('common');
|
||||
|
||||
#run ban system
|
||||
//run ban system
|
||||
get_ban();
|
||||
|
||||
if(isset($_GET['go']) && $_GET['go'] == 'login')
|
||||
if (isset($_GET['go']) && $_GET['go'] == 'login')
|
||||
{
|
||||
define('IN_LOGIN', true);
|
||||
define('IN_LOGIN', true);
|
||||
}
|
||||
|
||||
#install.php exists
|
||||
//install.php exists
|
||||
if (
|
||||
file_exists(PATH . 'install') &&
|
||||
!defined('IN_ADMIN') &&
|
||||
!defined('IN_LOGIN') &&
|
||||
!defined('DEV_STAGE') &&
|
||||
!(defined('IN_GO') && in_array(g('go'), array('queue'))) &&
|
||||
!(defined('IN_UCP') && in_array(g('go'), array('captcha', 'login')))
|
||||
)
|
||||
{
|
||||
#Different message for admins! delete install folder
|
||||
kleeja_info((user_can('enter_acp') ? $lang['DELETE_INSTALL_FOLDER'] : $lang['WE_UPDATING_KLEEJA_NOW']), $lang['SITE_CLOSED']);
|
||||
file_exists(PATH . 'install') &&
|
||||
! defined('IN_ADMIN') &&
|
||||
! defined('IN_LOGIN') &&
|
||||
! defined('DEV_STAGE') &&
|
||||
! (defined('IN_GO') && in_array(g('go'), ['queue'])) &&
|
||||
! (defined('IN_UCP') && in_array(g('go'), ['captcha', 'login']))
|
||||
) {
|
||||
//Different message for admins! delete install folder
|
||||
kleeja_info((user_can('enter_acp') ? $lang['DELETE_INSTALL_FOLDER'] : $lang['WE_UPDATING_KLEEJA_NOW']), $lang['SITE_CLOSED']);
|
||||
}
|
||||
|
||||
|
||||
#is site close
|
||||
//is site close
|
||||
$login_page = '';
|
||||
|
||||
if (
|
||||
$config['siteclose'] == '1' &&
|
||||
!user_can('enter_acp') &&
|
||||
!defined('IN_LOGIN') &&
|
||||
!defined('IN_ADMIN') &&
|
||||
!(defined('IN_GO') && in_array(g('go'), array('queue'))) &&
|
||||
!(defined('IN_UCP') && in_array(g('go'), array('captcha', 'login', 'register', 'logout')))
|
||||
)
|
||||
{
|
||||
//if download, images ?
|
||||
if(
|
||||
( defined('IN_DOWNLOAD') && (ig('img') || ig('thmb') || ig('thmbf') || ig('imgf')) )
|
||||
$config['siteclose'] == '1' &&
|
||||
! user_can('enter_acp') &&
|
||||
! defined('IN_LOGIN') &&
|
||||
! defined('IN_ADMIN') &&
|
||||
! (defined('IN_GO') && in_array(g('go'), ['queue'])) &&
|
||||
! (defined('IN_UCP') && in_array(g('go'), ['captcha', 'login', 'register', 'logout']))
|
||||
) {
|
||||
//if download, images ?
|
||||
if (
|
||||
( defined('IN_DOWNLOAD') && (ig('img') || ig('thmb') || ig('thmbf') || ig('imgf')) )
|
||||
|| g('go', 'str', '') == 'queue'
|
||||
)
|
||||
{
|
||||
@$SQL->close();
|
||||
$fullname = "images/site_closed.jpg";
|
||||
$filesize = filesize($fullname);
|
||||
header("Content-length: $filesize");
|
||||
header("Content-type: image/jpg");
|
||||
readfile($fullname);
|
||||
exit;
|
||||
}
|
||||
) {
|
||||
@$SQL->close();
|
||||
$fullname = 'images/site_closed.jpg';
|
||||
$filesize = filesize($fullname);
|
||||
header("Content-length: $filesize");
|
||||
header('Content-type: image/jpg');
|
||||
readfile($fullname);
|
||||
|
||||
// Send a 503 HTTP response code to prevent search bots from indexing the maintenace message
|
||||
header('HTTP/1.1 503 Service Temporarily Unavailable');
|
||||
kleeja_info($config['closemsg'], $lang['SITE_CLOSED']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Send a 503 HTTP response code to prevent search bots from indexing the maintenace message
|
||||
header('HTTP/1.1 503 Service Temporarily Unavailable');
|
||||
kleeja_info($config['closemsg'], $lang['SITE_CLOSED']);
|
||||
}
|
||||
|
||||
#exceed total size
|
||||
if (($stat_sizes >= ($config['total_size'] *(1048576))) && !defined('IN_LOGIN') && !defined('IN_ADMIN'))// convert megabytes to bytes
|
||||
{
|
||||
// Send a 503 HTTP response code to prevent search bots from indexing the maintenace message
|
||||
header('HTTP/1.1 503 Service Temporarily Unavailable');
|
||||
kleeja_info($lang['SIZES_EXCCEDED'], $lang['STOP_FOR_SIZE']);
|
||||
//exceed total size
|
||||
if (($stat_sizes >= ($config['total_size'] *(1048576))) && ! defined('IN_LOGIN') && ! defined('IN_ADMIN'))
|
||||
{// convert megabytes to bytes
|
||||
// Send a 503 HTTP response code to prevent search bots from indexing the maintenace message
|
||||
header('HTTP/1.1 503 Service Temporarily Unavailable');
|
||||
kleeja_info($lang['SIZES_EXCCEDED'], $lang['STOP_FOR_SIZE']);
|
||||
}
|
||||
|
||||
#detect bots and save stats
|
||||
//detect bots and save stats
|
||||
kleeja_detecting_bots();
|
||||
|
||||
#check for page number
|
||||
if(empty($perpage) || intval($perpage) == 0)
|
||||
//check for page number
|
||||
if (empty($perpage) || intval($perpage) == 0)
|
||||
{
|
||||
$perpage = 14;
|
||||
$perpage = 14;
|
||||
}
|
||||
|
||||
|
||||
#captcha file
|
||||
//captcha file
|
||||
$captcha_file_path = $config['siteurl'] . 'ucp.php?go=captcha';
|
||||
if(defined('STOP_CAPTCHA'))
|
||||
|
||||
if (defined('STOP_CAPTCHA'))
|
||||
{
|
||||
$config['enable_captcha'] = 0;
|
||||
$config['enable_captcha'] = 0;
|
||||
}
|
||||
|
||||
is_array($plugin_run_result = Plugins::getInstance()->run('end_common', get_defined_vars())) ? extract($plugin_run_result) : null; //run hook
|
||||
|
||||
|
||||
if(function_exists('session_register_shutdown'))
|
||||
if (function_exists('session_register_shutdown'))
|
||||
{
|
||||
session_register_shutdown();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user