shortcode_basic_tags.module in Shortcode 7.2
Provides basic ShortCodes (as examples).
File
shortcode_basic_tags/shortcode_basic_tags.moduleView source
<?php
/**
* @file
* Provides basic ShortCodes (as examples).
*/
/**
* Implements hook_shortcode_info().
*
* Using the same formatting as hook_filter_info()
*/
function shortcode_basic_tags_shortcode_info() {
$shortcodes['quote'] = array(
'title' => t('Quote'),
'description' => t('Replace the given text formatted like as a quote.'),
'process callback' => 'shortcode_basic_tags_shortcode_quote',
// todo: implements this.
// 'settings callback' => '_shortcode_settings_form',
'attributes callback' => 'shortcode_basic_tags_quote_attributes',
'tips callback' => 'shortcode_basic_tags_shortcode_quote_tip',
);
$shortcodes['img'] = array(
'title' => t('Image'),
'description' => t('Show an image.'),
'process callback' => 'shortcode_basic_tags_shortcode_img',
// todo: implements this.
// 'settings callback' => '_shortcode_settings_form',
'attributes callback' => 'shortcode_basic_tags_img_attributes',
'tips callback' => 'shortcode_basic_tags_shortcode_img_tip',
);
$shortcodes['highlight'] = array(
'title' => t('Highlight'),
'description' => t('Insert a span with highlight css class around the text.'),
'process callback' => 'shortcode_basic_tags_shortcode_highlight',
// todo: implements this.
// settings callback' => '_shortcode_settings_form',
'attributes callback' => 'shortcode_basic_tags_highlight_attributes',
'tips callback' => 'shortcode_basic_tags_shortcode_highlight_tip',
);
$shortcodes['button'] = array(
'title' => t('Button'),
'description' => t('Insert a link formatted as a button.'),
'process callback' => 'shortcode_basic_tags_shortcode_button',
// todo: implements this.
// 'settings callback' => '_shortcode_settings_form',
'attributes callback' => 'shortcode_basic_tags_button_attributes',
'tips callback' => 'shortcode_basic_tags_shortcode_button_tip',
);
$shortcodes['dropcap'] = array(
'title' => t('Dropcap'),
'description' => t('Replace the given text formatted like as a dropcap.'),
'process callback' => 'shortcode_basic_tags_shortcode_dropcap',
// todo: implements this.
// 'settings callback' => '_shortcode_settings_form',
'attributes callback' => 'shortcode_basic_tags_dropcap_attributes',
'tips callback' => 'shortcode_basic_tags_shortcode_dropcap_tip',
);
$shortcodes['item'] = array(
'title' => t('Item'),
'description' => t('Insert div or span around the text with some css classes.'),
'process callback' => 'shortcode_basic_tags_shortcode_item',
// todo: implements this.
// 'settings callback' => '_shortcode_settings_form',
'attributes callback' => 'shortcode_basic_tags_item_attributes',
'tips callback' => 'shortcode_basic_tags_shortcode_item_tip',
);
$shortcodes['clear'] = array(
'title' => t('Clear'),
'description' => t('Insert a float-clearing div for a proper layout.'),
'process callback' => 'shortcode_basic_tags_shortcode_clear',
// todo: implements this.
// 'settings callback' => '_shortcode_settings_form',
'attributes callback' => 'shortcode_basic_tags_clear_attributes',
'tips callback' => 'shortcode_basic_tags_shortcode_clear_tip',
);
$shortcodes['link'] = array(
'title' => t('Link'),
'description' => t('Makes an aliased link to the given path.'),
'process callback' => 'shortcode_basic_tags_shortcode_link',
// todo: implements this.
// 'settings callback' => '_shortcode_settings_form',
'attributes callback' => 'shortcode_basic_tags_link_attributes',
'tips callback' => 'shortcode_basic_tags_shortcode_link_tip',
);
$shortcodes['random'] = array(
'title' => t('Random text'),
'description' => t('Generating random text.'),
'process callback' => 'shortcode_basic_tags_shortcode_random',
// todo: implements this.
// 'settings callback' => '_shortcode_settings_form',
'attributes callback' => 'shortcode_basic_tags_random_attributes',
'tips callback' => 'shortcode_basic_tags_shortcode_random_tip',
);
return $shortcodes;
}
/**
* Implements hook_theme().
*/
function shortcode_basic_tags_theme() {
return array(
'shortcode_button' => array(
'variables' => array(
'link' => '#',
'text' => '',
'class' => 'button',
),
),
'shortcode_quote' => array(
'variables' => array(
'text' => '',
'author' => FALSE,
'class' => 'quote',
),
),
'shortcode_img' => array(
'variables' => array(
'src' => '',
'alt' => '',
'class' => 'img',
),
),
'shortcode_dropcap' => array(
'variables' => array(
'text' => '',
'class' => 'dropcap',
),
),
'shortcode_item' => array(
'variables' => array(
'text' => '',
'id' => '',
'class' => '',
'type' => 'div',
),
),
'shortcode_clear' => array(
'variables' => array(
'text' => '',
'id' => '',
'class' => '',
'type' => 'div',
),
),
);
}
/**
* Attributes form element for highlight shortcode.
*
* Used by shortcode_wysiwyg module to add form elements for attributes.
*/
function shortcode_basic_tags_highlight_attributes($form, &$form_state) {
$form['highlight-class'] = array(
'#title' => t('Class'),
'#type' => 'textfield',
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array(
'value' => 'highlight',
),
),
),
);
return $form;
}
/**
* Inserts a span with highlight css class around the text.
*
* Calling
* [highlight]text[/highlight]
*
*
* If the length is empty or invalid, between 1-99, the length will be 8
*/
function shortcode_basic_tags_shortcode_highlight($attrs, $text) {
$attrs = shortcode_attrs(array(
'class' => '',
), $attrs);
$class = shortcode_add_class($attrs['class'], 'highlight');
return '<span class="' . $class . '">' . $text . '</span>';
}
/**
* Provides tip callback for highlight Shortcode.
*/
function shortcode_basic_tags_shortcode_highlight_tip($format, $long) {
$output = array();
$output[] = '<p><strong>' . t('[highlight (class="additional class")]text[/highlight]') . '</strong> ';
if ($long) {
$output[] = t('Inserts span.highlight around the text.') . '</p>';
$output[] = '<p>' . t('Sample css:') . '</p>';
$output[] = '
<code>
span.highlight{
background-color:red;
}
span.highlight2{
background-color:cyan;
}
</code><p> </p>';
}
else {
$output[] = t('Inserts span.highlight around the text. Additional class names can be added by the <em>class</em> parameter.') . '</p>';
}
return implode(' ', $output);
}
/**
* Attributes form element for button Shortcode.
*
* Used by shortcode_wysiwyg module to add form elements for attributes.
*/
function shortcode_basic_tags_button_attributes($form, &$form_state) {
$form['button-title'] = array(
'#title' => t('Title'),
'#type' => 'textfield',
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array(
'value' => 'button',
),
),
),
);
$form['button-path'] = array(
'#title' => t('Path'),
'#type' => 'textfield',
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array(
'value' => 'button',
),
),
),
);
$form['button-class'] = array(
'#title' => t('Class'),
'#type' => 'textfield',
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array(
'value' => 'button',
),
),
),
);
return $form;
}
/**
* Provides process callback for Shortcode button.
*/
function shortcode_basic_tags_shortcode_button($attrs, $text) {
$attrs = shortcode_attrs(array(
'title' => 'title default',
'class' => 'button',
'url' => '',
'path' => '<front>',
), $attrs);
$class = shortcode_add_class($attrs['class'], 'button');
if ($attrs['url']) {
$attrs['path'] = $attrs['url'];
}
$path = url($attrs['path']);
return theme('shortcode_button', array(
'path' => $path,
'text' => $text,
'class' => $class,
));
}
/**
* Provides tip callback for button Shortcode.
*/
function shortcode_basic_tags_shortcode_button_tip($format, $long) {
$output = array();
$output[] = '<p><strong>' . t('[button path="path" (class="additional class")]text[/button]') . '</strong> ';
if ($long) {
$output[] = t('Inserts a link formatted as a button. Use the url parameter for the link.') . '</p>';
}
else {
$output[] = t('Inserts a link formatted like as a button. The <em>path</em> parameter provides the link target (the default is the front page).
The <em>title</em> will be formatted as a link title (small tooltip over the link - helps for SEO).
Additional class names can be added by the <em>class</em> parameter.') . '</p>';
}
return implode(' ', $output);
}
/**
* Implements theme for button Shortcode.
*/
function theme_shortcode_button($vars) {
return '<a href="' . $vars['path'] . '" class="' . $vars['class'] . '"><span>' . $vars['text'] . '</span></a>';
}
/**
* Attributes form element for dropcap shortcode.
*
* Used by shortcode_wysiwyg module to add form elements for attributes.
*/
function shortcode_basic_tags_dropcap_attributes($form, &$form_state) {
$form['dropcap-class'] = array(
'#title' => t('Class'),
'#type' => 'textfield',
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array(
'value' => 'dropcap',
),
),
),
);
return $form;
}
/**
* Provides process callback for dropcap Shortcode.
*/
function shortcode_basic_tags_shortcode_dropcap($attrs, $text) {
$attrs = shortcode_attrs(array(
'class' => 'dropcap',
), $attrs);
$class = shortcode_add_class($attrs['class'], 'dropcap');
return theme('shortcode_dropcap', array(
'text' => $text,
'class' => $class,
));
}
/**
* Provides theme for dropcap Shortcode.
*/
function theme_shortcode_dropcap($vars) {
return '<span class="' . $vars['class'] . '">' . $vars['text'] . '</span>';
}
/**
* Provides tip callback for dropcap Shortcode.
*/
function shortcode_basic_tags_shortcode_dropcap_tip($format, $long) {
$output = array();
$output[] = '<p><strong>' . t('[dropcap (class="additional class")]text[/dropcap]') . '</strong> ';
if ($long) {
$output[] = t('Makes dropcap from the text.') . '</p>';
$output[] = '<p>' . t('Sample css:') . '</p>';
$output[] = '<code>
.dropcap {
display:block;
float:left;
font-size:38px;
line-height:38px;
vertical-align:baseline;
padding-right:5px;
}
</code><p> </p>';
}
else {
$output[] = t('Makes dropcap from the text. Additional class names can be added by the <em>class</em> parameter.') . '</p>';
}
return implode(' ', $output);
}
/**
* Attributes form element for quote shortcode.
*
* Used by shortcode_wysiwyg module to add form elements for attributes.
*/
function shortcode_basic_tags_quote_attributes($form, &$form_state) {
$form['quote-author'] = array(
'#title' => t('Author'),
'#type' => 'textfield',
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array(
'value' => 'quote',
),
),
),
);
$form['quote-class'] = array(
'#title' => t('Class'),
'#type' => 'textfield',
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array(
'value' => 'quote',
),
),
),
);
return $form;
}
/**
* Provides process callback for quote Shortcode.
*/
function shortcode_basic_tags_shortcode_quote($attrs, $text) {
$attrs = shortcode_attrs(array(
'class' => 'quote',
'author' => '',
), $attrs);
$class = shortcode_add_class($attrs['class'], 'quote');
return theme('shortcode_quote', array(
'text' => $text,
'author' => $attrs['author'],
'class' => $class,
));
}
/**
* Provides theme for blockquote.
*/
function theme_shortcode_quote($vars) {
$output = '';
if (!empty($vars['author'])) {
// Adding author.
$output = '<span class="quote-author">' . t('%name wrote:', array(
'%name' => $vars['author'],
)) . '</span>';
}
$output .= $vars['text'];
return '<blockquote class="' . $vars['class'] . '">' . $output . '</blockquote>';
}
/**
* Provides tip callback for quote Shortcode.
*/
function shortcode_basic_tags_shortcode_quote_tip($format, $long) {
$output = array();
$output[] = '<p><strong>' . t('[quote (class="additional class" | author="author name")]text[/quote]') . '</strong> ';
if ($long) {
$output[] = t('Formats the text like as a quote.') . '</p>';
$output[] = '<p>' . t('Sample css:') . '</p>';
$output[] = '<code>
.quote {
display:block;
float:left;
width:30%;
margin:20px;
margin-left:0;
padding:5px 0 5px 20px;
font-style:italic;
border-left:3px solid #E8E8E8;
line-heigh:1.5em;
font-size:14px;
letter-spacing: 1px;
word-spacing: 2px;
}
.quote.right{
float:right;
margin-right:0;
margin-left:20px;
}
</code><p> </p>';
}
else {
$output[] = t('Formats the text like as a quote. Additional class names can be added by the <em>class</em> parameter.') . '</p>';
}
return implode(' ', $output);
}
/**
* Attributes form element for quote shortcode.
*
* Used by shortcode_wysiwyg module to add form elements for attributes.
*/
function shortcode_basic_tags_img_attributes($form, &$form_state) {
$form['img-src'] = array(
'#title' => t('Source URL'),
'#type' => 'textfield',
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array(
'value' => 'img',
),
),
),
);
$form['img-alt'] = array(
'#title' => t('Alt text'),
'#type' => 'textfield',
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array(
'value' => 'img',
),
),
),
);
$form['img-class'] = array(
'#title' => t('Class'),
'#type' => 'textfield',
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array(
'value' => 'img',
),
),
),
);
return $form;
}
/**
* Provides process callback for img Shortcode.
*/
function shortcode_basic_tags_shortcode_img($attrs, $text) {
$attrs = shortcode_attrs(array(
'class' => 'img',
'alt' => '',
// Add default logo from bartik theme.
'src' => 'themes/bartik/logo.png',
), $attrs);
$class = shortcode_add_class($attrs['class'], 'img');
return theme('shortcode_img', array(
'src' => check_plain($attrs['src']),
'alt' => check_plain($attrs['alt']),
'class' => $class,
));
}
/**
* Provides theme for img Shortcode.
*/
function theme_shortcode_img($vars) {
return '<img src="' . url($vars['src']) . '" class="' . $vars['class'] . '" alt="' . $vars['alt'] . '"/>';
}
/**
* Provides tip callback for img Shortcode.
*/
function shortcode_basic_tags_shortcode_img_tip($format, $long) {
$output = array();
$output[] = '<p><strong>' . t('[img src="image.jpg" (class="additional class"|alt="alt text")/]') . '</strong> ';
$output[] = t('Inserts an image based on the given image url.') . '</p>';
return implode(' ', $output);
}
/**
* Attributes form element for item Shortcode.
*
* Used by shortcode_wysiwyg module to add form elements for attributes.
*/
function shortcode_basic_tags_item_attributes($form, &$form_state) {
$form['item-class'] = array(
'#title' => t('Class'),
'#type' => 'textfield',
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array(
'value' => 'item',
),
),
),
);
$form['item-style'] = array(
'#title' => t('Style'),
'#type' => 'textfield',
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array(
'value' => 'item',
),
),
),
);
$form['item-id'] = array(
'#title' => t('ID'),
'#type' => 'textfield',
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array(
'value' => 'item',
),
),
),
);
$form['item-type'] = array(
'#title' => t('type'),
'#type' => 'select',
'#options' => array(
'd' => 'div',
's' => 'span',
),
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array(
'value' => 'item',
),
),
),
);
return $form;
}
/**
* Provides process callback for item ShortCode.
*/
function shortcode_basic_tags_shortcode_item($attrs, $text) {
$attrs = shortcode_attrs(array(
'class' => '',
'style' => '',
'id' => '',
'type' => 'div',
), $attrs);
switch ($attrs['type']) {
case 's':
case 'span':
$type = 'span';
break;
case 'd':
default:
$type = 'div';
break;
}
return theme('shortcode_item', array(
'text' => $text,
'id' => drupal_html_id($attrs['id']),
'class' => shortcode_add_class($attrs['class']),
'type' => $type,
'style' => $attrs['style'],
));
}
/**
* Provides tip callback for item ShortCode.
*/
function shortcode_basic_tags_shortcode_item_tip($format, $long) {
$output = array();
$output[] = '<p><strong>' . t('[item (class="additional class"|id=item id|type=div,d,span,s)]text[/item]') . '</strong> ';
if ($long) {
$output[] = t('Inserts an html item (type parameter = div or span) around the given text.') . '</p>';
$output[] = '<p>' . t('Additional class names can be added by the <em>class</em> parameter. The id parameter gives the html an unique css id.') . '</p>';
$output[] = '<p> </p>';
}
else {
$output[] = t('Inserts an html item (div or span) around the given text.') . '</p>';
}
return implode(' ', $output);
}
/**
* Implements theme for item ShortCode.
*/
function theme_shortcode_item($vars) {
$id = empty($vars['id']) ? '' : ' id="' . $vars['id'] . '"';
$class = empty($vars['class']) ? '' : ' class="' . $vars['class'] . '"';
$style = empty($vars['style']) ? '' : ' style="' . $vars['style'] . '"';
return '<' . $vars['type'] . $id . $class . $style . '>' . $vars['text'] . '</' . $vars['type'] . '>';
}
/**
* Attributes form element for clear ShortCode.
*
* Used by shortcode_wysiwyg module to add form elements for attributes.
*/
function shortcode_basic_tags_clear_attributes($form, &$form_state) {
$form['clear-class'] = array(
'#title' => t('Class'),
'#type' => 'textfield',
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array(
'value' => 'clear',
),
),
),
);
$form['clear-style'] = array(
'#title' => t('Style'),
'#type' => 'textfield',
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array(
'value' => 'clear',
),
),
),
);
$form['clear-id'] = array(
'#title' => t('ID'),
'#type' => 'textfield',
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array(
'value' => 'clear',
),
),
),
);
$form['clear-type'] = array(
'#title' => t('type'),
'#type' => 'select',
'#options' => array(
'd' => 'div',
's' => 'span',
),
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array(
'value' => 'clear',
),
),
),
);
return $form;
}
/**
* Provides process callback for clear ShortCode.
*/
function shortcode_basic_tags_shortcode_clear($attrs, $text) {
$attrs = shortcode_attrs(array(
'class' => '',
'style' => '',
'id' => '',
'type' => 'div',
), $attrs);
$class = shortcode_add_class($attrs['class'], 'clearfix');
switch ($attrs['type']) {
case 's':
case 'span':
$type = 'span';
break;
case 'd':
default:
$type = 'div';
break;
}
return theme('shortcode_clear', array(
'text' => check_plain($text),
'id' => drupal_html_id($attrs['id']),
'class' => $class,
'type' => $type,
'style' => check_plain($attrs['style']),
));
}
/**
* Provides tip callback for clear Shortcode.
*/
function shortcode_basic_tags_shortcode_clear_tip($format, $long) {
$output = array();
$output[] = '<p><strong>' . t('[clear (class="additional class"|id=item id|type=div,d,span,s)]text[/clear]') . '</strong>';
if ($long) {
$output[] = t('Inserts a float-clearing html item (type parameter = div or span) around the given text. Use the simple [clear /].') . '</p>';
$output[] = '<p>' . t('Additional class names can be added by the <em>class</em> parameter. The id parameter gives the html an unique css id.') . '</p>';
$output[] = '<p> </p>';
}
else {
$output[] = t('Inserts a float-clearing html item (div or span) around the given text. Use the simple [clear /].') . '</p>';
}
return implode(' ', $output);
}
/**
* Provides theme for clear Shortcode.
*/
function theme_shortcode_clear($vars) {
$id = empty($vars['id']) ? '' : ' id="' . $vars['id'] . '"';
$class = empty($vars['class']) ? '' : ' class="' . $vars['class'] . '"';
$style = empty($vars['style']) ? '' : ' style="' . $vars['style'] . '"';
return '<' . $vars['type'] . $id . $class . $style . '>' . $vars['text'] . '</' . $vars['type'] . '>';
}
/**
* Attributes form element for link shortcode.
*
* Used by shortcode_wysiwyg module to add form elements for attributes.
*/
function shortcode_basic_tags_link_attributes($form, &$form_state) {
$form['link-title'] = array(
'#title' => t('Title'),
'#type' => 'textfield',
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array(
'value' => 'link',
),
),
),
);
$form['link-path'] = array(
'#title' => t('Path'),
'#type' => 'textfield',
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array(
'value' => 'link',
),
),
),
);
$form['link-class'] = array(
'#title' => t('Class'),
'#type' => 'textfield',
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array(
'value' => 'link',
),
),
),
);
return $form;
}
/**
* Provides process callback for link ShortCode.
*
* @param array $attributes
* Optional.
* - title = the title of the link. Can be disabled by <none>. If empty the
* text will be used.
* - class = CSS classes separated by spaces
* - style = CSS styles
* - id – DOM id of the link.
* URL parameters:
* - path = the path of the link. Will be formatted by the url(). Default is
* the <front> link.
* - html – Enable HTML of the link text.
* - absolute — The link can be absolute or relative (default).
* - fragment - The url fragment.
* - alias — Flag for aliased URL (TRUE).
* @param string $text
* The linked text (optional).
*
* @return string
* The path string.
*/
function shortcode_basic_tags_shortcode_link($attributes, $text) {
// Used attributes by this macro.
$attributes = shortcode_attrs(array(
'path' => '<front>',
'title' => '',
'class' => '',
'style' => '',
'id' => '',
'html' => FALSE,
'absolute' => FALSE,
'fragment' => '',
'alias' => TRUE,
), $attributes);
$options = array(
'attributes' => array(),
);
$options['html'] = shortcode_bool($attributes['html']);
$options['absolute'] = shortcode_bool($attributes['absolute']);
$options['alias'] = shortcode_bool($attributes['alias']);
if ($attributes['fragment']) {
$options['fragment'] = check_plain($attributes['fragment']);
}
if ($text) {
if ($attributes['class']) {
$classes = shortcode_add_class($attributes['class']);
$options['attributes']['class'] = (array) $classes;
}
if ($attributes['style']) {
$options['attributes']['style'] = check_plain($attributes['style']);
}
if ($attributes['id']) {
$options['attributes']['id'] = check_plain($attributes['id']);
}
if ($attributes['title'] == '<none>') {
unset($options['attributes']['title']);
}
else {
$title = empty($attributes['title']) ? $text : $attributes['title'];
$options['attributes']['title'] = $title;
}
return l($text, $attributes['path'], $options);
}
// Return only the URL.
$path = check_plain(url($attributes['path'], $options));
return $path;
}
/**
* Provides tip callback for link Shortcode.
*/
function shortcode_basic_tags_shortcode_link_tip($format, $long) {
$output = array();
$output[] = '<p><strong>' . t('[link path="the Drupal path"]link text[/link]') . '</strong>';
$output[] = t('Inserts aliased Drupal path around the link text.');
if ($long) {
$output[] = '<p>';
$output[] = t('If you omit the text and the closing [/link] tag, you get back the URL only.') . '</p>';
$output[] = t('Additional parameters for the link:
<ul>
<li><em>title</em> for link title. Default value is the link text. Use <none> to disable.</li>
<li><em>class</em> for CSS classes.</li>
<li><em>style</em> for additional CSS rules.</li>
<li><em>id</em> for unique HTML id. (No need to use # sign.)</li>
</ul>
Parameters for the URL:
<ul>
<li><em>html</em> If true, enables HTML in the text. Default is false.</li>
<li><em>absolute</em> Provides absolute URL if true. Default is false.</li>
<li><em>fragment</em> The fragment of the URL.</li>
<li><em>alias</em> If false, it disables aliased URL. Default is true.</li>
</ul>
Samples:
<ul>
<li>Simple link with title: [link path="node/5" title="My little title"]link text[/link]</li>
<li>Link with class, style, no title: [link path="node/5" title="<none>" class="button my-button" style="text-transform: uppercase;" id="my-button"]button text[/link]</li>
<li>Absolute path with fragment: [link path="node/6" absolute="true" fragment="jump-to-content" /]</li>
</ul>
');
$output[] = '</p>';
$output[] = '<p> </p>';
}
return implode(' ', $output);
}
/**
* Attributes form element for random Shortcode.
*
* Used by shortcode_wysiwyg module to add form elements for attributes.
*/
function shortcode_basic_tags_random_attributes($form, &$form_state) {
$form['random-length'] = array(
'#title' => t('Length'),
'#type' => 'textfield',
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array(
'value' => 'random',
),
),
),
);
return $form;
}
/**
* Generates a random code.
*
* Calling
* [random length=X /]
*
* Where X is the length of the random text.
* If the length empty or invalid, between 1-99, the length will be 8.
*/
function shortcode_basic_tags_shortcode_random($attrs, $text) {
$attrs = shortcode_attrs(array(
'length' => 8,
), $attrs);
$length = intval($attrs['length']);
if ($length < 0 || $length > 99) {
$length = 8;
}
$text = '';
for ($i = 0; $i < $length; ++$i) {
$text .= chr(rand(32, 126));
}
return $text;
}
/**
* Provides tip callback for random Shortcode.
*/
function shortcode_basic_tags_shortcode_random_tip($format, $long) {
$output = array();
$output[] = '<p><strong>[random (length="8") /]</strong>';
if ($long) {
$output[] = t('Inserts a random text with the given length.') . '</p>';
$output[] = '<p> </p>';
}
else {
$output[] = t('Inserts a random text with the given length.') . '</p>';
}
return implode(' ', $output);
}
Functions
Name | Description |
---|---|
shortcode_basic_tags_button_attributes | Attributes form element for button Shortcode. |
shortcode_basic_tags_clear_attributes | Attributes form element for clear ShortCode. |
shortcode_basic_tags_dropcap_attributes | Attributes form element for dropcap shortcode. |
shortcode_basic_tags_highlight_attributes | Attributes form element for highlight shortcode. |
shortcode_basic_tags_img_attributes | Attributes form element for quote shortcode. |
shortcode_basic_tags_item_attributes | Attributes form element for item Shortcode. |
shortcode_basic_tags_link_attributes | Attributes form element for link shortcode. |
shortcode_basic_tags_quote_attributes | Attributes form element for quote shortcode. |
shortcode_basic_tags_random_attributes | Attributes form element for random Shortcode. |
shortcode_basic_tags_shortcode_button | Provides process callback for Shortcode button. |
shortcode_basic_tags_shortcode_button_tip | Provides tip callback for button Shortcode. |
shortcode_basic_tags_shortcode_clear | Provides process callback for clear ShortCode. |
shortcode_basic_tags_shortcode_clear_tip | Provides tip callback for clear Shortcode. |
shortcode_basic_tags_shortcode_dropcap | Provides process callback for dropcap Shortcode. |
shortcode_basic_tags_shortcode_dropcap_tip | Provides tip callback for dropcap Shortcode. |
shortcode_basic_tags_shortcode_highlight | Inserts a span with highlight css class around the text. |
shortcode_basic_tags_shortcode_highlight_tip | Provides tip callback for highlight Shortcode. |
shortcode_basic_tags_shortcode_img | Provides process callback for img Shortcode. |
shortcode_basic_tags_shortcode_img_tip | Provides tip callback for img Shortcode. |
shortcode_basic_tags_shortcode_info | Implements hook_shortcode_info(). |
shortcode_basic_tags_shortcode_item | Provides process callback for item ShortCode. |
shortcode_basic_tags_shortcode_item_tip | Provides tip callback for item ShortCode. |
shortcode_basic_tags_shortcode_link | Provides process callback for link ShortCode. |
shortcode_basic_tags_shortcode_link_tip | Provides tip callback for link Shortcode. |
shortcode_basic_tags_shortcode_quote | Provides process callback for quote Shortcode. |
shortcode_basic_tags_shortcode_quote_tip | Provides tip callback for quote Shortcode. |
shortcode_basic_tags_shortcode_random | Generates a random code. |
shortcode_basic_tags_shortcode_random_tip | Provides tip callback for random Shortcode. |
shortcode_basic_tags_theme | Implements hook_theme(). |
theme_shortcode_button | Implements theme for button Shortcode. |
theme_shortcode_clear | Provides theme for clear Shortcode. |
theme_shortcode_dropcap | Provides theme for dropcap Shortcode. |
theme_shortcode_img | Provides theme for img Shortcode. |
theme_shortcode_item | Implements theme for item ShortCode. |
theme_shortcode_quote | Provides theme for blockquote. |