View source
<?php
function typogrify_filter($op, $delta = 0, $format = -1, $text = '') {
switch ($op) {
case 'list':
return array(
t('Typogrify'),
);
case 'description':
return t('Adds typographic refinements.');
case 'settings':
return _typogrify_settings($format);
case 'process':
return _typogrify_process($text, $format);
default:
return $text;
}
}
function typogrify_filter_tips($delta = 0, $format = -1, $long) {
if ($long) {
$the_output = t('Typogrify.module brings the typographic refinements of Typogrify to Drupal.<ul>
<li>Wraps ampersands (the $ldquo;&” character) with <span class=\\"amp\\">&</span>.</li>
<li>Prevents single words from wrapping onto their own line using Shaun Inman\'s Widont technique.</li>
<li>Converts straight quotation marks to typographer\'s quotation marks, using SmartyPants.</li>
<li>Converts multiple hyphens to en dashes and em dashes (according to your preferences), using SmartyPants.</li>
<li>Wraps multiple capital letters with <span class=\\"caps\\">CAPS</span>.</li>
<li>Wraps initial quotation marks with <span class=\\"quo\\"></span> or <span class=\\"dquo\\"></span>.</li>
<li>Adds a css style sheet that uses the <span> tags to substitute a showy ampersand in headlines, switch caps to small caps, and hang initial quotation marks.</li></ul>');
}
else {
$the_output = t('Adds typographic refinements.');
}
return $the_output;
}
function typogrify_menu($may_cache) {
drupal_add_css(drupal_get_path('module', 'typogrify') . '/typogrify.css', 'module', 'all', TRUE);
}
function typogrify_help($in_section = 'admin/help#typogrify') {
switch ($in_section) {
case 'admin/settings/modules#description':
$the_output = t('Adds typographic refinements.');
break;
case 'admin/help#typogrify':
$the_output = t('Adds typographic refinements.');
break;
}
return $the_output;
}
function _typogrify_process($text, $format) {
require_once dirname(__FILE__) . '/typogrify.class.php';
require_once dirname(__FILE__) . '/unicode-conversion.php';
if (!function_exists('marksmarty_filter')) {
require_once dirname(__FILE__) . '/smartypants.php';
}
if (variable_get("typogrify_is_amp_on_{$format}", 1) == 1) {
$text = Typogrify::amp($text);
}
if (variable_get("typogrify_is_widont_on_{$format}", 1) == 1) {
$text = Typogrify::widont($text);
}
if (variable_get("marksmarty_is_smarty_on_{$format}", 1) == 1) {
global $smartypants_attr;
$smartypants_attr = variable_get("marksmarty_smarty_hyphens_{$format}", 1);
$text = SmartyPants($text);
}
if (variable_get("typogrify_is_caps_on_{$format}", 1) == 1) {
$text = Typogrify::caps($text);
}
if (variable_get("typogrify_is_initial_quotes_on_{$format}", 1) == 1) {
$text = Typogrify::initial_quotes($text);
}
global $ligature_map;
if (is_array($ligature_map) && count($ligature_map) > 0) {
foreach ($ligature_map as $pair => $ligature) {
$setting = 'typogrify_use_' . $pair . '_ligature_' . $format;
if (variable_get($setting, 0) == 1) {
$characters_to_convert[] = $pair;
}
}
}
global $arrow_map;
if (is_array($arrow_map) && count($arrow_map) > 0) {
foreach ($arrow_map as $ascii => $unicode) {
$setting = 'typogrify_use_unicode_for_' . $ascii . '_' . $format;
if (variable_get($setting, 0) == 1) {
$characters_to_convert[] = $ascii;
}
}
}
if (count($characters_to_convert) > 0) {
$text = convert_characters($text, $characters_to_convert);
}
return $text;
}
function _typogrify_settings($format) {
require_once dirname(__FILE__) . '/unicode-conversion.php';
$form['typogrify_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Typogrify'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['typogrify_settings']['help'] = array(
'#type' => 'markup',
'#value' => '<p>Enable the following typographic refinements:</p>',
);
if (!function_exists('marksmarty_filter')) {
$form['typogrify_settings']["marksmarty_is_smarty_on_{$format}"] = array(
'#type' => 'checkbox',
'#title' => t('Use typographers quotation marks and dashes (!smartylink)', array(
'!smartylink' => l('SmartyPants', 'http://daringfireball.net/projects/smartypants/'),
)),
'#default_value' => variable_get("marksmarty_is_smarty_on_{$format}", 1),
);
$form['typogrify_settings']["marksmarty_smarty_hyphens_{$format}"] = array(
'#type' => 'select',
'#title' => t('Hyphenation settings for SmartyPants'),
'#default_value' => variable_get("marksmarty_smarty_hyphens_{$format}", 3),
'#options' => array(
1 => t('"--" for em-dashes; no en-dash support'),
3 => t('"--" for em-dashes; "---" for en-dashes'),
2 => t('"---" for em-dashes; "--" for en-dashes'),
),
);
}
$form['typogrify_settings']["typogrify_is_amp_on_{$format}"] = array(
'#type' => 'checkbox',
'#title' => t('Wrap ampersands'),
'#default_value' => variable_get("typogrify_is_amp_on_{$format}", 1),
);
$form['typogrify_settings']["typogrify_is_widont_on_{$format}"] = array(
'#type' => 'checkbox',
'#title' => t('Remove widows'),
'#default_value' => variable_get("typogrify_is_widont_on_{$format}", 1),
);
$form['typogrify_settings']["typogrify_is_caps_on_{$format}"] = array(
'#type' => 'checkbox',
'#title' => t('Wrap caps'),
'#default_value' => variable_get("typogrify_is_caps_on_{$format}", 1),
);
$form['typogrify_settings']["typogrify_is_initial_quotes_on_{$format}"] = array(
'#type' => 'checkbox',
'#title' => t('Wrap quotation marks'),
'#default_value' => variable_get("typogrify_is_initial_quotes_on_{$format}", 1),
);
$form['typogrify_settings']['ligatures'] = array(
'#type' => 'fieldset',
'#title' => t('Ligatures'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
foreach ($ligature_map as $pair => $ligature) {
$setting = 'typogrify_use_' . $pair . '_ligature_' . $format;
$form['typogrify_settings']['ligatures'][$setting] = array(
'#type' => 'checkbox',
'#title' => t("Convert {$pair} to {$ligature}"),
'#default_value' => variable_get($setting, 0),
);
}
$form['typogrify_settings']['arrows'] = array(
'#type' => 'fieldset',
'#title' => t('Arrows'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
foreach ($arrow_map as $ascii => $unicode) {
$setting = 'typogrify_use_unicode_for_' . $ascii . '_' . $format;
$form['typogrify_settings']['arrows'][$setting] = array(
'#type' => 'checkbox',
'#title' => t("Convert {$ascii} to {$unicode}"),
'#default_value' => variable_get($setting, 0),
);
}
$version_strings = array();
$version_strings[] = t('SmartyPants PHP version: !version', array(
'!version' => l($GLOBALS['SmartyPantsPHPVersion'], 'http://www.michelf.com/projects/php-smartypants/'),
));
$version_strings[] = t('PHP Typogrify Version: !version', array(
'!version' => l('1.0', 'http://blog.hamstu.com/'),
));
$form['typogrify_settings']['info']['typogrify_status'] = array(
'#value' => theme('item_list', $version_strings, t('Version Information')),
);
return $form;
}