Changeset 05a631a in github


Ignore:
Timestamp:
Jun 3, 2010 2:40:06 AM (3 years ago)
Author:
thomascube <thomas@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
bb8721aa
Parents:
ae8a2a55
Message:

Allow plugins to register their own tasks

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • index.php

    r3544558 r05a631a  
    243243  $stepfile = !empty($action_map[$RCMAIL->task][$RCMAIL->action]) ? 
    244244    $action_map[$RCMAIL->task][$RCMAIL->action] : strtr($RCMAIL->action, '-', '_') . '.inc'; 
    245  
     245     
    246246  // execute a plugin action 
    247   if (preg_match('/^plugin\./', $RCMAIL->action)) { 
     247  if ($RCMAIL->plugins->is_plugin_task($RCMAIL->task)) { 
     248    $RCMAIL->plugins->exec_action($RCMAIL->task.'.'.$RCMAIL->action); 
     249    break; 
     250  } 
     251  else if (preg_match('/^plugin\./', $RCMAIL->action)) { 
    248252    $RCMAIL->plugins->exec_action($RCMAIL->action); 
    249253    break; 
  • program/include/rcube_plugin.php

    rd062dbe r05a631a  
    3232  protected $home; 
    3333  protected $urlbase; 
     34  private $mytask; 
    3435 
    3536  /** 
     
    135136  public function register_task($task) 
    136137  { 
    137     if ($task != asciiwords($task)) { 
    138       raise_error(array('code' => 526, 'type' => 'php', 
    139         'file' => __FILE__, 'line' => __LINE__, 
    140         'message' => "Invalid task name: $task. Only characters [a-z0-9_.-] are allowed"), true, false); 
    141     } 
    142     else if (in_array(rcmail::$main_tasks, $task)) { 
    143       raise_error(array('code' => 526, 'type' => 'php', 
    144         'file' => __FILE__, 'line' => __LINE__, 
    145         'message' => "Cannot register taks $task; already taken by another plugin or the application itself"), true, false); 
    146     } 
    147     else { 
    148       rcmail::$main_tasks[] = $task; 
    149     } 
     138    if ($this->api->register_task($task, $this->ID)) 
     139      $this->mytask = $task; 
    150140  } 
    151141 
     
    160150  public function register_action($action, $callback) 
    161151  { 
    162     $this->api->register_action($action, $this->ID, $callback); 
     152    $this->api->register_action($action, $this->ID, $callback, $this->mytask); 
    163153  } 
    164154 
  • program/include/rcube_plugin_api.php

    rd062dbe r05a631a  
    3535  public $handlers = array(); 
    3636  private $plugins = array(); 
     37  private $tasks = array(); 
    3738  private $actions = array(); 
    3839  private $actionmap = array(); 
     
    207208   * @param string Plugin name that registers this action 
    208209   * @param mixed Callback: string with global function name or array($obj, 'methodname') 
    209    */ 
    210   public function register_action($action, $owner, $callback) 
     210   * @param string Task name registered by this plugin 
     211   */ 
     212  public function register_action($action, $owner, $callback, $task = null) 
    211213  { 
    212214    // check action name 
    213     if (strpos($action, 'plugin.') !== 0) 
     215    if ($task) 
     216      $action = $task.'.'.$action; 
     217    else if (strpos($action, 'plugin.') !== 0) 
    214218      $action = 'plugin.'.$action; 
    215219     
     
    273277   
    274278  /** 
     279   * Register this plugin to be responsible for a specific task 
     280   * 
     281   * @param string Task name (only characters [a-z0-9_.-] are allowed) 
     282   * @param string Plugin name that registers this action 
     283   */ 
     284  public function register_task($task, $owner) 
     285  { 
     286    if ($task != asciiwords($task)) { 
     287      raise_error(array('code' => 526, 'type' => 'php', 
     288        'file' => __FILE__, 'line' => __LINE__, 
     289        'message' => "Invalid task name: $task. Only characters [a-z0-9_.-] are allowed"), true, false); 
     290    } 
     291    else if (in_array($task, rcmail::$main_tasks)) { 
     292      raise_error(array('code' => 526, 'type' => 'php', 
     293        'file' => __FILE__, 'line' => __LINE__, 
     294        'message' => "Cannot register taks $task; already taken by another plugin or the application itself"), true, false); 
     295    } 
     296    else { 
     297      $this->tasks[$task] = $owner; 
     298      rcmail::$main_tasks[] = $task; 
     299      return true; 
     300    } 
     301     
     302    return false; 
     303  } 
     304 
     305 
     306  /** 
     307   * Checks whether the given task is registered by a plugin 
     308   * 
     309   * @return boolean True if registered, otherwise false 
     310   */ 
     311  public function is_plugin_task($task) 
     312  { 
     313    return $this->tasks[$task] ? true : false; 
     314  } 
     315 
     316 
     317  /** 
    275318   * Check if a plugin hook is currently processing. 
    276319   * Mainly used to prevent loops and recursion. 
Note: See TracChangeset for help on using the changeset viewer.