Example #1
0
 public function save($model)
 {
     $id = $model[$this->idField];
     $filename = \Staq::App()->getDataPath() . $this->folder . '/' . $id;
     $data = $model->extractSeeds();
     if (isset($data['content'])) {
         // TODO: if the model exists verify that it is a markdown file
         $converter = new \Markdownify\ConverterExtra();
         file_put_contents($filename . '.md', $converter->parseString($model->content));
         unset($data['content']);
     }
     unset($data[$this->idField]);
     file_put_contents($filename . '.json', json_encode($data));
     return $id;
 }
 /**
  * Convert the main post content to Markdown.
  */
 function convert_content($post)
 {
     $content = apply_filters('the_content', $post->post_content);
     $converter = new Markdownify\ConverterExtra();
     $markdown = $converter->parseString($content);
     if (false !== strpos($markdown, '[]: ')) {
         // faulty links; return plain HTML
         return $content;
     }
     return $markdown;
 }
Example #3
0
// filter post
le_add_workflow('filter_post', function ($post, $categoriesConfig) {
    $text = (isset($post['description']) ? $post['description'] : '') . (isset($post['mt_text_more']) ? "\n\n<!--more-->\n\n" . $post['mt_text_more'] : '');
    $text = preg_replace("/<\\/p>\\s*<\\/p>/is", "</p>", $text);
    $text = preg_replace_callback("/<pre[^>]*><code[^>]*>(.+?)<\\/code><\\/pre>/is", function ($matches) {
        return '<pre>' . $matches[1] . '</pre>';
    }, $text);
    $text = preg_replace_callback("/<code[^>]*>(.+?)<\\/code>/is", function ($matches) {
        if (false !== strpos($matches[1], "\n")) {
            return '<pre>' . $matches[1] . '</pre>';
        }
        return '<code>' . $matches[1] . '</code>';
    }, $text);
    $text = preg_replace("/<a[^>]+(href=\"[^\"]+\")[^>]*>/is", "<a \\1>", $text);
    $text = preg_replace("/<img[^>]+(src=\"[^\"]+\")[^>]*\\/?>/is", "<img \\1>", $text);
    $parser = new \Markdownify\ConverterExtra();
    $content = "\n" . $post['title'] . "\n" . str_repeat('=', strlen($post['title'])) . "\n\n" . $parser->parseString($text);
    $date = $post['dateCreated'];
    if (!empty($post['mt_keywords'])) {
        $content = "@tag:{$post['mt_keywords']}\n" . $content;
    }
    if (!empty($post['categories'])) {
        $categories = [];
        foreach ($post['categories'] as $category) {
            $found = array_search($category, $categoriesConfig);
            if (false !== $found) {
                $categories[] = $found;
            }
        }
        if (!empty($categories)) {
            $content = "@category:" . implode(',', $categories) . "\n" . $content;