array('value' => 0, 'flags' => VARS_DYNAMIC), ); } } /** * Implements hook_filter(). */ function textile_filter($op, $delta = 0, $format = -1, $text = '', $cache_id = 0) { switch ($op) { case 'list': return array(t("Textile")); case 'description': return t('Allows content to be submitted using Textile, a simple, plain text syntax that is filtered into valid XHTML.'); case 'process': return _textile_process($text, $format); case 'settings': return _textile_settings($format); default: return $text; } } /** * Implements hook_filter_tips(). */ function textile_filter_tips($delta, $format, $long = FALSE) { $vars = new TextileVars(); if ($long) { module_load_include('inc', 'textile', 'textile.tips'); return _textile_filter_long_tips(); } elseif ($vars["textile_tags_$format"]) { 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.'); } } /** * 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.', array('@tips_url' => url('filter/tips'))) . '
'; } } /** * Retrivies where the Textile library has been copied. * * @return * The path of the Textile library. */ function textile_library_path() { $path = &Vars::staticValue(__FUNCTION__, ''); $vars = new Vars(); if ($path) { return $path; } $dirs = $vars->getLibraryPath('textile'); $dirs[] = drupal_get_path('module', 'textile') . '/include'; foreach ($dirs as $dir) { $bool = ( is_dir($dir) && file_exists("$dir/classTextile.php") && is_file("$dir/classTextile.php") ); if ($bool) { $path = $dir; break; } } // Allow third-party modules to alter the path where the library is found. drupal_alter('textile_library_path', $path); return $path; } /** * Textile filter. Provides filtering of Textile tags into XHTML. */ function _textile_process($text, $format) { $vars = new TextileVars(); if ($vars["textile_tags_$format"]) { return preg_replace_callback( '{\[textile\](.*?)(\[/textile\]|$)}is', '_textile_match_process', $text ); } else { return _textile_match_process(array(NULL, $text)); } } /** * Helper function for preg_replace_callback(). */ function _textile_match_process($matches) { static $textile = NULL; $path = textile_library_path(); if (empty($textile) && $path) { require_once './' . $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]); } /** * Settings callback for the Textile filter. */ function _textile_settings($format) { $form = array(); $vars = new TextileVars(); $form['textile_settings'] = array( '#type' => 'fieldset', '#title' => t('Textile filter'), '#collapsible' => TRUE ); $form['textile_settings']["textile_tags_$format"] = array( '#type' => 'checkbox', '#title' => t('Use tags'), '#default_value' => $vars["textile_tags_$format"], '#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 $form; }