$form['settings']['print_css'] = array(
'#type' => 'textfield',
- '#title' => t('Stylesheet URL'),
+ '#title' => t('Custom Stylesheet'),
'#default_value' => variable_get('print_css', PRINT_CSS_DEFAULT),
'#size' => 60,
'#maxlength' => 250,
- '#description' => t('The URL to your custom print cascading stylesheet, if any. When none is specified, the default module CSS file is used.') . '<br />' .
- t('Macros: %b (base path: "%base"), %t (path to theme: "%theme")', array('%base' => base_path(), '%theme' => path_to_theme())) . '<br />' .
+ '#description' => t('The path to your custom print cascading stylesheet, if any. The path provided must be relative to the base path. When none is specified, the default module CSS file is used.') . '<br />' .
+ t('Macros: %t (path to theme: "%theme")', array('%theme' => path_to_theme())) . '<br />' .
t('Requires the <em>administer site configuration</em> permission.'),
'#disabled' => !user_access('administer site configuration'),
);
}
}
- // Check that the stylesheet URL is a local URL, if it is an absolute URL, then it must start with the site's base URL
- if (preg_match('!^http://.*!', $form_state['values']['print_css'], $matches)) {
- if (!preg_match("!^$base_url/!", $matches[0])) {
- form_set_error('print_css', t("Stylesheet URL must be a relative path or start with the site's base URL"));
- }
+ // Check that the stylesheet path is indeed valid and relative to base_path()
+ $print_css = realpath($_SERVER["DOCUMENT_ROOT"].base_path()) .'/'. strtr($form_state['values']['print_css'], array('%t' => path_to_theme()));
+ if (!is_file($print_css) || !is_readable($print_css)) {
+ form_set_error('print_css', t("File %file is not readable by the web server.", array('%file' => $print_css)));
}
}
*/
function print_theme_registry_alter(&$theme_registry) {
// $theme_registry['print_node']['theme path'] += $theme_registry['node']['theme path'];
+// $theme_registry['print_page']['theme path'] += $theme_registry['page']['theme path'];
}
/**
$format = $vars['type'];
$type = $vars['node']->type;
template_preprocess_node($vars);
-
$variables['theme_hook_suggestions'][] = "node";
$variables['theme_hook_suggestions'][] = "node__$type";
$variables['theme_hook_suggestions'][] = "print_node";
function print_preprocess_print_page(&$vars) {
$format = $vars['type'];
$type = $vars['node']->type;
+ $vars['show_blocks'] = FALSE;
+ $vars['show_messages'] = FALSE;
+ template_preprocess_page($vars);
$variables['theme_hook_suggestions'][] = "print";
$variables['theme_hook_suggestions'][] = "print.node__$type";
$variables['theme_hook_suggestions'][] = "print_$format";
$print['favicon'] = theme_get_setting('toggle_favicon') ? "<link rel='shortcut icon' href='" . theme_get_setting('favicon') . "' type='image/x-icon' />\n" : '';
if (!empty($print_css)) {
- $replace_pairs = array('%b' => base_path(), '%t' => path_to_theme());
- $user_css = check_url(strtr($print_css, $replace_pairs));
+ drupal_add_css(strtr($print_css, array('%t' => path_to_theme())));
}
else {
drupal_add_css(drupal_get_path('module', 'print') . '/css/print.css');
if (!empty($message)) {
$style = '';
$css_files = array_keys($drupal_css);
- if (!empty($print_css)) {
- // Convert to a local path, by removing the base_path
- $pattern = '!^' . base_path() . '!';
- $css_files[] = preg_replace($pattern, '', $user_css);
- }
foreach ($css_files as $filename) {
$res = file_exists($filename) ? file_get_contents($filename, TRUE) : FALSE;
if ($res != FALSE) {
}
else {
$print['css'] = drupal_get_css($drupal_css);
- if (!empty($print_css)) {
- $query_string = '?' . substr(variable_get('css_js_query_string', '0'), 0, 1);
- $print['css'] .= "<link type='text/css' rel='stylesheet' media='all' href='${user_css}${query_string}' />\n";
- }
}
$window_close = ($print_html_new_window && $print_html_windowclose) ? 'window.close();' : '';