Пример #1
0
 public function about()
 {
     $pagePath = config('my.about_path');
     $markdown = file_get_contents($pagePath);
     $parser = new \cebe\markdown\MarkdownExtra();
     $pageContent = $parser->parse($markdown);
     return view('pages.aboutme')->withPage($pageContent);
 }
Пример #2
0
 /**
  * Parse markdown using the extra format
  * 
  * @param  string $markdown The Markdown you want to parse
  * @return string           The resulting HTML
  */
 public function parse_extra($markdown)
 {
     $instance = $this->instances['extra'];
     if (empty($instance)) {
         $instance = new \cebe\markdown\MarkdownExtra();
         $instance->html5 =& $this->use_html5;
         $instance->keepListStartNumber =& $this->keep_list_number;
     }
     return $instance->parse($markdown);
 }
Пример #3
0
 private function processMarkdown($sContent)
 {
     $this->setMarkdownVars();
     // Simple variable replacement
     foreach ($this->aVars as $sName => $sVar) {
         if (is_numeric($sVar) || is_string($sVar)) {
             $sContent = str_replace('%' . $sName . '%', $sVar, $sContent);
         }
     }
     // Markdown
     $oParser = new \cebe\markdown\MarkdownExtra();
     $sContent = $oParser->parse($sContent);
     return trim($sContent);
 }
Пример #4
0
 public function getMarkdown($link_id)
 {
     if ($link_id <= 0) {
         return "false";
     }
     $md_id_to_old = true;
     $max_timestamp_diff = 60;
     // Après combien de temps le markdown est obsolète (en secondes)
     // Recuperer le dernier Markdown de la BDD
     $query = "\n\t\t\t\t\tSELECT markdown, creation_timestamp \n\t\t\t\t\tFROM markdown \n\t\t\t\t\tWHERE \n\t\t\t\t\t\tlink_id=" . $link_id . "\n\t\t\t\t\t\tAND creation_timestamp=(SELECT MAX(creation_timestamp) FROM markdown WHERE link_id=" . $link_id . ")\n\t\t";
     $results = pg_query($query);
     if ($line = pg_fetch_array($results)) {
         $markdown = $line[0];
         // Verifier si le dernier MD est trop vieux
         $last_md_time = strtotime($line[1]);
         $diff = time() - $last_md_time;
         if ($diff < $max_timestamp_diff) {
             $md_id_to_old = true;
         }
     }
     // Si le markdown est obsolète
     // Recuperer l'URL demandé
     $query = "SELECT link FROM link WHERE id=" . $link_id;
     $results = pg_query($query);
     if ($line = pg_fetch_array($results)) {
         $url = $line[0];
     } else {
         throw new Exception("Ce lien n'existe pas");
     }
     if ($md_id_to_old) {
         // Recuperer le markdown à partir du lien
         try {
             $markdown = Tools::getUrlMarkdown($url);
         } catch (Exception $e) {
             return "false";
         }
         $last_md_time = time();
     }
     $parser = new \cebe\markdown\MarkdownExtra();
     $markdown = $parser->parse($markdown);
     $markdown = htmlspecialchars_decode($markdown);
     // Insérer le markdown dans la BDD
     $query = "INSERT INTO markdown(link_id, markdown) VALUES(" . $link_id . ", '" . $markdown . "')";
     pg_query($query);
     // Creer le tableau
     $arr = array();
     $arr[] = array('link_id' => $link_id, 'timestamp' => $last_md_time, 'markdown' => $markdown);
     return json_encode($arr);
 }
Пример #5
0
 private static function createPost($post)
 {
     $post->tags = explode(' ', $post->tags);
     if ($post->posttime) {
         $post->posttime = date('M d Y', strtotime($post->posttime));
     }
     $postPath = config('my.posts_path') . '/' . $post->slug . '.md';
     $markdown = file_get_contents($postPath);
     $parser = new \cebe\markdown\MarkdownExtra();
     $post->body = $parser->parse($markdown);
     return $post;
 }
