Recursively resolve paths of iframe contents; unify contentframe registration and reduce code-duplication

pull/42/head
Thomas Bruederli 12 years ago
parent 03970bd549
commit 28de391182

@ -90,8 +90,7 @@ class help extends rcube_plugin
$attrib['name'] = $attrib['id']; $attrib['name'] = $attrib['id'];
return html::tag('iframe', $attrib, '', array( return $rcmail->output->frame($attrib);
'id', 'class', 'style', 'src', 'width', 'height', 'frameborder'));
} }
} }

@ -205,6 +205,31 @@ class rcube_output_html extends rcube_output
} }
/**
* Find the given file in the current skin path stack
*
* @param string File name/path to resolve (starting with /)
* @param string Reference to the base path of the matching skin
* @param string Additional path to search in
* @return mixed Relative path to the requested file or False if not found
*/
public function get_skin_file($file, &$skin_path, $add_path = null)
{
$skin_paths = $this->skin_paths;
if ($add_path)
array_unshift($skin_paths, $add_path);
foreach ($skin_paths as $skin_path) {
$path = realpath($skin_path . $file);
if (is_file($path)) {
return $skin_path . $file;
}
}
return false;
}
/** /**
* Register a GUI object to the client script * Register a GUI object to the client script
* *
@ -401,13 +426,13 @@ class rcube_output_html extends rcube_output
// apply skin search escalation list to plugin directory // apply skin search escalation list to plugin directory
$plugin_skin_paths = array(); $plugin_skin_paths = array();
foreach ($this->skin_paths as $skin_path) { foreach ($this->skin_paths as $skin_path) {
$plugin_skin_paths[] = $this->app->plugins->dir . $plugin . '/' . $skin_path; $plugin_skin_paths[] = $this->app->plugins->url . $plugin . '/' . $skin_path;
} }
// add fallback to default skin // add fallback to default skin
if (is_dir($this->app->plugins->dir . $plugin . '/skins/default')) { if (is_dir($this->app->plugins->dir . $plugin . '/skins/default')) {
$skin_dir = $plugin . '/skins/default'; $skin_dir = $plugin . '/skins/default';
$plugin_skin_paths[] = $this->app->plugins->dir . $skin_dir; $plugin_skin_paths[] = $this->app->plugins->url . $skin_dir;
} }
// add plugin skin paths to search list // add plugin skin paths to search list
@ -536,12 +561,17 @@ class rcube_output_html extends rcube_output
* Make URLs starting with a slash point to skin directory * Make URLs starting with a slash point to skin directory
* *
* @param string Input string * @param string Input string
* @param boolean True if URL should be resolved using the current skin path stack
* @return string * @return string
*/ */
public function abs_url($str) public function abs_url($str, $search_path = false)
{ {
if ($str[0] == '/') if ($str[0] == '/') {
if ($search_path && ($file_url = $this->get_skin_file($str, $skin_path)))
return $file_url;
return $this->base_path . $str; return $this->base_path . $str;
}
else else
return $str; return $str;
} }
@ -825,15 +855,9 @@ class rcube_output_html extends rcube_output
// include a file // include a file
case 'include': case 'include':
$old_base_path = $this->base_path; $old_base_path = $this->base_path;
$skin_paths = $this->skin_paths; if ($path = $this->get_skin_file($attrib['file'], $skin_path, $attrib['skin_path'])) {
if ($attrib['skin_path'])
array_unshift($skin_paths, $attrib['skin_path']);
foreach ($skin_paths as $skin_path) {
$path = realpath($skin_path . $attrib['file']);
if (is_file($path)) {
$this->base_path = $skin_path; $this->base_path = $skin_path;
break; $path = realpath($path);
}
} }
if (is_readable($path)) { if (is_readable($path)) {
@ -1350,21 +1374,25 @@ class rcube_output_html extends rcube_output
* Returns iframe object, registers some related env variables * Returns iframe object, registers some related env variables
* *
* @param array $attrib HTML attributes * @param array $attrib HTML attributes
* * @param boolean $is_contentframe Register this iframe as the 'contentframe' gui object
* @return string IFRAME element * @return string IFRAME element
*/ */
public function frame($attrib) public function frame($attrib, $is_contentframe = false)
{ {
static $idcount = 0;
if (!$attrib['id']) { if (!$attrib['id']) {
$attrib['id'] = 'rcmframe'; $attrib['id'] = 'rcmframe' . ++$idcount;
} }
if (!$attrib['name']) {
$attrib['name'] = $attrib['id']; $attrib['name'] = $attrib['id'];
} $attrib['src'] = $attrib['src'] ? $this->abs_url($attrib['src'], true) : 'program/resources/blank.gif';
$this->set_env('contentframe', $attrib['id']); // register as 'contentframe' object
$this->set_env('blankpage', $attrib['src'] ? $this->abs_url($attrib['src']) : 'program/resources/blank.gif'); if ($is_contentframe)
$this->set_env('contentframe', $attrib['name']);
$this->set_env('blankpage', $attrib['src']);
}
return html::iframe($attrib); return html::iframe($attrib);
} }

@ -367,12 +367,7 @@ function rcmail_contact_frame($attrib)
if (!$attrib['id']) if (!$attrib['id'])
$attrib['id'] = 'rcmcontactframe'; $attrib['id'] = 'rcmcontactframe';
$attrib['name'] = $attrib['id']; return $OUTPUT->frame($attrib, true);
$OUTPUT->set_env('contentframe', $attrib['name']);
$OUTPUT->set_env('blankpage', $attrib['src'] ? $OUTPUT->abs_url($attrib['src']) : 'program/resources/blank.gif');
return html::iframe($attrib);
} }

