/** * @dataProvider provideUnserialized */ public function testUnserialize(SerializerInterface $serializer, ShortcodeInterface $test, $text) { $tested = $serializer->unserialize($text); $this->assertSame($test->getName(), $tested->getName(), 'name: ' . $text); $this->assertSame($test->getParameters(), $tested->getParameters(), 'parameters: ' . $text); $this->assertSame($test->getContent(), $tested->getContent(), 'content: ' . $text); $this->assertSame($test->getBbCode(), $tested->getBbCode(), 'bbCode: ' . $text); }
function __invoke(ShortcodeInterface $shortcode) { $attributeParser = new DataAttributesParser(); $formatHelper = new FormatHelper(); $atts = array("xclass" => $shortcode->getParameter('xclass', false), "data" => $shortcode->getParameter('data', false)); $class = 'row'; $class .= $atts['xclass'] ? ' ' . $atts['xclass'] : ''; $dataProps = $attributeParser($atts['data']); return sprintf('<div class="%s"%s>%s</div>', $formatHelper->esc_attr($class), $dataProps ? ' ' . $dataProps : '', $shortcode->getContent()); }
/** * [placeholder value=18]You age is %value%[/placeholder] * * @param ShortcodeInterface $shortcode * * @return mixed */ public function __invoke(ShortcodeInterface $shortcode) { $args = $shortcode->getParameters(); $delimiter = $this->delimiter; $keys = array_map(function ($key) use($delimiter) { return $delimiter . $key . $delimiter; }, array_keys($args)); $values = array_values($args); return str_replace($keys, $values, $shortcode->getContent()); }
public function serialize(ShortcodeInterface $shortcode) { $open = $this->syntax->getOpeningTag(); $close = $this->syntax->getClosingTag(); $marker = $this->syntax->getClosingTagMarker(); $parameters = $this->serializeParameters($shortcode->getParameters()); $bbCode = null !== $shortcode->getBbCode() ? $this->serializeValue($shortcode->getBbCode()) : ''; $return = $open . $shortcode->getName() . $bbCode . $parameters; return null === $shortcode->getContent() ? $return . ' ' . $marker . $close : $return . $close . $shortcode->getContent() . $open . $marker . $shortcode->getName() . $close; }
/** * [declare name]Your name is %value%[/declare] * [name value="Thomas" /] * * @param ShortcodeInterface $shortcode */ public function __invoke(ShortcodeInterface $shortcode) { $args = $shortcode->getParameters(); if (empty($args)) { return; } $keys = array_keys($args); $name = array_shift($keys); $content = $shortcode->getContent(); $delimiter = $this->delimiter; $this->handlers->add($name, function (ShortcodeInterface $shortcode) use($content, $delimiter) { $args = $shortcode->getParameters(); $keys = array_map(function ($key) use($delimiter) { return $delimiter . $key . $delimiter; }, array_keys($args)); $values = array_values($args); return str_replace($keys, $values, $content); }); }
public function serialize(ShortcodeInterface $shortcode) { $open = $this->syntax->getOpeningTag(); $close = $this->syntax->getClosingTag(); $marker = $this->syntax->getClosingTagMarker(); $parameters = $this->serializeParameters($shortcode->getParameters()); $return = $open . $shortcode->getName() . $parameters; return null === $shortcode->getContent() ? $return . ($shortcode instanceof ParsedShortcodeInterface && $shortcode->getMarkerOffset() ? ' ' . $marker : '') . $close : $return . $close . $shortcode->getContent() . $open . $marker . $shortcode->getName() . $close; }
/** * <shortcode name="NAME"> * <bbCode>BBCODE</bbCode> * <parameters> * <parameter name="KEY">VALUE</parameter> * <parameter name="KEY">VALUE</parameter> * </parameters> * <content>CONTENT></content> * </shortcode> * * @param ShortcodeInterface $shortcode * * @return string */ public function serialize(ShortcodeInterface $shortcode) { $doc = new \DOMDocument('1.0', 'UTF-8'); $doc->preserveWhiteSpace = false; $doc->formatOutput = true; $code = $doc->createElement('shortcode'); $code->setAttribute('name', $shortcode->getName()); $xml = $doc->appendChild($code); $xml->appendChild($this->createCDataNode($doc, 'bbCode', $shortcode->getBbCode())); $parameters = $xml->appendChild($doc->createElement('parameters')); foreach ($shortcode->getParameters() as $key => $value) { $parameter = $doc->createElement('parameter'); $parameter->setAttribute('name', $key); if (null !== $value) { $parameter->appendChild($doc->createCDATASection($value)); } $parameters->appendChild($parameter); } $xml->appendChild($this->createCDataNode($doc, 'content', $shortcode->getContent())); return $doc->saveXML(); }
public function __invoke(ShortcodeInterface $shortcode) { $attributeParser = new DataAttributesParser(); $formatHelper = new FormatHelper(); $atts = array("visible" => $shortcode->getParameter('visible', false), "hidden" => $shortcode->getParameter('hidden', false), "block" => $shortcode->getParameter('block', false), "inline" => $shortcode->getParameter('inline', false), "inline_block" => $shortcode->getParameter('inline_block', false), "xclass" => $shortcode->getParameter('xclass', false), "data" => $shortcode->getParameter('data', false)); $class = ''; if ($atts['visible']) { $visible = explode(' ', $atts['visible']); foreach ($visible as $v) { $class .= "visible-{$v} "; } } if ($atts['hidden']) { $hidden = explode(' ', $atts['hidden']); foreach ($hidden as $h) { $class .= "hidden-{$h} "; } } if ($atts['block']) { $block = explode(' ', $atts['block']); foreach ($block as $b) { $class .= "visible-{$b}-block "; } } if ($atts['inline']) { $inline = explode(' ', $atts['inline']); foreach ($inline as $i) { $class .= "visible-{$i}-inline "; } } if ($atts['inline_block']) { $inline_block = explode(' ', $atts['inline_block']); foreach ($inline_block as $ib) { $class .= "visible-{$ib}-inline "; } } $class .= $atts['xclass'] ? ' ' . $atts['xclass'] : ''; $dataProps = $attributeParser($atts['data']); return sprintf('<div class="%s"%s>%s</div>', $formatHelper->esc_attr($class), $dataProps ? ' ' . $dataProps : '', $shortcode->getContent()); }
public function __invoke(ShortcodeInterface $shortcode) { $attributeParser = new DataAttributesParser(); $formatHelper = new FormatHelper(); $atts = array("type" => $shortcode->getParameter('type', false), "dismissable" => $shortcode->getParameter('dismissable', false), "xclass" => $shortcode->getParameter('xclass', false), "data" => $shortcode->getParameter('data', false)); $class = 'alert'; $class .= $atts['type'] ? ' alert-' . $atts['type'] : ' alert-success'; $class .= $atts['dismissable'] == 'true' ? ' alert-dismissable' : ''; $class .= $atts['xclass'] ? ' ' . $atts['xclass'] : ''; $dismissable = $atts['dismissable'] ? '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>' : ''; $dataProps = $attributeParser($atts['data']); return sprintf('<div class="%s"%s>%s%s</div>', $formatHelper->esc_attr($class), $dataProps ? ' ' . $dataProps : '', $dismissable, $shortcode->getContent()); }
/** * [name /] * [name]content is ignored[/name] * * @param ShortcodeInterface $shortcode * * @return string */ public function __invoke(ShortcodeInterface $shortcode) { return $shortcode->getName(); }
public function serialize(ShortcodeInterface $shortcode) { return json_encode(array('name' => $shortcode->getName(), 'parameters' => $shortcode->getParameters(), 'content' => $shortcode->getContent())); }
/** * [email="*****@*****.**"]Contact me![/email] * [email="*****@*****.**" /] * [email]example@example.org[/email] * * @param ShortcodeInterface $shortcode * * @return string */ public function __invoke(ShortcodeInterface $shortcode) { $email = $shortcode->getBbCode() ?: $shortcode->getContent(); $content = $shortcode->getContent() === null ? $email : $shortcode->getContent(); return '<a href="mailto:' . $email . '">' . $content . '</a>'; }
public function __invoke(ShortcodeInterface $s) { return strrev($s->getContent()); }
public function serialize(ShortcodeInterface $shortcode) { return Yaml::dump(array('name' => $shortcode->getName(), 'parameters' => $shortcode->getParameters(), 'content' => $shortcode->getContent(), 'bbCode' => $shortcode->getBbCode())); }
/** * helper method to create a unique shortcode based on the content * * @param ShortcodeInterface $shortcode * @return string */ public function getId(ShortcodeInterface $shortcode) { return substr(md5($shortcode->getShortcodeText()), -10); }
public function __invoke(ShortcodeInterface $shortcode) { $attributeParser = new DataAttributesParser(); $formatHelper = new FormatHelper(); $atts = array("lg" => $shortcode->getParameter('lg', false), "md" => $shortcode->getParameter('md', false), "sm" => $shortcode->getParameter('sm', false), "xs" => $shortcode->getParameter('xs', false), "offset_lg" => $shortcode->getParameter('offset_lg', false), "offset_md" => $shortcode->getParameter('offset_md', false), "offset_sm" => $shortcode->getParameter('offset_sm', false), "offset_xs" => $shortcode->getParameter('offset_xs', false), "pull_lg" => $shortcode->getParameter('pull_lg', false), "pull_md" => $shortcode->getParameter('pull_md', false), "pull_sm" => $shortcode->getParameter('pull_sm', false), "pull_xs" => $shortcode->getParameter('pull_xs', false), "push_lg" => $shortcode->getParameter('push_lg', false), "push_md" => $shortcode->getParameter('push_md', false), "push_sm" => $shortcode->getParameter('push_sm', false), "push_xs" => $shortcode->getParameter('push_xs', false), "xclass" => $shortcode->getParameter('xclass', false), "data" => $shortcode->getParameter('data', false)); $class = ''; $class .= $atts['lg'] ? ' col-lg-' . $atts['lg'] : ''; $class .= $atts['md'] ? ' col-md-' . $atts['md'] : ''; $class .= $atts['sm'] ? ' col-sm-' . $atts['sm'] : ''; $class .= $atts['xs'] ? ' col-xs-' . $atts['xs'] : ''; $class .= $atts['offset_lg'] || $atts['offset_lg'] === "0" ? ' col-lg-offset-' . $atts['offset_lg'] : ''; $class .= $atts['offset_md'] || $atts['offset_md'] === "0" ? ' col-md-offset-' . $atts['offset_md'] : ''; $class .= $atts['offset_sm'] || $atts['offset_sm'] === "0" ? ' col-sm-offset-' . $atts['offset_sm'] : ''; $class .= $atts['offset_xs'] || $atts['offset_xs'] === "0" ? ' col-xs-offset-' . $atts['offset_xs'] : ''; $class .= $atts['pull_lg'] || $atts['pull_lg'] === "0" ? ' col-lg-pull-' . $atts['pull_lg'] : ''; $class .= $atts['pull_md'] || $atts['pull_md'] === "0" ? ' col-md-pull-' . $atts['pull_md'] : ''; $class .= $atts['pull_sm'] || $atts['pull_sm'] === "0" ? ' col-sm-pull-' . $atts['pull_sm'] : ''; $class .= $atts['pull_xs'] || $atts['pull_xs'] === "0" ? ' col-xs-pull-' . $atts['pull_xs'] : ''; $class .= $atts['push_lg'] || $atts['push_lg'] === "0" ? ' col-lg-push-' . $atts['push_lg'] : ''; $class .= $atts['push_md'] || $atts['push_md'] === "0" ? ' col-md-push-' . $atts['push_md'] : ''; $class .= $atts['push_sm'] || $atts['push_sm'] === "0" ? ' col-sm-push-' . $atts['push_sm'] : ''; $class .= $atts['push_xs'] || $atts['push_xs'] === "0" ? ' col-xs-push-' . $atts['push_xs'] : ''; $class .= $atts['xclass'] ? ' ' . $atts['xclass'] : ''; $dataProps = $attributeParser($atts['data']); return sprintf('<div class="%s"%s>%s</div>', $formatHelper->esc_attr($class), $dataProps ? ' ' . $dataProps : '', $shortcode->getContent()); }
/** * [b]content[b] * [strong]content[/strong] * * @param ShortcodeInterface $shortcode * * @return string */ public function __invoke(ShortcodeInterface $shortcode) { return $this->before . $shortcode->getContent() . $this->after; }
/** * [url="http://example.org"]Click![/url] * [url="http://example.org" /] * [url]http://example.org[/url] * * @param ShortcodeInterface $shortcode * * @return string */ public function __invoke(ShortcodeInterface $shortcode) { $url = $shortcode->getBbCode() ?: $shortcode->getContent(); return '<a href="' . $url . '">' . $shortcode->getContent() . '</a>'; }