diff -rup flexifilter_orig/flexifilter.components.inc modules/flexifilter/flexifilter.components.inc --- flexifilter_orig/flexifilter.components.inc 2009-02-15 11:40:30.000000000 +0100 +++ modules/flexifilter/flexifilter.components.inc 2009-02-15 12:00:11.000000000 +0100 @@ -98,6 +98,13 @@ function flexifilter_flexifilter_compone 'contains_components' => TRUE, 'step' => 'either', ); + $components['flexifilter_link_component'] = array( + 'label' => t('Linkifier'), + 'description' => t('Creates links (<a href="link">title</a>).'), + 'callback' => 'flexifilter_component_linkifier', + 'group' => t('Text: Intermediate'), + 'step' => 'either', + ); // Advanced. $components['flexifilter_advanced_php'] = array( @@ -659,6 +666,157 @@ function flexifilter_component_advanced_ } /** + * Flexifilter component callback. + * Creates links. + */ +function flexifilter_component_linkifier($op, $settings, $text) { + switch ($op) { + case 'settings': + return flexifilter_component_linkifer_form($settings); + + case 'prepare': + case 'process': + return flexifilter_component_linkifier_link($settings, $text); + } +} + +/** + * Helper function for flexifilter_component_linkifier(). + * @param $settings + * The flexifilter settings for the component. + * @return + * The settings form for the linkifier component. + */ +function flexifilter_component_linkifer_form($settings) { + $form = array(); + $form['ordering'] = array( + '#type' => 'radios', + '#title' => t('Ordering'), + '#description' => t('Should links come first, or their titles?'), + '#options' => array( + 0 => t('Link first'), + 1 => t('Title first'), + ), + '#default_value' => isset($settings['ordering']) ? $settings['ordering'] : 0, + ); + $form['divider'] = array( + '#type' => 'textfield', + '#title' => t('Divider'), + '#required' => TRUE, + '#default_value' => isset($settings['divider']) ? $settings['divider'] : '|', + '#description' => t('The divider between the link and the title.'), + ); + $form['no_links'] = array( + '#type' => 'checkbox', + '#title' => t('Leave text with empty links as simple text'), + '#description' => t('(By default they link to the plain prefix).'), + '#default_value' => isset($settings['no_links']) ? $settings['no_links'] : FALSE, + ); + $form['check_path'] = array( + '#type' => 'checkbox', + '#title' => t('Check internal paths for broken links, and add a class="broken" tag to them.'), + '#description' => t('WARNING: This may slow down process times considerably if you use this component a lot. However, it can also be freakishly cool. Note: this depends on the current theme\'s css to display the links differently.'), + '#default_value' => isset($settings['check_path']) ? $settings['check_path'] : FALSE, + ); + if (module_exists('pathauto')) { + $form['pathauto_cleanup'] = array( + '#type' => 'checkbox', + '#title' => t('Clean URL using pathauto settings.'), + '#description' => t('Process the link using pathauto\'s rules (character replacement, transliteration and others).'), + '#default_value' => isset($settings['pathauto_cleanup']) ? $settings['pathauto_cleanup'] : FALSE, + ); + } + $form['prefix'] = array( + '#type' => 'textfield', + '#title' => t('Prefix'), + '#default_value' => '', + '#description' => t('Prepend a prefix to all links (e.g. "http://en.wikipedia.org/wiki/" or "node/". Do not include a leading slash for internal paths.'), + ); + + // Add the default values for the form. + foreach ($form as $key => $item) { + if (!isset($settings[$key])) { + $form[$key]['#value'] = $form[$key]['#default_value']; + } + } + return $form; +} + +/** + * Helper function for flexifilter_component_linkifier(). + * @param $settings + * The flexifilter settings for the component. + * @param $text + * The text to linkify! + * @return + * The linkified text. + */ +function flexifilter_component_linkifier_link($settings, $text) { + extract($settings); + $parts = explode($divider, $text); + if (count($parts) == 1) { + $parts[] = $parts[0]; + } + if (count($parts) > 2) { + foreach ($parts as $key => $part) { + if ($key > 1) { + $parts[1] .= $divider . $parts[$key]; + unset($parts[$key]); + } + } + } + switch ($ordering) { + case 0: + $link = $parts[0]; + $title = $parts[1]; + break; + + case 1: + $title = $parts[0]; + $link = $parts[1]; + break; + } + + if ( $pathauto_cleanup && module_exists('pathauto')) { + // use pathauto module to clean up the link + + // make the string URL-suitable using pathauto_cleanstring() + $link = pathauto_cleanstring($link); + + // also make it lower case if this is configured so for pathauto + if (variable_get('pathauto_case', 1)) { + $link = drupal_strtolower($link); + } + } + + $link = $prefix . urlencode($link); + + if ($no_links && empty($link)) { + return $title; + } + + $options = array(); + if (!menu_path_is_external($link)) { + $parsed_link = parse_url($link); + if (isset($parsed_link['query'])) { + $options['query'] = $parsed_link['query']; + } + if (isset($parsed_link['fragment'])) { + $options['fragment'] = $parsed_link['fragment']; + } + if ($link != $parsed_link['path']) { + $link = $parsed_link['path']; + } + if ($check_path) { + if (!menu_valid_path(array('link_path' => $link))) { + $options['attributes']['class'] = 'broken'; + } + } + } + return l($title, $link, $options); +} + +/** * Basic sequence callback. */ function flexifilter_component_sequences($op, $settings, $text) { diff -rup flexifilter_orig/flexifilter.flexifilters.inc modules/flexifilter/flexifilter.flexifilters.inc --- flexifilter_orig/flexifilter.flexifilters.inc 2009-02-15 11:40:32.000000000 +0100 +++ modules/flexifilter/flexifilter.flexifilters.inc 2009-02-14 19:29:02.000000000 +0100 @@ -8,10 +8,10 @@ function flexifilter_flexifilters() { return array( array( 'label' => 'Mediawiki Format', - 'description' => 'This is an example format which provides a wikimedia-style input format.', + 'description' => 'You may enter text using Mediawiki-style markup.', 'id' => '1', - 'enabled' => true, - 'advanced' => true, + 'enabled' => TRUE, + 'advanced' => TRUE, 'delta' => '0', 'components' => array( array( @@ -70,7 +70,7 @@ function flexifilter_flexifilters() { array( 'class' => 'flexifilter_text_alternation', 'settings' => array( - 'find' => '\'\'\'', + 'find' => "'''", 'replace' => "\n", 'step' => 'process', ), @@ -79,7 +79,7 @@ function flexifilter_flexifilters() { array( 'class' => 'flexifilter_text_alternation', 'settings' => array( - 'find' => '\'\'', + 'find' => "''", 'replace' => "\n", 'step' => 'process', ), @@ -96,137 +96,25 @@ function flexifilter_flexifilters() { 'step' => 'process', 'components' => array( array( - 'class' => 'flexifilter_control_if', + 'class' => 'flexifilter_link_component', 'settings' => array( - 'components' => array( - array( - 'class' => 'flexifilter_text_replace', - 'settings' => array( - 'find' => '~', - 'replace' => '\\~', - 'step' => 'process', - ), - 'id' => '12', - ), - array( - 'class' => 'flexifilter_text_append', - 'settings' => array( - 'text' => '~~', - 'step' => 'process', - ), - 'id' => '13', - ), - array( - 'class' => 'flexifilter_advanced_append', - 'settings' => array( - 'step' => 'process', - 'components' => array( - array( - 'class' => 'flexifilter_text_replace', - 'settings' => array( - 'find' => '~~', - 'replace' => '', - 'step' => 'process', - ), - 'id' => '23', - ), - ), - ), - 'id' => '14', - ), - array( - 'class' => 'flexifilter_text_replace', - 'settings' => array( - 'find' => '~~', - 'replace' => '">', - 'step' => 'process', - ), - 'id' => '26', - ), - array( - 'class' => 'flexifilter_text_prepend', - 'settings' => array( - 'text' => ' 'process', - ), - 'id' => '33', - ), - array( - 'class' => 'flexifilter_text_replace', - 'settings' => array( - 'find' => '|', - 'replace' => '">', - 'step' => 'process', - ), - 'id' => '34', - ), - array( - 'class' => 'flexifilter_text_append', - 'settings' => array( - 'text' => '', - 'step' => 'process', - ), - 'id' => '35', - ), - ), - 'condition' => array( - 'class' => 'flexifilter_text_search', - 'settings' => array( - 'find' => '|', - 'is_regex' => 0, - ), - ), - ), - 'id' => '32', + 'ordering' => '0', + 'divider' => '|', + 'no_links' => 0, + 'check_path' => 0, + 'prefix' => 'http://en.wikipedia.org/wiki/', + 'step' => 'process', + ), ), ), ), - 'id' => '10', + 'id' => '202', ), ), ), 'id' => '4', ), - 'id_next' => 37, + 'id_next' => 204, 'id_prefix' => 'flexifilter_component_', ), 'fid' => 'new', Only in modules/flexifilter: flexifilter_link_01.patch