From f06e661a9bd2cde41c9974896bb5f819469dad14 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 3 Feb 2011 10:36:25 -0500 Subject: [PATCH] new methods for paths to plugin static files --- README | 17 +++++++++++++++++ lib/default.php | 3 +++ lib/plugin.php | 43 +++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/README b/README index d972bf5676..b71d21aba5 100644 --- a/README +++ b/README @@ -1572,6 +1572,23 @@ proxy_user: Username to use for authenticating to the HTTP proxy. Default null. proxy_password: Password to use for authenticating to the HTTP proxy. Default null. proxy_auth_scheme: Scheme to use for authenticating to the HTTP proxy. Default null. +plugins +------- + +default: associative array mapping plugin name to array of arguments. To disable + a default plugin, unset its value in this array. +locale_path: path for finding plugin locale files. In the plugin's directory + by default. +server: Server to find static files for a plugin when the page is plain old HTTP. + Defaults to site/server (same as pages). Use this to move plugin CSS and + JS files to a CDN. +sslserver: Server to find static files for a plugin when the page is HTTPS. Defaults + to site/server (same as pages). Use this to move plugin CSS and JS files + to a CDN. +path: Path to the plugin files. defaults to site/path + '/plugins/'. Expects that + each plugin will have a subdirectory at plugins/NameOfPlugin. Change this + if you're using a CDN. + Plugins ======= diff --git a/lib/default.php b/lib/default.php index 2ddc47bd17..7d8b1fec7a 100644 --- a/lib/default.php +++ b/lib/default.php @@ -314,6 +314,9 @@ $default = 'RSSCloud' => null, 'OpenID' => null), 'locale_path' => false, // Set to a path to use *instead of* each plugin's own locale subdirectories + 'server' => null, + 'sslserver' => null, + 'path' => null, ), 'admin' => array('panels' => array('design', 'site', 'user', 'paths', 'access', 'sessions', 'sitenotice', 'license')), diff --git a/lib/plugin.php b/lib/plugin.php index 3f84afa27e..1ca5deb5c5 100644 --- a/lib/plugin.php +++ b/lib/plugin.php @@ -110,11 +110,16 @@ class Plugin { $this->log(LOG_DEBUG, $msg); } + + function name() + { + $cls = get_class($this); + return mb_substr($cls, 0, -6); + } function onPluginVersion(&$versions) { - $cls = get_class($this); - $name = mb_substr($cls, 0, -6); + $name = $this->name(); $versions[] = array('name' => $name, // TRANS: Displayed as version information for a plugin if no version information was found. @@ -122,4 +127,38 @@ class Plugin return true; } + + function path($relative) + { + return self::staticPath($this->name(), $relative); + } + + static function staticPath($plugin, $relative) + { + $isHTTPS = StatusNet::isHTTPS(); + + if ($isHTTPS) { + $server = common_config('plugins', 'sslserver'); + } else { + $server = common_config('plugins', 'server'); + } + + if (is_null($server)) { + if ($isHTTPS) { + $server = common_config('site', 'sslserver'); + } else { + $server = common_config('site', 'server'); + } + } + + $path = common_config('plugins', 'path'); + + if (is_null($path)) { + $path = common_config('site', 'path') . '/plugins/'; + } + + $protocol = ($isHTTPS) ? 'https' : 'http'; + + return $protocol.'://'.$server.$path.$plugin.'/'.$relative; + } } -- 2.39.5