Changeset 2287 in subversion


Ignore:
Timestamp:
Feb 10, 2009 6:14:03 PM (4 years ago)
Author:
thomasb
Message:

Init plugins AFTER output object was created + make localized texts available on the client

Location:
branches/devel-api
Files:
2 added
12 edited

Legend:

Unmodified
Added
Removed
  • branches/devel-api/index.php

    r2266 r2287  
    33 +-------------------------------------------------------------------------+ 
    44 | RoundCube Webmail IMAP Client                                           | 
    5  | Version 0.3-20090201                                                    | 
     5 | Version 0.3-20090210                                                    | 
    66 |                                                                         | 
    77 | Copyright (C) 2005-2009, RoundCube Dev. - Switzerland                   | 
     
    3636// init output class 
    3737$OUTPUT = !empty($_REQUEST['_remote']) ? $RCMAIL->init_json() : $RCMAIL->load_gui(!empty($_REQUEST['_framed'])); 
     38 
     39// init plugin API 
     40$RCMAIL->plugins->init(); 
    3841 
    3942// set output buffering 
  • branches/devel-api/plugins/markasjunk/markasjunk.js

    r2285 r2287  
    1717     
    1818    // create button 
    19     var button = $('<A>').html('<img src="plugins/markasjunk/junk_pas.png" id="rcmButtonMarkAsJunk" width="32" height="32" alt="" title="" />').css('cursor', 'pointer'); 
     19    var button = $('<A>').html('<img src="plugins/markasjunk/junk_pas.png" id="rcmButtonMarkAsJunk" width="32" height="32" alt="" title="'+rcmail.gettext('buttontitle', 'markasjunk')+'" />').css('cursor', 'pointer'); 
    2020    button.bind('click', function(e){ return rcmail.command('plugin.markasjunk', this) }); 
    2121     
  • branches/devel-api/plugins/markasjunk/markasjunk.php

    r2279 r2287  
    1515     
    1616    $rcmail = rcmail::get_instance(); 
    17     if ($rcmail->action == '' || $rcmail->action == 'show') 
     17    if ($rcmail->action == '' || $rcmail->action == 'show') { 
    1818      $this->include_script('markasjunk.js'); 
     19      $this->add_texts('localization', true); 
     20    } 
    1921  } 
    2022 
    2123  function request_action() 
    2224  { 
    23     $rcmail = rcmail::get_instance(); 
     25    $this->add_texts('localization'); 
    2426     
    25     $count = sizeof(explode(',', ($uids = get_input_value('_uid', RCUBE_INPUT_POST)))); 
     27    $uids = get_input_value('_uid', RCUBE_INPUT_POST); 
    2628    $mbox = get_input_value('_mbox', RCUBE_INPUT_POST); 
    2729     
     30    $rcmail = rcmail::get_instance(); 
    2831    $rcmail->imap->set_flag($uids, 'JUNK'); 
    2932     
     
    3235    } 
    3336     
    34     $rcmail->output->show_message('reportedasspam', 'confirmation'); 
     37    $rcmail->output->command('display_message', $this->gettext('reportedasjunk'), 'confirmation'); 
    3538    $rcmail->output->send(); 
    3639  } 
  • branches/devel-api/plugins/userinfo/localization/de_CH.inc

    r2279 r2287  
    22 
    33$labels = array(); 
     4$labels['userinfo'] = 'Benutzerinfo'; 
    45$labels['created'] = 'Erstellt'; 
    56$labels['lastlogin'] = 'Letztes Login'; 
  • branches/devel-api/plugins/userinfo/localization/en_US.inc

    r2279 r2287  
    22 
    33$labels = array(); 
     4$labels['userinfo'] = 'User info'; 
    45$labels['created'] = 'Created'; 
    56$labels['lastlogin'] = 'Last Login'; 
  • branches/devel-api/plugins/userinfo/userinfo.js

    r2285 r2287  
    66    var tab = $('<span>').attr('id', 'settingstabpluginuserinfo').addClass('tablink'); 
    77     
    8     var button = $('<a>').attr('href', rcmail.env.comm_path+'&_action=plugin.userinfo').html('Userinfo').appendTo(tab); 
     8    var button = $('<a>').attr('href', rcmail.env.comm_path+'&_action=plugin.userinfo').html(rcmail.gettext('userinfo', 'userinfo')).appendTo(tab); 
    99    button.bind('click', function(e){ return rcmail.command('plugin.userinfo', this) }); 
    1010     
  • branches/devel-api/plugins/userinfo/userinfo.php

    r2279 r2287  
    1111  function init() 
    1212  { 
    13     $this->add_texts('localization/'); 
     13    $this->add_texts('localization/', array('userinfo')); 
    1414    $this->register_action('plugin.userinfo', array($this, 'infostep')); 
    1515    $this->include_script('userinfo.js'); 
  • branches/devel-api/program/include/rcmail.php

    r2279 r2287  
    320320    $this->output->add_label('loading'); 
    321321     
    322     // load plugins stuff 
    323     $this->plugins->init_gui($this->output); 
    324      
    325322    return $this->output; 
    326323  } 
  • branches/devel-api/program/include/rcube_plugin.php

    r2285 r2287  
    6262   * 
    6363   * @param string Directory to search in 
    64    * @param string Domain to save texts 
     64   * @param mixed Make texts also available on the client (array with list or true for all) 
    6565   */ 
    66   public function add_texts($dir) 
     66  public function add_texts($dir, $add2client = false) 
    6767  { 
    68     if (empty($domain)) 
    69       $domain = $this->ID; 
     68    $domain = $this->ID; 
    7069     
    7170    $lang = $_SESSION['language']; 
     
    8685      $rcmail = rcmail::get_instance(); 
    8786      $rcmail->load_language($lang, $add); 
     87       
     88      // add labels to client 
     89      if ($add2client) { 
     90        $js_labels = is_array($add2client) ? array_map(array($this, 'label_map_callback'), $add2client) : array_keys($add); 
     91        $rcmail->output->add_label($js_labels); 
     92      } 
    8893    } 
    8994  } 
     
    9196  /** 
    9297   * Wrapper for rcmail::gettext() adding the plugin ID as domain 
     98   * 
     99   * @return string Localized text 
     100   * @see rcmail::gettext() 
    93101   */ 
    94102  function gettext($p) 
     
    155163  } 
    156164 
     165  /** 
     166   * Callback function for array_map 
     167   */ 
     168  private function label_map_callback($key) 
     169  { 
     170    return $this->ID.'.'.$key; 
     171  } 
     172 
    157173 
    158174} 
  • branches/devel-api/program/include/rcube_plugin_api.php

    r2285 r2287  
    3636  private $actions = array(); 
    3737  private $actionmap = array(); 
    38   private $templobjects = array(); 
    3938  private $objectsmap = array(); 
    40   private $scripts = array(); 
    41   private $stylesheets = array(); 
    4239  private $output; 
    4340   
     
    7067     
    7168    $this->dir = realpath($rcmail->config->get('plugins_dir')); 
    72      
    73     // load all enabled plugins 
     69  } 
     70   
     71   
     72  /** 
     73   * Load and init all enabled plugins 
     74   * 
     75   * This has to be done after rcmail::load_gui() or rcmail::init_json() 
     76   * was called because plugins need to have access to rcmail->output 
     77   */ 
     78  public function init() 
     79  { 
     80    $rcmail = rcmail::get_instance(); 
     81    $this->output = $rcmail->output; 
     82     
    7483    $plugins_dir = dir($this->dir); 
    7584    $plugins_enabled = (array)$rcmail->config->get('plugins', array()); 
     
    104113   
    105114  /** 
    106    * Add GUI things once the output objects is created 
    107    */ 
    108   public function init_gui($output) 
    109   { 
    110     if ($output->type == 'html') { 
    111       $output->add_handlers($this->objectsmap); 
    112        
    113       foreach ($this->stylesheets as $css) 
    114         $output->add_header(html::tag('link', array('rel' => "stylesheet", 'type' => "text/css", 'href' => $css))); 
    115        
    116       foreach ($this->scripts as $script) 
    117         $output->add_header(html::tag('script', array('type' => "text/javascript", 'src' => $script))); 
    118     } 
    119      
    120     $this->output = $output; 
    121   } 
    122    
    123    
    124   /** 
    125115   * Allows a plugin object to register a callback for a certain hook 
    126116   * 
     
    218208    // can register handler only if it's not taken or registered by myself 
    219209    if (!isset($this->objectsmap[$name]) || $this->objectsmap[$name] == $owner) { 
    220       // output is ready 
    221       if ($this->output) { 
    222         $this->output->add_handler($name, $callback); 
    223       } 
    224       else { 
    225         $this->templobjects[$name] = $callback; 
    226         $this->objectsmap[$name] = $owner; 
    227       } 
     210      $this->output->add_handler($name, $callback); 
     211      $this->objectsmap[$name] = $owner; 
    228212    } 
    229213    else { 
     
    237221  public function include_script($fn) 
    238222  { 
    239     $src = $this->ressource_url($fn); 
    240      
    241     if ($this->output) 
     223    if ($this->output->type == 'html') { 
     224      $src = $this->ressource_url($fn); 
    242225      $this->output->add_header(html::tag('script', array('type' => "text/javascript", 'src' => $src))); 
    243     else 
    244       $this->scripts[] = $src; 
     226    } 
    245227  } 
    246228 
     
    250232  public function include_stylesheet($fn) 
    251233  { 
    252     $src = $this->ressource_url($fn); 
    253      
    254     if ($this->output) 
     234    if ($this->output->type == 'html') { 
     235      $src = $this->ressource_url($fn); 
    255236      $this->output->add_header(html::tag('link', array('rel' => "stylesheet", 'type' => "text/css", 'href' => $src))); 
    256     else 
    257       $this->stylesheets[] = $src; 
     237    } 
    258238  } 
    259239   
  • branches/devel-api/program/include/rcube_template.php

    r2285 r2287  
    210210    public function add_label() 
    211211    { 
    212         $arg_list = func_get_args(); 
    213         foreach ($arg_list as $i => $name) { 
     212        $args = func_get_args(); 
     213        if (count($args) == 1 && is_array($args[0])) 
     214          $args = $args[0]; 
     215         
     216        foreach ($args as $name) { 
    214217            $this->command('add_label', $name, rcube_label($name)); 
    215218        } 
  • branches/devel-api/program/js/app.js

    r2285 r2287  
    11591159 
    11601160  // return a localized string 
    1161   this.get_label = function(name) 
    1162     { 
    1163     if (this.labels[name]) 
     1161  this.get_label = function(name, domain) 
     1162    { 
     1163    if (domain && this.labels[domain+'.'+name]) 
     1164      return this.labels[domain+'.'+name]; 
     1165    else if (this.labels[name]) 
    11641166      return this.labels[name]; 
    11651167    else 
    11661168      return name; 
    11671169    }; 
     1170   
     1171  // alias for convenience reasons 
     1172  this.gettext = this.get_label; 
    11681173 
    11691174  // switch to another application task 
Note: See TracChangeset for help on using the changeset viewer.