From f0abc0fe15a54da468cf37e748041bba4f362e53 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Thu, 29 Oct 2009 13:18:51 +0100 Subject: Updated bookmarklet. Created its own action --- actions/bookmarklet.php | 75 +++++++++++++++++++++++++++++++++++++++++++++++++ doc-src/bookmarklet | 2 +- js/util.js | 3 ++ lib/router.php | 2 ++ 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 actions/bookmarklet.php diff --git a/actions/bookmarklet.php b/actions/bookmarklet.php new file mode 100644 index 000000000..f253399e4 --- /dev/null +++ b/actions/bookmarklet.php @@ -0,0 +1,75 @@ +. + * + * @category Bookmarklet + * @package StatusNet + * @author Sarven Capadisli + * @copyright 2008-2009 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') && !defined('LACONICA')) { + exit(1); +} + +require_once INSTALLDIR . '/actions/newnotice.php'; + +/** + * Action for posting a notice + * + * @category Bookmarklet + * @package StatusNet + * @author Sarven Capadisli + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +class BookmarkletAction extends NewnoticeAction +{ + function showTitle() + { + $this->element('title', null, _('Post to '.common_config('site', 'name'))); + } + + function showHeader() + { + $this->elementStart('div', array('id' => 'header')); + $this->elementStart('address'); + $this->element('a', array('class' => 'url', + 'href' => common_local_url('public')), + ''); + $this->elementEnd('address'); + if (common_logged_in()) { + $this->showNoticeForm(); + } + $this->elementEnd('div'); + } + + function showCore() + { + } + + function showFooter() + { + } +} + diff --git a/doc-src/bookmarklet b/doc-src/bookmarklet index e5ded7702..0aa9e1e49 100644 --- a/doc-src/bookmarklet +++ b/doc-src/bookmarklet @@ -2,4 +2,4 @@ A bookmarklet is a small piece of javascript code used as a bookmark. This one w Drag-and-drop the following link to your bookmarks bar or right-click it and add it to your browser favorites to keep it handy. -Post to %%site.name%% +Post to %%site.name%% diff --git a/js/util.js b/js/util.js index 0a943512f..b079388e4 100644 --- a/js/util.js +++ b/js/util.js @@ -241,6 +241,9 @@ $(document).ready(function(){ alert(result); } else { + if($('body')[0].id == 'bookmarklet') { + self.close(); + } if ($("#command_result", xml).length > 0) { var result = document._importNode($("p", xml).get(0), true); result = result.textContent || result.innerHTML; diff --git a/lib/router.php b/lib/router.php index dedf73c86..2fd255fe6 100644 --- a/lib/router.php +++ b/lib/router.php @@ -179,6 +179,8 @@ class Router array('action' => 'deletenotice'), array('notice' => '[0-9]+')); + $m->connect('bookmarklet/new', array('action' => 'bookmarklet')); + // conversation $m->connect('conversation/:id', -- cgit v1.2.3-54-g00ecf From 968389fb45346c77799d3ba2f787c9bcb3971173 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Thu, 29 Oct 2009 13:24:06 +0100 Subject: Don't include site in gettext --- actions/bookmarklet.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/bookmarklet.php b/actions/bookmarklet.php index f253399e4..0603a7456 100644 --- a/actions/bookmarklet.php +++ b/actions/bookmarklet.php @@ -47,7 +47,7 @@ class BookmarkletAction extends NewnoticeAction { function showTitle() { - $this->element('title', null, _('Post to '.common_config('site', 'name'))); + $this->element('title', null, _('Post to ').common_config('site', 'name')); } function showHeader() -- cgit v1.2.3-54-g00ecf From 47c659a1ba67940b537d77aacc2dba486b52f278 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Thu, 29 Oct 2009 13:31:56 +0100 Subject: Updated bookmarklet styles --- doc-src/bookmarklet | 2 +- theme/base/css/display.css | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/doc-src/bookmarklet b/doc-src/bookmarklet index 0aa9e1e49..ff42f66b2 100644 --- a/doc-src/bookmarklet +++ b/doc-src/bookmarklet @@ -2,4 +2,4 @@ A bookmarklet is a small piece of javascript code used as a bookmark. This one w Drag-and-drop the following link to your bookmarks bar or right-click it and add it to your browser favorites to keep it handy. -Post to %%site.name%% +Post to %%site.name%% diff --git a/theme/base/css/display.css b/theme/base/css/display.css index d9dca9815..c8aafe489 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -1295,3 +1295,13 @@ display:none; .guide { clear:both; } + +#bookmarklet address { +display:none; +} +#bookmarklet #form_notice { +width:auto; +} +#bookmarklet #wrap { +min-width:0; +} -- cgit v1.2.3-54-g00ecf From 2c1af973bbe285b373ede9944330444d85772625 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Thu, 29 Oct 2009 13:37:05 +0100 Subject: Fixed bookmarklet URL --- doc-src/bookmarklet | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc-src/bookmarklet b/doc-src/bookmarklet index ff42f66b2..6ce23bd0b 100644 --- a/doc-src/bookmarklet +++ b/doc-src/bookmarklet @@ -2,4 +2,4 @@ A bookmarklet is a small piece of javascript code used as a bookmark. This one w Drag-and-drop the following link to your bookmarks bar or right-click it and add it to your browser favorites to keep it handy. -Post to %%site.name%% +Post to %%site.name%% -- cgit v1.2.3-54-g00ecf From fd650715fa934df9b7e560881bfb622860588599 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 29 Oct 2009 13:55:37 -0400 Subject: Warning cleanup: drop reference on router parameter to RouterInitialized event handlers. We don't (and don't need to) pass a reference here, and the mix can trigger warnings. --- plugins/Facebook/FacebookPlugin.php | 2 +- plugins/OpenID/OpenIDPlugin.php | 2 +- plugins/TemplatePlugin.php | 2 +- plugins/TwitterBridge/TwitterBridgePlugin.php | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/Facebook/FacebookPlugin.php b/plugins/Facebook/FacebookPlugin.php index fc3adcfad..b68534b24 100644 --- a/plugins/Facebook/FacebookPlugin.php +++ b/plugins/Facebook/FacebookPlugin.php @@ -58,7 +58,7 @@ class FacebookPlugin extends Plugin * @return boolean hook return */ - function onRouterInitialized(&$m) + function onRouterInitialized($m) { // Facebook App stuff diff --git a/plugins/OpenID/OpenIDPlugin.php b/plugins/OpenID/OpenIDPlugin.php index 560da71e7..81e3ed9c4 100644 --- a/plugins/OpenID/OpenIDPlugin.php +++ b/plugins/OpenID/OpenIDPlugin.php @@ -62,7 +62,7 @@ class OpenIDPlugin extends Plugin * @return boolean hook return */ - function onRouterInitialized(&$m) + function onRouterInitialized($m) { $m->connect('main/openid', array('action' => 'openidlogin')); $m->connect('settings/openid', array('action' => 'openidsettings')); diff --git a/plugins/TemplatePlugin.php b/plugins/TemplatePlugin.php index cfa051162..5f3ad81f5 100644 --- a/plugins/TemplatePlugin.php +++ b/plugins/TemplatePlugin.php @@ -32,7 +32,7 @@ class TemplatePlugin extends Plugin { // capture the RouterInitialized event // and connect a new API method // for updating the template - function onRouterInitialized( &$m ) { + function onRouterInitialized( $m ) { $m->connect( 'template/update', array( 'action' => 'template', )); diff --git a/plugins/TwitterBridge/TwitterBridgePlugin.php b/plugins/TwitterBridge/TwitterBridgePlugin.php index e69567fc7..ad3c2e551 100644 --- a/plugins/TwitterBridge/TwitterBridgePlugin.php +++ b/plugins/TwitterBridge/TwitterBridgePlugin.php @@ -60,12 +60,12 @@ class TwitterBridgePlugin extends Plugin * * Hook for RouterInitialized event. * - * @param Net_URL_Mapper &$m path-to-action mapper + * @param Net_URL_Mapper $m path-to-action mapper * * @return boolean hook return */ - function onRouterInitialized(&$m) + function onRouterInitialized($m) { $m->connect('twitter/authorization', array('action' => 'twitterauthorization')); -- cgit v1.2.3-54-g00ecf From 201cbb56b6faa33b814344034954a9efdde65e49 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 29 Oct 2009 14:29:52 -0400 Subject: Don't spew warnings for URL shortener plugins that don't declare if they're free services. --- actions/othersettings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/othersettings.php b/actions/othersettings.php index 011b4fc83..d32a2d651 100644 --- a/actions/othersettings.php +++ b/actions/othersettings.php @@ -103,7 +103,7 @@ class OthersettingsAction extends AccountSettingsAction foreach($_shorteners as $name=>$value) { $services[$name]=$name; - if($value['info']['freeService']){ + if(!empty($value['info']['freeService'])){ // I18N $services[$name].=' (free service)'; } -- cgit v1.2.3-54-g00ecf From e88dd2d087bfcd4ae28ceebb833b1f02693dd3f1 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 29 Oct 2009 14:34:08 -0400 Subject: fix uninitialized variables in showstream.php --- actions/showstream.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/actions/showstream.php b/actions/showstream.php index b3a9b1f05..de7100b1d 100644 --- a/actions/showstream.php +++ b/actions/showstream.php @@ -348,6 +348,8 @@ class ShowstreamAction extends ProfileAction { if (Event::handle('StartProfilePageActionsSection', array(&$this, $this->profile))) { + $cur = common_current_user(); + $this->elementStart('div', 'entity_actions'); $this->element('h2', null, _('User actions')); $this->elementStart('ul'); @@ -379,21 +381,21 @@ class ShowstreamAction extends ProfileAction } $this->elementEnd('li'); - if ($cur->mutuallySubscribed($user)) { + if ($cur->mutuallySubscribed($this->user)) { // message $this->elementStart('li', 'entity_send-a-message'); - $this->element('a', array('href' => common_local_url('newmessage', array('to' => $user->id)), + $this->element('a', array('href' => common_local_url('newmessage', array('to' => $this->user->id)), 'title' => _('Send a direct message to this user')), _('Message')); $this->elementEnd('li'); // nudge - if ($user->email && $user->emailnotifynudge) { + if ($this->user->email && $this->user->emailnotifynudge) { $this->elementStart('li', 'entity_nudge'); - $nf = new NudgeForm($this, $user); + $nf = new NudgeForm($this, $this->user); $nf->show(); $this->elementEnd('li'); } -- cgit v1.2.3-54-g00ecf From e9644f03de3e30d46764ca0046ed29730cbe414e Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 29 Oct 2009 14:43:18 -0400 Subject: get location from a Notice --- classes/Notice.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/classes/Notice.php b/classes/Notice.php index fdf5cd4c8..c08a66790 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -1412,4 +1412,21 @@ class Notice extends Memcached_DataObject $contentlimit = self::maxContent(); return ($contentlimit > 0 && !empty($content) && (mb_strlen($content) > $contentlimit)); } + + function getLocation() + { + $location = null; + + if (!empty($this->location_id) && !empty($this->location_ns)) { + $location = Location::fromId($this->location_id, $this->location_ns); + } + + if (is_null($location)) { // no ID, or Location::fromId() failed + if (!empty($this->lat) && !empty($this->lon)) { + $location = Location::fromLatLon($this->lat, $this->lon); + } + } + + return $location; + } } -- cgit v1.2.3-54-g00ecf From 5d2b35cce6bbe8a760f273093b6a105a930f83fb Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 29 Oct 2009 14:43:25 -0400 Subject: get location from a Profile --- classes/Profile.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/classes/Profile.php b/classes/Profile.php index 53d07fb2f..7c1e9db33 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -562,4 +562,29 @@ class Profile extends Memcached_DataObject $block->blocked = $this->id; $block->delete(); } + + // XXX: identical to Notice::getLocation. + + function getLocation() + { + $location = null; + + if (!empty($this->location_id) && !empty($this->location_ns)) { + $location = Location::fromId($this->location_id, $this->location_ns); + } + + if (is_null($location)) { // no ID, or Location::fromId() failed + if (!empty($this->lat) && !empty($this->lon)) { + $location = Location::fromLatLon($this->lat, $this->lon); + } + } + + if (is_null($location)) { // still haven't found it! + if (!empty($this->location)) { + $location = Location::fromName($this->location); + } + } + + return $location; + } } -- cgit v1.2.3-54-g00ecf From a6ed4e5bf7e7c15bc649c91451bbe7b6aa1f0735 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 29 Oct 2009 14:49:00 -0400 Subject: a location method for getting an URL --- lib/location.php | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/lib/location.php b/lib/location.php index 048554f0f..c9411b55d 100644 --- a/lib/location.php +++ b/lib/location.php @@ -47,10 +47,11 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { class Location { - public $lat; - public $lon; - public $location_id; - public $location_ns; + public $lat; + public $lon; + public $location_id; + public $location_ns; + private $_url; var $names = array(); @@ -157,4 +158,33 @@ class Location } } } + + /** + * Get an URL suitable for this location + * + * @return string URL for this location or NULL + */ + + function getURL() + { + if ($this->_url == false) { // cached failure + return null; + } else if (is_string($this->_url)) { // cached value + return $this->_url; + } + + $url = null; + + Event::handle('LocationUrl', array($this, &$url)); + + // Save it for later + + if (is_null($url)) { + $this->_url = false; + } else { + $this->_url = $url; + } + + return $this->_url; + } } -- cgit v1.2.3-54-g00ecf From 62ba14f5cf54235a0929d2ab06b62bad02ff7241 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 29 Oct 2009 15:07:26 -0400 Subject: make an URL for a geonames location --- plugins/GeonamesPlugin.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/plugins/GeonamesPlugin.php b/plugins/GeonamesPlugin.php index 745cd4126..80ef44cc9 100644 --- a/plugins/GeonamesPlugin.php +++ b/plugins/GeonamesPlugin.php @@ -278,4 +278,28 @@ class GeonamesPlugin extends Plugin return true; } + + /** + * Human-readable name for a location + * + * Given a location, we try to retrieve a geonames.org URL. + * + * @param Location $location Location to get the url for + * @param string &$url Place to put the url + * + * @return boolean whether to continue + */ + + function onLocationUrl($location, &$url) + { + if ($location->location_ns != self::NAMESPACE) { + // It's not one of our IDs... keep processing + return true; + } + + $url = 'http://www.geonames.org/' . $location->location_id; + + // it's been filled, so don't process further. + return false; + } } -- cgit v1.2.3-54-g00ecf From 666c18a1dd79ed46fdab8c12d7061ad640c33a50 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Thu, 29 Oct 2009 15:08:24 -0400 Subject: use addPlugin() in the README setup example --- plugins/TwitterBridge/README | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/TwitterBridge/README b/plugins/TwitterBridge/README index 09352188e..d3bcda598 100644 --- a/plugins/TwitterBridge/README +++ b/plugins/TwitterBridge/README @@ -11,8 +11,7 @@ Installation To enable the plugin, add the following to your config.php: - require_once(INSTALLDIR . '/plugins/TwitterBridge/TwitterBridgePlugin.php'); - $tb = new TwitterBridgePlugin(); + addPlugin("TwitterBridge"); OAuth is used to to access protected resources on Twitter (as opposed to HTTP Basic Auth)*. To use Twitter bridging you will need to register -- cgit v1.2.3-54-g00ecf From 5b0809f4a3619e8123b486f7e910913dc4e10086 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 29 Oct 2009 16:15:49 -0400 Subject: fix caching in location.php --- lib/location.php | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/location.php b/lib/location.php index c9411b55d..bbfc15a36 100644 --- a/lib/location.php +++ b/lib/location.php @@ -91,6 +91,10 @@ class Location static function fromId($id, $ns, $language=null) { + if (is_null($language)) { + $language = common_language(); + } + $location = null; // Let a third-party handle it @@ -167,9 +171,9 @@ class Location function getURL() { - if ($this->_url == false) { // cached failure - return null; - } else if (is_string($this->_url)) { // cached value + // Keep one cached + + if (is_string($this->_url)) { return $this->_url; } @@ -177,14 +181,8 @@ class Location Event::handle('LocationUrl', array($this, &$url)); - // Save it for later - - if (is_null($url)) { - $this->_url = false; - } else { - $this->_url = $url; - } + $this->_url = $url; - return $this->_url; + return $url; } } -- cgit v1.2.3-54-g00ecf From 49dd54315ffd98b84e64d0377d4c26c07ec4084e Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 29 Oct 2009 16:16:02 -0400 Subject: show notice location in notice list --- lib/noticelist.php | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/lib/noticelist.php b/lib/noticelist.php index 6c296f82a..8b3015cc3 100644 --- a/lib/noticelist.php +++ b/lib/noticelist.php @@ -199,6 +199,7 @@ class NoticeListItem extends Widget { $this->out->elementStart('div', 'entry-content'); $this->showNoticeLink(); + $this->showNoticeLocation(); $this->showNoticeSource(); $this->showContext(); $this->out->elementEnd('div'); @@ -369,6 +370,44 @@ class NoticeListItem extends Widget $this->out->elementEnd('a'); } + /** + * show the notice location + * + * shows the notice location in the correct language. + * + * If an URL is available, makes a link. Otherwise, just a span. + * + * @return void + */ + + function showNoticeLocation() + { + $id = $this->notice->id; + + $location = $this->notice->getLocation(); + + if (empty($location)) { + return; + } + + $name = $location->getName(); + + if (empty($name)) { + // XXX: Could be a translation issue. Fall back to... something? + return; + } + + $url = $location->getUrl(); + + if (empty($url)) { + $this->out->element('span', array('class' => 'location'), $name); + } else { + $this->out->element('a', array('class' => 'location', + 'href' => $url), + $name); + } + } + /** * Show the source of the notice * -- cgit v1.2.3-54-g00ecf