[DATABASE] Set NULL in DB_DataObject in a more reliable manner
Also stop assuming that FeedSub::sub_state (enum) and FeedSub::sub_end (datetime) can possibly be set to an empty string.
This commit is contained in:
parent
d26aac77b3
commit
6fae840ee7
|
@ -1,48 +1,40 @@
|
|||
<?php
|
||||
// This file is part of GNU social - https://www.gnu.org/software/social
|
||||
//
|
||||
// GNU social 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.
|
||||
//
|
||||
// GNU social 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 GNU social. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* StatusNet, the distributed open-source microblogging tool
|
||||
*
|
||||
* Settings for email
|
||||
*
|
||||
* 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 Settings
|
||||
* @package StatusNet
|
||||
* @package GNUsocial
|
||||
* @author Evan Prodromou <evan@status.net>
|
||||
* @author Zach Copley <zach@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/
|
||||
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||
*/
|
||||
|
||||
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||
defined('GNUSOCIAL') || die();
|
||||
|
||||
/**
|
||||
* Settings for email
|
||||
*
|
||||
* @category Settings
|
||||
* @package StatusNet
|
||||
* @author Evan Prodromou <evan@status.net>
|
||||
* @author Zach Copley <zach@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/
|
||||
* @copyright 2008-2009 StatusNet, Inc.
|
||||
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||
*
|
||||
* @see Widget
|
||||
*/
|
||||
|
||||
class EmailsettingsAction extends SettingsAction
|
||||
{
|
||||
/**
|
||||
|
@ -50,7 +42,7 @@ class EmailsettingsAction extends SettingsAction
|
|||
*
|
||||
* @return string Title of the page
|
||||
*/
|
||||
function title()
|
||||
public function title()
|
||||
{
|
||||
// TRANS: Title for e-mail settings.
|
||||
return _('Email settings');
|
||||
|
@ -61,7 +53,7 @@ class EmailsettingsAction extends SettingsAction
|
|||
*
|
||||
* @return instructions for use
|
||||
*/
|
||||
function getInstructions()
|
||||
public function getInstructions()
|
||||
{
|
||||
// XXX: For consistency of parameters in messages, this should be a
|
||||
// regular parameters, replaced with sprintf().
|
||||
|
@ -70,7 +62,7 @@ class EmailsettingsAction extends SettingsAction
|
|||
return _('Manage how you get email from %%site.name%%.');
|
||||
}
|
||||
|
||||
function showScripts()
|
||||
public function showScripts()
|
||||
{
|
||||
parent::showScripts();
|
||||
$this->script('emailsettings.js');
|
||||
|
@ -85,7 +77,7 @@ class EmailsettingsAction extends SettingsAction
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
function showContent()
|
||||
public function showContent()
|
||||
{
|
||||
$user = $this->scoped->getUser();
|
||||
|
||||
|
@ -106,50 +98,58 @@ class EmailsettingsAction extends SettingsAction
|
|||
$this->element('p', array('class' => 'form_note'), _('Current confirmed email address.'));
|
||||
$this->hidden('email', $user->email);
|
||||
// TRANS: Button label to remove a confirmed e-mail address.
|
||||
$this->submit('remove', _m('BUTTON','Remove'));
|
||||
$this->submit('remove', _m('BUTTON', 'Remove'));
|
||||
} else {
|
||||
try {
|
||||
$confirm = $this->getConfirmation();
|
||||
$this->element('p', array('id' => 'form_unconfirmed'), $confirm->address);
|
||||
$this->element('p', array('class' => 'form_note'),
|
||||
// TRANS: Form note in e-mail settings form.
|
||||
_('Awaiting confirmation on this address. '.
|
||||
'Check your inbox (and spam box!) for a message '.
|
||||
'with further instructions.'));
|
||||
$this->element(
|
||||
'p',
|
||||
['class' => 'form_note'],
|
||||
// TRANS: Form note in e-mail settings form.
|
||||
_('Awaiting confirmation on this address. '.
|
||||
'Check your inbox (and spam box!) for a message '.
|
||||
'with further instructions.')
|
||||
);
|
||||
$this->hidden('email', $confirm->address);
|
||||
// TRANS: Button label to cancel an e-mail address confirmation procedure.
|
||||
$this->submit('cancel', _m('BUTTON','Cancel'));
|
||||
$this->submit('cancel', _m('BUTTON', 'Cancel'));
|
||||
} catch (NoResultException $e) {
|
||||
$this->elementStart('ul', 'form_data');
|
||||
$this->elementStart('li');
|
||||
// TRANS: Field label for e-mail address input in e-mail settings form.
|
||||
$this->input('email', _('Email address'),
|
||||
$this->trimmed('email') ?: null,
|
||||
// TRANS: Instructions for e-mail address input form. Do not translate
|
||||
// TRANS: "example.org". It is one of the domain names reserved for
|
||||
// TRANS: use in examples by http://www.rfc-editor.org/rfc/rfc2606.txt.
|
||||
// TRANS: Any other domain may be owned by a legitimate person or
|
||||
// TRANS: organization.
|
||||
_('Email address, like "UserName@example.org"'));
|
||||
$this->input(
|
||||
'email',
|
||||
_('Email address'),
|
||||
$this->trimmed('email') ?: null,
|
||||
// TRANS: Instructions for e-mail address input form. Do not translate
|
||||
// TRANS: "example.org". It is one of the domain names reserved for
|
||||
// TRANS: use in examples by http://www.rfc-editor.org/rfc/rfc2606.txt.
|
||||
// TRANS: Any other domain may be owned by a legitimate person or
|
||||
// TRANS: organization.
|
||||
_('Email address, like "UserName@example.org"')
|
||||
);
|
||||
$this->elementEnd('li');
|
||||
$this->elementEnd('ul');
|
||||
// TRANS: Button label for adding an e-mail address in e-mail settings form.
|
||||
$this->submit('add', _m('BUTTON','Add'));
|
||||
$this->submit('add', _m('BUTTON', 'Add'));
|
||||
}
|
||||
}
|
||||
$this->elementEnd('fieldset');
|
||||
|
||||
if (common_config('emailpost', 'enabled') && $user->email) {
|
||||
if (common_config('emailpost', 'enabled') && $user->email) {
|
||||
$this->elementStart('fieldset', array('id' => 'settings_email_incoming'));
|
||||
// TRANS: Form legend for incoming e-mail settings form.
|
||||
$this->element('legend', null, _('Incoming email'));
|
||||
|
||||
$this->elementStart('ul', 'form_data');
|
||||
$this->elementStart('li');
|
||||
$this->checkbox('emailpost',
|
||||
// TRANS: Checkbox label in e-mail preferences form.
|
||||
_('I want to post notices by email.'),
|
||||
$user->emailpost);
|
||||
$this->checkbox(
|
||||
'emailpost',
|
||||
// TRANS: Checkbox label in e-mail preferences form.
|
||||
_('I want to post notices by email.'),
|
||||
$user->emailpost
|
||||
);
|
||||
$this->elementEnd('li');
|
||||
$this->elementEnd('ul');
|
||||
|
||||
|
@ -168,12 +168,15 @@ class EmailsettingsAction extends SettingsAction
|
|||
$this->element('span', 'address', $user->incomingemail);
|
||||
// @todo XXX: Looks a little awkward in the UI.
|
||||
// Something like "xxxx@identi.ca Send email ..". Needs improvement.
|
||||
$this->element('span', 'input_instructions',
|
||||
// TRANS: Form instructions for incoming e-mail form in e-mail settings.
|
||||
_('Send email to this address to post new notices.'));
|
||||
$this->element(
|
||||
'span',
|
||||
'input_instructions',
|
||||
// TRANS: Form instructions for incoming e-mail form in e-mail settings.
|
||||
_('Send email to this address to post new notices.')
|
||||
);
|
||||
$this->elementEnd('p');
|
||||
// TRANS: Button label for removing a set sender e-mail address to post notices from.
|
||||
$this->submit('removeincoming', _m('BUTTON','Remove'));
|
||||
$this->submit('removeincoming', _m('BUTTON', 'Remove'));
|
||||
}
|
||||
|
||||
$this->elementStart('p');
|
||||
|
@ -189,7 +192,7 @@ class EmailsettingsAction extends SettingsAction
|
|||
$this->elementEnd('p');
|
||||
|
||||
// TRANS: Button label for adding an e-mail address to send notices from.
|
||||
$this->submit('newincoming', _m('BUTTON','New'));
|
||||
$this->submit('newincoming', _m('BUTTON', 'New'));
|
||||
|
||||
$this->elementEnd('div'); // div#emailincoming
|
||||
|
||||
|
@ -204,34 +207,42 @@ class EmailsettingsAction extends SettingsAction
|
|||
|
||||
if (Event::handle('StartEmailFormData', array($this, $this->scoped))) {
|
||||
$this->elementStart('li');
|
||||
$this->checkbox('emailnotifysub',
|
||||
// TRANS: Checkbox label in e-mail preferences form.
|
||||
_('Send me notices of new subscriptions through email.'),
|
||||
$user->emailnotifysub);
|
||||
$this->checkbox(
|
||||
'emailnotifysub',
|
||||
// TRANS: Checkbox label in e-mail preferences form.
|
||||
_('Send me notices of new subscriptions through email.'),
|
||||
$user->emailnotifysub
|
||||
);
|
||||
$this->elementEnd('li');
|
||||
$this->elementStart('li');
|
||||
$this->checkbox('emailnotifymsg',
|
||||
// TRANS: Checkbox label in e-mail preferences form.
|
||||
_('Send me email when someone sends me a private message.'),
|
||||
$user->emailnotifymsg);
|
||||
$this->checkbox(
|
||||
'emailnotifymsg',
|
||||
// TRANS: Checkbox label in e-mail preferences form.
|
||||
_('Send me email when someone sends me a private message.'),
|
||||
$user->emailnotifymsg
|
||||
);
|
||||
$this->elementEnd('li');
|
||||
$this->elementStart('li');
|
||||
$this->checkbox('emailnotifyattn',
|
||||
// TRANS: Checkbox label in e-mail preferences form.
|
||||
_('Send me email when someone sends me an "@-reply".'),
|
||||
$user->emailnotifyattn);
|
||||
$this->checkbox(
|
||||
'emailnotifyattn',
|
||||
// TRANS: Checkbox label in e-mail preferences form.
|
||||
_('Send me email when someone sends me an "@-reply".'),
|
||||
$user->emailnotifyattn
|
||||
);
|
||||
$this->elementEnd('li');
|
||||
$this->elementStart('li');
|
||||
$this->checkbox('emailnotifynudge',
|
||||
// TRANS: Checkbox label in e-mail preferences form.
|
||||
_('Allow friends to nudge me and send me an email.'),
|
||||
$user->emailnotifynudge);
|
||||
$this->checkbox(
|
||||
'emailnotifynudge',
|
||||
// TRANS: Checkbox label in e-mail preferences form.
|
||||
_('Allow friends to nudge me and send me an email.'),
|
||||
$user->emailnotifynudge
|
||||
);
|
||||
$this->elementEnd('li');
|
||||
Event::handle('EndEmailFormData', array($this, $this->scoped));
|
||||
}
|
||||
$this->elementEnd('ul');
|
||||
// TRANS: Button label to save e-mail preferences.
|
||||
$this->submit('save', _m('BUTTON','Save'));
|
||||
$this->submit('save', _m('BUTTON', 'Save'));
|
||||
$this->elementEnd('fieldset');
|
||||
$this->elementEnd('fieldset');
|
||||
$this->elementEnd('form');
|
||||
|
@ -242,7 +253,7 @@ class EmailsettingsAction extends SettingsAction
|
|||
*
|
||||
* @return Confirm_address Email address confirmation for user, or null
|
||||
*/
|
||||
function getConfirmation()
|
||||
public function getConfirmation()
|
||||
{
|
||||
$confirm = new Confirm_address();
|
||||
|
||||
|
@ -260,15 +271,15 @@ class EmailsettingsAction extends SettingsAction
|
|||
{
|
||||
if ($this->arg('save')) {
|
||||
return $this->savePreferences();
|
||||
} else if ($this->arg('add')) {
|
||||
} elseif ($this->arg('add')) {
|
||||
return $this->addAddress();
|
||||
} else if ($this->arg('cancel')) {
|
||||
} elseif ($this->arg('cancel')) {
|
||||
return $this->cancelConfirmation();
|
||||
} else if ($this->arg('remove')) {
|
||||
} elseif ($this->arg('remove')) {
|
||||
return $this->removeAddress();
|
||||
} else if ($this->arg('removeincoming')) {
|
||||
} elseif ($this->arg('removeincoming')) {
|
||||
return $this->removeIncoming();
|
||||
} else if ($this->arg('newincoming')) {
|
||||
} elseif ($this->arg('newincoming')) {
|
||||
return $this->newIncoming();
|
||||
}
|
||||
|
||||
|
@ -281,7 +292,7 @@ class EmailsettingsAction extends SettingsAction
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
function savePreferences()
|
||||
public function savePreferences()
|
||||
{
|
||||
if (Event::handle('StartEmailSaveForm', array($this, $this->scoped))) {
|
||||
$emailnotifysub = $this->booleanintstring('emailnotifysub');
|
||||
|
@ -322,7 +333,7 @@ class EmailsettingsAction extends SettingsAction
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
function addAddress()
|
||||
public function addAddress()
|
||||
{
|
||||
$user = $this->scoped->getUser();
|
||||
|
||||
|
@ -344,16 +355,15 @@ class EmailsettingsAction extends SettingsAction
|
|||
if (!Validate::email($email, common_config('email', 'check_domain'))) {
|
||||
// TRANS: Message given saving e-mail address that not valid.
|
||||
throw new ClientException(_('Not a valid email address.'));
|
||||
} else if ($user->email == $email) {
|
||||
} elseif ($user->email === $email) {
|
||||
// TRANS: Message given saving e-mail address that is already set.
|
||||
throw new ClientException(_('That is already your email address.'));
|
||||
} else if ($this->emailExists($email)) {
|
||||
} elseif ($this->emailExists($email)) {
|
||||
// TRANS: Message given saving e-mail address that is already set for another user.
|
||||
throw new ClientException(_('That email address already belongs to another user.'));
|
||||
}
|
||||
|
||||
if (Event::handle('StartAddEmailAddress', array($user, $email))) {
|
||||
|
||||
$confirm = new Confirm_address();
|
||||
|
||||
$confirm->address = $email;
|
||||
|
@ -385,7 +395,7 @@ class EmailsettingsAction extends SettingsAction
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
function cancelConfirmation()
|
||||
public function cancelConfirmation()
|
||||
{
|
||||
$email = $this->trimmed('email');
|
||||
|
||||
|
@ -411,7 +421,7 @@ class EmailsettingsAction extends SettingsAction
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
function removeAddress()
|
||||
public function removeAddress()
|
||||
{
|
||||
$user = common_current_user();
|
||||
|
||||
|
@ -425,7 +435,7 @@ class EmailsettingsAction extends SettingsAction
|
|||
}
|
||||
|
||||
$original = clone($user);
|
||||
$user->email = null;
|
||||
$user->email = DB_DataObject_Cast::sql('NULL');
|
||||
// Throws exception on failure. Also performs it within a transaction.
|
||||
$user->updateWithKeys($original);
|
||||
|
||||
|
@ -438,7 +448,7 @@ class EmailsettingsAction extends SettingsAction
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
function removeIncoming()
|
||||
public function removeIncoming()
|
||||
{
|
||||
$user = common_current_user();
|
||||
|
||||
|
@ -448,7 +458,7 @@ class EmailsettingsAction extends SettingsAction
|
|||
}
|
||||
|
||||
$orig = clone($user);
|
||||
$user->incomingemail = null;
|
||||
$user->incomingemail = DB_DataObject_Cast::sql('NULL');
|
||||
$user->emailpost = 0;
|
||||
// Throws exception on failure. Also performs it within a transaction.
|
||||
$user->updateWithKeys($orig);
|
||||
|
@ -462,7 +472,7 @@ class EmailsettingsAction extends SettingsAction
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
function newIncoming()
|
||||
public function newIncoming()
|
||||
{
|
||||
$user = common_current_user();
|
||||
$orig = clone($user);
|
||||
|
@ -485,7 +495,7 @@ class EmailsettingsAction extends SettingsAction
|
|||
* @return boolean Whether the email already exists.
|
||||
*/
|
||||
|
||||
function emailExists($email)
|
||||
public function emailExists($email)
|
||||
{
|
||||
$user = common_current_user();
|
||||
|
||||
|
|
|
@ -1,46 +1,39 @@
|
|||
<?php
|
||||
// This file is part of GNU social - https://www.gnu.org/software/social
|
||||
//
|
||||
// GNU social 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.
|
||||
//
|
||||
// GNU social 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 GNU social. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* StatusNet, the distributed open-source microblogging tool
|
||||
* Settings for SMS.
|
||||
*
|
||||
* Settings for SMS
|
||||
*
|
||||
* 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 Settings
|
||||
* @package StatusNet
|
||||
* @category Setting
|
||||
* @package GNUsocial
|
||||
* @author Evan Prodromou <evan@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/
|
||||
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||
*/
|
||||
|
||||
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||
defined('GNUSOCIAL') || die();
|
||||
|
||||
/**
|
||||
* Settings for SMS
|
||||
*
|
||||
* @category Settings
|
||||
* @package StatusNet
|
||||
* @author Evan Prodromou <evan@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/
|
||||
* @copyright 2008-2009 StatusNet, Inc.
|
||||
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||
*
|
||||
* @see SettingsAction
|
||||
*/
|
||||
|
||||
class SmssettingsAction extends SettingsAction
|
||||
{
|
||||
protected function doPreparation()
|
||||
|
@ -56,7 +49,7 @@ class SmssettingsAction extends SettingsAction
|
|||
*
|
||||
* @return string Title of the page
|
||||
*/
|
||||
function title()
|
||||
public function title()
|
||||
{
|
||||
// TRANS: Title for SMS settings.
|
||||
return _('SMS settings');
|
||||
|
@ -67,7 +60,7 @@ class SmssettingsAction extends SettingsAction
|
|||
*
|
||||
* @return instructions for use
|
||||
*/
|
||||
function getInstructions()
|
||||
public function getInstructions()
|
||||
{
|
||||
// XXX: For consistency of parameters in messages, this should be a
|
||||
// regular parameters, replaced with sprintf().
|
||||
|
@ -76,7 +69,7 @@ class SmssettingsAction extends SettingsAction
|
|||
return _('You can receive SMS messages through email from %%site.name%%.');
|
||||
}
|
||||
|
||||
function showScripts()
|
||||
public function showScripts()
|
||||
{
|
||||
parent::showScripts();
|
||||
$this->autofocus('sms');
|
||||
|
@ -90,7 +83,7 @@ class SmssettingsAction extends SettingsAction
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
function showContent()
|
||||
public function showContent()
|
||||
{
|
||||
$user = $this->scoped->getUser();
|
||||
|
||||
|
@ -107,80 +100,105 @@ class SmssettingsAction extends SettingsAction
|
|||
|
||||
if ($user->sms) {
|
||||
$carrier = $user->getCarrier();
|
||||
$this->element('p', 'form_confirmed',
|
||||
$user->sms . ' (' . $carrier->name . ')');
|
||||
$this->element('p', 'form_guide',
|
||||
// TRANS: Form guide in SMS settings form.
|
||||
_('Current confirmed SMS-enabled phone number.'));
|
||||
$this->element(
|
||||
'p',
|
||||
'form_confirmed',
|
||||
$user->sms . ' (' . $carrier->name . ')'
|
||||
);
|
||||
$this->element(
|
||||
'p',
|
||||
'form_guide',
|
||||
// TRANS: Form guide in SMS settings form.
|
||||
_('Current confirmed SMS-enabled phone number.')
|
||||
);
|
||||
$this->hidden('sms', $user->sms);
|
||||
$this->hidden('carrier', $user->carrier);
|
||||
// TRANS: Button label to remove a confirmed SMS address.
|
||||
$this->submit('remove', _m('BUTTON','Remove'));
|
||||
$this->submit('remove', _m('BUTTON', 'Remove'));
|
||||
} else {
|
||||
try {
|
||||
$confirm = $this->getConfirmation();
|
||||
$carrier = Sms_carrier::getKV($confirm->address_extra);
|
||||
$this->element('p', 'form_unconfirmed',
|
||||
$confirm->address . ' (' . $carrier->name . ')');
|
||||
$this->element('p', 'form_guide',
|
||||
// TRANS: Form guide in IM settings form.
|
||||
_('Awaiting confirmation on this phone number.'));
|
||||
$this->element(
|
||||
'p',
|
||||
'form_unconfirmed',
|
||||
$confirm->address . ' (' . $carrier->name . ')'
|
||||
);
|
||||
$this->element(
|
||||
'p',
|
||||
'form_guide',
|
||||
// TRANS: Form guide in IM settings form.
|
||||
_('Awaiting confirmation on this phone number.')
|
||||
);
|
||||
$this->hidden('sms', $confirm->address);
|
||||
$this->hidden('carrier', $confirm->address_extra);
|
||||
// TRANS: Button label to cancel a SMS address confirmation procedure.
|
||||
$this->submit('cancel', _m('BUTTON','Cancel'));
|
||||
$this->submit('cancel', _m('BUTTON', 'Cancel'));
|
||||
|
||||
$this->elementStart('ul', 'form_data');
|
||||
$this->elementStart('li');
|
||||
// TRANS: Field label for SMS address input in SMS settings form.
|
||||
$this->input('code', _('Confirmation code'), null,
|
||||
// TRANS: Form field instructions in SMS settings form.
|
||||
_('Enter the code you received on your phone.'));
|
||||
$this->input(
|
||||
'code',
|
||||
_('Confirmation code'),
|
||||
null,
|
||||
// TRANS: Form field instructions in SMS settings form.
|
||||
_('Enter the code you received on your phone.')
|
||||
);
|
||||
$this->elementEnd('li');
|
||||
$this->elementEnd('ul');
|
||||
// TRANS: Button label to confirm SMS confirmation code in SMS settings.
|
||||
$this->submit('confirm', _m('BUTTON','Confirm'));
|
||||
$this->submit('confirm', _m('BUTTON', 'Confirm'));
|
||||
} catch (NoResultException $e) {
|
||||
$this->elementStart('ul', 'form_data');
|
||||
$this->elementStart('li');
|
||||
// TRANS: Field label for SMS phone number input in SMS settings form.
|
||||
$this->input('sms', _('SMS phone number'),
|
||||
($this->arg('sms')) ? $this->arg('sms') : null,
|
||||
// TRANS: SMS phone number input field instructions in SMS settings form.
|
||||
_('Phone number, no punctuation or spaces, '.
|
||||
'with area code.'));
|
||||
$this->input(
|
||||
'sms',
|
||||
_('SMS phone number'),
|
||||
($this->arg('sms') ?: null),
|
||||
// TRANS: SMS phone number input field instructions in SMS settings form.
|
||||
_('Phone number, no punctuation or spaces, ' .
|
||||
'with area code.')
|
||||
);
|
||||
$this->elementEnd('li');
|
||||
$this->elementEnd('ul');
|
||||
$this->carrierSelect();
|
||||
// TRANS: Button label for adding a SMS phone number in SMS settings form.
|
||||
$this->submit('add', _m('BUTTON','Add'));
|
||||
$this->submit('add', _m('BUTTON', 'Add'));
|
||||
}
|
||||
}
|
||||
$this->elementEnd('fieldset');
|
||||
|
||||
if ($user->sms) {
|
||||
$this->elementStart('fieldset', array('id' => 'settings_sms_incoming_email'));
|
||||
$this->elementStart('fieldset', ['id' => 'settings_sms_incoming_email']);
|
||||
// XXX: Confused! This is about SMS. Should this message be updated?
|
||||
// TRANS: Form legend for incoming SMS settings form.
|
||||
$this->element('legend', null, _('Incoming email'));
|
||||
|
||||
if ($user->incomingemail) {
|
||||
$this->element('p', 'form_unconfirmed', $user->incomingemail);
|
||||
$this->element('p', 'form_note',
|
||||
// XXX: Confused! This is about SMS. Should this message be updated?
|
||||
// TRANS: Form instructions for incoming SMS e-mail address form in SMS settings.
|
||||
_('Send email to this address to post new notices.'));
|
||||
$this->element(
|
||||
'p',
|
||||
'form_note',
|
||||
// XXX: Confused! This is about SMS. Should this message be updated?
|
||||
// TRANS: Form instructions for incoming SMS e-mail address form in SMS settings.
|
||||
_('Send email to this address to post new notices.')
|
||||
);
|
||||
// TRANS: Button label for removing a set sender SMS e-mail address to post notices from.
|
||||
$this->submit('removeincoming', _m('BUTTON','Remove'));
|
||||
$this->submit('removeincoming', _m('BUTTON', 'Remove'));
|
||||
}
|
||||
|
||||
$this->element('p', 'form_guide',
|
||||
// XXX: Confused! This is about SMS. Should this message be updated?
|
||||
// TRANS: Instructions for incoming SMS e-mail address input form.
|
||||
_('Make a new email address for posting to; '.
|
||||
'cancels the old one.'));
|
||||
$this->element(
|
||||
'p',
|
||||
'form_guide',
|
||||
// XXX: Confused! This is about SMS. Should this message be updated?
|
||||
// TRANS: Instructions for incoming SMS e-mail address input form.
|
||||
_('Make a new email address for posting to; ' .
|
||||
'cancels the old one.')
|
||||
);
|
||||
// TRANS: Button label for adding an SMS e-mail address to send notices from.
|
||||
$this->submit('newincoming', _m('BUTTON','New'));
|
||||
$this->submit('newincoming', _m('BUTTON', 'New'));
|
||||
$this->elementEnd('fieldset');
|
||||
}
|
||||
|
||||
|
@ -190,17 +208,19 @@ class SmssettingsAction extends SettingsAction
|
|||
|
||||
$this->elementStart('ul', 'form_data');
|
||||
$this->elementStart('li');
|
||||
$this->checkbox('smsnotify',
|
||||
// TRANS: Checkbox label in SMS preferences form.
|
||||
_('Send me notices through SMS; '.
|
||||
'I understand I may incur '.
|
||||
'exorbitant charges from my carrier.'),
|
||||
$user->smsnotify);
|
||||
$this->checkbox(
|
||||
'smsnotify',
|
||||
// TRANS: Checkbox label in SMS preferences form.
|
||||
_('Send me notices through SMS; ' .
|
||||
'I understand I may incur ' .
|
||||
'exorbitant charges from my carrier.'),
|
||||
$user->smsnotify
|
||||
);
|
||||
$this->elementEnd('li');
|
||||
$this->elementEnd('ul');
|
||||
|
||||
// TRANS: Button label to save SMS preferences.
|
||||
$this->submit('save', _m('BUTTON','Save'));
|
||||
$this->submit('save', _m('BUTTON', 'Save'));
|
||||
|
||||
$this->elementEnd('fieldset');
|
||||
$this->elementEnd('form');
|
||||
|
@ -213,7 +233,7 @@ class SmssettingsAction extends SettingsAction
|
|||
*
|
||||
* @todo very similar to EmailsettingsAction::getConfirmation(); refactor?
|
||||
*/
|
||||
function getConfirmation()
|
||||
public function getConfirmation()
|
||||
{
|
||||
$confirm = new Confirm_address();
|
||||
|
||||
|
@ -229,20 +249,19 @@ class SmssettingsAction extends SettingsAction
|
|||
|
||||
protected function doPost()
|
||||
{
|
||||
|
||||
if ($this->arg('save')) {
|
||||
return $this->savePreferences();
|
||||
} else if ($this->arg('add')) {
|
||||
} elseif ($this->arg('add')) {
|
||||
return $this->addAddress();
|
||||
} else if ($this->arg('cancel')) {
|
||||
} elseif ($this->arg('cancel')) {
|
||||
return $this->cancelConfirmation();
|
||||
} else if ($this->arg('remove')) {
|
||||
} elseif ($this->arg('remove')) {
|
||||
return $this->removeAddress();
|
||||
} else if ($this->arg('removeincoming')) {
|
||||
} elseif ($this->arg('removeincoming')) {
|
||||
return $this->removeIncoming();
|
||||
} else if ($this->arg('newincoming')) {
|
||||
} elseif ($this->arg('newincoming')) {
|
||||
return $this->newIncoming();
|
||||
} else if ($this->arg('confirm')) {
|
||||
} elseif ($this->arg('confirm')) {
|
||||
return $this->confirmCode();
|
||||
}
|
||||
// TRANS: Message given submitting a form with an unknown action in SMS settings.
|
||||
|
@ -256,7 +275,7 @@ class SmssettingsAction extends SettingsAction
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
function savePreferences()
|
||||
public function savePreferences()
|
||||
{
|
||||
$user = $this->scoped->getUser();
|
||||
|
||||
|
@ -288,7 +307,7 @@ class SmssettingsAction extends SettingsAction
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
function addAddress()
|
||||
public function addAddress()
|
||||
{
|
||||
$user = common_current_user();
|
||||
|
||||
|
@ -312,7 +331,7 @@ class SmssettingsAction extends SettingsAction
|
|||
if ($user->sms === $sms) {
|
||||
// TRANS: Message given saving SMS phone number that is already set.
|
||||
throw new AlreadyFulfilledException(_('That is already your phone number.'));
|
||||
} else if ($this->smsExists($sms)) {
|
||||
} elseif ($this->smsExists($sms)) {
|
||||
// TRANS: Message given saving SMS phone number that is already set for another user.
|
||||
throw new ClientException(_('That phone number already belongs to another user.'));
|
||||
}
|
||||
|
@ -335,9 +354,11 @@ class SmssettingsAction extends SettingsAction
|
|||
|
||||
$carrier = Sms_carrier::getKV($carrier_id);
|
||||
|
||||
mail_confirm_sms($confirm->code,
|
||||
$user->nickname,
|
||||
$carrier->toEmailAddress($sms));
|
||||
mail_confirm_sms(
|
||||
$confirm->code,
|
||||
$user->nickname,
|
||||
$carrier->toEmailAddress($sms)
|
||||
);
|
||||
|
||||
// TRANS: Message given saving valid SMS phone number that is to be confirmed.
|
||||
return _('A confirmation code was sent to the phone number you added. '.
|
||||
|
@ -352,7 +373,7 @@ class SmssettingsAction extends SettingsAction
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
function cancelConfirmation()
|
||||
public function cancelConfirmation()
|
||||
{
|
||||
$sms = $this->trimmed('sms');
|
||||
$carrier = $this->trimmed('carrier');
|
||||
|
@ -379,7 +400,7 @@ class SmssettingsAction extends SettingsAction
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
function removeAddress()
|
||||
public function removeAddress()
|
||||
{
|
||||
$user = $this->scoped->getUser();
|
||||
|
||||
|
@ -396,9 +417,9 @@ class SmssettingsAction extends SettingsAction
|
|||
|
||||
$original = clone($user);
|
||||
|
||||
$user->sms = null;
|
||||
$user->carrier = null;
|
||||
$user->smsemail = null;
|
||||
$user->sms = DB_DataObject_Cast::sql('NULL');
|
||||
$user->carrier = DB_DataObject_Cast::sql('NULL');
|
||||
$user->smsemail = DB_DataObject_Cast::sql('NULL');
|
||||
|
||||
// Throws exception on failure. Also performs it within a transaction.
|
||||
$user->updateWithKeys($original);
|
||||
|
@ -416,7 +437,7 @@ class SmssettingsAction extends SettingsAction
|
|||
*
|
||||
* @return boolean does the number exist
|
||||
*/
|
||||
function smsExists($sms)
|
||||
public function smsExists($sms)
|
||||
{
|
||||
$other = User::getKV('sms', $sms);
|
||||
|
||||
|
@ -432,7 +453,7 @@ class SmssettingsAction extends SettingsAction
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
function carrierSelect()
|
||||
public function carrierSelect()
|
||||
{
|
||||
$carrier = new Sms_carrier();
|
||||
|
||||
|
@ -444,22 +465,33 @@ class SmssettingsAction extends SettingsAction
|
|||
$this->element('label', array('for' => 'carrier'), _('Mobile carrier'));
|
||||
$this->elementStart('select', array('name' => 'carrier',
|
||||
'id' => 'carrier'));
|
||||
$this->element('option', array('value' => 0),
|
||||
// TRANS: Default option for mobile carrier dropdown menu in SMS settings.
|
||||
_('Select a carrier'));
|
||||
$this->element(
|
||||
'option',
|
||||
['value' => 0],
|
||||
// TRANS: Default option for mobile carrier dropdown menu in SMS settings.
|
||||
_('Select a carrier')
|
||||
);
|
||||
while ($carrier->fetch()) {
|
||||
$this->element('option', array('value' => $carrier->id),
|
||||
$carrier->name);
|
||||
$this->element(
|
||||
'option',
|
||||
['value' => $carrier->id],
|
||||
$carrier->name
|
||||
);
|
||||
}
|
||||
$this->elementEnd('select');
|
||||
$this->element('p', 'form_guide',
|
||||
// TRANS: Form instructions for mobile carrier dropdown menu in SMS settings.
|
||||
// TRANS: %s is an administrative contact's e-mail address.
|
||||
sprintf(_('Mobile carrier for your phone. '.
|
||||
'If you know a carrier that accepts ' .
|
||||
'SMS over email but isn\'t listed here, ' .
|
||||
'send email to let us know at %s.'),
|
||||
common_config('site', 'email')));
|
||||
$this->element(
|
||||
'p',
|
||||
'form_guide',
|
||||
// TRANS: Form instructions for mobile carrier dropdown menu in SMS settings.
|
||||
// TRANS: %s is an administrative contact's e-mail address.
|
||||
sprintf(
|
||||
_('Mobile carrier for your phone. ' .
|
||||
'If you know a carrier that accepts ' .
|
||||
'SMS over email but isn\'t listed here, ' .
|
||||
'send email to let us know at %s.'),
|
||||
common_config('site', 'email')
|
||||
)
|
||||
);
|
||||
$this->elementEnd('li');
|
||||
$this->elementEnd('ul');
|
||||
}
|
||||
|
@ -471,7 +503,7 @@ class SmssettingsAction extends SettingsAction
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
function confirmCode()
|
||||
public function confirmCode()
|
||||
{
|
||||
$code = $this->trimmed('code');
|
||||
|
||||
|
@ -488,7 +520,7 @@ class SmssettingsAction extends SettingsAction
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
function removeIncoming()
|
||||
public function removeIncoming()
|
||||
{
|
||||
$user = common_current_user();
|
||||
|
||||
|
@ -499,7 +531,7 @@ class SmssettingsAction extends SettingsAction
|
|||
|
||||
$orig = clone($user);
|
||||
|
||||
$user->incomingemail = null;
|
||||
$user->incomingemail = DB_DataObject_Cast::sql('NULL');
|
||||
|
||||
// Throws exception on failure. Also performs it within a transaction.
|
||||
$user->updateWithKeys($orig);
|
||||
|
@ -515,7 +547,7 @@ class SmssettingsAction extends SettingsAction
|
|||
*
|
||||
* @see Emailsettings::newIncoming
|
||||
*/
|
||||
function newIncoming()
|
||||
public function newIncoming()
|
||||
{
|
||||
$user = $this->scoped->getUser();
|
||||
|
||||
|
|
|
@ -1,35 +1,32 @@
|
|||
<?php
|
||||
// This file is part of GNU social - https://www.gnu.org/software/social
|
||||
//
|
||||
// GNU social 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.
|
||||
//
|
||||
// GNU social 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 GNU social. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* StatusNet, the distributed open-source microblogging tool
|
||||
*
|
||||
* Data class for Conversations
|
||||
*
|
||||
* 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
|
||||
* @package GNUsocial
|
||||
* @author Zach Copley <zach@status.net>
|
||||
* @author Mikael Nordfeldth <mmn@hethane.se>
|
||||
* @copyright 2010 StatusNet Inc.
|
||||
* @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org
|
||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
||||
* @link http://status.net/
|
||||
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||
*/
|
||||
|
||||
if (!defined('GNUSOCIAL')) { exit(1); }
|
||||
defined('GNUSOCIAL') || die();
|
||||
|
||||
class Conversation extends Managed_DataObject
|
||||
{
|
||||
|
@ -57,14 +54,14 @@ class Conversation extends Managed_DataObject
|
|||
);
|
||||
}
|
||||
|
||||
static public function beforeSchemaUpdate()
|
||||
public static function beforeSchemaUpdate()
|
||||
{
|
||||
$table = strtolower(get_called_class());
|
||||
$schema = Schema::get();
|
||||
$schemadef = $schema->getTableDef($table);
|
||||
|
||||
// 2016-01-06 We have to make sure there is no conversation with id==0 since it will screw up auto increment resequencing
|
||||
if ($schemadef['fields']['id']['auto_increment']) {
|
||||
if ($schemadef['fields']['id']['auto_increment'] ?? false) {
|
||||
// since we already have auto incrementing ('serial') we can continue
|
||||
return;
|
||||
}
|
||||
|
@ -91,7 +88,7 @@ class Conversation extends Managed_DataObject
|
|||
*
|
||||
* @return Conversation the new conversation DO
|
||||
*/
|
||||
static function create(ActivityContext $ctx=null, $created=null)
|
||||
public static function create(ActivityContext $ctx = null, $created = null)
|
||||
{
|
||||
// Be aware that the Notice does not have an id yet since it's not inserted!
|
||||
$conv = new Conversation();
|
||||
|
@ -100,11 +97,16 @@ class Conversation extends Managed_DataObject
|
|||
$conv->uri = $ctx->conversation;
|
||||
$conv->url = $ctx->conversation_url;
|
||||
} else {
|
||||
$conv->uri = sprintf('%s%s=%s:%s=%s',
|
||||
TagURI::mint(),
|
||||
'objectType', 'thread',
|
||||
'nonce', common_random_hexstr(8));
|
||||
$conv->url = null; // locally generated Conversation objects don't get static URLs stored
|
||||
$conv->uri = sprintf(
|
||||
'%s%s=%s:%s=%s',
|
||||
TagURI::mint(),
|
||||
'objectType',
|
||||
'thread',
|
||||
'nonce',
|
||||
common_random_hexstr(8)
|
||||
);
|
||||
// locally generated Conversation objects don't get static URLs stored
|
||||
$conv->url = DB_DataObject_Cast::sql('NULL');
|
||||
}
|
||||
// This insert throws exceptions on failure
|
||||
$conv->insert();
|
||||
|
@ -112,7 +114,7 @@ class Conversation extends Managed_DataObject
|
|||
return $conv;
|
||||
}
|
||||
|
||||
static function noticeCount($id)
|
||||
public static function noticeCount($id)
|
||||
{
|
||||
$keypart = sprintf('conversation:notice_count:%d', $id);
|
||||
|
||||
|
@ -132,7 +134,7 @@ class Conversation extends Managed_DataObject
|
|||
return $cnt;
|
||||
}
|
||||
|
||||
static public function getUrlFromNotice(Notice $notice, $anchor=true)
|
||||
public static function getUrlFromNotice(Notice $notice, $anchor = true)
|
||||
{
|
||||
$conv = Conversation::getByID($notice->conversation);
|
||||
return $conv->getUrl($anchor ? $notice->getID() : null);
|
||||
|
|
|
@ -1,29 +1,32 @@
|
|||
<?php
|
||||
/*
|
||||
* StatusNet - the distributed open-source microblogging tool
|
||||
* Copyright (C) 2009-2010, StatusNet, 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('GNUSOCIAL')) { exit(1); }
|
||||
// This file is part of GNU social - https://www.gnu.org/software/social
|
||||
//
|
||||
// GNU social 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.
|
||||
//
|
||||
// GNU social 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 GNU social. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* @package OStatusPlugin
|
||||
* @maintainer Brion Vibber <brion@status.net>
|
||||
* FeedSub handles low-level WebSub (PubSubHubbub/PuSH) subscriptions.
|
||||
* Higher-level behavior building OStatus stuff on top is handled
|
||||
* under Ostatus_profile.
|
||||
*
|
||||
* @package OStatusPlugin
|
||||
* @author Brion Vibber <brion@status.net>
|
||||
* @copyright 2009-2010 StatusNet, Inc.
|
||||
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||
*/
|
||||
|
||||
defined('GNUSOCIAL') || die();
|
||||
|
||||
/*
|
||||
WebSub (previously PubSubHubbub/PuSH) subscription flow:
|
||||
|
||||
|
@ -37,14 +40,8 @@ WebSub (previously PubSubHubbub/PuSH) subscription flow:
|
|||
|
||||
main/push/callback
|
||||
hub sends us updates via POST
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* FeedSub handles low-level WebSub (PubSubHubbub/PuSH) subscriptions.
|
||||
* Higher-level behavior building OStatus stuff on top is handled
|
||||
* under Ostatus_profile.
|
||||
*/
|
||||
class FeedSub extends Managed_DataObject
|
||||
{
|
||||
public $__table = 'feedsub';
|
||||
|
@ -96,7 +93,7 @@ class FeedSub extends Managed_DataObject
|
|||
return $this->uri;
|
||||
}
|
||||
|
||||
function getLeaseRemaining()
|
||||
public function getLeaseRemaining()
|
||||
{
|
||||
if (empty($this->sub_end)) {
|
||||
return null;
|
||||
|
@ -118,8 +115,8 @@ class FeedSub extends Managed_DataObject
|
|||
if (empty($this->huburi)
|
||||
&& (!common_config('feedsub', 'fallback_hub')
|
||||
|| $this->sub_state === 'nohub')) {
|
||||
// Here we have no huburi set. Also, either there is no
|
||||
// fallback hub configured or sub_state is "nohub".
|
||||
// Here we have no huburi set. Also, either there is no
|
||||
// fallback hub configured or sub_state is "nohub".
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -180,7 +177,6 @@ class FeedSub extends Managed_DataObject
|
|||
try {
|
||||
// discover the hub uri
|
||||
$feedsub->ensureHub();
|
||||
|
||||
} catch (FeedSubNoHubException $e) {
|
||||
// Only throw this exception if we can't handle huburi-less feeds
|
||||
// (i.e. we have a fallback hub or we can do feed polling (nohub)
|
||||
|
@ -263,7 +259,7 @@ class FeedSub extends Managed_DataObject
|
|||
*/
|
||||
public function subscribe($rediscovered=false)
|
||||
{
|
||||
if ($this->sub_state && $this->sub_state != 'inactive') {
|
||||
if ($this->sub_state !== 'inactive') {
|
||||
common_log(LOG_WARNING, sprintf('Attempting to (re)start WebSub subscription to %s in unexpected state %s', $this->getUri(), $this->sub_state));
|
||||
}
|
||||
|
||||
|
@ -276,7 +272,7 @@ class FeedSub extends Managed_DataObject
|
|||
if (common_config('feedsub', 'fallback_hub')) {
|
||||
// No native hub on this feed?
|
||||
// Use our fallback hub, which handles polling on our behalf.
|
||||
} else if (common_config('feedsub', 'nohub')) {
|
||||
} elseif (common_config('feedsub', 'nohub')) {
|
||||
// For this to actually work, we'll need some polling mechanism.
|
||||
// The FeedPoller plugin should take care of it.
|
||||
return;
|
||||
|
@ -298,7 +294,8 @@ class FeedSub extends Managed_DataObject
|
|||
*
|
||||
* @throws ServerException if feed state is not valid
|
||||
*/
|
||||
public function unsubscribe() {
|
||||
public function unsubscribe()
|
||||
{
|
||||
if ($this->sub_state != 'active') {
|
||||
common_log(LOG_WARNING, sprintf('Attempting to (re)end WebSub subscription to %s in unexpected state %s', $this->getUri(), $this->sub_state));
|
||||
}
|
||||
|
@ -344,7 +341,7 @@ class FeedSub extends Managed_DataObject
|
|||
*/
|
||||
public function garbageCollect()
|
||||
{
|
||||
if ($this->sub_state == '' || $this->sub_state == 'inactive') {
|
||||
if ($this->sub_state === 'inactive') {
|
||||
// No active WebSub subscription, we can just leave it be.
|
||||
return true;
|
||||
}
|
||||
|
@ -366,12 +363,12 @@ class FeedSub extends Managed_DataObject
|
|||
return true;
|
||||
}
|
||||
|
||||
static public function renewalCheck()
|
||||
public static function renewalCheck()
|
||||
{
|
||||
$fs = new FeedSub();
|
||||
// the "" empty string check is because we historically haven't saved unsubscribed feeds as NULL
|
||||
$fs->whereAdd('sub_end IS NOT NULL AND sub_end!="" AND sub_end < NOW() + INTERVAL 1 day');
|
||||
if (!$fs->find()) { // find can be both false and 0, depending on why nothing was found
|
||||
$fs->whereAdd('sub_end IS NOT NULL AND sub_end < (CURRENT_TIMESTAMP + INTERVAL 1 DAY)');
|
||||
// find can be both false and 0, depending on why nothing was found
|
||||
if (!$fs->find()) {
|
||||
throw new NoResultException($fs);
|
||||
}
|
||||
return $fs;
|
||||
|
@ -437,10 +434,10 @@ class FeedSub extends Managed_DataObject
|
|||
if ($status == 202 || $status == 204) {
|
||||
common_log(LOG_INFO, __METHOD__ . ': sub req ok, awaiting verification callback');
|
||||
return;
|
||||
} else if ($status >= 200 && $status < 300) {
|
||||
} elseif ($status >= 200 && $status < 300) {
|
||||
common_log(LOG_ERR, __METHOD__ . ": sub req returned unexpected HTTP $status: " . $response->getBody());
|
||||
$msg = sprintf(_m("Unexpected HTTP status: %d"), $status);
|
||||
} else if ($status == 422 && !$rediscovered) {
|
||||
} elseif ($status == 422 && !$rediscovered) {
|
||||
// Error code regarding something wrong in the data (it seems
|
||||
// that we're talking to a WebSub hub at least, so let's check
|
||||
// our own data to be sure we're not mistaken somehow, which
|
||||
|
@ -482,7 +479,8 @@ class FeedSub extends Managed_DataObject
|
|||
if ($lease_seconds > 0) {
|
||||
$this->sub_end = common_sql_date(time() + $lease_seconds);
|
||||
} else {
|
||||
$this->sub_end = null; // Backwards compatibility to StatusNet (PuSH <0.4 supported permanent subs)
|
||||
// Backwards compatibility to StatusNet (PuSH <0.4 supported permanent subs)
|
||||
$this->sub_end = DB_DataObject_Cast::sql('NULL');
|
||||
}
|
||||
$this->modified = common_sql_now();
|
||||
|
||||
|
@ -498,11 +496,10 @@ class FeedSub extends Managed_DataObject
|
|||
{
|
||||
$original = clone($this);
|
||||
|
||||
// @fixme these should all be null, but DB_DataObject doesn't save null values...?????
|
||||
$this->secret = '';
|
||||
$this->sub_state = '';
|
||||
$this->sub_start = '';
|
||||
$this->sub_end = '';
|
||||
$this->secret = DB_DataObject_Cast::sql('NULL');
|
||||
$this->sub_state = 'inactive';
|
||||
$this->sub_start = DB_DataObject_Cast::sql('NULL');
|
||||
$this->sub_end = DB_DataObject_Cast::sql('NULL');
|
||||
$this->modified = common_sql_now();
|
||||
|
||||
return $this->update($original);
|
||||
|
@ -544,7 +541,6 @@ class FeedSub extends Managed_DataObject
|
|||
}
|
||||
|
||||
$this->receiveFeed($post);
|
||||
|
||||
} catch (FeedSubBadPushSignatureException $e) {
|
||||
// We got a signature, so something could be wrong. Let's check to see if
|
||||
// maybe upstream has switched to another hub. Let's fetch feed and then
|
||||
|
@ -628,7 +624,6 @@ class FeedSub extends Managed_DataObject
|
|||
throw new FeedSubBadPushSignatureException('Incoming WebSub push signature did not match expected HMAC hash.');
|
||||
}
|
||||
return true;
|
||||
|
||||
} else {
|
||||
common_log(LOG_ERR, sprintf(__METHOD__.': ignoring WebSub push with bogus HMAC==', _ve($hmac)));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user