Changeset 688 in subversion


Ignore:
Timestamp:
Aug 15, 2007 6:32:25 PM (6 years ago)
Author:
till
Message:

+ documentation
# many smaller bugfixes

  • added to logout call/command (HACK, FIXME)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/devel-vnext/program/include/rcmail_template.inc

    r655 r688  
    2828 * @todo Documentation 
    2929 * @todo CS 
    30  * @todo Remove globals 
    3130 * @todo PHP5? 
    3231 * @uses rcube_html_page 
     
    110109    } 
    111110 
    112   /** 
    113    * Register a list of template object handlers 
    114    * 
    115    * @param array Hash array with object=>handler pairs 
    116    */ 
    117   function add_handlers($arr) 
    118   { 
    119     $this->object_handlers = array_merge($this->object_handlers, $arr); 
    120   } 
    121  
    122   /** 
    123    * Register a GUI object to the client script 
    124    * 
    125    * @param string Object name 
    126    * @param string Object ID 
    127    */ 
    128   function add_gui_object($obj, $id) 
    129   { 
    130     $this->add_script(JS_OBJECT_NAME.".gui_object('$obj', '$id');"); 
    131   } 
    132  
    133  
    134   /** 
    135    * Call a client method 
    136    * 
    137    * @param string Method to call 
    138    * @param ... Additional arguments 
    139    */ 
    140   function command() 
    141   { 
    142     $this->js_commands[] = func_get_args(); 
    143   } 
    144  
    145  
    146   /** 
    147    * Invoke display_message command 
    148    */ 
    149   function show_message($message, $type='notice', $vars=NULL) 
    150   { 
    151     $this->command( 
    152       'display_message', 
    153       rcube_label(array('name' => $message, 'vars' => $vars)), 
    154       $type); 
    155   } 
    156  
    157  
    158   /** 
    159    * Delete all stored env variables and commands 
    160    */ 
    161   function reset() 
    162   { 
    163     $this->env = array(); 
    164     $this->js_env = array(); 
    165     $this->js_commands = array(); 
    166     $this->object_handlers = array(); 
    167     parent::reset(); 
    168   } 
    169  
    170   /** 
    171    * Send the request output to the client. 
    172    * This will either parse a skin tempalte or send an AJAX response 
    173    * 
    174    * @param string  Template name 
    175    * @param boolean True if script should terminate (default) 
    176    */ 
     111    /** 
     112     * Register a list of template object handlers 
     113     * 
     114     * @param  array Hash array with object=>handler pairs 
     115     * @return void 
     116     */ 
     117    function add_handlers($arr) 
     118    { 
     119        $this->object_handlers = array_merge($this->object_handlers, $arr); 
     120    } 
     121 
     122    /** 
     123     * Register a GUI object to the client script 
     124     * 
     125     * @param  string Object name 
     126     * @param  string Object ID 
     127     * @return void 
     128     */ 
     129    function add_gui_object($obj, $id) 
     130    { 
     131        $this->add_script(JS_OBJECT_NAME.".gui_object('$obj', '$id');"); 
     132    } 
     133 
     134    /** 
     135     * Call a client method 
     136     * 
     137     * @param string Method to call 
     138     * @param ... Additional arguments 
     139     */ 
     140    function command() 
     141    { 
     142        $this->js_commands[] = func_get_args(); 
     143    } 
     144 
     145    /** 
     146     * Invoke display_message command 
     147     * 
     148     * @param  string $message 
     149     * @param  string $type 
     150     * @param  mixed  $vars 
     151     * @return void 
     152     * @uses   self::command() 
     153     */ 
     154    function show_message($message, $type='notice', $vars=NULL) 
     155    { 
     156        $this->command( 
     157                'display_message', 
     158                rcube_label(array('name' => $message, 'vars' => $vars)), 
     159                $type 
     160        ); 
     161    } 
     162 
     163    /** 
     164     * Delete all stored env variables and commands 
     165     * 
     166     * @access public 
     167     * @return void 
     168     * @uses   rcube_html::reset() 
     169     * @uses   self::$env 
     170     * @uses   self::$js_env 
     171     * @uses   self::$js_commands 
     172     * @uses   self::$object_handlers 
     173     */ 
     174    public function reset() 
     175    { 
     176        $this->env = array(); 
     177        $this->js_env = array(); 
     178        $this->js_commands = array(); 
     179        $this->object_handlers = array(); 
     180        parent::reset(); 
     181    } 
     182 
     183    /** 
     184     * Send the request output to the client. 
     185     * This will either parse a skin tempalte or send an AJAX response 
     186     * 
     187     * @access public 
     188     * @param  string  $templ Template name 
     189     * @param  boolean $exit True if script should terminate (default) 
     190     */ 
    177191    function send($templ=null, $exit=true) 
    178192    { 
     
    195209 
    196210 
    197   /** 
    198    * Send an AJAX response with executable JS code 
    199    * 
    200    * @param string  Additional JS code 
    201    * @param boolean True if output buffer should be flushed 
    202    */ 
    203   function remote_response($add='', $flush=false) 
    204   { 
    205     static $s_header_sent = FALSE; 
    206  
    207     if (!$s_header_sent) 
    208     { 
    209       $s_header_sent = TRUE; 
    210       send_nocacheing_headers(); 
    211       header('Content-Type: application/x-javascript; charset='.RCMAIL_CHARSET); 
    212       print '/** ajax response ['.date('d/M/Y h:i:s O')."] **/\n"; 
    213     } 
    214  
    215     // unset default env vars 
    216     unset($this->js_env['task'], $this->js_env['action'], $this->js_env['comm_path']); 
    217  
    218     // send response code 
    219     echo rc_main::rcube_charset_convert($this->get_js_commands() . $add, RCMAIL_CHARSET, $this->get_charset()); 
    220  
    221     if ($flush)  // flush the output buffer 
    222       flush(); 
    223   } 
    224  
    225  
    226   /** 
    227    * @override 
    228    */ 
     211    /** 
     212     * Send an AJAX response with executable JS code 
     213     * 
     214     * @param  string  Additional JS code 
     215     * @param  boolean True if output buffer should be flushed 
     216     * @return void 
     217     */ 
     218    function remote_response($add='', $flush=false) 
     219    { 
     220        static $s_header_sent = FALSE; 
     221 
     222        if (!$s_header_sent) { 
     223            $s_header_sent = TRUE; 
     224            send_nocacheing_headers(); 
     225            header('Content-Type: application/x-javascript; charset='.RCMAIL_CHARSET); 
     226            print '/** ajax response ['.date('d/M/Y h:i:s O')."] **/\n"; 
     227        } 
     228 
     229        // unset default env vars 
     230        unset($this->js_env['task'], $this->js_env['action'], $this->js_env['comm_path']); 
     231 
     232        // send response code 
     233        echo rc_main::rcube_charset_convert( 
     234                $this->get_js_commands() . $add, 
     235                RCMAIL_CHARSET, 
     236                $this->get_charset() 
     237        ); 
     238 
     239        if ($flush) {  // flush the output buffer 
     240            flush(); 
     241        } 
     242    } 
     243 
     244    /** 
     245     * @override 
     246     */ 
    229247    function write($template='') 
    230248    { 
     
    237255        parent::write($template, $this->config['skin_path']); 
    238256    } 
    239  
    240257 
    241258    /** 
     
    360377    } 
    361378 
     379    /** 
     380     * Public wrapper to dipp into template parsing. 
     381     * 
     382     * @access public 
     383     * @param  string $input 
     384     * @return string 
     385     * @uses   rcmail_template::parse_conditions() 
     386     * @since  0.1-rc1 
     387     */ 
     388    public function just_parse($input) 
     389    { 
     390        return $this->parse_xml($input); 
     391    } 
    362392 
    363393    /** 
     
    368398     * @return string 
    369399     */ 
    370     function parse_conditions($input) 
     400    protected function parse_conditions($input) 
    371401    { 
    372402        $matches = preg_split( 
     
    440470    * @todo   Maybe a cache. 
    441471    */ 
    442    function parse_xml($input) 
     472   protected function parse_xml($input) 
    443473   { 
    444474        return preg_replace('/<roundcube:([-_a-z]+)\s+([^>]+)>/Uie', "\$this->xml_command('\\1', '\\2')", $input); 
     
    454484     * @return Tag/Object content string 
    455485     */ 
    456     function xml_command($command, $str_attrib, $add_attrib=array()) 
     486    protected function xml_command($command, $str_attrib, $add_attrib=array()) 
    457487    { 
    458488        $command = strtolower($command); 
    459489        $attrib  = rc_main::parse_attrib_string($str_attrib) + $add_attrib; 
     490        //var_dump($attrib); exit; 
    460491 
    461492        //rc_main::tfk_debug("// $command"); 
     
    472503            // return a button 
    473504            case 'button': 
    474                 if ($attrib['command']) 
    475                 return $this->button($attrib); 
     505                if ($attrib['command']) { 
     506                    return $this->button($attrib); 
     507                } 
    476508                break; 
    477509 
    478510            // show a label 
    479511            case 'label': 
    480                 if ($attrib['name'] || $attrib['command']) 
    481                     return rc_main::Q(rcube_label($attrib + array('vars' => array('product' => $this->config['product_name'])))); 
     512                if ($attrib['name'] || $attrib['command']) { 
     513                    return rc_main::Q( 
     514                                rcube_label( 
     515                                    $attrib + array('vars' => array('product' => $this->config['product_name'])) 
     516                                ) 
     517                    ); 
     518                } 
    482519                break; 
    483520 
     
    520557                $object = strtolower($attrib['name']); 
    521558 
     559                rc_main::tfk_debug("// object: $object"); 
     560                rc_main::tfk_debug(var_export($this->object_handlers[$object], true)); 
     561 
    522562                // execute object handler function 
    523563                if ($this->object_handlers[$object] && function_exists($this->object_handlers[$object])) { 
     
    562602     * Create and register a button 
    563603     * 
     604     * @access public 
    564605     * @param  array Button attributes 
    565606     * @return HTML button 
     
    567608     * @todo   Remove all sprintf()'s - they are pretty, but also slow. 
    568609     */ 
    569     function button($attrib) 
     610    public function button($attrib) 
    570611    { 
    571612        $registry   = rc_registry::getInstance(); 
     
    755796        // generate html code for button 
    756797        if ($btn_content) { 
     798            if ($command == 'logout') { 
     799                $btn_content = '<span>Hallo ' . $_SESSION['username'] . ', ' . $btn_content . '</span>'; 
     800            }             
    757801            $attrib_str = rc_main::create_attrib_string($attrib, $link_attrib); 
    758802            $out = sprintf('<a%s>%s</a>', $attrib_str, $btn_content); 
Note: See TracChangeset for help on using the changeset viewer.