Roundcube Community Forum

News and Announcements => General Discussion => Topic started by: realtime on October 09, 2009, 05:50:33 AM

Title: set product_name at runtime
Post by: realtime on October 09, 2009, 05:50:33 AM
Hello!

The product_name can be set in the configfile with $rcmail_config['product_name']. But I want to set it in my plugin at runtime. So I added
    $this->add_hook('startup', array($this, 'set_title'));
to the init() function of my plugin and the following method to the class:
  function set_title($args)
  {
    $rcmail = rcmail::get_instance();
    $rcmail->config->set('product_name', 'JustATestString');

    return $args;
  }


The product_name seem to be set, but it is not displayed in the title of the Browser. What do I wrong?

Thanks,
Peter
Title: set product_name at runtime
Post by: realtime on October 11, 2009, 11:24:35 AM
Any ideas? Maybe there is an other way to manipulate the content of the browser title in a plugin than using the startup hook...?
Title: Changing product_name at runtime
Post by: ezequiel on December 01, 2009, 11:05:15 AM
Hello realtime!

I'm also interested in changing the logo images and product name at runtime. Our product (which offers webmail as well) has different names in English and Spanish.

I have simply edited the HTMLs and used labels to change the images displayed at login and in every RoundCube page header (login.html and header.html).

Unfortunately, plugins are loaded AFTER the page has been initialized with the product_name from the main.inc.php file, so I'm almost sure it's not possible to do it via plugins. Check out index.php:


// init application and start session with requested task
$RCMAIL = rcmail::get_instance();

// init output class
$OUTPUT = !empty($_REQUEST['_remote']) ? $RCMAIL->init_json() : $RCMAIL->load_gui(!empty($_REQUEST['_framed'])); //<- sets title HERE!

// init plugin API
$RCMAIL->plugins->init(); //<- initializes plugins AFTER that...
 

I think it's no other way but to add code before $OUTPUT is initialized...


// include environment
require_once 'program/include/iniset.php';

// init application and start session with requested task
$RCMAIL = rcmail::get_instance();

// use language label for title
$RCMAIL->config->set("product_name", rcube_label("product_name_label"));

// init output class
$OUTPUT = !empty($_REQUEST['_remote']) ? $RCMAIL->init_json() : $RCMAIL->load_gui(!empty($_REQUEST['_framed']));

// init plugin API
$RCMAIL->plugins->init();


I don't like having to add modifications to the original Roundcube files, but I couldn't find any other way.

Greetings!
Ezequiel.

@edit: formatting code to PHP-code
Title: set product_name at runtime
Post by: rosali on December 01, 2009, 03:11:33 PM
Try this ... not tested:

  function set_title($args)
  {
    $rcmail = rcmail::get_instance();
    $arr = array_merge($rcmail->config->all(),array('product_name', 'JustATestString'));
    $rcmail->config->merge($arr);
    return $args;
  }  



I'm doing something similar in my plugins with the following code:


  function _load_config()
  {
    $rcmail = rcmail::get_instance();
    $config = "plugins/hmail_forwarding/config/config.inc.php";
    if(file_exists($config))
      include $config;
    else if(file_exists($config . ".dist"))
      include $config . ".dist";
    if(is_array($rcmail_config)){
      if(is_array($rcmail_config['settingsnav']) && is_array($rcmail->config->get('settingsnav'))){
        $nav = array_merge($rcmail->config->get('settingsnav'), $rcmail_config['settingsnav']);
        $rcmail_config['settingsnav'] = $nav;
      }
      $arr = array_merge($rcmail->config->all(),$rcmail_config);
      $rcmail->config->merge($arr);
    }
  }
Title: set product_name at runtime
Post by: nillkasra on December 03, 2009, 03:23:20 PM
I accept with code:function set_title($args)
  {
    $rcmail = rcmail::get_instance();
    $rcmail->config->set('product_name', 'JustATestString');

    return $args;
  }