Exemplo n.º 1
0
/**
 * User handler for images
 *
 * @param TexyHandlerInvocation  handler invocation
 * @param TexyImage
 * @param TexyLink
 * @return TexyHtml|string|FALSE
 */
function imageHandler($invocation, $image, $link)
{
    $texy = $invocation->getTexy();
    if (substr($image->URL, -4) === '.swf') {
        $movie = Texy::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 http://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();
}
Exemplo n.º 2
0
 /**
  * Finish invocation.
  *
  * @param  TexyHandlerInvocation  handler invocation
  * @param  string
  * @param  string
  * @return TexyHtml|FALSE
  */
 public function solve($invocation, $emoticon, $raw)
 {
     $tx = $this->texy;
     $file = $this->icons[$emoticon];
     $el = TexyHtml::el('img');
     $el->attrs['src'] = Texy::prependRoot($file, $this->root === NULL ? $tx->imageModule->root : $this->root);
     $el->attrs['alt'] = $raw;
     $el->attrs['class'][] = $this->class;
     // file path
     $file = rtrim($this->fileRoot === NULL ? $tx->imageModule->fileRoot : $this->fileRoot, '/\\') . '/' . $file;
     if (@is_file($file)) {
         // intentionally @
         $size = @getImageSize($file);
         // intentionally @
         if (is_array($size)) {
             $el->attrs['width'] = $size[0];
             $el->attrs['height'] = $size[1];
         }
     }
     $tx->summary['images'][] = $el->attrs['src'];
     return $el;
 }
 /**
  * Finish invocation.
  *
  * @param  TexyHandlerInvocation  handler invocation
  * @param  TexyLink
  * @param  TexyHtml|string
  * @return TexyHtml|string
  */
 public function solve($invocation, $link, $content = NULL)
 {
     if ($link->URL == NULL) {
         return $content;
     }
     $tx = $this->texy;
     $el = TexyHtml::el('a');
     if (empty($link->modifier)) {
         $nofollow = $popup = FALSE;
     } else {
         $nofollow = isset($link->modifier->classes['nofollow']);
         $popup = isset($link->modifier->classes['popup']);
         unset($link->modifier->classes['nofollow'], $link->modifier->classes['popup']);
         $el->attrs['href'] = NULL;
         // trick - move to front
         $link->modifier->decorate($tx, $el);
     }
     if ($link->type === TexyLink::IMAGE) {
         // image
         $el->attrs['href'] = Texy::prependRoot($link->URL, $tx->imageModule->linkedRoot);
         if ($this->imageClass) {
             $el->attrs['class'][] = $this->imageClass;
         } else {
             $el->attrs['onclick'] = $this->imageOnClick;
         }
     } else {
         $el->attrs['href'] = Texy::prependRoot($link->URL, $this->root);
         // rel="nofollow"
         if ($nofollow || $this->forceNoFollow && strpos($el->attrs['href'], '//') !== FALSE) {
             $el->attrs['rel'] = 'nofollow';
         }
     }
     // popup on click
     if ($popup) {
         $el->attrs['onclick'] = $this->popupOnClick;
     }
     if ($content !== NULL) {
         $el->add($content);
     }
     $tx->summary['links'][] = $el->attrs['href'];
     return $el;
 }
Exemplo n.º 4
0
 /**
  * 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)) {
                 $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;
     // 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;
 }
Exemplo n.º 5
0
 /**
  * Flash handler for images
  *
  * @example [* flash.swf 200x150 .(alternative content) *]
  *
  * @param TexyHandlerInvocation  handler invocation
  * @param TexyImage
  * @param TexyLink
  * @return TexyHtml|string|FALSE
  */
 public function flashHandler($invocation, $image, $link)
 {
     if (!Strings::endsWith($image->URL, ".swf")) {
         return $invocation->proceed();
     }
     $template = $this->createTemplate()->setFile(APP_DIR . "/templates/inc/@flash.latte");
     $template->url = Texy::prependRoot($image->URL, $this->imageModule->root);
     $template->width = $image->width;
     $template->height = $image->height;
     if ($image->modifier->title) {
         $template->title = $image->modifier->title;
     }
     return $this->protect((string) $template, Texy::CONTENT_BLOCK);
 }
 /**
  * Converts cite source to URL.
  *
  * @param  string
  *
  * @return string|NULL
  */
 public function citeLink($link)
 {
     $tx = $this->texy;
     if ($link == null) {
         return null;
     }
     if ($link[0] === '[') {
         // [ref]
         $link = substr($link, 1, -1);
         $ref = $tx->linkModule->getReference($link);
         if ($ref) {
             return Texy::prependRoot($ref->URL, $tx->linkModule->root);
         }
     }
     // special supported case
     if (strncasecmp($link, 'www.', 4) === 0) {
         return 'http://' . $link;
     }
     return Texy::prependRoot($link, $tx->linkModule->root);
 }