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

View File

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

View File

@ -36,7 +36,7 @@ VALUES
(100088, 'Orange (Poland)', '%s@orange.pl', now()),
(100089, 'Personal (Argentina)', '%s@personal-net.com.ar', 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()),
(100093, 'Rogers (Canada)', '%s@pcs.rogers.com', now()),
(100094, 'Sasktel (Canada)', '%s@sms.sasktel.com', now()),

View File

@ -1,31 +1,54 @@
<?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
{
function __construct(Profile $scoped=null)
public function __construct(Profile $scoped = null)
{
parent::__construct(new CachingNoticeStream(new RawNetworkPublicNoticeStream(),
'networkpublic'),
$scoped);
parent::__construct(
new CachingNoticeStream(
new RawNetworkPublicNoticeStream(),
'networkpublic'
),
$scoped
);
}
}
/**
* Raw public stream
*
* @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/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class RawNetworkPublicNoticeStream extends FullNoticeStream
{
function getNoticeIds($offset, $limit, $since_id, $max_id)
public function getNoticeIds($offset, $limit, $since_id, $max_id)
{
$notice = new Notice();
@ -38,11 +61,11 @@ class RawNetworkPublicNoticeStream extends FullNoticeStream
$notice->limit($offset, $limit);
}
$notice->whereAdd('is_local ='. Notice::REMOTE);
$notice->whereAdd('is_local = '. Notice::REMOTE);
// -1 == blacklisted, -2 == gateway (i.e. Twitter)
$notice->whereAdd('is_local !='. Notice::LOCAL_NONPUBLIC);
$notice->whereAdd('is_local !='. Notice::GATEWAY);
$notice->whereAdd('scope != ' . Notice::MESSAGE_SCOPE);
$notice->whereAdd('is_local <> '. Notice::LOCAL_NONPUBLIC);
$notice->whereAdd('is_local <> '. Notice::GATEWAY);
$notice->whereAdd('scope <> ' . Notice::MESSAGE_SCOPE);
Notice::addWhereSinceId($notice, $since_id);
Notice::addWhereMaxId($notice, $max_id);
@ -58,7 +81,7 @@ class RawNetworkPublicNoticeStream extends FullNoticeStream
}
$notice->free();
$notice = NULL;
$notice = null;
return $ids;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,36 +1,18 @@
<?php
/**
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2011, StatusNet, Inc.
*
* A channel for real-time browser data
*
* PHP version 5
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category 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);
}
// 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/>.
/**
* 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
* so we can send real-time updates to their browser.
*
* @category Realtime
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
* @category Realtime
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc.
* @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
*/
@ -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();
@ -131,7 +122,7 @@ class Realtime_channel extends Managed_DataObject
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);
@ -152,7 +143,7 @@ class Realtime_channel extends Managed_DataObject
return $channel;
}
static function getAllChannels($action, $arg1, $arg2)
public static function getAllChannels($action, $arg1, $arg2)
{
$channel = new Realtime_channel();
@ -170,9 +161,9 @@ class Realtime_channel extends Managed_DataObject
$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()) {
$channels = $channel->fetchAll();
@ -181,7 +172,7 @@ class Realtime_channel extends Managed_DataObject
return $channels;
}
static function fetchChannel($user_id, $action, $arg1, $arg2)
public static function fetchChannel($user_id, $action, $arg1, $arg2)
{
$channel = new Realtime_channel();
@ -213,7 +204,7 @@ class Realtime_channel extends Managed_DataObject
}
}
function increment()
public function increment()
{
// XXX: race
$orig = clone($this);
@ -222,7 +213,7 @@ class Realtime_channel extends Managed_DataObject
$this->update($orig);
}
function touch()
public function touch()
{
// XXX: race
$orig = clone($this);
@ -230,7 +221,7 @@ class Realtime_channel extends Managed_DataObject
$this->update($orig);
}
function decrement()
public function decrement()
{
// XXX: race
if ($this->audience == 1) {

View File

@ -1,23 +1,27 @@
#!/usr/bin/env 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
*
* 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/>.
* @package Realtime
* @author Mikael Nordfeldth <mmn@hethane.se>
* @copyright 2011, StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
define('INSTALLDIR', realpath(__DIR__ . '/../../..'));
@ -42,7 +46,7 @@ function cleanupChannels()
$rc->selectAdd();
$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()) {
$keys = $rc->fetchAll();

View File

@ -1,35 +1,30 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* Data class for counting notice postings by date
*
* PHP version 5
*
* @category Data
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2010, StatusNet, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* @category Data
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2010, StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('STATUSNET')) {
exit(1);
}
defined('GNUSOCIAL') || die();
require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
@ -43,11 +38,8 @@ require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
* 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.
*
* @category Data
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
* @copyright 2010, StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*
* @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');
@ -90,9 +82,9 @@ class Sitemap_notice_count extends Managed_DataObject
if (!$n) { // No counts saved yet
$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);
} else if ($snc->notice_date == $today) { // Refresh today's
} elseif ($snc->notice_date === $today) { // Refresh today's
$noticeCounts[$today] = self::updateToday();
}
@ -110,7 +102,7 @@ class Sitemap_notice_count extends Managed_DataObject
return $noticeCounts;
}
static function initializeCounts()
public static function initializeCounts()
{
$firstDate = self::getFirstDate(); // awww
$today = self::today();
@ -126,7 +118,7 @@ class Sitemap_notice_count extends Managed_DataObject
return $counts;
}
static function fillInCounts($lastDate)
public static function fillInCounts($lastDate)
{
$today = self::today();
@ -145,7 +137,7 @@ class Sitemap_notice_count extends Managed_DataObject
return $counts;
}
static function updateToday()
public static function updateToday()
{
$today = self::today();
@ -155,17 +147,20 @@ class Sitemap_notice_count extends Managed_DataObject
return $n;
}
static function getCount($d)
public static function getCount($d)
{
$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);
$n = $notice->count();
return $n;
}
static function insertCount($d, $n)
public static function insertCount($d, $n)
{
$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));
@ -202,23 +197,23 @@ class Sitemap_notice_count extends Managed_DataObject
}
}
static function incrementDay($d)
public static function incrementDay($d)
{
$dt = self::dateStrToInt($d);
return self::dateIntToStr($dt + 24 * 60 * 60);
}
static function dateStrToInt($d)
public static function dateStrToInt($d)
{
return strtotime($d.' 00:00:00');
}
static function dateIntToStr($dt)
public static function dateIntToStr($dt)
{
return date('Y-m-d', $dt);
}
static function getFirstDate()
public static function getFirstDate()
{
$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());
}

