Example #1
1
 public function render($action, $params = [], $cacheTime = null)
 {
     if (empty($action)) {
         return '';
     }
     $path = explode(':', $action);
     $params = ['data' => $params, 'module' => $this->controller->params['module'], 'controller' => $this->controller->params['controller']];
     switch (count($path)) {
         case 1:
             $params['action'] = $path[0];
             break;
         case 2:
             $params['controller'] = $path[0];
             $params['action'] = $path[1];
             break;
         default:
             $params['module'] = $path[0];
             $params['controller'] = $path[1];
             $params['action'] = $path[2];
     }
     try {
         if ($params['controller'] == $this->controller->params['controller'] && $params['module'] == $this->controller->params['module']) {
             return $this->controller->run($params);
         }
         return $this->controller->app->runController($params, $cacheTime);
     } catch (\Exception $e) {
         if ('dev' == $this->controller->app->conf['env']) {
             return $e;
         }
         return '';
     }
 }
 public function testException()
 {
     $except = false;
     try {
         $this->object->run('bogus');
     } catch (\PHPixie\Exception\PageNotFound $e) {
         $except = true;
     }
     $this->assertEquals($except, true);
 }
Example #3
0
 /**
  * Run application 
  */
 public function run()
 {
     try {
         // Pre settings before run controller
         foreach (Command::getCommands() as $cmd) {
             $cmd->doing();
         }
         foreach (Plugin::getPlugins() as $plugin) {
             $plugin->doing();
         }
         // Run the controller
         $ret = $this->controller->run();
         // After run the controller
         foreach (Command::getCommands() as $cmd) {
             $cmd->done();
         }
         foreach (Plugin::getPlugins() as $plugin) {
             $plugin->done();
         }
         // Rendering
         Renderer::getInstance()->render($ret);
     } catch (MyException $exc) {
         $text['title'] = 'error';
         $text['body'] = $exc->getMessage();
         Renderer::getInstance()->render($text);
     }
 }
 public function run($class_name)
 {
     $path = realpath(Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . $class_name);
     $class_name = ucfirst($class_name);
     if ($path && is_dir($path) && is_writable($path)) {
         $dir = key($_GET);
         $filename = $_GET[$dir];
         $pk = pathinfo($filename, PATHINFO_FILENAME);
         $image = Images::model()->findByPk($pk);
         if ($image != null) {
             $image->resize($dir);
         }
     } elseif (class_exists($class_name)) {
         $dir = key($_GET);
         $filename = $_GET[$dir];
         $size = explode('x', $dir);
         $path = realpath(Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . $class_name);
         if (YII_DEBUG && !file_exists($path . DIRECTORY_SEPARATOR . $dir)) {
             mkdir($path . DIRECTORY_SEPARATOR . $dir, 0777);
         }
         if ($path !== FALSE && file_exists($path . DIRECTORY_SEPARATOR . $dir) && is_file($path . DIRECTORY_SEPARATOR . $filename) && $size[0] > 0 && $size[1] > 0) {
             Yii::import('ext.iwi.Iwi');
             $image = new Iwi($path . DIRECTORY_SEPARATOR . $filename);
             $image->adaptive($size[0], $size[1]);
             $image->save($path . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . $filename, 0644, TRUE);
             $mime = CFileHelper::getMimeType($path . DIRECTORY_SEPARATOR . $filename);
             header('Content-Type: ' . $mime);
             $image->render();
             exit;
         }
     }
     return parent::run($class_name);
 }
Example #5
0
 /**
  * アプリケーションの実行。
  */
 function run()
 {
     try {
         //コントローラの本体処理実行前動作
         foreach (Command::getCommands() as $cmd) {
             $cmd->doing();
         }
         foreach (Plugin::getPlugins() as $plugin) {
             $plugin->doing();
         }
         //本体処理実行
         $ret = $this->controller->run();
         //コントローラの本体処理実行後動作
         foreach (Command::getCommands() as $cmd) {
             $cmd->done();
         }
         foreach (Plugin::getPlugins() as $plugin) {
             $plugin->done();
         }
         //レンダリング
         Renderer::getinstance()->render($ret);
     } catch (MyException $exc) {
         $text['title'] = 'error';
         $text['body'] = $exc->getMessage();
         Renderer::getinstance()->render($text);
     }
 }
