示例#1
0
文件: munla.php 项目: Borvik/Munla
 /**
  * Starts the application.
  * 
  * @return void
  */
 public static function run()
 {
     self::$starttime = microtime(true);
     error_reporting(config::ERROR_LEVEL);
     if (isset(config::$session_cookie_domain)) {
         ini_set('session.cookie_domain', config::$session_cookie_domain);
     }
     if (class_exists('formHelper')) {
         formHelper::fixArrays();
     }
     if (class_exists('csrfHelper')) {
         injector::register(array('csrfHelper', 'injector'));
     }
     if (is::ssl() && isset(config::$https_domain) && !isset(config::$http_domain)) {
         if (is::existset($_GET, 'r_domain')) {
             config::$http_domain = get::fulldomain($_GET['r_domain']);
         } else {
             config::$http_domain = get::fulldomain('www');
         }
     }
     session_start();
     if (config::$isolated_subdomains) {
         // find the domain
         $domain = isset(config::$http_domain) ? config::$http_domain : get::fulldomain();
         // kill any subdomain sessions that have been transfered to another subdomain
         $existing = array_keys($_SESSION);
         foreach ($existing as $d) {
             if (!is_array($_SESSION[$d])) {
                 continue;
             }
             if (array_key_exists('kill_munla_session', $_SESSION[$d]) && $_SESSION[$d]['kill_munla_session']) {
                 unset($_SESSION[$d]);
             }
         }
         // initialize and setup the session for this subdomain
         if (!array_key_exists($domain, $_SESSION)) {
             $_SESSION[$domain] = array();
         }
         munla::$session =& $_SESSION[$domain];
     } else {
         munla::$session =& $_SESSION;
     }
     if (class_exists('singleUseArray')) {
         if (!is::existset(munla::$session, 'MUNLA_SINGLE_USE')) {
             munla::$singleUse = new singleUseArray();
         } else {
             munla::$singleUse = unserialize(munla::$session['MUNLA_SINGLE_USE']);
         }
     }
     $route = get::route();
     if (is_array($route) && $route['controller'] == 'csrf' && $route['action'] == 'keepalive' && class_exists('csrfHelper') && is::existset($route, 'params') && count($route['params']) > 0) {
         if (isset($_POST['token'])) {
             echo csrfHelper::keepAlive($route['params'][0], $_POST['token']);
         }
         exit;
     }
     if (class_exists('user') && is_subclass_of('user', 'userBase')) {
         if (!is::existset(munla::$session, 'MUNLA_USER')) {
             munla::$session['MUNLA_USER'] = new userWrapper(new user());
         }
     }
     injector::start();
     if (class_exists('app') && is_callable(array('app', 'setup'))) {
         app::setup();
     }
     if (!isset(munla::$user) && is::existset(munla::$session, 'MUNLA_USER')) {
         munla::$user =& munla::$session['MUNLA_USER'];
     }
     if (!is::ajax()) {
         $submittedForm = formHelper::process();
         if (isset($submittedForm)) {
             formHelper::process($submittedForm);
         }
     }
     if (class_exists('app') && is_callable(array('app', 'start'))) {
         $route = app::start($route);
     }
     if ($route === null) {
         $route = array('controller' => 'index', 'action' => 'index', 'params' => null);
     }
     $controller = get::controller($route['controller']);
     if (!isset($controller) && $route['controller'] != 'index') {
         //push action to params, controller to action, and set controller to index and try again.
         if ($route['action'] != 'index') {
             if (!isset($route['params'])) {
                 $route['params'] = array();
             }
             array_unshift($route['params'], $route['action']);
         }
         $route['action'] = $route['controller'];
         $route['controller'] = 'index';
         $controller = get::controller('index');
     }
     $view = null;
     if (isset($controller)) {
         $action = $controller->getAction(array($route['action'], $route['params']));
         if (isset($action)) {
             try {
                 $viewParams = call_user_func_array(array($controller, $action['action']), $action['params']);
                 //various things could happen here...
                 if (!isset($viewParams)) {
                     $viewParams = array();
                 } elseif (!is_array($viewParams)) {
                     $viewParams = array($viewParams);
                 }
                 $view = get::view($route, $controller, $viewParams);
             } catch (SSLException $e) {
                 go::ssl(!is::ssl());
             } catch (PermissionException $e) {
                 munla::$nohistory = true;
                 if (isset(munla::$user) && !munla::$user->is_logged_in() && munla::$user->getLoginView()) {
                     $view = munla::$user->getLoginView();
                 } else {
                     $view = get::view('errors/generic', 'default', array('error_msg' => $e->getMessage()));
                 }
             } catch (Exception $e) {
                 munla::$nohistory = true;
                 $view = get::view('errors/generic', 'default', array('error_msg' => $e->getMessage()));
             }
         } else {
             $view = get::view($route, $controller);
         }
     } else {
         $view = get::view($route);
     }
     if ($view != null) {
         $view->render();
     } else {
         throw new Exception('View not found!');
     }
     if (class_exists('app', false)) {
         munla::$nohistory = app::finish(munla::$nohistory);
     }
     if (munla::$nohistory === false) {
         munla::$session['lastpage'] = get::url();
     }
     if (isset(munla::$singleUse)) {
         munla::$session['MUNLA_SINGLE_USE'] = serialize(munla::$singleUse);
     }
 }