View File

@ -1,35 +1,30 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* Data class for counting user registrations by date
*
* PHP version 5
*
* @category Data
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2010, StatusNet, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* @category Data
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2010, StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('STATUSNET')) {
exit(1);
}
defined('GNUSOCIAL') || die();
require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
@ -39,11 +34,8 @@ require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
* We make a separate sitemap for each user registered by date.
* To save ourselves some processing effort, we cache this data
*
* @category Action
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
* @copyright 2010, StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*
* @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');
if ($userCounts === false) {
$suc = new Sitemap_user_count();
$suc->orderBy('registration_date DESC');
@ -87,9 +78,9 @@ class Sitemap_user_count extends Managed_DataObject
if (!$n) { // No counts saved yet
$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);
} else if ($suc->registration_date == $today) { // Refresh today's
} elseif ($suc->registration_date === $today) { // Refresh today's
$userCounts[$today] = self::updateToday();
}
@ -107,7 +98,7 @@ class Sitemap_user_count extends Managed_DataObject
return $userCounts;
}
static function initializeCounts()
public static function initializeCounts()
{
$firstDate = self::getFirstDate(); // awww
$today = self::today();
@ -123,7 +114,7 @@ class Sitemap_user_count extends Managed_DataObject
return $counts;
}
static function fillInCounts($lastDate)
public static function fillInCounts($lastDate)
{
$today = self::today();
@ -142,7 +133,7 @@ class Sitemap_user_count extends Managed_DataObject
return $counts;
}
static function updateToday()
public static function updateToday()
{
$today = self::today();
@ -152,16 +143,19 @@ class Sitemap_user_count extends Managed_DataObject
return $n;
}
static function getCount($d)
public static function getCount($d)
{
$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();
return $n;
}
static function insertCount($d, $n)
public static function insertCount($d, $n)
{
$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));
@ -196,23 +190,23 @@ class Sitemap_user_count extends Managed_DataObject
}
}
static function incrementDay($d)
public static function incrementDay($d)
{
$dt = self::dateStrToInt($d);
return self::dateIntToStr($dt + 24 * 60 * 60);
}
static function dateStrToInt($d)
public static function dateStrToInt($d)
{
return strtotime($d.' 00:00:00');
}
static function dateIntToStr($dt)
public static function dateIntToStr($dt)
{
return date('Y-m-d', $dt);
}
static function getFirstDate()
public static function getFirstDate()
{
$u = new User();
$u->selectAdd();
@ -225,7 +219,7 @@ class Sitemap_user_count extends Managed_DataObject
}
}
static function today()
public static function today()
{
return self::dateIntToStr(time());
}

View File

@ -1,21 +1,25 @@
#!/usr/bin/env php
<?php
/*
* 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/>.
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* @package 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__) . '/../../..'));
@ -37,11 +41,13 @@ require_once INSTALLDIR.'/scripts/commandline.inc';
$n = new Notice();
$n->query('SELECT notice.id, notice.uri ' .
'FROM notice LEFT JOIN notice_to_status ' .
'ON notice.id = notice_to_status.notice_id ' .
'WHERE notice.source = "twitter"' .
'AND notice_to_status.status_id IS NULL');
$n->query(
'SELECT notice.id, notice.uri ' .
'FROM notice LEFT JOIN notice_to_status ' .
'ON notice.id = notice_to_status.notice_id ' .
"WHERE notice.source = 'twitter'" .
'AND notice_to_status.status_id IS NULL'
);
while ($n->fetch()) {
if (preg_match('/^http://twitter.com(/#!)?/[\w_.]+/status/(\d+)$/', $n->uri, $match)) {

View File

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

View File

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