'freelinking filter'); case 'no cache': return FALSE; case 'description': return t('Allows for a flexible format for linking content'); case 'process': _freelinking_include_all_plugins(); // Handle default freelinks first $regex = '/\[\[([^:]+)]]/Uu'; // find freelinks that don't contain a colon preg_match_all($regex, $text, $defaultmatches, PREG_SET_ORDER); $defaultplugin = variable_get('freelinking_default', 'nodetitle'); foreach ($defaultmatches as $match) { // loop through default matches if ($freelinking[$defaultplugin]['translate']) { // run the default text through tr $new = strtr($match[1], $freelinking[$defaultplugin]['translate']); } else { $new = $match[1]; } if ($freelinking[$defaultplugin]['replacement']) { // just a replacement pattern $pattern = '/' . preg_quote($match[0]) . '/'; $replacement = '' . $match[1] . ''; $text = preg_replace($pattern, $replacement, $text); } elseif ($freelinking[$defaultplugin]['callback']) { // uses a callback function $pattern = '/\[\[(' . $match[1] . ')]]/'; // have to capture the match in the pattern for the array passed to the callback $text = preg_replace_callback($pattern, $freelinking[$defaultplugin]['callback'], $text); } } // endforeach looping through default matches // Handle regular format freelinks $regex = '/\[\[(.+):(.+)]]/Uu'; $stuff_to_do = preg_match_all($regex, $text, $pregmatches, PREG_PATTERN_ORDER); // scarf all into $matches if ($stuff_to_do) { // there was at least one hit on our regex $matches = array_merge($pregmatches[1], $pregmatches[2]); for ($match = 0; $match < $stuff_to_do ; $match++) { // loop through matches $key = $pregmatches[1][$match]; // key is the indicator, value is the target $value = $pregmatches[2][$match]; foreach (array_keys($freelinking) as $plugin) { if (preg_match($freelinking[$plugin]['indicator'], $key)) { // got a hit $pattern = '/\[\[' . $key . ':(' . $value . ')]]/'; if ($freelinking[$plugin]['replacement']) { // It's just a replacement pattern if ($freelinking[$plugin]['translate']) { // there's some prematch tr to do $new = strtr($value, $freelinking[$plugin]['translate']); } // endif translation to do first else { $new = $value; } $replacement = '' . $value . ''; $text = preg_replace($pattern, $replacement, $text); } // replacement pattern only elseif ($freelinking[$plugin]['callback']) { // plugin uses a callback function $text = preg_replace_callback($pattern, $freelinking[$plugin]['callback'], $text); } // endifelse plugin uses a callback } // endif looking for plugins that match } // endforeach looping through plugins } // endfor looping through matches } // endif $stuff to do return $text; case 'prepare': default: return $text; } // endswitch $op } // endfunction freelinking_filter function freelinking_menu() { $items['admin/settings/freelinking'] = array( 'title' => 'Freelinking settings', 'description' => 'Configure settings for the freelinking input filter', 'page callback' => 'drupal_get_form', 'page arguments' => array('freelinking_settings'), 'access arguments' => array('administer freelinking'), ); return $items; } // endfunction freelinking_menu function freelinking_settings() { global $freelinking; _freelinking_include_all_plugins(); $form = array(); foreach (array_keys($freelinking) as $plugin) { $available_plugins[$plugin] = $plugin; if (function_exists('freelinking_' . $plugin . '_settings')) { // find plugins with settings $plugin_with_settings[] = $plugin; } // endif plugin has a settings function } // endforeach looping through plugins $form['freelinking_default'] = array( '#title' => t('Plugin to use when not indicated in the freelink'), '#type' => 'select', '#multiple' => FALSE, '#options' => $available_plugins, '#default_value' => variable_get('freelinking_default', 'nodetitle'), '#description' => t('Use this plugin when a freelink is created without specifying which plugin to use. If unsure, "nodetitle" mimics the behavior of previous versions of freelinking.'), ); // loop through plugin settings functions, adding a fieldset for each foreach ($plugin_with_settings as $plugin) { $form[$plugin] = array( '#title' => t('Settings for ' . $plugin . ' plugin'), '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => FALSE, ); $form[$plugin]['settings'] = call_user_func('freelinking_' . $plugin . '_settings'); } // endforeach looping through plugins with settings return system_settings_form($form); } // endfunction freelinking_settings (admin settings) // vim: tw=300 nowrap syn=php