load($matches[1]); } if (!$file) { return $matches[0]; } $options = array( 'size' => 'thumb', 'layout' => 'left', 'float' => false, 'name' => null, ); if (!empty($matches[2])) { $matches[2] = trim($matches[2], ', '); $options = PhutilSimpleOptions::parse($matches[2]) + $options; } $file_name = coalesce($options['name'], $file->getName()); if (!$file->isViewableImage() || $options['layout'] == 'link') { // If a file isn't in image, just render a link to it. $link = phutil_render_tag( 'a', array( 'href' => $file->getBestURI(), 'target' => '_blank', 'class' => 'phabricator-remarkup-embed-layout-link', ), phutil_escape_html($file_name)); return $this->getEngine()->storeText($link); } $attrs = array( 'class' => 'phabricator-remarkup-embed-image', ); switch ($options['size']) { case 'full': $attrs['src'] = $file->getBestURI(); $link = null; break; case 'thumb': default: $attrs['src'] = $file->getThumb160x120URI(); $attrs['width'] = 160; $attrs['height'] = 120; $link = $file->getBestURI(); break; } $embed = phutil_render_tag('img', $attrs); if ($link) { $embed = phutil_render_tag( 'a', array( 'href' => $link, 'target' => '_blank', ), $embed); } $layout_class = null; switch ($options['layout']) { case 'right': case 'center': case 'inline': case 'left': $layout_class = 'phabricator-remarkup-embed-layout-'.$options['layout']; break; default: $layout_class = 'phabricator-remarkup-embed-layout-left'; break; } if ($options['float']) { switch ($options['layout']) { case 'center': case 'inline': break; case 'right': $layout_class .= ' phabricator-remarkup-embed-float-right'; break; case 'left': default: $layout_class .= ' phabricator-remarkup-embed-float-left'; break; } } if ($layout_class) { $embed = phutil_render_tag( 'div', array( 'class' => $layout_class, ), $embed); } return $this->getEngine()->storeText($embed); } }