Esempio n. 1
0
function shutDownFunction()
{
    $error = error_get_last();
    if ($error['type']) {
        HTTP::error(500, $error['type'], $error["message"], $error["file"], $error["line"]);
        return true;
    }
}
Esempio n. 2
0
 public static function listen()
 {
     $found_route = self::findRoute($_SERVER['REQUEST_METHOD'], self::getRoute());
     if ($found_route != null) {
         echo $found_route->run();
     } else {
         HTTP::error(404);
     }
 }
Esempio n. 3
0
 public function timeline_for_trans_id()
 {
     $trans_id = isset($_REQUEST['id']) ? $_REQUEST['id'] : $_REQUEST['trans_id'];
     $conn = $this->get_connection();
     $transaction = new Transaction();
     if ($transaction->find_by_id($trans_id)) {
         $this->redirect_to(array('action' => 'timeline', 'id' => $transaction->isin));
     } else {
         HTTP::error(404);
     }
 }
Esempio n. 4
0
 /**
  *	@fn start_download
  *	@short Initiates the download of the file.
  *	@details This method takes control of the response by setting the relevant
  *	HTTP headers for content type, size and cache control, then outputs
  *	the contents of the file to the client.
  */
 public function start_download()
 {
     if (!file_exists($this->filename)) {
         HTTP::error(404);
     }
     header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
     header('Content-Description: File Transfer');
     header('Content-Type: application/octet-stream');
     header('Content-Length: ' . filesize($this->filename));
     header('Content-Disposition: attachment; filename=' . basename($this->filename));
     readfile($this->filename);
     exit;
 }
Esempio n. 5
0
 /**
  *	@fn _init_software
  *	@short Private method that initializes repetitive members of software product page actions.
  */
 private function _init_software()
 {
     $conn = Db::get_connection();
     if (isset($_REQUEST['software_name'])) {
         $software_factory = new Software();
         $softwares = $software_factory->find_all(array('where_clause' => '`name` = \'' . $conn->escape($_REQUEST['software_name']) . '\' AND `type` = \'' . $conn->escape($_REQUEST['software_type']) . '\'', 'limit' => 1));
         if (count($softwares) > 0) {
             $this->software = $softwares[0];
         } else {
             $softwares = $software_factory->find_by_query('SELECT `softwares`.`id` ' . 'FROM `softwares` ' . 'LEFT JOIN `software_typos` ON `softwares`.`id` = `software_typos`.`software_id` ' . 'WHERE `software_typos`.`typo` = \'' . $conn->escape($_REQUEST['software_name']) . '\' ' . 'LIMIT 1');
             if (count($softwares) > 0) {
                 $this->software = $softwares[0];
                 header(sprintf('Location: http://%s%s', $_SERVER['HTTP_HOST'], $this->software->url_to_detail($_REQUEST['subview'])));
                 exit;
             } else {
                 HTTP::error(404);
             }
         }
         $_REQUEST['id'] = $this->software->id;
     } else {
         if (isset($_GET['id'])) {
             $this->software = new Software();
             if ($this->software->find_by_id($_GET['id']) === FALSE) {
                 $this->flash(l('No such software product!'), 'error');
                 $this->redirect_to(array('action' => 'index'));
             }
         } else {
             HTTP::error(404);
         }
     }
     $this->software->has_many('software_releases', array('where_clause' => '`released` = \'1\''));
     $releases = $this->software->software_releases;
     usort($releases, array($releases[0], 'sort_releases'));
     $this->release = $releases[0];
     $this->software->software_releases = $releases;
     Db::close_connection($conn);
 }
Esempio n. 6
0
 /**
  *	@fn go
  *	@short Action method that redirects to an external article.
  */
 public function go()
 {
     $this->article = new DiarioPost();
     if ($this->article->find_by_id($_REQUEST['id']) === FALSE) {
         $this->flash(l('No such article'), 'error');
         $this->redirect_to(array('action' => 'index'));
     }
     if ($this->article->status != 'pubblicato' || $this->article->external_url == NULL) {
         HTTP::error(404);
     }
     // Annotates that the article has been read
     $this->article->readings++;
     $this->article->save();
     header(sprintf('Location: %s', $this->article->external_url));
     exit;
 }
Esempio n. 7
0
 /**
  *	@short Loads the contents of the desired view file.
  *	@details This method returns the contents of the requested view file
  *	without parsing.
  *	@param filename The name of the view file to load.
  */
 protected function load_part_contents($filename)
 {
     if (!file_exists($filename)) {
         HTTP::error(500);
     }
     $contents = file_get_contents($filename);
     return $this->strip_external_php_tags($contents);
 }
Esempio n. 8
0
<?php

require_once dirname(__FILE__) . "/include/common.inc.php";
require_once dirname(__FILE__) . "/helpers/application_helper.php";
require_once dirname(__FILE__) . "/helpers/http.php";
define('APPLICATION_ROOT', '/creso.new/');
try {
    if (isset($_REQUEST['controller']) && !empty($_REQUEST['controller'])) {
        // Include controller class
        $controller_file = dirname(__FILE__) . "/controllers/{$_REQUEST['controller']}_controller.php";
        if (!file_exists($controller_file)) {
            HTTP::error(404);
        }
        require $controller_file;
        // Instantiate main controller
        $main_controller = eval("return new " . ucwords($_REQUEST['controller']) . "Controller();");
        // Request rendering of the page
        // (If action didn't already do it before)
        $main_controller->render_page();
    } else {
        HTTP::error(400);
    }
} catch (Exception $e) {
    die("Exception {$e}");
    HTTP::error(500);
}
Esempio n. 9
0
 /**
  *	@fn include_localized($filename)
  *	@short Includes a localized version of the requested filename if possible.
  *	@details Checks if a localized version of the requested filename exists, otherwise
  *	calls <tt>include</tt>.
  *	@param filename The name of the file to be included.
  */
 protected function include_localized($filename)
 {
     $localized_filename = @preg_replace("/\\.([^\\.]+)\$/", "-{$_COOKIE['hl']}.\\1", $filename);
     if (file_exists($localized_filename)) {
         include $localized_filename;
     } else {
         if (!file_exists($filename)) {
             HTTP::error(500);
         }
         include $filename;
     }
 }
Esempio n. 10
0
 /**
  *  @fn toggle_favorite
  *  @short Toggles a favorite instrument
  *  @details Action to toggle an instrument as favorite, handles the postback
  *  action to save the model.
  */
 public function toggle_favorite()
 {
     if ($this->request->is_post()) {
         $_POST['isin'] = $_REQUEST['id'];
         if ($this->is_favorite) {
             $this->favorite->delete();
             unset($this->favorite);
             $this->is_favorite = FALSE;
         } else {
             $_POST['isin'] = $_REQUEST['id'];
             $favorite = new Favorite(array('utente' => $_COOKIE['username'], 'isin' => $_POST['isin']));
             $favorite->save();
             $this->is_favorite = TRUE;
         }
         die("{\"isin\":\"{$_REQUEST['id']}\",\"favorite\":" . ($this->is_favorite ? 'true' : 'false') . "}");
     } else {
         HTTP::error(400);
     }
 }