示例#2
0
    // Source: http://css-tricks.com/snippets/php/time-ago-function/
    function ago($time)
    {
        $periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
        $lengths = array("60", "60", "24", "7", "4.35", "12", "10");
        $now = time();
        $difference = $now - $time;
        $tense = "ago";
        for ($j = 0; $difference >= $lengths[$j] && $j < count($lengths) - 1; $j++) {
            $difference /= $lengths[$j];
        }
        $difference = round($difference);
        if ($difference != 1) {
            $periods[$j] .= "s";
        }
        return "{$difference} {$periods[$j]}";
    }
}
$app = new app();
$flag = isset($argv[1]) ? $argv[1] : '';
switch ($flag) {
    case 'info':
        $app->info();
        break;
    case 'logout':
        $app->modhash();
        break;
    default:
        $app->start();
        break;
}
示例#3
0
define('VAR_PATH', ROOT . 'var' . DIRECTORY_SEPARATOR);
define('LIB_PATH', '/data/git/mvc/app/system/');
define('VIEW_PATH', APP_PATH . 'view' . DIRECTORY_SEPARATOR);
define('MODEL_PATH', APP_PATH . 'model' . DIRECTORY_SEPARATOR);
define('CONTROLLER_PATH', APP_PATH . 'controller' . DIRECTORY_SEPARATOR);
require LIB_PATH . 'core.php';
if (DEBUG) {
    define('DB_DSN', 'mysql:host=172.168.1.3;port=13306;dbname=test1;charset=utf8');
    define('DB_USER', 'work');
    define('DB_PASS', '123456');
    base::url('//127.0.0.1:8088');
} else {
    define('DB_DSN', 'mysql:unix_socket=/var/run/mysql.sock;dbname=blog;charset=utf8');
    define('DB_USER', 'root');
    define('DB_PASS', 'root');
    base::url('//static-files.coding.io');
}
// 开启如下配置可使用sendMail
// define('MAIL_SERVER','smtp.126.com');
// define('MAIL_USERNAME','*****@*****.**');
// define('MAIL_PASSWORD','123456');
// define('MAIL_NAME','发送者名称');
/*************************************应用程序配置区*************************************/
app::route('\\/([\\w\\-]{2,20})\\/([\\w\\-]{2,32})\\.(png|css|json|less)', array('sprite', 'index'));
app::route('\\/?', array('sprite', 'site'));
base::version(1234);
base::project('sprite');
/*************************************应用程序配置区*************************************/
//配置完,可以启动啦!
app::start();