]> git.bts.cx Git - cx.git/blob - cx/lib/markdown.php
Use the correct file request call
[cx.git] / cx / lib / markdown.php
1 <?php
2
3 cx_require('lib', 'images.php');
4 cx_require('lib', 'url.php');
5 cx_require('third_party', 'parsedown', 'Parsedown.php');
6
7 class ExtendedParsedown extends Parsedown {
8         public function __construct() {
9                 $this->InlineTypes['{'][] = 'BlogImage';
10                 $this->InlineTypes['{'][] = 'Youtube';
11                 $this->inlineMarkerList .= '{';
12         }
13
14         protected function inlineBlogImage($excerpt) {
15                 if (preg_match('/^{img:([^}]+)}/', $excerpt['text'], $matches)) {
16                         $image_id = $matches[1];
17                         $image = cx_images_find_image($image_id);
18
19                         if ($image == null) {
20                                 return;
21                         }
22
23                         return array(
24                                 'extent' => strlen($matches[0]) + 1, 
25                                 'element' => array(
26                                         'name' => 'img',
27                                         'attributes' => array(
28                                                 'src' => cx_url_site($image->get_permalink_path()),
29                                                 'alt' => $image->alt_text,
30                                         ),
31                                 ),
32                         );
33                 }
34         }
35
36         protected function inlineYoutube($excerpt) {
37                 if (preg_match('/^{yt:([^}]+)}/', $excerpt['text'], $matches)) {
38                         $video_id = $matches[1];
39
40                         if ($video_id == null) {
41                                 return;
42                         }
43
44                         return array(
45                                 'extent' => strlen($matches[0]) + 1, 
46                                 'element' => array(
47                                         'name' => 'iframe',
48                                         'text' => '',
49                                         'attributes' => array(
50                                                 'class' => "video",
51                                                 'type' => "text/html",
52                                                 //'width' => "640",
53                                                 //'height' => "360",
54                                                 'src' => "https://www.youtube.com/embed/" . $video_id,
55                                                 'frameborder' => "0",
56                                                 'loading' => "lazy",
57                                                 'referrerpolicy' => "no-referrer",
58                                                 'sandbox' => "allow-same-origin allow-scripts",
59                                         ),
60                                 ),
61                         );
62                 }
63         }
64 }
65
66 function cx_markdown_generate_html($markdown) {
67         static $Parsedown = new ExtendedParsedown();
68         return $Parsedown->text($markdown);
69 }