add imsettings to menu
darcs-hash:20080623223641-34904-2758e19c70026a0c169e99d86481d87b0b4bc79c.gz
This commit is contained in:
parent
e4f5893f73
commit
ae40dfe842
120
actions/imsettings.php
Normal file
120
actions/imsettings.php
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Laconica - a distributed open-source microblogging tool
|
||||||
|
* Copyright (C) 2008, Controlez-Vous, Inc.
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!defined('LACONICA')) { exit(1); }
|
||||||
|
|
||||||
|
require_once(INSTALLDIR.'/lib/settingsaction.php');
|
||||||
|
|
||||||
|
class ImsettingsAction extends SettingsAction {
|
||||||
|
|
||||||
|
function show_top($arr) {
|
||||||
|
$msg = $arr[0];
|
||||||
|
$success = $arr[1];
|
||||||
|
if ($msg) {
|
||||||
|
$this->message($msg, $success);
|
||||||
|
} else {
|
||||||
|
common_element('div', 'instructions',
|
||||||
|
_t('You can send and receive notices through '.
|
||||||
|
'Jabber/GTalk instant messages. Configure '.
|
||||||
|
'your address and settings below.'));
|
||||||
|
}
|
||||||
|
$this->settings_menu();
|
||||||
|
}
|
||||||
|
|
||||||
|
function show_form($msg=NULL, $success=false) {
|
||||||
|
$user = common_current_user();
|
||||||
|
common_show_header(_t('IM settings'), NULL, array($msg, $success),
|
||||||
|
array($this, 'show_top'));
|
||||||
|
|
||||||
|
common_element_start('form', array('method' => 'POST',
|
||||||
|
'id' => 'imsettings',
|
||||||
|
'action' =>
|
||||||
|
common_local_url('imsettings')));
|
||||||
|
# too much common patterns here... abstractable?
|
||||||
|
common_input('jabber', _t('IM Address'),
|
||||||
|
($this->arg('jabber')) ? $this->arg('jabber') : $user->jabber,
|
||||||
|
_t('Jabber or GTalk address, like "UserName@example.org"'));
|
||||||
|
common_checkbox('jabbernotify',
|
||||||
|
_t('Send me notices through Jabber/GTalk.'));
|
||||||
|
common_checkbox('updatefrompresence',
|
||||||
|
_t('Post a notice when my Jabber/GTalk status changes.'));
|
||||||
|
common_submit('submit', _t('Save'));
|
||||||
|
common_element_end('form');
|
||||||
|
common_show_footer();
|
||||||
|
}
|
||||||
|
|
||||||
|
function handle_post() {
|
||||||
|
|
||||||
|
$jabber = $this->trimmed('jabber');
|
||||||
|
$jabbernotify = $this->boolean('jabbernotify');
|
||||||
|
$updatefrompresence = $this->boolean('updatefrompresence');
|
||||||
|
|
||||||
|
if (!jabber_validate_jid($jabber)) {
|
||||||
|
$this->show_form(_('Not a valid Jabber ID'));
|
||||||
|
return;
|
||||||
|
} else if ($this->jabber_exists($jabber)) {
|
||||||
|
$this->show_form(_('Not a valid Jabber ID'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Some validation
|
||||||
|
|
||||||
|
$user = common_current_user();
|
||||||
|
|
||||||
|
assert(!is_null($user)); # should already be checked
|
||||||
|
|
||||||
|
$user->query('BEGIN');
|
||||||
|
|
||||||
|
$original = clone($user);
|
||||||
|
|
||||||
|
$user->jabber = $jabber;
|
||||||
|
$user->jabbernotify = $jabbernotify;
|
||||||
|
$user->updatefrompresence = $updatefrompresence;
|
||||||
|
|
||||||
|
$result = $user->updateKeys($original); # For key columns
|
||||||
|
|
||||||
|
if ($result === FALSE) {
|
||||||
|
common_log_db_error($user, 'UPDATE', __FILE__);
|
||||||
|
common_server_error(_t('Couldnt update user.'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $user->update($original); # For non-key columns
|
||||||
|
|
||||||
|
if ($result === FALSE) {
|
||||||
|
common_log_db_error($user, 'UPDATE', __FILE__);
|
||||||
|
common_server_error(_t('Couldnt update user.'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$user->query('COMMIT');
|
||||||
|
|
||||||
|
$this->show_form(_t('Settings saved.'), TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
function jabber_exists($jabber) {
|
||||||
|
$user = common_current_user();
|
||||||
|
$other = User::staticGet('jabber', $jabber);
|
||||||
|
if (!$other) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return $other->id != $user->id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -35,8 +35,11 @@ class User extends DB_DataObject
|
||||||
public $password; // varchar(255)
|
public $password; // varchar(255)
|
||||||
public $email; // varchar(255) unique_key
|
public $email; // varchar(255) unique_key
|
||||||
public $jabber; // varchar(255) unique_key
|
public $jabber; // varchar(255) unique_key
|
||||||
|
public $jabbernotify; // tinyint(1)
|
||||||
|
public $updatefrompresence; // tinyint(1)
|
||||||
public $sms; // varchar(64) unique_key
|
public $sms; // varchar(64) unique_key
|
||||||
public $carrier; // int(4)
|
public $carrier; // int(4)
|
||||||
|
public $smsnotify; // tinyint(1)
|
||||||
public $uri; // varchar(255) unique_key
|
public $uri; // varchar(255) unique_key
|
||||||
public $created; // datetime() not_null
|
public $created; // datetime() not_null
|
||||||
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
|
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
|
||||||
|
|
|
@ -128,8 +128,11 @@ nickname = 2
|
||||||
password = 2
|
password = 2
|
||||||
email = 2
|
email = 2
|
||||||
jabber = 2
|
jabber = 2
|
||||||
|
jabbernotify = 17
|
||||||
|
updatefrompresence = 17
|
||||||
sms = 2
|
sms = 2
|
||||||
carrier = 1
|
carrier = 1
|
||||||
|
smsnotify = 17
|
||||||
uri = 2
|
uri = 2
|
||||||
created = 142
|
created = 142
|
||||||
modified = 384
|
modified = 384
|
||||||
|
|
|
@ -21,67 +21,60 @@ if (!defined('LACONICA')) { exit(1); }
|
||||||
|
|
||||||
class SettingsAction extends Action {
|
class SettingsAction extends Action {
|
||||||
|
|
||||||
function handle($args) {
|
function handle($args) {
|
||||||
parent::handle($args);
|
parent::handle($args);
|
||||||
if (!common_logged_in()) {
|
if (!common_logged_in()) {
|
||||||
common_user_error(_t('Not logged in.'));
|
common_user_error(_t('Not logged in.'));
|
||||||
return;
|
return;
|
||||||
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||||
$this->handle_post();
|
$this->handle_post();
|
||||||
} else {
|
} else {
|
||||||
$this->show_form();
|
$this->show_form();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# override!
|
# override!
|
||||||
function handle_post() {
|
function handle_post() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function show_form($msg=NULL, $success=false) {
|
function show_form($msg=NULL, $success=false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function message($msg, $success) {
|
function message($msg, $success) {
|
||||||
if ($msg) {
|
if ($msg) {
|
||||||
common_element('div', ($success) ? 'success' : 'error',
|
common_element('div', ($success) ? 'success' : 'error',
|
||||||
$msg);
|
$msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function settings_menu() {
|
function settings_menu() {
|
||||||
$action = $this->trimmed('action');
|
# action => array('prompt', 'title')
|
||||||
common_element_start('ul', array('id' => 'nav_views'));
|
static $menu =
|
||||||
common_menu_item(common_local_url('profilesettings'),
|
array('profilesettings' =>
|
||||||
_t('Profile'),
|
array('Profile',
|
||||||
_t('Change your profile settings'),
|
'Change your profile settings'),
|
||||||
$action == 'profilesettings');
|
'avatar' =>
|
||||||
common_menu_item(common_local_url('avatar'),
|
array('Avatar',
|
||||||
_t('Avatar'),
|
'Upload a new profile image'),
|
||||||
_t('Upload a new profile image'),
|
'password' =>
|
||||||
$action == 'avatar');
|
array('Password',
|
||||||
common_menu_item(common_local_url('password'),
|
'Change your password'),
|
||||||
_t('Password'),
|
'openidsettings' =>
|
||||||
_t('Change your password'),
|
array('OpenID',
|
||||||
$action == 'password');
|
'Add or remove OpenIDs'),
|
||||||
common_menu_item(common_local_url('openidsettings'),
|
'imsettings' =>
|
||||||
_t('OpenID'),
|
array('IM',
|
||||||
_t('Add or remove OpenIDs'),
|
'Updates by instant messenger (IM)'));
|
||||||
$action == 'openidsettings');
|
|
||||||
if (false) {
|
$action = $this->trimmed('action');
|
||||||
common_menu_item(common_local_url('emailsettings'),
|
common_element_start('ul', array('id' => 'nav_views'));
|
||||||
_t('Email'),
|
foreach ($menu as $menuaction => $menudesc) {
|
||||||
_t('Address and preferences'),
|
common_menu_item(common_local_url($menuaction),
|
||||||
$action == 'emailsettings');
|
_t($menudesc[0]),
|
||||||
common_menu_item(common_local_url('imsettings'),
|
_t($menudesc[1]));
|
||||||
_t('IM'),
|
}
|
||||||
_t('Notifications by instant messenger'),
|
common_element_end('ul');
|
||||||
$action == 'imsettings');
|
}
|
||||||
common_menu_item(common_local_url('phonesettings'),
|
|
||||||
_t('Phone'),
|
|
||||||
_t('Notifications by phone'),
|
|
||||||
$action == 'phonesettings');
|
|
||||||
}
|
|
||||||
common_element_end('ul');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,6 +81,12 @@ class XMPPDaemon {
|
||||||
}
|
}
|
||||||
|
|
||||||
function handle_message(&$pl) {
|
function handle_message(&$pl) {
|
||||||
|
if ($pl['type'] != 'chat') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (strlen($pl['body']) == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
$from = $this->normalize_jid($pl['from']);
|
$from = $this->normalize_jid($pl['from']);
|
||||||
$user = User::staticGet('jabber', $from);
|
$user = User::staticGet('jabber', $from);
|
||||||
if (!$user) {
|
if (!$user) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user