Пример #6
0
 /**
  * TestSuccess
  *
  * @return void
  */
 public function testSuccess()
 {
     $className = "\\NachoNerd\\MarkdownBlog\\Application";
     $className1 = "\\NachoNerd\\MarkdownBlog\\Factories\\ControllerProvider";
     $about = new \NachoNerd\MarkdownBlog\ControllerProviders\About();
     $parser = new \cebe\markdown\MarkdownExtra();
     $html = $parser->parse(file_get_contents(realpath(__DIR__ . "/../../../markdowns/misc/about.md")));
     $this->app = $this->getMock($className, array('getControllerProviderFactory'));
     $factory = $this->getMockBuilder($className1)->setMethods(array('create'))->getMock();
     $factory->expects($this->any())->method('create')->willReturn($about);
     $this->app->expects($this->any())->method('getControllerProviderFactory')->willReturn($factory);
     $reflectedObject = new \ReflectionClass($className);
     $path = realpath(__DIR__ . "/../../resources/about/config/") . "/";
     $rp = $reflectedObject->getProperty('configPath');
     $rp->setAccessible(true);
     $rp->setValue($this->app, $path);
     $path = realpath(__DIR__ . "/../../resources/about/views/") . "/";
     $rp1 = $reflectedObject->getProperty('viewsPath');
     $rp1->setAccessible(true);
     $rp1->setValue($this->app, $path);
     $client = $this->createClient();
     $client->request('GET', '/about/');
     $response = $client->getResponse();
     $this->assertEquals(str_replace("\n", "", $html), str_replace("\n", "", $response->getContent()));
 }
Пример #7
0
 /**
  * Get text markdown markup file
  * file is selected according to the localization
  * 
  * @param array $params Set params for [filename, content, type]
  * @return string
  */
 public function getMarkdown($params)
 {
     $arBox = new Default_Plugin_ArrayBox();
     $strBox = new Default_Plugin_String();
     $filename = isset($params['filename']) ? $params['filename'] : '';
     $strFile = isset($params['content']) ? $params['content'] : '';
     $type = isset($params['type']) ? $params['type'] : 'github';
     //Type of Markdown: traditional, github, extra
     $title = '';
     $locale = Default_Plugin_SysBox::getTranslateLocale();
     $locale = $locale == 'uk' ? 'ru' : $locale;
     $title = "";
     $filename = trim($filename);
     $filename = str_replace('\\', '/', $filename);
     //-------------------------------------------
     if ($filename) {
         if (is_file($filename)) {
             $lastFilename = $arBox->set($filename, "/")->getLast();
             // Set title
             $title = $lastFilename;
             // Check word in uppercase
             $upperFilename = $strBox->set($lastFilename)->toUpper()->get();
             $isUpper = $arBox->set($lastFilename, ".")->get(0) == $arBox->set($upperFilename, ".")->get(0);
             if ($isUpper) {
                 $locale = strtoupper($locale);
             }
             // Get the name of the file to a different locale
             $lastFilename = $arBox->set($lastFilename, ".")->get(0) . "-{$locale}.md";
             $localeFilename = $arBox->set($filename, "/")->pop()->join('/') . "/{$lastFilename}";
             // Get file content
             if (is_file($localeFilename)) {
                 // Set title
                 $title = $lastFilename;
                 $strFile = file_get_contents($localeFilename);
             } else {
                 $strFile = file_get_contents($filename);
             }
         } else {
             // Get file name
             $filename = APPLICATION_TEMPLATES . "/{$this->_params['controller']}/{$filename}";
             if (!is_file($filename)) {
                 throw new Exception("File '{$filename}' does not exist.");
             }
             $lastFilename = $arBox->set($filename, "/")->getLast();
             // Set title
             $title = $lastFilename;
             // Check word in uppercase
             $upperFilename = $strBox->set($lastFilename)->toUpper()->get();
             $isUpper = $arBox->set($lastFilename, ".")->get(0) == $arBox->set($upperFilename, ".")->get(0);
             if ($isUpper) {
                 $locale = strtoupper($locale);
             }
             // Get the name of the file to a different locale
             $lastFilename = $arBox->set($lastFilename, ".")->get(0) . "-{$locale}.md";
             $localeFilename = $arBox->set($filename, "/")->pop()->join('/') . "/{$lastFilename}";
             // Get file content
             if (is_file($localeFilename)) {
                 // Set title
                 $title = $lastFilename;
                 $strFile = file_get_contents($localeFilename);
             } else {
                 $strFile = file_get_contents($filename);
             }
         }
     }
     switch ($type) {
         case 'traditional':
             $markdown = new \cebe\markdown\Markdown();
             break;
         case 'github':
             $markdown = new \cebe\markdown\GithubMarkdown();
             break;
         case 'extra':
             $markdown = new \cebe\markdown\MarkdownExtra();
             break;
         default:
             break;
     }
     // Get markdown parser text
     $text = $markdown->parse($strFile);
     // Get content
     $content = array('title' => $title, 'text' => "<div class=\"markdown-body\">{$text}</div>");
     return $content;
 }