Lexer->addEntryPattern('(?=.*?)', $mode, 'plugin_plainembed');
}
public function postConnect() {
$this->Lexer->addExitPattern('', 'plugin_plainembed');
}
public function handle($match, $state, $pos, Doku_Handler $handler) {
switch ($state) {
case DOKU_LEXER_ENTER:
return array($state, '');
case DOKU_LEXER_UNMATCHED:
$clean_base64 = preg_replace('/\s+/', '', $match);
return array($state, $clean_base64);
case DOKU_LEXER_EXIT:
return array($state, '');
}
return false;
}
public function render($format, Doku_Renderer $renderer, $data) {
if($format != 'xhtml') return false;
list($state, $base64_string) = $data;
if ($state == DOKU_LEXER_UNMATCHED) {
if (empty($base64_string)) return true;
$binary_data = base64_decode($base64_string, true);
if ($binary_data === false) {
$renderer->doc .= ' [Invalid Base64 Data] ';
return true;
}
$mime_type = 'image/png';
if (class_exists('finfo')) {
$finfo = new finfo(FILEINFO_MIME_TYPE);
$mime_type = $finfo->buffer($binary_data);
}
if (strpos($mime_type, 'image/') === 0) {
// Dynamically fetch config options updated from the Admin Panel
$max_width = $this->getConf('max_width');
$border_style = $this->getConf('add_border') ? 'border: 1px solid #ccc; padding: 5px;' : '';
$renderer->doc .= '
';
$renderer->doc .= '
 . ';base64,' . hsc($base64_string) . ')
';
$renderer->doc .= '
';
} else {
$renderer->doc .= ' [Unsupported MIME Type: ' . hsc($mime_type) . '] ';
}
}
return true;
}
}