function wiki_texy_phraseHandler($invocation, $phrase, $content, $modifier, $link) { if (!$link) { return $invocation->proceed(); } if (Texy::isRelative($link->URL)) { $link->URL = '?page=' . urlencode($link->URL); } elseif (substr($link->URL, 0, 5) === 'wiki:') { $link->URL = 'http://en.wikipedia.org/wiki/Special:Search?search=' . urlencode(substr($link->URL, 5)); } elseif (substr($link->URL, 0, 4) === 'url:') { $link->URL = substr($link->URL, 4); } return $invocation->proceed(); }
/** * @param TexyHandlerInvocation handler invocation * @param string * @param string * @param TexyModifier * @param TexyLink * @return TexyHtml|string|FALSE */ function phraseHandler($invocation, $phrase, $content, $modifier, $link) { // is there link? if (!$link) { return $invocation->proceed(); } if (Texy::isRelative($link->URL)) { // modifiy link $link->URL = 'index?page=' . urlencode($link->URL); } elseif (substr($link->URL, 0, 5) === 'wiki:') { // modifiy link $link->URL = 'http://en.wikipedia.org/wiki/Special:Search?search=' . urlencode(substr($link->URL, 5)); } return $invocation->proceed(); }
public function solve($invocation, TexyImage $image, $link) { if ($image->URL == NULL) { return FALSE; } $tx = $this->texy; $mod = $image->modifier; $alt = $mod->title; $mod->title = NULL; $hAlign = $mod->hAlign; $mod->hAlign = NULL; $el = TexyHtml::el('img'); $el->attrs['src'] = NULL; $mod->decorate($tx, $el); $el->attrs['src'] = Texy::prependRoot($image->URL, $this->root); if (!isset($el->attrs['alt'])) { if ($alt !== NULL) { $el->attrs['alt'] = $tx->typographyModule->postLine($alt); } else { $el->attrs['alt'] = $this->defaultAlt; } } if ($hAlign) { $var = $hAlign . 'Class'; if (!empty($this->{$var})) { $el->attrs['class'][] = $this->{$var}; } elseif (empty($tx->alignClasses[$hAlign])) { $el->attrs['style']['float'] = $hAlign; } else { $el->attrs['class'][] = $tx->alignClasses[$hAlign]; } } if (!is_int($image->width) || !is_int($image->height) || $image->asMax) { if ($this->fileRoot === NULL && isset($_SERVER['SCRIPT_FILENAME'])) { $this->fileRoot = dirname($_SERVER['SCRIPT_FILENAME']) . '/' . $this->root; } if (Texy::isRelative($image->URL) && strpos($image->URL, '..') === FALSE) { $file = rtrim($this->fileRoot, '/\\') . '/' . $image->URL; if (@is_file($file)) { $size = getImageSize($file); if (is_array($size)) { if ($image->asMax) { $ratio = 1; if (is_int($image->width)) { $ratio = min($ratio, $image->width / $size[0]); } if (is_int($image->height)) { $ratio = min($ratio, $image->height / $size[1]); } $image->width = round($ratio * $size[0]); $image->height = round($ratio * $size[1]); } elseif (is_int($image->width)) { $ratio = round($size[1] / $size[0] * $image->width); $image->height = round($size[1] / $size[0] * $image->width); } elseif (is_int($image->height)) { $image->width = round($size[0] / $size[1] * $image->height); } else { $image->width = $size[0]; $image->height = $size[1]; } } } } } $el->attrs['width'] = $image->width; $el->attrs['height'] = $image->height; if ($image->overURL !== NULL) { $overSrc = Texy::prependRoot($image->overURL, $this->root); $el->attrs['onmouseover'] = 'this.src=\'' . addSlashes($overSrc) . '\''; $el->attrs['onmouseout'] = 'this.src=\'' . addSlashes($el->attrs['src']) . '\''; $el->attrs['onload'] = str_replace('%i', addSlashes($overSrc), $this->onLoad); $tx->summary['preload'][] = $overSrc; } $tx->summary['images'][] = $el->attrs['src']; if ($link) { return $tx->linkModule->solve(NULL, $link, $el); } return $el; }
/** * Finish invocation. * * @param TexyHandlerInvocation handler invocation * @param TexyImage * @param TexyLink * @return TexyHtml|FALSE */ public function solve($invocation, TexyImage $image, $link) { if ($image->URL == NULL) return FALSE; $tx = $this->texy; $mod = $image->modifier; $alt = $mod->title; $mod->title = NULL; $hAlign = $mod->hAlign; $mod->hAlign = NULL; $el = TexyHtml::el('img'); $el->attrs['src'] = NULL; // trick - move to front $mod->decorate($tx, $el); $el->attrs['src'] = Texy::prependRoot($image->URL, $this->root); if (!isset($el->attrs['alt'])) { if ($alt !== NULL) $el->attrs['alt'] = $tx->typographyModule->postLine($alt); else $el->attrs['alt'] = $this->defaultAlt; } if ($hAlign) { $var = $hAlign . 'Class'; // leftClass, rightClass if (!empty($this->$var)) { $el->attrs['class'][] = $this->$var; } elseif (empty($tx->alignClasses[$hAlign])) { $el->attrs['style']['float'] = $hAlign; } else { $el->attrs['class'][] = $tx->alignClasses[$hAlign]; } } if (!is_int($image->width) || !is_int($image->height) || $image->asMax) { // autodetect fileRoot if ($this->fileRoot === NULL && isset($_SERVER['SCRIPT_FILENAME'])) { $this->fileRoot = dirname($_SERVER['SCRIPT_FILENAME']) . '/' . $this->root; } // detect dimensions // absolute URL & security check for double dot if (Texy::isRelative($image->URL) && strpos($image->URL, '..') === FALSE) { $file = rtrim($this->fileRoot, '/\\') . '/' . $image->URL; if (@is_file($file)) { // intentionally @ $size = @getImageSize($file); // intentionally @ if (is_array($size)) { if ($image->asMax) { $ratio = 1; if (is_int($image->width)) $ratio = min($ratio, $image->width / $size[0]); if (is_int($image->height)) $ratio = min($ratio, $image->height / $size[1]); $image->width = round($ratio * $size[0]); $image->height = round($ratio * $size[1]); } elseif (is_int($image->width)) { $ratio = round($size[1] / $size[0] * $image->width); $image->height = round($size[1] / $size[0] * $image->width); } elseif (is_int($image->height)) { $image->width = round($size[0] / $size[1] * $image->height); } else { $image->width = $size[0]; $image->height = $size[1]; } } } } } $el->attrs['width'] = $image->width; $el->attrs['height'] = $image->height; $tx->summary['images'][] = $el->attrs['src']; if ($link) return $tx->linkModule->solve(NULL, $link, $el); return $el; }
/** * Finish invocation. * * @param TexyHandlerInvocation handler invocation * @param TexyImage * @param TexyLink * * @return TexyHtml|FALSE */ public function solve($invocation, TexyImage $image, $link) { if ($image->URL == null) { return false; } $tx = $this->texy; $mod = $image->modifier; $alt = $mod->title; $mod->title = null; $hAlign = $mod->hAlign; $mod->hAlign = null; $el = TexyHtml::el('img'); $el->attrs['src'] = null; // trick - move to front $mod->decorate($tx, $el); $el->attrs['src'] = Texy::prependRoot($image->URL, $this->root); if (!isset($el->attrs['alt'])) { if ($alt !== null) { $el->attrs['alt'] = $tx->typographyModule->postLine($alt); } else { $el->attrs['alt'] = $this->defaultAlt; } } if ($hAlign) { $var = $hAlign . 'Class'; // leftClass, rightClass if (!empty($this->{$var})) { $el->attrs['class'][] = $this->{$var}; } elseif (empty($tx->alignClasses[$hAlign])) { $el->attrs['style']['float'] = $hAlign; } else { $el->attrs['class'][] = $tx->alignClasses[$hAlign]; } } if (!is_int($image->width) || !is_int($image->height) || $image->asMax) { // autodetect fileRoot if ($this->fileRoot === null && isset($_SERVER['SCRIPT_FILENAME'])) { $this->fileRoot = dirname($_SERVER['SCRIPT_FILENAME']) . '/' . $this->root; } // detect dimensions // absolute URL & security check for double dot if (Texy::isRelative($image->URL) && strpos($image->URL, '..') === false) { $file = rtrim($this->fileRoot, '/\\') . '/' . $image->URL; if (@is_file($file)) { // intentionally @ $size = @getImageSize($file); // intentionally @ if (is_array($size)) { if ($image->asMax) { $ratio = 1; if (is_int($image->width)) { $ratio = min($ratio, $image->width / $size[0]); } if (is_int($image->height)) { $ratio = min($ratio, $image->height / $size[1]); } $image->width = round($ratio * $size[0]); $image->height = round($ratio * $size[1]); } elseif (is_int($image->width)) { $ratio = round($size[1] / $size[0] * $image->width); $image->height = round($size[1] / $size[0] * $image->width); } elseif (is_int($image->height)) { $image->width = round($size[0] / $size[1] * $image->height); } else { $image->width = $size[0]; $image->height = $size[1]; } } } } } $el->attrs['width'] = $image->width; $el->attrs['height'] = $image->height; // onmouseover actions generate if ($image->overURL !== null) { $overSrc = Texy::prependRoot($image->overURL, $this->root); $el->attrs['onmouseover'] = 'this.src=\'' . addSlashes($overSrc) . '\''; $el->attrs['onmouseout'] = 'this.src=\'' . addSlashes($el->attrs['src']) . '\''; $el->attrs['onload'] = str_replace('%i', addSlashes($overSrc), $this->onLoad); $tx->summary['preload'][] = $overSrc; } $tx->summary['images'][] = $el->attrs['src']; if ($link) { return $tx->linkModule->solve(null, $link, $el); } return $el; }