| 1 |
<?php
|
| 2 |
// $Id: texy.module,v 1.9.2.5 2009/04/24 11:46:02 havran Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Filters an easy to read Texy! syntax into XHTML.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Implementation of hook_help().
|
| 11 |
*/
|
| 12 |
function texy_help($path, $arg) {
|
| 13 |
switch ($path) {
|
| 14 |
case 'admin/help#texy':
|
| 15 |
$output = '<p>'. t('Texy! allows you to enter content using an easy to read Texy syntax which is filtered into structurally valid XHTML. No knowledge of HTML is required.') .'</p>';
|
| 16 |
$output .= '<p>'. t('Texy! is one of the most complex formatting tools. It allows adding of images, links, nested lists, tables and has full support for CSS. Usage examples can be found at <a href="@texy">the Texy homepage</a>.', array('@texy' => 'http://texy.info/en')) .'</p>';
|
| 17 |
return $output;
|
| 18 |
case 'admin/settings/texy':
|
| 19 |
return '<p>'. t('Below is a list of main settings for the Texy! module. You can enable extra Texy! functionality in Modules section...') .'</p>';
|
| 20 |
}
|
| 21 |
}
|
| 22 |
|
| 23 |
/**
|
| 24 |
* Implementation of hook_menu()
|
| 25 |
*/
|
| 26 |
function texy_menu() {
|
| 27 |
$items['admin/settings/texy'] = array(
|
| 28 |
'title' => 'Texy!',
|
| 29 |
'description' => 'Customize main Texy! filter settings.',
|
| 30 |
'page callback' => 'drupal_get_form',
|
| 31 |
'page arguments' => array('texy_form_main_settings'),
|
| 32 |
'access arguments' => array('administer site configuration'),
|
| 33 |
'file' => 'texy.admin.inc',
|
| 34 |
);
|
| 35 |
$items['admin/settings/texy/basic'] = array(
|
| 36 |
'title' => 'Basic',
|
| 37 |
'description' => 'Customize basic Texy! filter settings.',
|
| 38 |
'access arguments' => array('administer site configuration'),
|
| 39 |
'type' => MENU_DEFAULT_LOCAL_TASK,
|
| 40 |
'weight' => -10,
|
| 41 |
);
|
| 42 |
|
| 43 |
return $items;
|
| 44 |
}
|
| 45 |
|
| 46 |
/**
|
| 47 |
* Implementation of hook_theme()
|
| 48 |
*/
|
| 49 |
function texy_theme() {
|
| 50 |
return array(
|
| 51 |
'texy_form_main_settings' => array(
|
| 52 |
'arguments' => array('form' => NULL),
|
| 53 |
),
|
| 54 |
);
|
| 55 |
}
|
| 56 |
|
| 57 |
/**
|
| 58 |
* Implementation of hook_filter()
|
| 59 |
*/
|
| 60 |
function texy_filter($op, $delta = 0, $format = -1, $text = '') {
|
| 61 |
switch ($op) {
|
| 62 |
case 'list':
|
| 63 |
return array(0 => t('Texy! filter'));
|
| 64 |
case 'description':
|
| 65 |
return t('Filters an easy to read Texy! syntax into XHTML.');
|
| 66 |
case 'process':
|
| 67 |
return _filter_texy($text);
|
| 68 |
default:
|
| 69 |
return $text;
|
| 70 |
}
|
| 71 |
}
|
| 72 |
|
| 73 |
/**
|
| 74 |
* Implementation of hook_filter_tips().
|
| 75 |
*/
|
| 76 |
function texy_filter_tips($delta, $format, $long = false) {
|
| 77 |
if ($delta == 0) {
|
| 78 |
switch ($long) {
|
| 79 |
case 0:
|
| 80 |
return t('You can use <a href="http://texy.info/en">Texy!</a> to format and alter entered content.');
|
| 81 |
case 1:
|
| 82 |
$output = t('
|
| 83 |
<p>This site uses <a href="http://texy.info">Texy!</a> to format and alter entered content. Texy! provides an intuitive and easy to read syntax which is automatically filtered into XHTML upon content submission.</p>
|
| 84 |
<dl>
|
| 85 |
<dt>Paragraphs and line breaks</dt>
|
| 86 |
<dd>Just add two line breaks to create a paragraph. Put a space at the start of a new line to preserve a line break.</dd>
|
| 87 |
<dt>Emphasized</dt>
|
| 88 |
<dd>*Emphasized*</dd>
|
| 89 |
<dd><em>Emphasized</em></dd>
|
| 90 |
<dt>Strong</dt>
|
| 91 |
<dd>**Strong**</dd>
|
| 92 |
<dd><strong>Strong</strong></dd>
|
| 93 |
<dt>Hyperlink</dt>
|
| 94 |
<dd>"Hyperlink":http://drupal.org</dd>
|
| 95 |
<dd><a href="http://drupal.org">Hyperlink</a></dd>
|
| 96 |
<dt>Block quoted</dt>
|
| 97 |
<dd>> Block quoted</dd>
|
| 98 |
<dd><blockquote><p>Block quoted</p></blockquote></dd>
|
| 99 |
<dt>Quoted inline</dt>
|
| 100 |
<dd>>>Quoted inline<<</dd>
|
| 101 |
<dd><q>Quoted inline</q></dd>
|
| 102 |
<dt>Acronym</dt>
|
| 103 |
<dd>"SLA"((Some Lengthy Acronym))</dd>
|
| 104 |
<dd><acronym title="Some Lengthy Acronym">SLA</acronym></dd>
|
| 105 |
<dt>Source code</dt>
|
| 106 |
<dd>/---code html<br /><em>Texy!</em><br />\---code</dd>
|
| 107 |
<dd><pre><code><em>Texy!</em></code></pre></dd>
|
| 108 |
<dt>Unordered list</dt>
|
| 109 |
<dd>- First item<br />- Second item</dd>
|
| 110 |
<dd><ul> <li>First item</li> <li>Second item</li> </ul></dd>
|
| 111 |
<dt>Ordered list</dt>
|
| 112 |
<dd>1) First item<br />2) Second item</dd>
|
| 113 |
<dd><ol> <li>First item</li> <li>Second item</li> </ol></dd>
|
| 114 |
<dt>Subscripted</dt>
|
| 115 |
<dd>Sub_scripted</dd>
|
| 116 |
<dd>Sub<sub>scripted</sub></dd>
|
| 117 |
<dt>Superscripted</dt>
|
| 118 |
<dd>Super^scripted</dd>
|
| 119 |
<dd>Super<sup>scripted</sup></dd>
|
| 120 |
</dl>
|
| 121 |
<p>More information can be found at <a href="http://texy.info">the official Texy! page</a>.</p>
|
| 122 |
');
|
| 123 |
return $output;
|
| 124 |
}
|
| 125 |
}
|
| 126 |
}
|
| 127 |
|
| 128 |
/**
|
| 129 |
* Implementation of hook_texy_settings()
|
| 130 |
*
|
| 131 |
* For main Texy! settings
|
| 132 |
*/
|
| 133 |
function texy_texy_settings(&$texy) {
|
| 134 |
// start headings from h3
|
| 135 |
$texy->headingModule->top = variable_get('texy_heading_base', 3);
|
| 136 |
|
| 137 |
$_linewrap = variable_get('texy_line_wrap', '');
|
| 138 |
if (empty($_linewrap)) {
|
| 139 |
// do not wrap
|
| 140 |
$texy->cleaner->lineWrap = FALSE;
|
| 141 |
} else {
|
| 142 |
// wrap lines
|
| 143 |
$texy->cleaner->lineWrap = $_linewrap;
|
| 144 |
}
|
| 145 |
|
| 146 |
// break long words with insert ­ or not
|
| 147 |
$texy->allowed['longwords'] = variable_get('texy_allowed_longwords', FALSE);
|
| 148 |
// and set max word lenght which is not break
|
| 149 |
$texy->longWordsModule->wordLimit = variable_get('texy_word_limit', 20);
|
| 150 |
// obfuscate email addresses or not
|
| 151 |
$texy->obfuscateEmail = variable_get('texy_obfuscate_email', FALSE);
|
| 152 |
// force insert "nofollow" in links or not
|
| 153 |
$texy->linkModule->forceNoFollow = variable_get('texy_force_nofollow', FALSE);
|
| 154 |
// set typographic convention
|
| 155 |
$texy->typographyModule->locale = variable_get('texy_locale', 'en');
|
| 156 |
|
| 157 |
$_allowedclasses = variable_get('texy_allowed_classes', '');
|
| 158 |
if ($_allowedclasses == '<all>') {
|
| 159 |
// permit all classes
|
| 160 |
$texy->allowedClasses = TRUE;
|
| 161 |
} else if (empty($_allowedclasses)) {
|
| 162 |
// permit no classes
|
| 163 |
$texy->allowedClasses = FALSE;
|
| 164 |
} else {
|
| 165 |
// permit only specified classes
|
| 166 |
$texy->allowedClasses = preg_split('/,/', str_replace(' ', '', $_allowedclasses));
|
| 167 |
}
|
| 168 |
|
| 169 |
$_allowedstyles = variable_get('texy_allowed_styles', '');
|
| 170 |
if ($_allowedstyles == '<all>') {
|
| 171 |
// permit all styles
|
| 172 |
$texy->allowedStyles = TRUE;
|
| 173 |
} else if (empty($_allowedstyles)) {
|
| 174 |
// permit no styles
|
| 175 |
$texy->allowedStyles = FALSE;
|
| 176 |
} else {
|
| 177 |
// permit only specified styles
|
| 178 |
$texy->allowedStyles = preg_split('/,/', str_replace(' ', '', $_allowedstyles));
|
| 179 |
}
|
| 180 |
|
| 181 |
$_allowedtags = variable_get('texy_allowed_tags', '');
|
| 182 |
if ($_allowedtags == '<all>') {
|
| 183 |
// permit all tags
|
| 184 |
$texy->allowedTags = TRUE;
|
| 185 |
} else if (empty($_allowedtags)) {
|
| 186 |
// permit no tags
|
| 187 |
$texy->allowedTags = FALSE;
|
| 188 |
} else {
|
| 189 |
// permit only specified tags - with all attributes
|
| 190 |
$texy->allowedTags = array();
|
| 191 |
foreach (preg_split('/,/', str_replace(' ', '', $_allowedtags)) as $_tag) {
|
| 192 |
$texy->allowedTags[$_tag] = TRUE;
|
| 193 |
}
|
| 194 |
}
|
| 195 |
|
| 196 |
}
|
| 197 |
|
| 198 |
|
| 199 |
/**
|
| 200 |
* Main Texy! filter.
|
| 201 |
*/
|
| 202 |
function _filter_texy($text) {
|
| 203 |
$texy =& _texy_get_object();
|
| 204 |
|
| 205 |
if ($texy) {
|
| 206 |
$texy->encoding = 'utf-8'; // always UTF-8 for Drupal
|
| 207 |
|
| 208 |
// here we invoke all hook_texy_handler and set handlers for modify Texy!
|
| 209 |
// output
|
| 210 |
module_invoke_all('texy_handler', $texy);
|
| 211 |
|
| 212 |
// here we invoke all hook_texy_settings and set other Texy! modules s
|
| 213 |
// specific settings
|
| 214 |
module_invoke_all('texy_settings', $texy);
|
| 215 |
|
| 216 |
// main Texy! filter processing
|
| 217 |
$html = $texy->process($text);
|
| 218 |
|
| 219 |
return $html;
|
| 220 |
}
|
| 221 |
|
| 222 |
return $text;
|
| 223 |
}
|
| 224 |
|
| 225 |
/**
|
| 226 |
* Initialization of Texy! object
|
| 227 |
*/
|
| 228 |
function _texy_get_object($messages = FALSE) {
|
| 229 |
// get base module path
|
| 230 |
$module_path = drupal_get_path('module', 'texy');
|
| 231 |
// use PHP5?
|
| 232 |
$use_php5 = FALSE;
|
| 233 |
|
| 234 |
// check
|
| 235 |
if (version_compare('5.1.0', PHP_VERSION, '<=') && function_exists('iconv')) {
|
| 236 |
// for PHP5 (also requires iconv)
|
| 237 |
$use_php5 = TRUE;
|
| 238 |
}
|
| 239 |
else if (version_compare('5.1.0', PHP_VERSION, '<=') && !function_exists('iconv')) {
|
| 240 |
if ($message) drupal_set_message(t('You web site use PHP5 but without Iconv module. Texy filter module now use Texy! library for PHP4 which is now unsupported!'), 'warning');
|
| 241 |
}
|
| 242 |
else if (version_compare('5.0.0', PHP_VERSION, '<=') && version_compare('5.1.0', PHP_VERSION, '>')) {
|
| 243 |
if ($message) drupal_set_message(t('You web site use PHP5 but version older than PHP 5.1.0. Texy filter module now use Texy! library for PHP4 which is now unsupported!'), 'warning');
|
| 244 |
}
|
| 245 |
else {
|
| 246 |
if ($message) drupal_set_message(t('You web site use PHP4. Texy filter module now use Texy! library for PHP4 which is now unsupported!'), 'warning');
|
| 247 |
}
|
| 248 |
|
| 249 |
// include proper version of Texy! library
|
| 250 |
if ($use_php5) {
|
| 251 |
// for PHP5
|
| 252 |
require_once $module_path . '/texy/texy.compact.5.php';
|
| 253 |
}
|
| 254 |
else {
|
| 255 |
// for PHP4
|
| 256 |
require_once $module_path . '/texy/texy.compact.4.php';
|
| 257 |
}
|
| 258 |
|
| 259 |
// create new Texy! object
|
| 260 |
$texy = new Texy;
|
| 261 |
|
| 262 |
return $texy;
|
| 263 |
}
|