View source
<?php
function url_alter_help($path, $arg) {
switch ($path) {
case 'admin/settings/url-alter':
module_load_install('url_alter');
if (url_alter_check_status() && user_access('administer site configuration')) {
drupal_set_message(t('One or more problems were detected with your URL alter module configuration. Check the <a href="@status">status report</a> for more information.', array(
'@status' => url('admin/reports/status'),
)), 'error', FALSE);
}
return '<p>' . t('Do not use %php tags around your PHP code. Note that executing incorrect PHP-code can severely break your Drupal site.', array(
'%php' => '<?php ?>',
)) . '</p>';
}
}
function url_alter_boot() {
}
function url_alter_perm() {
return array(
'administer custom_url_rewrite functions',
);
}
function url_alter_menu() {
$items['admin/settings/url-alter'] = array(
'title' => 'URL alter',
'description' => 'Administer custom_url_rewrite function code',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'url_alter_settings_form',
),
'access arguments' => array(
'administer custom_url_rewrite functions',
),
'file' => 'url_alter.admin.inc',
);
return $items;
}
if (!function_exists('custom_url_rewrite_inbound')) {
define('URL_ALTER_CUSTOM_URL_REWRITE_INBOUND', TRUE);
function custom_url_rewrite_inbound(&$result, $path, $path_language) {
foreach (array_reverse(module_implements('url_inbound_alter')) as $module) {
$function = $module . '_url_inbound_alter';
$function($result, $path, $path_language);
}
}
}
function url_alter_url_inbound_alter(&$result, $path, $path_language) {
if (!url_alter_is_disabled() && ($code = variable_get('url_alter_inbound', ''))) {
eval($code);
}
}
if (!function_exists('custom_url_rewrite_outbound')) {
define('URL_ALTER_CUSTOM_URL_REWRITE_OUTBOUND', TRUE);
function custom_url_rewrite_outbound(&$path, &$options, $original_path) {
foreach (module_implements('url_outbound_alter') as $module) {
$function = $module . '_url_outbound_alter';
$function($path, $options, $original_path);
}
}
}
function url_alter_url_outbound_alter(&$path, &$options, $original_path) {
if (!url_alter_is_disabled() && ($code = variable_get('url_alter_outbound', ''))) {
eval($code);
}
}
function url_alter_is_disabled() {
static $is_disabled;
if (!isset($is_disabled)) {
$is_disabled = FALSE;
if (isset($_GET['url-alter-kill'])) {
$is_disabled = TRUE;
}
elseif (isset($_GET['q']) && $_GET['q'] == 'admin/settings/url-alter') {
$is_disabled = TRUE;
}
}
return $is_disabled;
}
function url_alter_get_function_info($function) {
if (!function_exists($function) || !class_exists('ReflectionFunction')) {
return FALSE;
}
$info = new ReflectionFunction($function);
$info->file = trim(substr($info
->getFileName(), strlen(getcwd())), '\\/');
$info->location = t('line @line in @file', array(
'@file' => $info->file,
'@line' => $info
->getStartLine(),
));
$file_contents = file_get_contents($info
->getFileName());
$file_contents = explode("\n", $file_contents);
$info->code = array_slice($file_contents, $info
->getStartLine(), $info
->getEndLine() - $info
->getStartLine() - 1);
$info->code = implode("\n", $info->code);
return $info;
}