Beispiel #1
0
 function getCode($no)
 {
     $_this =& StatusCodes::getInstance();
     if (!empty($_this->codes[$no])) {
         return array_merge(array("no" => $no), $_this->codes[$no]);
     } else {
         return false;
     }
 }
 /**
  * Handle various error operations /error/xxxx
  *
  * @param object	$context	The context object for the site
  *
  * @return string	A template name
  */
 public function handle($context)
 {
     $tpl = 'error/error.twig';
     $rest = $context->rest();
     switch ($rest[0]) {
         case '404':
             $tpl = 'error/404.twig';
             $context->local()->addval('page', $context->getpar('page', ''));
             break;
         default:
             $context->local()->addval(array('code' => $rest[0], 'message' => StatusCodes::getMessage($rest[0])));
             break;
     }
     header(StatusCodes::httpHeaderFor($rest[0]));
     return $tpl;
 }
Beispiel #3
0
 /**
  * 
  * Output an error in the specified return format with the correct HTTP header, and possibly with a custom message
  * @param int $errorcode	HTTP response code
  * @param str $msg			Custom error message (still will get the generic HTTP header)
  * @param bool $continue 	Whether to continue the script after outputting the error, defaults to false
  */
 private function _output_error($errorcode, $msg = false, $continue = false)
 {
     header(StatusCodes::httpHeaderFor($errorcode));
     $this->data['content'] = array('error' => array('message' => $msg ? $msg : StatusCodes::getMessageForCode($errorcode), 'code' => $errorcode));
     $this->_output();
     if (!$continue) {
         exit;
     }
 }
Beispiel #4
0
 /**
  * Output information about a group of pages based on class name
  */
 public function instancesof($class = '')
 {
     if ('system' == $class) {
         return self::system();
     }
     // Built-in pages
     try {
         $class = no_ext($class);
         $type = $category = null;
         $rel = RDF_Object::REL_CHILDREN_ONLY;
         switch ($class) {
             case 'content':
                 $model = 'pages';
                 break;
             case 'page':
             case 'composite':
                 $model = 'pages';
                 $type = 'composite';
                 break;
             case 'file':
             case 'media':
                 $model = 'pages';
                 $type = 'media';
                 break;
             case 'review':
             case 'commentary':
             case 'term':
                 $model = 'pages';
                 $category = $class;
                 break;
             case 'annotation':
             case 'reply':
             case 'tag':
             case 'path':
             case 'reference':
                 $this->load->model($class . '_model', plural($class));
                 $model = plural($class);
                 break;
             default:
                 header(StatusCodes::httpHeaderFor(StatusCodes::HTTP_NOT_FOUND));
                 exit;
         }
         $content = $this->{$model}->get_all($this->data['book']->book_id, $type, $category, $this->data['hidden'] ? false : true);
         $this->rdf_object->index($this->data['content'], array('book' => $this->data['book'], 'content' => $content, 'base_uri' => $this->data['base_uri'], 'method' => __FUNCTION__ . '/' . $class, 'restrict' => $this->data['restrict'], 'rel' => $rel, 'sq' => $this->data['sq'], 'versions' => $this->data['versions'] ? RDF_Object::VERSIONS_ALL : RDF_Object::VERSIONS_MOST_RECENT, 'ref' => $this->data['references'] ? RDF_Object::REFERENCES_ALL : RDF_Object::REFERENCES_NONE, 'prov' => $this->data['provenance'] ? RDF_Object::PROVENANCE_ALL : RDF_Object::PROVENANCE_NONE, 'pagination' => $this->data['pagination'], 'max_recurses' => $this->data['recursion']));
         $this->rdf_object->serialize($this->data['content'], $this->data['format']);
     } catch (Exception $e) {
         header(StatusCodes::httpHeaderFor(StatusCodes::HTTP_INTERNAL_SERVER_ERROR));
         exit;
     }
     $this->template->set_template('blank');
     $this->template->write_view('content', 'modules/data/' . $this->data['format'], $this->data);
     $this->template->render();
 }
Beispiel #5
0
 /**
  * Private function make_file_name doesn't override since defining
  * several different types in the super-class isn't useful.
  * Only required to be private either way. Each class implements it
  * in a completely different manner anyway.
  * @param $line - line code specified in URL request
  * @param $lines_list - the array of valid line codes
  * @return string - file name to be used for reading/writing cache file
  */
 private static function make_file_name($line, $lines_list)
 {
     // Construct the filename for output
     $filename = BASE_FILE . PREDICTION_SUMMARY . DIV;
     // Check line isn't empty, and line code is valid
     if ($line != null and array_key_exists($line, $lines_list) !== false) {
         $filename .= $line . FILE_EXTENSION;
     } else {
         // Fail fast if the line code is invalid/missing
         header(StatusCodes::httpHeaderFor(StatusCodes::HTTP_BAD_REQUEST));
         die("{\"error\":\"Invalid line code\"}");
     }
     return $filename;
 }
Beispiel #6
0
 /**
  * Make a header sequence for a particular return code and add some other useful headers
  *
  * @param integer	$code	The HTTP return code
  * @param string	$mtype	The mime-type of the file
  * @param string 	$length	The length of the data
  * @param string	$name	A file name
  *
  * @return void
  */
 public function sendheaders($code, $mtype = '', $length = '', $name = '')
 {
     header(StatusCodes::httpHeaderFor($code));
     $this->putheaders();
     if ($mtype !== '') {
         header('Content-Type: ' . $mtype);
     }
     if ($length !== '') {
         header('Content-Length: ' . $length);
     }
     if ($name !== '') {
         header('Content-Disposition: attachment; filename="' . $name . '"');
     }
 }