static function exit_with_status($status, $msg = null)
 {
     if (System::$conf->system_error_reporting) {
         ActionView::set_http_status($status);
         die($msg);
     } else {
         exit_with_status($status);
     }
 }
Example #2
0
 static function render($type, $value = null, $params = array())
 {
     if ($type === false) {
         self::$params['nothing'] = true;
         return;
     }
     if (is_int(strpos($type, '#'))) {
         /**
          * We're rendering a controller/action file.
          * In this case, $value holds the params, and we only change
          * the 'render' value and return. We can't call the
          * render file within this or any function because of variables scope.
          * 
          * This is expected to occur in a controller, therefore in the controller one must
          * also return; after calling this function, so further code won't be executed.
          */
         list($ctrl, $act) = explode('#', parse_url_token($type));
         self::parse_parameters($value);
         self::$render = VIEWPATH . "{$ctrl}/{$act}.php";
         return;
     }
     # Running after-filters.
     ActionController::run_after_filters();
     self::parse_parameters($params);
     if ($type == 'json') {
         header('Content-Type: application/json; charset=utf-8');
         if (is_array($value)) {
             $value = to_json($value);
         }
         echo $value;
         exit;
     } elseif ($type == 'xml') {
         header('Content-type: application/rss+xml; charset=UTF-8');
         if (is_array($value) || is_object($value)) {
             $root = isset($params['root']) ? $params['root'] : 'response';
             $value = to_xml($value, $root);
         }
         echo $value;
         exit;
     } elseif ($type == 'inline') {
         self::$params['render_type'] = 'inline';
         self::$params['render_value'] = $value;
         include SYSROOT . 'action_view/render_markup_default.php';
     }
 }
Example #3
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);
}
Example #4
0
 /**
  * Act as an internal constructor.
  * 
  * @param Request request, the request
  * @param Response response, the response
  */
 private function instantiate(Request $request, Response $response)
 {
     // class memebers
     $this->request = $request;
     $this->response = $response;
     $this->params = $request->getParameters();
     $this->logger = Registry::get('__logger');
     $this->injector = Registry::get('__injector');
     $this->config = Registry::get('__configurator');
     $this->session = $request->getSession();
     $this->app_path = $this->injector->getPath('__base');
     $this->template_root = $this->injector->getPath('views') . $this->params['controller'] . DIRECTORY_SEPARATOR;
     $this->template = ActionView::factory('php');
     // register session container if any
     // TODO: this should be moved elsewhere
     if ($this->config->getWebContext()->session !== NULL && $this->config->getWebContext()->session->container !== NULL) {
         // container location.
         $c_location = str_replace('.', DIRECTORY_SEPARATOR, (string) $this->config->getWebContext()->session->container) . '.php';
         include_once $c_location;
         // container class name.
         $e = explode('.', (string) $this->config->getWebContext()->session->container);
         // reflect on container.
         $container = new ReflectionClass(end($e));
         if ($container->implementsInterface('ISessionContainer')) {
             $this->session->setContainer($container->newInstance());
         }
     }
     // predefined variables:
     // TODO: check if we have a / at the end, if not, add one
     $this->template->assign('__base', (string) $this->config->getWebContext()->document_root);
     $this->template->assign('__server', (string) $this->config->getWebContext()->server_name);
     $this->template->assign('__controller', $this->params['controller']);
     $this->template->assign('__version', Medick::getVersion());
     $this->template->assign('__self', $this->__base . $this->request->getRequestUri());
     $this->logger->debug($this->request->toString());
 }
<?php

if (Request::$format == 'html') {
    header('Content-Type: text/html; charset=UTF-8');
    !ActionView::$render && (ActionView::$render = VIEWPATH . Request::$controller . '/' . Request::$action . '.php');
} elseif (Request::$format == 'xml') {
    header('Content-type: application/rss+xml; charset=UTF-8');
    !ActionView::$render && (ActionView::$render = VIEWPATH . Request::$controller . '/' . Request::$action . '.xml.php');
}
ob_start();
# 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);
Example #6
0
 private function __initialize(Request $request, Response $response)
 {
     // instance variables
     $this->request = $request;
     $this->response = $response;
     $this->execution_chain = new ExecutionChain($this, $this->context);
     // do we need to register and start a session?
     $this->__register_session();
     $this->controller = $this->request->parameter('controller');
     // create the template now.
     $this->template = ActionView::load($this->context, $this);
     // assign basic template variables.
     $this->template->assign('__controller', $this->controller);
     $this->template->assign('__action', $this->request->parameter('action'));
     return true;
 }
Example #7
0
 public function renderPartial($file, $data)
 {
     $oView = new ActionView($this->oController, $file, $data);
     echo $oView->fetch();
 }
Example #8
0
    }
    // @preload = @preload.delete_if { |post| not post.can_be_seen_by?(@current_user) }
}
if ($from_api and isset(Request::$params->api_version) && Request::$params->api_version == "2" and Request::$format != "json") {
    respond_to_error("V2 API is JSON-only", array(), array('status' => 424));
}
// @posts.replace(results)
$posts = $results;
unset($results);
switch (Request::$format) {
    case 'json':
        if (empty(Request::$params->api_version) || Request::$params->api_version != "2") {
            render('json', to_json(array_map(function ($p) {
                return $p->api_attributes();
            }, (array) $posts)));
            return;
        }
        $api_data = Post::batch_api_data($posts, array('exclude_tags' => !empty(Request::$params->include_tags) ? false : true, 'exclude_votes' => !empty(Request::$params->include_votes) ? false : true, 'exclude_pools' => !empty(Request::$params->include_pools) ? false : true));
        render('json', to_json($api_data));
        break;
    case 'xml':
        ActionView::$layout = false;
        return;
        break;
}
if (!empty($split_tags)) {
    $tags = Tag::parse_query($tags);
} else {
    $tags['include'] = Tag::count_by_period(gmd_math('sub', '1D'), gmd(), array('limit' => 25, 'exclude_types' => CONFIG::$exclude_from_tag_sidebar));
}
calc_pages();
Example #9
0
function redirect_to($url, $url_params = array(), $redirect_params = array())
{
    ActionView::redirect_to($url, $url_params, $redirect_params);
    // $args = func_get_args();
    // call_user_func_array('ActionView::redirect_to', $args);
}