| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392 | 
							- <?php
 
- /**
 
-  * Define a page.
 
-  * @author Valentin CARRUESCO
 
-  * @category Plugin
 
-  * @license copyright
 
-  */
 
- class WikiPage extends Entity{
 
-     public $id,$label,$content,$state,$path,$category,$slug,$sort = 0;
 
-     const PUBLISHED = 'published';
 
-     const DRAFT = 'draft';
 
-     protected $TABLE_NAME = 'wiki_page';
 
-     public $links = array(
 
-         'category' => 'WikiCategory'
 
-     );
 
-     public $fields =
 
-     array(
 
-         'id' => 'key',
 
-         'label' => 'string',
 
-         'state' => 'string',
 
-         'category' => 'int',
 
-         'slug' => 'string',
 
-         'sort' => 'int',
 
-         'path' => 'string'
 
-     );
 
-     public static function defaultContent(){
 
-         $default = 'Mon contenu ici...';
 
-         $defaultFile = File::dir().'wiki'.SLASH.'default.md';
 
-         if(file_exists($defaultFile)) $default = file_get_contents($defaultFile);
 
-         return $default;
 
-     }
 
-     public static function workspace(){
 
-         return File::dir().'wiki'.SLASH.'pages';
 
-     }
 
-     public static function uploads(){
 
-         return File::dir().'wiki'.SLASH.'uploads';
 
-     }
 
-     public static function path_from_label($label){
 
-         return preg_replace('|[\?\\\/\*\:\|\<\>]|i', '-',$label);
 
-     }
 
-     public function author(){
 
-         return User::byLogin($this->creator, false)->fullName();
 
-     }
 
-     public function created(){
 
-         return relative_time($this->created);
 
-     }
 
-     public function updater(){
 
-         return User::byLogin($this->updater, false)->fullName();
 
-     }
 
-     public function updated(){
 
-         return relative_time($this->updated);
 
-     }
 
-     public function html(){
 
-         
 
-         $markdown = new WikiPageParsedown();
 
-         $markdown->setBreaksEnabled(true);
 
-         return $markdown->text($this->content);
 
-     }
 
-     public function content(){
 
-         $this->content = file_get_contents(self::workspace().SLASH.wiki_os_encode($this->path));
 
-     }
 
- }
 
- require_once(__DIR__.SLASH.'lib'.SLASH.'Parsedown.php');
 
- //Etend la classe parsedown pour y ajouter des features (ex:le souligné (__texte souligné__))
 
