[DATABASE] Only use single quotation marks for SQL strings

Double quotation marks are only used for identifiers in the SQL standard.
This commit is contained in:
Alexei Sorokin 2019-09-11 09:46:30 +03:00
parent 0a5a3845db
commit 11dabbe44d
16 changed files with 977 additions and 762 deletions

View File

@ -1,28 +1,25 @@
<?php <?php
/* // This file is part of GNU social - https://www.gnu.org/software/social
* StatusNet - the distributed open-source microblogging tool //
* Copyright (C) 2008, 2009, StatusNet, Inc. // 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
* This program is free software: you can redistribute it and/or modify // the Free Software Foundation, either version 3 of the License, or
* it under the terms of the GNU Affero General Public License as published by // (at your option) any later version.
* 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
* This program is distributed in the hope that it will be useful, // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* but WITHOUT ANY WARRANTY; without even the implied warranty of // GNU Affero General Public License for more details.
* 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/>.
* 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); } defined('GNUSOCIAL') || die();
// @todo FIXME: documentation needed. // @todo FIXME: documentation needed.
class SupAction extends Action class SupAction extends Action
{ {
function handle() public function handle()
{ {
parent::handle(); parent::handle();
@ -43,21 +40,23 @@ class SupAction extends Action
'updates' => $updates)); 'updates' => $updates));
} }
function availablePeriods() public function availablePeriods()
{ {
static $periods = array(86400, 43200, 21600, 7200, static $periods = array(86400, 43200, 21600, 7200,
3600, 1800, 600, 300, 120, 3600, 1800, 600, 300, 120,
60, 30, 15); 60, 30, 15);
$available = array(); $available = array();
foreach ($periods as $period) { foreach ($periods as $period) {
$available[$period] = common_local_url('sup', $available[$period] = common_local_url(
array('seconds' => $period)); 'sup',
['seconds' => $period]
);
} }
return $available; return $available;
} }
function getUpdates($seconds) public function getUpdates($seconds)
{ {
$notice = new Notice(); $notice = new Notice();
@ -71,7 +70,7 @@ class SupAction extends Action
'SELECT profile_id, id FROM notice ' . 'SELECT profile_id, id FROM notice ' .
((common_config('db','type') == 'pgsql') ? ((common_config('db','type') == 'pgsql') ?
'WHERE extract(epoch from created) > (extract(epoch from now()) - ' . $seconds . ') ' : 'WHERE extract(epoch from created) > (extract(epoch from now()) - ' . $seconds . ') ' :
'WHERE created > "'.$divider.'" ' ) . "WHERE created > TIMESTAMP '" . $divider . "' ") .
') AS latest ' . ') AS latest ' .
'GROUP BY profile_id'); 'GROUP BY profile_id');
@ -84,7 +83,7 @@ class SupAction extends Action
return $updates; return $updates;
} }
function isReadOnly($args) public function isReadOnly($args)
{ {
return true; return true;
} }

View File

@ -1,8 +1,24 @@
<?php <?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 profile_tag * Table Definition for profile_tag
*/ */
class Profile_tag extends Managed_DataObject class Profile_tag extends Managed_DataObject
{ {
public $__table = 'profile_tag'; // table name public $__table = 'profile_tag'; // table name
@ -35,35 +51,34 @@ class Profile_tag extends Managed_DataObject
); );
} }
function links() public function links()
{ {
return array('tagger,tag' => 'profile_list:tagger,tag'); return array('tagger,tag' => 'profile_list:tagger,tag');
} }
function getMeta() public function getMeta()
{ {
return Profile_list::pkeyGet(array('tagger' => $this->tagger, 'tag' => $this->tag)); return Profile_list::pkeyGet(array('tagger' => $this->tagger, 'tag' => $this->tag));
} }
static function getSelfTagsArray(Profile $target) public static function getSelfTagsArray(Profile $target)
{ {
return self::getTagsArray($target->getID(), $target->getID(), $target); return self::getTagsArray($target->getID(), $target->getID(), $target);
} }
static function setSelfTags(Profile $target, array $newtags, array $privacy=array()) public static function setSelfTags(Profile $target, array $newtags, array $privacy = [])
{ {
return self::setTags($target->getID(), $target->getID(), $newtags, $privacy); return self::setTags($target->getID(), $target->getID(), $newtags, $privacy);
} }
static function getTags($tagger, $tagged, $auth_user=null) { public static function getTags($tagger, $tagged, $auth_user = null)
{
$profile_list = new Profile_list(); $profile_list = new Profile_list();
$include_priv = 1; $include_priv = 1;
if (!($auth_user instanceof User || if (!($auth_user instanceof User ||
$auth_user instanceof Profile) || $auth_user instanceof Profile) ||
($auth_user->id !== $tagger)) { ($auth_user->id !== $tagger)) {
$profile_list->private = false; $profile_list->private = false;
$include_priv = 0; $include_priv = 0;
} }
@ -91,17 +106,20 @@ class Profile_tag extends Managed_DataObject
return $profile_list; return $profile_list;
} }
static function getTagsArray($tagger, $tagged, Profile $scoped=null) public static function getTagsArray($tagger, $tagged, Profile $scoped = null)
{ {
$ptag = new Profile_tag(); $ptag = new Profile_tag();
$qry = sprintf('select profile_tag.tag '. $qry = sprintf(
'from profile_tag join profile_list '. 'SELECT profile_tag.tag '.
' on (profile_tag.tagger = profile_list.tagger ' . 'FROM profile_tag INNER JOIN profile_list '.
' and profile_tag.tag = profile_list.tag) ' . ' ON (profile_tag.tagger = profile_list.tagger ' .
'where profile_tag.tagger = %d ' . ' and profile_tag.tag = profile_list.tag) ' .
'and profile_tag.tagged = %d ', 'WHERE profile_tag.tagger = %d ' .
$tagger, $tagged); 'AND profile_tag.tagged = %d ',
$tagger,
$tagged
);
if (!$scoped instanceof Profile || $scoped->getID() !== $tagger) { if (!$scoped instanceof Profile || $scoped->getID() !== $tagger) {
$qry .= 'and profile_list.private = 0'; $qry .= 'and profile_list.private = 0';
@ -118,8 +136,8 @@ class Profile_tag extends Managed_DataObject
return $tags; return $tags;
} }
static function setTags($tagger, $tagged, array $newtags, array $privacy=array()) { public static function setTags($tagger, $tagged, array $newtags, array $privacy = [])
{
$newtags = array_unique($newtags); $newtags = array_unique($newtags);
$oldtags = self::getTagsArray($tagger, $tagged, Profile::getByID($tagger)); $oldtags = self::getTagsArray($tagger, $tagged, Profile::getByID($tagger));
@ -145,8 +163,8 @@ class Profile_tag extends Managed_DataObject
} }
# set a single tag # set a single tag
static function setTag($tagger, $tagged, $tag, $desc=null, $private=false) { public static function setTag($tagger, $tagged, $tag, $desc=null, $private = false)
{
$ptag = Profile_tag::pkeyGet(array('tagger' => $tagger, $ptag = Profile_tag::pkeyGet(array('tagger' => $tagger,
'tagged' => $tagged, 'tagged' => $tagged,
'tag' => $tag)); 'tag' => $tag));
@ -160,7 +178,6 @@ class Profile_tag extends Managed_DataObject
$tagged_profile = Profile::getByID($tagged); $tagged_profile = Profile::getByID($tagged);
if (Event::handle('StartTagProfile', array($tagger_profile, $tagged_profile, $tag))) { if (Event::handle('StartTagProfile', array($tagger_profile, $tagged_profile, $tag))) {
if (!$tagger_profile->canTag($tagged_profile)) { if (!$tagger_profile->canTag($tagged_profile)) {
// TRANS: Client exception thrown trying to set a tag for a user that cannot be tagged. // TRANS: Client exception thrown trying to set a tag for a user that cannot be tagged.
throw new ClientException(_('You cannot tag this user.')); throw new ClientException(_('You cannot tag this user.'));
@ -172,10 +189,12 @@ class Profile_tag extends Managed_DataObject
if ($count >= common_config('peopletag', 'maxtags')) { if ($count >= common_config('peopletag', 'maxtags')) {
// TRANS: Client exception thrown trying to set more tags than allowed. // TRANS: Client exception thrown trying to set more tags than allowed.
throw new ClientException(sprintf(_('You already have created %d or more tags ' . throw new ClientException(sprintf(
'which is the maximum allowed number of tags. ' . _('You already have created %d or more tags ' .
'Try using or deleting some existing tags.'), 'which is the maximum allowed number of tags. ' .
common_config('peopletag', 'maxtags'))); 'Try using or deleting some existing tags.'),
common_config('peopletag', 'maxtags')
));
} }
$plist = new Profile_list(); $plist = new Profile_list();
@ -185,10 +204,13 @@ class Profile_tag extends Managed_DataObject
if ($profile_list->taggedCount() >= common_config('peopletag', 'maxpeople')) { if ($profile_list->taggedCount() >= common_config('peopletag', 'maxpeople')) {
// TRANS: Client exception thrown when trying to add more people than allowed to a list. // TRANS: Client exception thrown when trying to add more people than allowed to a list.
throw new ClientException(sprintf(_('You already have %1$d or more people in list %2$s, ' . throw new ClientException(sprintf(
'which is the maximum allowed number. ' . _('You already have %1$d or more people in list %2$s, ' .
'Try unlisting others first.'), 'which is the maximum allowed number. ' .
common_config('peopletag', 'maxpeople'), $tag)); 'Try unlisting others first.'),
common_config('peopletag', 'maxpeople'),
$tag
));
} }
$newtag = new Profile_tag(); $newtag = new Profile_tag();
@ -221,7 +243,8 @@ class Profile_tag extends Managed_DataObject
return $newtag; return $newtag;
} }
static function unTag($tagger, $tagged, $tag) { public static function unTag($tagger, $tagged, $tag)
{
$ptag = Profile_tag::pkeyGet(array('tagger' => $tagger, $ptag = Profile_tag::pkeyGet(array('tagger' => $tagger,
'tagged' => $tagged, 'tagged' => $tagged,
'tag' => $tag)); 'tag' => $tag));
@ -247,13 +270,14 @@ class Profile_tag extends Managed_DataObject
} }
// @fixme: move this to Profile_list? // @fixme: move this to Profile_list?
static function cleanup($profile_list) { public static function cleanup($profile_list)
{
$ptag = new Profile_tag(); $ptag = new Profile_tag();
$ptag->tagger = $profile_list->tagger; $ptag->tagger = $profile_list->tagger;
$ptag->tag = $profile_list->tag; $ptag->tag = $profile_list->tag;
$ptag->find(); $ptag->find();
while($ptag->fetch()) { while ($ptag->fetch()) {
if (Event::handle('StartUntagProfile', array($ptag))) { if (Event::handle('StartUntagProfile', array($ptag))) {
$orig = clone($ptag); $orig = clone($ptag);
$result = $ptag->delete(); $result = $ptag->delete();
@ -266,17 +290,18 @@ class Profile_tag extends Managed_DataObject
} }
// move a tag! // move a tag!
static function moveTag($orig, $new) { public static function moveTag($orig, $new)
{
$tags = new Profile_tag(); $tags = new Profile_tag();
$qry = 'UPDATE profile_tag SET ' . $qry = "UPDATE profile_tag SET tag = '%s', tagger = '%s' " .
'tag = "%s", tagger = "%s" ' . "WHERE tag = '%s' AND tagger = '%s'";
'WHERE tag = "%s" ' . $result = $tags->query(sprintf(
'AND tagger = "%s"'; $qry,
$result = $tags->query(sprintf($qry, $tags->escape($new->tag),
$tags->escape($new->tag), $tags->escape($new->tagger),
$tags->escape($new->tagger), $tags->escape($orig->tag),
$tags->escape($orig->tag), $tags->escape($orig->tagger)
$tags->escape($orig->tagger))); ));
if ($result === false) { if ($result === false) {
common_log_db_error($tags, 'UPDATE', __FILE__); common_log_db_error($tags, 'UPDATE', __FILE__);
@ -285,7 +310,8 @@ class Profile_tag extends Managed_DataObject
return $result; return $result;
} }
static function blowCaches($tagger, $tagged) { public static function blowCaches($tagger, $tagged)
{
foreach (array(0, 1) as $perm) { foreach (array(0, 1) as $perm) {
self::blow(sprintf('profile_tag:tagger_tagged_privacy:%d-%d-%d', $tagger, $tagged, $perm)); self::blow(sprintf('profile_tag:tagger_tagged_privacy:%d-%d-%d', $tagger, $tagged, $perm));
} }
@ -293,38 +319,43 @@ class Profile_tag extends Managed_DataObject
} }
// Return profiles with a given tag // Return profiles with a given tag
static function getTagged($tagger, $tag) { public static function getTagged($tagger, $tag)
{
$profile = new Profile(); $profile = new Profile();
$profile->query('SELECT profile.* ' . $profile->query('SELECT profile.* ' .
'FROM profile JOIN profile_tag ' . 'FROM profile JOIN profile_tag ' .
'ON profile.id = profile_tag.tagged ' . 'ON profile.id = profile_tag.tagged ' .
'WHERE profile_tag.tagger = ' . $profile->escape($tagger) . ' ' . 'WHERE profile_tag.tagger = ' . $profile->escape($tagger) . ' ' .
'AND profile_tag.tag = "' . $profile->escape($tag) . '" '); "AND profile_tag.tag = '" . $profile->escape($tag) . "' ");
$tagged = array(); $tagged = [];
while ($profile->fetch()) { while ($profile->fetch()) {
$tagged[] = clone($profile); $tagged[] = clone($profile);
} }
return true; return true;
} }
function insert() public function insert()
{ {
$result = parent::insert(); $result = parent::insert();
if ($result) { if ($result) {
self::blow('profile_list:tagged_count:%d:%s', self::blow(
$this->tagger, 'profile_list:tagged_count:%d:%s',
$this->tag); $this->tagger,
$this->tag
);
} }
return $result; return $result;
} }
function delete($useWhere=false) public function delete($useWhere = false)
{ {
$result = parent::delete($useWhere); $result = parent::delete($useWhere);
if ($result !== false) { if ($result !== false) {
self::blow('profile_list:tagged_count:%d:%s', self::blow(
$this->tagger, 'profile_list:tagged_count:%d:%s',
$this->tag); $this->tagger,
$this->tag
);
} }
return $result; return $result;
} }

View File

@ -36,7 +36,7 @@ VALUES
(100088, 'Orange (Poland)', '%s@orange.pl', now()), (100088, 'Orange (Poland)', '%s@orange.pl', now()),
(100089, 'Personal (Argentina)', '%s@personal-net.com.ar', now()), (100089, 'Personal (Argentina)', '%s@personal-net.com.ar', now()),
(100090, 'Plus GSM (Poland)', '%s@text.plusgsm.pl', now()), (100090, 'Plus GSM (Poland)', '%s@text.plusgsm.pl', now()),
(100091, 'President\'s Choice (Canada)', '%s@txt.bell.ca', now()), (100091, 'President''s Choice (Canada)', '%s@txt.bell.ca', now()),
(100092, 'Qwest', '%s@qwestmp.com', now()), (100092, 'Qwest', '%s@qwestmp.com', now()),
(100093, 'Rogers (Canada)', '%s@pcs.rogers.com', now()), (100093, 'Rogers (Canada)', '%s@pcs.rogers.com', now()),
(100094, 'Sasktel (Canada)', '%s@sms.sasktel.com', now()), (100094, 'Sasktel (Canada)', '%s@sms.sasktel.com', now()),

View File

@ -1,31 +1,54 @@
<?php <?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();
/**
* Raw public stream
*
* @category Stream
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2019 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class NetworkPublicNoticeStream extends ModeratedNoticeStream class NetworkPublicNoticeStream extends ModeratedNoticeStream
{ {
function __construct(Profile $scoped=null) public function __construct(Profile $scoped = null)
{ {
parent::__construct(new CachingNoticeStream(new RawNetworkPublicNoticeStream(), parent::__construct(
'networkpublic'), new CachingNoticeStream(
$scoped); new RawNetworkPublicNoticeStream(),
'networkpublic'
),
$scoped
);
} }
} }
/** /**
* Raw public stream * Raw public stream
* *
* @category Stream
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc. * @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @link http://status.net/
*/ */
class RawNetworkPublicNoticeStream extends FullNoticeStream class RawNetworkPublicNoticeStream extends FullNoticeStream
{ {
function getNoticeIds($offset, $limit, $since_id, $max_id) public function getNoticeIds($offset, $limit, $since_id, $max_id)
{ {
$notice = new Notice(); $notice = new Notice();
@ -38,11 +61,11 @@ class RawNetworkPublicNoticeStream extends FullNoticeStream
$notice->limit($offset, $limit); $notice->limit($offset, $limit);
} }
$notice->whereAdd('is_local ='. Notice::REMOTE); $notice->whereAdd('is_local = '. Notice::REMOTE);
// -1 == blacklisted, -2 == gateway (i.e. Twitter) // -1 == blacklisted, -2 == gateway (i.e. Twitter)
$notice->whereAdd('is_local !='. Notice::LOCAL_NONPUBLIC); $notice->whereAdd('is_local <> '. Notice::LOCAL_NONPUBLIC);
$notice->whereAdd('is_local !='. Notice::GATEWAY); $notice->whereAdd('is_local <> '. Notice::GATEWAY);
$notice->whereAdd('scope != ' . Notice::MESSAGE_SCOPE); $notice->whereAdd('scope <> ' . Notice::MESSAGE_SCOPE);
Notice::addWhereSinceId($notice, $since_id); Notice::addWhereSinceId($notice, $since_id);
Notice::addWhereMaxId($notice, $max_id); Notice::addWhereMaxId($notice, $max_id);
@ -58,7 +81,7 @@ class RawNetworkPublicNoticeStream extends FullNoticeStream
} }
$notice->free(); $notice->free();
$notice = NULL; $notice = null;
return $ids; return $ids;
} }

View File

@ -1,72 +1,63 @@
<?php <?php
/** // This file is part of GNU social - https://www.gnu.org/software/social
* StatusNet - the distributed open-source microblogging tool //
* Copyright (C) 2011, StatusNet, Inc. // 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
* Stream of notices for a list // the Free Software Foundation, either version 3 of the License, or
* // (at your option) any later version.
* PHP version 5 //
* // GNU social is distributed in the hope that it will be useful,
* This program is free software: you can redistribute it and/or modify // but WITHOUT ANY WARRANTY; without even the implied warranty of
* it under the terms of the GNU Affero General Public License as published by // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* the Free Software Foundation, either version 3 of the License, or // GNU Affero General Public License for more details.
* (at your option) any later version. //
* // You should have received a copy of the GNU Affero General Public License
* This program is distributed in the hope that it will be useful, // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
* 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 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/
*/
if (!defined('GNUSOCIAL')) { exit(1); }
/** /**
* Stream of notices for a list * Stream of notices for a list
* *
* @category Stream * @category Stream
* @package StatusNet * @package GNUsocial
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @author Shashi Gowda <connect2shashi@gmail.com> * @author Shashi Gowda <connect2shashi@gmail.com>
* @copyright 2011 StatusNet, Inc. * @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @link http://status.net/ */
defined('GNUSOCIAL') || die();
/**
* Stream of notices for a list
*
* @copyright 2011 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/ */
class PeopletagNoticeStream extends ScopingNoticeStream class PeopletagNoticeStream extends ScopingNoticeStream
{ {
function __construct($plist, Profile $scoped=null) public function __construct($plist, Profile $scoped = null)
{ {
parent::__construct(new CachingNoticeStream(new RawPeopletagNoticeStream($plist), parent::__construct(
'profile_list:notice_ids:' . $plist->id), new CachingNoticeStream(
$scoped); new RawPeopletagNoticeStream($plist),
'profile_list:notice_ids:' . $plist->id
),
$scoped
);
} }
} }
/** /**
* Stream of notices for a list * Stream of notices for a list
* *
* @category Stream
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @author Shashi Gowda <connect2shashi@gmail.com>
* @copyright 2011 StatusNet, Inc. * @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @link http://status.net/
*/ */
class RawPeopletagNoticeStream extends NoticeStream class RawPeopletagNoticeStream extends NoticeStream
{ {
protected $profile_list; protected $profile_list;
function __construct($profile_list) public function __construct($profile_list)
{ {
$this->profile_list = $profile_list; $this->profile_list = $profile_list;
} }
@ -82,7 +73,7 @@ class RawPeopletagNoticeStream extends NoticeStream
* @return array array of notice ids. * @return array array of notice ids.
*/ */
function getNoticeIds($offset, $limit, $since_id, $max_id) public function getNoticeIds($offset, $limit, $since_id, $max_id)
{ {
$notice = new Notice(); $notice = new Notice();
@ -94,7 +85,10 @@ class RawPeopletagNoticeStream extends NoticeStream
$ptag->tagger = $this->profile_list->tagger; $ptag->tagger = $this->profile_list->tagger;
$notice->joinAdd(array('profile_id', 'profile_tag:tagged')); $notice->joinAdd(array('profile_id', 'profile_tag:tagged'));
$notice->whereAdd('profile_tag.tagger = ' . $this->profile_list->tagger); $notice->whereAdd('profile_tag.tagger = ' . $this->profile_list->tagger);
$notice->whereAdd(sprintf('profile_tag.tag = "%s"', $this->profile_list->tag)); $notice->whereAdd(sprintf(
"profile_tag.tag = '%s'",
$notice->escape($this->profile_list->tag)
));
if ($since_id != 0) { if ($since_id != 0) {
$notice->whereAdd('notice.id > ' . $since_id); $notice->whereAdd('notice.id > ' . $since_id);

View File

@ -1,47 +1,42 @@
<?php <?php
/* // This file is part of GNU social - https://www.gnu.org/software/social
* StatusNet - the distributed open-source microblogging tool //
* Copyright (C) 2008, 2009, StatusNet, Inc. // 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
* This program is free software: you can redistribute it and/or modify // the Free Software Foundation, either version 3 of the License, or
* it under the terms of the GNU Affero General Public License as published by // (at your option) any later version.
* 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
* This program is distributed in the hope that it will be useful, // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* but WITHOUT ANY WARRANTY; without even the implied warranty of // GNU Affero General Public License for more details.
* 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/>.
* 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')) { defined('GNUSOCIAL') || die();
exit(1);
}
class SearchEngine class SearchEngine
{ {
protected $target; protected $target;
protected $table; protected $table;
function __construct($target, $table) public function __construct($target, $table)
{ {
$this->target = $target; $this->target = $target;
$this->table = $table; $this->table = $table;
} }
function query($q) public function query($q)
{ {
} }
function limit($offset, $count, $rss = false) public function limit($offset, $count, $rss = false)
{ {
return $this->target->limit($offset, $count); return $this->target->limit($offset, $count);
} }
function set_sort_mode($mode) public function set_sort_mode($mode)
{ {
switch ($mode) { switch ($mode) {
case 'chron': case 'chron':
@ -77,40 +72,43 @@ class SearchEngine
class MySQLSearch extends SearchEngine class MySQLSearch extends SearchEngine
{ {
function query($q) public function query($q)
{ {
if ('profile' === $this->table) { if ($this->table === 'profile') {
$this->target->whereAdd( $this->target->whereAdd(sprintf(
sprintf('MATCH (%2$s.nickname, %2$s.fullname, %2$s.location, %2$s.bio, %2$s.homepage) ' . 'MATCH (%2$s.nickname, %2$s.fullname, %2$s.location, %2$s.bio, %2$s.homepage) ' .
'AGAINST ("%1$s" IN BOOLEAN MODE)', 'AGAINST (\'%1$s\' IN BOOLEAN MODE)',
$this->target->escape($q, true), $this->target->escape($q, true),
$this->table) $this->table
); ));
if (strtolower($q) != $q) { if (strtolower($q) != $q) {
$this->target->whereAdd( $this->target->whereAdd(
sprintf('MATCH (%2$s.nickname, %2$s.fullname, %2$s.location, %2$s.bio, %2$s.homepage) ' . sprintf(
'AGAINST ("%1$s" IN BOOLEAN MODE)', 'MATCH (%2$s.nickname, %2$s.fullname, %2$s.location, %2$s.bio, %2$s.homepage) ' .
'AGAINST (\'%1$s\' IN BOOLEAN MODE)',
$this->target->escape(strtolower($q), true), $this->target->escape(strtolower($q), true),
$this->table), $this->table
),
'OR' 'OR'
); );
} }
return true; return true;
} else if ('notice' === $this->table) { } elseif ($this->table === 'notice') {
// Don't show imported notices // Don't show imported notices
$this->target->whereAdd('notice.is_local != ' . Notice::GATEWAY); $this->target->whereAdd('notice.is_local != ' . Notice::GATEWAY);
$this->target->whereAdd( $this->target->whereAdd(sprintf(
sprintf('MATCH (%2$s.content) AGAINST ("%1$s" IN BOOLEAN MODE)', 'MATCH (%2$s.content) AGAINST (\'%1$s\' IN BOOLEAN MODE)',
$this->target->escape($q, true), $this->target->escape($q, true),
$this->table) $this->table
); ));
if (strtolower($q) != $q) { if (strtolower($q) != $q) {
$this->target->whereAdd( $this->target->whereAdd(
sprintf('MATCH (%2$s.content) AGAINST ("%1$s" IN BOOLEAN MODE)', sprintf(
'MATCH (%2$s.content) AGAINST (\'%1$s\' IN BOOLEAN MODE)',
$this->target->escape(strtolower($q), true), $this->target->escape(strtolower($q), true),
$this->table), $this->table
),
'OR' 'OR'
); );
} }
@ -124,18 +122,20 @@ class MySQLSearch extends SearchEngine
class MySQLLikeSearch extends SearchEngine class MySQLLikeSearch extends SearchEngine
{ {
function query($q) public function query($q)
{ {
if ('profile' === $this->table) { if ($this->table === 'profile') {
$qry = sprintf('(%2$s.nickname LIKE "%%%1$s%%" OR ' . $qry = sprintf(
' %2$s.fullname LIKE "%%%1$s%%" OR ' . '( %2$s.nickname LIKE \'%%%1$s%%\' ' .
' %2$s.location LIKE "%%%1$s%%" OR ' . ' OR %2$s.fullname LIKE \'%%%1$s%%\' ' .
' %2$s.bio LIKE "%%%1$s%%" OR ' . ' OR %2$s.location LIKE \'%%%1$s%%\' ' .
' %2$s.homepage LIKE "%%%1$s%%")', ' OR %2$s.bio LIKE \'%%%1$s%%\' ' .
$this->target->escape($q, true), ' OR %2$s.homepage LIKE \'%%%1$s%%\')',
$this->table); $this->target->escape($q, true),
} else if ('notice' === $this->table) { $this->table
$qry = sprintf('content LIKE "%%%1$s%%"', $this->target->escape($q, true)); );
} elseif ($this->table === 'notice') {
$qry = sprintf('content LIKE \'%%%1$s%%\'', $this->target->escape($q, true));
} else { } else {
throw new ServerException('Unknown table: ' . $this->table); throw new ServerException('Unknown table: ' . $this->table);
} }
@ -148,18 +148,15 @@ class MySQLLikeSearch extends SearchEngine
class PGSearch extends SearchEngine class PGSearch extends SearchEngine
{ {
function query($q) public function query($q)
{ {
if ('profile' === $this->table) { if ($this->table === 'profile') {
return $this->target->whereAdd('textsearch @@ plainto_tsquery(\'' . $this->target->escape($q) . '\')'); return $this->target->whereAdd('textsearch @@ plainto_tsquery(\'' . $this->target->escape($q) . '\')');
} else if ('notice' === $this->table) { } elseif ($this->table === 'notice') {
// XXX: We need to filter out gateway notices (notice.is_local = -2) --Zach // XXX: We need to filter out gateway notices (notice.is_local = -2) --Zach
return $this->target->whereAdd('to_tsvector(\'english\', content) @@ plainto_tsquery(\'' . $this->target->escape($q) . '\')'); return $this->target->whereAdd('to_tsvector(\'english\', content) @@ plainto_tsquery(\'' . $this->target->escape($q) . '\')');
} else { } else {
throw new ServerException('Unknown table: ' . $this->table); throw new ServerException('Unknown table: ' . $this->table);
} }
} }
} }

View File

@ -167,7 +167,7 @@ class InternalSessionHandler implements SessionHandlerInterface
$ids = []; $ids = [];
$session = new Session(); $session = new Session();
$session->whereAdd('modified < "' . $epoch . '"'); $session->whereAdd("modified < TIMESTAMP '" . $epoch . "'");
$session->selectAdd(); $session->selectAdd();
$session->selectAdd('id'); $session->selectAdd('id');

View File

@ -1,28 +1,28 @@
<?php <?php
/* // This file is part of GNU social - https://www.gnu.org/software/social
* GNU Social - a federating social network //
* Copyright (C) 2014, Free Software Foundation, Inc. // 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
* This program is free software: you can redistribute it and/or modify // the Free Software Foundation, either version 3 of the License, or
* it under the terms of the GNU Affero General Public License as published by // (at your option) any later version.
* 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
* This program is distributed in the hope that it will be useful, // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* but WITHOUT ANY WARRANTY; without even the implied warranty of // GNU Affero General Public License for more details.
* 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/>.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (!defined('GNUSOCIAL')) { exit(1); }
/** /**
* @package Activity * @package Favorite
* @maintainer Mikael Nordfeldth <mmn@hethane.se> * @author Mikael Nordfeldth <mmn@hethane.se>
* @copyright 2014 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/ */
defined('GNUSOCIAL') || die();
class FavoriteModule extends ActivityVerbHandlerModule class FavoriteModule extends ActivityVerbHandlerModule
{ {
const PLUGIN_VERSION = '2.0.0'; const PLUGIN_VERSION = '2.0.0';
@ -93,15 +93,14 @@ class FavoriteModule extends ActivityVerbHandlerModule
while ($fave->fetch()) { while ($fave->fetch()) {
try { try {
$fave->decache(); $fave->decache();
$fave->query(sprintf('UPDATE fave '. $fave->query(sprintf(
'SET uri = "%s", '. "UPDATE fave SET uri = '%s', modified = TIMESTAMP '%s' " .
' modified = "%s" '. 'WHERE user_id = %d AND notice_id = %d',
'WHERE user_id = %d '. Fave::newUri($fave->getActor(), $fave->getTarget(), $fave->modified),
'AND notice_id = %d', common_sql_date(strtotime($fave->modified)),
Fave::newUri($fave->getActor(), $fave->getTarget(), $fave->modified), $fave->user_id,
common_sql_date(strtotime($fave->modified)), $fave->notice_id
$fave->user_id, ));
$fave->notice_id));
} catch (Exception $e) { } catch (Exception $e) {
common_log(LOG_ERR, "Error updating fave URI: " . $e->getMessage()); common_log(LOG_ERR, "Error updating fave URI: " . $e->getMessage());
} }
@ -114,77 +113,129 @@ class FavoriteModule extends ActivityVerbHandlerModule
public function onRouterInitialized(URLMapper $m) public function onRouterInitialized(URLMapper $m)
{ {
// Web UI actions // Web UI actions
$m->connect('main/favor', $m->connect(
['action' => 'favor']); 'main/favor',
$m->connect('main/disfavor', ['action' => 'favor']
['action' => 'disfavor']); );
$m->connect(
'main/disfavor',
['action' => 'disfavor']
);
if (common_config('singleuser', 'enabled')) { if (common_config('singleuser', 'enabled')) {
$nickname = User::singleUserNickname(); $nickname = User::singleUserNickname();
$m->connect('favorites', $m->connect(
['action' => 'showfavorites', 'favorites',
'nickname' => $nickname]); [
$m->connect('favoritesrss', 'action' => 'showfavorites',
['action' => 'favoritesrss', 'nickname' => $nickname,
'nickname' => $nickname]); ]
);
$m->connect(
'favoritesrss',
[
'action' => 'favoritesrss',
'nickname' => $nickname,
]
);
} else { } else {
$m->connect('favoritedrss', $m->connect(
['action' => 'favoritedrss']); 'favoritedrss',
$m->connect('favorited/', ['action' => 'favoritedrss']
['action' => 'favorited']); );
$m->connect('favorited', $m->connect(
['action' => 'favorited']); 'favorited/',
['action' => 'favorited']
);
$m->connect(
'favorited',
['action' => 'favorited']
);
$m->connect(':nickname/favorites', $m->connect(
['action' => 'showfavorites'], ':nickname/favorites',
['nickname' => Nickname::DISPLAY_FMT]); ['action' => 'showfavorites'],
$m->connect(':nickname/favorites/rss', ['nickname' => Nickname::DISPLAY_FMT]
['action' => 'favoritesrss'], );
['nickname' => Nickname::DISPLAY_FMT]); $m->connect(
':nickname/favorites/rss',
['action' => 'favoritesrss'],
['nickname' => Nickname::DISPLAY_FMT]
);
} }
// Favorites for API // Favorites for API
$m->connect('api/favorites/create.:format', $m->connect(
['action' => 'ApiFavoriteCreate'], 'api/favorites/create.:format',
['format' => '(xml|json)']); ['action' => 'ApiFavoriteCreate'],
$m->connect('api/favorites/destroy.:format', ['format' => '(xml|json)']
['action' => 'ApiFavoriteDestroy'], );
['format' => '(xml|json)']); $m->connect(
$m->connect('api/favorites/list.:format', 'api/favorites/destroy.:format',
['action' => 'ApiTimelineFavorites'], ['action' => 'ApiFavoriteDestroy'],
['format' => '(xml|json|rss|atom|as)']); ['format' => '(xml|json)']
$m->connect('api/favorites/:id.:format', );
['action' => 'ApiTimelineFavorites'], $m->connect(
['id' => Nickname::INPUT_FMT, 'api/favorites/list.:format',
'format' => '(xml|json|rss|atom|as)']); ['action' => 'ApiTimelineFavorites'],
$m->connect('api/favorites.:format', ['format' => '(xml|json|rss|atom|as)']
['action' => 'ApiTimelineFavorites'], );
['format' => '(xml|json|rss|atom|as)']); $m->connect(
$m->connect('api/favorites/create/:id.:format', 'api/favorites/:id.:format',
['action' => 'ApiFavoriteCreate'], ['action' => 'ApiTimelineFavorites'],
['id' => '[0-9]+', [
'format' => '(xml|json)']); 'id' => Nickname::INPUT_FMT,
$m->connect('api/favorites/destroy/:id.:format', 'format' => '(xml|json|rss|atom|as)',
['action' => 'ApiFavoriteDestroy'], ]
['id' => '[0-9]+', );
'format' => '(xml|json)']); $m->connect(
'api/favorites.:format',
['action' => 'ApiTimelineFavorites'],
['format' => '(xml|json|rss|atom|as)']
);
$m->connect(
'api/favorites/create/:id.:format',
['action' => 'ApiFavoriteCreate'],
[
'id' => '[0-9]+',
'format' => '(xml|json)',
]
);
$m->connect(
'api/favorites/destroy/:id.:format',
['action' => 'ApiFavoriteDestroy'],
[
'id' => '[0-9]+',
'format' => '(xml|json)',
]
);
// AtomPub API // AtomPub API
$m->connect('api/statusnet/app/favorites/:profile/:notice.atom', $m->connect(
['action' => 'AtomPubShowFavorite'], 'api/statusnet/app/favorites/:profile/:notice.atom',
['profile' => '[0-9]+', ['action' => 'AtomPubShowFavorite'],
'notice' => '[0-9]+']); [
'profile' => '[0-9]+',
'notice' => '[0-9]+',
]
);
$m->connect('api/statusnet/app/favorites/:profile.atom', $m->connect(
['action' => 'AtomPubFavoriteFeed'], 'api/statusnet/app/favorites/:profile.atom',
['profile' => '[0-9]+']); ['action' => 'AtomPubFavoriteFeed'],
['profile' => '[0-9]+']
);
// Required for qvitter API // Required for qvitter API
$m->connect('api/statuses/favs/:id.:format', $m->connect(
['action' => 'ApiStatusesFavs'], 'api/statuses/favs/:id.:format',
['id' => '[0-9]+', ['action' => 'ApiStatusesFavs'],
'format' => '(xml|json)']); [
'id' => '[0-9]+',
'format' => '(xml|json)',
]
);
} }
// FIXME: Set this to abstract public in lib/modules/ActivityHandlerPlugin.php when all plugins have migrated! // FIXME: Set this to abstract public in lib/modules/ActivityHandlerPlugin.php when all plugins have migrated!
@ -443,10 +494,12 @@ class FavoriteModule extends ActivityVerbHandlerModule
$emailfave = $scoped->getConfigPref('email', 'notify_fave') ? 1 : 0; $emailfave = $scoped->getConfigPref('email', 'notify_fave') ? 1 : 0;
$action->elementStart('li'); $action->elementStart('li');
$action->checkbox('email-notify_fave', $action->checkbox(
// TRANS: Checkbox label in e-mail preferences form. 'email-notify_fave',
_('Send me email when someone adds my notice as a favorite.'), // TRANS: Checkbox label in e-mail preferences form.
$emailfave); _('Send me email when someone adds my notice as a favorite.'),
$emailfave
);
$action->elementEnd('li'); $action->elementEnd('li');
return true; return true;
@ -473,24 +526,31 @@ class FavoriteModule extends ActivityVerbHandlerModule
public function onEndPersonalGroupNav(Menu $menu, Profile $target, Profile $scoped=null) public function onEndPersonalGroupNav(Menu $menu, Profile $target, Profile $scoped=null)
{ {
$menu->out->menuItem(common_local_url('showfavorites', array('nickname' => $target->getNickname())), $menu->out->menuItem(
// TRANS: Menu item in personal group navigation menu. common_local_url('showfavorites', ['nickname' => $target->getNickname()]),
_m('MENU','Favorites'), // TRANS: Menu item in personal group navigation menu.
// @todo i18n FIXME: Need to make this two messages. _m('MENU', 'Favorites'),
// TRANS: Menu item title in personal group navigation menu. // @todo i18n FIXME: Need to make this two messages.
// TRANS: %s is a username. // TRANS: Menu item title in personal group navigation menu.
sprintf(_('%s\'s favorite notices'), $target->getBestName()), // TRANS: %s is a username.
$scoped instanceof Profile && $target->id === $scoped->id && $menu->actionName =='showfavorites', sprintf(_('%s\'s favorite notices'), $target->getBestName()),
'nav_timeline_favorites'); ($scoped instanceof Profile && $target->id === $scoped->id && $menu->actionName === 'showfavorites'),
'nav_timeline_favorites'
);
} }
public function onEndPublicGroupNav(Menu $menu) public function onEndPublicGroupNav(Menu $menu)
{ {
if (!common_config('singleuser', 'enabled')) { if (!common_config('singleuser', 'enabled')) {
// TRANS: Menu item in search group navigation panel. // TRANS: Menu item in search group navigation panel.
$menu->out->menuItem(common_local_url('favorited'), _m('MENU','Popular'), $menu->out->menuItem(
// TRANS: Menu item title in search group navigation panel. common_local_url('favorited'),
_('Popular notices'), $menu->actionName == 'favorited', 'nav_timeline_favorited'); _m('MENU', 'Popular'),
// TRANS: Menu item title in search group navigation panel.
_('Popular notices'),
($menu->actionName === 'favorited'),
'nav_timeline_favorited'
);
} }
} }
@ -519,7 +579,7 @@ class FavoriteModule extends ActivityVerbHandlerModule
{ {
if ($action->isPost()) { if ($action->isPost()) {
// The below tests are only for presenting to the user. POSTs which inflict // The below tests are only for presenting to the user. POSTs which inflict
// duplicate favorite entries are handled with AlreadyFulfilledException. // duplicate favorite entries are handled with AlreadyFulfilledException.
return false; return false;
} }
@ -529,9 +589,13 @@ class FavoriteModule extends ActivityVerbHandlerModule
switch (true) { switch (true) {
case $exists && ActivityUtils::compareVerbs($verb, array(ActivityVerb::FAVORITE, ActivityVerb::LIKE)): case $exists && ActivityUtils::compareVerbs($verb, array(ActivityVerb::FAVORITE, ActivityVerb::LIKE)):
case !$exists && ActivityUtils::compareVerbs($verb, array(ActivityVerb::UNFAVORITE, ActivityVerb::UNLIKE)): case !$exists && ActivityUtils::compareVerbs($verb, array(ActivityVerb::UNFAVORITE, ActivityVerb::UNLIKE)):
common_redirect(common_local_url('activityverb', common_redirect(common_local_url(
array('id' => $target->getID(), 'activityverb',
'verb' => ActivityUtils::resolveUri($expected_verb, true)))); [
'id' => $target->getID(),
'verb' => ActivityUtils::resolveUri($expected_verb, true),
]
));
break; break;
default: default:
// No need to redirect as we are on the correct action already. // No need to redirect as we are on the correct action already.
@ -617,23 +681,23 @@ function mail_notify_fave(User $rcpt, Profile $sender, Notice $notice)
// TRANS: %3$s is a URL to the faved notice, %4$s is the faved notice text, // TRANS: %3$s is a URL to the faved notice, %4$s is the faved notice text,
// TRANS: %5$s is a URL to all faves of the adding user, %6$s is the StatusNet sitename, // TRANS: %5$s is a URL to all faves of the adding user, %6$s is the StatusNet sitename,
// TRANS: %7$s is the adding user's nickname. // TRANS: %7$s is the adding user's nickname.
$body = sprintf(_("%1\$s (@%7\$s) just added your notice from %2\$s". $body = sprintf(
" as one of their favorites.\n\n" . _("%1\$s (@%7\$s) just added your notice from %2\$s".
"The URL of your notice is:\n\n" . " as one of their favorites.\n\n" .
"%3\$s\n\n" . "The URL of your notice is:\n\n" .
"The text of your notice is:\n\n" . "%3\$s\n\n" .
"%4\$s\n\n" . "The text of your notice is:\n\n" .
"You can see the list of %1\$s's favorites here:\n\n" . "%4\$s\n\n" .
"%5\$s"), "You can see the list of %1\$s's favorites here:\n\n" .
$bestname, "%5\$s"),
common_exact_date($notice->created), $bestname,
common_local_url('shownotice', common_exact_date($notice->created),
array('notice' => $notice->id)), common_local_url('shownotice', ['notice' => $notice->id]),
$notice->content, $notice->content,
common_local_url('showfavorites', common_local_url('showfavorites', ['nickname' => $sender->getNickname()]),
array('nickname' => $sender->getNickname())), common_config('site', 'name'),
common_config('site', 'name'), $sender->getNickname()
$sender->getNickname()) . ) .
mail_footer_block(); mail_footer_block();
$headers = _mail_prepare_headers('fave', $rcpt->getNickname(), $sender->getNickname()); $headers = _mail_prepare_headers('fave', $rcpt->getNickname(), $sender->getNickname());

View File

@ -1,32 +1,31 @@
<?php <?php
/* // This file is part of GNU social - https://www.gnu.org/software/social
* StatusNet - the distributed open-source microblogging tool //
* Copyright (C) 2009-2010, StatusNet, Inc. // 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
* This program is free software: you can redistribute it and/or modify // the Free Software Foundation, either version 3 of the License, or
* it under the terms of the GNU Affero General Public License as published by // (at your option) any later version.
* 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
* This program is distributed in the hope that it will be useful, // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* but WITHOUT ANY WARRANTY; without even the implied warranty of // GNU Affero General Public License for more details.
* 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/>.
* 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/>.
*/
/** /**
* OStatusPlugin implementation for GNU Social * OStatusPlugin implementation for GNU Social
*
* Depends on: WebFinger plugin * Depends on: WebFinger plugin
* *
* @package OStatusPlugin * @package OStatusPlugin
* @maintainer Brion Vibber <brion@status.net> * @author Brion Vibber <brion@status.net>
* @copyright 2009-2010 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/ */
if (!defined('GNUSOCIAL')) { exit(1); }
defined('GNUSOCIAL') || die();
require_once __DIR__ . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'util.php'; require_once __DIR__ . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'util.php';
@ -43,44 +42,68 @@ class OStatusPlugin extends Plugin
public function onRouterInitialized(URLMapper $m) public function onRouterInitialized(URLMapper $m)
{ {
// Discovery actions // Discovery actions
$m->connect('main/ostatustag', $m->connect(
['action' => 'ostatustag']); 'main/ostatustag',
$m->connect('main/ostatustag?nickname=:nickname', ['action' => 'ostatustag']
['action' => 'ostatustag'], );
['nickname' => '[A-Za-z0-9_-]+']); $m->connect(
$m->connect('main/ostatus/group/:group', 'main/ostatustag?nickname=:nickname',
['action' => 'ostatusinit'], ['action' => 'ostatustag'],
['group' => '[A-Za-z0-9_-]+']); ['nickname' => '[A-Za-z0-9_-]+']
$m->connect('main/ostatus/peopletag/:peopletag/tagger/:tagger', );
['action' => 'ostatusinit'], $m->connect(
['tagger' => '[A-Za-z0-9_-]+', 'main/ostatus/group/:group',
'peopletag' => '[A-Za-z0-9_-]+']); ['action' => 'ostatusinit'],
$m->connect('main/ostatus', ['group' => '[A-Za-z0-9_-]+']
['action' => 'ostatusinit']); );
$m->connect(
'main/ostatus/peopletag/:peopletag/tagger/:tagger',
['action' => 'ostatusinit'],
[
'tagger' => '[A-Za-z0-9_-]+',
'peopletag' => '[A-Za-z0-9_-]+',
]
);
$m->connect(
'main/ostatus',
['action' => 'ostatusinit']
);
// Remote subscription actions // Remote subscription actions
$m->connect('main/ostatusgroup', $m->connect(
['action' => 'ostatusgroup']); 'main/ostatusgroup',
$m->connect('main/ostatuspeopletag', ['action' => 'ostatusgroup']
['action' => 'ostatuspeopletag']); );
$m->connect(
'main/ostatuspeopletag',
['action' => 'ostatuspeopletag']
);
// WebSub actions // WebSub actions
$m->connect('main/push/hub', ['action' => 'pushhub']); $m->connect('main/push/hub', ['action' => 'pushhub']);
$m->connect('main/push/callback/:feed', $m->connect(
['action' => 'pushcallback'], 'main/push/callback/:feed',
['feed' => '[0-9]+']); ['action' => 'pushcallback'],
['feed' => '[0-9]+']
);
// Salmon endpoint // Salmon endpoint
$m->connect('main/salmon/user/:id', $m->connect(
['action' => 'usersalmon'], 'main/salmon/user/:id',
['id' => '[0-9]+']); ['action' => 'usersalmon'],
$m->connect('main/salmon/group/:id', ['id' => '[0-9]+']
['action' => 'groupsalmon'], );
['id' => '[0-9]+']); $m->connect(
$m->connect('main/salmon/peopletag/:id', 'main/salmon/group/:id',
['action' => 'peopletagsalmon'], ['action' => 'groupsalmon'],
['id' => '[0-9]+']); ['id' => '[0-9]+']
);
$m->connect(
'main/salmon/peopletag/:id',
['action' => 'peopletagsalmon'],
['id' => '[0-9]+']
);
return true; return true;
} }
@ -89,7 +112,7 @@ class OStatusPlugin extends Plugin
* @param QueueManager $qm * @param QueueManager $qm
* @return boolean hook return * @return boolean hook return
*/ */
function onEndInitializeQueueManager(QueueManager $qm) public function onEndInitializeQueueManager(QueueManager $qm)
{ {
// Prepare outgoing distributions after notice save. // Prepare outgoing distributions after notice save.
$qm->connect('ostatus', 'OStatusQueueHandler'); $qm->connect('ostatus', 'OStatusQueueHandler');
@ -114,7 +137,7 @@ class OStatusPlugin extends Plugin
/** /**
* Put saved notices into the queue for pubsub distribution. * Put saved notices into the queue for pubsub distribution.
*/ */
function onStartEnqueueNotice($notice, &$transports) public function onStartEnqueueNotice($notice, &$transports)
{ {
if ($notice->inScope(null) && $notice->getProfile()->hasRight(Right::PUBLICNOTICE)) { if ($notice->inScope(null) && $notice->getProfile()->hasRight(Right::PUBLICNOTICE)) {
$transports[] = 'ostatus'; $transports[] = 'ostatus';
@ -131,7 +154,7 @@ class OStatusPlugin extends Plugin
* Set up a WebSub hub link to our internal link for canonical timeline * Set up a WebSub hub link to our internal link for canonical timeline
* Atom feeds for users and groups. * Atom feeds for users and groups.
*/ */
function onStartApiAtom($feed) public function onStartApiAtom($feed)
{ {
$id = null; $id = null;
@ -140,11 +163,11 @@ class OStatusPlugin extends Plugin
$user = $feed->getUser(); $user = $feed->getUser();
$id = $user->id; $id = $user->id;
$profile = $user->getProfile(); $profile = $user->getProfile();
} else if ($feed instanceof AtomGroupNoticeFeed) { } elseif ($feed instanceof AtomGroupNoticeFeed) {
$salmonAction = 'groupsalmon'; $salmonAction = 'groupsalmon';
$group = $feed->getGroup(); $group = $feed->getGroup();
$id = $group->id; $id = $group->id;
} else if ($feed instanceof AtomListNoticeFeed) { } elseif ($feed instanceof AtomListNoticeFeed) {
$salmonAction = 'peopletagsalmon'; $salmonAction = 'peopletagsalmon';
$peopletag = $feed->getList(); $peopletag = $feed->getList();
$id = $peopletag->id; $id = $peopletag->id;
@ -179,25 +202,32 @@ class OStatusPlugin extends Plugin
* @param Profile $profile * @param Profile $profile
* @return bool hook return value * @return bool hook return value
*/ */
function onStartProfileRemoteSubscribe(HTMLOutputter $output, Profile $profile): bool public function onStartProfileRemoteSubscribe(HTMLOutputter $output, Profile $profile): bool
{ {
$this->onStartProfileListItemActionElements($output); $this->onStartProfileListItemActionElements($output);
return true; return true;
} }
function onStartGroupSubscribe($widget, $group) public function onStartGroupSubscribe($widget, $group)
{ {
$cur = common_current_user(); $cur = common_current_user();
if (empty($cur)) { if (empty($cur)) {
$widget->out->elementStart('li', 'entity_subscribe'); $widget->out->elementStart('li', 'entity_subscribe');
$url = common_local_url('ostatusinit', $url = common_local_url(
array('group' => $group->nickname)); 'ostatusinit',
$widget->out->element('a', array('href' => $url, ['group' => $group->nickname]
'class' => 'entity_remote_subscribe'), );
// TRANS: Link to subscribe to a remote entity. $widget->out->element(
_m('Subscribe')); 'a',
[
'href' => $url,
'class' => 'entity_remote_subscribe',
],
// TRANS: Link to subscribe to a remote entity.
_m('Subscribe')
);
$widget->out->elementEnd('li'); $widget->out->elementEnd('li');
return false; return false;
@ -206,19 +236,26 @@ class OStatusPlugin extends Plugin
return true; return true;
} }
function onStartSubscribePeopletagForm($output, $peopletag) public function onStartSubscribePeopletagForm($output, $peopletag)
{ {
$cur = common_current_user(); $cur = common_current_user();
if (empty($cur)) { if (empty($cur)) {
$output->elementStart('li', 'entity_subscribe'); $output->elementStart('li', 'entity_subscribe');
$profile = $peopletag->getTagger(); $profile = $peopletag->getTagger();
$url = common_local_url('ostatusinit', $url = common_local_url(
array('tagger' => $profile->nickname, 'peopletag' => $peopletag->tag)); 'ostatusinit',
$output->element('a', array('href' => $url, ['tagger' => $profile->nickname, 'peopletag' => $peopletag->tag]
'class' => 'entity_remote_subscribe'), );
// TRANS: Link to subscribe to a remote entity. $output->element(
_m('Subscribe')); 'a',
[
'href' => $url,
'class' => 'entity_remote_subscribe',
],
// TRANS: Link to subscribe to a remote entity.
_m('Subscribe')
);
$output->elementEnd('li'); $output->elementEnd('li');
return false; return false;
@ -230,10 +267,11 @@ class OStatusPlugin extends Plugin
/* /*
* If the field being looked for is URI look for the profile * If the field being looked for is URI look for the profile
*/ */
function onStartProfileCompletionSearch($action, $profile, $search_engine) { public function onStartProfileCompletionSearch($action, $profile, $search_engine)
{
if ($action->field == 'uri') { if ($action->field == 'uri') {
$profile->joinAdd(array('id', 'user:id')); $profile->joinAdd(['id', 'user:id']);
$profile->whereAdd('uri LIKE "%' . $profile->escape($q) . '%"'); $profile->whereAdd("uri LIKE '%" . $profile->escape($q) . "%'");
$profile->query(); $profile->query();
$validate = new Validate(); $validate = new Validate();
@ -242,17 +280,16 @@ class OStatusPlugin extends Plugin
try { try {
if ($validate->email($q)) { if ($validate->email($q)) {
$oprofile = Ostatus_profile::ensureWebfinger($q); $oprofile = Ostatus_profile::ensureWebfinger($q);
} else if ($validate->uri($q)) { } elseif ($validate->uri($q)) {
$oprofile = Ostatus_profile::ensureProfileURL($q); $oprofile = Ostatus_profile::ensureProfileURL($q);
} else { } else {
// TRANS: Exception in OStatus when invalid URI was entered. // TRANS: Exception in OStatus when invalid URI was entered.
throw new Exception(_m('Invalid URI.')); throw new Exception(_m('Invalid URI.'));
} }
return $this->filter(array($oprofile->localProfile())); return $this->filter(array($oprofile->localProfile()));
} catch (Exception $e) { } catch (Exception $e) {
// TRANS: Error message in OStatus plugin. Do not translate the domain names example.com // TRANS: Error message in OStatus plugin. Do not translate the domain names example.com
// TRANS: and example.net, as these are official standard domain names for use in examples. // TRANS: and example.net, as these are official standard domain names for use in examples.
$this->msg = _m("Sorry, we could not reach that address. Please make sure that the OStatus address is like nickname@example.com or http://example.net/nickname."); $this->msg = _m("Sorry, we could not reach that address. Please make sure that the OStatus address is like nickname@example.com or http://example.net/nickname.");
return array(); return array();
} }
@ -269,13 +306,15 @@ class OStatusPlugin extends Plugin
* *
* @return array The matching IDs (without $preMention) and each respective position in the given string. * @return array The matching IDs (without $preMention) and each respective position in the given string.
*/ */
static function extractWebfingerIds($text, $preMention='@') public static function extractWebfingerIds($text, $preMention = '@')
{ {
$wmatches = array(); $wmatches = array();
$result = preg_match_all('/(?<!\S)'.preg_quote($preMention, '/').'('.Nickname::WEBFINGER_FMT.')/', $result = preg_match_all(
$text, '/(?<!\S)' . preg_quote($preMention, '/') . '(' . Nickname::WEBFINGER_FMT . ')/',
$wmatches, $text,
PREG_OFFSET_CAPTURE); $wmatches,
PREG_OFFSET_CAPTURE
);
if ($result === false) { if ($result === false) {
common_log(LOG_ERR, __METHOD__ . ': Error parsing webfinger IDs from text (preg_last_error=='.preg_last_error().').'); common_log(LOG_ERR, __METHOD__ . ': Error parsing webfinger IDs from text (preg_last_error=='.preg_last_error().').');
return []; return [];
@ -292,15 +331,17 @@ class OStatusPlugin extends Plugin
* *
* @return array The matching URLs (without @ or acct:) and each respective position in the given string. * @return array The matching URLs (without @ or acct:) and each respective position in the given string.
*/ */
static function extractUrlMentions($text, $preMention='@') public static function extractUrlMentions($text, $preMention = '@')
{ {
$wmatches = array(); $wmatches = array();
// In the regexp below we need to match / _before_ URL_REGEX_VALID_PATH_CHARS because it otherwise gets merged // In the regexp below we need to match / _before_ URL_REGEX_VALID_PATH_CHARS because it otherwise gets merged
// with the TLD before (but / is in URL_REGEX_VALID_PATH_CHARS anyway, it's just its positioning that is important) // with the TLD before (but / is in URL_REGEX_VALID_PATH_CHARS anyway, it's just its positioning that is important)
$result = preg_match_all('/(?:^|\s+)'.preg_quote($preMention, '/').'('.URL_REGEX_DOMAIN_NAME.'(?:\/['.URL_REGEX_VALID_PATH_CHARS.']*)*)/', $result = preg_match_all(
$text, '/(?:^|\s+)' . preg_quote($preMention, '/') . '(' . URL_REGEX_DOMAIN_NAME . '(?:\/[' . URL_REGEX_VALID_PATH_CHARS . ']*)*)/',
$wmatches, $text,
PREG_OFFSET_CAPTURE); $wmatches,
PREG_OFFSET_CAPTURE
);
if ($result === false) { if ($result === false) {
common_log(LOG_ERR, __METHOD__ . ': Error parsing profile URL mentions from text (preg_last_error=='.preg_last_error().').'); common_log(LOG_ERR, __METHOD__ . ': Error parsing profile URL mentions from text (preg_last_error=='.preg_last_error().').');
return []; return [];
@ -319,7 +360,7 @@ class OStatusPlugin extends Plugin
* @param array &$mention in/out param: set of found mentions * @param array &$mention in/out param: set of found mentions
* @return boolean hook return value * @return boolean hook return value
*/ */
function onEndFindMentions(Profile $sender, $text, &$mentions) public function onEndFindMentions(Profile $sender, $text, &$mentions)
{ {
$matches = array(); $matches = array();
@ -472,7 +513,7 @@ class OStatusPlugin extends Plugin
* @param Profile &$profile * @param Profile &$profile
* @return hook return code * @return hook return code
*/ */
function onStartCommandGetProfile($command, $arg, &$profile) public function onStartCommandGetProfile($command, $arg, &$profile)
{ {
$oprofile = $this->pullRemoteProfile($arg); $oprofile = $this->pullRemoteProfile($arg);
if ($oprofile instanceof Ostatus_profile && !$oprofile->isGroup()) { if ($oprofile instanceof Ostatus_profile && !$oprofile->isGroup()) {
@ -499,7 +540,7 @@ class OStatusPlugin extends Plugin
* @param User_group &$group * @param User_group &$group
* @return hook return code * @return hook return code
*/ */
function onStartCommandGetGroup($command, $arg, &$group) public function onStartCommandGetGroup($command, $arg, &$group)
{ {
$oprofile = $this->pullRemoteProfile($arg); $oprofile = $this->pullRemoteProfile($arg);
if ($oprofile instanceof Ostatus_profile && $oprofile->isGroup()) { if ($oprofile instanceof Ostatus_profile && $oprofile->isGroup()) {
@ -546,21 +587,24 @@ class OStatusPlugin extends Plugin
return null; return null;
} }
function onEndProfileSettingsActions($out) { public function onEndProfileSettingsActions($out) {
$siteName = common_config('site', 'name'); $siteName = common_config('site', 'name');
$js = 'navigator.registerContentHandler("application/vnd.mozilla.maybe.feed", "'.addslashes(common_local_url('RemoteFollowSub', null, array('profile' => '%s'))).'", "'.addslashes($siteName).'")'; $js = 'navigator.registerContentHandler("application/vnd.mozilla.maybe.feed", "'.addslashes(common_local_url('RemoteFollowSub', null, array('profile' => '%s'))).'", "'.addslashes($siteName).'")';
$out->elementStart('li'); $out->elementStart('li');
$out->element('a', $out->element(
array('href' => 'javascript:'.$js), 'a',
// TRANS: Option in profile settings to add this instance to Firefox as a feedreader ['href' => 'javascript:' . $js],
_('Add to Firefox as feedreader')); // TRANS: Option in profile settings to add this instance to Firefox as a feedreader
_('Add to Firefox as feedreader')
);
$out->elementEnd('li'); $out->elementEnd('li');
} }
/** /**
* Make sure necessary tables are filled out. * Make sure necessary tables are filled out.
*/ */
function onCheckSchema() { public function onCheckSchema()
{
$schema = Schema::get(); $schema = Schema::get();
$schema->ensureTable('ostatus_profile', Ostatus_profile::schemaDef()); $schema->ensureTable('ostatus_profile', Ostatus_profile::schemaDef());
$schema->ensureTable('feedsub', FeedSub::schemaDef()); $schema->ensureTable('feedsub', FeedSub::schemaDef());
@ -569,12 +613,14 @@ class OStatusPlugin extends Plugin
return true; return true;
} }
public function onEndShowStylesheets(Action $action) { public function onEndShowStylesheets(Action $action)
{
$action->cssLink($this->path('theme/base/css/ostatus.css')); $action->cssLink($this->path('theme/base/css/ostatus.css'));
return true; return true;
} }
function onEndShowStatusNetScripts($action) { public function onEndShowStatusNetScripts($action)
{
$action->script($this->path('js/ostatus.js')); $action->script($this->path('js/ostatus.js'));
return true; return true;
} }
@ -589,7 +635,7 @@ class OStatusPlugin extends Plugin
* @param string out &$title * @param string out &$title
* @return mixed hook return code * @return mixed hook return code
*/ */
function onStartNoticeSourceLink($notice, &$name, &$url, &$title) public function onStartNoticeSourceLink($notice, &$name, &$url, &$title)
{ {
// If we don't handle this, keep the event handler going // If we don't handle this, keep the event handler going
if (!in_array($notice->source, array('ostatus', 'share'))) { if (!in_array($notice->source, array('ostatus', 'share'))) {
@ -626,7 +672,7 @@ class OStatusPlugin extends Plugin
* @param DOMDocument $feed * @param DOMDocument $feed
* @return mixed hook return code * @return mixed hook return code
*/ */
function onStartFeedSubReceive($feedsub, $feed) public function onStartFeedSubReceive($feedsub, $feed)
{ {
$oprofile = Ostatus_profile::getKV('feeduri', $feedsub->uri); $oprofile = Ostatus_profile::getKV('feeduri', $feedsub->uri);
if ($oprofile instanceof Ostatus_profile) { if ($oprofile instanceof Ostatus_profile) {
@ -645,7 +691,7 @@ class OStatusPlugin extends Plugin
* @param integer $count in/out * @param integer $count in/out
* @return mixed hook return code * @return mixed hook return code
*/ */
function onFeedSubSubscriberCount($feedsub, &$count) public function onFeedSubSubscriberCount($feedsub, &$count)
{ {
$oprofile = Ostatus_profile::getKV('feeduri', $feedsub->uri); $oprofile = Ostatus_profile::getKV('feeduri', $feedsub->uri);
if ($oprofile instanceof Ostatus_profile) { if ($oprofile instanceof Ostatus_profile) {
@ -668,7 +714,7 @@ class OStatusPlugin extends Plugin
* *
* @throws Exception * @throws Exception
*/ */
function onStartSubscribe(Profile $profile, Profile $other) public function onStartSubscribe(Profile $profile, Profile $other)
{ {
if (!$profile->isLocal()) { if (!$profile->isLocal()) {
return true; return true;
@ -693,7 +739,7 @@ class OStatusPlugin extends Plugin
* *
* @throws Exception * @throws Exception
*/ */
function onEndSubscribe(Profile $profile, Profile $other) public function onEndSubscribe(Profile $profile, Profile $other)
{ {
if (!$profile->isLocal()) { if (!$profile->isLocal()) {
return true; return true;
@ -722,7 +768,7 @@ class OStatusPlugin extends Plugin
* @param Profile $other * @param Profile $other
* @return hook return value * @return hook return value
*/ */
function onEndUnsubscribe(Profile $profile, Profile $other) public function onEndUnsubscribe(Profile $profile, Profile $other)
{ {
if (!$profile->isLocal()) { if (!$profile->isLocal()) {
return true; return true;
@ -740,19 +786,23 @@ class OStatusPlugin extends Plugin
$act->verb = ActivityVerb::UNFOLLOW; $act->verb = ActivityVerb::UNFOLLOW;
$act->id = TagURI::mint('unfollow:%d:%d:%s', $act->id = TagURI::mint(
$profile->id, 'unfollow:%d:%d:%s',
$other->id, $profile->id,
common_date_iso8601(time())); $other->id,
common_date_iso8601(time())
);
$act->time = time(); $act->time = time();
// TRANS: Title for unfollowing a remote profile. // TRANS: Title for unfollowing a remote profile.
$act->title = _m('TITLE','Unfollow'); $act->title = _m('TITLE', 'Unfollow');
// TRANS: Success message for unsubscribe from user attempt through OStatus. // TRANS: Success message for unsubscribe from user attempt through OStatus.
// TRANS: %1$s is the unsubscriber's name, %2$s is the unsubscribed user's name. // TRANS: %1$s is the unsubscriber's name, %2$s is the unsubscribed user's name.
$act->content = sprintf(_m('%1$s stopped following %2$s.'), $act->content = sprintf(
$profile->getBestName(), _m('%1$s stopped following %2$s.'),
$other->getBestName()); $profile->getBestName(),
$other->getBestName()
);
$act->actor = $profile->asActivityObject(); $act->actor = $profile->asActivityObject();
$act->objects[] = $other->asActivityObject(); $act->objects[] = $other->asActivityObject();
@ -773,7 +823,7 @@ class OStatusPlugin extends Plugin
* @return mixed hook return value * @return mixed hook return value
* @throws Exception of various kinds, some from $oprofile->subscribe(); * @throws Exception of various kinds, some from $oprofile->subscribe();
*/ */
function onStartJoinGroup($group, $profile) public function onStartJoinGroup($group, $profile)
{ {
$oprofile = Ostatus_profile::getKV('group_id', $group->id); $oprofile = Ostatus_profile::getKV('group_id', $group->id);
if (!$oprofile instanceof Ostatus_profile) { if (!$oprofile instanceof Ostatus_profile) {
@ -786,10 +836,12 @@ class OStatusPlugin extends Plugin
// has not yet been created. // has not yet been created.
$act = new Activity(); $act = new Activity();
$act->id = TagURI::mint('join:%d:%d:%s', $act->id = TagURI::mint(
$profile->id, 'join:%d:%d:%s',
$group->id, $profile->id,
common_date_iso8601(time())); $group->id,
common_date_iso8601(time())
);
$act->actor = $profile->asActivityObject(); $act->actor = $profile->asActivityObject();
$act->verb = ActivityVerb::JOIN; $act->verb = ActivityVerb::JOIN;
@ -797,12 +849,14 @@ class OStatusPlugin extends Plugin
$act->time = time(); $act->time = time();
// TRANS: Title for joining a remote groep. // TRANS: Title for joining a remote groep.
$act->title = _m('TITLE','Join'); $act->title = _m('TITLE', 'Join');
// TRANS: Success message for subscribe to group attempt through OStatus. // 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. // TRANS: %1$s is the member name, %2$s is the subscribed group's name.
$act->content = sprintf(_m('%1$s has joined group %2$s.'), $act->content = sprintf(
$profile->getBestName(), _m('%1$s has joined group %2$s.'),
$oprofile->getBestName()); $profile->getBestName(),
$oprofile->getBestName()
);
if ($oprofile->notifyActivity($act, $profile)) { if ($oprofile->notifyActivity($act, $profile)) {
return true; return true;
@ -827,7 +881,7 @@ class OStatusPlugin extends Plugin
* *
* @return mixed hook return value * @return mixed hook return value
*/ */
function onEndLeaveGroup($group, $profile) public function onEndLeaveGroup($group, $profile)
{ {
$oprofile = Ostatus_profile::getKV('group_id', $group->id); $oprofile = Ostatus_profile::getKV('group_id', $group->id);
if (!$oprofile instanceof Ostatus_profile) { if (!$oprofile instanceof Ostatus_profile) {
@ -840,10 +894,12 @@ class OStatusPlugin extends Plugin
$member = $profile; $member = $profile;
$act = new Activity(); $act = new Activity();
$act->id = TagURI::mint('leave:%d:%d:%s', $act->id = TagURI::mint(
$member->id, 'leave:%d:%d:%s',
$group->id, $member->id,
common_date_iso8601(time())); $group->id,
common_date_iso8601(time())
);
$act->actor = $member->asActivityObject(); $act->actor = $member->asActivityObject();
$act->verb = ActivityVerb::LEAVE; $act->verb = ActivityVerb::LEAVE;
@ -851,12 +907,14 @@ class OStatusPlugin extends Plugin
$act->time = time(); $act->time = time();
// TRANS: Title for leaving a remote group. // TRANS: Title for leaving a remote group.
$act->title = _m('TITLE','Leave'); $act->title = _m('TITLE', 'Leave');
// TRANS: Success message for unsubscribe from group attempt through OStatus. // TRANS: Success message for unsubscribe from group attempt through OStatus.
// TRANS: %1$s is the member name, %2$s is the unsubscribed group's name. // TRANS: %1$s is the member name, %2$s is the unsubscribed group's name.
$act->content = sprintf(_m('%1$s has left group %2$s.'), $act->content = sprintf(
$member->getBestName(), _m('%1$s has left group %2$s.'),
$oprofile->getBestName()); $member->getBestName(),
$oprofile->getBestName()
);
$oprofile->notifyActivity($act, $member); $oprofile->notifyActivity($act, $member);
} }
@ -873,7 +931,7 @@ class OStatusPlugin extends Plugin
* @throws Exception of various kinds, some from $oprofile->subscribe(); * @throws Exception of various kinds, some from $oprofile->subscribe();
*/ */
function onStartSubscribePeopletag($peopletag, $user) public function onStartSubscribePeopletag($peopletag, $user)
{ {
$oprofile = Ostatus_profile::getKV('peopletag_id', $peopletag->id); $oprofile = Ostatus_profile::getKV('peopletag_id', $peopletag->id);
if (!$oprofile instanceof Ostatus_profile) { if (!$oprofile instanceof Ostatus_profile) {
@ -886,10 +944,12 @@ class OStatusPlugin extends Plugin
$tagger = Profile::getKV($peopletag->tagger); $tagger = Profile::getKV($peopletag->tagger);
$act = new Activity(); $act = new Activity();
$act->id = TagURI::mint('subscribe_peopletag:%d:%d:%s', $act->id = TagURI::mint(
$sub->id, 'subscribe_peopletag:%d:%d:%s',
$peopletag->id, $sub->id,
common_date_iso8601(time())); $peopletag->id,
common_date_iso8601(time())
);
$act->actor = $sub->asActivityObject(); $act->actor = $sub->asActivityObject();
$act->verb = ActivityVerb::FOLLOW; $act->verb = ActivityVerb::FOLLOW;
@ -897,13 +957,15 @@ class OStatusPlugin extends Plugin
$act->time = time(); $act->time = time();
// TRANS: Title for following a remote list. // TRANS: Title for following a remote list.
$act->title = _m('TITLE','Follow list'); $act->title = _m('TITLE', 'Follow list');
// TRANS: Success message for remote list follow through OStatus. // TRANS: Success message for remote list follow through OStatus.
// TRANS: %1$s is the subscriber name, %2$s is the list, %3$s is the lister's name. // TRANS: %1$s is the subscriber name, %2$s is the list, %3$s is the lister's name.
$act->content = sprintf(_m('%1$s is now following people listed in %2$s by %3$s.'), $act->content = sprintf(
$sub->getBestName(), _m('%1$s is now following people listed in %2$s by %3$s.'),
$oprofile->getBestName(), $sub->getBestName(),
$tagger->getBestName()); $oprofile->getBestName(),
$tagger->getBestName()
);
if ($oprofile->notifyActivity($act, $sub)) { if ($oprofile->notifyActivity($act, $sub)) {
return true; return true;
@ -924,7 +986,7 @@ class OStatusPlugin extends Plugin
* @return mixed hook return value * @return mixed hook return value
*/ */
function onEndUnsubscribePeopletag($peopletag, $user) public function onEndUnsubscribePeopletag($peopletag, $user)
{ {
$oprofile = Ostatus_profile::getKV('peopletag_id', $peopletag->id); $oprofile = Ostatus_profile::getKV('peopletag_id', $peopletag->id);
if (!$oprofile instanceof Ostatus_profile) { if (!$oprofile instanceof Ostatus_profile) {
@ -938,10 +1000,12 @@ class OStatusPlugin extends Plugin
$tagger = Profile::getKV($peopletag->tagger); $tagger = Profile::getKV($peopletag->tagger);
$act = new Activity(); $act = new Activity();
$act->id = TagURI::mint('unsubscribe_peopletag:%d:%d:%s', $act->id = TagURI::mint(
$sub->id, 'unsubscribe_peopletag:%d:%d:%s',
$peopletag->id, $sub->id,
common_date_iso8601(time())); $peopletag->id,
common_date_iso8601(time())
);
$act->actor = $member->asActivityObject(); $act->actor = $member->asActivityObject();
$act->verb = ActivityVerb::UNFOLLOW; $act->verb = ActivityVerb::UNFOLLOW;
@ -952,10 +1016,12 @@ class OStatusPlugin extends Plugin
$act->title = _m('Unfollow list'); $act->title = _m('Unfollow list');
// TRANS: Success message for remote list unfollow through OStatus. // TRANS: Success message for remote list unfollow through OStatus.
// TRANS: %1$s is the subscriber name, %2$s is the list, %3$s is the lister's name. // TRANS: %1$s is the subscriber name, %2$s is the list, %3$s is the lister's name.
$act->content = sprintf(_m('%1$s stopped following the list %2$s by %3$s.'), $act->content = sprintf(
$sub->getBestName(), _m('%1$s stopped following the list %2$s by %3$s.'),
$oprofile->getBestName(), $sub->getBestName(),
$tagger->getBestName()); $oprofile->getBestName(),
$tagger->getBestName()
);
$oprofile->notifyActivity($act, $user); $oprofile->notifyActivity($act, $user);
} }
@ -967,7 +1033,7 @@ class OStatusPlugin extends Plugin
* @param Notice $notice being favored * @param Notice $notice being favored
* @return hook return value * @return hook return value
*/ */
function onEndFavorNotice(Profile $profile, Notice $notice) public function onEndFavorNotice(Profile $profile, Notice $notice)
{ {
// Only distribute local users' favor actions, remote users // Only distribute local users' favor actions, remote users
// will have already distributed theirs. // will have already distributed theirs.
@ -1005,7 +1071,7 @@ class OStatusPlugin extends Plugin
* @return hook return value * @return hook return value
* @throws Exception of various kinds, some from $oprofile->subscribe(); * @throws Exception of various kinds, some from $oprofile->subscribe();
*/ */
function onEndTagProfile($ptag) public function onEndTagProfile($ptag)
{ {
$oprofile = Ostatus_profile::getKV('profile_id', $ptag->tagged); $oprofile = Ostatus_profile::getKV('profile_id', $ptag->tagged);
if (!$oprofile instanceof Ostatus_profile) { if (!$oprofile instanceof Ostatus_profile) {
@ -1023,18 +1089,23 @@ class OStatusPlugin extends Plugin
$tagged = Profile::getKV('id', $ptag->tagged); $tagged = Profile::getKV('id', $ptag->tagged);
$act->verb = ActivityVerb::TAG; $act->verb = ActivityVerb::TAG;
$act->id = TagURI::mint('tag_profile:%d:%d:%s', $act->id = TagURI::mint(
$plist->tagger, $plist->id, 'tag_profile:%d:%d:%s',
common_date_iso8601(time())); $plist->tagger,
$plist->id,
common_date_iso8601(time())
);
$act->time = time(); $act->time = time();
// TRANS: Title for listing a remote profile. // TRANS: Title for listing a remote profile.
$act->title = _m('TITLE','List'); $act->title = _m('TITLE', 'List');
// TRANS: Success message for remote list addition through OStatus. // TRANS: Success message for remote list addition through OStatus.
// TRANS: %1$s is the list creator's name, %2$s is the added list member, %3$s is the list name. // TRANS: %1$s is the list creator's name, %2$s is the added list member, %3$s is the list name.
$act->content = sprintf(_m('%1$s listed %2$s in the list %3$s.'), $act->content = sprintf(
$tagger->getBestName(), _m('%1$s listed %2$s in the list %3$s.'),
$tagged->getBestName(), $tagger->getBestName(),
$plist->getBestName()); $tagged->getBestName(),
$plist->getBestName()
);
$act->actor = $tagger->asActivityObject(); $act->actor = $tagger->asActivityObject();
$act->objects = array($tagged->asActivityObject()); $act->objects = array($tagged->asActivityObject());
@ -1056,7 +1127,7 @@ class OStatusPlugin extends Plugin
* @param Profile_tag $ptag the people tag that was deleted * @param Profile_tag $ptag the people tag that was deleted
* @return hook return value * @return hook return value
*/ */
function onEndUntagProfile($ptag) public function onEndUntagProfile($ptag)
{ {
$oprofile = Ostatus_profile::getKV('profile_id', $ptag->tagged); $oprofile = Ostatus_profile::getKV('profile_id', $ptag->tagged);
if (!$oprofile instanceof Ostatus_profile) { if (!$oprofile instanceof Ostatus_profile) {
@ -1074,18 +1145,23 @@ class OStatusPlugin extends Plugin
$tagged = Profile::getKV('id', $ptag->tagged); $tagged = Profile::getKV('id', $ptag->tagged);
$act->verb = ActivityVerb::UNTAG; $act->verb = ActivityVerb::UNTAG;
$act->id = TagURI::mint('untag_profile:%d:%d:%s', $act->id = TagURI::mint(
$plist->tagger, $plist->id, 'untag_profile:%d:%d:%s',
common_date_iso8601(time())); $plist->tagger,
$plist->id,
common_date_iso8601(time())
);
$act->time = time(); $act->time = time();
// TRANS: Title for unlisting a remote profile. // TRANS: Title for unlisting a remote profile.
$act->title = _m('TITLE','Unlist'); $act->title = _m('TITLE', 'Unlist');
// TRANS: Success message for remote list removal through OStatus. // TRANS: Success message for remote list removal through OStatus.
// TRANS: %1$s is the list creator's name, %2$s is the removed list member, %3$s is the list name. // TRANS: %1$s is the list creator's name, %2$s is the removed list member, %3$s is the list name.
$act->content = sprintf(_m('%1$s removed %2$s from the list %3$s.'), $act->content = sprintf(
$tagger->getBestName(), _m('%1$s removed %2$s from the list %3$s.'),
$tagged->getBestName(), $tagger->getBestName(),
$plist->getBestName()); $tagged->getBestName(),
$plist->getBestName()
);
$act->actor = $tagger->asActivityObject(); $act->actor = $tagger->asActivityObject();
$act->objects = array($tagged->asActivityObject()); $act->objects = array($tagged->asActivityObject());
@ -1107,7 +1183,7 @@ class OStatusPlugin extends Plugin
* *
* @return hook return value * @return hook return value
*/ */
function onEndDisfavorNotice(Profile $profile, Notice $notice) public function onEndDisfavorNotice(Profile $profile, Notice $notice)
{ {
// Only distribute local users' disfavor actions, remote users // Only distribute local users' disfavor actions, remote users
// will have already distributed theirs. // will have already distributed theirs.
@ -1123,18 +1199,22 @@ class OStatusPlugin extends Plugin
$act = new Activity(); $act = new Activity();
$act->verb = ActivityVerb::UNFAVORITE; $act->verb = ActivityVerb::UNFAVORITE;
$act->id = TagURI::mint('disfavor:%d:%d:%s', $act->id = TagURI::mint(
$profile->id, 'disfavor:%d:%d:%s',
$notice->id, $profile->id,
common_date_iso8601(time())); $notice->id,
common_date_iso8601(time())
);
$act->time = time(); $act->time = time();
// TRANS: Title for unliking a remote notice. // TRANS: Title for unliking a remote notice.
$act->title = _m('Unlike'); $act->title = _m('Unlike');
// TRANS: Success message for remove a favorite notice through OStatus. // TRANS: Success message for remove a favorite notice through OStatus.
// TRANS: %1$s is the unfavoring user's name, %2$s is URI to the no longer favored notice. // TRANS: %1$s is the unfavoring user's name, %2$s is URI to the no longer favored notice.
$act->content = sprintf(_m('%1$s no longer likes %2$s.'), $act->content = sprintf(
$profile->getBestName(), _m('%1$s no longer likes %2$s.'),
$notice->getUrl()); $profile->getBestName(),
$notice->getUrl()
);
$act->actor = $profile->asActivityObject(); $act->actor = $profile->asActivityObject();
$act->objects[] = $notice->asActivityObject(); $act->objects[] = $notice->asActivityObject();
@ -1144,7 +1224,7 @@ class OStatusPlugin extends Plugin
return true; return true;
} }
function onStartGetProfileUri($profile, &$uri) public function onStartGetProfileUri($profile, &$uri)
{ {
$oprofile = Ostatus_profile::getKV('profile_id', $profile->id); $oprofile = Ostatus_profile::getKV('profile_id', $profile->id);
if ($oprofile instanceof Ostatus_profile) { if ($oprofile instanceof Ostatus_profile) {
@ -1154,12 +1234,12 @@ class OStatusPlugin extends Plugin
return true; return true;
} }
function onStartUserGroupHomeUrl($group, &$url) public function onStartUserGroupHomeUrl($group, &$url)
{ {
return $this->onStartUserGroupPermalink($group, $url); return $this->onStartUserGroupPermalink($group, $url);
} }
function onStartUserGroupPermalink($group, &$url) public function onStartUserGroupPermalink($group, &$url)
{ {
$oprofile = Ostatus_profile::getKV('group_id', $group->id); $oprofile = Ostatus_profile::getKV('group_id', $group->id);
if ($oprofile instanceof Ostatus_profile) { if ($oprofile instanceof Ostatus_profile) {
@ -1170,21 +1250,21 @@ class OStatusPlugin extends Plugin
} }
} }
function onStartShowUserGroupsContent($action) public function onStartShowUserGroupsContent($action)
{ {
$this->showEntityRemoteSubscribe($action); $this->showEntityRemoteSubscribe($action);
return true; return true;
} }
function onEndShowGroupsMiniList($action) public function onEndShowGroupsMiniList($action)
{ {
$this->showEntityRemoteSubscribe($action); $this->showEntityRemoteSubscribe($action);
return true; return true;
} }
function showEntityRemoteSubscribe($action) public function showEntityRemoteSubscribe($action)
{ {
if (!$action->getScoped() instanceof Profile) { if (!$action->getScoped() instanceof Profile) {
// early return if we're not logged in // early return if we're not logged in
@ -1195,10 +1275,15 @@ class OStatusPlugin extends Plugin
$action->elementStart('div', 'entity_actions'); $action->elementStart('div', 'entity_actions');
$action->elementStart('p', array('id' => 'entity_remote_subscribe', $action->elementStart('p', array('id' => 'entity_remote_subscribe',
'class' => 'entity_subscribe')); 'class' => 'entity_subscribe'));
$action->element('a', array('href' => common_local_url('ostatusgroup'), $action->element(
'class' => 'entity_remote_subscribe'), 'a',
// TRANS: Link text for link to remote subscribe. [
_m('Remote')); 'href' => common_local_url('ostatusgroup'),
'class' => 'entity_remote_subscribe',
],
// TRANS: Link text for link to remote subscribe.
_m('Remote')
);
$action->elementEnd('p'); $action->elementEnd('p');
$action->elementEnd('div'); $action->elementEnd('div');
} }
@ -1208,7 +1293,7 @@ class OStatusPlugin extends Plugin
* Ping remote profiles with updates to this profile. * Ping remote profiles with updates to this profile.
* Salmon pings are queued for background processing. * Salmon pings are queued for background processing.
*/ */
function onEndBroadcastProfile(Profile $profile) public function onEndBroadcastProfile(Profile $profile)
{ {
$user = User::getKV('id', $profile->id); $user = User::getKV('id', $profile->id);
@ -1233,16 +1318,20 @@ class OStatusPlugin extends Plugin
$act = new Activity(); $act = new Activity();
$act->verb = ActivityVerb::UPDATE_PROFILE; $act->verb = ActivityVerb::UPDATE_PROFILE;
$act->id = TagURI::mint('update-profile:%d:%s', $act->id = TagURI::mint(
$profile->id, 'update-profile:%d:%s',
common_date_iso8601(time())); $profile->id,
common_date_iso8601(time())
);
$act->time = time(); $act->time = time();
// TRANS: Title for activity. // TRANS: Title for activity.
$act->title = _m('Profile update'); $act->title = _m('Profile update');
// TRANS: Ping text for remote profile update through OStatus. // TRANS: Ping text for remote profile update through OStatus.
// TRANS: %s is user that updated their profile. // TRANS: %s is user that updated their profile.
$act->content = sprintf(_m('%s has updated their profile page.'), $act->content = sprintf(
$profile->getBestName()); _m('%s has updated their profile page.'),
$profile->getBestName()
);
$act->actor = $profile->asActivityObject(); $act->actor = $profile->asActivityObject();
$act->objects[] = $act->actor; $act->objects[] = $act->actor;
@ -1254,7 +1343,7 @@ class OStatusPlugin extends Plugin
return true; return true;
} }
function onEndShowAccountProfileBlock(HTMLOutputter $out, Profile $profile) public function onEndShowAccountProfileBlock(HTMLOutputter $out, Profile $profile)
{ {
if ($profile->isLocal()) { if ($profile->isLocal()) {
return true; return true;
@ -1288,7 +1377,7 @@ class OStatusPlugin extends Plugin
} }
// FIXME: This one can accept both an Action and a Widget. Confusing! Refactor to (HTMLOutputter $out, Profile $target)! // FIXME: This one can accept both an Action and a Widget. Confusing! Refactor to (HTMLOutputter $out, Profile $target)!
function onStartProfileListItemActionElements($item) public function onStartProfileListItemActionElements($item)
{ {
if (common_logged_in()) { if (common_logged_in()) {
// only non-logged in users get to see the "remote subscribe" form // only non-logged in users get to see the "remote subscribe" form
@ -1314,8 +1403,10 @@ class OStatusPlugin extends Plugin
$output->elementStart('li', 'entity_tag'); $output->elementStart('li', 'entity_tag');
$url = common_local_url('ostatustag', ['nickname' => $target->getNickname()]); $url = common_local_url('ostatustag', ['nickname' => $target->getNickname()]);
$output->element('a', $output->element('a',
['href' => $url, [
'class' => 'entity_remote_tag'], 'href' => $url,
'class' => 'entity_remote_tag',
],
// TRANS: Link text for a user to list an OStatus user. // TRANS: Link text for a user to list an OStatus user.
_m('List')); _m('List'));
$output->elementEnd('li'); $output->elementEnd('li');
@ -1388,7 +1479,7 @@ class OStatusPlugin extends Plugin
return false; return false;
} }
function onStartGetProfileFromURI($uri, &$profile) public function onStartGetProfileFromURI($uri, &$profile)
{ {
// Don't want to do Web-based discovery on our own server, // Don't want to do Web-based discovery on our own server,
// so we check locally first. This duplicates the functionality // so we check locally first. This duplicates the functionality
@ -1417,7 +1508,7 @@ class OStatusPlugin extends Plugin
} }
} }
function onEndWebFingerNoticeLinks(XML_XRD $xrd, Notice $target) public function onEndWebFingerNoticeLinks(XML_XRD $xrd, Notice $target)
{ {
$salmon_url = null; $salmon_url = null;
$actor = $target->getProfile(); $actor = $target->getProfile();
@ -1439,16 +1530,19 @@ class OStatusPlugin extends Plugin
return true; return true;
} }
function onEndWebFingerProfileLinks(XML_XRD $xrd, Profile $target) public function onEndWebFingerProfileLinks(XML_XRD $xrd, Profile $target)
{ {
if ($target->getObjectType() === ActivityObject::PERSON) { if ($target->getObjectType() === ActivityObject::PERSON) {
$this->addWebFingerPersonLinks($xrd, $target); $this->addWebFingerPersonLinks($xrd, $target);
} elseif ($target->getObjectType() === ActivityObject::GROUP) { } elseif ($target->getObjectType() === ActivityObject::GROUP) {
$xrd->links[] = new XML_XRD_Element_Link(Discovery::UPDATESFROM, $xrd->links[] = new XML_XRD_Element_Link(
common_local_url('ApiTimelineGroup', Discovery::UPDATESFROM,
array('id' => $target->getGroup()->getID(), 'format' => 'atom')), common_local_url(
'application/atom+xml'); 'ApiTimelineGroup',
['id' => $target->getGroup()->getID(), 'format' => 'atom']
),
'application/atom+xml'
);
} }
// Salmon // Salmon
@ -1479,10 +1573,14 @@ class OStatusPlugin extends Plugin
protected function addWebFingerPersonLinks(XML_XRD $xrd, Profile $target) protected function addWebFingerPersonLinks(XML_XRD $xrd, Profile $target)
{ {
$xrd->links[] = new XML_XRD_Element_Link(Discovery::UPDATESFROM, $xrd->links[] = new XML_XRD_Element_Link(
common_local_url('ApiTimelineUser', Discovery::UPDATESFROM,
array('id' => $target->id, 'format' => 'atom')), common_local_url(
'application/atom+xml'); 'ApiTimelineUser',
['id' => $target->id, 'format' => 'atom']
),
'application/atom+xml'
);
// Get this profile's keypair // Get this profile's keypair
$magicsig = Magicsig::getKV('user_id', $target->id); $magicsig = Magicsig::getKV('user_id', $target->id);
@ -1494,8 +1592,10 @@ class OStatusPlugin extends Plugin
return false; // value doesn't mean anything, just figured I'd indicate this function didn't do anything return false; // value doesn't mean anything, just figured I'd indicate this function didn't do anything
} }
if (Event::handle('StartAttachPubkeyToUserXRD', array($magicsig, $xrd, $target))) { if (Event::handle('StartAttachPubkeyToUserXRD', array($magicsig, $xrd, $target))) {
$xrd->links[] = new XML_XRD_Element_Link(Magicsig::PUBLICKEYREL, $xrd->links[] = new XML_XRD_Element_Link(
'data:application/magic-public-key,'. $magicsig->toString()); Magicsig::PUBLICKEYREL,
'data:application/magic-public-key,' . $magicsig->toString()
);
// The following event handles plugins like Diaspora which add their own version of the Magicsig pubkey // The following event handles plugins like Diaspora which add their own version of the Magicsig pubkey
Event::handle('EndAttachPubkeyToUserXRD', array($magicsig, $xrd, $target)); Event::handle('EndAttachPubkeyToUserXRD', array($magicsig, $xrd, $target));
} }
@ -1507,7 +1607,7 @@ class OStatusPlugin extends Plugin
} }
// FIXME: Maybe this shouldn't be so authoritative that it breaks other remote profile lookups? // FIXME: Maybe this shouldn't be so authoritative that it breaks other remote profile lookups?
static public function onCheckActivityAuthorship(Activity $activity, Profile &$profile) public static function onCheckActivityAuthorship(Activity $activity, Profile &$profile)
{ {
try { try {
$oprofile = Ostatus_profile::ensureProfileURL($profile->getUrl()); $oprofile = Ostatus_profile::ensureProfileURL($profile->getUrl());
@ -1562,8 +1662,13 @@ class OStatusPlugin extends Plugin
// 201 Created is what Mastodon returns when it's ok // 201 Created is what Mastodon returns when it's ok
// 202 Accepted is what we get from Diaspora, also good // 202 Accepted is what we get from Diaspora, also good
if (!in_array($response->getStatus(), array(200, 201, 202))) { if (!in_array($response->getStatus(), array(200, 201, 202))) {
common_log(LOG_ERR, sprintf('Salmon (from profile %d) endpoint %s returned status %s: %s', common_log(LOG_ERR, sprintf(
$magic_env->getActor()->getID(), $endpoint_uri, $response->getStatus(), $response->getBody())); 'Salmon (from profile %d) endpoint %s returned status %s: %s',
$magic_env->getActor()->getID(),
$endpoint_uri,
$response->getStatus(),
$response->getBody()
));
return true; return true;
} }

View File

@ -1,36 +1,18 @@
<?php <?php
/** // This file is part of GNU social - https://www.gnu.org/software/social
* StatusNet - the distributed open-source microblogging tool //
* Copyright (C) 2011, StatusNet, Inc. // 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
* A channel for real-time browser data // the Free Software Foundation, either version 3 of the License, or
* // (at your option) any later version.
* PHP version 5 //
* // GNU social is distributed in the hope that it will be useful,
* This program is free software: you can redistribute it and/or modify // but WITHOUT ANY WARRANTY; without even the implied warranty of
* it under the terms of the GNU Affero General Public License as published by // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* the Free Software Foundation, either version 3 of the License, or // GNU Affero General Public License for more details.
* (at your option) any later version. //
* // You should have received a copy of the GNU Affero General Public License
* This program is distributed in the hope that it will be useful, // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
* 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 Realtime
* @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/
*/
if (!defined('STATUSNET')) {
exit(1);
}
/** /**
* A channel for real-time browser data * A channel for real-time browser data
@ -38,11 +20,20 @@ if (!defined('STATUSNET')) {
* For each user currently browsing the site, we want to know which page they're on * For each user currently browsing the site, we want to know which page they're on
* so we can send real-time updates to their browser. * so we can send real-time updates to their browser.
* *
* @category Realtime * @category Realtime
* @package StatusNet * @package GNUsocial
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 * @copyright 2011 StatusNet, Inc.
* @link http://status.net/ * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
defined('GNUSOCIAL') || die();
/**
* A channel for real-time browser data
*
* @copyright 2011 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* *
* @see DB_DataObject * @see DB_DataObject
*/ */
@ -111,7 +102,7 @@ class Realtime_channel extends Managed_DataObject
); );
} }
static function saveNew($user_id, $action, $arg1, $arg2) public static function saveNew($user_id, $action, $arg1, $arg2)
{ {
$channel = new Realtime_channel(); $channel = new Realtime_channel();
@ -131,7 +122,7 @@ class Realtime_channel extends Managed_DataObject
return $channel; return $channel;
} }
static function getChannel($user_id, $action, $arg1, $arg2) public static function getChannel($user_id, $action, $arg1, $arg2)
{ {
$channel = self::fetchChannel($user_id, $action, $arg1, $arg2); $channel = self::fetchChannel($user_id, $action, $arg1, $arg2);
@ -152,7 +143,7 @@ class Realtime_channel extends Managed_DataObject
return $channel; return $channel;
} }
static function getAllChannels($action, $arg1, $arg2) public static function getAllChannels($action, $arg1, $arg2)
{ {
$channel = new Realtime_channel(); $channel = new Realtime_channel();
@ -170,9 +161,9 @@ class Realtime_channel extends Managed_DataObject
$channel->arg2 = $arg2; $channel->arg2 = $arg2;
} }
$channel->whereAdd('modified > "' . common_sql_date(time() - self::TIMEOUT) . '"'); $channel->whereAdd(sprintf("modified > TIMESTAMP '%s'", common_sql_date(time() - self::TIMEOUT)));
$channels = array(); $channels = [];
if ($channel->find()) { if ($channel->find()) {
$channels = $channel->fetchAll(); $channels = $channel->fetchAll();
@ -181,7 +172,7 @@ class Realtime_channel extends Managed_DataObject
return $channels; return $channels;
} }
static function fetchChannel($user_id, $action, $arg1, $arg2) public static function fetchChannel($user_id, $action, $arg1, $arg2)
{ {
$channel = new Realtime_channel(); $channel = new Realtime_channel();
@ -213,7 +204,7 @@ class Realtime_channel extends Managed_DataObject
} }
} }
function increment() public function increment()
{ {
// XXX: race // XXX: race
$orig = clone($this); $orig = clone($this);
@ -222,7 +213,7 @@ class Realtime_channel extends Managed_DataObject
$this->update($orig); $this->update($orig);
} }
function touch() public function touch()
{ {
// XXX: race // XXX: race
$orig = clone($this); $orig = clone($this);
@ -230,7 +221,7 @@ class Realtime_channel extends Managed_DataObject
$this->update($orig); $this->update($orig);
} }
function decrement() public function decrement()
{ {
// XXX: race // XXX: race
if ($this->audience == 1) { if ($this->audience == 1) {

View File

@ -1,23 +1,27 @@
#!/usr/bin/env php #!/usr/bin/env php
<?php <?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 - a distributed open-source microblogging tool
* Copyright (C) 2011, StatusNet, Inc.
*
* Script to print out current version of the software * Script to print out current version of the software
* *
* This program is free software: you can redistribute it and/or modify * @package Realtime
* it under the terms of the GNU Affero General Public License as published by * @author Mikael Nordfeldth <mmn@hethane.se>
* the Free Software Foundation, either version 3 of the License, or * @copyright 2011, StatusNet, Inc.
* (at your option) any later version. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*
* 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/>.
*/ */
define('INSTALLDIR', realpath(__DIR__ . '/../../..')); define('INSTALLDIR', realpath(__DIR__ . '/../../..'));
@ -42,7 +46,7 @@ function cleanupChannels()
$rc->selectAdd(); $rc->selectAdd();
$rc->selectAdd('channel_key'); $rc->selectAdd('channel_key');
$rc->whereAdd('modified < "' . common_sql_date(time() - Realtime_channel::TIMEOUT) . '"'); $rc->whereAdd(sprintf("modified < TIMESTAMP '%s'", common_sql_date(time() - Realtime_channel::TIMEOUT)));
if ($rc->find()) { if ($rc->find()) {
$keys = $rc->fetchAll(); $keys = $rc->fetchAll();

View File

@ -1,35 +1,30 @@
<?php <?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 notice postings by date * Data class for counting notice postings by date
* *
* PHP version 5 * @category Data
* * @package GNUsocial
* @category Data * @author Evan Prodromou <evan@status.net>
* @package StatusNet * @copyright 2010, StatusNet, Inc.
* @author Evan Prodromou <evan@status.net> * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @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/>.
*/ */
if (!defined('STATUSNET')) { defined('GNUSOCIAL') || die();
exit(1);
}
require_once INSTALLDIR . '/classes/Memcached_DataObject.php'; require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
@ -43,11 +38,8 @@ require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
* of notices posted on that day. Since, after the end of the day, * of notices posted on that day. Since, after the end of the day,
* this number doesn't change, it's a good candidate for persistent caching. * this number doesn't change, it's a good candidate for persistent caching.
* *
* @category Data * @copyright 2010, StatusNet, Inc.
* @package StatusNet * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @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
*/ */
@ -73,7 +65,7 @@ class Sitemap_notice_count extends Managed_DataObject
); );
} }
static function getAll() public static function getAll()
{ {
$noticeCounts = self::cacheGet('sitemap:notice:counts'); $noticeCounts = self::cacheGet('sitemap:notice:counts');
@ -90,9 +82,9 @@ class Sitemap_notice_count extends Managed_DataObject
if (!$n) { // No counts saved yet if (!$n) { // No counts saved yet
$noticeCounts = self::initializeCounts(); $noticeCounts = self::initializeCounts();
} else if ($snc->notice_date < $today) { // There are counts but not up to today } elseif ($snc->notice_date < $today) { // There are counts but not up to today
$noticeCounts = self::fillInCounts($snc->notice_date); $noticeCounts = self::fillInCounts($snc->notice_date);
} else if ($snc->notice_date == $today) { // Refresh today's } elseif ($snc->notice_date === $today) { // Refresh today's
$noticeCounts[$today] = self::updateToday(); $noticeCounts[$today] = self::updateToday();
} }
@ -110,7 +102,7 @@ class Sitemap_notice_count extends Managed_DataObject
return $noticeCounts; return $noticeCounts;
} }
static function initializeCounts() public static function initializeCounts()
{ {
$firstDate = self::getFirstDate(); // awww $firstDate = self::getFirstDate(); // awww
$today = self::today(); $today = self::today();
@ -126,7 +118,7 @@ class Sitemap_notice_count extends Managed_DataObject
return $counts; return $counts;
} }
static function fillInCounts($lastDate) public static function fillInCounts($lastDate)
{ {
$today = self::today(); $today = self::today();
@ -145,7 +137,7 @@ class Sitemap_notice_count extends Managed_DataObject
return $counts; return $counts;
} }
static function updateToday() public static function updateToday()
{ {
$today = self::today(); $today = self::today();
@ -155,17 +147,20 @@ class Sitemap_notice_count extends Managed_DataObject
return $n; return $n;
} }
static function getCount($d) public static function getCount($d)
{ {
$notice = new Notice(); $notice = new Notice();
$notice->whereAdd('created BETWEEN "'.$d.' 00:00:00" AND "'.self::incrementDay($d).' 00:00:00"'); $notice->whereAdd(
"created BETWEEN TIMESTAMP '" . $d . " 00:00:00' AND " .
"TIMESTAMP '" . self::incrementDay($d) . " 00:00:00'"
);
$notice->whereAdd('is_local = ' . Notice::LOCAL_PUBLIC); $notice->whereAdd('is_local = ' . Notice::LOCAL_PUBLIC);
$n = $notice->count(); $n = $notice->count();
return $n; return $n;
} }
static function insertCount($d, $n) public static function insertCount($d, $n)
{ {
$snc = new Sitemap_notice_count(); $snc = new Sitemap_notice_count();
@ -180,7 +175,7 @@ class Sitemap_notice_count extends Managed_DataObject
} }
} }
static function updateCount($d, $n) public static function updateCount($d, $n)
{ {
$snc = Sitemap_notice_count::getKV('notice_date', DB_DataObject_Cast::date($d)); $snc = Sitemap_notice_count::getKV('notice_date', DB_DataObject_Cast::date($d));
@ -202,23 +197,23 @@ class Sitemap_notice_count extends Managed_DataObject
} }
} }
static function incrementDay($d) public static function incrementDay($d)
{ {
$dt = self::dateStrToInt($d); $dt = self::dateStrToInt($d);
return self::dateIntToStr($dt + 24 * 60 * 60); return self::dateIntToStr($dt + 24 * 60 * 60);
} }
static function dateStrToInt($d) public static function dateStrToInt($d)
{ {
return strtotime($d.' 00:00:00'); return strtotime($d.' 00:00:00');
} }
static function dateIntToStr($dt) public static function dateIntToStr($dt)
{ {
return date('Y-m-d', $dt); return date('Y-m-d', $dt);
} }
static function getFirstDate() public static function getFirstDate()
{ {
$n = new Notice(); $n = new Notice();
@ -233,7 +228,7 @@ class Sitemap_notice_count extends Managed_DataObject
} }
} }
static function today() public static function today()
{ {
return self::dateIntToStr(time()); return self::dateIntToStr(time());
} }

View File

@ -1,35 +1,30 @@
<?php <?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 user registrations by date * Data class for counting user registrations by date
* *
* PHP version 5 * @category Data
* * @package GNUsocial
* @category Data * @author Evan Prodromou <evan@status.net>
* @package StatusNet * @copyright 2010, StatusNet, Inc.
* @author Evan Prodromou <evan@status.net> * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @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/>.
*/ */
if (!defined('STATUSNET')) { defined('GNUSOCIAL') || die();
exit(1);
}
require_once INSTALLDIR . '/classes/Memcached_DataObject.php'; require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
@ -39,11 +34,8 @@ require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
* We make a separate sitemap for each user registered by date. * We make a separate sitemap for each user registered by date.
* To save ourselves some processing effort, we cache this data * To save ourselves some processing effort, we cache this data
* *
* @category Action * @copyright 2010, StatusNet, Inc.
* @package StatusNet * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
* @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
*/ */
@ -69,12 +61,11 @@ class Sitemap_user_count extends Managed_DataObject
); );
} }
static function getAll() public static function getAll()
{ {
$userCounts = self::cacheGet('sitemap:user:counts'); $userCounts = self::cacheGet('sitemap:user:counts');
if ($userCounts === false) { if ($userCounts === false) {
$suc = new Sitemap_user_count(); $suc = new Sitemap_user_count();
$suc->orderBy('registration_date DESC'); $suc->orderBy('registration_date DESC');
@ -87,9 +78,9 @@ class Sitemap_user_count extends Managed_DataObject
if (!$n) { // No counts saved yet if (!$n) { // No counts saved yet
$userCounts = self::initializeCounts(); $userCounts = self::initializeCounts();
} else if ($suc->registration_date < $today) { // There are counts but not up to today } elseif ($suc->registration_date < $today) { // There are counts but not up to today
$userCounts = self::fillInCounts($suc->registration_date); $userCounts = self::fillInCounts($suc->registration_date);
} else if ($suc->registration_date == $today) { // Refresh today's } elseif ($suc->registration_date === $today) { // Refresh today's
$userCounts[$today] = self::updateToday(); $userCounts[$today] = self::updateToday();
} }
@ -107,7 +98,7 @@ class Sitemap_user_count extends Managed_DataObject
return $userCounts; return $userCounts;
} }
static function initializeCounts() public static function initializeCounts()
{ {
$firstDate = self::getFirstDate(); // awww $firstDate = self::getFirstDate(); // awww
$today = self::today(); $today = self::today();
@ -123,7 +114,7 @@ class Sitemap_user_count extends Managed_DataObject
return $counts; return $counts;
} }
static function fillInCounts($lastDate) public static function fillInCounts($lastDate)
{ {
$today = self::today(); $today = self::today();
@ -142,7 +133,7 @@ class Sitemap_user_count extends Managed_DataObject
return $counts; return $counts;
} }
static function updateToday() public static function updateToday()
{ {
$today = self::today(); $today = self::today();
@ -152,16 +143,19 @@ class Sitemap_user_count extends Managed_DataObject
return $n; return $n;
} }
static function getCount($d) public static function getCount($d)
{ {
$user = new User(); $user = new User();
$user->whereAdd('created BETWEEN "'.$d.' 00:00:00" AND "'.self::incrementDay($d).' 00:00:00"'); $user->whereAdd(
"created BETWEEN TIMESTAMP '" . $d . " 00:00:00' AND " .
"TIMESTAMP '" . self::incrementDay($d) . " 00:00:00'"
);
$n = $user->count(); $n = $user->count();
return $n; return $n;
} }
static function insertCount($d, $n) public static function insertCount($d, $n)
{ {
$suc = new Sitemap_user_count(); $suc = new Sitemap_user_count();
@ -175,7 +169,7 @@ class Sitemap_user_count extends Managed_DataObject
} }
} }
static function updateCount($d, $n) public static function updateCount($d, $n)
{ {
$suc = Sitemap_user_count::getKV('registration_date', DB_DataObject_Cast::date($d)); $suc = Sitemap_user_count::getKV('registration_date', DB_DataObject_Cast::date($d));
@ -196,23 +190,23 @@ class Sitemap_user_count extends Managed_DataObject
} }
} }
static function incrementDay($d) public static function incrementDay($d)
{ {
$dt = self::dateStrToInt($d); $dt = self::dateStrToInt($d);
return self::dateIntToStr($dt + 24 * 60 * 60); return self::dateIntToStr($dt + 24 * 60 * 60);
} }
static function dateStrToInt($d) public static function dateStrToInt($d)
{ {
return strtotime($d.' 00:00:00'); return strtotime($d.' 00:00:00');
} }
static function dateIntToStr($dt) public static function dateIntToStr($dt)
{ {
return date('Y-m-d', $dt); return date('Y-m-d', $dt);
} }
static function getFirstDate() public static function getFirstDate()
{ {
$u = new User(); $u = new User();
$u->selectAdd(); $u->selectAdd();
@ -225,7 +219,7 @@ class Sitemap_user_count extends Managed_DataObject
} }
} }
static function today() public static function today()
{ {
return self::dateIntToStr(time()); return self::dateIntToStr(time());
} }

View File

@ -1,21 +1,25 @@
#!/usr/bin/env php #!/usr/bin/env php
<?php <?php
/* // This file is part of GNU social - https://www.gnu.org/software/social
* StatusNet - the distributed open-source microblogging tool //
* Copyright (C) 2010, StatusNet, Inc. // 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
* This program is free software: you can redistribute it and/or modify // the Free Software Foundation, either version 3 of the License, or
* it under the terms of the GNU Affero General Public License as published by // (at your option) any later version.
* 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
* This program is distributed in the hope that it will be useful, // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* but WITHOUT ANY WARRANTY; without even the implied warranty of // GNU Affero General Public License for more details.
* 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/>.
* 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/>. /**
* @package TwitterBridge
* @author Evan Prodromou <evan@status.net>
* @copyright 2010, StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/ */
define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..')); define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
@ -37,11 +41,13 @@ require_once INSTALLDIR.'/scripts/commandline.inc';
$n = new Notice(); $n = new Notice();
$n->query('SELECT notice.id, notice.uri ' . $n->query(
'FROM notice LEFT JOIN notice_to_status ' . 'SELECT notice.id, notice.uri ' .
'ON notice.id = notice_to_status.notice_id ' . 'FROM notice LEFT JOIN notice_to_status ' .
'WHERE notice.source = "twitter"' . 'ON notice.id = notice_to_status.notice_id ' .
'AND notice_to_status.status_id IS NULL'); "WHERE notice.source = 'twitter'" .
'AND notice_to_status.status_id IS NULL'
);
while ($n->fetch()) { while ($n->fetch()) {
if (preg_match('/^http://twitter.com(/#!)?/[\w_.]+/status/(\d+)$/', $n->uri, $match)) { if (preg_match('/^http://twitter.com(/#!)?/[\w_.]+/status/(\d+)$/', $n->uri, $match)) {

View File

@ -1,21 +1,25 @@
#!/usr/bin/env php #!/usr/bin/env php
<?php <?php
/* // This file is part of GNU social - https://www.gnu.org/software/social
* StatusNet - the distributed open-source microblogging tool //
* Copyright (C) 2009, StatusNet, Inc. // 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
* This program is free software: you can redistribute it and/or modify // the Free Software Foundation, either version 3 of the License, or
* it under the terms of the GNU Affero General Public License as published by // (at your option) any later version.
* 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
* This program is distributed in the hope that it will be useful, // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* but WITHOUT ANY WARRANTY; without even the implied warranty of // GNU Affero General Public License for more details.
* 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/>.
* 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/>. /**
* @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
*/ */
// Abort if called from a web server // Abort if called from a web server
@ -37,8 +41,8 @@ ENDOFHELP;
require_once INSTALLDIR.'/scripts/commandline.inc'; require_once INSTALLDIR.'/scripts/commandline.inc';
function print_all_sites() { function print_all_sites()
{
$sn = new Status_network(); $sn = new Status_network();
if ($sn->find()) { if ($sn->find()) {
@ -49,14 +53,16 @@ function print_all_sites() {
return; return;
} }
function print_tagged_sites($tag) { function print_tagged_sites($tag)
{
$sn = new Status_network(); $sn = new Status_network();
$sn->query('select status_network.nickname '. $sn->query(
'from status_network join status_network_tag '. 'SELECT status_network.nickname '.
'on status_network.site_id = status_network_tag.site_id '. 'FROM status_network INNER JOIN status_network_tag '.
'where status_network_tag.tag = "' . $tag . '"'); 'ON status_network.site_id = status_network_tag.site_id '.
"WHERE status_network_tag.tag = '" . $sn->escape($tag) . "'"
);
while ($sn->fetch()) { while ($sn->fetch()) {
print "$sn->nickname\n"; print "$sn->nickname\n";
@ -65,16 +71,18 @@ function print_tagged_sites($tag) {
return; return;
} }
function print_untagged_sites($tag) { function print_untagged_sites($tag)
{
$sn = new Status_network(); $sn = new Status_network();
$sn->query('select status_network.nickname '. $sn->query(
'from status_network '. 'SELECT status_network.nickname '.
'where not exists '. 'FROM status_network '.
'(select tag from status_network_tag '. 'WHERE NOT EXISTS '.
'where site_id = status_network.site_id '. '(SELECT tag FROM status_network_tag '.
'and tag = "'.$tag.'")'); 'WHERE site_id = status_network.site_id '.
"AND tag = '" . $sn->escape($tag) . "')"
);
while ($sn->fetch()) { while ($sn->fetch()) {
print "$sn->nickname\n"; print "$sn->nickname\n";
@ -86,7 +94,7 @@ function print_untagged_sites($tag) {
if (have_option('t', 'tagged')) { if (have_option('t', 'tagged')) {
$tag = get_option_value('t', 'tagged'); $tag = get_option_value('t', 'tagged');
print_tagged_sites($tag); print_tagged_sites($tag);
} else if (have_option('w', 'not-tagged')) { } elseif (have_option('w', 'not-tagged')) {
$tag = get_option_value('w', 'not-tagged'); $tag = get_option_value('w', 'not-tagged');
print_untagged_sites($tag); print_untagged_sites($tag);
} else { } else {

View File

@ -249,7 +249,7 @@ function fixupConversationURIs()
while ($conv->fetch()) { while ($conv->fetch()) {
$uri = common_local_url('conversation', ['id' => $conv->id]); $uri = common_local_url('conversation', ['id' => $conv->id]);
$sql = sprintf( $sql = sprintf(
'UPDATE conversation SET uri="%1$s" WHERE id="%2$d";', 'UPDATE conversation SET uri = \'%1$s\' WHERE id = %2$d;',
$conv->escape($uri), $conv->escape($uri),
$conv->id $conv->id
); );
@ -379,7 +379,7 @@ function initSubscriptionURI()
$sub->decache(); $sub->decache();
$sub->query(sprintf( $sub->query(sprintf(
'UPDATE subscription '. 'UPDATE subscription '.
'SET uri = "%s" '. "SET uri = '%s' " .
'WHERE subscriber = %d '. 'WHERE subscriber = %d '.
'AND subscribed = %d', 'AND subscribed = %d',
$sub->escape(Subscription::newUri($sub->getSubscriber(), $sub->getSubscribed(), $sub->created)), $sub->escape(Subscription::newUri($sub->getSubscriber(), $sub->getSubscribed(), $sub->created)),
@ -408,7 +408,7 @@ function initGroupMemberURI()
$mem->decache(); $mem->decache();
$mem->query(sprintf( $mem->query(sprintf(
'UPDATE group_member '. 'UPDATE group_member '.
'SET uri = "%s" '. "SET uri = '%s' " .
'WHERE profile_id = %d ' . 'WHERE profile_id = %d ' .
'AND group_id = %d', 'AND group_id = %d',
Group_member::newUri(Profile::getByID($mem->profile_id), User_group::getByID($mem->group_id), $mem->created), Group_member::newUri(Profile::getByID($mem->profile_id), User_group::getByID($mem->group_id), $mem->created),
@ -537,7 +537,7 @@ function deleteLocalFileThumbnailsWithoutFilename()
while ($file->fetch()) { while ($file->fetch()) {
$thumbs = new File_thumbnail(); $thumbs = new File_thumbnail();
$thumbs->file_id = $file->id; $thumbs->file_id = $file->id;
$thumbs->whereAdd('filename IS NULL OR filename = ""'); $thumbs->whereAdd("filename IS NULL OR filename = ''");
// Checking if there were any File_thumbnail entries without filename // Checking if there were any File_thumbnail entries without filename
if (!$thumbs->find()) { if (!$thumbs->find()) {
continue; continue;
@ -560,7 +560,7 @@ function deleteMissingLocalFileThumbnails()
printfnq("Removing all local File_thumbnail entries without existing files..."); printfnq("Removing all local File_thumbnail entries without existing files...");
$thumbs = new File_thumbnail(); $thumbs = new File_thumbnail();
$thumbs->whereAdd('filename IS NOT NULL AND filename != ""'); $thumbs->whereAdd("filename IS NOT NULL AND filename != ''");
// Checking if there were any File_thumbnail entries without filename // Checking if there were any File_thumbnail entries without filename
if ($thumbs->find()) { if ($thumbs->find()) {
while ($thumbs->fetch()) { while ($thumbs->fetch()) {
@ -583,7 +583,7 @@ function setFilehashOnLocalFiles()
printfnq('Ensuring all local files have the filehash field set...'); printfnq('Ensuring all local files have the filehash field set...');
$file = new File(); $file = new File();
$file->whereAdd('filename IS NOT NULL AND filename != ""'); // local files $file->whereAdd("filename IS NOT NULL AND filename != ''"); // local files
$file->whereAdd('filehash IS NULL', 'AND'); // without filehash value $file->whereAdd('filehash IS NULL', 'AND'); // without filehash value
if ($file->find()) { if ($file->find()) {
@ -606,10 +606,14 @@ function fixupFileThumbnailUrlhash()
printfnq("Setting urlhash for File_thumbnail entries: "); printfnq("Setting urlhash for File_thumbnail entries: ");
$thumb = new File_thumbnail(); $thumb = new File_thumbnail();
$thumb->query('UPDATE '.$thumb->escapedTableName().' SET urlhash=SHA2(url, 256) WHERE'. $thumb->query(sprintf(
' url IS NOT NULL AND'. // find all entries with a url value 'UPDATE %1$s ' .
' url != "" AND'. // precaution against non-null empty strings 'SET urlhash = sha2(url, 256) ' .
' urlhash IS NULL'); // but don't touch those we've already calculated 'WHERE url IS NOT NULL ' . // find all entries with a url value
"AND url <> '' " . // precaution against non-null empty strings
'AND urlhash IS NULL', // but don't touch those we've already calculated
$thumb->escapedTableName()
));
printfnq("DONE.\n"); printfnq("DONE.\n");
} }