/** * Finish invocation. * @return Texy\HtmlElement|FALSE */ public function solve(Texy\HandlerInvocation $invocation = NULL, Image $image, Texy\Link $link = NULL) { if ($image->URL == NULL) { return FALSE; } $texy = $this->texy; $mod = $image->modifier; $alt = $mod->title; $mod->title = NULL; $hAlign = $mod->hAlign; $mod->hAlign = NULL; $el = new Texy\HtmlElement('img'); $el->attrs['src'] = NULL; // trick - move to front $mod->decorate($texy, $el); $el->attrs['src'] = Helpers::prependRoot($image->URL, $this->root); if (!isset($el->attrs['alt'])) { $el->attrs['alt'] = $alt === NULL ? $this->defaultAlt : $texy->typographyModule->postLine($alt); } if ($hAlign) { $var = $hAlign . 'Class'; // leftClass, rightClass if (!empty($this->{$var})) { $el->attrs['class'][] = $this->{$var}; } elseif (empty($texy->alignClasses[$hAlign])) { $el->attrs['style']['float'] = $hAlign; } else { $el->attrs['class'][] = $texy->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 (Helpers::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)) { $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 (!empty($texy->allowed['image/hover']) && $image->overURL !== NULL) { $overSrc = Helpers::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); $texy->summary['preload'][] = $overSrc; } $texy->summary['images'][] = $el->attrs['src']; if ($link) { return $texy->linkModule->solve(NULL, $link, $el); } return $el; }