From 1c932d58b57930ce527a77e885ace5b430a60883 Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Sun, 26 Apr 2009 12:33:22 -0400
Subject: [PATCH] Allow plugins to define their own tasks + add 'domain' parameter for rcube_template::button()

---
 program/include/rcube_plugin.php   |   22 ++++++++++++++++++++--
 program/include/rcmail.php         |   19 +++++++------------
 program/include/rcube_template.php |    6 +++---
 3 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/program/include/rcmail.php b/program/include/rcmail.php
index 603ac33..e660e52 100644
--- a/program/include/rcmail.php
+++ b/program/include/rcmail.php
@@ -91,7 +91,7 @@
     }
 
     // set task and action properties
-    $this->set_task(strip_quotes(get_input_value('_task', RCUBE_INPUT_GPC)));
+    $this->set_task(get_input_value('_task', RCUBE_INPUT_GPC));
     $this->action = asciiwords(get_input_value('_action', RCUBE_INPUT_GPC));
 
     // connect to database
@@ -145,14 +145,12 @@
    */
   public function set_task($task)
   {
-    if (!in_array($task, self::$main_tasks))
-      $task = 'mail';
-    
-    $this->task = $task;
-    $this->comm_path = $this->url(array('task' => $task));
+    $task = asciiwords($task);
+    $this->task = $task ? $task : 'mail';
+    $this->comm_path = $this->url(array('task' => $this->task));
     
     if ($this->output)
-      $this->output->set_env('task', $task);
+      $this->output->set_env('task', $this->task);
   }
   
   
@@ -936,11 +934,8 @@
   {
     if (!is_array($p))
       $p = array('_action' => @func_get_arg(0));
-      
-    $task = $p['_task'] ? $p['_task'] : $p['task'];
-    if (!$task || !in_array($task, rcmail::$main_tasks))
-      $task = $this->task;
-
+    
+    $task = $p['_task'] ? $p['_task'] : ($p['task'] ? $p['task'] : $this->task);
     $p['_task'] = $task;
     unset($p['task']);
 
diff --git a/program/include/rcube_plugin.php b/program/include/rcube_plugin.php
index 62f65a9..8aa4db6 100644
--- a/program/include/rcube_plugin.php
+++ b/program/include/rcube_plugin.php
@@ -101,11 +101,29 @@
    * @return string Localized text
    * @see rcmail::gettext()
    */
-  function gettext($p)
+  public function gettext($p)
   {
     return rcmail::get_instance()->gettext($p, $this->ID);
   }
-  
+
+  /**
+   * Register this plugin to be responsible for a specific task
+   *
+   * @param string Task name (only characters [a-z0-9_.-] are allowed)
+   */
+  public function register_task($task)
+  {
+    if ($task != asciiwords($task)) {
+      raise_error(array('code' => 526, 'type' => 'php', 'message' => "Invalid task name: $task. Only characters [a-z0-9_.-] are allowed"), true, false);
+    }
+    else if (in_array(rcmail::$main_tasks, $task)) {
+      raise_error(array('code' => 526, 'type' => 'php', 'message' => "Cannot register taks $task; already taken by another plugin or the application itself"), true, false);
+    }
+    else {
+      rcmail::$main_tasks[] = $task;
+    }
+  }
+
   /**
     * Register a handler for a specific client-request action
     *
diff --git a/program/include/rcube_template.php b/program/include/rcube_template.php
index 5de7738..307bd84 100755
--- a/program/include/rcube_template.php
+++ b/program/include/rcube_template.php
@@ -732,13 +732,13 @@
         }
         // get localized text for labels and titles
         if ($attrib['title']) {
-            $attrib['title'] = Q(rcube_label($attrib['title']));
+            $attrib['title'] = Q(rcube_label($attrib['title'], $attrib['domain']));
         }
         if ($attrib['label']) {
-            $attrib['label'] = Q(rcube_label($attrib['label']));
+            $attrib['label'] = Q(rcube_label($attrib['label'], $attrib['domain']));
         }
         if ($attrib['alt']) {
-            $attrib['alt'] = Q(rcube_label($attrib['alt']));
+            $attrib['alt'] = Q(rcube_label($attrib['alt'], $attrib['domain']));
         }
         // set title to alt attribute for IE browsers
         if ($this->browser->ie && $attrib['title'] && !$attrib['alt']) {

--
Gitblit v1.9.1