Merge commit 'mainline/0.9.x' into 0.9.x

This commit is contained in:
Brenda Wallace 2009-10-30 09:41:04 +13:00
commit c0f8c0178a
17 changed files with 241 additions and 17 deletions

75
actions/bookmarklet.php Normal file
View File

@ -0,0 +1,75 @@
<?php
/**
* StatusNet, the distributed open-source microblogging tool
*
* Handler for posting new notices
*
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Bookmarklet
* @package StatusNet
* @author Sarven Capadisli <csarven@status.net>
* @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 <csarven@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/
*/
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()
{
}
}

View File

@ -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)';
}

View File

@ -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');
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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.
<a href="javascript:var%20d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f='http://%%site.server%%/%%site.path%%/index.php?action=newnotice',l=d.location,e=encodeURIComponent,g=f+'&amp;status_textarea=%22'+((e(s))?e(s):e(document.title))+'%22 from '+l.href;function%20a(){if(!w.open(g,'t','toolbar=0,resizable=0,scrollbars=1,status=1,width=800,height=570')){l.href=g;}}a();void(0);">Post to %%site.name%%</a>
<a href="javascript:(function(){var%20d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f='http://%%site.server%%/%%site.path%%/index.php?action=bookmarklet',l=d.location,e=encodeURIComponent,g=f+'&status_textarea=%22'+((e(s))?e(s):e(document.title))+'%22%20%E2%80%94%20'+l.href;function%20a(){if(!w.open(g,'t','toolbar=0,resizable=0,scrollbars=1,status=1,width=450,height=200')){l.href=g;}}a();})()">Post to %%site.name%%</a>

View File

@ -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;

View File

@ -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();
@ -90,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
@ -157,4 +162,27 @@ class Location
}
}
}
/**
* Get an URL suitable for this location
*
* @return string URL for this location or NULL
*/
function getURL()
{
// Keep one cached
if (is_string($this->_url)) {
return $this->_url;
}
$url = null;
Event::handle('LocationUrl', array($this, &$url));
$this->_url = $url;
return $url;
}
}

View File

@ -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
*

View File

@ -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',

View File

@ -58,7 +58,7 @@ class FacebookPlugin extends Plugin
* @return boolean hook return
*/
function onRouterInitialized(&$m)
function onRouterInitialized($m)
{
// Facebook App stuff

View File

@ -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;
}
}

View File

@ -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'));

View File

@ -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',
));

View File

@ -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

View File

@ -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'));

View File

@ -1295,3 +1295,13 @@ display:none;
.guide {
clear:both;
}
#bookmarklet address {
display:none;
}
#bookmarklet #form_notice {
width:auto;
}
#bookmarklet #wrap {
min-width:0;
}