Ejemplo n.º 1
0
 /**
  * Load Files
  *
  * Loads models, controllers and helpers.
  */
 static function start()
 {
     require SYSROOT . 'data/app_controllers.php';
     require SYSROOT . 'classes/application.php';
     require SYSROOT . 'classes/application_helpers.php';
     require SYSROOT . 'classes/application_models.php';
     require SYSROOT . 'classes/record_errors.php';
     require SYSROOT . 'classes/cookies.php';
     require SYSROOT . 'classes/request_params.php';
     require SYSROOT . 'classes/collection.php';
     Application::load_files();
     foreach (self::$conf->autoload_models as $model) {
         Application::$models->{$model}->load();
     }
     if (self::$conf->system_error_reporting) {
         set_error_handler('system_error_reporting');
     }
     ActionController::start();
     if (System::$conf->show_errors_on_json && Request::$format == 'json') {
         set_error_handler('json_error_handler');
     }
     include CTRLSPATH . 'application.php';
     include ROOT . 'app/helpers/application_helper.php';
     ActionController::load_controller();
     if (!ActionController::action_exists()) {
         if (!ActionController::rescue_action()) {
             exit_with_status(404);
         }
     }
 }
/**
 * Verify request method
 *
 * @param string $method  - Request method to verify (post, get, etc).
 * @param array $actions  - Controller's actions to verify. The first value must be
 *                          either 'only' or 'except' to filter actions.
 * @param array callback  - Not yet supported. Custom callback function to call in case the verification fails.
 *                          By default the script will exit with a 400 HTTP status.
 */
function verify_method($method, $actions, $callback = array())
{
    $filter = array_shift($actions);
    if (!filter_actions($filter, $actions)) {
        return;
    }
    if (Request::$method !== strtoupper($method)) {
        exit_with_status(400);
    }
}
Ejemplo n.º 3
0
 static function start()
 {
     Request::parse_request();
     try {
         self::routing();
     } catch (Exception $e) {
         self::exit_with_status(500, $e->getMessage());
     }
     if (!self::controller_exists()) {
         if (!self::rescue_controller()) {
             exit_with_status(404);
         }
     }
 }
Ejemplo n.º 4
0
define('ACTVIEW', SYSROOT . 'action_view/');
require SYSROOT . 'system.php';
require SYSROOT . 'config/config.php';
require SYSROOT . 'config/config_system.php';
require SYSROOT . 'database/initialize.php';
require SYSROOT . 'load_functions.php';
require SYSROOT . 'request.php';
require SYSROOT . 'action_controller.php';
require ACTVIEW . 'action_view.php';
require SYSROOT . 'status_codes.php';
require SYSROOT . 'active_record.php';
require ROOT . 'config/config.php';
require ROOT . 'config/routes.php';
System::start();
/**
 * NOTE: in the case an action file needs to do "return;" (like post#show),
 * it must NOT return false, else it will be taken like the file wasn't found,
 * causing a missunderstanding.
 * (This also applies when including partials)
 * 
 * If an action returns an int, the system will exit with such HTTP status.
 */
$include = (include CTRLSPATH . Request::$controller . '/' . Request::$action . '.php');
if ($include === false) {
    ActionController::exit_with_error(500, 'Could not find action file.');
} elseif (is_int($include) && $include !== 1) {
    exit_with_status($include);
}
unset($include);
ActionController::run_after_filters();
include ACTVIEW . 'render.php';
Ejemplo n.º 5
0
<?php

