Esempio n. 1
0
 protected function teardown()
 {
     Config::restore($this->_backup);
     foreach (glob($this->_indices . '/*') as $file) {
         unlink($file);
     }
 }
Esempio n. 2
0
 public function error()
 {
     if ($this->error instanceof PageNotFoundException) {
         http_response_code(404);
         $this->action = 'pagenotfound';
         $this->viewVars['page'] = $this->error->page;
     } else {
         if ($this->error instanceof NotFoundException) {
             http_response_code(404);
             $this->action = 'notfound';
         } else {
             if ($this->error instanceof ForbiddenException) {
                 http_response_code(403);
                 $this->action = 'forbidden';
             } else {
                 http_response_code(500);
                 $this->action = 'error';
             }
         }
     }
     $this->viewVars['msg'] = $this->error->getMessage();
     if (Config::get('debug')) {
         $this->viewVars['stacktrace'] = $this->error->getTraceAsString();
     }
 }
Esempio n. 3
0
 public function view()
 {
     $page = new Page(Input::get('p', Config::get('index')), 'name');
     $name = urlencode($page->getName() . '.md');
     header('Content-Type: text/x-markdown; charset="UTF-8"');
     header("Content-Disposition: inline; filename=\"{$name}\"");
     echo $page->getHead()->getData();
     return false;
 }
Esempio n. 4
0
 public function testRestore()
 {
     Config::set('index', 'page1');
     $backup = Config::backup();
     Config::set('index', 'page2');
     $this->assertEquals('page2', Config::get('index'));
     Config::restore($backup);
     $this->assertEquals('page1', Config::get('index'));
 }
Esempio n. 5
0
 public function testTimestamp()
 {
     $data = 'FooFooBarBar';
     $id = hash('sha1', $data);
     $file = Config::get('page') . '/object/' . $id;
     touch($file);
     $time = fileatime($file);
     $object = new Object($data, 'data');
     $this->assertEquals($time, fileatime($file));
     $this->assertEmpty(file_get_contents($file));
 }
Esempio n. 6
0
 protected function tearDown()
 {
     Config::restore($this->_backup);
     foreach (glob($this->_pages . '/*/*') as $file) {
         unlink($file);
     }
     foreach (glob($this->_pages . '/*') as $file) {
         if (is_file($file)) {
             unlink($file);
         }
     }
 }
Esempio n. 7
0
 public function testConstruct()
 {
     $theme = new Theme();
     $this->assertEquals(Config::get('theme'), $theme->name);
 }
Esempio n. 8
0
 public function upload($options = [])
 {
     $this->_enforceExists();
     if ($this->method == 'POST' && Input::hasFile('file')) {
         $file = Input::file('file');
         if ($file['error']) {
             throw new InternalErrorException();
         }
         if (!in_array($file['type'], Config::get('filetype'))) {
             throw new ForbiddenException('Invalid file type');
         }
         if ($file['size'] > Config::get('maxsize')) {
             throw new ForbiddenException('Too large file');
         }
         if (!is_uploaded_file($file['tmp_name'])) {
             throw new ForbiddenException('Invalid file');
         }
         $id = $this->page->getId() . '_' . sha1($file['name']);
         $dst = dirname(dirname(dirname(__FILE__))) . '/file/' . $id;
         if (!move_uploaded_file($file['tmp_name'], $dst)) {
             throw new InternalErrorException();
         }
         file_put_contents($dst . '.json', json_encode($file));
         return $this->redirect('?a=edit&p=' . urlencode($this->page->name));
     }
 }
Esempio n. 9
0
File: Index.php Progetto: hawkao/mew
 public function getFilePath()
 {
     return Config::get('page') . '/index/' . $this->_id;
 }
Esempio n. 10
0
File: Page.php Progetto: hawkao/mew
 static function getPages()
 {
     return array_map(function ($file) {
         return new Page(basename($file));
     }, array_filter(glob(Config::get('page') . '/*'), 'is_file'));
 }
Esempio n. 11
0
 public function __construct()
 {
     $this->theme = new Theme(Config::get('theme'));
     $this->sidebar = new Page(Config::get('sidebar'), 'name');
 }
Esempio n. 12
0
File: Theme.php Progetto: hawkao/mew
 public function __construct()
 {
     $this->name = Config::get('theme');
 }
Esempio n. 13
0
File: index.php Progetto: hawkao/mew
<?php

require_once __DIR__ . '/vendor/autoload.php';
use ukatama\Mew\Config;
use ukatama\Mew\Input;
use ukatama\Mew\PageController;
use ukatama\Mew\Registry;
ini_set('display_errors', Config::get('debug'));
try {
    Registry::controller(Input::get('c', 'page'))->dispatch(Input::get('a', 'view'));
} catch (Exception $e) {
    $ctr = Registry::controller('error');
    $ctr->error = $e;
    $ctr->dispatch('error');
}
Esempio n. 14
0
 public function testConstruct()
 {
     $ctr = new Controller();
     $this->assertEquals(Config::get('theme'), $ctr->theme->name);
     $this->assertEquals(Config::get('sidebar'), $ctr->sidebar->getName());
 }