Esempio n. 1
0
 /**
  * Callback function for parsing an xml command tag
  * and turn it into real html content
  *
  * @param  array Matches array of preg_replace_callback
  * @return string Tag/Object content
  */
 private function xml_command($matches)
 {
     $command = strtolower($matches[1]);
     $attrib = parse_attrib_string($matches[2]);
     // empty output if required condition is not met
     if (!empty($attrib['condition']) && !$this->check_condition($attrib['condition'])) {
         return '';
     }
     // execute command
     switch ($command) {
         // return a button
         case 'button':
             if ($attrib['name'] || $attrib['command']) {
                 return $this->button($attrib);
             }
             break;
             // show a label
         // show a label
         case 'label':
             if ($attrib['name'] || $attrib['command']) {
                 $vars = $attrib + array('product' => $this->config['product_name']);
                 unset($vars['name'], $vars['command']);
                 $label = rcube_label($attrib + array('vars' => $vars));
                 return !$attrib['noshow'] ? get_boolean((string) $attrib['html']) ? $label : Q($label) : '';
             }
             break;
             // include a file
         // include a file
         case 'include':
             if (!$this->plugin_skin_path || !is_file($path = realpath($this->plugin_skin_path . $attrib['file']))) {
                 $path = realpath(($attrib['skin_path'] ? $attrib['skin_path'] : $this->config['skin_path']) . $attrib['file']);
             }
             if (is_readable($path)) {
                 if ($this->config['skin_include_php']) {
                     $incl = $this->include_php($path);
                 } else {
                     $incl = file_get_contents($path);
                 }
                 $incl = $this->parse_conditions($incl);
                 return $this->parse_xml($incl);
             }
             break;
         case 'plugin.include':
             $hook = $this->app->plugins->exec_hook("template_plugin_include", $attrib);
             return $hook['content'];
             break;
             // define a container block
         // define a container block
         case 'container':
             if ($attrib['name'] && $attrib['id']) {
                 $this->command('gui_container', $attrib['name'], $attrib['id']);
                 // let plugins insert some content here
                 $hook = $this->app->plugins->exec_hook("template_container", $attrib);
                 return $hook['content'];
             }
             break;
             // return code for a specific application object
         // return code for a specific application object
         case 'object':
             $object = strtolower($attrib['name']);
             $content = '';
             // we are calling a class/method
             if (($handler = $this->object_handlers[$object]) && is_array($handler)) {
                 if (is_object($handler[0]) && method_exists($handler[0], $handler[1]) || is_string($handler[0]) && class_exists($handler[0])) {
                     $content = call_user_func($handler, $attrib);
                 }
             } else {
                 if (function_exists($handler)) {
                     $content = call_user_func($handler, $attrib);
                 } else {
                     if ($object == 'logo') {
                         $attrib += array('alt' => $this->xml_command(array('', 'object', 'name="productname"')));
                         if ($this->config['skin_logo']) {
                             $attrib['src'] = $this->config['skin_logo'];
                         }
                         $content = html::img($attrib);
                     } else {
                         if ($object == 'productname') {
                             $name = !empty($this->config['product_name']) ? $this->config['product_name'] : 'Roundcube Webmail';
                             $content = Q($name);
                         } else {
                             if ($object == 'version') {
                                 $ver = (string) RCMAIL_VERSION;
                                 if (is_file(INSTALL_PATH . '.svn/entries')) {
                                     if (preg_match('/Revision:\\s(\\d+)/', @shell_exec('svn info'), $regs)) {
                                         $ver .= ' [SVN r' . $regs[1] . ']';
                                     }
                                 }
                                 $content = Q($ver);
                             } else {
                                 if ($object == 'steptitle') {
                                     $content = Q($this->get_pagetitle());
                                 } else {
                                     if ($object == 'pagetitle') {
                                         if (!empty($this->config['devel_mode']) && !empty($_SESSION['username'])) {
                                             $title = $_SESSION['username'] . ' :: ';
                                         } else {
                                             if (!empty($this->config['product_name'])) {
                                                 $title = $this->config['product_name'] . ' :: ';
                                             } else {
                                                 $title = '';
                                             }
                                         }
                                         $title .= $this->get_pagetitle();
                                         $content = Q($title);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             // exec plugin hooks for this template object
             $hook = $this->app->plugins->exec_hook("template_object_{$object}", $attrib + array('content' => $content));
             return $hook['content'];
             // return code for a specified eval expression
         // return code for a specified eval expression
         case 'exp':
             $value = $this->parse_expression($attrib['expression']);
             return eval("return Q({$value});");
             // return variable
         // return variable
         case 'var':
             $var = explode(':', $attrib['name']);
             $name = $var[1];
             $value = '';
             switch ($var[0]) {
                 case 'env':
                     $value = $this->env[$name];
                     break;
                 case 'config':
                     $value = $this->config[$name];
                     if (is_array($value) && $value[$_SESSION['imap_host']]) {
                         $value = $value[$_SESSION['imap_host']];
                     }
                     break;
                 case 'request':
                     $value = get_input_value($name, RCUBE_INPUT_GPC);
                     break;
                 case 'session':
                     $value = $_SESSION[$name];
                     break;
                 case 'cookie':
                     $value = htmlspecialchars($_COOKIE[$name]);
                     break;
                 case 'browser':
                     $value = $this->browser->{$name};
                     break;
             }
             if (is_array($value)) {
                 $value = implode(', ', $value);
             }
             return Q($value);
             break;
     }
     return '';
 }
 /**
  * Convert a xml command tag into real content
  *
  * @param  string Tag command: object,button,label, etc.
  * @param  string Attribute string
  * @return string Tag/Object content
  */
 private function xml_command($command, $str_attrib, $add_attrib = array())
 {
     $command = strtolower($command);
     $attrib = parse_attrib_string($str_attrib) + $add_attrib;
     // empty output if required condition is not met
     if (!empty($attrib['condition']) && !$this->check_condition($attrib['condition'])) {
         return '';
     }
     // execute command
     switch ($command) {
         // return a button
         case 'button':
             if ($attrib['name'] || $attrib['command']) {
                 return $this->button($attrib);
             }
             break;
             // show a label
         // show a label
         case 'label':
             if ($attrib['name'] || $attrib['command']) {
                 return Q(rcube_label($attrib + array('vars' => array('product' => $this->config['product_name']))));
             }
             break;
             // include a file
         // include a file
         case 'include':
             $path = realpath($this->config['skin_path'] . $attrib['file']);
             if (is_readable($path)) {
                 if ($this->config['skin_include_php']) {
                     $incl = $this->include_php($path);
                 } else {
                     $incl = file_get_contents($path);
                 }
                 return $this->parse_xml($incl);
             }
             break;
         case 'plugin.include':
             //rcube::tfk_debug(var_export($this->config['skin_path'], true));
             $path = realpath($this->config['skin_path'] . $attrib['file']);
             if (!$path) {
                 //rcube::tfk_debug("Does not exist:");
                 //rcube::tfk_debug($this->config['skin_path']);
                 //rcube::tfk_debug($attrib['file']);
                 //rcube::tfk_debug($path);
             }
             $incl = file_get_contents($path);
             if ($incl) {
                 return $this->parse_xml($incl);
             }
             break;
             // return code for a specific application object
         // return code for a specific application object
         case 'object':
             $object = strtolower($attrib['name']);
             // we are calling a class/method
             if (($handler = $this->object_handlers[$object]) && is_array($handler)) {
                 if (is_object($handler[0]) && method_exists($handler[0], $handler[1]) || is_string($handler[0]) && class_exists($handler[0])) {
                     return call_user_func($handler, $attrib);
                 }
             } else {
                 if (function_exists($handler)) {
                     // execute object handler function
                     return call_user_func($handler, $attrib);
                 }
             }
             if ($object == 'productname') {
                 $name = !empty($this->config['product_name']) ? $this->config['product_name'] : 'RoundCube Webmail';
                 return Q($name);
             }
             if ($object == 'version') {
                 $ver = (string) RCMAIL_VERSION;
                 if (is_file(INSTALL_PATH . '.svn/entries')) {
                     if (preg_match('/Revision:\\s(\\d+)/', @shell_exec('svn info'), $regs)) {
                         $ver .= ' [SVN r' . $regs[1] . ']';
                     }
                 }
                 return $ver;
             }
             if ($object == 'steptitle') {
                 return Q($this->get_pagetitle());
             }
             if ($object == 'pagetitle') {
                 $title = !empty($this->config['product_name']) ? $this->config['product_name'] . ' :: ' : '';
                 $title .= $this->get_pagetitle();
                 return Q($title);
             }
             break;
             // return code for a specified eval expression
         // return code for a specified eval expression
         case 'exp':
             $value = $this->parse_expression($attrib['expression']);
             return eval("return Q({$value});");
             // return variable
         // return variable
         case 'var':
             $var = explode(':', $attrib['name']);
             $name = $var[1];
             $value = '';
             switch ($var[0]) {
                 case 'env':
                     $value = $this->env[$name];
                     break;
                 case 'config':
                     $value = $this->config[$name];
                     if (is_array($value) && $value[$_SESSION['imap_host']]) {
                         $value = $value[$_SESSION['imap_host']];
                     }
                     break;
                 case 'request':
                     $value = get_input_value($name, RCUBE_INPUT_GPC);
                     break;
                 case 'session':
                     $value = $_SESSION[$name];
                     break;
                 case 'cookie':
                     $value = htmlspecialchars($_COOKIE[$name]);
                     break;
             }
             if (is_array($value)) {
                 $value = implode(', ', $value);
             }
             return Q($value);
             break;
     }
     return '';
 }