if (isset(ActionView::$params['status'])) {
    ActionView::$set_status(ActionView::$params['status']);
    unset(ActionView::$params['status']);
}
if (!empty(ActionView::$params['layout'])) {
    ActionView::$layout = ActionView::$params['layout'];
    unset(ActionView::$params['layout']);
}
if (array_key_exists('nothing', ActionView::$params) && ActionView::$params['nothing'] === true) {
    exit;
}
if (empty(ActionView::$params)) {
    if (Request::$format == 'html' || Request::$format == 'xml') {
        require ACTVIEW . 'render_markup_default.php';
    }
}
# If we got here and format is json, for now, this means the action doesn't support json.
if (Request::$format == 'json') {
    exit_with_status(400);
}
# TODO: change die for a nicer way to exit.
if (!empty(ActionView::$params['render_type'])) {
    if (ActionView::$params['render_type'] == 'inline') {
        echo ActionView::$params['render_value'];
    }
} else {
    if (false === (include ActionView::$render)) {
        if (System::$conf->system_error_reporting) {
            die('Unable to find View file.');
        } else {
            exit_with_status(500);
        }
    }
}
ActionView::$content_for['layout'] = ob_get_clean();
if (Request::$format == 'html' && !empty(ActionView::$layout)) {
    if (!(include LAYOUTS . ActionView::$layout . '.php')) {
        if (System::$conf->system_error_reporting) {
            die('Unable to load Layout.');
        } else {
            exit_with_status(500);
        }
    }
} else {
    if (Request::$format == 'html') {
        content_for('layout');
    } elseif (Request::$format == 'xml') {
        content_for('layout');
    }
}
exit;
Ejemplo n.º 7
0
<?php

required_params('id');
auto_set_params('reason');
if (!($post = Post::find(Request::$params->id))) {
    exit_with_status(404);
}
if (!empty(Request::$params->unflag)) {
    # Allow the user who flagged a post to unflag it.
    #
    # posts
    # "approve" is used both to mean "unflag post" and "approve pending post".
    if ($post->status != "flagged") {
        respond_to_error("Can only unflag flagged posts", array("#show", 'id' => Request::$params->id));
    }
    if (!User::is('>=40') and User::$current->id != $post->flag_detail->user_id) {
        access_denied();
    }
    $post->approve(User::$current->id);
    $message = "Post approved";
} else {
    if ($post->status != "active") {
        respond_to_error("Can only flag active posts", array("#show", 'id' => Request::$params->id));
    }
    $post->flag(Request::$params->reason, User::$current->id);
    $message = "Post flagged";
}
# Reload the post to pull in post.flag_reason.
$post->reload();
if (Request::$format == "json" || Request::$format == "xml") {
    $api_data = Post::batch_api_data(array($post));
Ejemplo n.º 8
0
 static function parse_request()
 {
     self::$params = new RequestParams();
     # Get method
     self::$method = $_SERVER['REQUEST_METHOD'];
     self::$remote_ip = $_SERVER['REMOTE_ADDR'];
     if (self::$method === 'POST') {
         self::$post = true;
     } elseif (self::$method === 'GET') {
         self::$get = true;
     }
     self::$abs_url =& $_SERVER['REQUEST_URI'];
     self::$url = preg_replace('~\\?.*~', '', $_SERVER['REQUEST_URI']);
     if (!System::$conf->php_parses_routes) {
         if (empty($_GET['URLtoken'])) {
             exit_with_status(404);
             die('Impossible to find route. Bad htaccess config?');
         }
         # $_GET is filled with parameters from htaccess.
         # Parse them accordingly and fill $_GET with url parameters.
         list($_GET['controller'], $_GET['action']) = explode('@', $_GET['URLtoken']);
         empty($_GET['controller']) && exit_with_status(404);
         empty($_GET['action']) && ($_GET['action'] = 'index');
         unset($_GET['URLtoken']);
         foreach ($_GET as $param => $value) {
             if (!property_exists('Request', $param)) {
                 continue;
             }
             self::${$param} = $value;
             unset($_GET[$param]);
         }
         empty(self::$format) && (self::$format = 'html');
         # Parse GET params from $abs_url
         if (!is_bool(strpos(self::$abs_url, '?'))) {
             $get_params = urldecode(substr(self::$abs_url, strpos(self::$abs_url, '?') + 1));
             $get_params = explode('&', $get_params);
             foreach ($get_params as $gp) {
                 $param = explode('=', $gp);
                 if (empty($param[0]) || empty($param[1])) {
                     continue;
                 }
                 $_GET[$param[0]] = $param[1];
             }
         }
     }
     # Get post/get parameters
     add_props(self::$params, $_GET, false);
     add_props(self::$params, $_POST, false);
     self::$get_params =& $_GET;
     self::$post_params =& $_POST;
 }