url_alter.admin.inc in URL alter 6
Administrative page callbacks for the url_alter module.
File
url_alter.admin.incView source
<?php
/**
* @file
* Administrative page callbacks for the url_alter module.
*/
function url_alter_settings_form() {
$form['url_alter_inbound'] = array(
'#type' => 'textarea',
'#title' => t('PHP code for custom_url_rewrite_inbound()'),
'#description' => t('The available variables are %variables.', array(
'%variables' => '&$result, $path, $path_language',
)),
'#default_value' => variable_get('url_alter_inbound', ''),
'#element_validate' => array(
'url_alter_validate_php_element',
),
'#url_alter_variables' => "\$result = \$path = '';\n\$path_language = 'en';\n",
);
$form['url_alter_outbound'] = array(
'#type' => 'textarea',
'#title' => t('PHP code for custom_url_rewrite_outbound()'),
'#description' => t('The available variables are %variables.', array(
'%variables' => '&$path, &$options, $original_path',
)),
'#default_value' => variable_get('url_alter_outbound', ''),
'#element_validate' => array(
'url_alter_validate_php_element',
),
'#url_alter_variables' => "\$path = \$original_path = '';\n\$options = array();\n",
);
return system_settings_form($form);
}
function url_alter_validate_php_element($element, &$form_state) {
$code =& $form_state['values'][$element['#name']];
$code = trim($code);
$result = url_alter_check_php_syntax($element['#url_alter_variables'] . $code);
if ($result !== TRUE) {
form_error($element, t('@function did not validate.', array(
'@function' => $element['#title'],
)));
}
}
/**
* Validate PHP code syntax.
*
* @param $code
* A string with PHP code, not including the opening or closing PHP tags.
* @return
* TRUE if the code was valid, otherwise an error message or FALSE.
*/
function url_alter_check_php_syntax($code) {
if (!strlen($code)) {
return TRUE;
}
elseif (preg_match('/<\\?php|\\?>/', $code, $matches)) {
return t('Do not use the PHP tag %code in your code.', array(
'%code' => $matches[0],
));
}
else {
$success = TRUE;
$code .= "\nreturn " . var_export($success, TRUE) . ";";
ob_start();
$result = @eval($code);
ob_end_clean();
if ($result === $success) {
return TRUE;
}
else {
return is_string($result) ? $result : FALSE;
}
}
}
Functions
Name | Description |
---|---|
url_alter_check_php_syntax | Validate PHP code syntax. |
url_alter_settings_form | @file Administrative page callbacks for the url_alter module. |
url_alter_validate_php_element |