Exemple #1
0
 /**
  * Parse requested page from file
  * 
  * @param array $uri Uri from request
  */
 public function renderRequest($uri)
 {
     $file = array();
     $file[] = Filters::arrayToPath(array($this->site, 'content'));
     $request = Filters::arrayToUri($uri);
     $this->api = array_merge($this->api, $this->crawler->indexContent($file[0], $uri));
     if (isset($this->api['index'][$request])) {
         $file[] = $this->api['index'][$request];
     } else {
         $file[] = '404';
         $file[] = 'index.txt';
     }
     $this->api['request'] = $this->content->parseFile($file);
     $this->api['request']['uri'] = $uri;
     $this->api['request']['file'] = $file;
 }
Exemple #2
0
 /**
  * Parse markdown file
  *
  * @param array or string $file Absolute path to file
  * @return array Result of rendering with statuscode, content and metadata
  */
 public function parseFile($file)
 {
     $file = Filters::arrayToPath($file);
     // File found
     if (file_exists($file)) {
         $file = file_get_contents($file, FILE_USE_INCLUDE_PATH);
         $file = $this->splitFile($file);
         // Metadata found
         if (count($file) > 1) {
             $content = $this->parseMarkdown($file[1]);
             $metadata = $this->parseMetadata($file[0]);
             $status = isset($metadata['status']) ? $metadata['status'] : 200;
             return array('status' => $status, 'content' => $content, 'metadata' => $metadata);
             // No metadata found
         } else {
             return array('status' => 200, 'content' => $this->parseMarkdown($file[0]));
         }
         // File not found, return false
     } else {
         return array('status' => 404, 'content' => false);
     }
 }
Exemple #3
0
 /**
  * Create index record
  *
  * @param array or string $path Path to index.txt file
  * @param array $uri Uri that matches index.txt file
  */
 private function createIndex($path, $uri)
 {
     $path[] = 'index.txt';
     $this->index[Filters::arrayToUri($uri)] = Filters::arrayToPath($path);
 }