Index: transliteration.module
===================================================================
--- transliteration.module (revision 12)
+++ transliteration.module (revision 46)
@@ -37,12 +37,82 @@
*
* Transliterate and clean the names of new uploaded files.
*/
-function transliteration_menu($may_cache) {
- if (!$may_cache && !empty($_FILES['files'])) {
+function transliteration_menu($may_cache) {
+ $items = array();
+
+ if ($may_cache) {
+ $items[] = array(
+ 'title' => t('Transliteration'),
+ 'path' => 'admin/settings/transliteration',
+ 'callback' => 'drupal_get_form',
+ 'callback arguments' => array('transliteration_settings_form'),
+ 'access' => user_access('administer site configuration'),
+ 'type' => MENU_NORMAL_ITEM,
+ );
+ }
+ elseif (!empty($_FILES['files']) && _transliteration_test_path()) {
require_once(drupal_get_path('module', 'transliteration') .'/transliteration.inc');
foreach ($_FILES['files']['name'] as $field => $filename) {
$_FILES['files']['name'][$field] = transliteration_clean_filename($filename);
}
- }
+ }
+
+ return $items;
}
+function transliteration_settings_form() {
+ $form = array();
+
+ $form['transliteration_enabled_settings'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Page specific enabled settings'),
+ '#collapsible' => TRUE,
+ );
+
+ $form['transliteration_enabled_settings']['transliteration_enabled_mode'] = array(
+ '#type' => 'radios',
+ '#title' => t('Enable transliteration on specific pages'),
+ '#options' => array(t('Enable on every page except the listed pages.'),
+ t('Enable on only the listed pages.'),
+ t('Enable if the following PHP code returns TRUE (PHP-mode, experts only).')),
+ '#default_value' => variable_get('transliteration_enabled_mode', 0),
+ );
+ $form['transliteration_enabled_settings']['transliteration_enabled_pages'] = array(
+ '#type' => 'textarea',
+ '#title' => t('Pages'),
+ '#default_value' => variable_get('transliteration_enabled_pages', ''),
+ '#description' => t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '')).' '.
+ t('If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can break your Drupal site.', array('%php' => '')),
+ );
+
+ return system_settings_form($form);
+}
+
+function _transliteration_test_path() {
+ $pages = variable_get('transliteration_enabled_pages', '');
+ $mode = variable_get('transliteration_enabled_mode', 0);
+
+ if ($pages) {
+ if ($mode < 2) {
+ $path = drupal_get_path_alias($_GET['q']);
+ $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote($pages, '/')) .')$/';
+ // Compare with the internal and path alias (if any).
+ $page_match = preg_match($regexp, $path);
+ if ($path != $_GET['q']) {
+ $page_match = $page_match || preg_match($regexp, $_GET['q']);
+ }
+ // When $mode has a value of 0, the transliteration is enabled on
+ // all pages except those listed in $pages. When set to 1, it
+ // is enabled only on those pages listed in $pages.
+ $page_match = !($mode xor $page_match);
+ }
+ else {
+ $page_match = drupal_eval($pages);
+ }
+ }
+ else {
+ $page_match = TRUE;
+ }
+
+ return $page_match;
+}
\ No newline at end of file