- class WikiPageParsedown extends Parsedown{
 
-     protected function paragraph($Line)
 
-     {
 
-         if (substr($Line['text'], -1) === '#')
 
-         {
 
-             $closed = true;
 
-             $Line['text'] = substr($Line['text'], 0, -1);
 
-         }
 
-         $Block = parent::paragraph($Line);
 
-         if (isset($closed))
 
-         {
 
-             $Block['closed'] = true;
 
-         }
 
-         return $Block;
 
-     }
 
-     protected function paragraphContinue($Line, array $Block)
 
-     {
 
-         if (isset($Block['closed']))
 
-         {
 
-             return;
 
-         }
 
-         if (isset($Block['interrupted']))
 
-         {
 
-             $Block['element']['handler']['argument'] .= '  '.str_repeat("\n  ", $Block['interrupted']);
 
-             unset($Block['interrupted']);
 
-         }
 
-         if (substr($Line['text'], -1) === '#')
 
-         {
 
-             $Block['closed'] = true;
 
-             $Line['text'] = substr($Line['text'], 0, -1);
 
-         }
 
-         $Block['element']['handler']['argument'] .= "\n".$Line['text'];
 
-         return $Block;
 
-     }
 
-    
 
-     protected function blockCode($Line, $Block = null)
 
-     {
 
-         if (isset($Block) and $Block['type'] === 'Paragraph' and ! isset($Block['interrupted']))
 
-         {
 
-             return;
 
-         }
 
-         if ($Line['indent'] >= 4)
 
-         {
 
-             $text = substr($Line['body'], 4);
 
-             $Block = array(
 
-                 'element' => array(
 
-                     'name' => 'pre',
 
-                     'element' => array(
 
-                         'name' => 'code',
 
-                         'attributes' => array('class' => "block-code"), 
 
-                         'text' => $text,
 
-                     ),
 
-                 ),
 
-             );
 
-             return $Block;
 
-         }
 
-     }
 
-     protected function blockQuote($Line)
 
-     {
 
-         if (preg_match('/^>[ ]?+(.*+)/', $Line['text'], $matches))
 
-         {
 
-             $Block = array(
 
-                 'element' => array(
 
-                     'name' => 'blockquote',
 
-                     'attributes' => array('class' => "blockquote"), 
 
-                     'handler' => array(
 
-                         'function' => 'linesElements',
 
-                         'argument' => (array) $matches[1],
 
-                         'destination' => 'elements',
 
-                     )
 
-                 ),
 
-             );
 
-             return $Block;
 
-         }
 
-     }
 
-     protected function blockTable($Line, array $Block = null)
 
-     {
 
-         if ( ! isset($Block) or $Block['type'] !== 'Paragraph' or isset($Block['interrupted']))
 
-         {
 
-             return;
 
-         }
 
-         if (
 
-             strpos($Block['element']['handler']['argument'], '|') === false
 
-             and strpos($Line['text'], '|') === false
 
-             and strpos($Line['text'], ':') === false
 
-             or strpos($Block['element']['handler']['argument'], "\n") !== false
 
-         ) {
 
-             return;
 
-         }
 
-         if (chop($Line['text'], ' -:|') !== '')
 
-         {
 
-             return;
 
-         }
 
-         $alignments = array();
 
-         $divider = $Line['text'];
 
-         $divider = trim($divider);
 
-         $divider = trim($divider, '|');
 
-         $dividerCells = explode('|', $divider);
 
-         foreach ($dividerCells as $dividerCell)
 
-         {
 
-             $dividerCell = trim($dividerCell);
 
-             if ($dividerCell === '')
 
-             {
 
-                 return;
 
-             }
 
-             $alignment = null;
 
-             if ($dividerCell[0] === ':')
 
-             {
 
-                 $alignment = 'left';
 
-             }
 
-             if (substr($dividerCell, - 1) === ':')
 
-             {
 
-                 $alignment = $alignment === 'left' ? 'center' : 'right';
 
-             }
 
-             $alignments []= $alignment;
 
-         }
 
-         # ~
 
-         $HeaderElements = array();
 
-         $header = $Block['element']['handler']['argument'];
 
-         $header = trim($header);
 
-         $header = trim($header, '|');
 
-         $headerCells = explode('|', $header);
 
-         if (count($headerCells) !== count($alignments))
 
-         {
 
-             return;
 
-         }
 
-         foreach ($headerCells as $index => $headerCell)
 
-         {
 
-             $headerCell = trim($headerCell);
 
-             $HeaderElement = array(
 
-                 'name' => 'th',
 
-                 'handler' => array(
 
-                     'function' => 'lineElements',
 
-                     'argument' => $headerCell,
 
-                     'destination' => 'elements',
 
-                 )
 
-             );
 
-             if (isset($alignments[$index]))
 
-             {
 
-                 $alignment = $alignments[$index];
 
-                 $HeaderElement['attributes'] = array(
 
-                     'style' => "text-align: $alignment;"
 
-                 );
 
-             }
 
-             $HeaderElements []= $HeaderElement;
 
-         }
 
-         # ~
 
-         $Block = array(
 
-             'alignments' => $alignments,
 
-             'identified' => true,
 
-             'element' => array(
 
-                 'name' => 'table',
 
-                 'attributes' => array('class' => "table"), /* + sys1 */
 
-                 'elements' => array(),
 
-             ),
 
-         );
 
-         $Block['element']['elements'] []= array(
 
-             'name' => 'thead',
 
-         );
 
-         $Block['element']['elements'] []= array(
 
-             'name' => 'tbody',
 
-             'elements' => array(),
 
-         );
 
-         $Block['element']['elements'][0]['elements'] []= array(
 
-             'name' => 'tr',
 
-             'elements' => $HeaderElements,
 
-         );
 
-         return $Block;
 
-     }
 
-     protected function blockFencedCode($Line)
 
-     {
 
-         $marker = $Line['text'][0];
 
-         $openerLength = strspn($Line['text'], $marker);
 
-         if ($openerLength < 3)
 
-         {
 
-             return;
 
-         }
 
-         $infostring = trim(substr($Line['text'], $openerLength), "\t ");
 
-         if (strpos($infostring, '`') !== false)
 
-         {
 
-             return;
 
-         }
 
-         $Element = array(
 
-             'name' => 'code',
 
-             'attributes' => array('class' => "block-code"),
 
-             'text' => '',
 
-         );
 
-         if ($infostring !== '')
 
-         {
 
-             $Element['attributes'] = array('class' => "language-$infostring");
 
-         }
 
-         $Block = array(
 
-             'char' => $marker,
 
-             'openerLength' => $openerLength,
 
-             'element' => array(
 
-                 'name' => 'pre',
 
-                 'element' => $Element,
 
-             ),
 
-         );
 
-         return $Block;
 
-     }
 
-     protected function inlineCode($Excerpt)
 
-     {
 
-         $marker = $Excerpt['text'][0];
 
-         if (preg_match('/^(['.$marker.']++)[ ]*+(.+?)[ ]*+(?<!['.$marker.'])\1(?!'.$marker.')/s', $Excerpt['text'], $matches))
 
-         {
 
-             $text = $matches[2];
 
-             $text = preg_replace('/[ ]*+\n/', ' ', $text);
 
-             return array(
 
-                 'extent' => strlen($matches[0]),
 
-                 'element' => array(
 
-                     'name' => 'code',
 
-                     'attributes' => array('class' => "inline-code"), 
 
-                     'text' => $text,
 
-                 ),
 
-             );
 
-         }
 
-     }
 
-     protected function inlineEmphasis($Excerpt)
 
-     {
 
-         if ( ! isset($Excerpt['text'][1]))
 
-         {
 
-             return;
 
-         }
 
-         $marker = $Excerpt['text'][0];
 
-         if(preg_match('/^__([^__]*)__/us', $Excerpt['text'], $matches)){
 
-             $emphasis = 'u';
 
-         }else if ($Excerpt['text'][1] === $marker and preg_match($this->StrongRegex[$marker], $Excerpt['text'], $matches))
 
-         {
 
-             $emphasis = 'strong';
 
-         }
 
-         elseif (preg_match($this->EmRegex[$marker], $Excerpt['text'], $matches))
 
-         {
 
-             $emphasis = 'em';
 
-         }
 
-         else
 
-         {
 
-             return;
 
-         }
 
-         return array(
 
-             'extent' => strlen($matches[0]),
 
-             'element' => array(
 
-                 'name' => $emphasis,
 
-                 'attributes' => array(
 
-                         'class' => 'emphasis-underscore' ,
 
-                 ),
 
-                 'handler' => array(
 
-                     'function' => 'lineElements',
 
-                     'argument' => $matches[1],
 
-                     'destination' => 'elements',
 
-                 )
 
-             ),
 
-         );
 
-     }
 
- }
 
- ?>
 
 
  |