Example #6
0
 public function run()
 {
     Utils::checkLogin();
     $msg = array();
     if (!empty($_POST['oldpassword'])) {
         if (!empty($_POST['newpassword']) && $_POST['newpassword'] == $_POST['confirmpassword']) {
             $password = '******' . Utils::encryptPassword($_POST['newpassword']);
             $sql = "\n                    UPDATE " . USERS . "\n                    SET password = '******'\n                    WHERE id ='" . $_SESSION['userid'] . "'";
             if (mysql_query($sql)) {
                 $msg[] = array("text" => "Password updated successfully!");
                 $to = $_SESSION['username'];
                 $subject = "Password Change";
                 $body = "<p>Congratulations!</p>";
                 $body .= "<p>You have successfully updated your password with " . SERVER_NAME . ".";
                 $body .= "</p><p>Love,<br/>Philip and Ryan</p>";
                 if (!Utils::send_email($to, $subject, $body)) {
                     error_log("PasswordController: Utils::send_email failed");
                 }
             } else {
                 $msg[] = array("text" => "Failed to update your password");
             }
         } else {
             $msg[] = array("text" => "New passwords don't match!");
         }
     }
     $this->write('msg', $msg);
     parent::run();
 }
Example #7
0
 public function getView()
 {
     $gh_events = array();
     try {
         $this->client = new Github\Client(new Github\HttpClient\CachedHttpClient(array('cache_dir' => TEMP_DIR . DIRECTORY_SEPARATOR . 'github')));
         $this->client->authenticate(GITHUB_OAUTH2_CLIENT_ID, GITHUB_OAUTH2_CLIENT_SECRET, Github\Client::AUTH_URL_CLIENT_ID);
         // first: request github for 3 pages with 30 events data each
         $gh_events = array_merge($this->listGithubEvents(GITHUB_ORGANIZATION, 1), $this->listGithubEvents(GITHUB_ORGANIZATION, 2), $this->listGithubEvents(GITHUB_ORGANIZATION, 3));
         // then: find out $seconds_ago based on the last event in order to
         // use as date limit when looking for worklist entries
         $fromTime = strtotime(self::olderGithubEventDate($gh_events));
         $toTime = strtotime(Model::now());
     } catch (Exception $e) {
         error_log('StatusController::run exception: ' . $e->getMessage());
         $fromTime = strtotime('10 days ago');
         $toTime = strtotime(Model::now());
     }
     $seconds_ago = abs($toTime - $fromTime);
     $this->write('gh_events', $gh_events);
     // and, finally: fetches worklist data
     $entry = new EntryModel();
     $this->write('entries', $entry->latest($seconds_ago, 90));
     // alright, ready to go :)
     parent::run();
 }
