Esempio n. 1
0
 public function upload()
 {
     if (Input::hasFile('files') && $this->method === 'POST') {
         $files = Input::file('files');
         $num = count($files['name']);
         $saved = 0;
         for ($i = 0; $i < $num; ++$i) {
             $file = array_combine(array_keys($files), array_map(function ($value) use($i) {
                 return $value[$i];
             }, array_values($files)));
             if (!is_uploaded_file($file['tmp_name'])) {
                 throw new InternalErrorException();
             }
             $ext = pathinfo($file['name'], PATHINFO_EXTENSION);
             if ($ext == 'md') {
                 $markdown = file_get_contents($file['tmp_name']);
                 $page_name = basename($file['name'], '.md');
                 $markdown = preg_replace_callback('/Title: (.*?)(\\r\\n|\\r|\\n)/', function ($matches) use(&$page_name) {
                     $page_name = $matches[1];
                     return '';
                 }, $markdown);
                 $page = new Page($page_name, 'name');
                 $page->update($markdown);
                 ++$saved;
             }
         }
         if ($saved == 1) {
             return $this->redirect(['p' => $page_name]);
         }
     }
 }
Esempio n. 2
0
 public function testExists()
 {
     $page = new Page('PageName', 'name');
     $id = $page->getId();
     $this->assertFalse((new Page('PageName', 'name'))->exists());
     $page->update('Test');
     $this->assertTrue((new Page('PageName', 'name'))->exists());
 }