merged filter_path_alias submodule

This commit is contained in:
Bachir Soussi Chiadmi 2015-04-19 16:18:02 +02:00
commit 8d74b0bb06
2 changed files with 50 additions and 0 deletions

View File

@ -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

View File

@ -0,0 +1,44 @@
<?php
/**
* Implements hook_filter_info().
*/
function filter_path_alias_filter_info() {
$filters['path_alias'] = array(
'title' => 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;
}