Example #8
0
 public function run()
 {
     $msg = '';
     if (!empty($_POST['submit'])) {
         if (!empty($_POST['password'])) {
             $user = new User();
             if ($user->findUserByUsername($_POST['username'])) {
                 if ($user->getForgot_hash() == $_REQUEST['token']) {
                     $password = '******' . Utils::encryptPassword($_POST['password']);
                     $user->setPassword($password)->setForgot_hash(md5(uniqid()))->save();
                     Utils::sendTemplateEmail($_POST['username'], 'changed_pass', array('app_name' => APP_NAME));
                     Utils::redirect('./');
                 }
             } else {
                 $msg = 'The link to reset your password has expired or is invalid. <a href="./forgot">Please try again.</a>';
             }
         } else {
             $msg = "Please enter a password!";
         }
     }
     if (empty($_REQUEST['token'])) {
         // no required information specified, redirect user
         $this->view = null;
         Utils::redirect('./');
     }
     $this->write('msg', $msg);
     $this->write('un', isset($_REQUEST['un']) ? base64_decode($_REQUEST['un']) : "");
     $this->write('token', $_REQUEST['token']);
     parent::run();
 }
 public function run($a)
 {
     if (@Yii::app()->params['installer'] !== 'show') {
         return $this->missingAction($a);
     }
     return parent::run($a);
 }
 public function run($thumb)
 {
     $key = key($_GET);
     if (NULL == ($file = Files::model()->findByPk($key))) {
         throw new CException('Page not found', 404);
     }
     $path = Yii::getPathOfAlias('webroot') . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . 'photos';
     $src_file = $file->id . '.' . $file->extension;
     $in_file = $path . DIRECTORY_SEPARATOR . $src_file;
     $out_file = $path . DIRECTORY_SEPARATOR . $thumb . DIRECTORY_SEPARATOR . $src_file;
     if (is_file($out_file)) {
         $mime = CFileHelper::getMimeType($out_file);
         header('Content-Type: ' . $mime);
         readfile($out_file);
         exit;
     }
     if (is_file($in_file)) {
         $dir = $path . DIRECTORY_SEPARATOR . $thumb;
         if (YII_DEBUG && !file_exists($dir)) {
             mkdir($dir, 0777);
         }
         if (file_exists($dir)) {
             if (($out_file = $file->resize($thumb)) == 0) {
                 throw new CException('Page not found', 404);
             }
             $mime = CFileHelper::getMimeType($in_file);
             header('Content-Type: ' . $mime);
             readfile($out_file);
             exit;
         }
     }
     return parent::run($thumb);
 }
Example #11
0
 public function run($action, $params)
 {
     if ($this->getAuthorizator()->canPerform($this, $action)) {
         return parent::run($action, $params);
     } else {
         $this->accessDenied();
     }
 }
Example #12
0
 /**
  * Add search to your app.
  *
  * @return string
  */
 public static function search_header()
 {
     $conf = self::$conf;
     if ($conf['App Settings']['search']) {
         return self::$controller->run($conf['App Settings']['search'], array('header' => true));
     }
     return '';
 }
Example #13
0
 static function run()
 {
     $uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
     $appPath = config('app.path', dirname($_SERVER['PHP_SELF']));
     if ($appPath !== DIRECTORY_SEPARATOR && str_contains($uri, $appPath)) {
         $uri = substr($uri, strlen($appPath));
     }
     list($uri, ) = explode('?', $uri);
     $routes = array('/^\\/(\\d+)(\\/.*)?$/' => 'c=index&a=show&id=$1&v=$2', '/^\\/([\\w]+)\\/(\\d+)(\\/.*)?$/' => 'c=$1&a=show&id=$2&v=$3', '/^\\/([\\w]+)\\/([\\w]+)\\/(\\d+)(\\/.*)?$/' => 'c=$1&a=$2&id=$3&v=$4', '/^\\/([\\w]+)\\/([\\w%]+)(\\/.*)?$/' => 'c=$1&a=$2&v=$3', '/^\\/([\\w]+)\\/?$/' => 'c=$1&a=index&v=');
     if (is_array(self::$routes)) {
         $routes = array_merge(self::$routes, $routes);
         foreach (self::$routes as $k => $v) {
             $routes[$k] = $v;
         }
     }
     foreach ($routes as $rk => $rv) {
         if (preg_match($rk, $uri, $m)) {
             foreach ($m as $mk => $mv) {
                 if ($mk > 0) {
                     $rv = str_replace('$' . $mk, $mv, $rv);
                 }
             }
             parse_str($rv, $args);
             if (is_array($args)) {
                 self::$controller = $args['c'];
                 self::$action = $args['a'];
                 unset($args['c']);
                 unset($args['a']);
                 if ($args['v']) {
                     $moreArgs = explode('/', trim($args['v'], '/'));
                     unset($args['v']);
                     for ($i = 0; $i < count($moreArgs); $i = $i + 2) {
                         if (!is_numeric($moreArgs[$i]) && !(preg_match('/^\\$[1-9]$/', $moreArgs[$i]) && !$moreArgs[$i + 1])) {
                             $args[$moreArgs[$i]] = $moreArgs[$i + 1];
                         }
                     }
                 }
                 $_GET = array_merge($_GET, $args);
                 $_REQUEST = array_merge($_REQUEST, $args);
             }
             break;
         }
     }
     if (!self::$controller) {
         self::$controller = 'index';
     }
     if (!self::$action) {
         self::$action = 'index';
     }
     self::$route = self::$controller . '/' . self::$action;
     echo Controller::run();
 }
