summaryrefslogtreecommitdiff
path: root/plugins/BitlyUrl/BitlyUrlPlugin.php
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/BitlyUrl/BitlyUrlPlugin.php')
-rw-r--r--plugins/BitlyUrl/BitlyUrlPlugin.php45
1 files changed, 43 insertions, 2 deletions
diff --git a/plugins/BitlyUrl/BitlyUrlPlugin.php b/plugins/BitlyUrl/BitlyUrlPlugin.php
index c9005e52e..93a35b3f3 100644
--- a/plugins/BitlyUrl/BitlyUrlPlugin.php
+++ b/plugins/BitlyUrl/BitlyUrlPlugin.php
@@ -39,6 +39,8 @@ class BitlyUrlPlugin extends UrlShortenerPlugin
{
public $shortenerName = 'bit.ly';
public $serviceUrl = 'http://bit.ly/api?method=shorten&version=2.0.1&longUrl=%s';
+ public $login; // To set a site-default when admins or users don't override it.
+ public $apiKey;
function onInitializePlugin(){
parent::onInitializePlugin();
@@ -48,6 +50,21 @@ class BitlyUrlPlugin extends UrlShortenerPlugin
}
/**
+ * Add bit.ly to the list of available URL shorteners if it's configured,
+ * otherwise leave it out.
+ *
+ * @param array $shorteners
+ * @return boolean hook return value
+ */
+ function onGetUrlShorteners(&$shorteners)
+ {
+ if ($this->getLogin() && $this->getApiKey()) {
+ return parent::onGetUrlShorteners($shorteners);
+ }
+ return true;
+ }
+
+ /**
* Short a URL
* @param url
* @return string shortened version of the url, or null if URL shortening failed
@@ -68,7 +85,11 @@ class BitlyUrlPlugin extends UrlShortenerPlugin
*/
protected function getLogin()
{
- return common_config('bitly', 'default_login');
+ $login = common_config('bitly', 'default_login');
+ if (!$login) {
+ $login = $this->login;
+ }
+ return $login;
}
/**
@@ -78,7 +99,11 @@ class BitlyUrlPlugin extends UrlShortenerPlugin
*/
protected function getApiKey()
{
- return common_config('bitly', 'default_apikey');
+ $key = common_config('bitly', 'default_apikey');
+ if (!$key) {
+ $key = $this->apiKey;
+ }
+ return $key;
}
/**
@@ -213,4 +238,20 @@ class BitlyUrlPlugin extends UrlShortenerPlugin
return true;
}
}
+
+ /**
+ * Internal hook point to check the default global credentials so
+ * the admin form knows if we have a fallback or not.
+ *
+ * @param string $login
+ * @param string $apiKey
+ * @return boolean hook return value
+ */
+ function onBitlyDefaultCredentials(&$login, &$apiKey)
+ {
+ $login = $this->login;
+ $apiKey = $this->apiKey;
+ return false;
+ }
+
}