t('Textile'), 'description' => t('Allows content to be submitted using Textile, a simple, plain text syntax that is filtered into valid XHTML.'), 'process callback' => '_textile_process', 'settings callback' => '_textile_settings', 'default settings' => array( 'textile_tags' => FALSE, ), 'tips callback' => '_textile_filter_tips', ); return $filters; } /** * Implements hook_help(). */ function textile_help($path, $arg) { switch ($path) { case 'admin/help#textile': return '
' . t(' The Textile module allows users to enter content using Textile, a simple, plain text syntax that is filtered into valid XHTML. The filter tips page provides syntax descriptions and examples.') . '
'; } } /** * Retrivies where the Textile library has been copied. * * @return * The path of the Textile library. */ function textile_library_path() { $path = ''; $vars = new Vars(); foreach ($vars->getLibraryPath('textile', drupal_get_path('module', 'textile') . '/include') as $dir) { $bool = ( is_dir($dir) && file_exists("$dir/classTextile.php") && is_file("$dir/classTextile.php") ); if ($bool) { $path = $dir; } } // Allow third-party modules to alter the path where the library is found. drupal_alter('textile_library_path', $path); return $path; } /** * Filter tips callback for the Textile filter. */ function _textile_filter_tips($filter, $format, $long = FALSE) { if ($long) { module_load_include('inc', 'textile', 'textile.tips'); return _textile_filter_long_tips(); } elseif (isset($filter->settings['textile_tags']) && $filter->settings['textile_tags']) { return t('You can use Textile markup to format text between the [textile] and (optional) [/textile] tags.'); } else { return t('You can use Textile markup to format text.'); } } /** * Helper function for preg_replace_callback(). */ function _textile_match_process($matches) { $textile = &Vars::staticValue(__FUNCTION__, NULL); if (empty($textile)) { $path = textile_library_path(); if ($path) { require_once DRUPAL_ROOT . '/' . $path . 'classTextile.php'; $textile = new Textile(); // $textile->hu is the string that preceeds all relative URLs. $textile->hu = url(NULL); } } return $textile->TextileThis($matches[1]); } /** * Textile filter. Provides filtering of Textile tags into XHTML. */ function _textile_process($text, $filter, $format, $langcode, $cache, $cache_id) { if ($filter->settings['textile_tags']) { return preg_replace_callback('{\[textile\](.*?)(\[/textile\]|$)}is', '_textile_match_process', $text); } else { return _textile_match_process(array(NULL, $text)); } } /** * Settings callback for the Textile filter. */ function _textile_settings($form, &$form_state, $filter, $format, $defaults, $filters) { $settings = array(); $settings['textile_tags'] = array( '#type' => 'checkbox', '#title' => t('Use tags'), '#default_value' => isset($filter->settings['textile_tags']) ? $filter->settings['textile_tags'] : $defaults['textile_tags'], '#description' => t('If enabled, only text between [textile] and optional [/textile] tags will be processed; otherwise, all text will be processed as Textile markup.') ); return $settings; }