Example #14
0
 public function run()
 {
     if (ENV == 'development') {
         $this->_Timestamp = microtime(true);
     }
     Logger::info('', false);
     $protocol = empty($_SERVER['HTTPS']) ? 'http://' : 'https://';
     Logger::debug($_SERVER['REQUEST_METHOD'] . " " . $protocol . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
     Logger::info('App start...');
     session_start();
     // zistenie a spustenie daneho kontrolera
     $controllerName = CLASSES_PREFIX . "Controller" . Router::getControllerName();
     if (class_exists($controllerName)) {
         Logger::debug("Loading controller {$controllerName}...");
         $this->_Controller = new $controllerName();
         $this->_Controller->run();
         $this->_Controller->render();
     } else {
         throw new Exception('Unknown controller: ' . $controllerName);
     }
     if (ENV == 'development') {
         Logger::debug("Generated in " . round((microtime(true) - $this->_Timestamp) * 1000) . " msec.");
     }
 }
Example #15
0
 public function run()
 {
     // @TODO: We extra the request but it seems we then don't use it?
     extract($_REQUEST);
     $msg = '';
     if (!empty($_POST['username'])) {
         $token = md5(uniqid());
         $user = new User();
         if ($user->findUserByUsername($_POST['username'])) {
             $user->setForgot_hash($token);
             $user->save();
             $resetUrl = SECURE_SERVER_URL . 'resetpass?un=' . base64_encode($_POST['username']) . '&amp;token=' . $token;
             $resetUrl = '<a href="' . $resetUrl . '" title="Password Recovery">' . $resetUrl . '</a>';
             Utils::sendTemplateEmail($_POST['username'], 'recovery', array('url' => $resetUrl));
             $msg = '<p class="LV_valid">Login information will be sent if the email address ' . $_POST['username'] . ' is registered.</p>';
         } else {
             $msg = '<p class="LV_invalid">Sorry, unable to send password reset information. Try again or contact an administrator.</p>';
         }
     }
     $this->write('msg', $msg);
     parent::run();
 }
Example #16
0
 public function run()
 {
     extract($_REQUEST);
     if (!empty($_POST['username'])) {
         $res = mysql_query("select id, confirm, confirm_string from " . USERS . " where username ='******'username']) . "'");
         if (mysql_num_rows($res) > 0) {
             $row = mysql_fetch_array($res);
             $to = $_POST['username'];
             // Email user
             $subject = "Worklist Registration Confirmation";
             $body = "<p>You are only one click away from completing your registration with Worklist!</p><p>Click the link below or copy into your browser's window to verify your email address and activate your account. <br/>";
             $body .= "&nbsp;&nbsp;&nbsp;&nbsp;" . SECURE_SERVER_URL . "confirmation?cs=" . $row['confirm_string'] . "&str=" . base64_encode($_POST['username']) . "</p>";
             $body .= "<p>Looking forward to seeing you in the Workroom! :)</p>";
             if (!Utils::send_email($to, $subject, $body)) {
                 error_log("ResendController: Utils::send_email failed");
             }
             $msg = "An email containing a link to confirm your email address is being sent to " . $to;
         } else {
             $msg = "Sorry, your email address doesn't match";
         }
     }
     $this->write('msg', $msg);
     parent::run();
 }
Example #17
0
<?php

// We turn on PHP output buffering feature
ob_start();
include_once "controller/Controller.php";
// Run the controller
$controller = new Controller();
$controller->run();
Example #18
0
 /**
  * Run Controller
  */
 public function run()
 {
     // we most call this function because it will potentially redirect
     $this->getWords();
     parent::run();
 }
Example #19
0
if (Cache::$time && !is_writable(Cache::$path)) {
    Cache::$time = 0;
    Debug::write('Disable Cache system, don\'t have write acess to "' . Cache::$path . '".', 'error');
}
if (Client::$AutoExtract && !is_writable(Client::$path . 'data/')) {
    Client::$AutoExtract = false;
    Debug::write('Disable GRF auto-extract mode, don\'t have write access to "' . Client::$path . 'data/".', 'error');
}
// Don't cache images when debug mode is on
if (Debug::isEnable()) {
    Cache::$time = 0;
}
// Url Rewriting
$routes = array();
$routes['/character/(.*)/(\\d+)/([0-7])'] = 'Character';
$routes['/character/(.*)'] = 'Character';
$routes['/characterhead/(.*)'] = 'CharacterHead';
$routes['/avatar/(.*)'] = 'Avatar';
$routes['/signature/(.*)'] = 'Signature';
$routes['/monster/(\\d+)'] = 'Monster';
$routes['/generate/body=(F|M)-(\\d+)-(\\d+)/hair=(\\d+)-(\\d+)-(\\d)/hats=(\\d+)-(\\d+)-(\\d+)/equip=(\\d+)-(\\d+)-(\\d+)/option=(\\d+)/actdir=([0-7])-(\\d+)-(\\d+)'] = 'Generator';
//$routes['/update/(hats|mobs|robes)'] = 'Update'; // Uncomment this line if you want to perform updates by updating lua files.
try {
    // Initialize client and process
    Client::init();
    Controller::run($routes);
} catch (Exception $e) {
    Debug::write($e->getMessage(), 'error');
}
// Debug
Debug::output();
    echo "    -u           Cache update only, do not do the analysis" . PHP_EOL;
    echo "    -f           Do the analysis and run only fast analyzers" . PHP_EOL;
    echo "    -d           Enable debug features" . PHP_EOL;
    exit;
}
$passcode = isset($options['passcode']) ? $options['passcode'] : (isset($options['p']) ? $options['p'] : null);
$runAnalysis = !isset($options['update']) && !isset($options['u']);
$fastOnly = isset($options['fast']) || isset($options['f']);
$debug = isset($options['debug']) || isset($options['d']);
$correctPasscode = Config::get("passcode");
if ($correctPasscode) {
    if ($passcode == null) {
        echo "Passcode non specificato...";
        exit(1);
    }
    if (md5($passcode) != $correctPasscode) {
        echo "Passcode non valido...";
        exit(2);
    }
}
$locked = Atomic::isLocked();
if ($locked) {
    echo "Analysis is locked... waiting up to 60 seconds" . PHP_EOL;
}
Atomic::waitForLock(60.0);
if ($debug) {
    Controller::init();
    Config::override("debug", true);
}
Controller::run($runAnalysis, $fastOnly);
Atomic::unlock();
Example #21
0
 public function run()
 {
     parent::run();
 }
Example #22
0
 /**
  * @covers aRvi\Controller\Controller::run
  */
 public function testRunForJsonp()
 {
     $controller = new Controller();
     $controller->strViewType = "jsonp";
     $this->assertInstanceOf("\\aRvi\\WebResponse\\JsonpWebResponse", $controller->run());
 }
Example #23
0
    {
    }
    static function run()
    {
        $instance = new Controller();
        $instance->init();
        $instance->handleRequest();
    }
    function init()
    {
        $applicationHelper = ApplicationHelper::instance();
        $applicationHelper->init();
    }
    function handleRequest()
    {
        $request = new Request();
        $app_c = \woo\base\ApplicationRegistry::appController();
        while ($cmd = $app_c->getCommand($request)) {
            $cmd->execute($request);
        }
        \woo\domain\ObjectWatcher::instance()->performOperations();
        $this->invokeView($app_c->getView($request));
    }
    function invokeView($target)
    {
        include "woo/view/{$target}.php";
        exit;
    }
}
Controller::run();
Example #24
0
	/**
	 * The front controller only has one static method, `run()`, which
	 * 
	 */
	public static function run ($argv, $argc) {
		/**
		 * For compatibility with PHP 5.4's built-in web server, we bypass
		 * the front controller for requests with file extensions and
		 * return false.
		 */
		if (php_sapi_name () === 'cli-server' && isset ($_SERVER['REQUEST_URI']) && preg_match ('/\.[a-zA-Z0-9]+$/', parse_url ($_SERVER['REQUEST_URI'], PHP_URL_PATH))) {
			return false;
		}

		/**
		 * Normalize slashes for servers that are still poorly
		 * configured...
		 */
		if (get_magic_quotes_gpc ()) {
			function stripslashes_gpc (&$value) {
				$value = stripslashes ($value);
			}
			array_walk_recursive ($_GET, 'stripslashes_gpc');
			array_walk_recursive ($_POST, 'stripslashes_gpc');
			array_walk_recursive ($_COOKIE, 'stripslashes_gpc');
			array_walk_recursive ($_REQUEST, 'stripslashes_gpc');
		}

		/**
		 * Check ELEFANT_ENV environment variable to determine which
		 * configuration to load. Also include the Elefant version,
		 * autoloader, and core functions, and set the default
		 * timezone to avoid warnings in date functions.
		 */
		define ('ELEFANT_ENV', getenv ('ELEFANT_ENV') ? getenv ('ELEFANT_ENV') : 'config');
		require ('conf/version.php');
		require ('lib/Autoloader.php');
		require ('lib/Functions.php');
		date_default_timezone_set(conf ('General', 'timezone'));
		ini_set ('session.cookie_httponly', 1);
		ini_set ('session.use_only_cookies', 1);

		/**
		 * Set the default error reporting level to All except Notices,
		 * and turn off displaying errors. Error handling/debugging can
		 * be done by setting conf[General][debug] to true, causing full
		 * debug traces to be displayed with highlighted code in the
		 * browser (*for development purposes only*), or by checking
		 * the error log for errors.
		 */
		error_reporting (E_ALL & ~E_NOTICE);
		if (conf ('General', 'display_errors')) {
			ini_set ('display_errors', 'On');
		} else {
			ini_set ('display_errors', 'Off');
		}

		/**
		 * Enable the debugger if conf[General][debug] is true.
		 */
		require ('lib/Debugger.php');
		Debugger::start (conf ('General', 'debug'));

		/**
		 * Include the core libraries used by the front controller
		 * to dispatch and respond to requests.
		 */
		require ('lib/DB.php');
		require ('lib/Page.php');
		require ('lib/I18n.php');
		require ('lib/Controller.php');
		require ('lib/Template.php');
		require ('lib/View.php');

		/**
		 * If we're on the command line, set the request to use
		 * the first argument passed to the script.
		 */
		if (defined ('STDIN')) {
			$_SERVER['REQUEST_URI'] = '/' . $argv[1];
		}

		/**
		 * Initialize some core objects. These function as singletons
		 * because only one instance of them per request is desired
		 * (no duplicate execution for things like loading translation
		 * files).
		 */
		$i18n = new I18n ('lang', conf ('I18n'));
		$page = new Page;
		$controller = new Controller (conf ('Hooks'));
		$tpl = new Template (conf ('General', 'charset'), $controller);
		$controller->page ($page);
		$controller->i18n ($i18n);
		$controller->template ($tpl);
		View::init ($tpl);

		/**
		 * Check for a bootstrap.php file in the root of the site
		 * and if found, use it for additional app-level configurations
		 * (Dependency Injection, custom logging settings, etc.).
		 */
		if (file_exists ('bootstrap.php')) {
			require ('bootstrap.php');
		}

		/**
		 * Initialize the built-in cache support. Provides a
		 * consistent cache API (based on Memcache) so we can always
		 * include caching in our handlers and in the front controller.
		 */
		if (! isset ($cache) || ! is_object ($cache)) {
			$cache = Cache::init (conf ('Cache'));
		}
		$controller->cache ($cache);

		/**
		 * Provide global access to core objects, although the preferred
		 * way of accessing these is via the Controller object (`$this`
		 * in handlers).
		 */
		$GLOBALS['i18n'] = $i18n;
		$GLOBALS['page'] = $page;
		$GLOBALS['controller'] = $controller;
		$GLOBALS['tpl'] = $tpl;
		$GLOBALS['cache'] = $cache;

		/**
		 * Run any config level route overrides.
		 */
		if (file_exists ('conf/routes.php')) {
			$_routes = parse_ini_file ('conf/routes.php',true);
			if (isset($_routes['Disable'])){
			foreach ($_routes['Disable'] as $_route => $_strict) {
				if (
					(!$_strict && strpos($_SERVER['REQUEST_URI'],$_route) === 0 && $_SERVER['REQUEST_URI'] !== $_route) //match from left, exclude exact
					|| 
					($_strict && $_SERVER['REQUEST_URI'] == $_route) // match exact
				) {
					$page->body = $controller->run (conf ('General', 'error_handler'), array (
						'code' => 404,
						'title' => 'Page not found.',
						'message' => ''
					));
					echo $page->render ($tpl, $controller); // render 404 page and exit
					return true;
				}
			}}
			if (isset($_routes['Redirect'])){
			foreach ($_routes['Redirect'] as $_old => $_new) {
				if ($_old !== $_new && $_SERVER['REQUEST_URI'] == $_old) $controller->redirect($_new);
			}}
			if (isset($_routes['Alias'])){
			foreach ($_routes['Alias'] as $_old => $_new) {
				if (strpos($_SERVER['REQUEST_URI'],$_old) === 0) {
					$_SERVER['REQUEST_URI'] = str_replace($_old,$_new,$_SERVER['REQUEST_URI']);
					break;
				}
			}}
			unset($_routes);
		}

		/**
		 * Route the request to the appropriate handler and get
		 * the handler's response.
		 */
		if ($i18n->url_includes_lang) {
			$handler = $controller->route ($i18n->new_request_uri);
		} else {
			$handler = $controller->route ($_SERVER['REQUEST_URI']);
		}
		$page->body = $controller->handle ($handler, false);

		/**
		 * Control caching of the response
		 */
		if (conf ('Cache', 'control') && !conf ('General', 'debug')) {
			/* Cache control is ON */
			if (session_id () === '' && $page->cache_control)
			{
				if (isset ($_SERVER["SERVER_SOFTWARE"]) && strpos ($_SERVER["SERVER_SOFTWARE"],"nginx") !== false) {
					/* Allow NGINX to cache this request  - see http://wiki.nginx.org/X-accel */
					$controller->header ('X-Accel-Buffering: yes');
					$controller->header ('X-Accel-Expires: ' . conf ('Cache', 'expires'));
				}
				/* Standard http headers */
				$controller->header ('Cache-Control: public, no-cache="set-cookie", must-revalidate, proxy-revalidate, max-age=0');
				$controller->header ('Pragma: public');
				$controller->header ('Expires: ' . gmdate ('D, d M Y H:i:s', time () + conf ('Cache', 'expires')) . ' GMT');
			} else {
				if (isset ($_SERVER["SERVER_SOFTWARE"]) && strpos ($_SERVER["SERVER_SOFTWARE"],"nginx") !== false) {
					/* Do NOT allow NGINX to cache this request - see http://wiki.nginx.org/X-accel */
					$controller->header ('X-Accel-Buffering: no');
					$controller->header ('X-Accel-Expires: 0');
				}

				/* Standard http headers */
				$controller->header ('Pragma: no-cache');
				$controller->header ('Cache-Control: no-cache, must-revalidate');
				$controller->header ('Expires: 0');
			}
		} else {
			if (isset ($_SERVER["SERVER_SOFTWARE"]) && strpos ($_SERVER["SERVER_SOFTWARE"],"nginx") !== false) {
				/* Do NOT allow NGINX to cache this request by default  - see http://wiki.nginx.org/X-accel */
				$controller->header ('X-Accel-Buffering: no');
				$controller->header ('X-Accel-Expires: 0');
			}
		}

		/**
		 * Render and send the output to the client, using gzip
		 * compression if conf[General][compress_output] is true.
		 */
		$out = $page->render ($tpl, $controller);
		if (extension_loaded ('zlib') && conf ('General', 'compress_output')) {
			ini_set ('zlib.output_compression', 4096);
		}
		@session_write_close ();
		echo $out;
		return true;
	}
