Avoid use of assignments bare inside statements

Either use them in a subroutine call or put parentheses around the assignment.
This commit is contained in:
Alexei Sorokin 2020-09-08 12:42:51 +03:00 committed by Diogo Peralta Cordeiro
parent 7c2cf605f4
commit 9efbef720d
15 changed files with 934 additions and 791 deletions

View File

@ -1,4 +1,19 @@
<?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/>.
/**
* Settings for Jabber/XMPP integration
*
@ -93,7 +108,10 @@ class ImsettingsAction extends SettingsAction
$this->hidden('token', common_session_token());
$this->hidden('transport', $transport);
if ($user_im_prefs = User_im_prefs::pkeyGet(['transport' => $transport, 'user_id' => $user->id])) {
if (!empty($user_im_prefs = User_im_prefs::pkeyGet([
'transport' => $transport,
'user_id' => $user->id,
]))) {
$user_im_prefs_by_transport[$transport] = $user_im_prefs;
$this->element('p', 'form_confirmed', $user_im_prefs->screenname);
$this->element(

View File

@ -1,23 +1,25 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 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/>.
* @copyright 2010 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('GNUSOCIAL')) { exit(1); }
defined('GNUSOCIAL') || die();
/**
* Extended DB_DataObject to improve a few things:
@ -34,7 +36,7 @@ class Safe_DataObject extends GS_DataObject
* DB_DataObject doesn't do this yet by itself.
*/
function __destruct()
public function __destruct()
{
$this->free();
if (method_exists('DB_DataObject', '__destruct')) {
@ -56,7 +58,7 @@ class Safe_DataObject extends GS_DataObject
* It will still be freed properly when the original object
* gets destroyed.
*/
function __clone()
public function __clone()
{
$this->_DB_resultid = false;
}
@ -70,7 +72,7 @@ class Safe_DataObject extends GS_DataObject
*
* @return array of variable names to include in serialization.
*/
function __sleep()
public function __sleep()
{
$vars = array_keys(get_object_vars($this));
$skip = array('_DB_resultid', '_link_loaded');
@ -86,7 +88,7 @@ class Safe_DataObject extends GS_DataObject
*
* Old cached objects may still have them.
*/
function __wakeup()
public function __wakeup()
{
// Refers to global state info from a previous process.
// Clear this out so we don't accidentally break global
@ -108,7 +110,7 @@ class Safe_DataObject extends GS_DataObject
* @return mixed
* @throws Exception
*/
function __call($method, $params)
public function __call($method, $params)
{
$return = null;
// Yes, that's _call with one underscore, which does the
@ -135,19 +137,18 @@ class Safe_DataObject extends GS_DataObject
* @return true or PEAR:error on wrong paramenters.. or false if no file exists..
* or the array(tablename => array(column_name=>type)) if called with 1 argument.. (databasename)
*/
function databaseStructure()
public function databaseStructure()
{
global $_DB_DATAOBJECT;
// Assignment code
if ($args = func_get_args()) {
if (!empty($args = func_get_args())) {
if (count($args) == 1) {
// this returns all the tables and their structure..
if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) {
$this->debug("Loading Generator as databaseStructure called with args",1);
$this->debug(
'Loading Generator as databaseStructure called with args',
1
);
}
$x = new DB_DataObject;
@ -159,13 +160,12 @@ class Safe_DataObject extends GS_DataObject
class_exists('DB_DataObject_Generator') ? '' :
require_once 'DB/DataObject/Generator.php';
foreach($tables as $table) {
foreach ($tables as $table) {
$y = new DB_DataObject_Generator;
$y->fillTableSchema($x->_database,$table);
$y->fillTableSchema($x->_database, $table);
}
return $_DB_DATAOBJECT['INI'][$x->_database];
} else {
$_DB_DATAOBJECT['INI'][$args[0]] = isset($_DB_DATAOBJECT['INI'][$args[0]]) ?
$_DB_DATAOBJECT['INI'][$args[0]] + $args[1] : $args[1];
@ -175,7 +175,6 @@ class Safe_DataObject extends GS_DataObject
}
return true;
}
}
if (!$this->_database) {
$this->_connect();
@ -190,14 +189,14 @@ class Safe_DataObject extends GS_DataObject
&& !empty($_DB_DATAOBJECT['CONFIG']['proxy'])
) {
if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) {
$this->debug("Loading Generator to fetch Schema",1);
$this->debug('Loading Generator to fetch Schema', 1);
}
class_exists('DB_DataObject_Generator') ? '' :
require_once 'DB/DataObject/Generator.php';
$x = new DB_DataObject_Generator;
$x->fillTableSchema($this->_database,$this->tableName());
$x->fillTableSchema($this->_database, $this->tableName());
}
return true;
}
@ -216,7 +215,7 @@ class Safe_DataObject extends GS_DataObject
if (isset($_DB_DATAOBJECT['CONFIG']["ini_{$this->_database}"])) {
$schemas = is_array($_DB_DATAOBJECT['CONFIG']["ini_{$this->_database}"]) ?
$_DB_DATAOBJECT['CONFIG']["ini_{$this->_database}"] :
explode(PATH_SEPARATOR,$_DB_DATAOBJECT['CONFIG']["ini_{$this->_database}"]);
explode(PATH_SEPARATOR, $_DB_DATAOBJECT['CONFIG']["ini_{$this->_database}"]);
}
/* BEGIN CHANGED FROM UPSTREAM */
@ -234,15 +233,25 @@ class Safe_DataObject extends GS_DataObject
require_once 'DB/DataObject/Generator.php';
$x = new DB_DataObject_Generator;
$x->fillTableSchema($this->_database,$this->tableName());
$x->fillTableSchema($this->_database, $this->tableName());
// should this fail!!!???
return true;
}
$this->debug("Cant find database schema: {$this->_database}/{$this->tableName()} \n".
"in links file data: " . print_r($_DB_DATAOBJECT['INI'],true),"databaseStructure",5);
$this->debug(
"Can't find database schema: {$this->_database}/{$this->tableName()}\n"
. 'in links file data: '
. print_r($_DB_DATAOBJECT['INI'], true),
'databaseStructure',
5
);
// we have to die here!! - it causes chaos if we don't (including looping forever!)
// Low level exception. No need for i18n as discussed with Brion.
$this->raiseError( "Unable to load schema for database and table (turn debugging up to 5 for full error message)", DB_DATAOBJECT_ERROR_INVALIDARGS, PEAR_ERROR_DIE);
$this->raiseError(
'Unable to load schema for database and table '
. '(turn debugging up to 5 for full error message)',
DB_DATAOBJECT_ERROR_INVALIDARGS,
PEAR_ERROR_DIE
);
return false;
}
@ -268,15 +277,27 @@ class Safe_DataObject extends GS_DataObject
$data = array_merge($data, parse_ini_file($ini, true));
if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) {
if (!is_readable ($ini)) {
$this->debug("ini file is not readable: $ini","databaseStructure",1);
if (!is_readable($ini)) {
$this->debug(
"ini file is not readable: {$ini}",
'databaseStructure',
1
);
} else {
$this->debug("Loaded ini file: $ini","databaseStructure",1);
$this->debug(
"Loaded ini file: {$ini}",
'databaseStructure',
1
);
}
}
} else {
if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) {
$this->debug("Missing ini file: $ini","databaseStructure",1);
$this->debug(
"Missing ini file: {$ini}",
'databaseStructure',
1
);
}
}
}

