protected function handleTag_img()
{
if (!$this->parser->isStartTag) {
return;
// just to be sure this is really an empty tag...
}
if (isset($this->parser->tagAttributes['title'])) {
$this->parser->tagAttributes['title'] = $this->decode($this->parser->tagAttributes['title']);
} else {
$this->parser->tagAttributes['title'] = null;
}
if (isset($this->parser->tagAttributes['alt'])) {
$this->parser->tagAttributes['alt'] = $this->decode($this->parser->tagAttributes['alt']);
} else {
$this->parser->tagAttributes['alt'] = null;
}
if (empty($this->parser->tagAttributes['src'])) {
// support for "empty" images... dunno if this is really needed
// but there are some test cases which do that...
if (!empty($this->parser->tagAttributes['title'])) {
$this->parser->tagAttributes['title'] = ' ' . $this->parser->tagAttributes['title'] . ' ';
}
$this->out('![' . $this->parser->tagAttributes['alt'] . '](' . $this->parser->tagAttributes['title'] . ')', true);
return;
} else {
$this->parser->tagAttributes['src'] = $this->decode($this->parser->tagAttributes['src']);
}
$out = '![' . $this->parser->tagAttributes['alt'] . ']';
if ($this->linkPosition == self::LINK_IN_PARAGRAPH) {
$out .= '(' . $this->parser->tagAttributes['src'];
if ($this->parser->tagAttributes['title']) {
$out .= ' "' . $this->parser->tagAttributes['title'] . '"';
}
$out .= ')';
$this->out($out, true);
return;
}
// ![This image][id]
$link_id = false;
if (!empty($this->footnotes)) {
foreach ($this->footnotes as $tag) {
if ($tag['href'] == $this->parser->tagAttributes['src'] && $tag['title'] === $this->parser->tagAttributes['title']) {
$link_id = $tag['linkID'];
break;
}
}
}
if (!$link_id) {
$link_id = count($this->footnotes) + 1;
$tag = array('href' => $this->parser->tagAttributes['src'], 'linkID' => $link_id, 'title' => $this->parser->tagAttributes['title']);
array_push($this->footnotes, $tag);
}
$out .= '[' . $link_id . ']';
$this->out($out, true);
}