Merge branch 'locshunt' into 0.9.x
This commit is contained in:
commit
e119362fde
|
@ -203,12 +203,6 @@ class ApiStatusesUpdateAction extends ApiAuthAction
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$location = null;
|
|
||||||
|
|
||||||
if (!empty($this->lat) && !empty($this->lon)) {
|
|
||||||
$location = Location::fromLatLon($this->lat, $this->lon);
|
|
||||||
}
|
|
||||||
|
|
||||||
$upload = null;
|
$upload = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -235,11 +229,15 @@ class ApiStatusesUpdateAction extends ApiAuthAction
|
||||||
|
|
||||||
$options = array('reply_to' => $reply_to);
|
$options = array('reply_to' => $reply_to);
|
||||||
|
|
||||||
if (!empty($location)) {
|
if ($this->user->shareLocation()) {
|
||||||
$options['lat'] = $location->lat;
|
|
||||||
$options['lon'] = $location->lon;
|
$locOptions = Notice::locationOptions($this->lat,
|
||||||
$options['location_id'] = $location->location_id;
|
$this->lon,
|
||||||
$options['location_ns'] = $location->location_ns;
|
null,
|
||||||
|
null,
|
||||||
|
$this->user->getProfile());
|
||||||
|
|
||||||
|
$options = array_merge($options, $locOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->notice =
|
$this->notice =
|
||||||
|
|
|
@ -164,19 +164,6 @@ class NewnoticeAction extends Action
|
||||||
$replyto = 'false';
|
$replyto = 'false';
|
||||||
}
|
}
|
||||||
|
|
||||||
$lat = $this->trimmed('lat');
|
|
||||||
$lon = $this->trimmed('lon');
|
|
||||||
$location_id = $this->trimmed('location_id');
|
|
||||||
$location_ns = $this->trimmed('location_ns');
|
|
||||||
|
|
||||||
if (!empty($lat) && !empty($lon) && empty($location_id)) {
|
|
||||||
$location = Location::fromLatLon($lat, $lon);
|
|
||||||
if (!empty($location)) {
|
|
||||||
$location_id = $location->location_id;
|
|
||||||
$location_ns = $location->location_ns;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$upload = null;
|
$upload = null;
|
||||||
$upload = MediaFile::fromUpload('attach');
|
$upload = MediaFile::fromUpload('attach');
|
||||||
|
|
||||||
|
@ -195,12 +182,20 @@ class NewnoticeAction extends Action
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$notice = Notice::saveNew($user->id, $content_shortened, 'web',
|
$options = array('reply_to' => ($replyto == 'false') ? null : $replyto);
|
||||||
array('reply_to' => ($replyto == 'false') ? null : $replyto,
|
|
||||||
'lat' => $lat,
|
if ($user->shareLocation()) {
|
||||||
'lon' => $lon,
|
|
||||||
'location_id' => $location_id,
|
$locOptions = Notice::locationOptions($this->trimmed('lat'),
|
||||||
'location_ns' => $location_ns));
|
$this->trimmed('lon'),
|
||||||
|
$this->trimmed('location_id'),
|
||||||
|
$this->trimmed('location_ns'),
|
||||||
|
$user->getProfile());
|
||||||
|
|
||||||
|
$options = array_merge($options, $locOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
$notice = Notice::saveNew($user->id, $content_shortened, 'web', $options);
|
||||||
|
|
||||||
if (isset($upload)) {
|
if (isset($upload)) {
|
||||||
$upload->attachToNotice($notice);
|
$upload->attachToNotice($notice);
|
||||||
|
|
|
@ -133,6 +133,13 @@ class ProfilesettingsAction extends AccountSettingsAction
|
||||||
($this->arg('location')) ? $this->arg('location') : $profile->location,
|
($this->arg('location')) ? $this->arg('location') : $profile->location,
|
||||||
_('Where you are, like "City, State (or Region), Country"'));
|
_('Where you are, like "City, State (or Region), Country"'));
|
||||||
$this->elementEnd('li');
|
$this->elementEnd('li');
|
||||||
|
if (common_config('location', 'share') == 'user') {
|
||||||
|
$this->elementStart('li');
|
||||||
|
$this->checkbox('sharelocation', _('Share my current location when posting notices'),
|
||||||
|
($this->arg('sharelocation')) ?
|
||||||
|
$this->arg('sharelocation') : $user->shareLocation());
|
||||||
|
$this->elementEnd('li');
|
||||||
|
}
|
||||||
Event::handle('EndProfileFormData', array($this));
|
Event::handle('EndProfileFormData', array($this));
|
||||||
$this->elementStart('li');
|
$this->elementStart('li');
|
||||||
$this->input('tags', _('Tags'),
|
$this->input('tags', _('Tags'),
|
||||||
|
@ -318,6 +325,37 @@ class ProfilesettingsAction extends AccountSettingsAction
|
||||||
|
|
||||||
$profile->profileurl = common_profile_url($nickname);
|
$profile->profileurl = common_profile_url($nickname);
|
||||||
|
|
||||||
|
if (common_config('location', 'share') == 'user') {
|
||||||
|
|
||||||
|
$exists = false;
|
||||||
|
|
||||||
|
$prefs = User_location_prefs::staticGet('user_id', $user->id);
|
||||||
|
|
||||||
|
if (empty($prefs)) {
|
||||||
|
$prefs = new User_location_prefs();
|
||||||
|
|
||||||
|
$prefs->user_id = $user->id;
|
||||||
|
$prefs->created = common_sql_now();
|
||||||
|
} else {
|
||||||
|
$exists = true;
|
||||||
|
$orig = clone($prefs);
|
||||||
|
}
|
||||||
|
|
||||||
|
$prefs->share_location = $this->boolean('sharelocation');
|
||||||
|
|
||||||
|
if ($exists) {
|
||||||
|
$result = $prefs->update($orig);
|
||||||
|
} else {
|
||||||
|
$result = $prefs->insert();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($result === false) {
|
||||||
|
common_log_db_error($prefs, ($exists) ? 'UPDATE' : 'INSERT', __FILE__);
|
||||||
|
$this->serverError(_('Couldn\'t save location prefs.'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
common_debug('Old profile: ' . common_log_objstring($orig_profile), __FILE__);
|
common_debug('Old profile: ' . common_log_objstring($orig_profile), __FILE__);
|
||||||
common_debug('New profile: ' . common_log_objstring($profile), __FILE__);
|
common_debug('New profile: ' . common_log_objstring($profile), __FILE__);
|
||||||
|
|
||||||
|
|
|
@ -289,21 +289,11 @@ class Notice extends Memcached_DataObject
|
||||||
if (!empty($lat) && !empty($lon)) {
|
if (!empty($lat) && !empty($lon)) {
|
||||||
$notice->lat = $lat;
|
$notice->lat = $lat;
|
||||||
$notice->lon = $lon;
|
$notice->lon = $lon;
|
||||||
$notice->location_id = $location_id;
|
|
||||||
$notice->location_ns = $location_ns;
|
|
||||||
} else if (!empty($location_ns) && !empty($location_id)) {
|
|
||||||
$location = Location::fromId($location_id, $location_ns);
|
|
||||||
if (!empty($location)) {
|
|
||||||
$notice->lat = $location->lat;
|
|
||||||
$notice->lon = $location->lon;
|
|
||||||
$notice->location_id = $location_id;
|
|
||||||
$notice->location_ns = $location_ns;
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$notice->lat = $profile->lat;
|
if (!empty($location_ns) && !empty($location_id)) {
|
||||||
$notice->lon = $profile->lon;
|
$notice->location_id = $location_id;
|
||||||
$notice->location_id = $profile->location_id;
|
$notice->location_ns = $location_ns;
|
||||||
$notice->location_ns = $profile->location_ns;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Event::handle('StartNoticeSave', array(&$notice))) {
|
if (Event::handle('StartNoticeSave', array(&$notice))) {
|
||||||
|
@ -1429,4 +1419,47 @@ class Notice extends Memcached_DataObject
|
||||||
|
|
||||||
return $ids;
|
return $ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function locationOptions($lat, $lon, $location_id, $location_ns, $profile = null)
|
||||||
|
{
|
||||||
|
$options = array();
|
||||||
|
|
||||||
|
if (!empty($location_id) && !empty($location_ns)) {
|
||||||
|
|
||||||
|
$options['location_id'] = $location_id;
|
||||||
|
$options['location_ns'] = $location_ns;
|
||||||
|
|
||||||
|
$location = Location::fromId($location_id, $location_ns);
|
||||||
|
|
||||||
|
if (!empty($location)) {
|
||||||
|
$options['lat'] = $location->lat;
|
||||||
|
$options['lon'] = $location->lon;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (!empty($lat) && !empty($lon)) {
|
||||||
|
|
||||||
|
$options['lat'] = $lat;
|
||||||
|
$options['lon'] = $lon;
|
||||||
|
|
||||||
|
$location = Location::fromLatLon($lat, $lon);
|
||||||
|
|
||||||
|
if (!empty($location)) {
|
||||||
|
$options['location_id'] = $location->location_id;
|
||||||
|
$options['location_ns'] = $location->location_ns;
|
||||||
|
}
|
||||||
|
} else if (!empty($profile)) {
|
||||||
|
|
||||||
|
if (isset($profile->lat) && isset($profile->lon)) {
|
||||||
|
$options['lat'] = $profile->lat;
|
||||||
|
$options['lon'] = $profile->lon;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($profile->location_id) && isset($profile->location_ns)) {
|
||||||
|
$options['location_id'] = $profile->location_id;
|
||||||
|
$options['location_ns'] = $profile->location_ns;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $options;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -996,4 +996,28 @@ class User extends Memcached_DataObject
|
||||||
|
|
||||||
return $ids;
|
return $ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function shareLocation()
|
||||||
|
{
|
||||||
|
$cfg = common_config('location', 'share');
|
||||||
|
|
||||||
|
if ($cfg == 'always') {
|
||||||
|
return true;
|
||||||
|
} else if ($cfg == 'never') {
|
||||||
|
return false;
|
||||||
|
} else { // user
|
||||||
|
$share = true;
|
||||||
|
|
||||||
|
$prefs = User_location_prefs::staticGet('user_id', $this->id);
|
||||||
|
|
||||||
|
if (empty($prefs)) {
|
||||||
|
$share = common_config('location', 'sharedefault');
|
||||||
|
} else {
|
||||||
|
$share = $prefs->share_location;
|
||||||
|
$prefs->free();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $share;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
48
classes/User_location_prefs.php
Normal file
48
classes/User_location_prefs.php
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* StatusNet, the distributed open-source microblogging tool
|
||||||
|
*
|
||||||
|
* Data class for user location preferences
|
||||||
|
*
|
||||||
|
* 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 Data
|
||||||
|
* @package StatusNet
|
||||||
|
* @author Evan Prodromou <evan@status.net>
|
||||||
|
* @copyright 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/
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
|
||||||
|
|
||||||
|
class User_location_prefs extends Memcached_DataObject
|
||||||
|
{
|
||||||
|
###START_AUTOCODE
|
||||||
|
/* the code below is auto generated do not remove the above tag */
|
||||||
|
|
||||||
|
public $__table = 'user_location_prefs'; // table name
|
||||||
|
public $user_id; // int(4) primary_key not_null
|
||||||
|
public $share_location; // tinyint(1) default_1
|
||||||
|
public $created; // datetime not_null default_0000-00-00%2000%3A00%3A00
|
||||||
|
public $modified; // timestamp not_null default_CURRENT_TIMESTAMP
|
||||||
|
|
||||||
|
/* Static get */
|
||||||
|
function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('User_location_prefs',$k,$v); }
|
||||||
|
|
||||||
|
/* the code above is auto generated do not remove the tag below */
|
||||||
|
###END_AUTOCODE
|
||||||
|
}
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
[avatar]
|
[avatar]
|
||||||
profile_id = 129
|
profile_id = 129
|
||||||
original = 17
|
original = 17
|
||||||
|
@ -565,3 +564,13 @@ modified = 384
|
||||||
[user_openid__keys]
|
[user_openid__keys]
|
||||||
trustroot = K
|
trustroot = K
|
||||||
user_id = K
|
user_id = K
|
||||||
|
|
||||||
|
[user_location_prefs]
|
||||||
|
user_id = 129
|
||||||
|
share_location = 17
|
||||||
|
created = 142
|
||||||
|
modified = 384
|
||||||
|
|
||||||
|
[user_location_prefs__keys]
|
||||||
|
user_id = N
|
||||||
|
|
||||||
|
|
|
@ -84,3 +84,13 @@ create table login_token (
|
||||||
|
|
||||||
constraint primary key (user_id)
|
constraint primary key (user_id)
|
||||||
) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
|
) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
|
||||||
|
|
||||||
|
create table user_location_prefs (
|
||||||
|
user_id integer not null comment 'user who has the preference' references user (id),
|
||||||
|
share_location tinyint default 1 comment 'Whether to share location data',
|
||||||
|
created datetime not null comment 'date this record was created',
|
||||||
|
modified timestamp comment 'date this record was modified',
|
||||||
|
|
||||||
|
constraint primary key (user_id)
|
||||||
|
) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
|
||||||
|
|
||||||
|
|
|
@ -587,3 +587,12 @@ create table login_token (
|
||||||
constraint primary key (user_id)
|
constraint primary key (user_id)
|
||||||
) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
|
) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
|
||||||
|
|
||||||
|
create table user_location_prefs (
|
||||||
|
user_id integer not null comment 'user who has the preference' references user (id),
|
||||||
|
share_location tinyint default 1 comment 'Whether to share location data',
|
||||||
|
created datetime not null comment 'date this record was created',
|
||||||
|
modified timestamp comment 'date this record was modified',
|
||||||
|
|
||||||
|
constraint primary key (user_id)
|
||||||
|
) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin;
|
||||||
|
|
||||||
|
|
|
@ -226,7 +226,8 @@ $default =
|
||||||
'message' =>
|
'message' =>
|
||||||
array('contentlimit' => null),
|
array('contentlimit' => null),
|
||||||
'location' =>
|
'location' =>
|
||||||
array('namespace' => 1), // 1 = geonames, 2 = Yahoo Where on Earth
|
array('share' => 'user', // whether to share location; 'always', 'user', 'never'
|
||||||
|
'sharedefault' => true),
|
||||||
'omb' =>
|
'omb' =>
|
||||||
array('timeout' => 5), // HTTP request timeout in seconds when contacting remote hosts for OMB updates
|
array('timeout' => 5), // HTTP request timeout in seconds when contacting remote hosts for OMB updates
|
||||||
'logincommand' =>
|
'logincommand' =>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user