From a59e01d58103049a7b1e07d4bb9c4b2bcdc2bab6 Mon Sep 17 00:00:00 2001 From: bachy Date: Sun, 10 Feb 2013 21:29:08 +0100 Subject: [PATCH] first import Signed-off-by: bachy --- filter_path_alias.info | 6 ++++++ filter_path_alias.module | 44 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 filter_path_alias.info create mode 100644 filter_path_alias.module diff --git a/filter_path_alias.info b/filter_path_alias.info new file mode 100644 index 00000000..14e2d030 --- /dev/null +++ b/filter_path_alias.info @@ -0,0 +1,6 @@ +name = Filter path alias +description = "filter for input format that check links and converte them with alias" + +; Core version (required) +core = 7.x + diff --git a/filter_path_alias.module b/filter_path_alias.module new file mode 100644 index 00000000..83703ce9 --- /dev/null +++ b/filter_path_alias.module @@ -0,0 +1,44 @@ + t('Path Alias'), + 'description' => t('replace internal machine links with alias'), + 'process callback' => 'filter_path_alias_callback', + ); + return $filters; +} + + +function filter_path_alias_callback($text, $filter, $format, $langcode, $cache, $cache_id){ + // dsm($text, 'text'); + // dsm($_SERVER, 'server'); + if (preg_match_all('/href="([^"]+)"/', $text, $matches_code)) { + // dsm($matches_code, 'matches_code'); + foreach ($matches_code[1] as $i => $path) { + $old_path = $path; + $path = str_replace('http://', '', $path); + $path = str_replace($_SERVER['SERVER_NAME'], '', $path); + $path = preg_replace('/#.*$/', '', $path); + $path = preg_replace('/\?.*$/', '', $path); + $path = preg_replace('/^\//', '', $path); + // dsm($path, 'path'); + + if($path != ""){ + $alias = drupal_get_path_alias($path, $langcode); + // dsm($alias, 'alias'); + if($alias != $path){ + $path_aliased = str_replace($old_path, $alias, $matches_code[0][$i]); + $text = str_replace($matches_code[0][$i], $path_aliased, $text); + } + } + } + } + + + return $text; +} \ No newline at end of file