summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSiebrand Mazeland <s.mazeland@xs4all.nl>2009-11-11 19:58:43 +0100
committerSiebrand Mazeland <s.mazeland@xs4all.nl>2009-11-11 19:58:43 +0100
commit086759f32ab6d2c5aadecb57941e7e14015b8bd6 (patch)
tree5b4e2875a7bf02717a8a987d5c1af91318a2fe29 /lib
parent37c62c6356af22a7b1eb444b241083d9fa53166e (diff)
parent6a19bcc0e2e2e0d0743480921e3be787b5b27729 (diff)
Merge branch '0.9.x' of git://gitorious.org/statusnet/mainline into 0.9.x
Diffstat (limited to 'lib')
-rw-r--r--lib/accountsettingsaction.php57
-rw-r--r--lib/api.php56
-rw-r--r--lib/default.php4
-rw-r--r--lib/router.php12
-rw-r--r--lib/search_engines.php71
-rw-r--r--lib/util.php7
6 files changed, 99 insertions, 108 deletions
diff --git a/lib/accountsettingsaction.php b/lib/accountsettingsaction.php
index 9865e1748..c79a1f5d7 100644
--- a/lib/accountsettingsaction.php
+++ b/lib/accountsettingsaction.php
@@ -104,35 +104,29 @@ class AccountSettingsNav extends Widget
if (Event::handle('StartAccountSettingsNav', array(&$this->action))) {
$user = common_current_user();
- $menu = array();
- $menu['profilesettings'] =
- array(_('Profile'),
- _('Change your profile settings'));
- if(Event::handle('CanUserChangeField', array($user->nickname, 'avatar'))){
- $menu['avatarsettings'] =
- array(_('Avatar'),
- _('Upload an avatar'));
+ if(Event::handle('StartAccountSettingsProfileMenuItem', array($this, &$menu))){
+ $this->showMenuItem('profilesettings',_('Profile'),_('Change your profile settings'));
+ Event::handle('EndAccountSettingsProfileMenuItem', array($this, &$menu));
}
- if(Event::handle('CanUserChangeField', array($user->nickname, 'password'))){
- $menu['passwordsettings'] =
- array(_('Password'),
- _('Change your password'));
+ if(Event::handle('StartAccountSettingsAvatarMenuItem', array($this, &$menu))){
+ $this->showMenuItem('avatarsettings',_('Avatar'),_('Upload an avatar'));
+ Event::handle('EndAccountSettingsAvatarMenuItem', array($this, &$menu));
}
- $menu['emailsettings'] =
- array(_('Email'),
- _('Change email handling'));
- $menu['userdesignsettings'] =
- array(_('Design'),
- _('Design your profile'));
- $menu['othersettings'] =
- array(_('Other'),
- _('Other options'));
-
- foreach ($menu as $menuaction => $menudesc) {
- $this->action->menuItem(common_local_url($menuaction),
- $menudesc[0],
- $menudesc[1],
- $action_name === $menuaction);
+ if(Event::handle('StartAccountSettingsPasswordMenuItem', array($this, &$menu))){
+ $this->showMenuItem('passwordsettings',_('Password'),_('Change your password'));
+ Event::handle('EndAccountSettingsPasswordMenuItem', array($this, &$menu));
+ }
+ if(Event::handle('StartAccountSettingsEmailMenuItem', array($this, &$menu))){
+ $this->showMenuItem('emailsettings',_('Email'),_('Change email handling'));
+ Event::handle('EndAccountSettingsEmailMenuItem', array($this, &$menu));
+ }
+ if(Event::handle('StartAccountSettingsDesignMenuItem', array($this, &$menu))){
+ $this->showMenuItem('userdesignsettings',_('Design'),_('Design your profile'));
+ Event::handle('EndAccountSettingsDesignMenuItem', array($this, &$menu));
+ }
+ if(Event::handle('StartAccountSettingsOtherMenuItem', array($this, &$menu))){
+ $this->showMenuItem('othersettings',_('Other'),_('Other options'));
+ Event::handle('EndAccountSettingsOtherMenuItem', array($this, &$menu));
}
Event::handle('EndAccountSettingsNav', array(&$this->action));
@@ -140,4 +134,13 @@ class AccountSettingsNav extends Widget
$this->action->elementEnd('ul');
}
+
+ function showMenuItem($menuaction, $desc1, $desc2)
+ {
+ $action_name = $this->action->trimmed('action');
+ $this->action->menuItem(common_local_url($menuaction),
+ $desc1,
+ $desc2,
+ $action_name === $menuaction);
+ }
}
diff --git a/lib/api.php b/lib/api.php
index a1236ab7e..e2ea87b43 100644
--- a/lib/api.php
+++ b/lib/api.php
@@ -60,7 +60,7 @@ class ApiAction extends Action
var $max_id = null;
var $since_id = null;
var $since = null;
-
+
/**
* Initialization.
*
@@ -72,14 +72,14 @@ class ApiAction extends Action
function prepare($args)
{
parent::prepare($args);
-
+
$this->format = $this->arg('format');
$this->page = (int)$this->arg('page', 1);
$this->count = (int)$this->arg('count', 20);
$this->max_id = (int)$this->arg('max_id', 0);
$this->since_id = (int)$this->arg('since_id', 0);
$this->since = $this->arg('since');
-
+
return true;
}
@@ -164,7 +164,6 @@ class ApiAction extends Action
$twitter_user['favourites_count'] = $profile->faveCount(); // British spelling!
-
$timezone = 'UTC';
if ($user->timezone) {
@@ -177,9 +176,14 @@ class ApiAction extends Action
$twitter_user['utc_offset'] = $t->format('Z');
$twitter_user['time_zone'] = $timezone;
- // To be supported some day, perhaps
- $twitter_user['profile_background_image_url'] = '';
- $twitter_user['profile_background_tile'] = false;
+ $twitter_user['profile_background_image_url']
+ = empty($design->backgroundimage)
+ ? '' : ($design->disposition & BACKGROUND_ON)
+ ? Design::url($design->backgroundimage) : '';
+
+ $twitter_user['profile_background_tile']
+ = empty($design->disposition)
+ ? '' : ($design->disposition & BACKGROUND_TILE) ? 'true' : 'false';
$twitter_user['statuses_count'] = $profile->noticeCount();
@@ -238,6 +242,15 @@ class ApiAction extends Action
$twitter_status['in_reply_to_screen_name'] =
($replier_profile) ? $replier_profile->nickname : null;
+ if (isset($notice->lat) && isset($notice->lon)) {
+ // This is the format that GeoJSON expects stuff to be in
+ $twitter_status['geo'] = array('type' => 'Point',
+ 'coordinates' => array((float) $notice->lat,
+ (float) $notice->lon));
+ } else {
+ $twitter_status['geo'] = null;
+ }
+
if (isset($this->auth_user)) {
$twitter_status['favorited'] = $this->auth_user->hasFave($notice);
} else {
@@ -362,10 +375,19 @@ class ApiAction extends Action
$entry['pubDate'] = common_date_rfc2822($notice->created);
$entry['guid'] = $entry['link'];
+ if (isset($notice->lat) && isset($notice->lon)) {
+ // This is the format that GeoJSON expects stuff to be in.
+ // showGeoRSS() below uses it for XML output, so we reuse it
+ $entry['geo'] = array('type' => 'Point',
+ 'coordinates' => array((float) $notice->lat,
+ (float) $notice->lon));
+ } else {
+ $entry['geo'] = null;
+ }
+
return $entry;
}
-
function twitterRelationshipArray($source, $target)
{
$relationship = array();
@@ -441,6 +463,9 @@ class ApiAction extends Action
case 'attachments':
$this->showXmlAttachments($twitter_status['attachments']);
break;
+ case 'geo':
+ $this->showGeoRSS($value);
+ break;
default:
$this->element($element, null, $value);
}
@@ -484,6 +509,18 @@ class ApiAction extends Action
}
}
+ function showGeoRSS($geo)
+ {
+ if (empty($geo)) {
+ // empty geo element
+ $this->element('geo');
+ } else {
+ $this->elementStart('geo', array('xmlns:georss' => 'http://www.georss.org/georss'));
+ $this->element('georss:point', null, $geo['coordinates'][0] . ' ' . $geo['coordinates'][1]);
+ $this->elementEnd('geo');
+ }
+ }
+
function showTwitterRssItem($entry)
{
$this->elementStart('item');
@@ -505,6 +542,7 @@ class ApiAction extends Action
}
}
+ $this->showGeoRSS($entry['geo']);
$this->elementEnd('item');
}
@@ -529,7 +567,6 @@ class ApiAction extends Action
$this->endDocument('json');
}
-
function showXmlTimeline($notice)
{
@@ -649,7 +686,6 @@ class ApiAction extends Action
$this->endTwitterRss();
}
-
function showTwitterAtomEntry($entry)
{
$this->elementStart('entry');
diff --git a/lib/default.php b/lib/default.php
index f6cc4b725..95366e0b3 100644
--- a/lib/default.php
+++ b/lib/default.php
@@ -125,10 +125,6 @@ $default =
'public' => array()), # JIDs of users who want to receive the public stream
'invite' =>
array('enabled' => true),
- 'sphinx' =>
- array('enabled' => false,
- 'server' => 'localhost',
- 'port' => 3312),
'tag' =>
array('dropoff' => 864000.0),
'popular' =>
diff --git a/lib/router.php b/lib/router.php
index db9fdb470..bad3decad 100644
--- a/lib/router.php
+++ b/lib/router.php
@@ -428,9 +428,21 @@ class Router
$m->connect('api/account/verify_credentials.:format',
array('action' => 'ApiAccountVerifyCredentials'));
+ $m->connect('api/account/update_profile.:format',
+ array('action' => 'ApiAccountUpdateProfile'));
+
$m->connect('api/account/update_profile_image.:format',
array('action' => 'ApiAccountUpdateProfileImage'));
+ $m->connect('api/account/update_profile_background_image.:format',
+ array('action' => 'ApiAccountUpdateProfileBackgroundImage'));
+
+ $m->connect('api/account/update_profile_colors.:format',
+ array('action' => 'ApiAccountUpdateProfileColors'));
+
+ $m->connect('api/account/update_delivery_device.:format',
+ array('action' => 'ApiAccountUpdateDeliveryDevice'));
+
// special case where verify_credentials is called w/out a format
$m->connect('api/account/verify_credentials',
diff --git a/lib/search_engines.php b/lib/search_engines.php
index 69f6ff468..332db3f89 100644
--- a/lib/search_engines.php
+++ b/lib/search_engines.php
@@ -46,70 +46,11 @@ class SearchEngine
}
}
-class SphinxSearch extends SearchEngine
-{
- private $sphinx;
- private $connected;
-
- function __construct($target, $table)
- {
- $fp = @fsockopen(common_config('sphinx', 'server'), common_config('sphinx', 'port'));
- if (!$fp) {
- $this->connected = false;
- return;
- }
- fclose($fp);
- parent::__construct($target, $table);
- $this->sphinx = new SphinxClient;
- $this->sphinx->setServer(common_config('sphinx', 'server'), common_config('sphinx', 'port'));
- $this->connected = true;
- }
-
- function is_connected()
- {
- return $this->connected;
- }
-
- function limit($offset, $count, $rss = false)
- {
- //FIXME without LARGEST_POSSIBLE, the most recent results aren't returned
- // this probably has a large impact on performance
- $LARGEST_POSSIBLE = 1e6;
-
- if ($rss) {
- $this->sphinx->setLimits($offset, $count, $count, $LARGEST_POSSIBLE);
- }
- else {
- // return at most 50 pages of results
- $this->sphinx->setLimits($offset, $count, 50 * ($count - 1), $LARGEST_POSSIBLE);
- }
-
- return $this->target->limit(0, $count);
- }
-
- function query($q)
- {
- $result = $this->sphinx->query($q, $this->table);
- if (!isset($result['matches'])) return false;
- $id_set = join(', ', array_keys($result['matches']));
- $this->target->whereAdd("id in ($id_set)");
- return true;
- }
-
- function set_sort_mode($mode)
- {
- if ('chron' === $mode) {
- $this->sphinx->SetSortMode(SPH_SORT_ATTR_DESC, 'created_ts');
- return $this->target->orderBy('created desc');
- }
- }
-}
-
class MySQLSearch extends SearchEngine
{
function query($q)
{
- if ('identica_people' === $this->table) {
+ if ('profile' === $this->table) {
$this->target->whereAdd('MATCH(nickname, fullname, location, bio, homepage) ' .
'AGAINST (\''.addslashes($q).'\' IN BOOLEAN MODE)');
if (strtolower($q) != $q) {
@@ -117,7 +58,7 @@ class MySQLSearch extends SearchEngine
'AGAINST (\''.addslashes(strtolower($q)).'\' IN BOOLEAN MODE)', 'OR');
}
return true;
- } else if ('identica_notices' === $this->table) {
+ } else if ('notice' === $this->table) {
// Don't show imported notices
$this->target->whereAdd('notice.is_local != ' . Notice::GATEWAY);
@@ -143,13 +84,13 @@ class MySQLLikeSearch extends SearchEngine
{
function query($q)
{
- if ('identica_people' === $this->table) {
+ if ('profile' === $this->table) {
$qry = sprintf('(nickname LIKE "%%%1$s%%" OR '.
' fullname LIKE "%%%1$s%%" OR '.
' location LIKE "%%%1$s%%" OR '.
' bio LIKE "%%%1$s%%" OR '.
' homepage LIKE "%%%1$s%%")', addslashes($q));
- } else if ('identica_notices' === $this->table) {
+ } else if ('notice' === $this->table) {
$qry = sprintf('content LIKE "%%%1$s%%"', addslashes($q));
} else {
throw new ServerException('Unknown table: ' . $this->table);
@@ -165,9 +106,9 @@ class PGSearch extends SearchEngine
{
function query($q)
{
- if ('identica_people' === $this->table) {
+ if ('profile' === $this->table) {
return $this->target->whereAdd('textsearch @@ plainto_tsquery(\''.addslashes($q).'\')');
- } else if ('identica_notices' === $this->table) {
+ } else if ('notice' === $this->table) {
// XXX: We need to filter out gateway notices (notice.is_local = -2) --Zach
diff --git a/lib/util.php b/lib/util.php
index 81160d052..7aca4af8d 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -350,8 +350,11 @@ function common_current_user()
common_ensure_session();
$id = isset($_SESSION['userid']) ? $_SESSION['userid'] : false;
if ($id) {
- $_cur = User::staticGet($id);
- return $_cur;
+ $user = User::staticGet($id);
+ if ($user) {
+ $_cur = $user;
+ return $_cur;
+ }
}
}