protected function teardown() { Config::restore($this->_backup); foreach (glob($this->_indices . '/*') as $file) { unlink($file); } }
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(); } }
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; }
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')); }
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)); }
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); } } }
public function testConstruct() { $theme = new Theme(); $this->assertEquals(Config::get('theme'), $theme->name); }
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)); } }
public function getFilePath() { return Config::get('page') . '/index/' . $this->_id; }
static function getPages() { return array_map(function ($file) { return new Page(basename($file)); }, array_filter(glob(Config::get('page') . '/*'), 'is_file')); }
public function __construct() { $this->theme = new Theme(Config::get('theme')); $this->sidebar = new Page(Config::get('sidebar'), 'name'); }
public function __construct() { $this->name = Config::get('theme'); }
<?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'); }
public function testConstruct() { $ctr = new Controller(); $this->assertEquals(Config::get('theme'), $ctr->theme->name); $this->assertEquals(Config::get('sidebar'), $ctr->sidebar->getName()); }