View File

@ -770,7 +770,7 @@ class User extends Managed_DataObject
throw new ServerException(_('Single-user mode code called when not enabled.'));
}
if ($nickname = common_config('singleuser', 'nickname')) {
if (!empty($nickname = common_config('singleuser', 'nickname'))) {
$user = User::getKV('nickname', $nickname);
if ($user instanceof User) {
return $user;

View File

@ -1,36 +1,31 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* StatusNet, the distributed open-source microblogging tool
*
* An activity
*
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Feed
* @package StatusNet
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @author Zach Copley <zach@status.net>
* @copyright 2010 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('STATUSNET')) {
exit(1);
}
defined('GNUSOCIAL') || die();
/**
* An activity in the ActivityStrea.ms world
@ -42,11 +37,10 @@ if (!defined('STATUSNET')) {
* 'something else' is the object.
*
* @category OStatus
* @package StatusNet
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2010 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class Activity
{
@ -113,7 +107,7 @@ class Activity
* @param DOMElement $entry Atom entry to poke at
* @param DOMElement $feed Atom feed, for context
*/
function __construct($entry = null, $feed = null)
public function __construct($entry = null, $feed = null)
{
if (is_null($entry)) {
return;
@ -130,14 +124,20 @@ class Activity
$this->entry = $entry;
$this->feed = $feed;
if ($entry->namespaceURI == Activity::ATOM &&
$entry->localName == 'entry') {
if (
$entry->namespaceURI === Activity::ATOM
&& $entry->localName === 'entry'
) {
$this->_fromAtomEntry($entry, $feed);
} else if ($entry->namespaceURI == Activity::RSS &&
$entry->localName == 'item') {
} elseif (
$entry->namespaceURI === Activity::RSS
&& $entry->localName === 'item'
) {
$this->_fromRssItem($entry, $feed);
} else if ($entry->namespaceURI == Activity::SPEC &&
$entry->localName == 'object') {
} elseif (
$entry->namespaceURI === Activity::SPEC
&& $entry->localName === 'object'
) {
$this->_fromAtomEntry($entry, $feed);
} else {
// Low level exception. No need for i18n.
@ -145,7 +145,7 @@ class Activity
}
}
function _fromAtomEntry($entry, $feed)
public function _fromAtomEntry($entry, $feed)
{
$pubEl = $this->_child($entry, self::PUBLISHED, self::ATOM);
@ -191,9 +191,7 @@ class Activity
$this->objects[] = new ActivityObject($entry);
}
$actorEl = $this->_child($entry, self::ACTOR);
if (!empty($actorEl)) {
if (!empty($actorEl = $this->_child($entry, self::ACTOR))) {
// Standalone <activity:actor> elements are a holdover from older
// versions of ActivityStreams. Newer feeds should have this data
// integrated straight into <atom:author>.
@ -211,22 +209,25 @@ class Activity
$this->actor->id = $authorObj->id;
}
}
} else if ($authorEl = $this->_child($entry, self::AUTHOR, self::ATOM)) {
} elseif (!empty($authorEl = $this->_child(
$entry,
self::AUTHOR,
self::ATOM
))) {
// An <atom:author> in the entry overrides any author info on
// the surrounding feed.
$this->actor = new ActivityObject($authorEl);
} else if (!empty($feed) &&
$subjectEl = $this->_child($feed, self::SUBJECT)) {
} elseif (
!empty($feed)
&& !empty($subjectEl = $this->_child($feed, self::SUBJECT))
) {
// Feed subject is used for things like groups.
// Should actually possibly not be interpreted as an actor...?
$this->actor = new ActivityObject($subjectEl);
} else if (!empty($feed) && $authorEl = $this->_child($feed, self::AUTHOR,
self::ATOM)) {
} elseif (
!empty($feed)
&& !empty($authorEl = $this->_child($feed, self::AUTHOR, self::ATOM))
) {
// If there's no <atom:author> on the entry, it's safe to assume
// the containing feed's authorship info applies.
$this->actor = new ActivityObject($authorEl);
@ -271,7 +272,7 @@ class Activity
$this->editLink = ActivityUtils::getLink($entry, 'edit', 'application/atom+xml');
}
function _fromRssItem($item, $channel)
public function _fromRssItem($item, $channel)
{
$verbEl = $this->_child($item, self::VERB);
@ -288,14 +289,26 @@ class Activity
$this->time = strtotime($pubDateEl->textContent);
}
if ($authorEl = $this->_child($item, self::AUTHOR, self::RSS)) {
if (!empty($authorEl = $this->_child(
$item,
self::AUTHOR,
self::RSS
))) {
$this->actor = ActivityObject::fromRssAuthor($authorEl);
} else if ($dcCreatorEl = $this->_child($item, self::CREATOR, self::DC)) {
} elseif (!empty($dcCreatorEl = $this->_child(
$item,
self::CREATOR,
self::DC
))) {
$this->actor = ActivityObject::fromDcCreator($dcCreatorEl);
} else if ($posterousEl = $this->_child($item, ActivityObject::AUTHOR, ActivityObject::POSTEROUS)) {
} elseif (!empty($posterousEl = $this->_child(
$item,
ActivityObject::AUTHOR,
ActivityObject::POSTEROUS
))) {
// Special case for Posterous.com
$this->actor = ActivityObject::fromPosterousAuthor($posterousEl);
} else if (!empty($channel)) {
} elseif (!empty($channel)) {
$this->actor = ActivityObject::fromRssChannel($channel);
} else {
// No actor!
@ -347,7 +360,7 @@ class Activity
* @return DOMElement Atom entry
*/
function toAtomEntry()
public function toAtomEntry()
{
return null;
}
@ -359,7 +372,7 @@ class Activity
* @return array $activity
*/
function asArray()
public function asArray()
{
$activity = array();
@ -416,7 +429,6 @@ class Activity
// Context stuff.
if (!empty($this->context)) {
if (!empty($this->context->location)) {
$loc = $this->context->location;
@ -528,15 +540,23 @@ class Activity
return array_filter($activity);
}
function asString($namespace=false, $author=true, $source=false)
{
public function asString(
$namespace = false,
$author = true,
$source = false
) {
$xs = new XMLStringer(true);
$this->outputTo($xs, $namespace, $author, $source);
return $xs->getString();
}
function outputTo($xs, $namespace=false, $author=true, $source=false, $tag='entry')
{
public function outputTo(
$xs,
$namespace = false,
$author = true,
$source = false,
$tag = 'entry'
) {
if ($namespace) {
$attrs = array('xmlns' => 'http://www.w3.org/2005/Atom',
'xmlns:thr' => 'http://purl.org/syndication/thread/1.0',
@ -557,10 +577,8 @@ class Activity
}
if ($this->verb == ActivityVerb::POST && count($this->objects) == 1 && $tag == 'entry') {
$obj = $this->objects[0];
$obj->outputTo($xs, null);
$obj->outputTo($xs, null);
} else {
$xs->element('id', null, $this->id);
@ -582,7 +600,6 @@ class Activity
'type' => 'text/html',
'href' => $this->link));
}
}
$xs->element('activity:verb', null, $this->verb);
@ -597,7 +614,7 @@ class Activity
}
if ($this->verb != ActivityVerb::POST || count($this->objects) != 1 || $tag != 'entry') {
foreach($this->objects as $object) {
foreach ($this->objects as $object) {
if ($object instanceof Activity) {
$object->outputTo($xs, false, true, true, 'activity:object');
} else {
@ -607,21 +624,24 @@ class Activity
}
if (!empty($this->context)) {
if (!empty($this->context->replyToID)) {
if (!empty($this->context->replyToUrl)) {
$xs->element('thr:in-reply-to',
array('ref' => $this->context->replyToID,
'href' => $this->context->replyToUrl));
$xs->element('thr:in-reply-to', [
'ref' => $this->context->replyToID,
'href' => $this->context->replyToUrl,
]);
} else {
$xs->element('thr:in-reply-to',
array('ref' => $this->context->replyToID));
$xs->element('thr:in-reply-to', [
'ref' => $this->context->replyToID,
]);
}
}
if (!empty($this->context->replyToUrl)) {
$xs->element('link', array('rel' => 'related',
'href' => $this->context->replyToUrl));
$xs->element('link', [
'rel' => 'related',
'href' => $this->context->replyToUrl,
]);
}
if (!empty($this->context->conversation)) {
@ -631,14 +651,18 @@ class Activity
$convattr['href'] = $conv->getUrl();
$convattr['local_id'] = $conv->getID();
$convattr['ref'] = $conv->getUri();
$xs->element('link', array('rel' => 'ostatus:'.ActivityContext::CONVERSATION,
'href' => $convattr['href']));
$xs->element('link', [
'rel' => 'ostatus:' . ActivityContext::CONVERSATION,
'href' => $convattr['href'],
]);
} else {
$convattr['ref'] = $this->context->conversation;
}
$xs->element('ostatus:'.ActivityContext::CONVERSATION,
$convattr,
$this->context->conversation);
$xs->element(
'ostatus:' . ActivityContext::CONVERSATION,
$convattr,
$this->context->conversation
);
/* Since we use XMLWriter we just use the previously hardcoded prefix for ostatus,
otherwise we should use something like this:
$xs->elementNS(array(ActivityContext::OSTATUS => 'ostatus'), // namespace
@ -649,9 +673,11 @@ class Activity
}
foreach ($this->context->attention as $attnURI=>$type) {
$xs->element('link', array('rel' => ActivityContext::MENTIONED,
ActivityContext::OBJECTTYPE => $type, // FIXME: undocumented
'href' => $attnURI));
$xs->element('link', [
'rel' => ActivityContext::MENTIONED,
ActivityContext::OBJECTTYPE => $type, // @fixme undocumented
'href' => $attnURI,
]);
}
if (!empty($this->context->location)) {
@ -759,7 +785,7 @@ class Activity
* @param int $tm Unix timestamp
* @return string
*/
static function iso8601Date($tm)
public static function iso8601Date($tm)
{
$dateStr = date('d F Y H:i:s', $tm);
$d = new DateTime($dateStr, new DateTimeZone('UTC'));

View File

@ -1,36 +1,31 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* StatusNet, the distributed open-source microblogging tool
*
* Utilities for theme files and paths
*
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Paths
* @package StatusNet
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @author Sarven Capadisli <csarven@status.net>
* @copyright 2008-2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
defined('GNUSOCIAL') || die();
/**
* Class for querying and manipulating a theme
@ -45,19 +40,18 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
* This used to be a couple of functions, but for various reasons it's nice
* to have a class instead.
*
* @category Output
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
* @category Output
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class Theme
{
const FALLBACK = 'neo';
var $name = null;
var $dir = null;
var $path = null;
public $name = null;
public $dir = null;
public $path = null;
protected $metadata = null; // access via getMetadata() lazy-loader
protected $externals = null;
protected $deps = null;
@ -70,7 +64,7 @@ class Theme
* @param string $name Name of the theme; defaults to config value
* @throws ServerException
*/
function __construct($name = null)
public function __construct($name = null)
{
if (empty($name)) {
$name = common_config('site', 'theme');
@ -107,14 +101,15 @@ class Theme
// Ruh roh. Fall back to default, then.
common_log(LOG_WARNING, sprintf("Unable to find theme '%s', falling back to default theme '%s'",
$name,
Theme::FALLBACK));
common_log(LOG_WARNING, sprintf(
'Unable to find theme \'%s\', falling back to default theme \'%s\'',
$name,
Theme::FALLBACK
));
$this->name = Theme::FALLBACK;
$this->dir = $instroot.'/'.Theme::FALLBACK;
$this->path = $this->relativeThemePath('theme', 'theme', Theme::FALLBACK);
}
/**
@ -135,13 +130,13 @@ class Theme
$sslserver = common_config($group, 'sslserver');
if (empty($sslserver)) {
if (is_string(common_config('site', 'sslserver')) &&
mb_strlen(common_config('site', 'sslserver')) > 0) {
$server = common_config('site', 'sslserver');
} else if (common_config('site', 'server')) {
$sslserver = common_config('site', 'sslserver');
if (is_string($sslserver) && strlen($sslserver) > 0) {
$server = $sslserver;
} elseif (!empty(common_config('site', 'server'))) {
$server = common_config('site', 'server');
}
$path = common_config('site', 'path') . '/';
$path = common_config('site', 'path') . '/';
if ($fallbackSubdir) {
$path .= $fallbackSubdir . '/';
}
@ -191,7 +186,7 @@ class Theme
*
* @return string full pathname, like /var/www/mublog/theme/default/logo.png
*/
function getFile($relative)
public function getFile($relative)
{
return $this->dir.'/'.$relative;
}
@ -203,7 +198,7 @@ class Theme
*
* @return string full URL, like 'http://example.com/theme/default/logo.png'
*/
function getPath($relative)
public function getPath($relative)
{
return $this->path.'/'.$relative;
}
@ -215,7 +210,7 @@ class Theme
*
* @return array of strings with theme names
*/
function getDeps()
public function getDeps()
{
if ($this->deps === null) {
$chain = $this->doGetDeps(array($this->name));
@ -238,9 +233,11 @@ class Theme
array_unshift($chain, $include);
return $theme->doGetDeps($chain);
} catch (Exception $e) {
common_log(LOG_ERR,
"Exception while fetching theme dependencies " .
"for $this->name: " . $e->getMessage());
common_log(
LOG_ERR,
'Exception while fetching theme dependencies '
. "for {$this->name}: {$e->getMessage()}"
);
}
}
}
@ -253,9 +250,9 @@ class Theme
*
* @return array associative of strings
*/
function getMetadata()
public function getMetadata()
{
if ($this->metadata == null) {
if (is_null($this->metadata)) {
$this->metadata = $this->doGetMetadata();
}
return $this->metadata;
@ -284,9 +281,9 @@ class Theme
* @return array of URL strings
* @throws ServerException
*/
function getExternals()
public function getExternals()
{
if ($this->externals == null) {
if (is_null($this->externals)) {
$data = $this->getMetadata();
if (!empty($data['external'])) {
$ext = (array)$data['external'];
@ -313,7 +310,7 @@ class Theme
* @return string File path to the theme file
* @throws ServerException
*/
static function file($relative, $name=null)
public static function file($relative, $name = null)
{
$theme = new Theme($name);
return $theme->getFile($relative);
@ -328,7 +325,7 @@ class Theme
* @return string URL of the file
* @throws ServerException
*/
static function path($relative, $name=null)
public static function path($relative, $name = null)
{
$theme = new Theme($name);
return $theme->getPath($relative);
@ -339,7 +336,7 @@ class Theme
*
* @return array list of available theme names
*/
static function listAvailable()
public static function listAvailable()
{
$local = self::subdirsOf(self::localRoot());
$install = self::subdirsOf(self::installRoot());
@ -363,7 +360,7 @@ class Theme
$subdirs = array();
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
if (($dh = opendir($dir)) !== false) {
while (($filename = readdir($dh)) !== false) {
if ($filename != '..' && $filename !== '.' &&
is_dir($dir.'/'.$filename)) {
@ -409,7 +406,7 @@ class Theme
return $instroot;
}
static function validName($name)
public static function validName($name)
{
return preg_match('/^[a-z0-9][a-z0-9_-]*$/i', $name);
}

View File

@ -1,43 +1,40 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* Form action extendable class.
*
* PHP version 5
*
* @category Action
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2008, 2009, StatusNet, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* @category Action
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2008, 2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('GNUSOCIAL')) { exit(1); }
defined('GNUSOCIAL') || die();
/**
* Form action extendable class
*
* @category Action
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @author Mikael Nordfeldth <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
* @link http://status.net/
* @category Action
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @author Mikael Nordfeldth <evan@status.net>
* @copyright 2008, 2009 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class FormAction extends ManagedAction
{
@ -47,7 +44,8 @@ class FormAction extends ManagedAction
protected $needLogin = true;
protected $canPost = true;
protected function prepare(array $args = []) {
protected function prepare(array $args = [])
{
parent::prepare($args);
$this->form = $this->form ?: ucfirst($this->action);
@ -63,17 +61,18 @@ class FormAction extends ManagedAction
return true;
}
public function isReadOnly($args) {
public function isReadOnly($args)
{
return !$this->isPost();
}
public function showPageNotice()
{
$this->showInstructions();
if ($msg = $this->getError()) {
if (!empty($msg = $this->getError())) {
$this->element('div', 'error', $msg);
}
if ($msg = $this->getInfo()) {
if (!empty($msg = $this->getInfo())) {
$this->element('div', 'info', $msg);
}
}

View File

@ -2097,7 +2097,7 @@ function common_get_mime_media($type)
function common_bare_mime($mimetype)
{
$mimetype = mb_strtolower($mimetype);
if ($semicolon = mb_strpos($mimetype, ';')) {
if (($semicolon = mb_strpos($mimetype, ';')) !== false) {
$mimetype = mb_substr($mimetype, 0, $semicolon);
}
return trim($mimetype);

View File

@ -598,7 +598,7 @@ class ActivityPubPlugin extends Plugin
if ($result === false) {
common_log(LOG_ERR, __METHOD__ . ': Error parsing webfinger IDs from text (preg_last_error=='.preg_last_error().').');
return [];
} elseif ($n_matches = count($wmatches)) {
} elseif (($n_matches = count($wmatches)) != 0) {
common_debug(sprintf('Found %d matches for WebFinger IDs: %s', $n_matches, _ve($wmatches)));
}
return $wmatches[1];
@ -891,10 +891,12 @@ class ActivityPubPlugin extends Plugin
// Local user can be ignored
}
$other = array_merge($other,
$other = array_merge(
$other,
Activitypub_profile::from_profile_collection(
$notice->getAttentionProfiles()
));
)
);
if ($notice->reply_to) {
try {
@ -906,10 +908,12 @@ class ActivityPubPlugin extends Plugin
// Local user can be ignored
}
$other = array_merge($other,
$other = array_merge(
$other,
Activitypub_profile::from_profile_collection(
$parent_notice->getAttentionProfiles()
));
)
);
} catch (NoParentNoticeException $e) {
// This is not a reply to something (has no parent)
} catch (NoResultException $e) {

View File

@ -115,7 +115,13 @@ class OEmbedAction extends Action
// TRANS: %d is an attachment ID.
$this->clientError(sprintf(_('Attachment %s not found.'), $id), 404);
}
if (empty($attachment->filename) && $file_oembed = File_oembed::getKV('file_id', $attachment->id)) {
if (
empty($attachment->filename)
&& !empty($file_oembed = File_oembed::getKV(
'file_id',
$attachment->id
))
) {
// Proxy the existing oembed information
$oembed['type']=$file_oembed->type;
$oembed['provider']=$file_oembed->provider;

File diff suppressed because it is too large Load Diff

View File

@ -964,7 +964,10 @@ class Ostatus_profile extends Managed_DataObject
$best = false;
// Take the exact-size avatar, or the largest avatar, or the first avatar if all sizeless
foreach ($object->avatarLinks as $avatar) {
if ($avatar->width == AVATAR_PROFILE_SIZE && $avatar->height = AVATAR_PROFILE_SIZE) {
if (
$avatar->width === AVATAR_PROFILE_SIZE
&& $avatar->height === AVATAR_PROFILE_SIZE
) {
// Exact match!
$best = $avatar;
break;

View File

@ -1,44 +1,38 @@
<?php
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
/**
* StatusNet, the distributed open-source microblogging tool
*
* Superclass for sitemap-generating actions
*
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Sitemap
* @package StatusNet
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @copyright 2010 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('STATUSNET')) {
exit(1);
}
defined('GNUSOCIAL') || die();
/**
* superclass for sitemap actions
*
* @category Sitemap
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
* @category Sitemap
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
class SitemapAction extends Action
{
@ -49,7 +43,7 @@ class SitemapAction extends Action
*
* @return void
*/
function handle()
public function handle()
{
parent::handle();
@ -58,8 +52,8 @@ class SitemapAction extends Action
$this->elementStart('urlset', array('xmlns' => 'http://www.sitemaps.org/schemas/sitemap/0.9'));
while (list($url, $lm, $cf, $p) = $this->nextUrl()) {
$this->showUrl($url, $lm, $cf, $p);
while (!is_null($next = $this->nextUrl())) {
$this->showUrl(...$next);
}
$this->elementEnd('urlset');
@ -67,7 +61,7 @@ class SitemapAction extends Action
$this->endXML();
}
function lastModified()
public function lastModified()
{
$y = $this->trimmed('year');
@ -88,8 +82,12 @@ class SitemapAction extends Action
}
}
function showUrl($url, $lastMod=null, $changeFreq=null, $priority=null)
{
public function showUrl(
$url,
$lastMod = null,
$changeFreq = null,
$priority = null
) {
$this->elementStart('url');
$this->element('loc', null, $url);
if (!is_null($lastMod)) {
@ -104,12 +102,12 @@ class SitemapAction extends Action
$this->elementEnd('url');
}
function nextUrl()
public function nextUrl()
{
return null;
}
function isReadOnly()
public function isReadOnly()
{
return true;
}

View File

@ -1,29 +1,28 @@
<?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 WebFingerPlugin
* @author James Walker <james@status.net>
* @author Mikael Nordfeldth <mmn@hethane.se>
* @package WebFingerPlugin
* @author James Walker <james@status.net>
* @author Mikael Nordfeldth <mmn@hethane.se>
* @copyright 2010 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
if (!defined('GNUSOCIAL')) { exit(1); }
defined('GNUSOCIAL') || die();
class OwnerxrdAction extends WebfingerAction
{
@ -49,7 +48,7 @@ class OwnerxrdAction extends WebfingerAction
// Check to see if a $config['webfinger']['owner'] has been set
// and then make sure 'subject' is set to that primary identity.
if ($owner = common_config('webfinger', 'owner')) {
if (!empty($owner = common_config('webfinger', 'owner'))) {
$this->xrd->aliases[] = $this->xrd->subject;
$this->xrd->subject = Discovery::normalize($owner);
} else {

View File

@ -67,7 +67,10 @@ call_user_func(function () {
// Find composer.json
if (is_file($path . '/composer.json')) {
if ($cfg = json_decode(file_get_contents($path . '/composer.json'), true)) {
if (!empty($cfg = json_decode(
file_get_contents($path . '/composer.json'),
true
))) {
if (isset($cfg['name']) && $cfg['name'] === 'psy/psysh') {
// We're inside the psysh project. Let's use the local
// Composer autoload.
@ -82,7 +85,10 @@ call_user_func(function () {
// Or a composer.lock
if (is_file($path . '/composer.lock')) {
if ($cfg = json_decode(file_get_contents($path . '/composer.lock'), true)) {
if (!empty($cfg = json_decode(
file_get_contents($path . '/composer.lock'),
true
))) {
foreach (array_merge($cfg['packages'], $cfg['packages-dev']) as $pkg) {
if (isset($pkg['name']) && $pkg['name'] === 'psy/psysh') {
// We're inside a project which requires psysh. We'll

View File

@ -1,21 +1,23 @@
#!/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) 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/>.
* @copyright 2010 StatusNet, Inc.
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/
define('INSTALLDIR', dirname(__DIR__));
@ -71,16 +73,19 @@ function get_max_profile_id()
*/
function get_missing_profiles($start, $end)
{
$query = sprintf("SELECT id FROM profile WHERE id BETWEEN %d AND %d",
$start, $end);
$query = sprintf(
'SELECT id FROM profile WHERE id BETWEEN %d AND %d',
$start,
$end
);
$profile = new Profile();
$profile->query($query);
$all = range($start, $end);
$known = array();
while ($row = $profile->fetch()) {
$known[] = intval($profile->id);
$known = [];
while ($profile->fetch()) {
$known[] = (int) $profile->id;
}
unset($profile);
@ -164,4 +169,3 @@ for ($start = $begin; $start <= $final; $start += $chunk) {
}
echo "done.\n";