-
-
Save nokimaro/7849c6f2e9d23e5751fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once "jBBCode" . DIRECTORY_SEPARATOR . "Parser.php"; | |
/** | |
* Implements an [img=alt] tag that supports an optional class argument. | |
* | |
*/ | |
class ImageWithClass extends \JBBCode\CodeDefinition | |
{ | |
public function __construct() | |
{ | |
$this->parseContent = false; | |
$this->useOption = true; | |
$this->setTagName('img'); | |
$this->nestLimit = -1; | |
} | |
public function asHtml(\JBBCode\ElementNode $el) | |
{ | |
$url = ''; | |
foreach ($el->getChildren() as $child) { | |
$url .= $child->getAsText(); | |
} | |
// Split the argument on the pipe character | |
$argPieces = explode('|', $el->getAttribute()); | |
$altText = $argPieces[0]; | |
$class = 'default-class'; | |
if (count($argPieces) > 1) { | |
$class = $argPieces[1]; | |
} | |
return '<img src="' + $url + '" alt="' + $altText + '" class="' + $class + '" />'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment