From 2f8b1036da42ec3d15a51c6b17a473f9f4df71d3 Mon Sep 17 00:00:00 2001
From: Thomas Bruederli <bruederli@kolabsys.com>
Date: Sat, 07 Feb 2015 12:33:24 -0500
Subject: [PATCH] Bump version and copyright year

---
 program/lib/Roundcube/rcube_plugin.php |   68 +++++++++++++++++++++++++++++++---
 1 files changed, 62 insertions(+), 6 deletions(-)

diff --git a/program/lib/Roundcube/rcube_plugin.php b/program/lib/Roundcube/rcube_plugin.php
index d24a269..e240448 100644
--- a/program/lib/Roundcube/rcube_plugin.php
+++ b/program/lib/Roundcube/rcube_plugin.php
@@ -3,7 +3,7 @@
 /*
  +-----------------------------------------------------------------------+
  | This file is part of the Roundcube Webmail client                     |
- | Copyright (C) 2008-2012, The Roundcube Dev Team                       |
+ | Copyright (C) 2008-2014, The Roundcube Dev Team                       |
  |                                                                       |
  | Licensed under the GNU General Public License version 3 or            |
  | any later version with exceptions for skins & plugins.                |
@@ -71,6 +71,7 @@
     protected $home;
     protected $urlbase;
     private $mytask;
+    private $loaded_config = array();
 
 
     /**
@@ -94,7 +95,15 @@
     /**
      * Provide information about this
      *
-     * @return array Meta information about a plugin or false if not implemented
+     * @return array Meta information about a plugin or false if not implemented:
+     * As hash array with the following keys:
+     *      name: The plugin name
+     *    vendor: Name of the plugin developer
+     *   version: Plugin version name
+     *   license: License name (short form according to http://spdx.org/licenses/)
+     *       uri: The URL to the plugin homepage or source repository
+     *   src_uri: Direct download URL to the source code of this plugin
+     *   require: List of plugins required for this one (as array of plugin names)
      */
     public static function info()
     {
@@ -109,7 +118,18 @@
      */
     public function require_plugin($plugin_name)
     {
-        return $this->api->load_plugin($plugin_name);
+        return $this->api->load_plugin($plugin_name, true);
+    }
+
+    /**
+     * Attempt to load the given plugin which is optional for the current plugin
+     *
+     * @param string Plugin name
+     * @return boolean True on success, false on failure
+     */
+    public function include_plugin($plugin_name)
+    {
+        return $this->api->load_plugin($plugin_name, true, false);
     }
 
     /**
@@ -122,15 +142,25 @@
      */
     public function load_config($fname = 'config.inc.php')
     {
+        if (in_array($fname, $this->loaded_config)) {
+            return true;
+        }
+
+        $this->loaded_config[] = $fname;
+
         $fpath = $this->home.'/'.$fname;
         $rcube = rcube::get_instance();
 
-        if (is_file($fpath) && !$rcube->config->load_from_file($fpath)) {
+        if (($is_local = is_file($fpath)) && !$rcube->config->load_from_file($fpath)) {
             rcube::raise_error(array(
                 'code' => 527, 'type' => 'php',
                 'file' => __FILE__, 'line' => __LINE__,
                 'message' => "Failed to load config from $fpath"), true, false);
             return false;
+        }
+        else if (!$is_local) {
+            // Search plugin_name.inc.php file in any configured path
+            return $rcube->config->load_from_file($this->ID . '.inc.php');
         }
 
         return true;
@@ -227,7 +257,7 @@
             $rcube->load_language($lang, $add);
 
             // add labels to client
-            if ($add2client) {
+            if ($add2client && method_exists($rcube->output, 'add_label')) {
                 if (is_array($add2client)) {
                     $js_labels = array_map(array($this, 'label_map_callback'), $add2client);
                 }
@@ -236,6 +266,24 @@
                 }
                 $rcube->output->add_label($js_labels);
             }
+        }
+    }
+
+    /**
+     * Wrapper for add_label() adding the plugin ID as domain
+     */
+    public function add_label()
+    {
+        $rcube = rcube::get_instance();
+
+        if (method_exists($rcube->output, 'add_label')) {
+            $args = func_get_args();
+            if (count($args) == 1 && is_array($args[0])) {
+                $args = $args[0];
+            }
+
+            $args = array_map(array($this, 'label_map_callback'), $args);
+            $rcube->output->add_label($args);
         }
     }
 
@@ -372,7 +420,11 @@
     public function local_skin_path()
     {
         $rcube = rcube::get_instance();
-        foreach (array($rcube->config->get('skin'), 'larry') as $skin) {
+        $skins = array_keys((array)$rcube->output->skins);
+        if (empty($skins)) {
+            $skins = (array) $rcube->config->get('skin');
+        }
+        foreach ($skins as $skin) {
             $skin_path = 'skins/' . $skin;
             if (is_dir(realpath(slashify($this->home) . $skin_path))) {
                 break;
@@ -390,6 +442,10 @@
      */
     private function label_map_callback($key)
     {
+        if (strpos($key, $this->ID.'.') === 0) {
+            return $key;
+        }
+
         return $this->ID.'.'.$key;
     }
 }

--
Gitblit v1.9.1