@ -471,7 +471,7 @@ function rcmail_messagecontent_frame($attrib)
$OUTPUT->set_env('contentframe', $attrib['id']); $OUTPUT->set_env('contentframe', $attrib['id']);
$OUTPUT->set_env('blankpage', $attrib['src'] ? $OUTPUT->abs_url($attrib['src']) : 'program/resources/blank.gif'); $OUTPUT->set_env('blankpage', $attrib['src'] ? $OUTPUT->abs_url($attrib['src']) : 'program/resources/blank.gif');
return html::iframe($attrib); return $OUTPUT->frame($attrib, true);
} }

@ -369,12 +369,7 @@ function rcmail_folder_frame($attrib)
if (!$attrib['id']) if (!$attrib['id'])
$attrib['id'] = 'rcmfolderframe'; $attrib['id'] = 'rcmfolderframe';
$attrib['name'] = $attrib['id']; return $OUTPUT->frame($attrib, true);
$OUTPUT->set_env('contentframe', $attrib['name']);
$OUTPUT->set_env('blankpage', $attrib['src'] ? $OUTPUT->abs_url($attrib['src']) : 'program/resources/blank.gif');
return html::iframe($attrib);
} }
function rcmail_rename_folder($oldname, $newname) function rcmail_rename_folder($oldname, $newname)

@ -31,12 +31,7 @@ function rcmail_preferences_frame($attrib)
if (!$attrib['id']) if (!$attrib['id'])
$attrib['id'] = 'rcmprefsframe'; $attrib['id'] = 'rcmprefsframe';
$attrib['name'] = $attrib['id']; return $OUTPUT->frame($attrib, true);
$OUTPUT->set_env('contentframe', $attrib['name']);
$OUTPUT->set_env('blankpage', $attrib['src'] ? $OUTPUT->abs_url($attrib['src']) : 'program/resources/blank.gif');
return html::iframe($attrib);
} }

@ -33,11 +33,7 @@ function rcmail_identity_frame($attrib)
if (!$attrib['id']) if (!$attrib['id'])
$attrib['id'] = 'rcmIdentityFrame'; $attrib['id'] = 'rcmIdentityFrame';
$attrib['name'] = $attrib['id']; return $OUTPUT->frame($attrib, true);
$OUTPUT->set_env('contentframe', $attrib['name']);
return html::iframe($attrib);
} }
$OUTPUT->add_handler('identityframe', 'rcmail_identity_frame'); $OUTPUT->add_handler('identityframe', 'rcmail_identity_frame');

Loading…
Cancel
Save