/include/inc.php
PHP | 93 lines | 68 code | 22 blank | 3 comment | 19 complexity | 9c01bee8b1b0f36988e2fa91ff53e09a MD5 | raw file
- <?php
- ini_set('error_reporting', E_ALL);
- date_default_timezone_set('UTC');
- if(!file_exists(dirname(__FILE__) . '/config.php'))
- {
- die('Setup not complete: Copy config.template.php to config.php and modify the configuration settings to match your environment.');
- }
- require_once(dirname(__FILE__) . '/config.php');
- if(!array_key_exists('SHELL', $_SERVER)) {
- session_set_cookie_params(365*24*60*60);
- session_start();
- }
- $START_TIME = microtime(TRUE);
- require_once('functions.php');
- require_once('Model.php');
- require_once('Model/User.php');
- require_once('Model/Graph.php');
- require_once('Model/GraphSeries.php');
- require_once('Model/GraphData.php');
- require_once('Model/GraphDataNote.php');
- require_once('Model/GraphString.php');
- $headerTags = array();
- $user = FALSE;
- if(!array_key_exists('argv', $_SERVER)) {
- // Don't do this stuff for cli scripts
-
- if(get('login_token') && session('noLoginRedirect') != 1) {
- $user = Model_User::createFromLoginToken(get('login_token'));
- if($user) {
- $_SESSION['userID'] = $user->id;
- Model_User::update(array('lastLoginAt'=>date('Y-m-d H:i:s')), $user->id);
-
- // Redirect to the page they were trying to get to
- $redirect = trim(str_replace('login_token=' . get('login_token'), '', $_SERVER['REQUEST_URI']), '?');
- if($redirect != '/login') {
- header('Location: ' . $redirect);
- die();
- }
- }
- } else {
- if(session('userID')) {
- $user = new Model_User(session('userID'));
- }
- }
-
- // Redirect to the login page if they're not logged in now
- if(($user == FALSE || $user->id == FALSE) && !in_array($_SERVER['SCRIPT_NAME'], array('/login.php', '/index.php', '/help.php'))) {
- header('Location: /login');
- die();
- }
- }
- if(($user && $user->id != FALSE)) {
- $timezone = new DateTimeZone($user->timezone);
- date_default_timezone_set($user->timezone);
- }
- function formatText($text) {
- $text = nl2br($text);
- $expressions[] = '|(https?://[^\s]+)|';
- $replacements[] = '<a href="$1">$1</a>';
- $expressions[] = '/(?<![a-z0-9_])@([a-z0-9_]+)/i';
- $replacements[] = '<a href="http://twitter.com/$1">@$1</a>';
-
- $expressions[] = '|([a-z0-9_\.\+\-]+@[a-z0-9_\.\+\-]+\.[a-z0-9\.]{2,4})|i';
- $replacements[] = '<a href="mailto:$1">$1</a>';
- $text = preg_replace($expressions, $replacements, $text);
-
- return $text;
- }
- function uuidSecure()
- {
- return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
- mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
- mt_rand( 0, 0x0fff ) | 0x4000,
- mt_rand( 0, 0x3fff ) | 0x8000,
- mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ) );
- }