Example #25
0
<?php

require_once 'inc/shortcuts.php';
require_once 'inc/db.php';
require_once 'inc/routing.php';
require_once 'models/Planet.php';
require_once 'models/SessionManager.php';
$result = null;
if (SessionManager::is_authenticated() && ($form = is_form_submitted(['declination', 'hour_angle', 'brightness', 'size', 'color', 'message']))) {
    try {
        $planet = new Planet(['declination' => (double) $form['declination'], 'hour_angle' => (double) $form['hour_angle'], 'brightness' => (double) $form['brightness'], 'size' => (double) $form['size'], 'color' => $form['color'], 'message' => $form['message'], 'added_by' => SessionManager::current_user()]);
        $planet->save();
        redirect('/?planet_added=1');
    } catch (DbException $e) {
        $result = $e->getMessage();
    }
}
$index = new Controller('index', ['result' => $result]);
$index->run();
Example #26
0
    {
        $this->dx = $params['dx'];
        $this->height = $params['height'];
    }
    public function jpg_draw()
    {
        echo "Нарисован квадрат в формате jpg.";
    }
    public function arr_draw()
    {
        echo "Квадрат в формате массива точек.";
    }
}
//------------------------------------------------------------------
/* 
 * 
 */
class Controller
{
    function run($shapes)
    {
        foreach ($shapes as $shape) {
            $shape = Shapes::getInstance($shape['type'], $shape['params']);
            $shape->jpg_draw();
        }
    }
}
//------------------------------------------------------------------
$graph_app = new Controller();
$graph_app->run($_POST['params']);
Example #27
0
 /**
  * 解析标签
  * @return bool|void
  */
 public function dispatch()
 {
     //加载路由定义
     require ROOT_PATH . '/system/routes.php';
     //设置路由缓存
     if (C('http.route_cache') && ($route = Cache::get('route'))) {
         $this->route = $route;
         return true;
     }
     $this->parseRoute();
     //匹配路由
     foreach ($this->route as $key => $route) {
         $method = '_' . $route['method'];
         $this->{$method}($key);
         if ($this->found) {
             return null;
         }
     }
     //GET模式处理
     Controller::run();
 }
Example #28
0
 public function run()
 {
     Session::check();
     parent::run();
 }
Example #29
0
 public function testCombinerNotFound()
 {
     $this->markTestIncomplete('Unfinished.');
     $theme = new Theme();
     $theme->load('test');
     $controller = new Controller($theme);
     $response = $controller->run('/combine/xxxxxxxxx');
     $this->assertEquals("The combiner file 'xxx' is not found.", $response->getOriginalContent());
 }
Example #30
0
<?php

require_once 'System/Settings.php';
require_once 'System/Autoloader.php';
require_once 'System/Factory.php';
require_once 'System/Controller.php';
require_once 'System/SystemLog.php';
require_once 'System/Model.php';
$autoloader = new Autoloader($AutoLoad);
$start = new Controller();
try {
    $start->run();
} catch (Exception_404 $e) {
    $start->view('Exceptions/404', false);
    $start->show(array('ERROR_MSG' => $e->getMessage()));
} catch (Exception_Login $e) {
    $start->view('Exceptions/Login', false);
    $start->show(array('ERROR_MSG' => $e->getMessage()));
} catch (Exception $e) {
    $start->view('Exceptions/Exception', false);
    $start->show(array('ERROR_MSG' => $e->getMessage()));
}