Exemplo n.º 1
0
 /**
  * Sends the correct header for the response
  *
  * @param boolean $send If set to false, the header will be returned
  * @return mixed
  */
 public function header($send = true)
 {
     $status = header::status($this->code, false);
     $type = header::type($this->format, 'utf-8', false);
     if (!$send) {
         return $status . PHP_EOL . $type;
     }
     header($status);
     header($type);
 }
Exemplo n.º 2
0
 /**
  * Sends an appropriate header for the asset
  *
  * @param boolean $send
  * @return mixed
  */
 public function header($send = true)
 {
     return header::type($this->mime(), false, $send);
 }
Exemplo n.º 3
0
 /**
  * Starts the router, renders the page and returns the response
  *
  * @return mixed
  */
 public function launch()
 {
     // this will trigger the configuration
     $site = $this->site();
     // force secure connections if enabled
     if ($this->option('ssl') and !r::secure()) {
         // rebuild the current url with https
         go(url::build(array('scheme' => 'https')));
     }
     // set the timezone for all date functions
     date_default_timezone_set($this->options['timezone']);
     // load all extensions
     $this->extensions();
     // load all plugins
     $this->plugins();
     // load all models
     $this->models();
     // start the router
     $this->router = new Router($this->routes());
     $this->route = $this->router->run($this->path());
     // check for a valid route
     if (is_null($this->route)) {
         header::status('500');
         header::type('json');
         die(json_encode(array('status' => 'error', 'message' => 'Invalid route or request method')));
     }
     // call the router action with all arguments from the pattern
     $response = call($this->route->action(), $this->route->arguments());
     // load all language variables
     // this can only be loaded once the router action has been called
     // otherwise the current language is not yet available
     $this->localize();
     // build the response
     $this->response = $this->component('response')->make($response);
     // store the current language in the session
     if ($this->site()->multilang() && ($language = $this->site()->language())) {
         s::set('language', $language->code());
     }
     return $this->response;
 }
Exemplo n.º 4
0
Arquivo: f.php Projeto: chrishiam/LVSL
 /**
  * Read and send the file with the correct headers
  *
  * @param string $file
  */
 public static function show($file)
 {
     // stop the download if the file does not exist or is not readable
     if (!is_file($file) or !is_readable($file)) {
         return false;
     }
     // send the browser headers
     header::type(f::mime($file));
     // send the file
     die(f::read($file));
 }
Exemplo n.º 5
0
 */
Pages::$methods['feed'] = function ($pages, $params = array()) {
    // set all default values
    $defaults = array('url' => url(), 'title' => 'Blog Feed', 'description' => 'Latest articles from the blog', 'link' => url(), 'datefield' => 'modified', 'textfield' => 'text', 'modified' => time(), 'excerpt' => false, 'generator' => kirby()->option('feed.generator', 'Kirby'), 'header' => true, 'snippet' => false);
    // merge them with the user input
    $options = array_merge($defaults, $params);
    // sort by date
    $items = $pages->sortBy($options['datefield'], 'desc');
    // add the items
    $options['items'] = $items;
    $options['link'] = url($options['link']);
    // fetch the modification date
    if ($options['datefield'] == 'modified') {
        $options['modified'] = $items->first()->modified();
    } else {
        $options['modified'] = $items->first()->date(false, $options['datefield']);
    }
    // send the xml header
    if ($options['header']) {
        header::type('text/xml');
    }
    // echo the doctype
    $html = '<?xml version="1.0" encoding="utf-8"?>' . PHP_EOL;
    // custom snippet
    if ($options['snippet']) {
        $html .= snippet($options['snippet'], $options, true);
    } else {
        $html .= tpl::load(__DIR__ . DS . 'template.php', $options);
    }
    return $html;
};
Exemplo n.º 6
0
 public function response()
 {
     // this will trigger the configuration
     $site = $this->site();
     $router = new Router($this->routes());
     $route = $router->run($this->path());
     // check for a valid route
     if (is_null($route)) {
         header::status('500');
         header::type('json');
         die(json_encode(array('status' => 'error', 'message' => 'Invalid route or request method')));
     }
     $response = call($route->action(), $route->arguments());
     if (is_string($response)) {
         $this->response = static::render(page($response));
     } else {
         if (is_array($response)) {
             $this->response = static::render(page($response[0]), $response[1]);
         } else {
             if (is_a($response, 'Response')) {
                 $this->response = $response;
             } else {
                 if (is_a($response, 'Page')) {
                     $this->response = static::render($response);
                 } else {
                     $this->response = null;
                 }
             }
         }
     }
     return $this->response;
 }
 if ($page && ($image = $page->file($filename . $extension))) {
     $modified = substr(md5($image->modified()), 0, 12);
     if ($modified === $hash) {
         // thumb root
         $path = str_replace('/', DS, $page->id());
         $root = kirby()->roots()->index() . DS . 'thumbs' . DS . $path;
         // create directories if necessary
         if (!f::exists($root)) {
             dir::make($root, true);
         }
         // thumb url
         $url = kirby()->urls()->index() . '/thumbs/' . $page->id();
         // create thumb
         $thumb = thumb($image, array('destination' => true, 'width' => $width, 'filename' => '{safeName}-{width}-' . $modified . '.{extension}', 'root' => $root, 'url' => $url));
         // send headers
         header::type($image->mime());
         header('Cache-control: max-age=' . 60 * 60 * 24 * 365);
         header('Expires: ' . gmdate(DATE_RFC1123, time() + 60 * 60 * 24 * 365));
         // read file
         function readFileChunked($filename, $retbytes = true)
         {
             $chunkSize = 8192;
             $buffer = '';
             $cnt = 0;
             $handle = fopen($filename, 'rb');
             if ($handle === false) {
                 return false;
             }
             while (!feof($handle)) {
                 $buffer = fread($handle, $chunkSize);
                 echo $buffer;