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 $email; // 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 $carrier; // int(4)
|
||||
public $smsnotify; // tinyint(1)
|
||||
public $uri; // varchar(255) unique_key
|
||||
public $created; // datetime() not_null
|
||||
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
|
||||
|
@ -128,8 +128,11 @@ nickname = 2
|
||||
password = 2
|
||||
email = 2
|
||||
jabber = 2
|
||||
jabbernotify = 17
|
||||
updatefrompresence = 17
|
||||
sms = 2
|
||||
carrier = 1
|
||||
smsnotify = 17
|
||||
uri = 2
|
||||
created = 142
|
||||
modified = 384
|
||||
|
@ -21,67 +21,60 @@ if (!defined('LACONICA')) { exit(1); }
|
||||
|
||||
class SettingsAction extends Action {
|
||||
|
||||
function handle($args) {
|
||||
parent::handle($args);
|
||||
if (!common_logged_in()) {
|
||||
common_user_error(_t('Not logged in.'));
|
||||
return;
|
||||
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
$this->handle_post();
|
||||
} else {
|
||||
$this->show_form();
|
||||
}
|
||||
}
|
||||
function handle($args) {
|
||||
parent::handle($args);
|
||||
if (!common_logged_in()) {
|
||||
common_user_error(_t('Not logged in.'));
|
||||
return;
|
||||
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
$this->handle_post();
|
||||
} else {
|
||||
$this->show_form();
|
||||
}
|
||||
}
|
||||
|
||||
# override!
|
||||
function handle_post() {
|
||||
return false;
|
||||
}
|
||||
# override!
|
||||
function handle_post() {
|
||||
return false;
|
||||
}
|
||||
|
||||
function show_form($msg=NULL, $success=false) {
|
||||
return false;
|
||||
}
|
||||
function show_form($msg=NULL, $success=false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function message($msg, $success) {
|
||||
if ($msg) {
|
||||
common_element('div', ($success) ? 'success' : 'error',
|
||||
$msg);
|
||||
}
|
||||
}
|
||||
function message($msg, $success) {
|
||||
if ($msg) {
|
||||
common_element('div', ($success) ? 'success' : 'error',
|
||||
$msg);
|
||||
}
|
||||
}
|
||||
|
||||
function settings_menu() {
|
||||
$action = $this->trimmed('action');
|
||||
common_element_start('ul', array('id' => 'nav_views'));
|
||||
common_menu_item(common_local_url('profilesettings'),
|
||||
_t('Profile'),
|
||||
_t('Change your profile settings'),
|
||||
$action == 'profilesettings');
|
||||
common_menu_item(common_local_url('avatar'),
|
||||
_t('Avatar'),
|
||||
_t('Upload a new profile image'),
|
||||
$action == 'avatar');
|
||||
common_menu_item(common_local_url('password'),
|
||||
_t('Password'),
|
||||
_t('Change your password'),
|
||||
$action == 'password');
|
||||
common_menu_item(common_local_url('openidsettings'),
|
||||
_t('OpenID'),
|
||||
_t('Add or remove OpenIDs'),
|
||||
$action == 'openidsettings');
|
||||
if (false) {
|
||||
common_menu_item(common_local_url('emailsettings'),
|
||||
_t('Email'),
|
||||
_t('Address and preferences'),
|
||||
$action == 'emailsettings');
|
||||
common_menu_item(common_local_url('imsettings'),
|
||||
_t('IM'),
|
||||
_t('Notifications by instant messenger'),
|
||||
$action == 'imsettings');
|
||||
common_menu_item(common_local_url('phonesettings'),
|
||||
_t('Phone'),
|
||||
_t('Notifications by phone'),
|
||||
$action == 'phonesettings');
|
||||
}
|
||||
common_element_end('ul');
|
||||
}
|
||||
function settings_menu() {
|
||||
# action => array('prompt', 'title')
|
||||
static $menu =
|
||||
array('profilesettings' =>
|
||||
array('Profile',
|
||||
'Change your profile settings'),
|
||||
'avatar' =>
|
||||
array('Avatar',
|
||||
'Upload a new profile image'),
|
||||
'password' =>
|
||||
array('Password',
|
||||
'Change your password'),
|
||||
'openidsettings' =>
|
||||
array('OpenID',
|
||||
'Add or remove OpenIDs'),
|
||||
'imsettings' =>
|
||||
array('IM',
|
||||
'Updates by instant messenger (IM)'));
|
||||
|
||||
$action = $this->trimmed('action');
|
||||
common_element_start('ul', array('id' => 'nav_views'));
|
||||
foreach ($menu as $menuaction => $menudesc) {
|
||||
common_menu_item(common_local_url($menuaction),
|
||||
_t($menudesc[0]),
|
||||
_t($menudesc[1]));
|
||||
}
|
||||
common_element_end('ul');
|
||||
}
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ class XMPPDaemon {
|
||||
$resource = $matches[3];
|
||||
return strtolower($node.'@'.$server);
|
||||
}
|
||||
|
||||
|
||||
function handle() {
|
||||
while(!$this->conn->disconnected) {
|
||||
$payloads = $this->conn->processUntil(array('message', 'presence',
|
||||
@ -81,6 +81,12 @@ class XMPPDaemon {
|
||||
}
|
||||
|
||||
function handle_message(&$pl) {
|
||||
if ($pl['type'] != 'chat') {
|
||||
return;
|
||||
}
|
||||
if (strlen($pl['body']) == 0) {
|
||||
return;
|
||||
}
|
||||
$from = $this->normalize_jid($pl['from']);
|
||||
$user = User::staticGet('jabber', $from);
|
||||
if (!$user) {
|
||||
|
Loading…
Reference in New Issue
Block a user