diff --git a/conf/default.php b/conf/default.php new file mode 100644 index 0000000..bc6a6e6 --- /dev/null +++ b/conf/default.php @@ -0,0 +1,3 @@ +doc .= "{{" . $src . "}}"; + global $ID; + + if (strpos($src, '#') !== false) { + [$src, $hash] = sexplode('#', $src, 2); + } + $src = (new MediaResolver($ID))->resolveId($src, $this->date_at, true); + $exists = media_exists($src); + + $noLink = false; + $render = $linking != 'linkonly'; + $render = $render && $exists; + $render = $render && class_exists("Imagick"); + $render = $render && $this->getConf("render_sixel"); + + [$ext, $mime] = mimetype($src, false); + if (str_starts_with($mime, 'image') && $render) + { + $url = mediaFN($src, $this->_getLastMediaRevisionAt($src)); + $image = new Imagick($url); + // todo: resize + if($width || $height) $image->thumbnailImage($width, $height); + $image->setImageFormat('sixel'); + $ret = $image->getImageBlob(); + } + else + { + $url = ml($src, + [ + 'id' => $ID, + 'cache' => $cache, + 'rev' => $this->_getLastMediaRevisionAt($src) + ], + true + ); + if(is_array($title)) $title = $title['title']; + if($title) $title = "\xF0\x9F\x96\xBC\xEF\xB8\x8F ".$title; + else $title = "\xF0\x9F\x96\xBC\xEF\xB8\x8F"; + $ret = self::CSI.($exists ? "35" : "31") . ";4m" .$this->_formatLink($src, $this->_getFullLink($url), $title) . self::CSI."24;39m"; + } + if($return) return $ret; + else $this->doc .= $ret; } /** @inheritdoc */ public function externalmedia($src, $title = null, $align = null, $width = null, $height = null, $cache = null, $linking = null, $return = false) { - $this->doc .= "{{" . $src . "}}"; + if($title) $title = "\xF0\x9F\x96\xBC\xEF\xB8\x8F ".$title; + else $title = "\xF0\x9F\x96\xBC\xEF\xB8\x8F"; + + $ret = self::CSI."95;4m" . $this->_formatLink($src, $src, $title) . self::CSI."24;39m"; + + if($return) return $ret; + else $this->doc .= $ret; + } + + public function _media($src, $title = null, $align = null, $width = null, + $height = null, $cache = null, $linking = null, $return = false) + { + } /** @inheritdoc */ public function rss($url, $params) { - $this->doc .= "{{rss>" . $url . "}}" . DOKU_LF; + $this->doc .= "{{rss>" . $url . "}}" . DOKU_LF; } /** @inheritdoc */ @@ -647,4 +701,11 @@ class renderer_plugin_ansi extends Doku_Renderer { return self::OSC."8;;" . $url . self::ST . $name . ($id == $name ? "" : " [" . $id . "]") . self::OSC."8;;" . self::ST; } + + protected function _getLastMediaRevisionAt($media_id) + { + if (!$this->date_at || media_isexternal($media_id)) return ''; + $changelog = new MediaChangeLog($media_id); + return $changelog->getLastRevisionAt($this->date_at); + } }