/** * User handler for code block * @return Texy\HtmlElement */ function blockHandler(Texy\HandlerInvocation $invocation, $blocktype, $content, $lang, Texy\Modifier $modifier) { if ($blocktype !== 'block/code') { return $invocation->proceed(); } $lang = strtoupper($lang); if ($lang == 'JAVASCRIPT') { $lang = 'JS'; } $fshl = new fshlParser('HTML_UTF8', P_TAB_INDENT); if (!$fshl->isLanguage($lang)) { return $invocation->proceed(); } $texy = $invocation->getTexy(); $content = Texy\Helpers::outdent($content); $content = $fshl->highlightString($lang, $content); $content = $texy->protect($content, $texy::CONTENT_BLOCK); $elPre = new Texy\HtmlElement('pre'); if ($modifier) { $modifier->decorate($texy, $elPre); } $elPre->attrs['class'] = strtolower($lang); $elCode = $elPre->create('code', $content); return $elPre; }
/** * @return Texy\HtmlElement|string|FALSE */ function phraseHandler(Texy\HandlerInvocation $invocation, $phrase, $content, Texy\Modifier $modifier, Texy\Link $link = NULL) { // is there link? if (!$link) { return $invocation->proceed(); } if (Texy\Helpers::isRelative($link->URL)) { // modifiy link $link->URL = 'index?page=' . urlencode($link->URL); } elseif (substr($link->URL, 0, 5) === 'wiki:') { // modifiy link $link->URL = 'https://en.wikipedia.org/wiki/Special:Search?search=' . urlencode(substr($link->URL, 5)); } return $invocation->proceed(); }
/** * User handler for images * @return Texy\HtmlElement|string|FALSE */ function imageHandler(Texy\HandlerInvocation $invocation, Texy\Image $image, Texy\Link $link = NULL) { $texy = $invocation->getTexy(); if (substr($image->URL, -4) === '.swf') { $movie = Texy\Helpers::prependRoot($image->URL, $texy->imageModule->root); $dimensions = ($image->width ? 'width="' . $image->width . '" ' : '') . ($image->height ? 'width="' . $image->height . '" ' : ''); $movie = htmlSpecialChars($movie); $altContent = htmlSpecialChars($image->modifier->title); // @see https://phpfashion.com/how-to-correctly-insert-a-flash-into-xhtml $code = ' <!--[if !IE]> --> <object type="application/x-shockwave-flash" data="' . $movie . '" ' . $dimensions . '> <!-- <![endif]--> <!--[if IE]> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ' . $dimensions . ' codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"> <param name="movie" value="' . $movie . '" /> <!--><!--dgx--> <p>' . $altContent . '</p> </object> <!-- <![endif]--> '; return $texy->protect($code, $texy::CONTENT_BLOCK); } return $invocation->proceed(); }
/** * User handler for images * @return Texy\HtmlElement|string|FALSE */ function imageHandler(Texy\HandlerInvocation $invocation, Texy\Image $image, Texy\Link $link = NULL) { $parts = explode(':', $image->URL); if (count($parts) !== 2) { return $invocation->proceed(); } switch ($parts[0]) { case 'youtube': $video = htmlSpecialChars($parts[1]); $dimensions = 'width="' . ($image->width ? $image->width : 425) . '" height="' . ($image->height ? $image->height : 350) . '"'; $code = '<div><object ' . $dimensions . '>' . '<param name="movie" value="https://www.youtube.com/v/' . $video . '" /><param name="wmode" value="transparent" />' . '<embed src="https://www.youtube.com/v/' . $video . '" type="application/x-shockwave-flash" wmode="transparent" ' . $dimensions . ' /></object></div>'; $texy = $invocation->getTexy(); return $texy->protect($code, $texy::CONTENT_BLOCK); } return $invocation->proceed(); }
/** * User handler for code block * @return Texy\HtmlElement */ function blockHandler(Texy\HandlerInvocation $invocation, $blocktype, $content, $lang, Texy\Modifier $modifier) { if ($blocktype !== 'block/code') { return $invocation->proceed(); } $texy = $invocation->getTexy(); global $geshiPath; if ($lang == 'html') { $lang = 'html4strict'; } $content = Texy\Helpers::outdent($content); $geshi = new GeSHi($content, $lang, $geshiPath . 'geshi/'); // GeSHi could not find the language if ($geshi->error) { return $invocation->proceed(); } // do syntax-highlighting $geshi->set_encoding('UTF-8'); $geshi->set_header_type(GESHI_HEADER_PRE); $geshi->enable_classes(); $geshi->set_overall_style('color: #000066; border: 1px solid #d0d0d0; background-color: #f0f0f0;', TRUE); $geshi->set_line_style('font: normal normal 95% \'Courier New\', Courier, monospace; color: #003030;', 'font-weight: bold; color: #006060;', TRUE); $geshi->set_code_style('color: #000020;', 'color: #000020;'); $geshi->set_link_styles(GESHI_LINK, 'color: #000060;'); $geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;'); // save generated stylesheet $texy->styleSheet .= $geshi->get_stylesheet(); $content = $geshi->parse_code(); // check buggy GESHI, it sometimes produce not UTF-8 valid code :-(( $content = iconv('UTF-8', 'UTF-8//IGNORE', $content); // protect output is in HTML $content = $texy->protect($content, $texy::CONTENT_BLOCK); $el = new Texy\HtmlElement(); $el->setText($content); return $el; }
/** * User handler for images * @return Texy\HtmlElement|string|FALSE */ function imageHandler(Texy\HandlerInvocation $invocation, Texy\Image $image, Texy\Link $link = NULL) { if ($image->URL == 'user') { // accepts only [* user *] $image->URL = 'image.gif'; // image URL $image->overURL = 'image-over.gif'; // onmouseover image $image->modifier->title = 'Texy! logo'; if ($link) { // linked image $link->URL = 'big.gif'; } } return $invocation->proceed($image, $link); }
/** * @return Texy\HtmlElement|string|FALSE */ function figureHandler(Texy\HandlerInvocation $invocation, Texy\Image $image, Texy\Link $link = NULL, $content, Texy\Modifier $modifier) { // finish invocation by default way $el = $invocation->proceed(); // change div -> dl $el->setName('dl'); // change p -> dd $el[1]->setName('dd'); // wrap img into dt $img = $el[0]; unset($el[0]); $dt = new Texy\HtmlElement('dt'); $dt->add($img); $el->insert(0, $dt); return $el; }
/** * @return Texy\HtmlElement|string */ function block(Texy\HandlerInvocation $invocation, $blocktype, $content, $param, Texy\Modifier $modifier) { return $invocation->proceed(); }