Last active
February 11, 2019 08:23
-
-
Save typhonius/5046260 to your computer and use it in GitHub Desktop.
A filter format for applying greentext correctly to Drupal text. The snippet will provide any filter format with the ability to change any line starting with '>' into a greentext line. >Implying anyone will use it
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 | |
function greentext_filter_info() { | |
$filters['greentext'] = array( | |
'title' => t('Implying greentext'), | |
'description' => t('Allows you to alter any lines input starting with \'>\' to appear as greentext.'), | |
'process callback' => '_greentext_greentext', | |
'tips callback' => '_greentext_greentext_tips', | |
); | |
return $filters; | |
} | |
function _greentext_greentext($text, $filter) { | |
$lines = explode("\n", $text); | |
foreach ($lines as $index => $line) { | |
if (preg_match('/^>/', strip_tags($line), $matches)) { | |
$lines[$index] = theme('greentext', array('text' => $line)); | |
} | |
} | |
$text = implode("\n", $lines); | |
return $text; | |
} | |
function _greentext_greentext_tips($filter, $format, $long = FALSE) { | |
$output = t('Lines beginning with \'>\' will automatically be replaced with greentext'); | |
return $output; | |
} | |
function greentext_theme($existing, $type, $theme, $path) { | |
return array( | |
'greentext' => array( | |
'template' => 'greentext', | |
'variables' => array('text' => NULL), | |
), | |
); | |
} |
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 | |
// Put this in a CSS file and add class. | |
print '<span style="color:#789922">' . $text . '</span>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This can also be done with PHP's DOMDocument library. Code:
https://www.256kilobytes.com/content/show/4285/how-do-i-make-create-greentext-4chan-style-using-the-php-domdocument-library