| 1 |
<?php
|
| 2 |
// $Id: smartypants.module,v 1.6.2.1 2007/02/15 17:39:56 jhriggs Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* The smartypants filter module uses SmartyPants-PHP
|
| 6 |
* (http://monauraljerk.org/smartypants-php/) to translate plain ASCII
|
| 7 |
* punctuation characters into "smart" typographic punctuation HTML
|
| 8 |
* entities.
|
| 9 |
*
|
| 10 |
* @version $Id: smartypants.module,v 1.6.2.1 2007/02/15 17:39:56 jhriggs Exp $
|
| 11 |
* @copyright Copyright (c) 2003-2007 Jim Riggs. All rights reserved.
|
| 12 |
* @author Jim Riggs <drupal at jimandlissa dot com>
|
| 13 |
*/
|
| 14 |
|
| 15 |
/********************************************************************
|
| 16 |
* Drupal Hooks
|
| 17 |
********************************************************************/
|
| 18 |
|
| 19 |
/**
|
| 20 |
* Implementation of hook_filter().
|
| 21 |
*/
|
| 22 |
function smartypants_filter($op, $delta = 0, $format = -1, $text = '') {
|
| 23 |
switch ($op) {
|
| 24 |
case 'list':
|
| 25 |
return array(t("SmartyPants"));
|
| 26 |
|
| 27 |
case 'description':
|
| 28 |
return t('Translates plain ASCII punctuation characters into “smart” typographic punctuation HTML entities.');
|
| 29 |
|
| 30 |
case 'settings':
|
| 31 |
require_once(dirname(__FILE__) . '/smartypants-php/SmartyPants-PHP.inc');
|
| 32 |
|
| 33 |
$form = array();
|
| 34 |
$form['smartypants'] = array(
|
| 35 |
'#type' => 'fieldset',
|
| 36 |
'#title' => t('SmartyPants filter'),
|
| 37 |
'#collapsible' => TRUE
|
| 38 |
);
|
| 39 |
$form['smartypants']['smartypants_dashes'] = array(
|
| 40 |
'#type' => 'fieldset',
|
| 41 |
'#title' => t('Dash conversion'),
|
| 42 |
'#collapsible' => TRUE
|
| 43 |
);
|
| 44 |
$form['smartypants']['smartypants_dashes']["smartypants_dashes_$format"] = array(
|
| 45 |
'#type' => 'radios',
|
| 46 |
'#default_value' => variable_get("smartypants_dashes_$format", DO_DASHES),
|
| 47 |
'#options' => array(
|
| 48 |
0 => t('None'),
|
| 49 |
DO_DASHES => t('Convert -- to em-dash (—)'),
|
| 50 |
DO_OLDSCHOOL_DASHES => t('Convert -- to en-dash (–) and --- to em-dash (—)'),
|
| 51 |
DO_INVERTED_OLDSCHOOL_DASHES => t('Convert -- to em-dash (—) and --- to en-dash (–)'))
|
| 52 |
);
|
| 53 |
$form['smartypants']['smartypants_backticks'] = array(
|
| 54 |
'#type' => 'fieldset',
|
| 55 |
'#title' => t('Backtick conversion'),
|
| 56 |
'#collapsible' => TRUE
|
| 57 |
);
|
| 58 |
$form['smartypants']['smartypants_backticks']["smartypants_backticks_$format"] = array(
|
| 59 |
'#type' => 'radios',
|
| 60 |
'#default_value' => variable_get("smartypants_backticks_$format", DO_BACKTICKS_DOUBLE),
|
| 61 |
'#options' => array(
|
| 62 |
0 => t('None'),
|
| 63 |
DO_BACKTICKS_DOUBLE => t('Convert ``text\'\' to “text”'),
|
| 64 |
DO_BACKTICKS_ALL => t('Convert ``text\'\' to “text” and `text\' to ‘text’'))
|
| 65 |
);
|
| 66 |
$form['smartypants']["smartypants_ellipses_$format"] = array(
|
| 67 |
'#type' => 'checkbox',
|
| 68 |
'#title' => t('Convert ellipses'),
|
| 69 |
'#default_value' => variable_get("smartypants_ellipses_$format", DO_ELLIPSES),
|
| 70 |
'#return_value' => DO_ELLIPSES,
|
| 71 |
'#description' => t('Converts ... and . . . to ellipses (…).')
|
| 72 |
);
|
| 73 |
$form['smartypants']["smartypants_quotes_$format"] = array(
|
| 74 |
'#type' => 'checkbox',
|
| 75 |
'#title' => t('Convert quotation marks'),
|
| 76 |
'#default_value' => variable_get("smartypants_quotes_$format", DO_QUOTES),
|
| 77 |
'#return_value' => DO_QUOTES,
|
| 78 |
'#description' => t('Converts "text" to “text” and \'text\' to ‘text’.')
|
| 79 |
);
|
| 80 |
|
| 81 |
return $form;
|
| 82 |
|
| 83 |
case 'process':
|
| 84 |
require_once(dirname(__FILE__) . '/smartypants-php/SmartyPants-PHP.inc');
|
| 85 |
|
| 86 |
static $settings = array();
|
| 87 |
|
| 88 |
if (!isset($settings[$format])) {
|
| 89 |
$settings[$format] = (
|
| 90 |
intval(variable_get("smartypants_quotes_$format", DO_QUOTES))
|
| 91 |
| intval(variable_get("smartypants_backticks_$format", DO_BACKTICKS_DOUBLE))
|
| 92 |
| intval(variable_get("smartypants_dashes_$format", DO_DASHES))
|
| 93 |
| intval(variable_get("smartypants_ellipses_$format", DO_ELLIPSES))
|
| 94 |
);
|
| 95 |
}
|
| 96 |
|
| 97 |
return SmartyPants($text, $settings[$format]);
|
| 98 |
|
| 99 |
default:
|
| 100 |
return $text;
|
| 101 |
}
|
| 102 |
}
|
| 103 |
|
| 104 |
/**
|
| 105 |
* Implementation of hook_filter_tips().
|
| 106 |
*/
|
| 107 |
function smartypants_filter_tips($delta, $format, $long = FALSE) {
|
| 108 |
if ($long) {
|
| 109 |
return t('
|
| 110 |
<h1>Smartypants Help</h1>
|
| 111 |
|
| 112 |
<p>
|
| 113 |
SmartyPants will translate plain ASCII punctuation characters into
|
| 114 |
“smart” typographic punctuation HTML entities. It performs the
|
| 115 |
following transformations:
|
| 116 |
</p>
|
| 117 |
|
| 118 |
<ul>
|
| 119 |
<li>Straight quotes ( " and ' ) into “curly”
|
| 120 |
quote HTML entities</li>
|
| 121 |
<li>Backticks-style quotes (``like this\'\') into “curly”
|
| 122 |
quote HTML entities</li>
|
| 123 |
<li>Dashes (“--” and “---”) into en- and
|
| 124 |
em-dash entities</li>
|
| 125 |
<li>Three consecutive dots (“...”) into an ellipsis
|
| 126 |
entity</li>
|
| 127 |
</ul>
|
| 128 |
');
|
| 129 |
}
|
| 130 |
else {
|
| 131 |
return t('SmartyPants will translate ASCII punctuation characters into “smart” typographic punctuation HTML entities.');
|
| 132 |
}
|
| 133 |
}
|
| 134 |
|
| 135 |
/**
|
| 136 |
* Implementation of hook_help().
|
| 137 |
*/
|
| 138 |
function smartypants_help($section = 'admin/help#smartypants') {
|
| 139 |
switch ($section) {
|
| 140 |
case 'admin/help#smartypants':
|
| 141 |
return smartypants_filter_tips(NULL, NULL, TRUE);
|
| 142 |
}
|
| 143 |
}
|
| 144 |
|
| 145 |
?>
|