spoiler.module in Spoiler 5
Same filename and directory in other branches
Spoiler module: This module allows users to hide potential "spoiler" content by inserting them between [spoiler][/spoiler] tags. These tags will be converted to HTML by this filter and the relevant CSS rules will set the foreground and background colours to the same value, thereby rendering the text invisible until highlighted.
File
spoiler.moduleView source
<?php
/**
* @file
* Spoiler module: This module allows users to hide potential "spoiler"
* content by inserting them between [spoiler][/spoiler] tags. These tags will
* be converted to HTML by this filter and the relevant CSS rules will set the
* foreground and background colours to the same value, thereby rendering the
* text invisible until highlighted.
*/
/**
* Implementation of hook_menu().
*/
function spoiler_menu($may_cache) {
if (!$may_cache) {
// Include spoiler.css.
drupal_add_css(drupal_get_path('module', 'spoiler') . '/spoiler.css');
}
return array();
}
/**
* Implementation of hook_filter().
*/
function spoiler_filter($op, $delta = 0, $format = -1, $text = '') {
switch ($op) {
case 'list':
return array(
0 => t('Spoiler filter'),
);
case 'description':
return t('Converts [spoiler][/spoiler] tags into HTML and sets the foreground and background colours to the same value, effectively rendering the content within invisible.');
case 'process':
return _spoiler_filter_process($text);
default:
return $text;
}
}
/**
* Implementation of hook_filter_tips().
*/
function spoiler_filter_tips($delta, $format, $long = FALSE) {
return t('<p>Spoilers can be placed between [spoiler][/spoiler] tags in order to be masked using CSS. Users will need to highlight the text to read content.');
}
/**
* Replace [spoiler] tags with markup.
*
* @param $text
* The text with the [spoiler] tags that need to be replaced with HTML tags.
*
* @return $text
* Filtered text.
*/
function _spoiler_filter_process($text) {
// Keep it simple. Use of the lazy quantifier allows use of multiple spoiler
// blocks but does not address nested spoilers.
return preg_replace('#\\[\\s*spoiler\\s*\\](.*?)\\[\\s*/\\s*spoiler\\s*\\]#is', t('<div class="spoiler"><div class="spoiler-warning"><span>Spoiler:</span> Highlight to view</div><div class="spoiler-content">$1</div></div>'), $text);
}
Functions
Name![]() |
Description |
---|---|
spoiler_filter | Implementation of hook_filter(). |
spoiler_filter_tips | Implementation of hook_filter_tips(). |
spoiler_menu | Implementation of hook_menu(). |
_spoiler_filter_process | Replace [spoiler] tags with markup. |