[DATABASE] Introduce a bool type in schema

PostgreSQL has a clear distinction between integers and booleans, so it makes
sense to draw a clear line.
This commit is contained in:
Alexei Sorokin 2019-09-11 11:25:39 +03:00 committed by Diogo Peralta Cordeiro
parent 9d87c37ac1
commit 3f17a0efea
39 changed files with 1324 additions and 1280 deletions

View File

@ -295,11 +295,11 @@ class EmailsettingsAction extends SettingsAction
public function savePreferences()
{
if (Event::handle('StartEmailSaveForm', array($this, $this->scoped))) {
$emailnotifysub = $this->booleanintstring('emailnotifysub');
$emailnotifymsg = $this->booleanintstring('emailnotifymsg');
$emailnotifynudge = $this->booleanintstring('emailnotifynudge');
$emailnotifyattn = $this->booleanintstring('emailnotifyattn');
$emailpost = $this->booleanintstring('emailpost');
$emailnotifysub = $this->boolean('emailnotifysub');
$emailnotifymsg = $this->boolean('emailnotifymsg');
$emailnotifynudge = $this->boolean('emailnotifynudge');
$emailnotifyattn = $this->boolean('emailnotifyattn');
$emailpost = $this->boolean('emailpost');
$user = $this->scoped->getUser();
$user->query('BEGIN');
@ -459,7 +459,7 @@ class EmailsettingsAction extends SettingsAction
$orig = clone($user);
$user->incomingemail = DB_DataObject_Cast::sql('NULL');
$user->emailpost = 0;
$user->emailpost = false;
// Throws exception on failure. Also performs it within a transaction.
$user->updateWithKeys($orig);
@ -477,7 +477,7 @@ class EmailsettingsAction extends SettingsAction
$user = common_current_user();
$orig = clone($user);
$user->incomingemail = mail_new_incoming_address();
$user->emailpost = 1;
$user->emailpost = true;
// Throws exception on failure. Also performs it within a transaction.
$user->updateWithKeys($orig);

View File

@ -1,50 +1,41 @@
<?php
/**
* Make another user an admin of a group
*
* PHP version 5
*
* @category Action
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2008, 2009, 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('STATUSNET') && !defined('LACONICA')) {
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/>.
/**
* Make another user an admin of a group
*
* @category Action
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
* @category Action
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2008, 2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
defined('GNUSOCIAL') || die();
/**
* Make another user an admin of a group
*
* @copyright 2008, 2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class MakeadminAction extends RedirectingAction
{
var $profile = null;
var $group = null;
public $profile = null;
public $group = null;
/**
* Take arguments for running
@ -54,7 +45,7 @@ class MakeadminAction extends RedirectingAction
* @return boolean success flag
*/
function prepare(array $args = array())
public function prepare(array $args = [])
{
parent::prepare($args);
if (!common_logged_in()) {
@ -95,10 +86,14 @@ class MakeadminAction extends RedirectingAction
if ($this->profile->isAdmin($this->group)) {
// TRANS: Client error displayed when trying to make another user admin on the Make Admin page who already is admin.
// TRANS: %1$s is the user that is already admin, %2$s is the group user is already admin for.
$this->clientError(sprintf(_('%1$s is already an admin for group "%2$s".'),
$this->profile->getBestName(),
$this->group->getBestName()),
401);
$this->clientError(
sprintf(
_('%1$s is already an admin for group "%2$s".'),
$this->profile->getBestName(),
$this->group->getBestName()
),
401
);
}
return true;
}
@ -111,7 +106,7 @@ class MakeadminAction extends RedirectingAction
* @return void
*/
function handle()
public function handle()
{
parent::handle();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
@ -125,7 +120,7 @@ class MakeadminAction extends RedirectingAction
* @return void
*/
function makeAdmin()
public function makeAdmin()
{
$member = Group_member::pkeyGet(array('group_id' => $this->group->id,
'profile_id' => $this->profile->id));
@ -134,14 +129,16 @@ class MakeadminAction extends RedirectingAction
// TRANS: Server error displayed when trying to make another user admin on the Make Admin page fails
// TRANS: because the group membership record could not be gotten.
// TRANS: %1$s is the to be admin user, %2$s is the group user should be admin for.
$this->serverError(_('Can\'t get membership record for %1$s in group %2$s.'),
$this->profile->getBestName(),
$this->group->getBestName());
$this->serverError(
_('Can\'t get membership record for %1$s in group %2$s.'),
$this->profile->getBestName(),
$this->group->getBestName()
);
}
$orig = clone($member);
$member->is_admin = 1;
$member->is_admin = true;
$result = $member->update($orig);
@ -150,9 +147,11 @@ class MakeadminAction extends RedirectingAction
// TRANS: Server error displayed when trying to make another user admin on the Make Admin page fails
// TRANS: because the group adminship record coud not be saved properly.
// TRANS: %1$s is the to be admin user, %2$s is the group user is already admin for.
$this->serverError(_('Can\'t make %1$s an admin for group %2$s.'),
$this->profile->getBestName(),
$this->group->getBestName());
$this->serverError(
_('Can\'t make %1$s an admin for group %2$s.'),
$this->profile->getBestName(),
$this->group->getBestName()
);
}
$this->returnToPrevious();
@ -161,13 +160,14 @@ class MakeadminAction extends RedirectingAction
/**
* If we reached this form without returnto arguments, default to
* the top of the group's member list.
*
*
* @return string URL
*/
function defaultReturnTo()
public function defaultReturnTo()
{
return common_local_url('groupmembers',
array('nickname' => $this->group->nickname));
return common_local_url(
'groupmembers',
['nickname' => $this->group->nickname]
);
}
}

View File

@ -1,46 +1,38 @@
<?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
*
* Change profile settings
*
* 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>
* @author Sarven Capadisli <csarven@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();
/**
* Change profile settings
*
* @category Settings
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @author Zach Copley <zach@status.net>
* @author Sarven Capadisli <csarven@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
*/
class ProfilesettingsAction extends SettingsAction
{
@ -49,7 +41,7 @@ class ProfilesettingsAction extends SettingsAction
*
* @return string Title of the page
*/
function title()
public function title()
{
// TRANS: Page title for profile settings.
return _('Profile settings');
@ -60,14 +52,14 @@ class ProfilesettingsAction extends SettingsAction
*
* @return instructions for use
*/
function getInstructions()
public function getInstructions()
{
// TRANS: Usage instructions for profile settings.
return _('You can update your personal profile info here '.
'so people know more about you.');
}
function showScripts()
public function showScripts()
{
parent::showScripts();
$this->autofocus('fullname');
@ -80,7 +72,7 @@ class ProfilesettingsAction extends SettingsAction
*
* @return void
*/
function showContent()
public function showContent()
{
$user = $this->scoped->getUser();
@ -98,29 +90,40 @@ class ProfilesettingsAction extends SettingsAction
if (Event::handle('StartProfileFormData', array($this))) {
$this->elementStart('li');
// TRANS: Field label in form for profile settings.
$this->input('nickname', _('Nickname'),
$this->trimmed('nickname') ?: $this->scoped->getNickname(),
// TRANS: Tooltip for field label in form for profile settings.
_('1-64 lowercase letters or numbers, no punctuation or spaces.'),
null, false, // "name" (will be set to id), then "required"
!common_config('profile', 'changenick')
? array('disabled' => 'disabled', 'placeholder' => null)
: array('placeholder' => null));
$this->input(
'nickname',
_('Nickname'),
$this->trimmed('nickname') ?: $this->scoped->getNickname(),
// TRANS: Tooltip for field label in form for profile settings.
_('1-64 lowercase letters or numbers, no punctuation or spaces.'),
null,
false, // "name" (will be set to id), then "required"
(common_config('profile', 'changenick')
? ['placeholder' => null]
: ['disabled' => 'disabled', 'placeholder' => null])
);
$this->elementEnd('li');
$this->elementStart('li');
// TRANS: Field label in form for profile settings.
$this->input('fullname', _('Full name'),
$this->trimmed('fullname') ?: $this->scoped->getFullname(),
// TRANS: Instructions for full name text field on profile settings
_('A full name is required, if empty it will be set to your nickname.'),
null, true);
$this->input(
'fullname',
_('Full name'),
$this->trimmed('fullname') ?: $this->scoped->getFullname(),
// TRANS: Instructions for full name text field on profile settings
_('A full name is required, if empty it will be set to your nickname.'),
null,
true
);
$this->elementEnd('li');
$this->elementStart('li');
// TRANS: Field label in form for profile settings.
$this->input('homepage', _('Homepage'),
$this->trimmed('homepage') ?: $this->scoped->getHomepage(),
// TRANS: Tooltip for field label in form for profile settings.
_('URL of your homepage, blog, or profile on another site.'));
$this->input(
'homepage',
_('Homepage'),
$this->trimmed('homepage') ?: $this->scoped->getHomepage(),
// TRANS: Tooltip for field label in form for profile settings.
_('URL of your homepage, blog, or profile on another site.')
);
$this->elementEnd('li');
$this->elementStart('li');
$maxBio = Profile::maxBio();
@ -128,97 +131,129 @@ class ProfilesettingsAction extends SettingsAction
// TRANS: Tooltip for field label in form for profile settings. Plural
// TRANS: is decided by the number of characters available for the
// TRANS: biography (%d).
$bioInstr = sprintf(_m('Describe yourself and your interests in %d character.',
'Describe yourself and your interests in %d characters.',
$maxBio),
$maxBio);
$bioInstr = sprintf(
_m('Describe yourself and your interests in %d character.',
'Describe yourself and your interests in %d characters.',
$maxBio),
$maxBio
);
} else {
// TRANS: Tooltip for field label in form for profile settings.
$bioInstr = _('Describe yourself and your interests.');
}
// TRANS: Text area label in form for profile settings where users can provide
// TRANS: their biography.
$this->textarea('bio', _('Bio'),
$this->trimmed('bio') ?: $this->scoped->getDescription(),
$bioInstr);
$this->textarea(
'bio',
_('Bio'),
($this->trimmed('bio') ?: $this->scoped->getDescription()),
$bioInstr
);
$this->elementEnd('li');
$this->elementStart('li');
// TRANS: Field label in form for profile settings.
$this->input('location', _('Location'),
$this->trimmed('location') ?: $this->scoped->location,
// TRANS: Tooltip for field label in form for profile settings.
_('Where you are, like "City, State (or Region), Country".'));
$this->input(
'location',
_('Location'),
($this->trimmed('location') ?: $this->scoped->location),
// TRANS: Tooltip for field label in form for profile settings.
_('Where you are, like "City, State (or Region), Country".')
);
$this->elementEnd('li');
if (common_config('location', 'share') == 'user') {
$this->elementStart('li');
// TRANS: Checkbox label in form for profile settings.
$this->checkbox('sharelocation', _('Share my current location when posting notices'),
($this->arg('sharelocation')) ?
$this->boolean('sharelocation') : $this->scoped->shareLocation());
$this->checkbox(
'sharelocation',
_('Share my current location when posting notices'),
($this->arg('sharelocation') ?
$this->boolean('sharelocation') : $this->scoped->shareLocation())
);
$this->elementEnd('li');
}
Event::handle('EndProfileFormData', array($this));
$this->elementStart('li');
// TRANS: Field label in form for profile settings.
$this->input('tags', _('Tags'),
$this->trimmed('tags') ?: implode(' ', Profile_tag::getSelfTagsArray($this->scoped)),
// TRANS: Tooltip for field label in form for profile settings.
_('Tags for yourself (letters, numbers, -, ., and _), comma- or space- separated.'));
$this->input(
'tags',
_('Tags'),
($this->trimmed('tags') ?: implode(' ', Profile_tag::getSelfTagsArray($this->scoped))),
// TRANS: Tooltip for field label in form for profile settings.
_('Tags for yourself (letters, numbers, -, ., and _), comma- or space- separated.')
);
$this->elementEnd('li');
$this->elementStart('li');
$language = common_language();
// TRANS: Dropdownlist label in form for profile settings.
$this->dropdown('language', _('Language'),
// TRANS: Tooltip for dropdown list label in form for profile settings.
get_nice_language_list(), _('Preferred language.'),
false, $language);
$this->dropdown(
'language',
_('Language'),
// TRANS: Tooltip for dropdown list label in form for profile settings.
get_nice_language_list(),
_('Preferred language.'),
false,
$language
);
$this->elementEnd('li');
$timezone = common_timezone();
$timezones = array();
foreach(DateTimeZone::listIdentifiers() as $k => $v) {
foreach (DateTimeZone::listIdentifiers() as $k => $v) {
$timezones[$v] = $v;
}
$this->elementStart('li');
// TRANS: Dropdownlist label in form for profile settings.
$this->dropdown('timezone', _('Timezone'),
// TRANS: Tooltip for dropdown list label in form for profile settings.
$timezones, _('What timezone are you normally in?'),
true, $timezone);
$this->dropdown(
'timezone',
_('Timezone'),
// TRANS: Tooltip for dropdown list label in form for profile settings.
$timezones,
_('What timezone are you normally in?'),
true,
$timezone
);
$this->elementEnd('li');
$this->elementStart('li');
$this->checkbox('autosubscribe',
// TRANS: Checkbox label in form for profile settings.
_('Automatically subscribe to whoever '.
'subscribes to me (best for non-humans)'),
($this->arg('autosubscribe')) ?
$this->boolean('autosubscribe') : $user->autosubscribe);
$this->checkbox(
'autosubscribe',
// TRANS: Checkbox label in form for profile settings.
_('Automatically subscribe to whoever '.
'subscribes to me (best for non-humans)'),
($this->arg('autosubscribe') ?
$this->boolean('autosubscribe') : $user->autosubscribe)
);
$this->elementEnd('li');
$this->elementStart('li');
$this->dropdown('subscribe_policy',
// TRANS: Dropdown field label on profile settings, for what policies to apply when someone else tries to subscribe to your updates.
_('Subscription policy'),
// TRANS: Dropdown field option for following policy.
array(User::SUBSCRIBE_POLICY_OPEN => _('Let anyone follow me'),
// TRANS: Dropdown field option for following policy.
User::SUBSCRIBE_POLICY_MODERATE => _('Ask me first')),
// TRANS: Dropdown field title on group edit form.
_('Whether other users need your permission to follow your updates.'),
false,
(empty($user->subscribe_policy)) ? User::SUBSCRIBE_POLICY_OPEN : $user->subscribe_policy);
$this->dropdown(
'subscribe_policy',
// TRANS: Dropdown field label on profile settings, for what policies to apply when someone else tries to subscribe to your updates.
_('Subscription policy'),
[
// TRANS: Dropdown field option for following policy.
User::SUBSCRIBE_POLICY_OPEN => _('Let anyone follow me'),
// TRANS: Dropdown field option for following policy.
User::SUBSCRIBE_POLICY_MODERATE => _('Ask me first'),
],
// TRANS: Dropdown field title on group edit form.
_('Whether other users need your permission to follow your updates.'),
false,
(empty($user->subscribe_policy) ? User::SUBSCRIBE_POLICY_OPEN : $user->subscribe_policy)
);
$this->elementEnd('li');
}
if (common_config('profile', 'allowprivate') || $user->private_stream) {
$this->elementStart('li');
$this->checkbox('private_stream',
// TRANS: Checkbox label in profile settings.
_('Make updates visible only to my followers'),
($this->arg('private_stream')) ?
$this->boolean('private_stream') : $user->private_stream);
$this->checkbox(
'private_stream',
// TRANS: Checkbox label in profile settings.
_('Make updates visible only to my followers'),
($this->arg('private_stream') ?
$this->boolean('private_stream') : $user->private_stream)
);
$this->elementEnd('li');
}
$this->elementEnd('ul');
// TRANS: Button to save input in profile settings.
$this->submit('save', _m('BUTTON','Save'));
$this->submit('save', _m('BUTTON', 'Save'));
$this->elementEnd('fieldset');
$this->elementEnd('form');
@ -255,7 +290,7 @@ class ProfilesettingsAction extends SettingsAction
$homepage = $this->trimmed('homepage');
$bio = $this->trimmed('bio');
$location = $this->trimmed('location');
$autosubscribe = $this->booleanintstring('autosubscribe');
$autosubscribe = $this->boolean('autosubscribe');
$subscribe_policy = $this->trimmed('subscribe_policy');
$language = $this->trimmed('language');
$timezone = $this->trimmed('timezone');
@ -266,24 +301,26 @@ class ProfilesettingsAction extends SettingsAction
!common_valid_http_url($homepage)) {
// TRANS: Validation error in form for profile settings.
throw new ClientException(_('Homepage is not a valid URL.'));
} else if (!is_null($fullname) && mb_strlen($fullname) > 191) {
} elseif (!is_null($fullname) && mb_strlen($fullname) > 191) {
// TRANS: Validation error in form for profile settings.
throw new ClientException(_('Full name is too long (maximum 191 characters).'));
} else if (Profile::bioTooLong($bio)) {
} elseif (Profile::bioTooLong($bio)) {
// TRANS: Validation error in form for profile settings.
// TRANS: Plural form is used based on the maximum number of allowed
// TRANS: characters for the biography (%d).
throw new ClientException(sprintf(_m('Bio is too long (maximum %d character).',
'Bio is too long (maximum %d characters).',
Profile::maxBio()),
Profile::maxBio()));
} else if (!is_null($location) && mb_strlen($location) > 191) {
throw new ClientException(sprintf(
_m('Bio is too long (maximum %d character).',
'Bio is too long (maximum %d characters).',
Profile::maxBio()),
Profile::maxBio()
));
} elseif (!is_null($location) && mb_strlen($location) > 191) {
// TRANS: Validation error in form for profile settings.
throw new ClientException(_('Location is too long (maximum 191 characters).'));
} else if (is_null($timezone) || !in_array($timezone, DateTimeZone::listIdentifiers())) {
} elseif (is_null($timezone) || !in_array($timezone, DateTimeZone::listIdentifiers())) {
// TRANS: Validation error in form for profile settings.
throw new ClientException(_('Timezone not selected.'));
} else if (!is_null($language) && strlen($language) > 50) {
} elseif (!is_null($language) && strlen($language) > 50) {
// TRANS: Validation error in form for profile settings.
throw new ClientException(_('Language is too long (maximum 50 characters).'));
}
@ -291,7 +328,6 @@ class ProfilesettingsAction extends SettingsAction
$tags = array();
$tag_priv = array();
if (is_string($tagstring) && strlen($tagstring) > 0) {
$tags = preg_split('/[\s,]+/', $tagstring);
foreach ($tags as &$tag) {
@ -314,21 +350,19 @@ class ProfilesettingsAction extends SettingsAction
// Only allow setting private_stream if site policy allows it
// (or user already _has_ a private stream, then you can unset it)
if (common_config('profile', 'allowprivate') || $user->private_stream) {
$private_stream = $this->booleanintstring('private_stream');
$private_stream = $this->boolean('private_stream');
} else {
// if not allowed, we set to the existing value
$private_stream = $user->private_stream;
$private_stream = (bool) $user->private_stream;
}
// $user->nickname is updated through Profile->update();
// XXX: XOR
if (($user->autosubscribe ^ $autosubscribe)
|| ($user->private_stream ^ $private_stream)
if ((bool) $user->autosubscribe != $autosubscribe
|| (bool) $user->private_stream != $private_stream
|| $user->timezone != $timezone
|| $user->language != $language
|| $user->subscribe_policy != $subscribe_policy) {
$original = clone($user);
$user->autosubscribe = $autosubscribe;
@ -378,7 +412,6 @@ class ProfilesettingsAction extends SettingsAction
}
if (common_config('location', 'share') == 'user') {
$exists = false;
$prefs = User_location_prefs::getKV('user_id', $this->scoped->getID());
@ -393,7 +426,7 @@ class ProfilesettingsAction extends SettingsAction
$orig = clone($prefs);
}
$prefs->share_location = $this->booleanintstring('sharelocation');
$prefs->share_location = $this->boolean('sharelocation');
if ($exists) {
$result = $prefs->update($orig);
@ -429,11 +462,11 @@ class ProfilesettingsAction extends SettingsAction
// TRANS: Confirmation shown when user profile settings are saved.
return _('Settings saved.');
}
}
function showAside() {
public function showAside()
{
$this->elementStart('div', array('id' => 'aside_primary',
'class' => 'aside'));
@ -443,26 +476,32 @@ class ProfilesettingsAction extends SettingsAction
if (Event::handle('StartProfileSettingsActions', array($this))) {
if ($this->scoped->hasRight(Right::BACKUPACCOUNT)) {
$this->elementStart('li');
$this->element('a',
array('href' => common_local_url('backupaccount')),
// TRANS: Option in profile settings to create a backup of the account of the currently logged in user.
_('Backup account'));
$this->element(
'a',
['href' => common_local_url('backupaccount')],
// TRANS: Option in profile settings to create a backup of the account of the currently logged in user.
_('Backup account')
);
$this->elementEnd('li');
}
if ($this->scoped->hasRight(Right::DELETEACCOUNT)) {
$this->elementStart('li');
$this->element('a',
array('href' => common_local_url('deleteaccount')),
// TRANS: Option in profile settings to delete the account of the currently logged in user.
_('Delete account'));
$this->element(
'a',
['href' => common_local_url('deleteaccount')],
// TRANS: Option in profile settings to delete the account of the currently logged in user.
_('Delete account')
);
$this->elementEnd('li');
}
if ($this->scoped->hasRight(Right::RESTOREACCOUNT)) {
$this->elementStart('li');
$this->element('a',
array('href' => common_local_url('restoreaccount')),
// TRANS: Option in profile settings to restore the account of the currently logged in user from a backup.
_('Restore account'));
$this->element(
'a',
['href' => common_local_url('restoreaccount')],
// TRANS: Option in profile settings to restore the account of the currently logged in user from a backup.
_('Restore account')
);
$this->elementEnd('li');
}
Event::handle('EndProfileSettingsActions', array($this));

View File

@ -1,6 +1,20 @@
<?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/>.
if (!defined('GNUSOCIAL')) { exit(1); }
defined('GNUSOCIAL') || die();
/**
* Table Definition for avatar
@ -10,20 +24,20 @@ class Avatar extends Managed_DataObject
{
public $__table = 'avatar'; // table name
public $profile_id; // int(4) primary_key not_null
public $original; // tinyint(1)
public $original; // bool default_false
public $width; // int(4) primary_key not_null
public $height; // int(4) primary_key not_null
public $mediatype; // varchar(32) not_null
public $filename; // varchar(191) not 255 because utf8mb4 takes more space
public $created; // datetime() not_null default_0000-00-00%2000%3A00%3A00
public $modified; // datetime() not_null default_CURRENT_TIMESTAMP
public static function schemaDef()
{
return array(
'fields' => array(
'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to profile table'),
'original' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'uploaded by user or generated?'),
'original' => array('type' => 'bool', 'default' => false, 'description' => 'uploaded by user or generated?'),
'width' => array('type' => 'int', 'not null' => true, 'description' => 'image width'),
'height' => array('type' => 'int', 'not null' => true, 'description' => 'image height'),
'mediatype' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'file type'),
@ -45,7 +59,7 @@ class Avatar extends Managed_DataObject
}
// We clean up the file, too
function delete($useWhere=false)
public function delete($useWhere = false)
{
$filename = $this->filename;
if (file_exists(Avatar::path($filename))) {
@ -57,11 +71,12 @@ class Avatar extends Managed_DataObject
/*
* Deletes all avatars (but may spare the original) from a profile.
*
*
* @param Profile $target The profile we're deleting avatars of.
* @param boolean $original Whether original should be removed or not.
*/
public static function deleteFromProfile(Profile $target, $original=true) {
public static function deleteFromProfile(Profile $target, $original = true)
{
try {
$avatars = self::getProfileAvatars($target);
foreach ($avatars as $avatar) {
@ -77,7 +92,7 @@ class Avatar extends Managed_DataObject
return true;
}
static protected $_avatars = array();
protected static $_avatars = [];
/*
* Get an avatar by profile. Currently can't call newSize with $height
@ -93,7 +108,7 @@ class Avatar extends Managed_DataObject
$size = "{$width}x{$height}";
if (!isset(self::$_avatars[$target->id])) {
self::$_avatars[$target->id] = array();
} elseif (isset(self::$_avatars[$target->id][$size])){
} elseif (isset(self::$_avatars[$target->id][$size])) {
return self::$_avatars[$target->id][$size];
}
@ -137,7 +152,8 @@ class Avatar extends Managed_DataObject
return $avatar;
}
public static function getProfileAvatars(Profile $target) {
public static function getProfileAvatars(Profile $target)
{
$avatar = new Avatar();
$avatar->profile_id = $target->id;
if (!$avatar->find()) {
@ -149,7 +165,7 @@ class Avatar extends Managed_DataObject
/**
* Where should the avatar go for this user?
*/
static function filename($id, $extension, $size=null, $extra=null)
public static function filename($id, $extension, $size = null, $extra = null)
{
if ($size) {
return $id . '-' . $size . (($extra) ? ('-' . $extra) : '') . $extension;
@ -158,7 +174,7 @@ class Avatar extends Managed_DataObject
}
}
static function path($filename)
public static function path($filename)
{
$dir = common_config('avatar', 'dir');
@ -169,7 +185,7 @@ class Avatar extends Managed_DataObject
return $dir . $filename;
}
static function url($filename)
public static function url($filename)
{
$path = common_config('avatar', 'path');
@ -194,20 +210,21 @@ class Avatar extends Managed_DataObject
return $protocol.'://'.$server.$path.$filename;
}
function displayUrl()
public function displayUrl()
{
return Avatar::url($this->filename);
}
static function urlByProfile(Profile $target, $width=null, $height=null) {
public static function urlByProfile(Profile $target, $width = null, $height = null)
{
try {
return self::byProfile($target, $width, $height)->displayUrl();
return self::byProfile($target, $width, $height)->displayUrl();
} catch (Exception $e) {
return self::defaultImage($width);
}
}
static function defaultImage($size=null)
public static function defaultImage($size = null)
{
if (is_null($size)) {
$size = AVATAR_PROFILE_SIZE;
@ -218,7 +235,8 @@ class Avatar extends Managed_DataObject
return Theme::path('default-avatar-'.$sizenames[$size].'.png');
}
static function newSize(Profile $target, $width) {
public static function newSize(Profile $target, $width)
{
$width = intval($width);
if ($width < 1 || $width > common_config('avatar', 'maxsize')) {
// TRANS: An error message when avatar size is unreasonable
@ -231,8 +249,12 @@ class Avatar extends Managed_DataObject
$original = Avatar::getUploaded($target);
$imagefile = new ImageFile(null, Avatar::path($original->filename));
$filename = Avatar::filename($target->getID(), image_type_to_extension($imagefile->preferredType()),
$width, common_timestamp());
$filename = Avatar::filename(
$target->getID(),
image_type_to_extension($imagefile->preferredType()),
$width,
common_timestamp()
);
$imagefile->resizeTo(Avatar::path($filename), array('width'=>$width, 'height'=>$height));
$scaled = clone($original);

View File

@ -1,4 +1,21 @@
<?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/>.
defined('GNUSOCIAL') || die();
/**
* Table Definition for group_member
*/
@ -11,7 +28,7 @@ class Group_member extends Managed_DataObject
public $__table = 'group_member'; // table name
public $group_id; // int(4) primary_key not_null
public $profile_id; // int(4) primary_key not_null
public $is_admin; // tinyint(1)
public $is_admin; // bool default_false
public $uri; // varchar(191) not 255 because utf8mb4 takes more space
public $created; // datetime() not_null default_0000-00-00%2000%3A00%3A00
public $modified; // datetime() not_null default_CURRENT_TIMESTAMP
@ -25,7 +42,7 @@ class Group_member extends Managed_DataObject
'fields' => array(
'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to user_group'),
'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to profile table'),
'is_admin' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'is this user an admin?'),
'is_admin' => array('type' => 'bool', 'default' => false, 'description' => 'is this user an admin?'),
'uri' => array('type' => 'varchar', 'length' => 191, 'description' => 'universal identifier'),
'created' => array('type' => 'datetime', 'not null' => true, 'default' => '0000-00-00 00:00:00', 'description' => 'date this record was created'),
'modified' => array('type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'),
@ -54,20 +71,22 @@ class Group_member extends Managed_DataObject
*
* @param integer $group_id Group to add to
* @param integer $profile_id Profile being added
*
*
* @return Group_member new membership object
*/
static function join($group_id, $profile_id)
public static function join($group_id, $profile_id)
{
$member = new Group_member();
$member->group_id = $group_id;
$member->profile_id = $profile_id;
$member->created = common_sql_now();
$member->uri = self::newUri(Profile::getByID($profile_id),
User_group::getByID($group_id),
$member->created);
$member->uri = self::newUri(
Profile::getByID($profile_id),
User_group::getByID($group_id),
$member->created
);
$result = $member->insert();
@ -80,7 +99,7 @@ class Group_member extends Managed_DataObject
return $member;
}
static function leave($group_id, $profile_id)
public static function leave($group_id, $profile_id)
{
$member = Group_member::pkeyGet(array('group_id' => $group_id,
'profile_id' => $profile_id));
@ -101,27 +120,27 @@ class Group_member extends Managed_DataObject
return true;
}
function getMember()
public function getMember()
{
$member = Profile::getKV('id', $this->profile_id);
if (empty($member)) {
// TRANS: Exception thrown providing an invalid profile ID.
// TRANS: %s is the invalid profile ID.
throw new Exception(sprintf(_("Profile ID %s is invalid."),$this->profile_id));
throw new Exception(sprintf(_("Profile ID %s is invalid."), $this->profile_id));
}
return $member;
}
function getGroup()
public function getGroup()
{
$group = User_group::getKV('id', $this->group_id);
if (empty($group)) {
// TRANS: Exception thrown providing an invalid group ID.
// TRANS: %s is the invalid group ID.
throw new Exception(sprintf(_("Group ID %s is invalid."),$this->group_id));
throw new Exception(sprintf(_('Group ID %s is invalid.'), $this->group_id));
}
return $group;
@ -137,7 +156,7 @@ class Group_member extends Managed_DataObject
* @return Group_member stream of memberships, use fetch() to iterate
*/
static function byMember($memberId, $offset=0, $limit=GROUPS_PER_PAGE)
public static function byMember($memberId, $offset = 0, $limit = GROUPS_PER_PAGE)
{
$membership = new Group_member();
@ -152,7 +171,7 @@ class Group_member extends Managed_DataObject
return $membership;
}
function asActivity()
public function asActivity()
{
$member = $this->getMember();
@ -180,13 +199,19 @@ class Group_member extends Managed_DataObject
// TRANS: Success message for subscribe to group attempt through OStatus.
// TRANS: %1$s is the member name, %2$s is the subscribed group's name.
$act->content = sprintf(_('%1$s has joined group %2$s.'),
$member->getBestName(),
$group->getBestName());
$act->content = sprintf(
_('%1$s has joined group %2$s.'),
$member->getBestName(),
$group->getBestName()
);
$url = common_local_url('AtomPubShowMembership',
array('profile' => $member->id,
'group' => $group->id));
$url = common_local_url(
'AtomPubShowMembership',
[
'profile' => $member->id,
'group' => $group->id,
]
);
$act->selfLink = $url;
$act->editLink = $url;
@ -203,7 +228,7 @@ class Group_member extends Managed_DataObject
mail_notify_group_join($this->getGroup(), $this->getMember());
}
function getUri()
public function getUri()
{
return $this->uri ?: self::newUri($this->getMember(), $this->getGroup()->getProfile(), $this->created);
}

View File

@ -238,12 +238,15 @@ abstract class Managed_DataObject extends Memcached_DataObject
}
// Data type formatting style...
$formatStyles = array('blob' => DB_DATAOBJECT_BLOB,
'text' => DB_DATAOBJECT_TXT,
'date' => DB_DATAOBJECT_DATE,
'time' => DB_DATAOBJECT_TIME,
'datetime' => DB_DATAOBJECT_DATE | DB_DATAOBJECT_TIME,
'timestamp' => DB_DATAOBJECT_MYSQLTIMESTAMP);
$formatStyles = [
'blob' => DB_DATAOBJECT_BLOB,
'text' => DB_DATAOBJECT_TXT,
'bool' => DB_DATAOBJECT_BOOL,
'date' => DB_DATAOBJECT_DATE,
'time' => DB_DATAOBJECT_TIME,
'datetime' => DB_DATAOBJECT_DATE | DB_DATAOBJECT_TIME,
'timestamp' => DB_DATAOBJECT_MYSQLTIMESTAMP,
];
if (isset($formatStyles[$type])) {
$style |= $formatStyles[$type];

View File

@ -1,48 +1,36 @@
<?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
* Copyright (C) 2011, StatusNet, Inc.
*
* Older-style UI preferences
*
* PHP version 5
*
* 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 UI
* @package StatusNet
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('STATUSNET')) {
// This check helps protect against security problems;
// your code file can't be executed directly from the web.
exit(1);
}
defined('GNUSOCIAL') || die();
/**
* Separate table for storing UI preferences
*
* @category UI
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class Old_school_prefs extends Managed_DataObject
@ -60,17 +48,14 @@ class Old_school_prefs extends Managed_DataObject
return array(
'fields' => array(
'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user who has the preference'),
'stream_mode_only' => array('type' => 'int',
'size' => 'tiny',
'default' => 1,
'stream_mode_only' => array('type' => 'bool',
'default' => true,
'description' => 'No conversation streams'),
'conversation_tree' => array('type' => 'int',
'size' => 'tiny',
'default' => 1,
'conversation_tree' => array('type' => 'bool',
'default' => true,
'description' => 'Hierarchical tree view for conversations'),
'stream_nicknames' => array('type' => 'int',
'size' => 'tiny',
'default' => 1,
'stream_nicknames' => array('type' => 'bool',
'default' => true,
'description' => 'Show nicknames for authors and addressees in streams'),
'created' => array('type' => 'datetime', 'not null' => true, 'default' => '0000-00-00 00:00:00', 'description' => 'date this record was created'),
'modified' => array('type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'),

View File

@ -1,23 +1,25 @@
<?php
/*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2008-2011, 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/>.
// 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/>.
/**
* @copyright 2008-2011 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('GNUSOCIAL')) { exit(1); }
defined('GNUSOCIAL') || die();
/**
* Table Definition for profile
@ -81,7 +83,7 @@ class Profile extends Managed_DataObject
throw new NoSuchUserException(array('email'=>$email));
}
return $user->getProfile();
}
}
protected $_user = array();
@ -202,16 +204,16 @@ class Profile extends Managed_DataObject
*
* @return string
*/
function getBestName()
public function getBestName()
{
return ($this->fullname) ? $this->fullname : $this->nickname;
}
/**
* Takes the currently scoped profile into account to give a name
* Takes the currently scoped profile into account to give a name
* to list in notice streams. Preferences may differ between profiles.
*/
function getStreamName()
public function getStreamName()
{
$user = common_current_user();
if ($user instanceof User && $user->streamNicknames()) {
@ -228,7 +230,7 @@ class Profile extends Managed_DataObject
*
* @return string
*/
function getFancyName()
public function getFancyName()
{
$uri = null;
try {
@ -243,7 +245,7 @@ class Profile extends Managed_DataObject
if (mb_strlen($this->getFullname()) > 0) {
// TRANS: The "fancy name": Full name of a profile or group (%1$s) followed by some URI (%2$s) in parentheses.
return sprintf(_m('FANCYNAME','%1$s (%2$s)'), $this->getFullname(), $uri);
return sprintf(_m('FANCYNAME', '%1$s (%2$s)'), $this->getFullname(), $uri);
} else {
return $uri;
}
@ -254,7 +256,7 @@ class Profile extends Managed_DataObject
*
* @return mixed Notice or null
*/
function getCurrentNotice(Profile $scoped=null)
public function getCurrentNotice(Profile $scoped = null)
{
try {
$notice = $this->getNotices(0, 1, 0, 0, $scoped);
@ -271,16 +273,16 @@ class Profile extends Managed_DataObject
// Maybe we should let this through if it's handled well upstream
return null;
}
return null;
}
function getReplies($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
public function getReplies($offset = 0, $limit = NOTICES_PER_PAGE, $since_id = 0, $before_id = 0)
{
return Reply::stream($this->getID(), $offset, $limit, $since_id, $before_id);
}
function getTaggedNotices($tag, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0)
public function getTaggedNotices($tag, $offset = 0, $limit = NOTICES_PER_PAGE, $since_id = 0, $max_id = 0)
{
//FIXME: Get Profile::current() some other way to avoid possible
// confusion between current session profile and background processing.
@ -289,39 +291,39 @@ class Profile extends Managed_DataObject
return $stream->getNotices($offset, $limit, $since_id, $max_id);
}
function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0, Profile $scoped=null)
public function getNotices($offset = 0, $limit = NOTICES_PER_PAGE, $since_id = 0, $max_id = 0, Profile $scoped = null)
{
$stream = new ProfileNoticeStream($this, $scoped);
return $stream->getNotices($offset, $limit, $since_id, $max_id);
}
function isMember(User_group $group)
public function isMember(User_group $group)
{
$groups = $this->getGroups(0, null);
$groups = $this->getGroups(0, null);
while ($groups instanceof User_group && $groups->fetch()) {
if ($groups->id == $group->id) {
return true;
}
}
return false;
if ($groups->id == $group->id) {
return true;
}
}
return false;
}
function isAdmin(User_group $group)
public function isAdmin(User_group $group)
{
$gm = Group_member::pkeyGet(array('profile_id' => $this->id,
'group_id' => $group->id));
return (!empty($gm) && $gm->is_admin);
}
function isPendingMember($group)
public function isPendingMember($group)
{
$request = Group_join_queue::pkeyGet(array('profile_id' => $this->id,
'group_id' => $group->id));
return !empty($request);
}
function getGroups($offset=0, $limit=PROFILES_PER_PAGE)
public function getGroups($offset = 0, $limit = PROFILES_PER_PAGE)
{
$ids = array();
@ -356,14 +358,15 @@ class Profile extends Managed_DataObject
}
}
function getGroupCount() {
public function getGroupCount()
{
$groups = $this->getGroups(0, null);
return $groups instanceof User_group
? $groups->N
: 0;
}
function isTagged($peopletag)
public function isTagged($peopletag)
{
$tag = Profile_tag::pkeyGet(array('tagger' => $peopletag->tagger,
'tagged' => $this->id,
@ -371,7 +374,7 @@ class Profile extends Managed_DataObject
return !empty($tag);
}
function canTag($tagged)
public function canTag($tagged)
{
if (empty($tagged)) {
return false;
@ -395,16 +398,16 @@ class Profile extends Managed_DataObject
if ($local) {
return true;
}
} else if ($subs) {
} elseif ($subs) {
return (Subscription::exists($this, $tagged) ||
Subscription::exists($tagged, $this));
} else if ($remote) {
} elseif ($remote) {
return true;
}
return false;
}
function getLists(Profile $scoped=null, $offset=0, $limit=null, $since_id=0, $max_id=0)
public function getLists(Profile $scoped = null, $offset = 0, $limit = null, $since_id = 0, $max_id = 0)
{
$ids = array();
@ -421,15 +424,15 @@ class Profile extends Managed_DataObject
$list->tagger = $this->id;
$list->selectAdd('id as "cursor"');
if ($since_id>0) {
$list->whereAdd('id > '.$since_id);
if ($since_id > 0) {
$list->whereAdd('id > ' . $since_id);
}
if ($max_id>0) {
$list->whereAdd('id <= '.$max_id);
if ($max_id > 0) {
$list->whereAdd('id <= ' . $max_id);
}
if($offset>=0 && !is_null($limit)) {
if ($offset >= 0 && !is_null($limit)) {
$list->limit($offset, $limit);
}
@ -452,7 +455,6 @@ class Profile extends Managed_DataObject
$list = Profile_list::getKV('id', $id);
if (!empty($list) &&
($showPrivate || !$list->private)) {
if (!isset($list->cursor)) {
$list->cursor = $list->id;
}
@ -476,25 +478,28 @@ class Profile extends Managed_DataObject
* @return Profile_list resulting lists
*/
function getOtherTags(Profile $scoped=null, $offset=0, $limit=null, $since_id=0, $max_id=0)
public function getOtherTags(Profile $scoped = null, $offset = 0, $limit = null, $since_id = 0, $max_id = 0)
{
$list = new Profile_list();
$qry = sprintf('select profile_list.*, unix_timestamp(profile_tag.modified) as "cursor" ' .
'from profile_tag join profile_list '.
'on (profile_tag.tagger = profile_list.tagger ' .
' and profile_tag.tag = profile_list.tag) ' .
'where profile_tag.tagged = %d ',
$this->id);
$qry = sprintf(
'SELECT profile_list.*, unix_timestamp(profile_tag.modified) AS "cursor" ' .
'FROM profile_tag JOIN profile_list '.
'ON (profile_tag.tagger = profile_list.tagger ' .
' AND profile_tag.tag = profile_list.tag) ' .
'WHERE profile_tag.tagged = %d ',
$this->id
);
if (!is_null($scoped)) {
$qry .= sprintf('AND ( ( profile_list.private = false ) ' .
'OR ( profile_list.tagger = %d AND ' .
'profile_list.private = true ) )',
$scoped->getID());
$qry .= sprintf(
'AND ( profile_list.private = false ' .
'OR ( profile_list.tagger = %d AND ' .
'profile_list.private = TRUE ) )',
$scoped->getID()
);
} else {
$qry .= 'AND profile_list.private = 0 ';
$qry .= 'AND profile_list.private = FALSE ';
}
if ($since_id > 0) {
@ -515,21 +520,21 @@ class Profile extends Managed_DataObject
return $list;
}
function getPrivateTags($offset=0, $limit=null, $since_id=0, $max_id=0)
public function getPrivateTags($offset = 0, $limit = null, $since_id = 0, $max_id = 0)
{
$tags = new Profile_list();
$tags->private = true;
$tags->tagger = $this->id;
if ($since_id>0) {
$tags->whereAdd('id > '.$since_id);
if ($since_id > 0) {
$tags->whereAdd('id > ' . $since_id);
}
if ($max_id>0) {
$tags->whereAdd('id <= '.$max_id);
if ($max_id > 0) {
$tags->whereAdd('id <= ' . $max_id);
}
if($offset>=0 && !is_null($limit)) {
if ($offset >= 0 && !is_null($limit)) {
$tags->limit($offset, $limit);
}
@ -539,7 +544,7 @@ class Profile extends Managed_DataObject
return $tags;
}
function hasLocalTags()
public function hasLocalTags()
{
$tags = new Profile_tag();
@ -553,7 +558,7 @@ class Profile extends Managed_DataObject
return ($tags->N == 0) ? false : true;
}
function getTagSubscriptions($offset=0, $limit=null, $since_id=0, $max_id=0)
public function getTagSubscriptions($offset = 0, $limit = null, $since_id = 0, $max_id = 0)
{
$lists = new Profile_list();
$subs = new Profile_tag_subscription();
@ -565,15 +570,15 @@ class Profile extends Managed_DataObject
$lists->whereAdd('profile_tag_subscription.profile_id = '.$this->id);
if ($since_id>0) {
$lists->whereAdd('cursor > '.$since_id);
if ($since_id > 0) {
$lists->whereAdd('cursor > ' . $since_id);
}
if ($max_id>0) {
$lists->whereAdd('cursor <= '.$max_id);
if ($max_id > 0) {
$lists->whereAdd('cursor <= ' . $max_id);
}
if($offset>=0 && !is_null($limit)) {
if ($offset >= 0 && !is_null($limit)) {
$lists->limit($offset, $limit);
}
@ -590,7 +595,7 @@ class Profile extends Managed_DataObject
* @param User_group $group
* @return mixed: Group_member on success, Group_join_queue if pending approval, null on some cancels?
*/
function joinGroup(User_group $group)
public function joinGroup(User_group $group)
{
$join = null;
if ($group->join_policy == User_group::JOIN_POLICY_MODERATE) {
@ -616,7 +621,7 @@ class Profile extends Managed_DataObject
*
* @param User_group $group
*/
function leaveGroup(User_group $group)
public function leaveGroup(User_group $group)
{
if (Event::handle('StartLeaveGroup', array($group, $this))) {
Group_member::leave($group->id, $this->id);
@ -627,12 +632,12 @@ class Profile extends Managed_DataObject
}
}
function avatarUrl($size=AVATAR_PROFILE_SIZE)
public function avatarUrl($size = AVATAR_PROFILE_SIZE)
{
return Avatar::urlByProfile($this, $size);
}
function getSubscribed($offset=0, $limit=null)
public function getSubscribed($offset = 0, $limit = null)
{
$subs = Subscription::getSubscribedIDs($this->id, $offset, $limit);
try {
@ -643,7 +648,7 @@ class Profile extends Managed_DataObject
return $profiles;
}
function getSubscribers($offset=0, $limit=null)
public function getSubscribers($offset = 0, $limit = null)
{
$subs = Subscription::getSubscriberIDs($this->id, $offset, $limit);
try {
@ -654,7 +659,7 @@ class Profile extends Managed_DataObject
return $profiles;
}
function getTaggedSubscribers($tag, $offset=0, $limit=null)
public function getTaggedSubscribers($tag, $offset = 0, $limit = null)
{
$qry =
'SELECT profile.* ' .
@ -678,7 +683,7 @@ class Profile extends Managed_DataObject
return $profile;
}
function getTaggedSubscriptions($tag, $offset=0, $limit=null)
public function getTaggedSubscriptions($tag, $offset = 0, $limit = null)
{
$qry =
'SELECT profile.* ' .
@ -707,7 +712,7 @@ class Profile extends Managed_DataObject
* @param int $limit
* @return Profile
*/
function getRequests($offset=0, $limit=null)
public function getRequests($offset = 0, $limit = null)
{
// FIXME: mysql only
$subqueue = new Profile();
@ -721,7 +726,7 @@ class Profile extends Managed_DataObject
return $subqueue;
}
function subscriptionCount()
public function subscriptionCount()
{
$c = Cache::instance();
@ -749,7 +754,7 @@ class Profile extends Managed_DataObject
return $cnt;
}
function subscriberCount()
public function subscriberCount()
{
$c = Cache::instance();
if (!empty($c)) {
@ -777,12 +782,12 @@ class Profile extends Managed_DataObject
* @param Profile $other
* @return boolean
*/
function isSubscribed(Profile $other)
public function isSubscribed(Profile $other)
{
return Subscription::exists($this, $other);
}
function readableBy(Profile $other=null)
public function readableBy(Profile $other = null)
{
// If it's not a private stream, it's readable by anyone
if (!$this->isPrivateStream()) {
@ -793,7 +798,7 @@ class Profile extends Managed_DataObject
return is_null($other) ? false : $other->isSubscribed($this);
}
function requiresSubscriptionApproval(Profile $other=null): bool
public function requiresSubscriptionApproval(Profile $other = null): bool
{
if (!$this->isLocal()) {
// We don't know for remote users, and we'll always be able to send
@ -818,7 +823,7 @@ class Profile extends Managed_DataObject
* @param Profile $other
* @return boolean
*/
function hasPendingSubscription(Profile $other)
public function hasPendingSubscription(Profile $other)
{
return Subscription_queue::exists($this, $other);
}
@ -829,13 +834,13 @@ class Profile extends Managed_DataObject
* @param Profile $other
* @return boolean
*/
function mutuallySubscribed(Profile $other)
public function mutuallySubscribed(Profile $other)
{
return $this->isSubscribed($other) &&
$other->isSubscribed($this);
}
function noticeCount()
public function noticeCount()
{
$c = Cache::instance();
@ -858,7 +863,7 @@ class Profile extends Managed_DataObject
return $cnt;
}
function blowSubscriberCount()
public function blowSubscriberCount()
{
$c = Cache::instance();
if (!empty($c)) {
@ -866,7 +871,7 @@ class Profile extends Managed_DataObject
}
}
function blowSubscriptionCount()
public function blowSubscriptionCount()
{
$c = Cache::instance();
if (!empty($c)) {
@ -874,7 +879,7 @@ class Profile extends Managed_DataObject
}
}
function blowNoticeCount()
public function blowNoticeCount()
{
$c = Cache::instance();
if (!empty($c)) {
@ -882,7 +887,7 @@ class Profile extends Managed_DataObject
}
}
static function maxBio()
public static function maxBio()
{
$biolimit = common_config('profile', 'biolimit');
// null => use global limit (distinct from 0!)
@ -892,13 +897,13 @@ class Profile extends Managed_DataObject
return $biolimit;
}
static function bioTooLong($bio)
public static function bioTooLong($bio)
{
$biolimit = self::maxBio();
return ($biolimit > 0 && !empty($bio) && (mb_strlen($bio) > $biolimit));
}
function update($dataObject=false)
public function update($dataObject = false)
{
if (is_object($dataObject) && $this->nickname != $dataObject->nickname) {
try {
@ -946,7 +951,7 @@ class Profile extends Managed_DataObject
return $relMes;
}
function delete($useWhere=false)
public function delete($useWhere = false)
{
$this->_deleteNotices();
$this->_deleteSubscriptions();
@ -957,10 +962,11 @@ class Profile extends Managed_DataObject
// Warning: delete() will run on the batch objects,
// not on individual objects.
$related = array('Reply',
'Group_member',
'Profile_role'
);
$related = [
'Reply',
'Group_member',
'Profile_role',
];
Event::handle('ProfileDeleteRelated', array($this, &$related));
foreach ($related as $cls) {
@ -968,7 +974,7 @@ class Profile extends Managed_DataObject
$inst->profile_id = $this->id;
$inst->delete();
}
$this->grantRole(Profile_role::DELETED);
$localuser = User::getKV('id', $this->id);
@ -979,7 +985,7 @@ class Profile extends Managed_DataObject
return parent::delete($useWhere);
}
function _deleteNotices()
public function _deleteNotices()
{
$notice = new Notice();
$notice->profile_id = $this->id;
@ -992,7 +998,7 @@ class Profile extends Managed_DataObject
}
}
function _deleteSubscriptions()
public function _deleteSubscriptions()
{
$sub = new Subscription();
$sub->subscriber = $this->getID();
@ -1040,14 +1046,14 @@ class Profile extends Managed_DataObject
$self->delete();
}
function _deleteTags()
public function _deleteTags()
{
$tag = new Profile_tag();
$tag->tagged = $this->id;
$tag->delete();
}
function _deleteBlocks()
public function _deleteBlocks()
{
$block = new Profile_block();
$block->blocked = $this->id;
@ -1058,7 +1064,7 @@ class Profile extends Managed_DataObject
$block->delete();
}
function _deleteAttentions()
public function _deleteAttentions()
{
$att = new Attention();
$att->profile_id = $this->getID();
@ -1103,7 +1109,7 @@ class Profile extends Managed_DataObject
if ($cfg == 'always') {
return true;
} else if ($cfg == 'never') {
} elseif ($cfg == 'never') {
return false;
} else { // user
$share = common_config('location', 'sharedefault');
@ -1120,7 +1126,7 @@ class Profile extends Managed_DataObject
}
}
function hasRole($name)
public function hasRole($name)
{
$has_role = false;
if (Event::handle('StartHasRole', array($this, $name, &$has_role))) {
@ -1132,10 +1138,9 @@ class Profile extends Managed_DataObject
return $has_role;
}
function grantRole($name)
public function grantRole($name)
{
if (Event::handle('StartGrantRole', array($this, $name))) {
$role = new Profile_role();
$role->profile_id = $this->id;
@ -1158,17 +1163,20 @@ class Profile extends Managed_DataObject
return $result;
}
function revokeRole($name)
public function revokeRole($name)
{
if (Event::handle('StartRevokeRole', array($this, $name))) {
$role = Profile_role::pkeyGet(array('profile_id' => $this->id,
'role' => $name));
if (empty($role)) {
// TRANS: Exception thrown when trying to revoke an existing role for a user that does not exist.
// TRANS: %1$s is the role name, %2$s is the user ID (number).
throw new Exception(sprintf(_('Cannot revoke role "%1$s" for user #%2$d; does not exist.'),$name, $this->id));
throw new Exception(sprintf(
_('Cannot revoke role "%1$s" for user #%2$d; does not exist.'),
$name,
$this->id
));
}
$result = $role->delete();
@ -1177,7 +1185,11 @@ class Profile extends Managed_DataObject
common_log_db_error($role, 'DELETE', __FILE__);
// TRANS: Exception thrown when trying to revoke a role for a user with a failing database query.
// TRANS: %1$s is the role name, %2$s is the user ID (number).
throw new Exception(sprintf(_('Cannot revoke role "%1$s" for user #%2$d; database error.'),$name, $this->id));
throw new Exception(sprintf(
_('Cannot revoke role "%1$s" for user #%2$d; database error.'),
$name,
$this->id
));
}
if ($name == 'owner') {
@ -1190,27 +1202,27 @@ class Profile extends Managed_DataObject
}
}
function isSandboxed()
public function isSandboxed()
{
return $this->hasRole(Profile_role::SANDBOXED);
}
function isSilenced()
public function isSilenced()
{
return $this->hasRole(Profile_role::SILENCED);
}
function sandbox()
public function sandbox()
{
$this->grantRole(Profile_role::SANDBOXED);
}
function unsandbox()
public function unsandbox()
{
$this->revokeRole(Profile_role::SANDBOXED);
}
function silence()
public function silence()
{
$this->grantRole(Profile_role::SILENCED);
if (common_config('notice', 'hidespam')) {
@ -1218,7 +1230,7 @@ class Profile extends Managed_DataObject
}
}
function silenceAs(Profile $actor)
public function silenceAs(Profile $actor)
{
if (!$actor->hasRight(Right::SILENCEUSER)) {
throw new AuthorizationException(_('You cannot silence users on this site.'));
@ -1234,7 +1246,7 @@ class Profile extends Managed_DataObject
return $this->silence();
}
function unsilence()
public function unsilence()
{
$this->revokeRole(Profile_role::SILENCED);
if (common_config('notice', 'hidespam')) {
@ -1242,7 +1254,7 @@ class Profile extends Managed_DataObject
}
}
function unsilenceAs(Profile $actor)
public function unsilenceAs(Profile $actor)
{
if (!$actor->hasRight(Right::SILENCEUSER)) {
// TRANS: Client error displayed trying to unsilence a user when the user does not have the right.
@ -1255,7 +1267,7 @@ class Profile extends Managed_DataObject
return $this->unsilence();
}
function flushVisibility()
public function flushVisibility()
{
// Get all notices
$stream = new ProfileNoticeStream($this, $this);
@ -1301,8 +1313,7 @@ class Profile extends Managed_DataObject
}
if (Event::handle('UserRightsCheck', array($this, $right, &$result))) {
switch ($right)
{
switch ($right) {
case Right::DELETEOTHERSNOTICE:
case Right::MAKEGROUPADMIN:
case Right::SANDBOXUSER:
@ -1380,7 +1391,7 @@ class Profile extends Managed_DataObject
*
* @return string
*/
function asAtomAuthor($cur = null)
public function asAtomAuthor($cur = null)
{
$xs = new XMLStringer(true);
@ -1388,7 +1399,7 @@ class Profile extends Managed_DataObject
$xs->element('name', null, $this->nickname);
$xs->element('uri', null, $this->getUri());
if ($cur != null) {
$attrs = Array();
$attrs = [];
$attrs['following'] = $cur->isSubscribed($this) ? 'true' : 'false';
$attrs['blocking'] = $cur->hasBlocked($this) ? 'true' : 'false';
$xs->element('statusnet:profile_info', $attrs, null);
@ -1409,7 +1420,7 @@ class Profile extends Managed_DataObject
* @return array representation of <statusnet:profile_info> element or null
*/
function profileInfo(Profile $scoped=null)
public function profileInfo(Profile $scoped = null)
{
$profileInfoAttr = array('local_id' => $this->id);
@ -1431,7 +1442,7 @@ class Profile extends Managed_DataObject
*
* @return string
*/
function asActivityActor()
public function asActivityActor()
{
return $this->asActivityNoun('actor');
}
@ -1447,7 +1458,7 @@ class Profile extends Managed_DataObject
*
* @return string
*/
function asActivityNoun($element)
public function asActivityNoun($element)
{
$noun = $this->asActivityObject();
return $noun->asString('activity:' . $element);
@ -1619,7 +1630,7 @@ class Profile extends Managed_DataObject
return $scheme ? $acct : mb_substr($acct, 5);
}
function hasBlocked(Profile $other)
public function hasBlocked(Profile $other)
{
$block = Profile_block::exists($this, $other);
return !empty($block);
@ -1652,7 +1663,7 @@ class Profile extends Managed_DataObject
*
* @param string $uri A unique identifier for a resource (profile/group/whatever)
*/
static function fromUri($uri)
public static function fromUri($uri)
{
$profile = null;
@ -1677,7 +1688,7 @@ class Profile extends Managed_DataObject
return $profile;
}
function canRead(Notice $notice)
public function canRead(Notice $notice)
{
if ($notice->scope & Notice::SITE_SCOPE) {
$user = $this->getUser();
@ -1717,7 +1728,7 @@ class Profile extends Managed_DataObject
return true;
}
static function current()
public static function current()
{
$user = common_current_user();
if (empty($user)) {
@ -1728,7 +1739,7 @@ class Profile extends Managed_DataObject
return $profile;
}
static function ensureCurrent()
public static function ensureCurrent()
{
$profile = self::current();
if (!$profile instanceof Profile) {
@ -1747,7 +1758,7 @@ class Profile extends Managed_DataObject
* @return array of variable names to include in serialization.
*/
function __sleep()
public function __sleep()
{
$vars = parent::__sleep();
$skip = array('_user', '_group');
@ -1802,11 +1813,13 @@ class Profile extends Managed_DataObject
return !is_null($private_stream) && $private_stream;
}
public function delPref($namespace, $topic) {
public function delPref($namespace, $topic)
{
return Profile_prefs::setData($this, $namespace, $topic, null);
}
public function getPref($namespace, $topic, $default=null) {
public function getPref($namespace, $topic, $default = null)
{
// If you want an exception to be thrown, call Profile_prefs::getData directly
try {
return Profile_prefs::getData($this, $namespace, $topic, $default);
@ -1821,7 +1834,8 @@ class Profile extends Managed_DataObject
return Profile_prefs::getConfigData($this, $namespace, $topic);
}
public function setPref($namespace, $topic, $data) {
public function setPref($namespace, $topic, $data)
{
return Profile_prefs::setData($this, $namespace, $topic, $data);
}

View File

@ -31,7 +31,7 @@ class Profile_list extends Managed_DataObject
public $tagger; // int(4)
public $tag; // varchar(64)
public $description; // text
public $private; // tinyint(1)
public $private; // bool default_false
public $created; // datetime() not_null default_0000-00-00%2000%3A00%3A00
public $modified; // datetime() not_null default_CURRENT_TIMESTAMP
public $uri; // varchar(191) unique_key not 255 because utf8mb4 takes more space
@ -47,7 +47,7 @@ class Profile_list extends Managed_DataObject
'tagger' => array('type' => 'int', 'not null' => true, 'description' => 'user making the tag'),
'tag' => array('type' => 'varchar', 'length' => 64, 'not null' => true, 'description' => 'people tag'),
'description' => array('type' => 'text', 'description' => 'description of the people tag'),
'private' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'is this tag private'),
'private' => array('type' => 'bool', 'default' => false, 'description' => 'is this tag private'),
'created' => array('type' => 'datetime', 'not null' => true, 'default' => '0000-00-00 00:00:00', 'description' => 'date the tag was added'),
'modified' => array('type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date the tag was modified'),

View File

@ -96,7 +96,7 @@ class Profile_tag extends Managed_DataObject
$qry = sprintf($qry, $tagger, $tagged);
if (!$include_priv) {
$qry .= ' and profile_list.private = 0';
$qry .= ' AND profile_list.private = FALSE';
}
$profile_list->query($qry);
@ -122,7 +122,7 @@ class Profile_tag extends Managed_DataObject
);
if (!$scoped instanceof Profile || $scoped->getID() !== $tagger) {
$qry .= 'and profile_list.private = 0';
$qry .= 'AND profile_list.private = FALSE';
}
$tags = array();

View File

@ -1,23 +1,25 @@
<?php
/*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2008, 2009, 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/>.
// 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/>.
/**
* @copyright 2008, 2009, StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('GNUSOCIAL')) { exit(1); }
defined('GNUSOCIAL') || die();
/**
* Table Definition for subscription
@ -30,8 +32,8 @@ class Subscription extends Managed_DataObject
public $__table = 'subscription'; // table name
public $subscriber; // int(4) primary_key not_null
public $subscribed; // int(4) primary_key not_null
public $jabber; // tinyint(1) default_1
public $sms; // tinyint(1) default_1
public $jabber; // bool default_true
public $sms; // bool default_true
public $token; // varchar(191) not 255 because utf8mb4 takes more space
public $secret; // varchar(191) not 255 because utf8mb4 takes more space
public $uri; // varchar(191) not 255 because utf8mb4 takes more space
@ -44,8 +46,8 @@ class Subscription extends Managed_DataObject
'fields' => array(
'subscriber' => array('type' => 'int', 'not null' => true, 'description' => 'profile listening'),
'subscribed' => array('type' => 'int', 'not null' => true, 'description' => 'profile being listened to'),
'jabber' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'deliver jabber messages'),
'sms' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'deliver sms messages'),
'jabber' => array('type' => 'bool', 'default' => true, 'description' => 'deliver jabber messages'),
'sms' => array('type' => 'bool', 'default' => true, 'description' => 'deliver sms messages'),
'token' => array('type' => 'varchar', 'length' => 191, 'description' => 'authorization token'),
'secret' => array('type' => 'varchar', 'length' => 191, 'description' => 'token secret'),
'uri' => array('type' => 'varchar', 'length' => 191, 'description' => 'universally unique identifier'),
@ -74,7 +76,7 @@ class Subscription extends Managed_DataObject
* @return mixed Subscription or Subscription_queue: new subscription info
*/
static function start(Profile $subscriber, Profile $other, $force=false)
public static function start(Profile $subscriber, Profile $other, $force = false)
{
if (!$subscriber->hasRight(Right::SUBSCRIBE)) {
// TRANS: Exception thrown when trying to subscribe while being banned from subscribing.
@ -117,7 +119,6 @@ class Subscription extends Managed_DataObject
$otherUser->autosubscribe &&
!self::exists($other, $subscriber) &&
!$subscriber->hasBlocked($other)) {
try {
self::start($other, $subscriber);
} catch (AlreadyFulfilledException $e) {
@ -137,7 +138,7 @@ class Subscription extends Managed_DataObject
return $sub;
}
static function ensureStart(Profile $subscriber, Profile $other, $force=false)
public static function ensureStart(Profile $subscriber, Profile $other, $force = false)
{
try {
$sub = self::start($subscriber, $other, $force);
@ -157,12 +158,14 @@ class Subscription extends Managed_DataObject
$sub->subscriber = $subscriber->getID();
$sub->subscribed = $other->getID();
$sub->jabber = 1;
$sub->sms = 1;
$sub->jabber = true;
$sub->sms = true;
$sub->created = common_sql_now();
$sub->uri = self::newUri($subscriber,
$other,
$sub->created);
$sub->uri = self::newUri(
$subscriber,
$other,
$sub->created
);
$result = $sub->insert();
@ -175,7 +178,7 @@ class Subscription extends Managed_DataObject
return $sub;
}
function notify()
public function notify()
{
// XXX: add other notifications (Jabber, SMS) here
// XXX: queue this and handle it offline
@ -184,12 +187,11 @@ class Subscription extends Managed_DataObject
$this->notifyEmail();
}
function notifyEmail()
public function notifyEmail()
{
$subscribedUser = User::getKV('id', $this->subscribed);
if ($subscribedUser instanceof User) {
$subscriber = Profile::getKV('id', $this->subscriber);
mail_subscribe_notify_profile($subscribedUser, $subscriber);
@ -200,7 +202,7 @@ class Subscription extends Managed_DataObject
* Cancel a subscription
*
*/
static function cancel(Profile $subscriber, Profile $other)
public static function cancel(Profile $subscriber, Profile $other)
{
if (!self::exists($subscriber, $other)) {
// TRANS: Exception thrown when trying to unsibscribe without a subscription.
@ -215,7 +217,6 @@ class Subscription extends Managed_DataObject
}
if (Event::handle('StartUnsubscribe', array($subscriber, $other))) {
$sub = Subscription::pkeyGet(array('subscriber' => $subscriber->id,
'subscribed' => $other->id));
@ -245,7 +246,7 @@ class Subscription extends Managed_DataObject
return;
}
static function exists(Profile $subscriber, Profile $other)
public static function exists(Profile $subscriber, Profile $other)
{
try {
$sub = self::getSubscription($subscriber, $other);
@ -256,7 +257,7 @@ class Subscription extends Managed_DataObject
return true;
}
static function getSubscription(Profile $subscriber, Profile $other)
public static function getSubscription(Profile $subscriber, Profile $other)
{
// This is essentially a pkeyGet but we have an object to return in NoResultException
$sub = new Subscription();
@ -278,7 +279,7 @@ class Subscription extends Managed_DataObject
return Profile::getByID($this->subscribed);
}
function asActivity()
public function asActivity()
{
$subscriber = $this->getSubscriber();
$subscribed = $this->getSubscribed();
@ -293,19 +294,25 @@ class Subscription extends Managed_DataObject
$act->time = strtotime($this->created);
// TRANS: Activity title when subscribing to another person.
$act->title = _m('TITLE','Follow');
$act->title = _m('TITLE', 'Follow');
// TRANS: Notification given when one person starts following another.
// TRANS: %1$s is the subscriber, %2$s is the subscribed.
$act->content = sprintf(_('%1$s is now following %2$s.'),
$subscriber->getBestName(),
$subscribed->getBestName());
$act->content = sprintf(
_('%1$s is now following %2$s.'),
$subscriber->getBestName(),
$subscribed->getBestName()
);
$act->actor = $subscriber->asActivityObject();
$act->objects[] = $subscribed->asActivityObject();
$url = common_local_url('AtomPubShowSubscription',
array('subscriber' => $subscriber->id,
'subscribed' => $subscribed->id));
$url = common_local_url(
'AtomPubShowSubscription',
[
'subscriber' => $subscriber->id,
'subscribed' => $subscribed->id,
]
);
$act->selfLink = $url;
$act->editLink = $url;
@ -356,11 +363,13 @@ class Subscription extends Managed_DataObject
// The following are helper functions to the subscription lists,
// notably the public ones get used in places such as Profile
public static function getSubscribedIDs($profile_id, $offset, $limit) {
public static function getSubscribedIDs($profile_id, $offset, $limit)
{
return self::getSubscriptionIDs('subscribed', $profile_id, $offset, $limit);
}
public static function getSubscriberIDs($profile_id, $offset, $limit) {
public static function getSubscriberIDs($profile_id, $offset, $limit)
{
return self::getSubscriptionIDs('subscriber', $profile_id, $offset, $limit);
}
@ -426,7 +435,7 @@ class Subscription extends Managed_DataObject
*
* @return boolean success flag.
*/
function update($dataObject=false)
public function update($dataObject = false)
{
self::blow('subscription:by-subscriber:'.$this->subscriber);
self::blow('subscription:by-subscribed:'.$this->subscribed);

View File

@ -34,24 +34,24 @@ class User extends Managed_DataObject
public $password; // varchar(191) not 255 because utf8mb4 takes more space
public $email; // varchar(191) unique_key not 255 because utf8mb4 takes more space
public $incomingemail; // varchar(191) unique_key not 255 because utf8mb4 takes more space
public $emailnotifysub; // tinyint(1) default_1
public $emailnotifyfav; // tinyint(1) default_1
public $emailnotifynudge; // tinyint(1) default_1
public $emailnotifymsg; // tinyint(1) default_1
public $emailnotifyattn; // tinyint(1) default_1
public $emailnotifysub; // bool default_true
public $emailnotifyfav; // tinyint(1) default_null
public $emailnotifynudge; // bool default_true
public $emailnotifymsg; // bool default_true
public $emailnotifyattn; // bool default_true
public $language; // varchar(50)
public $timezone; // varchar(50)
public $emailpost; // tinyint(1) default_1
public $emailpost; // bool default_true
public $sms; // varchar(64) unique_key
public $carrier; // int(4)
public $smsnotify; // tinyint(1)
public $smsreplies; // tinyint(1)
public $smsnotify; // bool default_false
public $smsreplies; // bool default_false
public $smsemail; // varchar(191) not 255 because utf8mb4 takes more space
public $uri; // varchar(191) unique_key not 255 because utf8mb4 takes more space
public $autosubscribe; // tinyint(1)
public $autosubscribe; // bool default_false
public $subscribe_policy; // tinyint(1)
public $urlshorteningservice; // varchar(50) default_ur1.ca
public $private_stream; // tinyint(1) default_0
public $private_stream; // bool default_false
public $created; // datetime() not_null default_0000-00-00%2000%3A00%3A00
public $modified; // datetime() not_null default_CURRENT_TIMESTAMP
@ -68,24 +68,24 @@ class User extends Managed_DataObject
'password' => array('type' => 'varchar', 'length' => 191, 'description' => 'salted password, can be null for OpenID users'),
'email' => array('type' => 'varchar', 'length' => 191, 'description' => 'email address for password recovery etc.'),
'incomingemail' => array('type' => 'varchar', 'length' => 191, 'description' => 'email address for post-by-email'),
'emailnotifysub' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Notify by email of subscriptions'),
'emailnotifysub' => array('type' => 'bool', 'default' => true, 'description' => 'Notify by email of subscriptions'),
'emailnotifyfav' => array('type' => 'int', 'size' => 'tiny', 'default' => null, 'description' => 'Notify by email of favorites'),
'emailnotifynudge' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Notify by email of nudges'),
'emailnotifymsg' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Notify by email of direct messages'),
'emailnotifyattn' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Notify by email of @-replies'),
'emailnotifynudge' => array('type' => 'bool', 'default' => true, 'description' => 'Notify by email of nudges'),
'emailnotifymsg' => array('type' => 'bool', 'default' => true, 'description' => 'Notify by email of direct messages'),
'emailnotifyattn' => array('type' => 'bool', 'default' => true, 'description' => 'Notify by email of @-replies'),
'language' => array('type' => 'varchar', 'length' => 50, 'description' => 'preferred language'),
'timezone' => array('type' => 'varchar', 'length' => 50, 'description' => 'timezone'),
'emailpost' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Post by email'),
'emailpost' => array('type' => 'bool', 'default' => true, 'description' => 'Post by email'),
'sms' => array('type' => 'varchar', 'length' => 64, 'description' => 'sms phone number'),
'carrier' => array('type' => 'int', 'description' => 'foreign key to sms_carrier'),
'smsnotify' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'whether to send notices to SMS'),
'smsreplies' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'whether to send notices to SMS on replies'),
'smsnotify' => array('type' => 'bool', 'default' => false, 'description' => 'whether to send notices to SMS'),
'smsreplies' => array('type' => 'bool', 'default' => false, 'description' => 'whether to send notices to SMS on replies'),
'smsemail' => array('type' => 'varchar', 'length' => 191, 'description' => 'built from sms and carrier'),
'uri' => array('type' => 'varchar', 'length' => 191, 'description' => 'universally unique identifier, usually a tag URI'),
'autosubscribe' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'automatically subscribe to users who subscribe to us'),
'autosubscribe' => array('type' => 'bool', 'default' => false, 'description' => 'automatically subscribe to users who subscribe to us'),
'subscribe_policy' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => '0 = anybody can subscribe; 1 = require approval'),
'urlshorteningservice' => array('type' => 'varchar', 'length' => 50, 'default' => 'internal', 'description' => 'service to use for auto-shortening URLs'),
'private_stream' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'whether to limit all notices to followers only'),
'private_stream' => array('type' => 'bool', 'default' => false, 'description' => 'whether to limit all notices to followers only'),
'created' => array('type' => 'datetime', 'not null' => true, 'default' => '0000-00-00 00:00:00', 'description' => 'date this record was created'),
'modified' => array('type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'),
),
@ -265,11 +265,11 @@ class User extends Managed_DataObject
// Set default-on options here, otherwise they'll be disabled
// initially for sites using caching, since the initial encache
// doesn't know about the defaults in the database.
$user->emailnotifysub = 1;
$user->emailnotifynudge = 1;
$user->emailnotifymsg = 1;
$user->emailnotifyattn = 1;
$user->emailpost = 1;
$user->emailnotifysub = true;
$user->emailnotifynudge = true;
$user->emailnotifymsg = true;
$user->emailnotifyattn = true;
$user->emailpost = true;
$user->created = common_sql_now();

View File

@ -248,7 +248,7 @@ class User_group extends Managed_DataObject
{
$block = new Group_member();
$block->group_id = $this->id;
$block->is_admin = 1;
$block->is_admin = true;
return $block->count();
}
@ -300,7 +300,7 @@ class User_group extends Managed_DataObject
{
$admins = new Profile();
$admins->joinAdd(array('id', 'group_member:profile_id'));
$admins->whereAdd(sprintf('group_member.group_id = %u AND group_member.is_admin = 1', $this->id));
$admins->whereAdd('group_member.group_id = ' . $this->id . ' AND group_member.is_admin = true');
$admins->orderBy('group_member.modified ASC');
$admins->limit($offset, $limit);
$admins->find();
@ -692,7 +692,7 @@ class User_group extends Managed_DataObject
$member->group_id = $group->id;
$member->profile_id = $userid;
$member->is_admin = 1;
$member->is_admin = true;
$member->created = $group->created;
$result = $member->insert();

View File

@ -1,32 +1,31 @@
<?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 user IM 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
* @package GNUsocial
* @author Craig Andrews <candrews@integralblue.com>
* @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/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
defined('GNUSOCIAL') || die();
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
class User_im_prefs extends Managed_DataObject
@ -38,9 +37,9 @@ class User_im_prefs extends Managed_DataObject
public $user_id; // int(4) primary_key not_null
public $screenname; // varchar(191) not_null not 255 because utf8mb4 takes more space
public $transport; // varchar(191) not_null not 255 because utf8mb4 takes more space
public $notify; // tinyint(1)
public $replies; // tinyint(1)
public $updatefrompresence; // tinyint(1)
public $notify; // bool not_null default_false
public $replies; // bool not_null default_false
public $updatefrompresence; // bool not_null default_false
public $created; // datetime() not_null default_0000-00-00%2000%3A00%3A00
public $modified; // datetime() not_null default_CURRENT_TIMESTAMP
@ -54,9 +53,9 @@ class User_im_prefs extends Managed_DataObject
'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user'),
'screenname' => array('type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'screenname on this service'),
'transport' => array('type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'transport (ex xmpp, aim)'),
'notify' => array('type' => 'int', 'size' => 'tiny', 'not null' => true, 'default' => 0, 'description' => 'Notify when a new notice is sent'),
'replies' => array('type' => 'int', 'size' => 'tiny', 'not null' => true, 'default' => 0, 'description' => 'Send replies from people not subscribed to'),
'updatefrompresence' => array('type' => 'int', 'size' => 'tiny', 'not null' => true, 'default' => 0, 'description' => 'Send replies from people not subscribed to.'),
'notify' => array('type' => 'bool', 'not null' => true, 'default' => false, 'description' => 'Notify when a new notice is sent'),
'replies' => array('type' => 'bool', 'not null' => true, 'default' => false, 'description' => 'Send replies from people not subscribed to'),
'updatefrompresence' => array('type' => 'bool', 'not null' => true, 'default' => false, 'description' => 'Update from presence.'),
'created' => array('type' => 'datetime', 'not null' => true, 'default' => '0000-00-00 00:00:00', 'description' => 'date this record was created'),
'modified' => array('type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'),
),
@ -69,5 +68,4 @@ class User_im_prefs extends Managed_DataObject
),
);
}
}

View File

@ -1,30 +1,27 @@
<?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 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
* @package GNUsocial
* @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/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
@ -36,7 +33,7 @@ class User_location_prefs extends Managed_DataObject
public $__table = 'user_location_prefs'; // table name
public $user_id; // int(4) primary_key not_null
public $share_location; // tinyint(1) default_1
public $share_location; // bool default_true
public $created; // datetime() not_null default_0000-00-00%2000%3A00%3A00
public $modified; // datetime() not_null default_CURRENT_TIMESTAMP
@ -48,7 +45,7 @@ class User_location_prefs extends Managed_DataObject
return array(
'fields' => array(
'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user who has the preference'),
'share_location' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'description' => 'Whether to share location data'),
'share_location' => array('type' => 'bool', 'default' => true, 'description' => 'Whether to share location data'),
'created' => array('type' => 'datetime', 'not null' => true, 'default' => '0000-00-00 00:00:00', 'description' => 'date this record was created'),
'modified' => array('type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'),
),

View File

@ -4,10 +4,6 @@
*
* Some notes...
*
* Drupal docs don't list a bool type, but it might be nice to use rather than 'tinyint'
* Note however that we use bitfields and things as well in tinyints, and PG's
* "bool" type isn't 100% compatible with 0/1 checks. Just keeping tinyints. :)
*
* decimal <-> numeric
*
* MySQL 'timestamp' columns were formerly used for 'modified' files for their

View File

@ -1787,12 +1787,27 @@ class DB_DataObject extends DB_DataObject_Overload
// note: we dont declare this to keep the print_r size down.
$_DB_DATAOBJECT['RESULTFIELDS'][$this->_DB_resultid] = array_flip(array_keys($array));
}
$dbtype = $_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5]->dsn['phptype'];
if ($dbtype === 'pgsql') {
if (($_DB_DATAOBJECT['CONFIG']['db_driver'] ?? 'DB') === 'DB') {
$tableInfo = $result->tableInfo();
} elseif ($result->db->supports('result_introspection')) { // MDB2
$result->db->loadModule('Reverse', null, true);
$tableInfo = $result->db->reverse->tableInfo($result);
}
}
$replace = array('.', ' ');
foreach ($array as $k => $v) {
foreach (array_keys($array) as $i => $k) {
// use strpos as str_replace is slow.
$kk = (strpos($k, '.') === false && strpos($k, ' ') === false) ?
$k : str_replace($replace, '_', $k);
if ($dbtype === 'pgsql' && $tableInfo[$i]['type'] == 'bool') {
$array[$k] = str_replace(['t', 'f'], ['1', '0'], $array[$k]);
}
if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) {
$this->debug("$kk = " . $array[$k], "fetchrow LINE", 3);
}
@ -2949,12 +2964,27 @@ class DB_DataObject extends DB_DataObject_Overload
$this->raiseError("fetchrow: No results available", DB_DATAOBJECT_ERROR_NODATA);
return false;
}
$dbtype = $_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5]->dsn['phptype'];
if ($dbtype === 'pgsql') {
if (($_DB_DATAOBJECT['CONFIG']['db_driver'] ?? 'DB') === 'DB') {
$tableInfo = $result->tableInfo();
} elseif ($result->db->supports('result_introspection')) { // MDB2
$result->db->loadModule('Reverse', null, true);
$tableInfo = $result->db->reverse->tableInfo($result);
}
}
$replace = array('.', ' ');
foreach ($array as $k => $v) {
foreach (array_keys($array) as $i => $k) {
// use strpos as str_replace is slow.
$kk = (strpos($k, '.') === false && strpos($k, ' ') === false) ?
$k : str_replace($replace, '_', $k);
if ($dbtype === 'pgsql' && $tableInfo[$i]['type'] == 'bool') {
$array[$k] = str_replace(['t', 'f'], ['1', '0'], $array[$k]);
}
if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) {
$this->debug("$kk = " . $array[$k], "fetchrow LINE", 3);
}

View File

@ -1,36 +1,31 @@
<?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
*
* Base class for all actions (~views)
*
* 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 Action
* @package StatusNet
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @author Sarven Capadisli <csarven@status.net>
* @copyright 2008 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();
/**
* Base class for all actions
@ -41,14 +36,11 @@ if (!defined('GNUSOCIAL')) {
* Actions are responsible for extracting and validating parameters; using
* model classes to read and write to the database; and doing ouput.
*
* @category Output
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @author Sarven Capadisli <csarven@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/
* @category Output
* @copyright 2008 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*
* @see HTMLOutputter
* @see HTMLOutputter
*/
class Action extends HTMLOutputter // lawsuit
{
@ -1566,19 +1558,6 @@ class Action extends HTMLOutputter // lawsuit
// needs to be defined by the class
}
/**
* This is a cheap hack to avoid a bug in DB_DataObject
* where '' is non-type-aware compared to 0, which means it
* will always be true for values like false and 0 too...
*
* Upstream bug is::
* https://pear.php.net/bugs/bug.php?id=20291
*/
public function booleanintstring($key, $def = false)
{
return $this->boolean($key, $def) ? '1' : '0';
}
/**
* Integer value of an argument
*

View File

@ -396,9 +396,9 @@ class MysqlSchema extends Schema
function mapType($column)
{
$map = [
'serial' => 'int',
'integer' => 'int',
'numeric' => 'decimal'
'bool' => 'tinyint',
'numeric' => 'decimal',
];
$type = $column['type'];

View File

@ -348,10 +348,11 @@ class PgsqlSchema extends Schema
public function mapType($column)
{
$map = [
'serial' => 'bigserial', // FIXME: creates the wrong name for the sequence for some internal sequence-lookup function, so better fix this to do the real 'create sequence' dance.
'numeric' => 'decimal',
'serial' => 'bigserial', // FIXME: creates the wrong name for the sequence for some internal sequence-lookup function, so better fix this to do the real 'create sequence' dance.
'bool' => 'boolean',
'numeric' => 'decimal',
'datetime' => 'timestamp',
'blob' => 'bytea'
'blob' => 'bytea',
];
$type = $column['type'];

View File

@ -434,11 +434,11 @@ function mail_broadcast_notice_sms($notice)
// Users (other than the sender) who `want SMS notices':
'WHERE %1$s.id <> %2$d ' .
'AND %1$s.smsemail IS NOT NULL ' .
'AND %1$s.smsnotify = 1 ' .
'AND %1$s.smsnotify = TRUE ' .
// ... where either the user _is_ subscribed to the sender
// (any of the "subscription" fields IS NOT NULL)
// and wants to get SMS for all of this scribe's notices...
'AND (subscription.sms = 1 ' .
'AND (subscription.sms = TRUE ' .
// ... or where the user was mentioned in
// or replied-to with the notice:
$repliesQry .

View File

@ -507,9 +507,9 @@ class FavoriteModule extends ActivityVerbHandlerModule
public function onStartEmailSaveForm(Action $action, Profile $scoped)
{
$emailfave = $action->booleanintstring('email-notify_fave');
$emailfave = $action->boolean('email-notify_fave');
try {
if ($emailfave == $scoped->getPref('email', 'notify_fave')) {
if ($emailfave == (bool) $scoped->getPref('email', 'notify_fave')) {
// No need to update setting
return true;
}

View File

@ -1,47 +1,38 @@
<?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
* Copyright (C) 2011, StatusNet, Inc.
*
* Score of a notice by activity spam service
*
* PHP version 5
*
* 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 Spam
* @package StatusNet
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('STATUSNET')) {
exit(1);
}
defined('GNUSOCIAL') || die();
/**
* Score of a notice per the activity spam service
*
* @category Spam
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
* @copyright 2011 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*
* @see DB_DataObject
* @see DB_DataObject
*/
class Spam_score extends Managed_DataObject
{
@ -54,7 +45,6 @@ class Spam_score extends Managed_DataObject
public static function save($notice, $result)
{
$orig = null;
$score = Spam_score::getKV('notice_id', $notice->id);
@ -98,7 +88,7 @@ class Spam_score extends Managed_DataObject
'description' => 'score for the notice (0.0, 1.0)'),
'scaled' => array('type' => 'int',
'description' => 'scaled score for the notice (0, 10000)'),
'is_spam' => array('type' => 'tinyint',
'is_spam' => array('type' => 'bool',
'description' => 'flag for spamosity'),
'created' => array('type' => 'datetime',
'not null' => true,
@ -146,7 +136,7 @@ class Spam_score extends Managed_DataObject
if ($score->find()) {
while ($score->fetch()) {
$orig = clone($score);
$score->is_spam = ($score->score >= 0.90) ? 1 : 0;
$score->is_spam = ($score->score >= 0.90) ? true : false;
$score->update($orig);
}
}
@ -169,9 +159,8 @@ class Spam_score extends Managed_DataObject
}
}
function saveNew($notice, $result)
public function saveNew($notice, $result)
{
$score = new Spam_score();
$score->notice_id = $notice->id;

View File

@ -1,52 +1,45 @@
<?php
/**
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2012, StatusNet, Inc.
*
* Spam notice stream
*
* PHP version 5
*
* 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 Spam
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2012 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
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/>.
/**
* Spam notice stream
*
* @category Spam
* @package StatusNet
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2012 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
defined('GNUSOCIAL') || die();
/**
* Spam notice stream
*
* @copyright 2012 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
*/
class SpamNoticeStream extends ScopingNoticeStream
{
function __construct(Profile $scoped=null)
public function __construct(Profile $scoped = null)
{
parent::__construct(new CachingNoticeStream(new RawSpamNoticeStream(), 'spam_score:notice_ids'),
$scoped);
parent::__construct(
new CachingNoticeStream(new RawSpamNoticeStream(), 'spam_score:notice_ids'),
$scoped
);
}
}
@ -54,20 +47,16 @@ class SpamNoticeStream extends ScopingNoticeStream
* Raw stream of spammy notices
*
* @category Stream
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
class RawSpamNoticeStream extends NoticeStream
{
function getNoticeIds($offset, $limit, $since_id, $max_id)
public function getNoticeIds($offset, $limit, $since_id, $max_id)
{
$ss = new Spam_score();
$ss->is_spam = 1;
$ss->is_spam = true;
$ss->selectAdd();
$ss->selectAdd('notice_id');

View File

@ -1,20 +1,22 @@
<?php
/*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2013 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/>.
// 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/>.
/**
* @copyright 2013 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
@ -33,13 +35,13 @@ END_OF_SILENCESPAMMER_HELP;
require_once INSTALLDIR.'/scripts/commandline.inc';
function testAllUsers($filter, $minimum, $percent) {
function testAllUsers($filter, $minimum, $percent)
{
$found = false;
$offset = 0;
$limit = 1000;
do {
$user = new User();
$user->orderBy('created');
$user->limit($offset, $limit);
@ -56,37 +58,36 @@ function testAllUsers($filter, $minimum, $percent) {
}
$offset += $found;
}
} while ($found > 0);
}
function silencespammer($filter, $user, $minimum, $percent) {
function silencespammer($filter, $user, $minimum, $percent)
{
printfnq("Testing user %s\n", $user->nickname);
$profile = Profile::getKV('id', $user->id);
if ($profile->isSilenced()) {
printfnq("Already silenced %s\n", $user->nickname);
return;
printfnq("Already silenced %s\n", $user->nickname);
return;
}
$cnt = $profile->noticeCount();
if ($cnt < $minimum) {
printfnq("Only %d notices posted (minimum %d); skipping\n", $cnt, $minimum);
return;
return;
}
$ss = new Spam_score();
$ss->query(sprintf("SELECT count(*) as spam_count ".
"FROM notice join spam_score on notice.id = spam_score.notice_id ".
"WHERE notice.profile_id = %d AND spam_score.is_spam = 1", $profile->id));
'WHERE notice.profile_id = %d AND spam_score.is_spam = TRUE', $profile->id));
while ($ss->fetch()) {
$spam_count = $ss->spam_count;
}
}
$spam_percent = ($spam_count * 100.0 / $cnt);
@ -94,10 +95,10 @@ function silencespammer($filter, $user, $minimum, $percent) {
printfnq("Silencing user %s (%d/%d = %0.2f%% spam)\n", $user->nickname, $spam_count, $cnt, $spam_percent);
try {
$profile->silence();
} catch(Exception $e) {
} catch (Exception $e) {
printfnq("Error: %s", $e->getMessage());
}
}
}
}
}
try {

View File

@ -1,35 +1,30 @@
<?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/>.
/**
* Data class for email summary status
*
* PHP version 5
*
* @category Data
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 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/>.
* @category Data
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2010, StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('STATUSNET')) {
exit(1);
}
defined('GNUSOCIAL') || die();
require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
@ -38,19 +33,17 @@ require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
*
* Email summary information for users
*
* @category Action
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
* @category Action
* @copyright 2010, StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*
* @see DB_DataObject
* @see DB_DataObject
*/
class Email_summary_status extends Managed_DataObject
{
public $__table = 'email_summary_status'; // table name
public $user_id; // int(4) primary_key not_null
public $send_summary; // tinyint not_null
public $send_summary; // bool not_null default_true
public $last_summary_id; // int(4) null
public $created; // datetime not_null
public $modified; // datetime not_null
@ -60,9 +53,9 @@ class Email_summary_status extends Managed_DataObject
return array(
'fields' => array(
'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user id'),
'send_summary' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'not null' => true, 'description' => 'whether to send a summary or not'),
'send_summary' => array('type' => 'bool', 'default' => true, 'not null' => true, 'description' => 'whether to send a summary or not'),
'last_summary_id' => array('type' => 'int', 'description' => 'last summary id'),
'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
),
'primary key' => array('user_id'),
@ -79,7 +72,7 @@ class Email_summary_status extends Managed_DataObject
*
* @return int flag for whether to send this user a summary email
*/
static function getSendSummary($user_id)
public static function getSendSummary($user_id)
{
$ess = Email_summary_status::getKV('user_id', $user_id);
@ -97,7 +90,7 @@ class Email_summary_status extends Managed_DataObject
*
* @return Email_summary_status instance for this user, with count already incremented.
*/
static function getLastSummaryID($user_id)
public static function getLastSummaryID($user_id)
{
$ess = Email_summary_status::getKV('user_id', $user_id);

View File

@ -1,35 +1,30 @@
<?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/>.
/**
* Data class for counting greetings
*
* PHP version 5
*
* @category Data
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2009, 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/>.
* @category Data
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2009, StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('STATUSNET')) {
exit(1);
}
defined('GNUSOCIAL') || die();
require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
@ -44,19 +39,17 @@ require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
* extension of DB_DataObject that provides caching, internationalization,
* and other bits of good functionality to StatusNet-specific data classes.
*
* @category Action
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
* @category Action
* @copyright 2009, StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*
* @see DB_DataObject
* @see DB_DataObject
*/
class User_followeveryone_prefs extends Managed_DataObject
{
public $__table = 'user_followeveryone_prefs'; // table name
public $user_id; // int(4) primary_key not_null
public $followeveryone; // tinyint(1)
public $followeveryone; // bool default_true
public $created; // datetime() not_null
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
@ -65,7 +58,7 @@ class User_followeveryone_prefs extends Managed_DataObject
return array(
'fields' => array(
'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user id'),
'followeveryone' => array('type' => 'int', 'default' => 1, 'size' => 'tiny', 'description' => 'whether to follow everyone'),
'followeveryone' => array('type' => 'bool', 'default' => true, 'description' => 'whether to follow everyone'),
'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
),
@ -76,7 +69,7 @@ class User_followeveryone_prefs extends Managed_DataObject
);
}
static function followEveryone($user_id)
public static function followEveryone($user_id)
{
$ufep = self::getKV('user_id', $user_id);
@ -87,7 +80,7 @@ class User_followeveryone_prefs extends Managed_DataObject
}
}
static function savePref($user_id, $followEveryone)
public static function savePref($user_id, $followEveryone)
{
$ufep = self::getKV('user_id', $user_id);

View File

@ -1,52 +1,37 @@
<?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
* Copyright (C) 2012, StatusNet, Inc.
*
* ModLogPlugin.php
*
* PHP version 5
*
* 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 Moderation
* @package StatusNet
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2012 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('STATUSNET')) {
// This check helps protect against security problems;
// your code file can't be executed directly from the web.
exit(1);
}
defined('GNUSOCIAL') || die();
/**
* Moderation logging
*
* Shows a history of moderation for this user in the sidebar
*
* @category Moderation
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2012 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class ModLogPlugin extends Plugin
{
const PLUGIN_VERSION = '2.0.0';
@ -63,7 +48,7 @@ class ModLogPlugin extends Plugin
* @return boolean hook value; true means continue processing, false means stop.
*/
function onCheckSchema()
public function onCheckSchema()
{
$schema = Schema::get();
@ -72,7 +57,7 @@ class ModLogPlugin extends Plugin
return true;
}
function onEndGrantRole($profile, $role)
public function onEndGrantRole($profile, $role)
{
$modlog = new ModLog();
@ -86,7 +71,7 @@ class ModLogPlugin extends Plugin
}
$modlog->role = $role;
$modlog->is_grant = 1;
$modlog->is_grant = true;
$modlog->created = common_sql_now();
$modlog->insert();
@ -94,7 +79,7 @@ class ModLogPlugin extends Plugin
return true;
}
function onEndRevokeRole($profile, $role)
public function onEndRevokeRole($profile, $role)
{
$modlog = new ModLog();
@ -109,7 +94,7 @@ class ModLogPlugin extends Plugin
}
$modlog->role = $role;
$modlog->is_grant = 0;
$modlog->is_grant = false;
$modlog->created = common_sql_now();
$modlog->insert();
@ -117,7 +102,7 @@ class ModLogPlugin extends Plugin
return true;
}
function onEndShowSections(Action $action)
public function onEndShowSections(Action $action)
{
if (!$action instanceof ShowstreamAction) {
// early return for actions we're not interested in
@ -140,7 +125,6 @@ class ModLogPlugin extends Plugin
$cnt = $ml->find();
if ($cnt > 0) {
$action->elementStart('div', array('id' => 'entity_mod_log',
'class' => 'section'));
@ -158,9 +142,14 @@ class ModLogPlugin extends Plugin
if (empty($mod)) {
$action->text(_('[unknown]'));
} else {
$action->element('a', array('href' => $mod->getUrl(),
'title' => $mod->getFullname()),
$mod->getNickname());
$action->element(
'a',
[
'href' => $mod->getUrl(),
'title' => $mod->getFullname(),
],
$mod->getNickname()
);
}
} else {
$action->text(_('[unknown]'));
@ -175,7 +164,8 @@ class ModLogPlugin extends Plugin
}
}
function onUserRightsCheck($profile, $right, &$result) {
public function onUserRightsCheck($profile, $right, &$result)
{
switch ($right) {
case self::VIEWMODLOG:
$result = ($profile->hasRole(Profile_role::MODERATOR) || $profile->hasRole('modhelper'));

View File

@ -1,49 +1,37 @@
<?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
* Copyright (C) 2012, StatusNet, Inc.
*
* ModLog.php -- data object to store moderation logs
*
* PHP version 5
*
* 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/>.
* Data object to store moderation logs
*
* @category Moderation
* @package StatusNet
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2012 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('STATUSNET')) {
exit(1);
}
defined('GNUSOCIAL') || die();
/**
* Class comment here
* @copyright 2012 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*
* @category Category here
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
*
* @see DB_DataObject
* @see DB_DataObject
*/
class ModLog extends Managed_DataObject
{
public $__table = 'mod_log'; // table name
@ -52,7 +40,7 @@ class ModLog extends Managed_DataObject
public $profile_id; // profile id
public $moderator_id; // profile id
public $role; // the role
public $grant; // 1 = grant, 0 = revoke
public $is_grant; // true = grant, false = revoke
public $created; // datetime
/**
@ -75,9 +63,8 @@ class ModLog extends Managed_DataObject
'length' => 32,
'not null' => true,
'description' => 'role granted or revoked'),
'is_grant' => array('type' => 'int',
'size' => 'tiny',
'default' => 1,
'is_grant' => array('type' => 'bool',
'default' => true,
'description' => 'Was this a grant or revocation of a role'),
'created' => array('type' => 'datetime',
'not null' => true,

View File

@ -1,35 +1,30 @@
<?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 OpenID
*
* 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>
* @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();
require_once INSTALLDIR.'/plugins/OpenID/openid.php';
@ -38,11 +33,8 @@ require_once INSTALLDIR.'/plugins/OpenID/openid.php';
*
* Lets users add, edit and delete OpenIDs from their account
*
* @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
*/
class OpenidsettingsAction extends SettingsAction
{
@ -100,17 +92,26 @@ class OpenidsettingsAction extends SettingsAction
$this->elementStart('ul', 'form_data');
$this->elementStart('li');
// TRANS: Field label.
$this->input('openid_url', _m('OpenID URL'), null,
// TRANS: Form guide.
_m('An OpenID URL which identifies you.'),
null, true,
['placeholder'=>'https://example.com/you']);
$this->input(
'openid_url',
_m('OpenID URL'),
null,
// TRANS: Form guide.
_m('An OpenID URL which identifies you.'),
null,
true,
['placeholder' => 'https://example.com/you']
);
$this->elementEnd('li');
$this->elementStart('li');
// TRANS: Field label.
$this->checkbox('openid-synch', _m('Synchronize Account'), false,
// TRANS: Form guide.
_m('Synchronize GNU social profile with this OpenID identity.'));
$this->checkbox(
'openid-synch',
_m('Synchronize Account'),
false,
// TRANS: Form guide.
_m('Synchronize GNU social profile with this OpenID identity.')
);
$this->elementEnd('li');
$this->elementEnd('ul');
// TRANS: Button text for adding an OpenID URL.
@ -129,13 +130,16 @@ class OpenidsettingsAction extends SettingsAction
$this->element('h2', null, _m('HEADER', 'OpenID Actions'));
if ($cnt == 1 && !$this->scoped->hasPassword()) {
$this->element('p', 'form_guide',
// TRANS: Form guide.
_m('You can\'t remove your main OpenID account ' .
'without either adding a password to your ' .
'GNU social account or another OpenID account. ' .
'You can synchronize your profile with your ' .
'OpenID by clicking the button labeled "Synchronize".'));
$this->element(
'p',
'form_guide',
// TRANS: Form guide.
_m('You can\'t remove your main OpenID account ' .
'without either adding a password to your ' .
'GNU social account or another OpenID account. ' .
'You can synchronize your profile with your ' .
'OpenID by clicking the button labeled "Synchronize".')
);
if ($oid->fetch()) {
$this->elementStart('form', ['method' => 'POST',
@ -152,12 +156,15 @@ class OpenidsettingsAction extends SettingsAction
$this->elementEnd('form');
}
} else {
$this->element('p', 'form_guide',
// TRANS: Form guide.
_m('You can remove an OpenID from your account ' .
'by clicking the button labeled "Remove". ' .
'You can synchronize your profile with an OpenID ' .
'by clicking the button labeled "Synchronize".'));
$this->element(
'p',
'form_guide',
// TRANS: Form guide.
_m('You can remove an OpenID from your account ' .
'by clicking the button labeled "Remove". ' .
'You can synchronize your profile with an OpenID ' .
'by clicking the button labeled "Synchronize".')
);
$idx = 0;
while ($oid->fetch()) {
@ -191,26 +198,38 @@ class OpenidsettingsAction extends SettingsAction
// TRANS: Fieldset legend.
$this->element('legend', null, _m('OpenID Trusted Sites'));
$this->hidden('token', common_session_token());
$this->element('p', 'form_guide',
// TRANS: Form guide.
_m('The following sites are allowed to access your ' .
'identity and log you in. You can remove a site from ' .
'this list to deny it access to your OpenID.'));
$this->element(
'p',
'form_guide',
// TRANS: Form guide.
_m('The following sites are allowed to access your ' .
'identity and log you in. You can remove a site from ' .
'this list to deny it access to your OpenID.')
);
$this->elementStart('ul', 'form_data');
$user_openid_trustroot = new User_openid_trustroot();
$user_openid_trustroot->user_id = $this->scoped->getID();
if ($user_openid_trustroot->find()) {
while ($user_openid_trustroot->fetch()) {
$this->elementStart('li');
$this->element('input', ['name' => 'openid_trustroot[]',
'type' => 'checkbox',
'class' => 'checkbox',
'value' => $user_openid_trustroot->trustroot,
'id' => 'openid_trustroot_' . crc32($user_openid_trustroot->trustroot)]);
$this->element('label',
['class'=>'checkbox',
'for' => 'openid_trustroot_' . crc32($user_openid_trustroot->trustroot)],
$user_openid_trustroot->trustroot);
$this->element(
'input',
[
'name' => 'openid_trustroot[]',
'type' => 'checkbox',
'class' => 'checkbox',
'value' => $user_openid_trustroot->trustroot,
'id' => 'openid_trustroot_' . crc32($user_openid_trustroot->trustroot),
]
);
$this->element(
'label',
[
'class'=>'checkbox',
'for' => 'openid_trustroot_' . crc32($user_openid_trustroot->trustroot),
],
$user_openid_trustroot->trustroot
);
$this->elementEnd('li');
}
}
@ -363,7 +382,7 @@ class OpenidsettingsAction extends SettingsAction
$orig = clone($prefs);
}
$prefs->hide_profile_link = $this->booleanintstring('hide_profile_link');
$prefs->hide_profile_link = $this->boolean('hide_profile_link');
if ($orig instanceof User_openid_prefs) {
$prefs->update($orig);

View File

@ -1,44 +1,37 @@
<?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/>.
/**
* Data class to record user prefs for polls
*
* PHP version 5
*
* @category PollPlugin
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2012, 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/>.
* @category PollPlugin
* @package GNUsocial
* @author Brion Vibber <brion@status.net>
* @author Evan Prodromou <evan@status.net>
* @copyright 2012, StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('STATUSNET')) {
exit(1);
}
defined('GNUSOCIAL') || die();
/**
* For storing the poll prefs
*
* @category PollPlugin
* @package StatusNet
* @author Brion Vibber <brion@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
* @copyright 2012, StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*
* @see DB_DataObject
*/
@ -46,7 +39,7 @@ class User_poll_prefs extends Managed_DataObject
{
public $__table = 'user_poll_prefs'; // table name
public $user_id; // int id
public $hide_responses; // boolean
public $hide_responses; // bool
public $created; // datetime
public $modified; // datetime
@ -59,7 +52,7 @@ class User_poll_prefs extends Managed_DataObject
'description' => 'Record of user preferences for polls',
'fields' => array(
'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user id'),
'hide_responses' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'Hide all poll responses'),
'hide_responses' => array('type' => 'bool', 'default' => false, 'description' => 'Hide all poll responses'),
'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
),

View File

@ -1,47 +1,36 @@
<?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
* Copyright (C) 2011, StatusNet, Inc.
*
* Close a question to further answers
*
* PHP version 5
*
* 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 QnA
* @package StatusNet
* @package GNUsocial
* @author Zach Copley <zach@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or late
*/
if (!defined('STATUSNET')) {
// This check helps protect against security problems;
// your code file can't be executed directly from the web.
exit(1);
}
defined('GNUSOCIAL') || die();
/**
* Close a question to new answers
*
* @category QnA
* @package StatusNet
* @author Zach Copley <zach@status.net>
* @copyright 2010 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or late
*/
class QnaclosequestionAction extends Action
{
@ -57,7 +46,7 @@ class QnaclosequestionAction extends Action
*
* @return string Action title
*/
function title()
public function title()
{
// TRANS: Page title for close a question
return _m('Close question');
@ -71,7 +60,7 @@ class QnaclosequestionAction extends Action
* @return boolean true
* @throws ClientException
*/
function prepare(array $args = [])
public function prepare(array $args = [])
{
parent::prepare($args);
if ($this->boolean('ajax')) {
@ -107,7 +96,7 @@ class QnaclosequestionAction extends Action
*
* @return void
*/
function handle()
public function handle()
{
parent::handle();
@ -125,7 +114,7 @@ class QnaclosequestionAction extends Action
*
* @return void
*/
function closeQuestion()
public function closeQuestion()
{
$user = common_current_user();
@ -136,9 +125,8 @@ class QnaclosequestionAction extends Action
}
$orig = clone($this->question);
$this->question->closed = 1;
$this->question->closed = true;
$this->question->update($orig);
} catch (ClientException $ce) {
$this->error = $ce->getMessage();
$this->showPage();
@ -166,7 +154,7 @@ class QnaclosequestionAction extends Action
*
* @return void
*/
function showContent()
public function showContent()
{
if (!empty($this->error)) {
$this->element('p', 'error', $this->error);
@ -184,7 +172,7 @@ class QnaclosequestionAction extends Action
*
* @return boolean is read only action?
*/
function isReadOnly($args)
public function isReadOnly($args)
{
if ($_SERVER['REQUEST_METHOD'] == 'GET' ||
$_SERVER['REQUEST_METHOD'] == 'HEAD') {

View File

@ -1,47 +1,36 @@
<?php
/**
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2011, StatusNet, Inc.
*
* Revise an answer
*
* PHP version 5
*
* 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 QnA
* @package StatusNet
* @author Zach Copley <zach@status.net>
* @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
if (!defined('STATUSNET')) {
// This check helps protect against security problems;
// your code file can't be executed directly from the web.
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/>.
/**
* Revise an answer
*
* @category QnA
* @package StatusNet
* @package GNUsocial
* @author Zach Copley <zach@status.net>
* @copyright 2011 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
defined('GNUSOCIAL') || die();
/**
* Revise an answer
*
* @copyright 2010 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class QnareviseanswerAction extends Action
{
@ -56,7 +45,7 @@ class QnareviseanswerAction extends Action
*
* @return string Action title
*/
function title()
public function title()
{
// TRANS: Page title for revising a question
return _m('Revise answer');
@ -70,7 +59,7 @@ class QnareviseanswerAction extends Action
* @return boolean true
* @throws ClientException
*/
function prepare(array $args = [])
public function prepare(array $args = [])
{
parent::prepare($args);
if ($this->boolean('ajax')) {
@ -110,7 +99,7 @@ class QnareviseanswerAction extends Action
*
* @return void
*/
function handle()
public function handle()
{
parent::handle();
@ -119,7 +108,7 @@ class QnareviseanswerAction extends Action
if ($this->arg('revise')) {
$this->showContent();
return;
} else if ($this->arg('best')) {
} elseif ($this->arg('best')) {
if ($this->user->id == $this->question->profile_id) {
$this->markBest();
return;
@ -138,7 +127,7 @@ class QnareviseanswerAction extends Action
*
* @return void
*/
function showContent()
public function showContent()
{
if (!empty($this->error)) {
$this->element('p', 'error', $this->error);
@ -154,7 +143,7 @@ class QnareviseanswerAction extends Action
return;
}
function showAjaxReviseForm()
public function showAjaxReviseForm()
{
$this->startHTML('text/xml;charset=utf-8');
$this->elementStart('head');
@ -173,7 +162,7 @@ class QnareviseanswerAction extends Action
*
* @return void
*/
function markBest()
public function markBest()
{
$question = $this->question;
$answer = $this->answer;
@ -181,12 +170,12 @@ class QnareviseanswerAction extends Action
try {
// close the question to further answers
$orig = clone($question);
$question->closed = 1;
$question->closed = true;
$result = $question->update($orig);
// mark this answer an the best answer
$orig = clone($answer);
$answer->best = 1;
$answer->best = true;
$result = $answer->update($orig);
} catch (ClientException $ce) {
$this->error = $ce->getMessage();
@ -215,7 +204,7 @@ class QnareviseanswerAction extends Action
*
* @return void
*/
function reviseAnswer()
public function reviseAnswer()
{
$answer = $this->answer;
@ -255,7 +244,7 @@ class QnareviseanswerAction extends Action
*
* @return boolean is read only action?
*/
function isReadOnly($args)
public function isReadOnly($args)
{
if ($_SERVER['REQUEST_METHOD'] == 'GET' ||
$_SERVER['REQUEST_METHOD'] == 'HEAD') {

View File

@ -1,46 +1,38 @@
<?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/>.
/**
* Data class to save answers to questions
*
* PHP version 5
*
* @category QnA
* @package StatusNet
* @author Zach Copley <zach@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2011, 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/>.
* @category QnA
* @package GNUsocial
* @author Zach Copley <zach@status.net>
* @copyright 2011 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('STATUSNET')) {
exit(1);
}
defined('STATUSNET') || die();
/**
* For storing answers
*
* @category QnA
* @package StatusNet
* @author Zach Copley <zach@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
* @copyright 2011 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*
* @see DB_DataObject
* @see DB_DataObject
*/
class QnA_Answer extends Managed_DataObject
{
@ -51,7 +43,7 @@ class QnA_Answer extends Managed_DataObject
public $uri; // varchar(191) not 255 because utf8mb4 takes more space
public $question_id; // char(36) -> question.id UUID
public $profile_id; // int -> question.id
public $best; // (boolean) int -> whether the question asker has marked this as the best answer
public $best; // bool -> whether the question asker has marked this as the best answer
public $revisions; // int -> count of revisions to this answer
public $content; // text -> response text
public $created; // datetime
@ -82,7 +74,7 @@ class QnA_Answer extends Managed_DataObject
'description' => 'UUID of question being responded to',
),
'content' => array('type' => 'text'), // got a better name?
'best' => array('type' => 'int', 'size' => 'tiny'),
'best' => array('type' => 'bool'),
'revisions' => array('type' => 'int'),
'profile_id' => array('type' => 'int'),
'created' => array('type' => 'datetime', 'not null' => true),
@ -105,7 +97,7 @@ class QnA_Answer extends Managed_DataObject
*
* @return QnA_Answer found response or null
*/
static function getByNotice($notice)
public static function getByNotice($notice)
{
$answer = self::getKV('uri', $notice->uri);
if (empty($answer)) {
@ -119,17 +111,17 @@ class QnA_Answer extends Managed_DataObject
*
* @return Notice
*/
function getNotice()
public function getNotice()
{
return Notice::getKV('uri', $this->uri);
}
static function fromNotice($notice)
public static function fromNotice($notice)
{
return QnA_Answer::getKV('uri', $notice->uri);
}
function getUrl()
public function getUrl()
{
return $this->getNotice()->getUrl();
}
@ -139,29 +131,29 @@ class QnA_Answer extends Managed_DataObject
*
* @return QnA_Question
*/
function getQuestion()
public function getQuestion()
{
$question = QnA_Question::getKV('id', $this->question_id);
if (empty($question)) {
// TRANS: Exception thown when getting a question with a non-existing ID.
// TRANS: %s is the non-existing question ID.
throw new Exception(sprintf(_m('No question with ID %s'),$this->question_id));
throw new Exception(sprintf(_m('No question with ID %s'), $this->question_id));
}
return $question;
}
function getProfile()
public function getProfile()
{
$profile = Profile::getKV('id', $this->profile_id);
if (empty($profile)) {
// TRANS: Exception thown when getting a profile with a non-existing ID.
// TRANS: %s is the non-existing profile ID.
throw new Exception(sprintf(_m('No profile with ID %s'),$this->profile_id));
throw new Exception(sprintf(_m('No profile with ID %s'), $this->profile_id));
}
return $profile;
}
function asHTML()
public function asHTML()
{
return self::toHTML(
$this->getProfile(),
@ -170,7 +162,7 @@ class QnA_Answer extends Managed_DataObject
);
}
function asString()
public function asString()
{
return self::toString(
$this->getProfile(),
@ -179,7 +171,7 @@ class QnA_Answer extends Managed_DataObject
);
}
static function toHTML($profile, $question, $answer)
public static function toHTML($profile, $question, $answer)
{
$notice = $question->getNotice();
@ -201,7 +193,7 @@ class QnA_Answer extends Managed_DataObject
htmlspecialchars(
// Notification of how often an answer was revised.
// TRANS: %s is the number of answer revisions.
sprintf(_m('%s revision','%s revisions',$answer->revisions), $answer->revisions)
sprintf(_m('%s revision', '%s revisions', $answer->revisions), $answer->revisions)
)
);
$out->elementEnd('span');
@ -212,7 +204,7 @@ class QnA_Answer extends Managed_DataObject
return $out->getString();
}
static function toString($profile, $question, $answer)
public static function toString($profile, $question, $answer)
{
// @todo FIXME: unused variable?
$notice = $question->getNotice();
@ -237,7 +229,7 @@ class QnA_Answer extends Managed_DataObject
*
* @return Notice saved notice
*/
static function saveNew($profile, $question, $text, $options = null)
public static function saveNew($profile, $question, $text, $options = null)
{
if (empty($options)) {
$options = array();
@ -248,7 +240,7 @@ class QnA_Answer extends Managed_DataObject
$answer->profile_id = $profile->id;
$answer->question_id = $question->id;
$answer->revisions = 0;
$answer->best = 0;
$answer->best = false;
$answer->content = $text;
$answer->created = common_sql_now();
$answer->uri = common_local_url(

View File

@ -1,46 +1,38 @@
<?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/>.
/**
* Data class to mark a notice as a question
*
* PHP version 5
*
* @category QnA
* @package StatusNet
* @author Zach Copley <zach@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2011, 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/>.
* @category QnA
* @package GNUsocial
* @author Zach Copley <zach@status.net>
* @copyright 2011 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('STATUSNET')) {
exit(1);
}
defined('GNUSOCIAL') || die();
/**
* For storing a question
*
* @category QnA
* @package StatusNet
* @author Zach Copley <zach@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
* @copyright 2011 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*
* @see DB_DataObject
* @see DB_DataObject
*/
class QnA_Question extends Managed_DataObject
{
@ -52,7 +44,7 @@ class QnA_Question extends Managed_DataObject
public $profile_id; // int -> profile.id
public $title; // text
public $description; // text
public $closed; // int (boolean) whether a question is closed
public $closed; // bool -> whether a question is closed
public $created; // datetime
/**
@ -76,7 +68,7 @@ class QnA_Question extends Managed_DataObject
),
'profile_id' => array('type' => 'int'),
'title' => array('type' => 'text'),
'closed' => array('type' => 'int', 'size' => 'tiny'),
'closed' => array('type' => 'bool'),
'description' => array('type' => 'text'),
'created' => array(
'type' => 'datetime',
@ -97,28 +89,28 @@ class QnA_Question extends Managed_DataObject
*
* @return Question found question or null
*/
static function getByNotice($notice)
public static function getByNotice($notice)
{
return self::getKV('uri', $notice->uri);
}
function getNotice()
public function getNotice()
{
return Notice::getKV('uri', $this->uri);
}
function getUrl()
public function getUrl()
{
return $this->getNotice()->getUrl();
}
function getProfile()
public function getProfile()
{
$profile = Profile::getKV('id', $this->profile_id);
if (empty($profile)) {
// TRANS: Exception trown when getting a profile for a non-existing ID.
// TRANS: %s is the provided profile ID.
throw new Exception(sprintf(_m('No profile with ID %s'),$this->profile_id));
throw new Exception(sprintf(_m('No profile with ID %s'), $this->profile_id));
}
return $profile;
}
@ -130,7 +122,7 @@ class QnA_Question extends Managed_DataObject
*
* @return Answer object or null
*/
function getAnswer(Profile $profile)
public function getAnswer(Profile $profile)
{
$a = new QnA_Answer();
$a->question_id = $this->id;
@ -143,7 +135,7 @@ class QnA_Question extends Managed_DataObject
}
}
function getAnswers()
public function getAnswers()
{
$a = new QnA_Answer();
$a->question_id = $this->id;
@ -155,7 +147,7 @@ class QnA_Question extends Managed_DataObject
}
}
function countAnswers()
public function countAnswers()
{
$a = new QnA_Answer();
@ -164,22 +156,22 @@ class QnA_Question extends Managed_DataObject
return $a->count();
}
static function fromNotice($notice)
public static function fromNotice($notice)
{
return QnA_Question::getKV('uri', $notice->uri);
}
function asHTML()
public function asHTML()
{
return self::toHTML($this->getProfile(), $this);
}
function asString()
public function asString()
{
return self::toString($this->getProfile(), $this);
}
static function toHTML($profile, $question)
public static function toHTML($profile, $question)
{
$notice = $question->getNotice();
@ -205,7 +197,7 @@ class QnA_Question extends Managed_DataObject
$out->elementStart('span', 'answer-count');
// TRANS: Number of given answers to a question.
// TRANS: %s is the number of given answers.
$out->text(sprintf(_m('%s answer','%s answers',$cnt), $cnt));
$out->text(sprintf(_m('%s answer', '%s answers', $cnt), $cnt));
$out->elementEnd('span');
}
@ -221,7 +213,7 @@ class QnA_Question extends Managed_DataObject
return $out->getString();
}
static function toString($profile, $question, $answers)
public static function toString($profile, $question, $answers)
{
return sprintf(htmlspecialchars($question->description));
}
@ -237,7 +229,7 @@ class QnA_Question extends Managed_DataObject
*
* @return Notice saved notice
*/
static function saveNew($profile, $title, $description, $options = array())
public static function saveNew($profile, $title, $description, $options = [])
{
$q = new QnA_Question();

View File

@ -1,51 +1,72 @@
<?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/>.
if (!defined('GNUSOCIAL')) { exit(1); }
defined('GNUSOCIAL') || die();
class SensitiveContentSettingsAction extends SettingsAction
{
function title()
{
return _m('Sensitive content settings');
}
public function title()
{
return _m('Sensitive content settings');
}
function getInstructions()
{
return _m('Set preferences for display of "sensitive" content');
}
public function getInstructions()
{
return _m('Set preferences for display of "sensitive" content');
}
function showContent()
{
public function showContent()
{
$user = $this->scoped->getUser();
$user = $this->scoped->getUser();
$this->elementStart(
'form',
[
'method' => 'post',
'id' => 'sensitivecontent',
'class' => 'form_settings',
'action' => common_local_url('sensitivecontentsettings'),
]
);
$this->elementStart('form', array('method' => 'post',
'id' => 'sensitivecontent',
'class' => 'form_settings',
'action' => common_local_url('sensitivecontentsettings')));
$this->elementStart('fieldset');
$this->hidden('token', common_session_token());
$this->elementStart('ul', 'form_data');
$this->elementStart('fieldset');
$this->hidden('token', common_session_token());
$this->elementStart('ul', 'form_data');
$this->elementStart('li');
$this->checkbox('hidesensitive', _('Hide attachments in posts hashtagged #NSFW'),
($this->arg('hidesensitive')) ?
$this->boolean('hidesensitive') : $this->scoped->getPref('MoonMan','hide_sensitive',0));
$this->elementEnd('li');
$this->elementStart('li');
$this->checkbox(
'hidesensitive',
_('Hide attachments in posts hashtagged #NSFW'),
($this->arg('hidesensitive') ?
$this->boolean('hidesensitive') : $this->scoped->getPref('MoonMan', 'hide_sensitive', 0))
);
$this->elementEnd('li');
$this->elementEnd('ul');
$this->submit('save', _m('BUTTON','Save'));
$this->elementEnd('ul');
$this->submit('save', _m('BUTTON', 'Save'));
$this->elementEnd('fieldset');
$this->elementEnd('form');
}
$this->elementEnd('fieldset');
$this->elementEnd('form');
}
function doPost()
{
$hidesensitive = $this->booleanintstring('hidesensitive');
$this->scoped->setPref('MoonMan','hide_sensitive', $hidesensitive);
return _('Settings saved.');
}
public function doPost()
{
$hidesensitive = $this->boolean('hidesensitive') ? '1' : '0';
$this->scoped->setPref('MoonMan', 'hide_sensitive', $hidesensitive);
return _('Settings saved.');
}
}

View File

@ -1,35 +1,30 @@
<?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
*
* 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 Plugin
* @package StatusNet
* @package GNUsocial
* @author Zach Copley <zach@status.net>
* @author Julien C <chaumond@gmail.com>
* @author Brion Vibber <brion@status.net>
* @copyright 2009-2010 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('STATUSNET')) {
exit(1);
}
defined('GNUSOCIAL') || die();
require_once dirname(__DIR__) . '/twitter.php';
@ -38,14 +33,8 @@ require_once dirname(__DIR__) . '/twitter.php';
* Is used by both the polling twitterstatusfetcher.php daemon, and the
* in-progress streaming import.
*
* @category Plugin
* @package StatusNet
* @author Zach Copley <zach@status.net>
* @author Julien C <chaumond@gmail.com>
* @author Brion Vibber <brion@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/
* @link http://twitter.com/
* @copyright 2009-2010 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class TwitterImport
{
@ -74,12 +63,12 @@ class TwitterImport
return $notice;
}
function name()
public function name()
{
return get_class($this);
}
function saveStatus($status)
public function saveStatus($status)
{
$profile = $this->ensureProfile($status->user);
@ -103,7 +92,7 @@ class TwitterImport
}
$dupe = Notice::getKV('uri', $statusUri);
if($dupe instanceof Notice) {
if ($dupe instanceof Notice) {
// Add it to our record
Notice_to_status::saveNew($dupe->id, $statusId);
common_log(
@ -123,24 +112,29 @@ class TwitterImport
$author = $original->getProfile();
// TRANS: Message used to repeat a notice. RT is the abbreviation of 'retweet'.
// TRANS: %1$s is the repeated user's name, %2$s is the repeated notice.
$content = sprintf(_m('RT @%1$s %2$s'),
$author->nickname,
$original->content);
$content = sprintf(
_m('RT @%1$s %2$s'),
$author->nickname,
$original->content
);
if (Notice::contentTooLong($content)) {
$contentlimit = Notice::maxContent();
$content = mb_substr($content, 0, $contentlimit - 4) . ' ...';
}
$repeat = Notice::saveNew($profile->id,
$content,
'twitter',
array('repeat_of' => $original->id,
'uri' => $statusUri,
'is_local' => Notice::GATEWAY,
'object_type' => ActivityObject::NOTE,
'verb' => ActivityVerb::POST
));
$repeat = Notice::saveNew(
$profile->id,
$content,
'twitter',
[
'repeat_of' => $original->id,
'uri' => $statusUri,
'is_local' => Notice::GATEWAY,
'object_type' => ActivityObject::NOTE,
'verb' => ActivityVerb::POST,
]
);
common_log(LOG_INFO, "Saved {$repeat->id} as a repeat of {$original->id}");
Notice_to_status::saveNew($repeat->id, $statusId);
return $repeat;
@ -183,11 +177,10 @@ class TwitterImport
$notice->is_local = Notice::GATEWAY;
$notice->content = html_entity_decode($this->linkify($status, FALSE), ENT_QUOTES, 'UTF-8');
$notice->rendered = $this->linkify($status, TRUE);
$notice->content = html_entity_decode($this->linkify($status, false), ENT_QUOTES, 'UTF-8');
$notice->rendered = $this->linkify($status, true);
if (Event::handle('StartNoticeSave', array(&$notice))) {
if (empty($notice->conversation)) {
$conv = Conversation::create();
common_log(LOG_INFO, "No known conversation for status {$statusId} so a new one ({$conv->getID()}) was created.");
@ -221,7 +214,7 @@ class TwitterImport
*
* @return string URI
*/
function makeStatusURI($username, $id)
public function makeStatusURI($username, $id)
{
return 'https://twitter.com/'
. $username
@ -283,7 +276,7 @@ class TwitterImport
if (empty($id)) {
throw new Exception('Failed insert');
}
} catch(Exception $e) {
} catch (Exception $e) {
common_log(LOG_WARNING, __METHOD__ . " Couldn't insert profile: " . $e->getMessage());
common_log_db_error($profile, 'INSERT', __FILE__);
$profile->query("ROLLBACK");
@ -314,8 +307,13 @@ class TwitterImport
if ($avatar->filename === $filename) {
return null;
}
common_debug(__METHOD__ . " - Updating profile avatar (profile_id={$profile->id}) " .
"from {$avatar->filename} to {$filename}");
common_debug(sprintf(
'%s - Updating profile avatar (profile_id=%d) from %s to %s',
__METHOD__,
$profile->id,
$avatar->filename,
$filename
));
// else we continue with creating a new avatar
} catch (NoAvatarException $e) {
// Avatar was not found. We can catch NoAvatarException or FileNotFoundException
@ -367,7 +365,7 @@ class TwitterImport
$avatar = new Avatar();
$avatar->profile_id = $profile->id;
$avatar->original = 1; // this is an original/"uploaded" avatar
$avatar->original = true; // this is an original/"uploaded" avatar
$avatar->mediatype = $mediatype;
$avatar->filename = $filename;
$avatar->width = $this->avatarsize;
@ -416,7 +414,7 @@ class TwitterImport
const HASHTAG = 2;
const MENTION = 3;
function linkify($status, $html = FALSE)
public function linkify($status, $html = false)
{
$text = $status->text;
@ -424,10 +422,20 @@ class TwitterImport
$statusId = twitter_id($status);
common_log(LOG_WARNING, "No entities data for {$statusId}; trying to fake up links ourselves.");
$text = common_replace_urls_callback($text, 'common_linkify');
$text = preg_replace_callback('/(^|\&quot\;|\'|\(|\[|\{|\s+)#([\pL\pN_\-\.]{1,64})/',
function ($m) { return $m[1].'#'.TwitterStatusFetcher::tagLink($m[2]); }, $text);
$text = preg_replace_callback('/(^|\s+)@([a-z0-9A-Z_]{1,64})/',
function ($m) { return $m[1].'@'.TwitterStatusFetcher::atLink($m[2]); }, $text);
$text = preg_replace_callback(
'/(^|\&quot\;|\'|\(|\[|\{|\s+)#([\pL\pN_\-\.]{1,64})/',
function ($m) {
return $m[1] . '#'.TwitterStatusFetcher::tagLink($m[2]);
},
$text
);
$text = preg_replace_callback(
'/(^|\s+)@([a-z0-9A-Z_]{1,64})/',
function ($m) {
return $m[1] . '@'.TwitterStatusFetcher::atLink($m[2]);
},
$text
);
return $text;
}
@ -472,21 +480,21 @@ class TwitterImport
$cursor = $start;
}
$orig = $this->twitEscape(mb_substr($text, $start, $end - $start));
switch($type) {
switch ($type) {
case self::URL:
$linkText = $this->makeUrlLink($object, $orig, $html);
break;
case self::HASHTAG:
if ($html) {
$linkText = $this->makeHashtagLink($object, $orig);
}else{
} else {
$linkText = $orig;
}
break;
case self::MENTION:
if ($html) {
$linkText = $this->makeMentionLink($object, $orig);
}else{
} else {
$linkText = $orig;
}
break;
@ -503,7 +511,7 @@ class TwitterImport
return $result;
}
function twitEscape($str)
public function twitEscape($str)
{
// Twitter seems to preemptive turn < and > into &lt; and &gt;
// but doesn't for &, so while you may have some magic protection
@ -516,31 +524,31 @@ class TwitterImport
return htmlspecialchars(html_entity_decode($str, ENT_COMPAT, 'UTF-8'));
}
function makeUrlLink($object, $orig, $html)
public function makeUrlLink($object, $orig, $html)
{
if ($html) {
return '<a href="'.htmlspecialchars($object->expanded_url).'" class="extlink">'.htmlspecialchars($object->display_url).'</a>';
}else{
} else {
return htmlspecialchars($object->expanded_url);
}
}
function makeHashtagLink($object, $orig)
public function makeHashtagLink($object, $orig)
{
return "#" . self::tagLink($object->text, substr($orig, 1));
}
function makeMentionLink($object, $orig)
public function makeMentionLink($object, $orig)
{
return "@".self::atLink($object->screen_name, $object->name, substr($orig, 1));
}
static function tagLink($tag, $orig)
public static function tagLink($tag, $orig)
{
return "<a href='https://twitter.com/search?q=%23{$tag}' class='hashtag'>{$orig}</a>";
}
static function atLink($screenName, $fullName, $orig)
public static function atLink($screenName, $fullName, $orig)
{
if (!empty($fullName)) {
return "<a href='https://twitter.com/{$screenName}' title='{$fullName}'>{$orig}</a>";
@ -549,7 +557,7 @@ class TwitterImport
}
}
function saveStatusMentions($notice, $status)
public function saveStatusMentions($notice, $status)
{
$mentions = array();
@ -582,7 +590,7 @@ class TwitterImport
* @param Notice $notice
* @param object $status
*/
function saveStatusAttachments(Notice $notice, $status)
public function saveStatusAttachments(Notice $notice, $status)
{
if (common_config('attachments', 'process_links')) {
if (!empty($status->entities) && !empty($status->entities->urls)) {

View File

@ -1,21 +1,25 @@
#!/usr/bin/env php
<?php
/*
* StatusNet - a distributed open-source microblogging tool
* Copyright (C) 2008, 2009, 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/>.
// 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 GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2008, 2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
define('INSTALLDIR', dirname(__DIR__));
@ -44,7 +48,6 @@ if (empty($nickname) || empty($groupname)) {
}
try {
$user = User::getKV('nickname', $nickname);
if (empty($user)) {
@ -78,12 +81,11 @@ try {
$orig = clone($member);
$member->is_admin = 1;
$member->is_admin = true;
if (!$member->update($orig)) {
throw new Exception("Can't make '$nickname' admin of '$groupname'.");
}
} catch (Exception $e) {
print $e->getMessage() . "\n";
exit(1);

View File

@ -443,7 +443,7 @@ function initProfileLists()
$plist->tagger = $ptag->tagger;
$plist->tag = $ptag->tag;
$plist->private = 0;
$plist->private = false;
$plist->created = common_sql_now();
$plist->modified = $plist->created;
$plist->mainpage = common_local_url(