03.12.2015 Views

laravel4cookbook

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

File-Based CMS 347<br />

15 )<br />

16 {<br />

17 $this->engine = $engine;<br />

18 $this->filesystem = $filesystem;<br />

19 }<br />

20<br />

21 protected function parseFile($file)<br />

22 {<br />

23 return $this->parseContent(<br />

24 $this->filesystem->read($file["path"]),<br />

25 $file<br />

26 );<br />

27 }<br />

28<br />

29 protected function parseContent($content, $file = null)<br />

30 {<br />

31 $extracted = $this->engine->extractMeta($content);<br />

32 $parsed = $this->engine->parseMeta($extracted["meta"]);<br />

33<br />

34 return compact("file", "content", "extracted", "parsed");<br />

35 }<br />

36<br />

37 protected function stripExtension($name)<br />

38 {<br />

39 return str_ireplace(".blade.php", "", $name);<br />

40 }<br />

41<br />

42 protected function cleanArray($array)<br />

43 {<br />

44 return array_filter($array, function($item) {<br />

45 return !empty($item);<br />

46 });<br />

47 }<br />

48<br />

49 public function indexAction($route = "/")<br />

50 {<br />

51 $pages = $this->filesystem->listContents("pages");<br />

52<br />

53 foreach ($pages as $page)<br />

54 {<br />

55 if ($page["type"] == "file")<br />

56 {

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!