2015-04-01 17:35:27 +02:00
< ? php
/*
2015-05-24 22:06:53 +00:00
* Sakura Community Management System
2015-05-29 19:27:45 +00:00
* ( c ) 2013 - 2015 Flashwave < http :// flash . moe > & Circlestorm < http :// circlestorm . net >
2015-04-01 17:35:27 +02:00
*/
// Declare namespace
namespace Sakura ;
// Define Sakura version
2015-09-15 22:37:29 +02:00
define ( 'SAKURA_VERSION' , '20150915' );
2015-09-14 22:51:23 +02:00
define ( 'SAKURA_VLABEL' , 'Eminence' );
define ( 'SAKURA_COLOUR' , '#6C3082' );
define ( 'SAKURA_STABLE' , false );
2015-04-01 17:35:27 +02:00
// Define Sakura Path
2015-04-06 16:15:20 +00:00
define ( 'ROOT' , str_replace ( basename ( __DIR__ ), '' , dirname ( __FILE__ )));
2015-04-01 17:35:27 +02:00
// Error Reporting: 0 for production and -1 for testing
2015-06-29 02:36:37 +02:00
error_reporting ( SAKURA_STABLE ? 0 : - 1 );
2015-04-01 17:35:27 +02:00
2015-07-05 02:03:15 +02:00
// Set internal encoding method
mb_internal_encoding ( 'utf-8' );
2015-08-24 00:08:36 +02:00
// Stop the execution if the PHP Version is older than 5.4.0
2015-09-14 22:51:23 +02:00
if ( version_compare ( phpversion (), '5.4.0' , '<' )) {
2015-08-29 15:25:57 +02:00
die ( '<h3>Sakura requires at least PHP 5.4.0, please upgrade to a newer PHP version.</h3>' );
2015-08-24 00:08:36 +02:00
}
2015-04-01 17:35:27 +02:00
// Include libraries
2015-09-14 22:51:23 +02:00
require_once ROOT . '_sakura/vendor/autoload.php' ;
require_once ROOT . '_sakura/components/Main.php' ;
require_once ROOT . '_sakura/components/Hashing.php' ;
require_once ROOT . '_sakura/components/Configuration.php' ;
require_once ROOT . '_sakura/components/Database.php' ;
require_once ROOT . '_sakura/components/Urls.php' ;
require_once ROOT . '_sakura/components/Templates.php' ;
require_once ROOT . '_sakura/components/Permissions.php' ;
require_once ROOT . '_sakura/components/Sessions.php' ;
require_once ROOT . '_sakura/components/User.php' ;
require_once ROOT . '_sakura/components/Users.php' ;
require_once ROOT . '_sakura/components/Forum.php' ;
require_once ROOT . '_sakura/components/News.php' ;
require_once ROOT . '_sakura/components/Comments.php' ;
require_once ROOT . '_sakura/components/Manage.php' ;
require_once ROOT . '_sakura/components/Bans.php' ;
require_once ROOT . '_sakura/components/Whois.php' ;
require_once ROOT . '_sakura/components/Payments.php' ;
2015-04-01 17:35:27 +02:00
2015-05-29 19:27:45 +00:00
// Include database extensions
2015-09-14 22:51:23 +02:00
foreach ( glob ( ROOT . '_sakura/components/database/*.php' ) as $driver ) {
2015-07-30 03:12:53 +02:00
require_once $driver ;
}
2015-04-01 17:35:27 +02:00
// Set Error handler
2015-04-30 23:01:01 +00:00
set_error_handler ( array ( 'Sakura\Main' , 'errorHandler' ));
2015-04-01 17:35:27 +02:00
2015-07-30 03:12:53 +02:00
// Initialise Main Class
2015-09-14 22:51:23 +02:00
Main :: init ( ROOT . '_sakura/config/config.ini' );
2015-05-29 19:27:45 +00:00
2015-08-24 00:08:36 +02:00
// Assign servers file to whois class
2015-09-14 22:51:23 +02:00
Whois :: setServers ( ROOT . '_sakura/' . Configuration :: getLocalConfig ( 'data' , 'whoisservers' ));
2015-08-24 00:08:36 +02:00
2015-09-12 21:57:44 +02:00
// Check if we the system has a cron service
2015-09-14 22:51:23 +02:00
if ( Configuration :: getConfig ( 'no_cron_service' )) {
2015-09-12 21:57:44 +02:00
// If not do an "asynchronous" call to the cron.php script
2015-09-14 22:51:23 +02:00
if ( Configuration :: getConfig ( 'no_cron_last' ) < ( time () - Configuration :: getConfig ( 'no_cron_interval' ))) {
2015-09-12 21:57:44 +02:00
// Check OS
2015-09-14 22:51:23 +02:00
if ( substr ( strtolower ( PHP_OS ), 0 , 3 ) == 'win' ) {
pclose ( popen ( 'start /B ' . PHP_BINDIR . '\php.exe ' . addslashes ( ROOT . '_sakura\cron.php' ), 'r' ));
2015-09-12 21:57:44 +02:00
} else {
2015-09-14 22:51:23 +02:00
pclose ( popen ( PHP_BINDIR . '/php ' . ROOT . '_sakura/cron.php > /dev/null 2>/dev/null &' , 'r' ));
2015-09-12 21:57:44 +02:00
}
// Update last execution time
Database :: update ( 'config' , [
[
2015-09-14 22:51:23 +02:00
'config_value' => time (),
2015-09-12 21:57:44 +02:00
],
[
2015-09-14 22:51:23 +02:00
'config_name' => [ 'no_cron_last' , '=' ],
2015-09-12 21:57:44 +02:00
2015-09-14 22:51:23 +02:00
],
2015-09-12 21:57:44 +02:00
]);
}
}
2015-05-29 19:27:45 +00:00
// Start output buffering
ob_start ( Configuration :: getConfig ( 'use_gzip' ) ? 'ob_gzhandler' : null );
2015-04-01 17:35:27 +02:00
2015-08-22 00:07:45 +02:00
// Create a user object for the current logged in user
$currentUser = new User ( Session :: $userId );
2015-09-05 01:49:53 +02:00
// Create the Urls object
$urls = new Urls ();
2015-08-29 15:25:57 +02:00
// Prepare the name of the template to load (outside of SAKURA_NO_TPL because it's used in imageserve.php)
2015-09-14 22:51:23 +02:00
$templateName =
defined ( 'SAKURA_MANAGE' ) ?
Configuration :: getConfig ( 'manage_style' ) :
Configuration :: getConfig ( 'site_style' );
2015-07-30 03:12:53 +02:00
2015-09-14 22:51:23 +02:00
if ( ! defined ( 'SAKURA_NO_TPL' )) {
2015-08-24 00:08:36 +02:00
// Initialise templating engine
2015-08-29 15:25:57 +02:00
Templates :: init ( $templateName );
2015-08-24 00:08:36 +02:00
2015-07-30 03:12:53 +02:00
// Set base page rendering data
$renderData = [
2015-09-02 19:51:03 +02:00
/*
* Idea for flexibility in templates and to reduce redundancy ;
* Attempt to use a class instead of an assoc . array for the
* template variables since twig supports this to make accessing
* certain functions , like the time elapsed function easier .
2015-09-08 23:57:33 +02:00
* Update 2015 - 09 - 08 : Apparently this will be added in PHP 7 so
* we ' ll be looking out for that .
2015-09-02 19:51:03 +02:00
*/
2015-07-30 03:12:53 +02:00
'sakura' => [
2015-08-21 01:17:27 +02:00
'versionInfo' => [
2015-09-14 22:51:23 +02:00
'version' => SAKURA_VERSION ,
'label' => SAKURA_VLABEL ,
'colour' => SAKURA_COLOUR ,
'stable' => SAKURA_STABLE ,
2015-08-21 01:17:27 +02:00
],
'cookie' => [
2015-09-14 22:51:23 +02:00
'prefix' => Configuration :: getConfig ( 'cookie_prefix' ),
'domain' => Configuration :: getConfig ( 'cookie_domain' ),
'path' => Configuration :: getConfig ( 'cookie_path' ),
2015-08-21 01:17:27 +02:00
],
2015-09-14 22:51:23 +02:00
'urlMain' => Configuration :: getConfig ( 'url_main' ),
'urlApi' => Configuration :: getConfig ( 'url_api' ),
2015-08-21 01:17:27 +02:00
2015-09-14 22:51:23 +02:00
'contentPath' => Configuration :: getConfig ( 'content_path' ),
'resources' => Configuration :: getConfig ( 'content_path' ) . '/data/' . strtolower ( Templates :: $template ),
2015-08-21 01:17:27 +02:00
2015-09-14 22:51:23 +02:00
'charset' => Configuration :: getConfig ( 'charset' ),
'siteName' => Configuration :: getConfig ( 'sitename' ),
'siteDesc' => Configuration :: getConfig ( 'sitedesc' ),
'siteTags' => implode ( " , " , json_decode ( Configuration :: getConfig ( 'sitetags' ), true )),
'dateFormat' => Configuration :: getConfig ( 'date_format' ),
'currentPage' => '//' . $_SERVER [ 'SERVER_NAME' ] . $_SERVER [ 'REQUEST_URI' ],
2015-08-21 01:17:27 +02:00
2015-09-14 22:51:23 +02:00
'recaptchaPublic' => Configuration :: getConfig ( 'recaptcha_public' ),
'recaptchaEnabled' => Configuration :: getConfig ( 'recaptcha' ),
2015-08-21 01:17:27 +02:00
2015-09-14 22:51:23 +02:00
'disableRegistration' => Configuration :: getConfig ( 'disable_registration' ),
'lockSite' => Configuration :: getConfig ( 'lock_site' ),
'lockSiteReason' => Configuration :: getConfig ( 'lock_site_reason' ),
'lockAuth' => Configuration :: getConfig ( 'lock_authentication' ),
'requireRegCodes' => Configuration :: getConfig ( 'require_registration_code' ),
'requireActivation' => Configuration :: getConfig ( 'require_activation' ),
'minPwdEntropy' => Configuration :: getConfig ( 'min_entropy' ),
'minUsernameLength' => Configuration :: getConfig ( 'username_min_length' ),
'maxUsernameLength' => Configuration :: getConfig ( 'username_max_length' ),
2015-07-30 03:12:53 +02:00
],
'php' => [
'sessionid' => \session_id (),
2015-09-14 22:51:23 +02:00
'time' => \time (),
'self' => $_SERVER [ 'PHP_SELF' ],
2015-07-30 03:12:53 +02:00
],
2015-08-19 21:44:01 +02:00
'session' => [
2015-07-30 03:12:53 +02:00
2015-09-14 22:51:23 +02:00
'checkLogin' => Users :: checkLogin (),
'sessionId' => Session :: $sessionId ,
'userId' => Session :: $userId ,
2015-07-30 03:12:53 +02:00
2015-08-19 21:44:01 +02:00
],
2015-09-05 01:49:53 +02:00
'user' => $currentUser ,
2015-09-14 22:51:23 +02:00
'urls' => $urls ,
2015-07-30 03:12:53 +02:00
];
// Ban checking
2015-09-14 22:51:23 +02:00
if ( Users :: checkLogin () && $ban = Bans :: checkBan ( Session :: $userId )) {
2015-07-30 03:12:53 +02:00
// Additional render data
$renderData = array_merge ( $renderData , [
2015-09-07 22:53:47 +02:00
2015-07-30 03:12:53 +02:00
'ban' => [
2015-09-14 22:51:23 +02:00
'reason' => $ban [ 'reason' ],
'issued' => $ban [ 'issued' ],
'expires' => $ban [ 'expires' ],
'issuer' => Users :: getUser ( $ban [ 'issuer' ]),
],
2015-09-07 22:53:47 +02:00
2015-07-30 03:12:53 +02:00
]);
2015-07-30 19:07:23 +02:00
Users :: logout ();
2015-09-05 18:11:04 +02:00
print Templates :: render ( 'main/banned.tpl' , $renderData );
2015-07-30 03:12:53 +02:00
exit ;
}
}