From 1ad8c67843d5d81621012c9c2cbe7425cf6f5828 Mon Sep 17 00:00:00 2001 From: Samantha Doherty Date: Wed, 6 Oct 2010 16:30:43 -0400 Subject: [PATCH 01/10] A few quick theme fixes, mostly for IE. Full update to follow. --- theme/clean/css/display.css | 3 +- theme/clean/css/ie.css | 62 ++++++++++++++++++++++++++++++ theme/rebase/css/display.css | 1 + theme/rebase/css/ie.css | 5 +++ theme/shiny/css/display.css | 3 +- theme/shiny/css/ie.css | 67 ++++++++++++++++++++++++++++++++- theme/shiny/images/wrap_bg.png | Bin 0 -> 111 bytes 7 files changed, 137 insertions(+), 4 deletions(-) create mode 100644 theme/clean/css/ie.css create mode 100644 theme/shiny/images/wrap_bg.png diff --git a/theme/clean/css/display.css b/theme/clean/css/display.css index be72993b55..260ee5926a 100644 --- a/theme/clean/css/display.css +++ b/theme/clean/css/display.css @@ -117,7 +117,8 @@ address { top: 74px; right:0; height: 2.4em; - width: 106px; + width: 96px; + right: 10px; } #core { diff --git a/theme/clean/css/ie.css b/theme/clean/css/ie.css new file mode 100644 index 0000000000..ede8f078ad --- /dev/null +++ b/theme/clean/css/ie.css @@ -0,0 +1,62 @@ +/* IE specific styles */ + +/* base theme overrides */ + +input.checkbox, +input.radio { +top:0; +} +.form_notice textarea { + width: 364px; +} +.form_notice .form_note + label { +position:absolute; +top:25px; +left:83%; +text-indent:-9999px; +height:16px; +width:16px; +display:block; + top: 31px; + right: 88px; +} +.form_notice #notice_action-submit { + width: 96px; + max-width: 96px; +} +.form_notice #notice_data-attach_selected, +.form_notice #notice_data-geo_selected { +width:78.75%; +} +.form_notice #notice_data-attach_selected button, +.form_notice #notice_data-geo_selected button { +padding:0 4px; +} +.notice-options input.submit { +font-size:0; +text-align:right; +text-indent:0; +} +.notice div.entry-content .timestamp a { +margin-right:4px; +} +.entity_profile { +width:64%; +} +.notice { +z-index:1; +} +.notice:hover { +z-index:9999; +} +.notice .thumbnail img { +z-index:9999; +} + +.form_settings fieldset fieldset legend { +line-height:auto; +} + +.form_notice #notice_data-attach { +filter: alpha(opacity=0); +} diff --git a/theme/rebase/css/display.css b/theme/rebase/css/display.css index bc0b5a4f27..b532be5d03 100644 --- a/theme/rebase/css/display.css +++ b/theme/rebase/css/display.css @@ -196,6 +196,7 @@ address .poweredby { width: 485px; height: 63px; padding-bottom: 15px; + z-index: 9; } .form_notice label[for=notice_data-attach], diff --git a/theme/rebase/css/ie.css b/theme/rebase/css/ie.css index 48b5cd6af7..88985efb74 100644 --- a/theme/rebase/css/ie.css +++ b/theme/rebase/css/ie.css @@ -58,3 +58,8 @@ z-index:9999; .form_settings fieldset fieldset legend { line-height:auto; } + + +.form_notice #notice_data-attach { +filter: alpha(opacity=0); +} diff --git a/theme/shiny/css/display.css b/theme/shiny/css/display.css index 5b51b530dc..ec98a049c0 100644 --- a/theme/shiny/css/display.css +++ b/theme/shiny/css/display.css @@ -209,7 +209,8 @@ address { top: 74px; right:0; height: 2.4em; - width: 106px; + width: 96px; + right: 10px; } #content { diff --git a/theme/shiny/css/ie.css b/theme/shiny/css/ie.css index ca6c09d44e..3c8e2230d5 100644 --- a/theme/shiny/css/ie.css +++ b/theme/shiny/css/ie.css @@ -1,9 +1,72 @@ /* IE specific styles */ +/* IE specific styles */ + +/* base theme overrides */ + +input.checkbox, +input.radio { +top:0; +} +.form_notice textarea { + width: 374px; +} +.form_notice .form_note + label { +position:absolute; +top:25px; +left:83%; +text-indent:-9999px; +height:16px; +width:16px; +display:block; + top: 31px; + right: 88px; +} +.form_notice #notice_action-submit { + width: 96px; + max-width: 96px; +} +.form_notice #notice_data-attach_selected, +.form_notice #notice_data-geo_selected { +width:78.75%; +} +.form_notice #notice_data-attach_selected button, +.form_notice #notice_data-geo_selected button { +padding:0 4px; +} +.notice-options input.submit { +font-size:0; +text-align:right; +text-indent:0; +} +.notice div.entry-content .timestamp a { +margin-right:4px; +} +.entity_profile { +width:64%; +} +.notice { +z-index:1; +} +.notice:hover { +z-index:9999; +} +.notice .thumbnail img { +z-index:9999; +} + +.form_settings fieldset fieldset legend { +line-height:auto; +} + +.form_notice #notice_data-attach { +filter: alpha(opacity=0); +} + #wrap { - background-color: #c9c9c9; + background: url(../images/wrap_bg.png) repeat top left; } #aside_primary .section { - background-color: #c9c9c9; + background: url(../images/wrap_bg.png) repeat top left; } diff --git a/theme/shiny/images/wrap_bg.png b/theme/shiny/images/wrap_bg.png new file mode 100644 index 0000000000000000000000000000000000000000..ce9e4eceeb91ac654828a5d56c47527c6fdaabf3 GIT binary patch literal 111 zcmeAS@N?(olHy`uVBq!ia0vp^k|4~%1|*NXY)uAIjKx9jP7LeL$-D$|G(BA$Lp+Wr x+f@Dvv1RUM6lRt^utIh5w4NxVtdmF#9tKNOX8vg7H6WuIJYD@<);T3K0RYcI9yI^} literal 0 HcmV?d00001 From a9654beb5d7506e7594fd88ce2739d993e27e982 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 7 Oct 2010 10:56:10 -0700 Subject: [PATCH 02/10] Fix regression in OStatus remote group delivery: local group check was bogus in updated Ostatus_profile::localGroupFromUrl() --- plugins/OStatus/OStatusPlugin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/OStatus/OStatusPlugin.php b/plugins/OStatus/OStatusPlugin.php index 3cd29aff71..9c6696439a 100644 --- a/plugins/OStatus/OStatusPlugin.php +++ b/plugins/OStatus/OStatusPlugin.php @@ -966,7 +966,7 @@ class OStatusPlugin extends Plugin { $group = User_group::staticGet('uri', $url); if ($group) { - $local = Local_group::staticGet('id', $group->id); + $local = Local_group::staticGet('group_id', $group->id); if ($local) { return $group->id; } From 458f93bddd45ad3f37e18565edef67ac02ed15c2 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 7 Oct 2010 11:26:07 -0700 Subject: [PATCH 03/10] OStatus fixup-shadow.php: add check for user_group entries with 'uri' entry shadowing an actual local_group -- this can cause trouble now that we sometimes actually use the uri field for lookups, and leaving the entries around would break updating the table to fill out formerly missing uris, since the unique index entry would already be taken by the bad entry. --- plugins/OStatus/scripts/fixup-shadow.php | 44 ++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/plugins/OStatus/scripts/fixup-shadow.php b/plugins/OStatus/scripts/fixup-shadow.php index 3e2c18e02f..18df2995fb 100644 --- a/plugins/OStatus/scripts/fixup-shadow.php +++ b/plugins/OStatus/scripts/fixup-shadow.php @@ -84,6 +84,50 @@ while ($group->fetch()) { } echo "\n"; +// And there may be user_group entries remaining where we've already killed +// the ostatus_profile. These were "harmless" until our lookup started actually +// using the uri field, at which point we can clearly see it breaks stuff. +echo "Checking for leftover bogus user_group.uri entries obscuring local_group entries...\n"; + +$group = new User_group(); +$group->joinAdd(array('id', 'local_group:group_id'), 'LEFT'); +$group->whereAdd('group_id IS NULL'); + + +$marker = mt_rand(31337, 31337000); +$groupTemplate = common_local_url('groupbyid', array('id' => $marker)); +$encGroup = $group->escape($groupTemplate, true); +$encGroup = str_replace($marker, '%', $encGroup); +echo " LIKE '$encGroup'\n"; +$group->whereAdd("uri LIKE '$encGroup'"); + +$group->find(); +$count = $group->N; +echo "Found $count...\n"; + +while ($group->fetch()) { + $uri = $group->uri; + if (preg_match('!/group/(\d+)/id!', $uri, $matches)) { + $id = intval($matches[1]); + $local = Local_group::staticGet('group_id', $id); + if ($local) { + $nick = $local->nickname; + } else { + $nick = ''; + } + echo "local group $id ($local->nickname) hidden by $uri (bogus group id $group->id)"; + if ($dry) { + echo " - skipping\n"; + } else { + echo " - removing bogus user_group entry..."; + $evil = User_group::staticGet('id', $group->id); + $evil->delete(); + echo " ok\n"; + } + } +} +echo "\n"; + // Fallback? echo "Checking for bogus profiles blocking local users/groups by URI pattern match...\n"; From 51254ed85eaa755f676e0772d5406deb2cdc73a5 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 7 Oct 2010 12:03:33 -0700 Subject: [PATCH 04/10] Pull up the guts of my fixed bit.ly plugin from an old work branch (that had made other changes we weren't happy with in the plugin management). Now works if given a global API key. --- plugins/BitlyUrl/BitlyUrlPlugin.php | 88 ++++++++++++++++++++++++++--- 1 file changed, 81 insertions(+), 7 deletions(-) diff --git a/plugins/BitlyUrl/BitlyUrlPlugin.php b/plugins/BitlyUrl/BitlyUrlPlugin.php index 10d99b3588..ceabeb29cd 100644 --- a/plugins/BitlyUrl/BitlyUrlPlugin.php +++ b/plugins/BitlyUrl/BitlyUrlPlugin.php @@ -2,7 +2,7 @@ /** * StatusNet, the distributed open-source microblogging tool * - * Plugin to push RSS/Atom updates to a PubSubHubBub hub + * Plugin to use bit.ly URL shortening services. * * PHP version 5 * @@ -22,7 +22,9 @@ * @category Plugin * @package StatusNet * @author Craig Andrews + * @author Brion Vibber * @copyright 2009 Free Software Foundation, Inc http://www.fsf.org + * @copyright 2010 StatusNet, Inc http://status.net/ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ @@ -35,26 +37,98 @@ require_once INSTALLDIR.'/plugins/UrlShortener/UrlShortenerPlugin.php'; class BitlyUrlPlugin extends UrlShortenerPlugin { - public $serviceUrl; + public $shortenerName = 'bit.ly'; + public $serviceUrl = 'http://bit.ly/api?method=shorten&version=2.0.1&longUrl=%s'; + public $login; + public $apiKey; function onInitializePlugin(){ parent::onInitializePlugin(); if(!isset($this->serviceUrl)){ - throw new Exception(_m("You must specify a serviceUrl.")); + throw new Exception(_m("You must specify a serviceUrl for bit.ly shortening.")); + } + if(!isset($this->login)){ + throw new Exception(_m("You must specify a login name for bit.ly shortening.")); + } + if(!isset($this->login)){ + throw new Exception(_m("You must specify an API key for bit.ly shortening.")); } } + /** + * Short a URL + * @param url + * @return string shortened version of the url, or null if URL shortening failed + */ protected function shorten($url) { - $response = $this->http_get($url); - if(!$response) return; - return current(json_decode($response)->results)->hashUrl; + $response = $this->query($url); + if ($this->isOk($url, $response)) { + return $this->decode($url, $response->getBody()); + } else { + return null; + } + } + + /** + * Inject API key into query before sending out... + * + * @param string $url + * @return HTTPResponse + */ + protected function query($url) + { + // http://code.google.com/p/bitly-api/wiki/ApiDocumentation#/shorten + $params = http_build_query(array( + 'login' => $this->login, + 'apiKey' => $this->apiKey), '', '&'); + $serviceUrl = sprintf($this->serviceUrl, $url) . '&' . $params; + + $request = HTTPClient::start(); + return $request->get($serviceUrl); + } + + /** + * JSON decode for API result + */ + protected function decode($url, $body) + { + $json = json_decode($body, true); + return $json['results'][$url]['shortUrl']; + } + + /** + * JSON decode for API result + */ + protected function isOk($url, $response) + { + $code = 'unknown'; + $msg = ''; + if ($response->isOk()) { + $body = $response->getBody(); + common_log(LOG_INFO, $body); + $json = json_decode($body, true); + if ($json['statusCode'] == 'OK') { + $data = $json['results'][$url]; + if (isset($data['shortUrl'])) { + return true; + } else if (isset($data['statusCode']) && $data['statusCode'] == 'ERROR') { + $code = $data['errorCode']; + $msg = $data['errorMessage']; + } + } else if ($json['statusCode'] == 'ERROR') { + $code = $json['errorCode']; + $msg = $json['errorMessage']; + } + common_log(LOG_ERR, "bit.ly returned error $code $msg for $url"); + } + return false; } function onPluginVersion(&$versions) { $versions[] = array('name' => sprintf('BitlyUrl (%s)', $this->shortenerName), 'version' => STATUSNET_VERSION, - 'author' => 'Craig Andrews', + 'author' => 'Craig Andrews, Brion Vibber', 'homepage' => 'http://status.net/wiki/Plugin:BitlyUrl', 'rawdescription' => sprintf(_m('Uses %1$s URL-shortener service.'), From 5e0f3e7bd4e7035efdb8bc62cd61d4613e1ad6b1 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 7 Oct 2010 12:32:10 -0700 Subject: [PATCH 05/10] Workaround for regression in input validation due to more PCRE oddities. Recommend redoing common_validate_utf8() using something more reliable, perhaps. :P --- lib/util.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/util.php b/lib/util.php index 35fcfdb090..c05fcf15a2 100644 --- a/lib/util.php +++ b/lib/util.php @@ -919,7 +919,12 @@ function common_shorten_links($text, $always = false) function common_validate_utf8($str) { // preg_replace will return NULL on invalid UTF-8 input. - return preg_replace('//u', '', $str); + // + // Note: empty regex //u also caused NULL return on some + // production machines, but none of our test machines. + // + // This should be replaced with a more reliable check. + return preg_replace('/\x00/u', '', $str); } /** From 80f0b9421f63be2f4b8ebd7b722b138da220dc45 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 7 Oct 2010 12:30:32 -0700 Subject: [PATCH 06/10] bit.ly admin panel to set the API keys to use. --- plugins/BitlyUrl/BitlyUrlPlugin.php | 97 +++++++- plugins/BitlyUrl/bitlyadminpanelaction.php | 271 +++++++++++++++++++++ 2 files changed, 358 insertions(+), 10 deletions(-) create mode 100644 plugins/BitlyUrl/bitlyadminpanelaction.php diff --git a/plugins/BitlyUrl/BitlyUrlPlugin.php b/plugins/BitlyUrl/BitlyUrlPlugin.php index ceabeb29cd..c9005e52ec 100644 --- a/plugins/BitlyUrl/BitlyUrlPlugin.php +++ b/plugins/BitlyUrl/BitlyUrlPlugin.php @@ -39,20 +39,12 @@ class BitlyUrlPlugin extends UrlShortenerPlugin { public $shortenerName = 'bit.ly'; public $serviceUrl = 'http://bit.ly/api?method=shorten&version=2.0.1&longUrl=%s'; - public $login; - public $apiKey; function onInitializePlugin(){ parent::onInitializePlugin(); if(!isset($this->serviceUrl)){ throw new Exception(_m("You must specify a serviceUrl for bit.ly shortening.")); } - if(!isset($this->login)){ - throw new Exception(_m("You must specify a login name for bit.ly shortening.")); - } - if(!isset($this->login)){ - throw new Exception(_m("You must specify an API key for bit.ly shortening.")); - } } /** @@ -69,6 +61,26 @@ class BitlyUrlPlugin extends UrlShortenerPlugin } } + /** + * Get the user's or site-wide default bit.ly login name. + * + * @return string + */ + protected function getLogin() + { + return common_config('bitly', 'default_login'); + } + + /** + * Get the user's or site-wide default bit.ly API key. + * + * @return string + */ + protected function getApiKey() + { + return common_config('bitly', 'default_apikey'); + } + /** * Inject API key into query before sending out... * @@ -79,8 +91,8 @@ class BitlyUrlPlugin extends UrlShortenerPlugin { // http://code.google.com/p/bitly-api/wiki/ApiDocumentation#/shorten $params = http_build_query(array( - 'login' => $this->login, - 'apiKey' => $this->apiKey), '', '&'); + 'login' => $this->getLogin(), + 'apiKey' => $this->getApiKey()), '', '&'); $serviceUrl = sprintf($this->serviceUrl, $url) . '&' . $params; $request = HTTPClient::start(); @@ -136,4 +148,69 @@ class BitlyUrlPlugin extends UrlShortenerPlugin return true; } + + /** + * Hook for RouterInitialized event. + * + * @param Net_URL_Mapper $m path-to-action mapper + * @return boolean hook return + */ + function onRouterInitialized($m) + { + $m->connect('admin/bitly', + array('action' => 'bitlyadminpanel')); + return true; + } + + /** + * If the plugin's installed, this should be accessible to admins. + */ + function onAdminPanelCheck($name, &$isOK) + { + if ($name == 'bitly') { + $isOK = true; + return false; + } + + return true; + } + + /** + * Add the bit.ly admin panel to the list... + */ + function onEndAdminPanelNav($nav) + { + if (AdminPanelAction::canAdmin('bitly')) { + $action_name = $nav->action->trimmed('action'); + + $nav->out->menuItem(common_local_url('bitlyadminpanel'), + _m('bit.ly'), + _m('bit.ly URL shortening'), + $action_name == 'bitlyadminpanel', + 'nav_bitly_admin_panel'); + } + + return true; + } + + /** + * Automatically load the actions and libraries used by the plugin + * + * @param Class $cls the class + * + * @return boolean hook return + * + */ + function onAutoload($cls) + { + $base = dirname(__FILE__); + $lower = strtolower($cls); + switch ($lower) { + case 'bitlyadminpanelaction': + require_once "$base/$lower.php"; + return false; + default: + return true; + } + } } diff --git a/plugins/BitlyUrl/bitlyadminpanelaction.php b/plugins/BitlyUrl/bitlyadminpanelaction.php new file mode 100644 index 0000000000..56f78e1648 --- /dev/null +++ b/plugins/BitlyUrl/bitlyadminpanelaction.php @@ -0,0 +1,271 @@ +. + * + * @category Settings + * @package StatusNet + * @author Brion Vibber + * @copyright 2010 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +if (!defined('STATUSNET')) { + exit(1); +} + +/** + * Administer global bit.ly URL shortener settings + * + * @category Admin + * @package StatusNet + * @author Brion Vibber + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +class BitlyadminpanelAction extends AdminPanelAction +{ + /** + * Returns the page title + * + * @return string page title + */ + + function title() + { + return _m('bit.ly URL shortening'); + } + + /** + * Instructions for using this form. + * + * @return string instructions + */ + + function getInstructions() + { + return _m('URL shortening with bit.ly requires ' . + '[a bit.ly account and API key](http://bit.ly/a/your_api_key). ' . + 'This verifies that this is an authorized account, and ' . + 'allow you to use bit.ly\'s tracking features and custom domains.'); + } + + /** + * Show the bit.ly admin panel form + * + * @return void + */ + + function showForm() + { + $form = new BitlyAdminPanelForm($this); + $form->show(); + return; + } + + /** + * Save settings from the form + * + * @return void + */ + + function saveSettings() + { + static $settings = array( + 'bitly' => array('default_login', 'default_apikey') + ); + + static $booleans = array( + 'bitly' => array('allow_override') + ); + + $values = array(); + + foreach ($settings as $section => $parts) { + foreach ($parts as $setting) { + $values[$section][$setting] + = $this->trimmed($setting); + } + } + + foreach ($booleans as $section => $parts) { + foreach ($parts as $setting) { + $values[$section][$setting] + = ($this->boolean($setting)) ? 1 : 0; + } + } + + // This throws an exception on validation errors + + $this->validate($values); + + // assert(all values are valid); + + $config = new Config(); + + $config->query('BEGIN'); + + foreach ($settings as $section => $parts) { + foreach ($parts as $setting) { + Config::save($section, $setting, $values[$section][$setting]); + } + } + + foreach ($booleans as $section => $parts) { + foreach ($parts as $setting) { + Config::save($section, $setting, $values[$section][$setting]); + } + } + + $config->query('COMMIT'); + + return; + } + + function validate(&$values) + { + // Validate consumer key and secret (can't be too long) + + if (mb_strlen($values['bitly']['default_apikey']) > 255) { + $this->clientError( + _m("Invalid login. Max length is 255 characters.") + ); + } + + if (mb_strlen($values['bitly']['default_apikey']) > 255) { + $this->clientError( + _m("Invalid API key. Max length is 255 characters.") + ); + } + } +} + +class BitlyAdminPanelForm extends AdminForm +{ + /** + * ID of the form + * + * @return int ID of the form + */ + + function id() + { + return 'bitlyadminpanel'; + } + + /** + * class of the form + * + * @return string class of the form + */ + + function formClass() + { + return 'form_settings'; + } + + /** + * Action of the form + * + * @return string URL of the action + */ + + function action() + { + return common_local_url('bitlyadminpanel'); + } + + /** + * Data elements of the form + * + * @return void + */ + + function formData() + { + $this->out->elementStart( + 'fieldset', + array('id' => 'settings_bitly') + ); + $this->out->element('legend', null, _m('Default credentials')); + $this->out->element('p', 'form_guide', + _m('When users select the bit.ly shortening service, by default ' . + 'these credentials will be used. If you leave these empty, ' . + 'users will need to set up their own credentials in order to ' . + 'use bit.ly.')); + $this->out->elementStart('ul', 'form_data'); + + $this->li(); + $this->input( + 'default_login', + _m('Login name'), + null, + 'bitly' + ); + $this->unli(); + + $this->li(); + $this->input( + 'default_apikey', + _m('API key'), + null, + 'bitly' + ); + $this->unli(); + + $this->out->elementEnd('ul'); + $this->out->elementEnd('fieldset'); + + $this->out->elementStart( + 'fieldset', + array('id' => 'settings_bitly-options') + ); + $this->out->element('legend', null, _m('Options')); + + $this->out->elementStart('ul', 'form_data'); + + $this->li(); + + $this->out->checkbox( + 'allow_override', _m('Allow users to specify their own API key.'), + (bool) $this->value('bitly', 'allow_override'), + _m('If set, users will be able to specify their own bit.ly login and API key ' . + 'to be used for shortening their links.'), + 'true' + ); + $this->unli(); + + $this->out->elementEnd('ul'); + + $this->out->elementEnd('fieldset'); + } + + /** + * Action elements + * + * @return void + */ + + function formActions() + { + $this->out->submit('submit', _('Save'), 'submit', null, _m('Save bit.ly settings')); + } +} From cad480551675c05452df109e5c4d43018139d6a1 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 7 Oct 2010 13:05:51 -0700 Subject: [PATCH 07/10] Clean up bit.ly admin panel behavior, and hide it from the shorteners list if it's not fully configured. --- plugins/BitlyUrl/BitlyUrlPlugin.php | 45 +++++++++++++++++++++- plugins/BitlyUrl/bitlyadminpanelaction.php | 17 +++++--- 2 files changed, 55 insertions(+), 7 deletions(-) diff --git a/plugins/BitlyUrl/BitlyUrlPlugin.php b/plugins/BitlyUrl/BitlyUrlPlugin.php index c9005e52ec..93a35b3f38 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(); @@ -47,6 +49,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 @@ -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; + } + } diff --git a/plugins/BitlyUrl/bitlyadminpanelaction.php b/plugins/BitlyUrl/bitlyadminpanelaction.php index 56f78e1648..805b56b857 100644 --- a/plugins/BitlyUrl/bitlyadminpanelaction.php +++ b/plugins/BitlyUrl/bitlyadminpanelaction.php @@ -206,11 +206,18 @@ class BitlyAdminPanelForm extends AdminForm array('id' => 'settings_bitly') ); $this->out->element('legend', null, _m('Default credentials')); - $this->out->element('p', 'form_guide', - _m('When users select the bit.ly shortening service, by default ' . - 'these credentials will be used. If you leave these empty, ' . - 'users will need to set up their own credentials in order to ' . - 'use bit.ly.')); + + // Do we have global defaults to fall back on? + $login = $apiKey = false; + Event::handle('BitlyDefaultCredentials', array(&$login, &$apiKey)); + $haveGlobalDefaults = ($login && $apiKey); + if ($login && $apiKey) { + $this->out->element('p', 'form_guide', + _m('Leave these empty to use the default credentials.')); + } else { + $this->out->element('p', 'form_guide', + _m('If you leave these empty, bit.ly will be unavailable to users.')); + } $this->out->elementStart('ul', 'form_data'); $this->li(); From fbfd96dfb945712b60f5b9f34aaaec5118e7c641 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 7 Oct 2010 13:08:23 -0700 Subject: [PATCH 08/10] Drop out the 'allow user override' checkbox on bit.ly admin panel until we find a good way to shove the user settings in. :) --- plugins/BitlyUrl/bitlyadminpanelaction.php | 40 ---------------------- 1 file changed, 40 deletions(-) diff --git a/plugins/BitlyUrl/bitlyadminpanelaction.php b/plugins/BitlyUrl/bitlyadminpanelaction.php index 805b56b857..046ae52c2a 100644 --- a/plugins/BitlyUrl/bitlyadminpanelaction.php +++ b/plugins/BitlyUrl/bitlyadminpanelaction.php @@ -93,10 +93,6 @@ class BitlyadminpanelAction extends AdminPanelAction 'bitly' => array('default_login', 'default_apikey') ); - static $booleans = array( - 'bitly' => array('allow_override') - ); - $values = array(); foreach ($settings as $section => $parts) { @@ -106,13 +102,6 @@ class BitlyadminpanelAction extends AdminPanelAction } } - foreach ($booleans as $section => $parts) { - foreach ($parts as $setting) { - $values[$section][$setting] - = ($this->boolean($setting)) ? 1 : 0; - } - } - // This throws an exception on validation errors $this->validate($values); @@ -129,12 +118,6 @@ class BitlyadminpanelAction extends AdminPanelAction } } - foreach ($booleans as $section => $parts) { - foreach ($parts as $setting) { - Config::save($section, $setting, $values[$section][$setting]); - } - } - $config->query('COMMIT'); return; @@ -240,29 +223,6 @@ class BitlyAdminPanelForm extends AdminForm $this->out->elementEnd('ul'); $this->out->elementEnd('fieldset'); - - $this->out->elementStart( - 'fieldset', - array('id' => 'settings_bitly-options') - ); - $this->out->element('legend', null, _m('Options')); - - $this->out->elementStart('ul', 'form_data'); - - $this->li(); - - $this->out->checkbox( - 'allow_override', _m('Allow users to specify their own API key.'), - (bool) $this->value('bitly', 'allow_override'), - _m('If set, users will be able to specify their own bit.ly login and API key ' . - 'to be used for shortening their links.'), - 'true' - ); - $this->unli(); - - $this->out->elementEnd('ul'); - - $this->out->elementEnd('fieldset'); } /** From bd5925a6dbe53d08cde01618c73a7be034401455 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 7 Oct 2010 13:17:20 -0700 Subject: [PATCH 09/10] Tweak bit.ly admin panel messages to distinguish the admin settings from config.php globals --- plugins/BitlyUrl/bitlyadminpanelaction.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/BitlyUrl/bitlyadminpanelaction.php b/plugins/BitlyUrl/bitlyadminpanelaction.php index 046ae52c2a..05b8e83267 100644 --- a/plugins/BitlyUrl/bitlyadminpanelaction.php +++ b/plugins/BitlyUrl/bitlyadminpanelaction.php @@ -188,7 +188,7 @@ class BitlyAdminPanelForm extends AdminForm 'fieldset', array('id' => 'settings_bitly') ); - $this->out->element('legend', null, _m('Default credentials')); + $this->out->element('legend', null, _m('Credentials')); // Do we have global defaults to fall back on? $login = $apiKey = false; @@ -196,7 +196,7 @@ class BitlyAdminPanelForm extends AdminForm $haveGlobalDefaults = ($login && $apiKey); if ($login && $apiKey) { $this->out->element('p', 'form_guide', - _m('Leave these empty to use the default credentials.')); + _m('Leave these empty to use global default credentials.')); } else { $this->out->element('p', 'form_guide', _m('If you leave these empty, bit.ly will be unavailable to users.')); From 603e1dc563128c6e5ad0f5cd457563b7db7c787e Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 7 Oct 2010 13:23:18 -0700 Subject: [PATCH 10/10] Add a README for BitlyUrlPlugin --- plugins/BitlyUrl/README | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 plugins/BitlyUrl/README diff --git a/plugins/BitlyUrl/README b/plugins/BitlyUrl/README new file mode 100644 index 0000000000..0b3af1dd63 --- /dev/null +++ b/plugins/BitlyUrl/README @@ -0,0 +1,37 @@ +bit.ly URL shortening requires the login name and API key for a bit.ly account. +Register for an account or set up your API key here: + + http://bit.ly/a/your_api_key + +Administrators can configure a login and API key to use through the admin panels +on the site; these credentials will then be used for all users. + +(In the future, options will be added for individual users to override the keys +with their own login for URLs they post.) + +If the login and API key are left empty in the admin panel, then bit.ly will be +disabled and hidden from the list of available URL shorteners unless a global +default was provided in the plugin configuration. + + +To enable bit.ly with no default credentials, simply slip into your config.php: + + addPlugin('BitlyUrl'); + +To provide default credentials, add them as parameters: + + addPlugin('BitlyUrl', array( + 'login' => 'myname', + 'apiKey' => '############################' + )); + +These settings will not be individually exposed to the admin panels, but the +panel will indicate whether or not the global default settings are available; +this makes it suitable as a global default for multi-site hosting, where admins +on individual sites can change to use their own settings. + + +If you're using a bit.ly pro account with a custom domain etc, it should all +"just work" as long as you use the correct login name and API key for your +account. +