Ignore:
Timestamp:
Aug 7, 2007 5:02:12 PM (6 years ago)
Author:
thomascube <thomas@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
4b9efbb
Parents:
93be5b7
Message:

Documentation, code style and cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • program/include/rcmail_template.inc

    r41bece1 r6d969b4  
    1111 | PURPOSE:                                                              | 
    1212 |   Class to handle HTML page output using a skin template.             | 
    13  |   Extends rcube_html_page class from rcube_shared.inc                 | 
     13 |   Extends rcube_html_page class from rcube_html.inc                   | 
    1414 |                                                                       | 
    1515 +-----------------------------------------------------------------------+ 
     
    2121*/ 
    2222 
    23 require_once('include/rcube_shared.inc'); 
    24  
    25  
     23 
     24/** 
     25 * Classes and functions for HTML output 
     26 * 
     27 * @package View 
     28 */ 
     29 
     30require_once('include/rcube_html.inc'); 
     31 
     32 
     33/** 
     34 * Class to create HTML page output using a skin template 
     35 */ 
    2636class rcmail_template extends rcube_html_page 
    2737{ 
     
    3747 
    3848 
    39   // PHP 5 constructor 
     49  /** 
     50   * Constructor 
     51   * 
     52   * @param array Configuration array 
     53   * @param string Current task 
     54   */ 
    4055  function __construct(&$config, $task) 
    4156  { 
    42     parent::__construct(); 
    43      
    4457    $this->task = $task; 
    4558    $this->config = $config; 
     
    6275  } 
    6376 
    64   // PHP 4 compatibility 
     77  /** 
     78   * PHP 4 compatibility 
     79   * @see rcmail_template::__construct() 
     80   */ 
    6581  function rcmail_template(&$config, $task) 
    6682  { 
     
    7187  /** 
    7288   * Set environment variable 
     89   * 
     90   * @param string Property name 
     91   * @param mixed Property value 
     92   * @param boolean True if this property should be added to client environment 
    7393   */ 
    7494  function set_env($name, $value, $addtojs=true) 
     
    136156  /** 
    137157   * Invoke display_message command 
     158   * 
     159   * @param string Message to display 
     160   * @param string Message type [notice|confirm|error] 
     161   * @param array Key-value pairs to be replaced in localized text 
    138162   */ 
    139163  function show_message($message, $type='notice', $vars=NULL) 
     
    212236   
    213237  /** 
    214    * @override 
     238   * Process template and write to stdOut 
     239   * 
     240   * @param string HTML template 
     241   * @see rcube_html_page::write() 
    215242   */ 
    216243  function write($template='') 
     
    274301  /** 
    275302   * Return executable javascript code for all registered commands 
    276    * @private 
     303   * @access private 
    277304   */ 
    278305  function get_js_commands() 
     
    301328  /** 
    302329   * Make URLs starting with a slash point to skin directory 
     330   * @access private 
    303331   */ 
    304332  function abs_url($str) 
     
    312340   
    313341  /** 
    314    * Replace all strings ($varname) with the content 
    315    * of the according global variable. 
     342   * Replace all strings ($varname) 
     343   * with the content of the according global variable. 
     344   * @access private 
    316345   */ 
    317346  function parse_with_globals($input) 
     
    324353  /** 
    325354   * Parse for conditional tags 
     355   * @access private 
    326356   */ 
    327357  function parse_conditions($input) 
     
    362392   * 
    363393   * @return True if condition is valid, False is not 
     394   * @access private 
    364395   */ 
    365396  function check_condition($condition) 
     
    380411   * @param string Input string to parse 
    381412   * @return Altered input string 
     413   * @access private 
    382414   */ 
    383415  function parse_xml($input) 
     
    393425   * @param string Attribute string 
    394426   * @return Tag/Object content string 
     427   * @access private 
    395428   */ 
    396429  function xml_command($command, $str_attrib, $add_attrib=array()) 
    397     { 
     430  { 
    398431    $command = strtolower($command); 
    399432    $attrib = parse_attrib_string($str_attrib) + $add_attrib; 
     
    438471 
    439472        else if ($object=='productname') 
    440           { 
     473        { 
    441474          $name = !empty($this->config['product_name']) ? $this->config['product_name'] : 'RoundCube Webmail'; 
    442475          return Q($name); 
    443           } 
     476        } 
    444477        else if ($object=='version') 
    445           { 
     478        { 
    446479          return (string)RCMAIL_VERSION; 
    447           } 
     480        } 
    448481        else if ($object=='pagetitle') 
    449           { 
     482        { 
    450483          $task = $this->task; 
    451484          $title = !empty($this->config['product_name']) ? $this->config['product_name'].' :: ' : ''; 
     
    459492 
    460493          return Q($title); 
    461           } 
     494        } 
    462495 
    463496        break; 
     
    465498 
    466499    return ''; 
    467     } 
     500  } 
    468501 
    469502 
     
    473506   * @param array Button attributes 
    474507   * @return HTML button 
     508   * @access private 
    475509   */ 
    476510  function button($attrib) 
    477     { 
     511  { 
    478512    global $CONFIG, $OUTPUT, $BROWSER, $MAIN_TASKS; 
    479513    static $sa_buttons = array(); 
     
    627661  } 
    628662 
    629 } 
     663}  // end class rcmail_template 
     664 
     665 
     666 
     667// ************** common functions delivering gui objects ************** 
     668 
     669 
     670/** 
     671 * Builder for GUI object 'message' 
     672 * 
     673 * @param array Named tag parameters 
     674 * @return string HTML code for the gui object 
     675 */ 
     676function rcmail_message_container($attrib) 
     677  { 
     678  global $OUTPUT; 
     679 
     680  if (!$attrib['id']) 
     681    $attrib['id'] = 'rcmMessageContainer'; 
     682 
     683  // allow the following attributes to be added to the <table> tag 
     684  $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id')); 
     685  $out = '<div' . $attrib_str . "></div>"; 
     686   
     687  $OUTPUT->add_gui_object('message', $attrib['id']); 
     688   
     689  return $out; 
     690  } 
     691 
     692 
     693/** 
     694 * GUI object 'username' 
     695 * Showing IMAP username of the current session 
     696 * 
     697 * @param array Named tag parameters (currently not used) 
     698 * @return string HTML code for the gui object 
     699 */ 
     700function rcmail_current_username($attrib) 
     701  { 
     702  global $DB; 
     703  static $s_username; 
     704 
     705  // alread fetched   
     706  if (!empty($s_username)) 
     707    return $s_username; 
     708 
     709  // get e-mail address form default identity 
     710  $sql_result = $DB->query( 
     711    "SELECT email AS mailto 
     712     FROM ".get_table_name('identities')." 
     713     WHERE  user_id=? 
     714     AND    standard=1 
     715     AND    del<>1", 
     716    $_SESSION['user_id']); 
     717                                    
     718  if ($DB->num_rows($sql_result)) 
     719    { 
     720    $sql_arr = $DB->fetch_assoc($sql_result); 
     721    $s_username = $sql_arr['mailto']; 
     722    } 
     723  else if (strstr($_SESSION['username'], '@')) 
     724    $s_username = $_SESSION['username']; 
     725  else 
     726    $s_username = $_SESSION['username'].'@'.$_SESSION['imap_host']; 
     727 
     728  return $s_username; 
     729  } 
     730 
     731 
     732/** 
     733 * GUI object 'loginform' 
     734 * Returns code for the webmail login form 
     735 * 
     736 * @param array Named parameters 
     737 * @return string HTML code for the gui object 
     738 */ 
     739function rcmail_login_form($attrib) 
     740  { 
     741  global $CONFIG, $OUTPUT, $SESS_HIDDEN_FIELD; 
     742   
     743  $labels = array(); 
     744  $labels['user'] = rcube_label('username'); 
     745  $labels['pass'] = rcube_label('password'); 
     746  $labels['host'] = rcube_label('server'); 
     747   
     748  $input_user = new textfield(array('name' => '_user', 'id' => 'rcmloginuser', 'size' => 30, 'autocomplete' => 'off')); 
     749  $input_pass = new passwordfield(array('name' => '_pass', 'id' => 'rcmloginpwd', 'size' => 30)); 
     750  $input_action = new hiddenfield(array('name' => '_action', 'value' => 'login')); 
     751     
     752  $fields = array(); 
     753  $fields['user'] = $input_user->show(get_input_value('_user', RCUBE_INPUT_POST)); 
     754  $fields['pass'] = $input_pass->show(); 
     755  $fields['action'] = $input_action->show(); 
     756   
     757  if (is_array($CONFIG['default_host'])) 
     758    { 
     759    $select_host = new select(array('name' => '_host', 'id' => 'rcmloginhost')); 
     760     
     761    foreach ($CONFIG['default_host'] as $key => $value) 
     762    { 
     763      if (!is_array($value)) 
     764        $select_host->add($value, (is_numeric($key) ? $value : $key)); 
     765      else 
     766        { 
     767        unset($select_host); 
     768        break; 
     769        } 
     770    } 
     771       
     772    $fields['host'] = isset($select_host) ? $select_host->show($_POST['_host']) : null; 
     773    } 
     774  else if (!strlen($CONFIG['default_host'])) 
     775    { 
     776    $input_host = new textfield(array('name' => '_host', 'id' => 'rcmloginhost', 'size' => 30)); 
     777    $fields['host'] = $input_host->show($_POST['_host']); 
     778    } 
     779 
     780  $form_name = strlen($attrib['form']) ? $attrib['form'] : 'form'; 
     781  $form_start = !strlen($attrib['form']) ? '<form name="form" action="./" method="post">' : ''; 
     782  $form_end = !strlen($attrib['form']) ? '</form>' : ''; 
     783   
     784  if ($fields['host']) 
     785    $form_host = <<<EOF 
     786     
     787</tr><tr> 
     788 
     789<td class="title"><label for="rcmloginhost">$labels[host]</label></td> 
     790<td>$fields[host]</td> 
     791 
     792EOF; 
     793 
     794  $OUTPUT->add_gui_object('loginform', $form_name); 
     795   
     796  $out = <<<EOF 
     797$form_start 
     798$SESS_HIDDEN_FIELD 
     799$fields[action] 
     800<table><tr> 
     801 
     802<td class="title"><label for="rcmloginuser">$labels[user]</label></td> 
     803<td>$fields[user]</td> 
     804 
     805</tr><tr> 
     806 
     807<td class="title"><label for="rcmloginpwd">$labels[pass]</label></td> 
     808<td>$fields[pass]</td> 
     809$form_host 
     810</tr></table> 
     811$form_end 
     812EOF; 
     813 
     814  return $out; 
     815  } 
     816 
     817 
     818/** 
     819 * GUI object 'charsetselector' 
     820 * 
     821 * @param array Named parameters for the select tag 
     822 * @return string HTML code for the gui object 
     823 */ 
     824function rcmail_charset_selector($attrib) 
     825  { 
     826  global $OUTPUT; 
     827   
     828  // pass the following attributes to the form class 
     829  $field_attrib = array('name' => '_charset'); 
     830  foreach ($attrib as $attr => $value) 
     831    if (in_array($attr, array('id', 'class', 'style', 'size', 'tabindex'))) 
     832      $field_attrib[$attr] = $value; 
     833       
     834  $charsets = array( 
     835    'US-ASCII'     => 'ASCII (English)', 
     836    'EUC-JP'       => 'EUC-JP (Japanese)', 
     837    'EUC-KR'       => 'EUC-KR (Korean)', 
     838    'BIG5'         => 'BIG5 (Chinese)', 
     839    'GB2312'       => 'GB2312 (Chinese)', 
     840    'ISO-2022-JP'  => 'ISO-2022-JP (Japanese)', 
     841    'ISO-8859-1'   => 'ISO-8859-1 (Latin-1)', 
     842    'ISO-8859-2'   => 'ISO-8895-2 (Central European)', 
     843    'ISO-8859-7'   => 'ISO-8859-7 (Greek)', 
     844    'ISO-8859-9'   => 'ISO-8859-9 (Turkish)', 
     845    'Windows-1251' => 'Windows-1251 (Cyrillic)', 
     846    'Windows-1252' => 'Windows-1252 (Western)', 
     847    'Windows-1255' => 'Windows-1255 (Hebrew)', 
     848    'Windows-1256' => 'Windows-1256 (Arabic)', 
     849    'Windows-1257' => 'Windows-1257 (Baltic)', 
     850    'UTF-8'        => 'UTF-8' 
     851    ); 
     852 
     853  $select = new select($field_attrib); 
     854  $select->add(array_values($charsets), array_keys($charsets)); 
     855   
     856  $set = $_POST['_charset'] ? $_POST['_charset'] : $OUTPUT->get_charset(); 
     857  return $select->show($set); 
     858  } 
     859 
     860 
     861/** 
     862 * GUI object 'searchform' 
     863 * Returns code for search function 
     864 * 
     865 * @param array Named parameters 
     866 * @return string HTML code for the gui object 
     867 */ 
     868function rcmail_search_form($attrib) 
     869  { 
     870  global $OUTPUT; 
     871 
     872  // add some labels to client 
     873  rcube_add_label('searching'); 
     874 
     875  $attrib['name'] = '_q'; 
     876 
     877  if (empty($attrib['id'])) 
     878    $attrib['id'] = 'rcmqsearchbox'; 
     879 
     880  $input_q = new textfield($attrib); 
     881  $out = $input_q->show(); 
     882 
     883  $OUTPUT->add_gui_object('qsearchbox', $attrib['id']); 
     884 
     885  // add form tag around text field 
     886  if (empty($attrib['form'])) 
     887    $out = sprintf( 
     888      '<form name="rcmqsearchform" action="./" '. 
     889      'onsubmit="%s.command(\'search\');return false" style="display:inline;">%s</form>', 
     890      JS_OBJECT_NAME, 
     891      $out); 
     892 
     893  return $out; 
     894  }  
     895 
    630896 
    631897?> 
Note: See TracChangeset for help on using the changeset viewer.