WikiPage.class.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Define a page.
  4. * @author Valentin CARRUESCO
  5. * @category Plugin
  6. * @license copyright
  7. */
  8. class WikiPage extends Entity{
  9. public $id,$label,$content,$state,$path,$category,$slug;
  10. const PUBLISHED = 'published';
  11. const DRAFT = 'draft';
  12. protected $TABLE_NAME = 'wiki_page';
  13. public $links = array(
  14. 'category' => 'WikiCategory'
  15. );
  16. public $fields =
  17. array(
  18. 'id' => 'key',
  19. 'label' => 'string',
  20. 'state' => 'string',
  21. 'category' => 'int',
  22. 'slug' => 'string',
  23. 'path' => 'string'
  24. );
  25. public static function workspace(){
  26. return File::dir().'wiki'.SLASH.'pages';
  27. }
  28. public static function uploads(){
  29. return File::dir().'wiki'.SLASH.'uploads';
  30. }
  31. public static function path_from_label($label){
  32. return preg_replace('|[\?\\\/\*\:\|\<\>]|i', '-',$label);
  33. }
  34. public function author(){
  35. return User::byLogin($this->creator)->fullName();
  36. }
  37. public function created(){
  38. return relative_time($this->created);
  39. }
  40. public function updater(){
  41. return User::byLogin($this->updater)->fullName();
  42. }
  43. public function updated(){
  44. return relative_time($this->updated);
  45. }
  46. public function html(){
  47. require_once(__DIR__.SLASH.'lib'.SLASH.'Parsedown.php');
  48. $markdown = new Parsedown();
  49. return $markdown->text($this->content);
  50. }
  51. public function content(){
  52. $this->content = file_get_contents(self::workspace().SLASH.wiki_os_encode($this->path));
  53. }
  54. }
  55. ?>