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:
parent
d0f96a7023
commit
adc689cb15
@ -1,4 +1,19 @@
|
|||||||
<?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/>.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Settings for Jabber/XMPP integration
|
* Settings for Jabber/XMPP integration
|
||||||
*
|
*
|
||||||
@ -93,7 +108,10 @@ class ImsettingsAction extends SettingsAction
|
|||||||
$this->hidden('token', common_session_token());
|
$this->hidden('token', common_session_token());
|
||||||
$this->hidden('transport', $transport);
|
$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;
|
$user_im_prefs_by_transport[$transport] = $user_im_prefs;
|
||||||
$this->element('p', 'form_confirmed', $user_im_prefs->screenname);
|
$this->element('p', 'form_confirmed', $user_im_prefs->screenname);
|
||||||
$this->element(
|
$this->element(
|
||||||
|
@ -1,23 +1,25 @@
|
|||||||
<?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 - the distributed open-source microblogging tool
|
* @copyright 2010 StatusNet, Inc.
|
||||||
* Copyright (C) 2010, StatusNet, Inc.
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||||
*
|
|
||||||
* 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); }
|
defined('GNUSOCIAL') || die();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extended DB_DataObject to improve a few things:
|
* 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.
|
* DB_DataObject doesn't do this yet by itself.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function __destruct()
|
public function __destruct()
|
||||||
{
|
{
|
||||||
$this->free();
|
$this->free();
|
||||||
if (method_exists('DB_DataObject', '__destruct')) {
|
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
|
* It will still be freed properly when the original object
|
||||||
* gets destroyed.
|
* gets destroyed.
|
||||||
*/
|
*/
|
||||||
function __clone()
|
public function __clone()
|
||||||
{
|
{
|
||||||
$this->_DB_resultid = false;
|
$this->_DB_resultid = false;
|
||||||
}
|
}
|
||||||
@ -70,7 +72,7 @@ class Safe_DataObject extends GS_DataObject
|
|||||||
*
|
*
|
||||||
* @return array of variable names to include in serialization.
|
* @return array of variable names to include in serialization.
|
||||||
*/
|
*/
|
||||||
function __sleep()
|
public function __sleep()
|
||||||
{
|
{
|
||||||
$vars = array_keys(get_object_vars($this));
|
$vars = array_keys(get_object_vars($this));
|
||||||
$skip = array('_DB_resultid', '_link_loaded');
|
$skip = array('_DB_resultid', '_link_loaded');
|
||||||
@ -86,7 +88,7 @@ class Safe_DataObject extends GS_DataObject
|
|||||||
*
|
*
|
||||||
* Old cached objects may still have them.
|
* Old cached objects may still have them.
|
||||||
*/
|
*/
|
||||||
function __wakeup()
|
public function __wakeup()
|
||||||
{
|
{
|
||||||
// Refers to global state info from a previous process.
|
// Refers to global state info from a previous process.
|
||||||
// Clear this out so we don't accidentally break global
|
// Clear this out so we don't accidentally break global
|
||||||
@ -108,7 +110,7 @@ class Safe_DataObject extends GS_DataObject
|
|||||||
* @return mixed
|
* @return mixed
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
function __call($method, $params)
|
public function __call($method, $params)
|
||||||
{
|
{
|
||||||
$return = null;
|
$return = null;
|
||||||
// Yes, that's _call with one underscore, which does the
|
// 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..
|
* @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)
|
* or the array(tablename => array(column_name=>type)) if called with 1 argument.. (databasename)
|
||||||
*/
|
*/
|
||||||
function databaseStructure()
|
public function databaseStructure()
|
||||||
{
|
{
|
||||||
global $_DB_DATAOBJECT;
|
global $_DB_DATAOBJECT;
|
||||||
|
|
||||||
// Assignment code
|
if (!empty($args = func_get_args())) {
|
||||||
|
|
||||||
if ($args = func_get_args()) {
|
|
||||||
|
|
||||||
if (count($args) == 1) {
|
if (count($args) == 1) {
|
||||||
|
|
||||||
// this returns all the tables and their structure..
|
// this returns all the tables and their structure..
|
||||||
if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) {
|
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;
|
$x = new DB_DataObject;
|
||||||
@ -165,7 +166,6 @@ class Safe_DataObject extends GS_DataObject
|
|||||||
}
|
}
|
||||||
return $_DB_DATAOBJECT['INI'][$x->_database];
|
return $_DB_DATAOBJECT['INI'][$x->_database];
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
$_DB_DATAOBJECT['INI'][$args[0]] = isset($_DB_DATAOBJECT['INI'][$args[0]]) ?
|
$_DB_DATAOBJECT['INI'][$args[0]] = isset($_DB_DATAOBJECT['INI'][$args[0]]) ?
|
||||||
$_DB_DATAOBJECT['INI'][$args[0]] + $args[1] : $args[1];
|
$_DB_DATAOBJECT['INI'][$args[0]] + $args[1] : $args[1];
|
||||||
|
|
||||||
@ -175,7 +175,6 @@ class Safe_DataObject extends GS_DataObject
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (!$this->_database) {
|
if (!$this->_database) {
|
||||||
$this->_connect();
|
$this->_connect();
|
||||||
@ -190,7 +189,7 @@ class Safe_DataObject extends GS_DataObject
|
|||||||
&& !empty($_DB_DATAOBJECT['CONFIG']['proxy'])
|
&& !empty($_DB_DATAOBJECT['CONFIG']['proxy'])
|
||||||
) {
|
) {
|
||||||
if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) {
|
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') ? '' :
|
class_exists('DB_DataObject_Generator') ? '' :
|
||||||
require_once 'DB/DataObject/Generator.php';
|
require_once 'DB/DataObject/Generator.php';
|
||||||
@ -238,11 +237,21 @@ class Safe_DataObject extends GS_DataObject
|
|||||||
// should this fail!!!???
|
// should this fail!!!???
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
$this->debug("Cant find database schema: {$this->_database}/{$this->tableName()} \n".
|
$this->debug(
|
||||||
"in links file data: " . print_r($_DB_DATAOBJECT['INI'],true),"databaseStructure",5);
|
"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!)
|
// 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.
|
// 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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,14 +278,26 @@ class Safe_DataObject extends GS_DataObject
|
|||||||
|
|
||||||
if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) {
|
if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) {
|
||||||
if (!is_readable($ini)) {
|
if (!is_readable($ini)) {
|
||||||
$this->debug("ini file is not readable: $ini","databaseStructure",1);
|
$this->debug(
|
||||||
|
"ini file is not readable: {$ini}",
|
||||||
|
'databaseStructure',
|
||||||
|
1
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
$this->debug("Loaded ini file: $ini","databaseStructure",1);
|
$this->debug(
|
||||||
|
"Loaded ini file: {$ini}",
|
||||||
|
'databaseStructure',
|
||||||
|
1
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) {
|
if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) {
|
||||||
$this->debug("Missing ini file: $ini","databaseStructure",1);
|
$this->debug(
|
||||||
|
"Missing ini file: {$ini}",
|
||||||
|
'databaseStructure',
|
||||||
|
1
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -770,7 +770,7 @@ class User extends Managed_DataObject
|
|||||||
throw new ServerException(_('Single-user mode code called when not enabled.'));
|
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);
|
$user = User::getKV('nickname', $nickname);
|
||||||
if ($user instanceof User) {
|
if ($user instanceof User) {
|
||||||
return $user;
|
return $user;
|
||||||
|
@ -1,36 +1,31 @@
|
|||||||
<?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, the distributed open-source microblogging tool
|
|
||||||
*
|
|
||||||
* An activity
|
* 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
|
* @category Feed
|
||||||
* @package StatusNet
|
* @package GNUsocial
|
||||||
* @author Evan Prodromou <evan@status.net>
|
* @author Evan Prodromou <evan@status.net>
|
||||||
* @author Zach Copley <zach@status.net>
|
* @author Zach Copley <zach@status.net>
|
||||||
* @copyright 2010 StatusNet, Inc.
|
* @copyright 2010 StatusNet, Inc.
|
||||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||||
* @link http://status.net/
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('STATUSNET')) {
|
defined('GNUSOCIAL') || die();
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An activity in the ActivityStrea.ms world
|
* An activity in the ActivityStrea.ms world
|
||||||
@ -42,11 +37,10 @@ if (!defined('STATUSNET')) {
|
|||||||
* 'something else' is the object.
|
* 'something else' is the object.
|
||||||
*
|
*
|
||||||
* @category OStatus
|
* @category OStatus
|
||||||
* @package StatusNet
|
* @package GNUsocial
|
||||||
* @author Evan Prodromou <evan@status.net>
|
* @author Evan Prodromou <evan@status.net>
|
||||||
* @copyright 2010 StatusNet, Inc.
|
* @copyright 2010 StatusNet, Inc.
|
||||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||||
* @link http://status.net/
|
|
||||||
*/
|
*/
|
||||||
class Activity
|
class Activity
|
||||||
{
|
{
|
||||||
@ -113,7 +107,7 @@ class Activity
|
|||||||
* @param DOMElement $entry Atom entry to poke at
|
* @param DOMElement $entry Atom entry to poke at
|
||||||
* @param DOMElement $feed Atom feed, for context
|
* @param DOMElement $feed Atom feed, for context
|
||||||
*/
|
*/
|
||||||
function __construct($entry = null, $feed = null)
|
public function __construct($entry = null, $feed = null)
|
||||||
{
|
{
|
||||||
if (is_null($entry)) {
|
if (is_null($entry)) {
|
||||||
return;
|
return;
|
||||||
@ -130,14 +124,20 @@ class Activity
|
|||||||
$this->entry = $entry;
|
$this->entry = $entry;
|
||||||
$this->feed = $feed;
|
$this->feed = $feed;
|
||||||
|
|
||||||
if ($entry->namespaceURI == Activity::ATOM &&
|
if (
|
||||||
$entry->localName == 'entry') {
|
$entry->namespaceURI === Activity::ATOM
|
||||||
|
&& $entry->localName === 'entry'
|
||||||
|
) {
|
||||||
$this->_fromAtomEntry($entry, $feed);
|
$this->_fromAtomEntry($entry, $feed);
|
||||||
} else if ($entry->namespaceURI == Activity::RSS &&
|
} elseif (
|
||||||
$entry->localName == 'item') {
|
$entry->namespaceURI === Activity::RSS
|
||||||
|
&& $entry->localName === 'item'
|
||||||
|
) {
|
||||||
$this->_fromRssItem($entry, $feed);
|
$this->_fromRssItem($entry, $feed);
|
||||||
} else if ($entry->namespaceURI == Activity::SPEC &&
|
} elseif (
|
||||||
$entry->localName == 'object') {
|
$entry->namespaceURI === Activity::SPEC
|
||||||
|
&& $entry->localName === 'object'
|
||||||
|
) {
|
||||||
$this->_fromAtomEntry($entry, $feed);
|
$this->_fromAtomEntry($entry, $feed);
|
||||||
} else {
|
} else {
|
||||||
// Low level exception. No need for i18n.
|
// 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);
|
$pubEl = $this->_child($entry, self::PUBLISHED, self::ATOM);
|
||||||
|
|
||||||
@ -191,9 +191,7 @@ class Activity
|
|||||||
$this->objects[] = new ActivityObject($entry);
|
$this->objects[] = new ActivityObject($entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
$actorEl = $this->_child($entry, self::ACTOR);
|
if (!empty($actorEl = $this->_child($entry, self::ACTOR))) {
|
||||||
|
|
||||||
if (!empty($actorEl)) {
|
|
||||||
// Standalone <activity:actor> elements are a holdover from older
|
// Standalone <activity:actor> elements are a holdover from older
|
||||||
// versions of ActivityStreams. Newer feeds should have this data
|
// versions of ActivityStreams. Newer feeds should have this data
|
||||||
// integrated straight into <atom:author>.
|
// integrated straight into <atom:author>.
|
||||||
@ -211,22 +209,25 @@ class Activity
|
|||||||
$this->actor->id = $authorObj->id;
|
$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
|
// An <atom:author> in the entry overrides any author info on
|
||||||
// the surrounding feed.
|
// the surrounding feed.
|
||||||
$this->actor = new ActivityObject($authorEl);
|
$this->actor = new ActivityObject($authorEl);
|
||||||
|
} elseif (
|
||||||
} else if (!empty($feed) &&
|
!empty($feed)
|
||||||
$subjectEl = $this->_child($feed, self::SUBJECT)) {
|
&& !empty($subjectEl = $this->_child($feed, self::SUBJECT))
|
||||||
|
) {
|
||||||
// Feed subject is used for things like groups.
|
// Feed subject is used for things like groups.
|
||||||
// Should actually possibly not be interpreted as an actor...?
|
// Should actually possibly not be interpreted as an actor...?
|
||||||
$this->actor = new ActivityObject($subjectEl);
|
$this->actor = new ActivityObject($subjectEl);
|
||||||
|
} elseif (
|
||||||
} else if (!empty($feed) && $authorEl = $this->_child($feed, self::AUTHOR,
|
!empty($feed)
|
||||||
self::ATOM)) {
|
&& !empty($authorEl = $this->_child($feed, self::AUTHOR, self::ATOM))
|
||||||
|
) {
|
||||||
// If there's no <atom:author> on the entry, it's safe to assume
|
// If there's no <atom:author> on the entry, it's safe to assume
|
||||||
// the containing feed's authorship info applies.
|
// the containing feed's authorship info applies.
|
||||||
$this->actor = new ActivityObject($authorEl);
|
$this->actor = new ActivityObject($authorEl);
|
||||||
@ -271,7 +272,7 @@ class Activity
|
|||||||
$this->editLink = ActivityUtils::getLink($entry, 'edit', 'application/atom+xml');
|
$this->editLink = ActivityUtils::getLink($entry, 'edit', 'application/atom+xml');
|
||||||
}
|
}
|
||||||
|
|
||||||
function _fromRssItem($item, $channel)
|
public function _fromRssItem($item, $channel)
|
||||||
{
|
{
|
||||||
$verbEl = $this->_child($item, self::VERB);
|
$verbEl = $this->_child($item, self::VERB);
|
||||||
|
|
||||||
@ -288,11 +289,23 @@ class Activity
|
|||||||
$this->time = strtotime($pubDateEl->textContent);
|
$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);
|
$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);
|
$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
|
// Special case for Posterous.com
|
||||||
$this->actor = ActivityObject::fromPosterousAuthor($posterousEl);
|
$this->actor = ActivityObject::fromPosterousAuthor($posterousEl);
|
||||||
} elseif (!empty($channel)) {
|
} elseif (!empty($channel)) {
|
||||||
@ -347,7 +360,7 @@ class Activity
|
|||||||
* @return DOMElement Atom entry
|
* @return DOMElement Atom entry
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function toAtomEntry()
|
public function toAtomEntry()
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -359,7 +372,7 @@ class Activity
|
|||||||
* @return array $activity
|
* @return array $activity
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function asArray()
|
public function asArray()
|
||||||
{
|
{
|
||||||
$activity = array();
|
$activity = array();
|
||||||
|
|
||||||
@ -416,7 +429,6 @@ class Activity
|
|||||||
// Context stuff.
|
// Context stuff.
|
||||||
|
|
||||||
if (!empty($this->context)) {
|
if (!empty($this->context)) {
|
||||||
|
|
||||||
if (!empty($this->context->location)) {
|
if (!empty($this->context->location)) {
|
||||||
$loc = $this->context->location;
|
$loc = $this->context->location;
|
||||||
|
|
||||||
@ -528,15 +540,23 @@ class Activity
|
|||||||
return array_filter($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);
|
$xs = new XMLStringer(true);
|
||||||
$this->outputTo($xs, $namespace, $author, $source);
|
$this->outputTo($xs, $namespace, $author, $source);
|
||||||
return $xs->getString();
|
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) {
|
if ($namespace) {
|
||||||
$attrs = array('xmlns' => 'http://www.w3.org/2005/Atom',
|
$attrs = array('xmlns' => 'http://www.w3.org/2005/Atom',
|
||||||
'xmlns:thr' => 'http://purl.org/syndication/thread/1.0',
|
'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') {
|
if ($this->verb == ActivityVerb::POST && count($this->objects) == 1 && $tag == 'entry') {
|
||||||
|
|
||||||
$obj = $this->objects[0];
|
$obj = $this->objects[0];
|
||||||
$obj->outputTo($xs, null);
|
$obj->outputTo($xs, null);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$xs->element('id', null, $this->id);
|
$xs->element('id', null, $this->id);
|
||||||
|
|
||||||
@ -582,7 +600,6 @@ class Activity
|
|||||||
'type' => 'text/html',
|
'type' => 'text/html',
|
||||||
'href' => $this->link));
|
'href' => $this->link));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$xs->element('activity:verb', null, $this->verb);
|
$xs->element('activity:verb', null, $this->verb);
|
||||||
@ -607,21 +624,24 @@ class Activity
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($this->context)) {
|
if (!empty($this->context)) {
|
||||||
|
|
||||||
if (!empty($this->context->replyToID)) {
|
if (!empty($this->context->replyToID)) {
|
||||||
if (!empty($this->context->replyToUrl)) {
|
if (!empty($this->context->replyToUrl)) {
|
||||||
$xs->element('thr:in-reply-to',
|
$xs->element('thr:in-reply-to', [
|
||||||
array('ref' => $this->context->replyToID,
|
'ref' => $this->context->replyToID,
|
||||||
'href' => $this->context->replyToUrl));
|
'href' => $this->context->replyToUrl,
|
||||||
|
]);
|
||||||
} else {
|
} else {
|
||||||
$xs->element('thr:in-reply-to',
|
$xs->element('thr:in-reply-to', [
|
||||||
array('ref' => $this->context->replyToID));
|
'ref' => $this->context->replyToID,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($this->context->replyToUrl)) {
|
if (!empty($this->context->replyToUrl)) {
|
||||||
$xs->element('link', array('rel' => 'related',
|
$xs->element('link', [
|
||||||
'href' => $this->context->replyToUrl));
|
'rel' => 'related',
|
||||||
|
'href' => $this->context->replyToUrl,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($this->context->conversation)) {
|
if (!empty($this->context->conversation)) {
|
||||||
@ -631,14 +651,18 @@ class Activity
|
|||||||
$convattr['href'] = $conv->getUrl();
|
$convattr['href'] = $conv->getUrl();
|
||||||
$convattr['local_id'] = $conv->getID();
|
$convattr['local_id'] = $conv->getID();
|
||||||
$convattr['ref'] = $conv->getUri();
|
$convattr['ref'] = $conv->getUri();
|
||||||
$xs->element('link', array('rel' => 'ostatus:'.ActivityContext::CONVERSATION,
|
$xs->element('link', [
|
||||||
'href' => $convattr['href']));
|
'rel' => 'ostatus:' . ActivityContext::CONVERSATION,
|
||||||
|
'href' => $convattr['href'],
|
||||||
|
]);
|
||||||
} else {
|
} else {
|
||||||
$convattr['ref'] = $this->context->conversation;
|
$convattr['ref'] = $this->context->conversation;
|
||||||
}
|
}
|
||||||
$xs->element('ostatus:'.ActivityContext::CONVERSATION,
|
$xs->element(
|
||||||
|
'ostatus:' . ActivityContext::CONVERSATION,
|
||||||
$convattr,
|
$convattr,
|
||||||
$this->context->conversation);
|
$this->context->conversation
|
||||||
|
);
|
||||||
/* Since we use XMLWriter we just use the previously hardcoded prefix for ostatus,
|
/* Since we use XMLWriter we just use the previously hardcoded prefix for ostatus,
|
||||||
otherwise we should use something like this:
|
otherwise we should use something like this:
|
||||||
$xs->elementNS(array(ActivityContext::OSTATUS => 'ostatus'), // namespace
|
$xs->elementNS(array(ActivityContext::OSTATUS => 'ostatus'), // namespace
|
||||||
@ -649,9 +673,11 @@ class Activity
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->context->attention as $attnURI=>$type) {
|
foreach ($this->context->attention as $attnURI=>$type) {
|
||||||
$xs->element('link', array('rel' => ActivityContext::MENTIONED,
|
$xs->element('link', [
|
||||||
ActivityContext::OBJECTTYPE => $type, // FIXME: undocumented
|
'rel' => ActivityContext::MENTIONED,
|
||||||
'href' => $attnURI));
|
ActivityContext::OBJECTTYPE => $type, // @fixme undocumented
|
||||||
|
'href' => $attnURI,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($this->context->location)) {
|
if (!empty($this->context->location)) {
|
||||||
@ -759,7 +785,7 @@ class Activity
|
|||||||
* @param int $tm Unix timestamp
|
* @param int $tm Unix timestamp
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
static function iso8601Date($tm)
|
public static function iso8601Date($tm)
|
||||||
{
|
{
|
||||||
$dateStr = date('d F Y H:i:s', $tm);
|
$dateStr = date('d F Y H:i:s', $tm);
|
||||||
$d = new DateTime($dateStr, new DateTimeZone('UTC'));
|
$d = new DateTime($dateStr, new DateTimeZone('UTC'));
|
||||||
|
101
lib/ui/theme.php
101
lib/ui/theme.php
@ -1,36 +1,31 @@
|
|||||||
<?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, the distributed open-source microblogging tool
|
|
||||||
*
|
|
||||||
* Utilities for theme files and paths
|
* 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
|
* @category Paths
|
||||||
* @package StatusNet
|
* @package GNUsocial
|
||||||
* @author Evan Prodromou <evan@status.net>
|
* @author Evan Prodromou <evan@status.net>
|
||||||
* @author Sarven Capadisli <csarven@status.net>
|
* @author Sarven Capadisli <csarven@status.net>
|
||||||
* @copyright 2008-2009 StatusNet, Inc.
|
* @copyright 2008-2009 StatusNet, Inc.
|
||||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||||
* @link http://status.net/
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('STATUSNET') && !defined('LACONICA')) {
|
defined('GNUSOCIAL') || die();
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for querying and manipulating a theme
|
* Class for querying and manipulating a theme
|
||||||
@ -46,18 +41,17 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
|
|||||||
* to have a class instead.
|
* to have a class instead.
|
||||||
*
|
*
|
||||||
* @category Output
|
* @category Output
|
||||||
* @package StatusNet
|
* @package GNUsocial
|
||||||
* @author Evan Prodromou <evan@status.net>
|
* @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
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||||
* @link http://status.net/
|
|
||||||
*/
|
*/
|
||||||
class Theme
|
class Theme
|
||||||
{
|
{
|
||||||
const FALLBACK = 'neo';
|
const FALLBACK = 'neo';
|
||||||
|
|
||||||
var $name = null;
|
public $name = null;
|
||||||
var $dir = null;
|
public $dir = null;
|
||||||
var $path = null;
|
public $path = null;
|
||||||
protected $metadata = null; // access via getMetadata() lazy-loader
|
protected $metadata = null; // access via getMetadata() lazy-loader
|
||||||
protected $externals = null;
|
protected $externals = null;
|
||||||
protected $deps = null;
|
protected $deps = null;
|
||||||
@ -70,7 +64,7 @@ class Theme
|
|||||||
* @param string $name Name of the theme; defaults to config value
|
* @param string $name Name of the theme; defaults to config value
|
||||||
* @throws ServerException
|
* @throws ServerException
|
||||||
*/
|
*/
|
||||||
function __construct($name = null)
|
public function __construct($name = null)
|
||||||
{
|
{
|
||||||
if (empty($name)) {
|
if (empty($name)) {
|
||||||
$name = common_config('site', 'theme');
|
$name = common_config('site', 'theme');
|
||||||
@ -107,14 +101,15 @@ class Theme
|
|||||||
|
|
||||||
// Ruh roh. Fall back to default, then.
|
// Ruh roh. Fall back to default, then.
|
||||||
|
|
||||||
common_log(LOG_WARNING, sprintf("Unable to find theme '%s', falling back to default theme '%s'",
|
common_log(LOG_WARNING, sprintf(
|
||||||
|
'Unable to find theme \'%s\', falling back to default theme \'%s\'',
|
||||||
$name,
|
$name,
|
||||||
Theme::FALLBACK));
|
Theme::FALLBACK
|
||||||
|
));
|
||||||
|
|
||||||
$this->name = Theme::FALLBACK;
|
$this->name = Theme::FALLBACK;
|
||||||
$this->dir = $instroot.'/'.Theme::FALLBACK;
|
$this->dir = $instroot.'/'.Theme::FALLBACK;
|
||||||
$this->path = $this->relativeThemePath('theme', 'theme', Theme::FALLBACK);
|
$this->path = $this->relativeThemePath('theme', 'theme', Theme::FALLBACK);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -135,10 +130,10 @@ class Theme
|
|||||||
$sslserver = common_config($group, 'sslserver');
|
$sslserver = common_config($group, 'sslserver');
|
||||||
|
|
||||||
if (empty($sslserver)) {
|
if (empty($sslserver)) {
|
||||||
if (is_string(common_config('site', 'sslserver')) &&
|
$sslserver = common_config('site', 'sslserver');
|
||||||
mb_strlen(common_config('site', 'sslserver')) > 0) {
|
if (is_string($sslserver) && strlen($sslserver) > 0) {
|
||||||
$server = common_config('site', 'sslserver');
|
$server = $sslserver;
|
||||||
} else if (common_config('site', 'server')) {
|
} elseif (!empty(common_config('site', 'server'))) {
|
||||||
$server = common_config('site', 'server');
|
$server = common_config('site', 'server');
|
||||||
}
|
}
|
||||||
$path = common_config('site', 'path') . '/';
|
$path = common_config('site', 'path') . '/';
|
||||||
@ -191,7 +186,7 @@ class Theme
|
|||||||
*
|
*
|
||||||
* @return string full pathname, like /var/www/mublog/theme/default/logo.png
|
* @return string full pathname, like /var/www/mublog/theme/default/logo.png
|
||||||
*/
|
*/
|
||||||
function getFile($relative)
|
public function getFile($relative)
|
||||||
{
|
{
|
||||||
return $this->dir.'/'.$relative;
|
return $this->dir.'/'.$relative;
|
||||||
}
|
}
|
||||||
@ -203,7 +198,7 @@ class Theme
|
|||||||
*
|
*
|
||||||
* @return string full URL, like 'http://example.com/theme/default/logo.png'
|
* @return string full URL, like 'http://example.com/theme/default/logo.png'
|
||||||
*/
|
*/
|
||||||
function getPath($relative)
|
public function getPath($relative)
|
||||||
{
|
{
|
||||||
return $this->path.'/'.$relative;
|
return $this->path.'/'.$relative;
|
||||||
}
|
}
|
||||||
@ -215,7 +210,7 @@ class Theme
|
|||||||
*
|
*
|
||||||
* @return array of strings with theme names
|
* @return array of strings with theme names
|
||||||
*/
|
*/
|
||||||
function getDeps()
|
public function getDeps()
|
||||||
{
|
{
|
||||||
if ($this->deps === null) {
|
if ($this->deps === null) {
|
||||||
$chain = $this->doGetDeps(array($this->name));
|
$chain = $this->doGetDeps(array($this->name));
|
||||||
@ -238,9 +233,11 @@ class Theme
|
|||||||
array_unshift($chain, $include);
|
array_unshift($chain, $include);
|
||||||
return $theme->doGetDeps($chain);
|
return $theme->doGetDeps($chain);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
common_log(LOG_ERR,
|
common_log(
|
||||||
"Exception while fetching theme dependencies " .
|
LOG_ERR,
|
||||||
"for $this->name: " . $e->getMessage());
|
'Exception while fetching theme dependencies '
|
||||||
|
. "for {$this->name}: {$e->getMessage()}"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -253,9 +250,9 @@ class Theme
|
|||||||
*
|
*
|
||||||
* @return array associative of strings
|
* @return array associative of strings
|
||||||
*/
|
*/
|
||||||
function getMetadata()
|
public function getMetadata()
|
||||||
{
|
{
|
||||||
if ($this->metadata == null) {
|
if (is_null($this->metadata)) {
|
||||||
$this->metadata = $this->doGetMetadata();
|
$this->metadata = $this->doGetMetadata();
|
||||||
}
|
}
|
||||||
return $this->metadata;
|
return $this->metadata;
|
||||||
@ -284,9 +281,9 @@ class Theme
|
|||||||
* @return array of URL strings
|
* @return array of URL strings
|
||||||
* @throws ServerException
|
* @throws ServerException
|
||||||
*/
|
*/
|
||||||
function getExternals()
|
public function getExternals()
|
||||||
{
|
{
|
||||||
if ($this->externals == null) {
|
if (is_null($this->externals)) {
|
||||||
$data = $this->getMetadata();
|
$data = $this->getMetadata();
|
||||||
if (!empty($data['external'])) {
|
if (!empty($data['external'])) {
|
||||||
$ext = (array)$data['external'];
|
$ext = (array)$data['external'];
|
||||||
@ -313,7 +310,7 @@ class Theme
|
|||||||
* @return string File path to the theme file
|
* @return string File path to the theme file
|
||||||
* @throws ServerException
|
* @throws ServerException
|
||||||
*/
|
*/
|
||||||
static function file($relative, $name=null)
|
public static function file($relative, $name = null)
|
||||||
{
|
{
|
||||||
$theme = new Theme($name);
|
$theme = new Theme($name);
|
||||||
return $theme->getFile($relative);
|
return $theme->getFile($relative);
|
||||||
@ -328,7 +325,7 @@ class Theme
|
|||||||
* @return string URL of the file
|
* @return string URL of the file
|
||||||
* @throws ServerException
|
* @throws ServerException
|
||||||
*/
|
*/
|
||||||
static function path($relative, $name=null)
|
public static function path($relative, $name = null)
|
||||||
{
|
{
|
||||||
$theme = new Theme($name);
|
$theme = new Theme($name);
|
||||||
return $theme->getPath($relative);
|
return $theme->getPath($relative);
|
||||||
@ -339,7 +336,7 @@ class Theme
|
|||||||
*
|
*
|
||||||
* @return array list of available theme names
|
* @return array list of available theme names
|
||||||
*/
|
*/
|
||||||
static function listAvailable()
|
public static function listAvailable()
|
||||||
{
|
{
|
||||||
$local = self::subdirsOf(self::localRoot());
|
$local = self::subdirsOf(self::localRoot());
|
||||||
$install = self::subdirsOf(self::installRoot());
|
$install = self::subdirsOf(self::installRoot());
|
||||||
@ -363,7 +360,7 @@ class Theme
|
|||||||
$subdirs = array();
|
$subdirs = array();
|
||||||
|
|
||||||
if (is_dir($dir)) {
|
if (is_dir($dir)) {
|
||||||
if ($dh = opendir($dir)) {
|
if (($dh = opendir($dir)) !== false) {
|
||||||
while (($filename = readdir($dh)) !== false) {
|
while (($filename = readdir($dh)) !== false) {
|
||||||
if ($filename != '..' && $filename !== '.' &&
|
if ($filename != '..' && $filename !== '.' &&
|
||||||
is_dir($dir.'/'.$filename)) {
|
is_dir($dir.'/'.$filename)) {
|
||||||
@ -409,7 +406,7 @@ class Theme
|
|||||||
return $instroot;
|
return $instroot;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function validName($name)
|
public static function validName($name)
|
||||||
{
|
{
|
||||||
return preg_match('/^[a-z0-9][a-z0-9_-]*$/i', $name);
|
return preg_match('/^[a-z0-9][a-z0-9_-]*$/i', $name);
|
||||||
}
|
}
|
||||||
|
@ -1,43 +1,40 @@
|
|||||||
<?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/>.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Form action extendable class.
|
* Form action extendable class.
|
||||||
*
|
*
|
||||||
* PHP version 5
|
|
||||||
*
|
|
||||||
* @category Action
|
* @category Action
|
||||||
* @package StatusNet
|
* @package GNUsocial
|
||||||
* @author Evan Prodromou <evan@status.net>
|
* @author Evan Prodromou <evan@status.net>
|
||||||
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
|
* @copyright 2008, 2009 StatusNet, Inc.
|
||||||
* @link http://status.net/
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||||
*
|
|
||||||
* StatusNet - the distributed open-source microblogging tool
|
|
||||||
* Copyright (C) 2008, 2009, StatusNet, Inc.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('GNUSOCIAL')) { exit(1); }
|
defined('GNUSOCIAL') || die();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Form action extendable class
|
* Form action extendable class
|
||||||
*
|
*
|
||||||
* @category Action
|
* @category Action
|
||||||
* @package StatusNet
|
* @package GNUsocial
|
||||||
* @author Evan Prodromou <evan@status.net>
|
* @author Evan Prodromou <evan@status.net>
|
||||||
* @author Mikael Nordfeldth <evan@status.net>
|
* @author Mikael Nordfeldth <evan@status.net>
|
||||||
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
|
* @copyright 2008, 2009 StatusNet, Inc.
|
||||||
* @link http://status.net/
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||||
*/
|
*/
|
||||||
class FormAction extends ManagedAction
|
class FormAction extends ManagedAction
|
||||||
{
|
{
|
||||||
@ -47,7 +44,8 @@ class FormAction extends ManagedAction
|
|||||||
protected $needLogin = true;
|
protected $needLogin = true;
|
||||||
protected $canPost = true;
|
protected $canPost = true;
|
||||||
|
|
||||||
protected function prepare(array $args = []) {
|
protected function prepare(array $args = [])
|
||||||
|
{
|
||||||
parent::prepare($args);
|
parent::prepare($args);
|
||||||
|
|
||||||
$this->form = $this->form ?: ucfirst($this->action);
|
$this->form = $this->form ?: ucfirst($this->action);
|
||||||
@ -63,17 +61,18 @@ class FormAction extends ManagedAction
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isReadOnly($args) {
|
public function isReadOnly($args)
|
||||||
|
{
|
||||||
return !$this->isPost();
|
return !$this->isPost();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function showPageNotice()
|
public function showPageNotice()
|
||||||
{
|
{
|
||||||
$this->showInstructions();
|
$this->showInstructions();
|
||||||
if ($msg = $this->getError()) {
|
if (!empty($msg = $this->getError())) {
|
||||||
$this->element('div', 'error', $msg);
|
$this->element('div', 'error', $msg);
|
||||||
}
|
}
|
||||||
if ($msg = $this->getInfo()) {
|
if (!empty($msg = $this->getInfo())) {
|
||||||
$this->element('div', 'info', $msg);
|
$this->element('div', 'info', $msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2097,7 +2097,7 @@ function common_get_mime_media($type)
|
|||||||
function common_bare_mime($mimetype)
|
function common_bare_mime($mimetype)
|
||||||
{
|
{
|
||||||
$mimetype = mb_strtolower($mimetype);
|
$mimetype = mb_strtolower($mimetype);
|
||||||
if ($semicolon = mb_strpos($mimetype, ';')) {
|
if (($semicolon = mb_strpos($mimetype, ';')) !== false) {
|
||||||
$mimetype = mb_substr($mimetype, 0, $semicolon);
|
$mimetype = mb_substr($mimetype, 0, $semicolon);
|
||||||
}
|
}
|
||||||
return trim($mimetype);
|
return trim($mimetype);
|
||||||
|
@ -598,7 +598,7 @@ class ActivityPubPlugin extends Plugin
|
|||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
common_log(LOG_ERR, __METHOD__ . ': Error parsing webfinger IDs from text (preg_last_error=='.preg_last_error().').');
|
common_log(LOG_ERR, __METHOD__ . ': Error parsing webfinger IDs from text (preg_last_error=='.preg_last_error().').');
|
||||||
return [];
|
return [];
|
||||||
} 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)));
|
common_debug(sprintf('Found %d matches for WebFinger IDs: %s', $n_matches, _ve($wmatches)));
|
||||||
}
|
}
|
||||||
return $wmatches[1];
|
return $wmatches[1];
|
||||||
@ -891,10 +891,12 @@ class ActivityPubPlugin extends Plugin
|
|||||||
// Local user can be ignored
|
// Local user can be ignored
|
||||||
}
|
}
|
||||||
|
|
||||||
$other = array_merge($other,
|
$other = array_merge(
|
||||||
|
$other,
|
||||||
Activitypub_profile::from_profile_collection(
|
Activitypub_profile::from_profile_collection(
|
||||||
$notice->getAttentionProfiles()
|
$notice->getAttentionProfiles()
|
||||||
));
|
)
|
||||||
|
);
|
||||||
|
|
||||||
if ($notice->reply_to) {
|
if ($notice->reply_to) {
|
||||||
try {
|
try {
|
||||||
@ -906,10 +908,12 @@ class ActivityPubPlugin extends Plugin
|
|||||||
// Local user can be ignored
|
// Local user can be ignored
|
||||||
}
|
}
|
||||||
|
|
||||||
$other = array_merge($other,
|
$other = array_merge(
|
||||||
|
$other,
|
||||||
Activitypub_profile::from_profile_collection(
|
Activitypub_profile::from_profile_collection(
|
||||||
$parent_notice->getAttentionProfiles()
|
$parent_notice->getAttentionProfiles()
|
||||||
));
|
)
|
||||||
|
);
|
||||||
} catch (NoParentNoticeException $e) {
|
} catch (NoParentNoticeException $e) {
|
||||||
// This is not a reply to something (has no parent)
|
// This is not a reply to something (has no parent)
|
||||||
} catch (NoResultException $e) {
|
} catch (NoResultException $e) {
|
||||||
|
@ -115,7 +115,13 @@ class OEmbedAction extends Action
|
|||||||
// TRANS: %d is an attachment ID.
|
// TRANS: %d is an attachment ID.
|
||||||
$this->clientError(sprintf(_('Attachment %s not found.'), $id), 404);
|
$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
|
// Proxy the existing oembed information
|
||||||
$oembed['type']=$file_oembed->type;
|
$oembed['type']=$file_oembed->type;
|
||||||
$oembed['provider']=$file_oembed->provider;
|
$oembed['provider']=$file_oembed->provider;
|
||||||
|
@ -1,37 +1,33 @@
|
|||||||
<?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/>.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Laconica, the distributed open-source microblogging tool
|
|
||||||
*
|
|
||||||
* Plugin to check submitted notices with Mollom
|
* Plugin to check submitted notices with Mollom
|
||||||
*
|
*
|
||||||
* 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/>.
|
|
||||||
*
|
|
||||||
* Mollom is a bayesian spam checker, wrapped into a webservice
|
* Mollom is a bayesian spam checker, wrapped into a webservice
|
||||||
* This plugin is based on the Drupal Mollom Plugin
|
* This plugin is based on the Drupal Mollom Plugin
|
||||||
*
|
*
|
||||||
* @category Plugin
|
* @category Plugin
|
||||||
* @package Laconica
|
* @package GNUsocial
|
||||||
* @author Brenda Wallace <brenda@cpan.org>
|
* @author Brenda Wallace <brenda@cpan.org>
|
||||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
* @copyright 2010 StatusNet, Inc.
|
||||||
*
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('STATUSNET')) {
|
defined('GNUsocial') || die();
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
define('MOLLOMPLUGIN_VERSION', '0.1');
|
define('MOLLOMPLUGIN_VERSION', '0.1');
|
||||||
define('MOLLOM_API_VERSION', '1.0');
|
define('MOLLOM_API_VERSION', '1.0');
|
||||||
@ -58,9 +54,10 @@ define('MOLLOM_REDIRECT', 1200);
|
|||||||
* Mollom is a bayesian spam filter provided by webservice.
|
* Mollom is a bayesian spam filter provided by webservice.
|
||||||
*
|
*
|
||||||
* @category Plugin
|
* @category Plugin
|
||||||
* @package Laconica
|
* @package GNUsocial
|
||||||
* @author Brenda Wallace <shiny@cpan.org>
|
* @author Brenda Wallace <shiny@cpan.org>
|
||||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
* @copyright 2010 StatusNet, Inc.
|
||||||
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||||
*
|
*
|
||||||
* @see Event
|
* @see Event
|
||||||
*/
|
*/
|
||||||
@ -68,36 +65,38 @@ class MollomPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
public $public_key;
|
public $public_key;
|
||||||
public $private_key;
|
public $private_key;
|
||||||
public $servers;
|
public $servers = null;
|
||||||
|
|
||||||
function onStartNoticeSave($notice)
|
public function onStartNoticeSave($notice)
|
||||||
{
|
{
|
||||||
if ($this->public_key) {
|
if ($this->public_key) {
|
||||||
//Check spam
|
//Check spam
|
||||||
$data = array(
|
$data = [
|
||||||
'post_body' => $notice->content,
|
'post_body' => $notice->content,
|
||||||
'author_name' => $profile->nickname,
|
'author_name' => $profile->nickname,
|
||||||
'author_url' => $profile->homepage,
|
'author_url' => $profile->homepage,
|
||||||
'author_id' => $profile->id,
|
'author_id' => $profile->id,
|
||||||
'author_ip' => $this->getClientIp(),
|
'author_ip' => $this->getClientIp(),
|
||||||
);
|
];
|
||||||
$response = $this->mollom('mollom.checkContent', $data);
|
$response = $this->mollom('mollom.checkContent', $data);
|
||||||
if ($response['spam'] == MOLLOM_ANALYSIS_SPAM) {
|
switch ($response['spam']) {
|
||||||
|
case MOLLOM_ANALYSIS_SPAM:
|
||||||
// TRANS: Client exception thrown when notice content triggers the spam filter.
|
// TRANS: Client exception thrown when notice content triggers the spam filter.
|
||||||
throw new ClientException(_m('Spam Detected.'), 400);
|
throw new ClientException(_m('Spam Detected.'), 400);
|
||||||
}
|
case MOLLOM_ANALYSIS_UNSURE:
|
||||||
if ($response['spam'] == MOLLOM_ANALYSIS_UNSURE) {
|
|
||||||
//if unsure, let through
|
//if unsure, let through
|
||||||
}
|
break;
|
||||||
if($response['spam'] == MOLLOM_ANALYSIS_HAM) {
|
case MOLLOM_ANALYSIS_HAM:
|
||||||
// all good! :-)
|
// all good! :-)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getClientIP() {
|
public function getClientIP()
|
||||||
|
{
|
||||||
if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
|
if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
|
||||||
// Note: order matters here; use proxy-forwarded stuff first
|
// Note: order matters here; use proxy-forwarded stuff first
|
||||||
foreach (array('HTTP_X_FORWARDED_FOR', 'CLIENT-IP', 'REMOTE_ADDR') as $k) {
|
foreach (array('HTTP_X_FORWARDED_FOR', 'CLIENT-IP', 'REMOTE_ADDR') as $k) {
|
||||||
@ -114,7 +113,8 @@ class MollomPlugin extends Plugin
|
|||||||
* automatically add the information required to authenticate against
|
* automatically add the information required to authenticate against
|
||||||
* Mollom.
|
* Mollom.
|
||||||
*/
|
*/
|
||||||
function mollom($method, $data = array()) {
|
public function mollom($method, $data = [])
|
||||||
|
{
|
||||||
if (!extension_loaded('xmlrpc')) {
|
if (!extension_loaded('xmlrpc')) {
|
||||||
if (!dl('xmlrpc.so')) {
|
if (!dl('xmlrpc.so')) {
|
||||||
common_log(LOG_ERR, "Can't pingback; xmlrpc extension not available.");
|
common_log(LOG_ERR, "Can't pingback; xmlrpc extension not available.");
|
||||||
@ -126,12 +126,12 @@ class MollomPlugin extends Plugin
|
|||||||
// Retrieve the list of Mollom servers from the database:
|
// Retrieve the list of Mollom servers from the database:
|
||||||
$servers = $this->servers;
|
$servers = $this->servers;
|
||||||
|
|
||||||
if ($servers == NULL) {
|
if (is_null($servers)) {
|
||||||
// Retrieve a list of valid Mollom servers from mollom.com:
|
// Retrieve a list of valid Mollom servers from mollom.com:
|
||||||
$servers = $this->xmlrpc('http://xmlrpc.mollom.com/'. MOLLOM_API_VERSION, 'mollom.getServerList', $this->authentication());
|
$servers = $this->xmlrpc('http://xmlrpc.mollom.com/'. MOLLOM_API_VERSION, 'mollom.getServerList', $this->authentication());
|
||||||
|
|
||||||
// Store the list of servers in the database:
|
// Store the list of servers in the database:
|
||||||
// TODO! variable_set('mollom_servers', $servers);
|
// @todo variable_set('mollom_servers', $servers);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($servers)) {
|
if (is_array($servers)) {
|
||||||
@ -139,45 +139,61 @@ class MollomPlugin extends Plugin
|
|||||||
foreach ($servers as $server) {
|
foreach ($servers as $server) {
|
||||||
$auth = $this->authentication();
|
$auth = $this->authentication();
|
||||||
$data = array_merge($data, $auth);
|
$data = array_merge($data, $auth);
|
||||||
$result = $this->xmlrpc($server .'/'. MOLLOM_API_VERSION, $method, $data);
|
$result = $this->xmlrpc(
|
||||||
|
$server . '/' . MOLLOM_API_VERSION,
|
||||||
|
$method,
|
||||||
|
$data
|
||||||
|
);
|
||||||
|
|
||||||
// Debug output:
|
// Debug output:
|
||||||
if (isset($data['session_id'])) {
|
if (array_key_exists('session_id', $data)) {
|
||||||
common_debug("called $method at server $server with session ID '". $data['session_id'] ."'");
|
common_debug(
|
||||||
}
|
"called {$method} at server {$server} with session ID "
|
||||||
else {
|
. "'{$data['session_id']}'"
|
||||||
common_debug("called $method at server $server with no session ID");
|
);
|
||||||
|
} else {
|
||||||
|
common_debug(
|
||||||
|
"called {$method} at server {$server} with no session ID"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($errno = $this->xmlrpc_errno()) {
|
if (!empty($errno = $this->xmlrpc_errno())) {
|
||||||
common_log(LOG_ERR, sprintf('Error @errno: %s - %s - %s - <pre>%s</pre>', $this->xmlrpc_errno(), $server, $this->xmlrpc_error_msg(), $method, print_r($data, TRUE)));
|
common_log(LOG_ERR, sprintf(
|
||||||
|
'Error @errno: %s - %s - %s - <pre>%s</pre>',
|
||||||
|
$this->xmlrpc_errno(),
|
||||||
|
$server,
|
||||||
|
$this->xmlrpc_error_msg(),
|
||||||
|
$method,
|
||||||
|
print_r($data, true)
|
||||||
|
));
|
||||||
|
|
||||||
if ($errno == MOLLOM_REFRESH) {
|
if ($errno === MOLLOM_REFRESH) {
|
||||||
// Retrieve a list of valid Mollom servers from mollom.com:
|
// Retrieve a list of valid Mollom servers from mollom.com:
|
||||||
$servers = $this->xmlrpc('http://xmlrpc.mollom.com/'. MOLLOM_API_VERSION, 'mollom.getServerList', $this->authentication());
|
$servers = $this->xmlrpc(
|
||||||
|
'http://xmlrpc.mollom.com/' . MOLLOM_API_VERSION,
|
||||||
|
'mollom.getServerList',
|
||||||
|
$this->authentication()
|
||||||
|
);
|
||||||
|
|
||||||
// Store the updated list of servers in the database:
|
// Store the updated list of servers in the database:
|
||||||
//tODO variable_set('mollom_servers', $servers);
|
// @todo variable_set('mollom_servers', $servers);
|
||||||
}
|
} elseif ($errno === MOLLOM_ERROR) {
|
||||||
else if ($errno == MOLLOM_ERROR) {
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
} elseif ($errno === MOLLOM_REDIRECT) {
|
||||||
else if ($errno == MOLLOM_REDIRECT) {
|
|
||||||
// Do nothing, we select the next client automatically.
|
// Do nothing, we select the next client automatically.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset the XMLRPC error:
|
// Reset the XMLRPC error:
|
||||||
$this->xmlrpc_error(0); // FIXME: this is crazy.
|
$this->xmlrpc_error(0); // FIXME: this is crazy.
|
||||||
}
|
} else {
|
||||||
else {
|
common_debug('Result = ' . print_r($result, true));
|
||||||
common_debug("Result = " . print_r($result, TRUE));
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If none of the servers worked, activate the fallback mechanism:
|
// If none of the servers worked, activate the fallback mechanism:
|
||||||
common_debug("none of the servers worked");
|
common_debug('none of the servers worked');
|
||||||
// _mollom_fallback();
|
// _mollom_fallback();
|
||||||
|
|
||||||
// If everything failed, we reset the server list to force Mollom to request a new list:
|
// If everything failed, we reset the server list to force Mollom to request a new list:
|
||||||
@ -202,20 +218,12 @@ class MollomPlugin extends Plugin
|
|||||||
* Make sure your server's time is synchronized with the world clocks,
|
* Make sure your server's time is synchronized with the world clocks,
|
||||||
* and that you don't share your private key with anyone else.
|
* and that you don't share your private key with anyone else.
|
||||||
*/
|
*/
|
||||||
private function authentication() {
|
private function authentication()
|
||||||
|
{
|
||||||
$public_key = $this->public_key;
|
$public_key = $this->public_key;
|
||||||
$private_key = $this->private_key;
|
$private_key = $this->private_key;
|
||||||
|
|
||||||
// Generate a timestamp according to the dateTime format (http://www.w3.org/TR/xmlschema-2/#dateTime):
|
$hash = hash_hmac('sha1', $private_key, $private_key, true);
|
||||||
$time = gmdate("Y-m-d\TH:i:s.\\0\\0\\0O", time());
|
|
||||||
|
|
||||||
// Calculate a HMAC-SHA1 according to RFC2104 (http://www.ietf.org/rfc/rfc2104.txt):
|
|
||||||
$hash = base64_encode(
|
|
||||||
pack("H*", sha1((str_pad($private_key, 64, chr(0x00)) ^ (str_repeat(chr(0x5c), 64))) .
|
|
||||||
pack("H*", sha1((str_pad($private_key, 64, chr(0x00)) ^ (str_repeat(chr(0x36), 64))) .
|
|
||||||
$time))))
|
|
||||||
);
|
|
||||||
|
|
||||||
// Store everything in an array. Elsewhere in the code, we'll add the
|
// Store everything in an array. Elsewhere in the code, we'll add the
|
||||||
// acutal data before we pass it onto the XML-RPC library:
|
// acutal data before we pass it onto the XML-RPC library:
|
||||||
@ -226,10 +234,11 @@ class MollomPlugin extends Plugin
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
function xmlrpc($url) {
|
public function xmlrpc($url)
|
||||||
|
{
|
||||||
//require_once './includes/xmlrpc.inc';
|
//require_once './includes/xmlrpc.inc';
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
return call_user_func_array(array('MollomPlugin', '_xmlrpc'), $args);
|
return call_user_func_array(['MollomPlugin', '_xmlrpc'], $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -242,21 +251,22 @@ class MollomPlugin extends Plugin
|
|||||||
* @return
|
* @return
|
||||||
* Object.
|
* Object.
|
||||||
*/
|
*/
|
||||||
function xmlrpc_value($data, $type = FALSE) {
|
public function xmlrpc_value($data, $type = false)
|
||||||
|
{
|
||||||
$xmlrpc_value = new stdClass();
|
$xmlrpc_value = new stdClass();
|
||||||
$xmlrpc_value->data = $data;
|
$xmlrpc_value->data = $data;
|
||||||
if (!$type) {
|
if (!$type) {
|
||||||
$type = $this->xmlrpc_value_calculate_type($xmlrpc_value);
|
$type = $this->xmlrpc_value_calculate_type($xmlrpc_value);
|
||||||
}
|
}
|
||||||
$xmlrpc_value->type = $type;
|
$xmlrpc_value->type = $type;
|
||||||
if ($type == 'struct') {
|
if ($type === 'struct') {
|
||||||
// Turn all the values in the array into new xmlrpc_values
|
// Turn all the values in the array into new xmlrpc_values
|
||||||
foreach ($xmlrpc_value->data as $key => $value) {
|
foreach ($xmlrpc_value->data as $key => $value) {
|
||||||
$xmlrpc_value->data[$key] = $this->xmlrpc_value($value);
|
$xmlrpc_value->data[$key] = $this->xmlrpc_value($value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($type == 'array') {
|
if ($type === 'array') {
|
||||||
for ($i = 0, $j = count($xmlrpc_value->data); $i < $j; $i++) {
|
for ($i = 0, $j = count($xmlrpc_value->data); $i < $j; ++$i) {
|
||||||
$xmlrpc_value->data[$i] = $this->xmlrpc_value($xmlrpc_value->data[$i]);
|
$xmlrpc_value->data[$i] = $this->xmlrpc_value($xmlrpc_value->data[$i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -273,26 +283,24 @@ class MollomPlugin extends Plugin
|
|||||||
* @see
|
* @see
|
||||||
* http://www.xmlrpc.com/spec#scalars
|
* http://www.xmlrpc.com/spec#scalars
|
||||||
*/
|
*/
|
||||||
function xmlrpc_value_calculate_type(&$xmlrpc_value) {
|
public function xmlrpc_value_calculate_type(&$xmlrpc_value)
|
||||||
|
{
|
||||||
// http://www.php.net/gettype: Never use gettype() to test for a certain type [...] Instead, use the is_* functions.
|
// http://www.php.net/gettype: Never use gettype() to test for a certain type [...] Instead, use the is_* functions.
|
||||||
if (is_bool($xmlrpc_value->data)) {
|
if (is_bool($xmlrpc_value->data)) {
|
||||||
return 'boolean';
|
return 'boolean';
|
||||||
}
|
} elseif (is_double($xmlrpc_value->data)) {
|
||||||
if (is_double($xmlrpc_value->data)) {
|
|
||||||
return 'double';
|
return 'double';
|
||||||
}
|
} elseif (is_int($xmlrpc_value->data)) {
|
||||||
if (is_int($xmlrpc_value->data)) {
|
|
||||||
return 'int';
|
return 'int';
|
||||||
}
|
} elseif (is_array($xmlrpc_value->data)) {
|
||||||
if (is_array($xmlrpc_value->data)) {
|
|
||||||
// empty or integer-indexed arrays are 'array', string-indexed arrays 'struct'
|
// empty or integer-indexed arrays are 'array', string-indexed arrays 'struct'
|
||||||
return empty($xmlrpc_value->data) || range(0, count($xmlrpc_value->data) - 1) === array_keys($xmlrpc_value->data) ? 'array' : 'struct';
|
return empty($xmlrpc_value->data)
|
||||||
|
|| (range(0, count($xmlrpc_value->data) - 1) === array_keys($xmlrpc_value->data) ? 'array' : 'struct');
|
||||||
}
|
}
|
||||||
if (is_object($xmlrpc_value->data)) {
|
if (is_object($xmlrpc_value->data)) {
|
||||||
if ($xmlrpc_value->data->is_date) {
|
if ($xmlrpc_value->data->is_date) {
|
||||||
return 'date';
|
return 'date';
|
||||||
}
|
} elseif ($xmlrpc_value->data->is_base64) {
|
||||||
if ($xmlrpc_value->data->is_base64) {
|
|
||||||
return 'base64';
|
return 'base64';
|
||||||
}
|
}
|
||||||
$xmlrpc_value->data = get_object_vars($xmlrpc_value->data);
|
$xmlrpc_value->data = get_object_vars($xmlrpc_value->data);
|
||||||
@ -309,7 +317,8 @@ class MollomPlugin extends Plugin
|
|||||||
* @return
|
* @return
|
||||||
* XML representation of value.
|
* XML representation of value.
|
||||||
*/
|
*/
|
||||||
function xmlrpc_value_get_xml($xmlrpc_value) {
|
public function xmlrpc_value_get_xml($xmlrpc_value)
|
||||||
|
{
|
||||||
switch ($xmlrpc_value->type) {
|
switch ($xmlrpc_value->type) {
|
||||||
case 'boolean':
|
case 'boolean':
|
||||||
return '<boolean>'. (($xmlrpc_value->data) ? '1' : '0') .'</boolean>';
|
return '<boolean>'. (($xmlrpc_value->data) ? '1' : '0') .'</boolean>';
|
||||||
@ -326,7 +335,7 @@ class MollomPlugin extends Plugin
|
|||||||
return '<string>'. htmlspecialchars($xmlrpc_value->data) .'</string>';
|
return '<string>'. htmlspecialchars($xmlrpc_value->data) .'</string>';
|
||||||
break;
|
break;
|
||||||
case 'array':
|
case 'array':
|
||||||
$return = '<array><data>'."\n";
|
$return = "<array><data>\n";
|
||||||
foreach ($xmlrpc_value->data as $item) {
|
foreach ($xmlrpc_value->data as $item) {
|
||||||
$return .= ' <value>'. $this->xmlrpc_value_get_xml($item) ."</value>\n";
|
$return .= ' <value>'. $this->xmlrpc_value_get_xml($item) ."</value>\n";
|
||||||
}
|
}
|
||||||
@ -334,9 +343,9 @@ class MollomPlugin extends Plugin
|
|||||||
return $return;
|
return $return;
|
||||||
break;
|
break;
|
||||||
case 'struct':
|
case 'struct':
|
||||||
$return = '<struct>'."\n";
|
$return = "<struct>\n";
|
||||||
foreach ($xmlrpc_value->data as $name => $value) {
|
foreach ($xmlrpc_value->data as $name => $value) {
|
||||||
$return .= " <member><name>". htmlentities($name) ."</name><value>";
|
$return .= ' <member><name>' . htmlentities($name) . '</name><value>';
|
||||||
$return .= $this->xmlrpc_value_get_xml($value) . "</value></member>\n";
|
$return .= $this->xmlrpc_value_get_xml($value) . "</value></member>\n";
|
||||||
}
|
}
|
||||||
$return .= '</struct>';
|
$return .= '</struct>';
|
||||||
@ -349,7 +358,7 @@ class MollomPlugin extends Plugin
|
|||||||
return $this->xmlrpc_base64_get_xml($xmlrpc_value->data);
|
return $this->xmlrpc_base64_get_xml($xmlrpc_value->data);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -373,7 +382,13 @@ class MollomPlugin extends Plugin
|
|||||||
* An object containing the HTTP request headers, response code, headers,
|
* An object containing the HTTP request headers, response code, headers,
|
||||||
* data and redirect status.
|
* data and redirect status.
|
||||||
*/
|
*/
|
||||||
function http_request($url, $headers = array(), $method = 'GET', $data = NULL, $retry = 3) {
|
public function http_request(
|
||||||
|
$url,
|
||||||
|
$headers = [],
|
||||||
|
$method = 'GET',
|
||||||
|
$data = null,
|
||||||
|
$retry = 3
|
||||||
|
) {
|
||||||
global $db_prefix;
|
global $db_prefix;
|
||||||
|
|
||||||
$result = new stdClass();
|
$result = new stdClass();
|
||||||
@ -381,12 +396,12 @@ class MollomPlugin extends Plugin
|
|||||||
// Parse the URL and make sure we can handle the schema.
|
// Parse the URL and make sure we can handle the schema.
|
||||||
$uri = parse_url($url);
|
$uri = parse_url($url);
|
||||||
|
|
||||||
if ($uri == FALSE) {
|
if ($uri === false) {
|
||||||
$result->error = 'unable to parse URL';
|
$result->error = 'unable to parse URL';
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($uri['scheme'])) {
|
if (!array_key_exists('scheme', $uri)) {
|
||||||
$result->error = 'missing schema';
|
$result->error = 'missing schema';
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
@ -409,7 +424,7 @@ class MollomPlugin extends Plugin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Make sure the socket opened properly.
|
// Make sure the socket opened properly.
|
||||||
if (!$fp) {
|
if ($fp === false) {
|
||||||
// When a network error occurs, we use a negative number so it does not
|
// When a network error occurs, we use a negative number so it does not
|
||||||
// clash with the HTTP status codes.
|
// clash with the HTTP status codes.
|
||||||
$result->code = -$errno;
|
$result->code = -$errno;
|
||||||
@ -419,30 +434,32 @@ class MollomPlugin extends Plugin
|
|||||||
// server's ability to make outgoing HTTP requests the next time that
|
// server's ability to make outgoing HTTP requests the next time that
|
||||||
// requirements checking is performed.
|
// requirements checking is performed.
|
||||||
// @see system_requirements()
|
// @see system_requirements()
|
||||||
//TODO variable_set('drupal_http_request_fails', TRUE);
|
// @todo variable_set('drupal_http_request_fails', TRUE);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct the path to act on.
|
// Construct the path to act on.
|
||||||
$path = isset($uri['path']) ? $uri['path'] : '/';
|
$path = $uri['path'] ?? '/';
|
||||||
if (isset($uri['query'])) {
|
if (array_key_exists('query', $uri)) {
|
||||||
$path .= '?' . $uri['query'];
|
$path .= '?' . $uri['query'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create HTTP request.
|
// Create HTTP request.
|
||||||
$defaults = array(
|
$defaults = [
|
||||||
// RFC 2616: "non-standard ports MUST, default ports MAY be included".
|
// RFC 2616: "non-standard ports MUST, default ports MAY be included".
|
||||||
// We don't add the port to prevent from breaking rewrite rules checking the
|
// We don't add the port to prevent from breaking rewrite rules checking the
|
||||||
// host that do not take into account the port number.
|
// host that do not take into account the port number.
|
||||||
'Host' => "Host: $host",
|
'Host' => "Host: {$host}",
|
||||||
'User-Agent' => 'User-Agent: Drupal (+http://drupal.org/)',
|
'User-Agent' => 'User-Agent: Drupal (+http://drupal.org/)',
|
||||||
'Content-Length' => 'Content-Length: '. strlen($data)
|
'Content-Length' => 'Content-Length: ' . strlen($data),
|
||||||
);
|
];
|
||||||
|
|
||||||
// If the server url has a user then attempt to use basic authentication
|
// If the server url has a user then attempt to use basic authentication
|
||||||
if (isset($uri['user'])) {
|
if (array_key_exists('user', $uri)) {
|
||||||
$defaults['Authorization'] = 'Authorization: Basic '. base64_encode($uri['user'] . (!empty($uri['pass']) ? ":". $uri['pass'] : ''));
|
$defaults['Authorization'] = 'Authorization: Basic '
|
||||||
|
. base64_encode($uri['user']
|
||||||
|
. (!empty($uri['pass']) ? ':' . $uri['pass'] : ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the database prefix is being used by SimpleTest to run the tests in a copied
|
// If the database prefix is being used by SimpleTest to run the tests in a copied
|
||||||
@ -451,7 +468,10 @@ class MollomPlugin extends Plugin
|
|||||||
// user-agent is used to ensure that multiple testing sessions running at the
|
// user-agent is used to ensure that multiple testing sessions running at the
|
||||||
// same time won't interfere with each other as they would if the database
|
// same time won't interfere with each other as they would if the database
|
||||||
// prefix were stored statically in a file or database variable.
|
// prefix were stored statically in a file or database variable.
|
||||||
if (is_string($db_prefix) && preg_match("/^simpletest\d+$/", $db_prefix, $matches)) {
|
if (
|
||||||
|
is_string($db_prefix)
|
||||||
|
&& preg_match('/^simpletest\d+$/', $db_prefix, $matches)
|
||||||
|
) {
|
||||||
$defaults['User-Agent'] = 'User-Agent: ' . $matches[0];
|
$defaults['User-Agent'] = 'User-Agent: ' . $matches[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -470,41 +490,43 @@ class MollomPlugin extends Plugin
|
|||||||
|
|
||||||
// Fetch response.
|
// Fetch response.
|
||||||
$response = '';
|
$response = '';
|
||||||
while (!feof($fp) && $chunk = fread($fp, 1024)) {
|
while (!feof($fp) && ($chunk = fread($fp, 1024)) !== false) {
|
||||||
$response .= $chunk;
|
$response .= $chunk;
|
||||||
}
|
}
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
|
|
||||||
// Parse response.
|
// Parse response.
|
||||||
list($split, $result->data) = explode("\r\n\r\n", $response, 2);
|
[$split, $result->data] = explode("\r\n\r\n", $response, 2);
|
||||||
$split = preg_split("/\r\n|\n|\r/", $split);
|
$split = preg_split("/\r\n|\n|\r/", $split);
|
||||||
|
|
||||||
list($protocol, $code, $text) = explode(' ', trim(array_shift($split)), 3);
|
[$protocol, $code, $text] = explode(' ', trim(array_shift($split)), 3);
|
||||||
$result->headers = array();
|
$result->headers = [];
|
||||||
|
|
||||||
// Parse headers.
|
// Parse headers.
|
||||||
while ($line = trim(array_shift($split))) {
|
while (($line = trim(array_shift($split))) !== '') {
|
||||||
list($header, $value) = explode(':', $line, 2);
|
[$header, $value] = explode(':', $line, 2);
|
||||||
if (isset($result->headers[$header]) && $header == 'Set-Cookie') {
|
if (
|
||||||
|
array_key_exists($header, $result->headers)
|
||||||
|
&& $header === 'Set-Cookie'
|
||||||
|
) {
|
||||||
// RFC 2109: the Set-Cookie response header comprises the token Set-
|
// RFC 2109: the Set-Cookie response header comprises the token Set-
|
||||||
// Cookie:, followed by a comma-separated list of one or more cookies.
|
// Cookie:, followed by a comma-separated list of one or more cookies.
|
||||||
$result->headers[$header] .= ',' . trim($value);
|
$result->headers[$header] .= ',' . trim($value);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$result->headers[$header] = trim($value);
|
$result->headers[$header] = trim($value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$responses = array(
|
$responses = [
|
||||||
100 => 'Continue', 101 => 'Switching Protocols',
|
100 => 'Continue', 101 => 'Switching Protocols',
|
||||||
200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content',
|
200 => 'OK', 201 => 'Created', 202 => 'Accepted', 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content',
|
||||||
300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 307 => 'Temporary Redirect',
|
300 => 'Multiple Choices', 301 => 'Moved Permanently', 302 => 'Found', 303 => 'See Other', 304 => 'Not Modified', 305 => 'Use Proxy', 307 => 'Temporary Redirect',
|
||||||
400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Time-out', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Large', 415 => 'Unsupported Media Type', 416 => 'Requested range not satisfiable', 417 => 'Expectation Failed',
|
400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 406 => 'Not Acceptable', 407 => 'Proxy Authentication Required', 408 => 'Request Time-out', 409 => 'Conflict', 410 => 'Gone', 411 => 'Length Required', 412 => 'Precondition Failed', 413 => 'Request Entity Too Large', 414 => 'Request-URI Too Large', 415 => 'Unsupported Media Type', 416 => 'Requested range not satisfiable', 417 => 'Expectation Failed',
|
||||||
500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Time-out', 505 => 'HTTP Version not supported'
|
500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Time-out', 505 => 'HTTP Version not supported',
|
||||||
);
|
];
|
||||||
// RFC 2616 states that all unknown HTTP codes must be treated the same as the
|
// RFC 2616 states that all unknown HTTP codes must be treated the same as the
|
||||||
// base code in their class.
|
// base code in their class.
|
||||||
if (!isset($responses[$code])) {
|
if (!array_key_exists($code, $responses)) {
|
||||||
$code = floor($code / 100) * 100;
|
$code = floor($code / 100) * 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -522,7 +544,6 @@ class MollomPlugin extends Plugin
|
|||||||
$result->redirect_code = $result->code;
|
$result->redirect_code = $result->code;
|
||||||
}
|
}
|
||||||
$result->redirect_url = $location;
|
$result->redirect_url = $location;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$result->error = $text;
|
$result->error = $text;
|
||||||
@ -540,11 +561,15 @@ class MollomPlugin extends Plugin
|
|||||||
* @return
|
* @return
|
||||||
* Object
|
* Object
|
||||||
*/
|
*/
|
||||||
function xmlrpc_message($message) {
|
public function xmlrpc_message($message)
|
||||||
|
{
|
||||||
$xmlrpc_message = new stdClass();
|
$xmlrpc_message = new stdClass();
|
||||||
$xmlrpc_message->array_structs = array(); // The stack used to keep track of the current array/struct
|
// The stack used to keep track of the current array/struct
|
||||||
$xmlrpc_message->array_structs_types = array(); // The stack used to keep track of if things are structs or array
|
$xmlrpc_message->array_structs = [];
|
||||||
$xmlrpc_message->current_struct_name = array(); // A stack as well
|
// The stack used to keep track of if things are structs or array
|
||||||
|
$xmlrpc_message->array_structs_types = [];
|
||||||
|
// A stack as well
|
||||||
|
$xmlrpc_message->current_struct_name = [];
|
||||||
$xmlrpc_message->message = $message;
|
$xmlrpc_message->message = $message;
|
||||||
return $xmlrpc_message;
|
return $xmlrpc_message;
|
||||||
}
|
}
|
||||||
@ -558,30 +583,46 @@ class MollomPlugin extends Plugin
|
|||||||
* @return
|
* @return
|
||||||
* TRUE if parsing succeeded; FALSE otherwise
|
* TRUE if parsing succeeded; FALSE otherwise
|
||||||
*/
|
*/
|
||||||
function xmlrpc_message_parse(&$xmlrpc_message) {
|
public function xmlrpc_message_parse(&$xmlrpc_message)
|
||||||
|
{
|
||||||
// First remove the XML declaration
|
// First remove the XML declaration
|
||||||
$xmlrpc_message->message = preg_replace('/<\?xml(.*)?\?'.'>/', '', $xmlrpc_message->message);
|
$xmlrpc_message->message = preg_replace(
|
||||||
if (trim($xmlrpc_message->message) == '') {
|
'/<\?xml(.*)?\?'.'>/',
|
||||||
return FALSE;
|
'',
|
||||||
|
$xmlrpc_message->message
|
||||||
|
);
|
||||||
|
if (trim($xmlrpc_message->message) === '') {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
$xmlrpc_message->_parser = xml_parser_create();
|
$xmlrpc_message->_parser = xml_parser_create();
|
||||||
// Set XML parser to take the case of tags into account.
|
// Set XML parser to take the case of tags into account.
|
||||||
xml_parser_set_option($xmlrpc_message->_parser, XML_OPTION_CASE_FOLDING, FALSE);
|
xml_parser_set_option(
|
||||||
|
$xmlrpc_message->_parser,
|
||||||
|
XML_OPTION_CASE_FOLDING,
|
||||||
|
false
|
||||||
|
);
|
||||||
// Set XML parser callback functions
|
// Set XML parser callback functions
|
||||||
xml_set_element_handler($xmlrpc_message->_parser, array('MollomPlugin', 'xmlrpc_message_tag_open'), array('MollomPlugin', 'xmlrpc_message_tag_close'));
|
xml_set_element_handler(
|
||||||
xml_set_character_data_handler($xmlrpc_message->_parser, array('MollomPlugin', 'xmlrpc_message_cdata'));
|
$xmlrpc_message->_parser,
|
||||||
|
['MollomPlugin', 'xmlrpc_message_tag_open'],
|
||||||
|
['MollomPlugin', 'xmlrpc_message_tag_close']
|
||||||
|
);
|
||||||
|
xml_set_character_data_handler(
|
||||||
|
$xmlrpc_message->_parser,
|
||||||
|
['MollomPlugin', 'xmlrpc_message_cdata']
|
||||||
|
);
|
||||||
$this->xmlrpc_message_set($xmlrpc_message);
|
$this->xmlrpc_message_set($xmlrpc_message);
|
||||||
if (!xml_parse($xmlrpc_message->_parser, $xmlrpc_message->message)) {
|
if (!xml_parse($xmlrpc_message->_parser, $xmlrpc_message->message)) {
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
xml_parser_free($xmlrpc_message->_parser);
|
xml_parser_free($xmlrpc_message->_parser);
|
||||||
// Grab the error messages, if any
|
// Grab the error messages, if any
|
||||||
$xmlrpc_message = $this->xmlrpc_message_get();
|
$xmlrpc_message = $this->xmlrpc_message_get();
|
||||||
if ($xmlrpc_message->messagetype == 'fault') {
|
if ($xmlrpc_message->messagetype === 'fault') {
|
||||||
$xmlrpc_message->fault_code = $xmlrpc_message->params[0]['faultCode'];
|
$xmlrpc_message->fault_code = $xmlrpc_message->params[0]['faultCode'];
|
||||||
$xmlrpc_message->fault_string = $xmlrpc_message->params[0]['faultString'];
|
$xmlrpc_message->fault_string = $xmlrpc_message->params[0]['faultString'];
|
||||||
}
|
}
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -592,7 +633,8 @@ class MollomPlugin extends Plugin
|
|||||||
* @return
|
* @return
|
||||||
* The most recently stored $xmlrpc_message
|
* The most recently stored $xmlrpc_message
|
||||||
*/
|
*/
|
||||||
function xmlrpc_message_set($value = NULL) {
|
public function xmlrpc_message_set($value = null)
|
||||||
|
{
|
||||||
static $xmlrpc_message;
|
static $xmlrpc_message;
|
||||||
if ($value) {
|
if ($value) {
|
||||||
$xmlrpc_message = $value;
|
$xmlrpc_message = $value;
|
||||||
@ -600,11 +642,13 @@ class MollomPlugin extends Plugin
|
|||||||
return $xmlrpc_message;
|
return $xmlrpc_message;
|
||||||
}
|
}
|
||||||
|
|
||||||
function xmlrpc_message_get() {
|
public function xmlrpc_message_get()
|
||||||
|
{
|
||||||
return $this->xmlrpc_message_set();
|
return $this->xmlrpc_message_set();
|
||||||
}
|
}
|
||||||
|
|
||||||
function xmlrpc_message_tag_open($parser, $tag, $attr) {
|
public function xmlrpc_message_tag_open($parser, $tag, $attr)
|
||||||
|
{
|
||||||
$xmlrpc_message = $this->xmlrpc_message_get();
|
$xmlrpc_message = $this->xmlrpc_message_get();
|
||||||
$xmlrpc_message->current_tag_contents = '';
|
$xmlrpc_message->current_tag_contents = '';
|
||||||
$xmlrpc_message->last_open = $tag;
|
$xmlrpc_message->last_open = $tag;
|
||||||
@ -627,57 +671,59 @@ class MollomPlugin extends Plugin
|
|||||||
$this->xmlrpc_message_set($xmlrpc_message);
|
$this->xmlrpc_message_set($xmlrpc_message);
|
||||||
}
|
}
|
||||||
|
|
||||||
function xmlrpc_message_cdata($parser, $cdata) {
|
public function xmlrpc_message_cdata($parser, $cdata)
|
||||||
|
{
|
||||||
$xmlrpc_message = $this->xmlrpc_message_get();
|
$xmlrpc_message = $this->xmlrpc_message_get();
|
||||||
$xmlrpc_message->current_tag_contents .= $cdata;
|
$xmlrpc_message->current_tag_contents .= $cdata;
|
||||||
$this->xmlrpc_message_set($xmlrpc_message);
|
$this->xmlrpc_message_set($xmlrpc_message);
|
||||||
}
|
}
|
||||||
|
|
||||||
function xmlrpc_message_tag_close($parser, $tag) {
|
public function xmlrpc_message_tag_close($parser, $tag)
|
||||||
|
{
|
||||||
$xmlrpc_message = $this->xmlrpc_message_get();
|
$xmlrpc_message = $this->xmlrpc_message_get();
|
||||||
$value_flag = FALSE;
|
$value_flag = false;
|
||||||
switch ($tag) {
|
switch ($tag) {
|
||||||
case 'int':
|
case 'int':
|
||||||
case 'i4':
|
case 'i4':
|
||||||
$value = (int)trim($xmlrpc_message->current_tag_contents);
|
$value = (int)trim($xmlrpc_message->current_tag_contents);
|
||||||
$value_flag = TRUE;
|
$value_flag = true;
|
||||||
break;
|
break;
|
||||||
case 'double':
|
case 'double':
|
||||||
$value = (double)trim($xmlrpc_message->current_tag_contents);
|
$value = (double)trim($xmlrpc_message->current_tag_contents);
|
||||||
$value_flag = TRUE;
|
$value_flag = true;
|
||||||
break;
|
break;
|
||||||
case 'string':
|
case 'string':
|
||||||
$value = $xmlrpc_message->current_tag_contents;
|
$value = $xmlrpc_message->current_tag_contents;
|
||||||
$value_flag = TRUE;
|
$value_flag = true;
|
||||||
break;
|
break;
|
||||||
case 'dateTime.iso8601':
|
case 'dateTime.iso8601':
|
||||||
$value = xmlrpc_date(trim($xmlrpc_message->current_tag_contents));
|
$value = xmlrpc_date(trim($xmlrpc_message->current_tag_contents));
|
||||||
// $value = $iso->getTimestamp();
|
// $value = $iso->getTimestamp();
|
||||||
$value_flag = TRUE;
|
$value_flag = true;
|
||||||
break;
|
break;
|
||||||
case 'value':
|
case 'value':
|
||||||
// If no type is indicated, the type is string
|
// If no type is indicated, the type is string
|
||||||
// We take special care for empty values
|
// We take special care for empty values
|
||||||
if (trim($xmlrpc_message->current_tag_contents) != '' || (isset($xmlrpc_message->last_open) && ($xmlrpc_message->last_open == 'value'))) {
|
if (trim($xmlrpc_message->current_tag_contents) != '' || (isset($xmlrpc_message->last_open) && ($xmlrpc_message->last_open == 'value'))) {
|
||||||
$value = (string)$xmlrpc_message->current_tag_contents;
|
$value = (string)$xmlrpc_message->current_tag_contents;
|
||||||
$value_flag = TRUE;
|
$value_flag = true;
|
||||||
}
|
}
|
||||||
unset($xmlrpc_message->last_open);
|
unset($xmlrpc_message->last_open);
|
||||||
break;
|
break;
|
||||||
case 'boolean':
|
case 'boolean':
|
||||||
$value = (boolean)trim($xmlrpc_message->current_tag_contents);
|
$value = (boolean)trim($xmlrpc_message->current_tag_contents);
|
||||||
$value_flag = TRUE;
|
$value_flag = true;
|
||||||
break;
|
break;
|
||||||
case 'base64':
|
case 'base64':
|
||||||
$value = base64_decode(trim($xmlrpc_message->current_tag_contents));
|
$value = base64_decode(trim($xmlrpc_message->current_tag_contents));
|
||||||
$value_flag = TRUE;
|
$value_flag = true;
|
||||||
break;
|
break;
|
||||||
// Deal with stacks of arrays and structs
|
// Deal with stacks of arrays and structs
|
||||||
case 'data':
|
case 'data':
|
||||||
case 'struct':
|
case 'struct':
|
||||||
$value = array_pop($xmlrpc_message->array_structs);
|
$value = array_pop($xmlrpc_message->array_structs);
|
||||||
array_pop($xmlrpc_message->array_structs_types);
|
array_pop($xmlrpc_message->array_structs_types);
|
||||||
$value_flag = TRUE;
|
$value_flag = true;
|
||||||
break;
|
break;
|
||||||
case 'member':
|
case 'member':
|
||||||
array_pop($xmlrpc_message->current_struct_name);
|
array_pop($xmlrpc_message->current_struct_name);
|
||||||
@ -693,21 +739,19 @@ class MollomPlugin extends Plugin
|
|||||||
if ($value_flag) {
|
if ($value_flag) {
|
||||||
if (count($xmlrpc_message->array_structs) > 0) {
|
if (count($xmlrpc_message->array_structs) > 0) {
|
||||||
// Add value to struct or array
|
// Add value to struct or array
|
||||||
if ($xmlrpc_message->array_structs_types[count($xmlrpc_message->array_structs_types)-1] == 'struct') {
|
if ($xmlrpc_message->array_structs_types[count($xmlrpc_message->array_structs_types) - 1] === 'struct') {
|
||||||
// Add to struct
|
// Add to struct
|
||||||
$xmlrpc_message->array_structs[count($xmlrpc_message->array_structs) - 1][$xmlrpc_message->current_struct_name[count($xmlrpc_message->current_struct_name) - 1]] = $value;
|
$xmlrpc_message->array_structs[count($xmlrpc_message->array_structs) - 1][$xmlrpc_message->current_struct_name[count($xmlrpc_message->current_struct_name) - 1]] = $value;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Add to array
|
// Add to array
|
||||||
$xmlrpc_message->array_structs[count($xmlrpc_message->array_structs) - 1][] = $value;
|
$xmlrpc_message->array_structs[count($xmlrpc_message->array_structs) - 1][] = $value;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Just add as a parameter
|
// Just add as a parameter
|
||||||
$xmlrpc_message->params[] = $value;
|
$xmlrpc_message->params[] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!in_array($tag, array("data", "struct", "member"))) {
|
if (!in_array($tag, ['data', 'struct', 'member'])) {
|
||||||
$xmlrpc_message->current_tag_contents = '';
|
$xmlrpc_message->current_tag_contents = '';
|
||||||
}
|
}
|
||||||
$this->xmlrpc_message_set($xmlrpc_message);
|
$this->xmlrpc_message_set($xmlrpc_message);
|
||||||
@ -723,7 +767,8 @@ class MollomPlugin extends Plugin
|
|||||||
* @return
|
* @return
|
||||||
* Object
|
* Object
|
||||||
*/
|
*/
|
||||||
function xmlrpc_request($method, $args) {
|
public function xmlrpc_request($method, $args)
|
||||||
|
{
|
||||||
$xmlrpc_request = new stdClass();
|
$xmlrpc_request = new stdClass();
|
||||||
$xmlrpc_request->method = $method;
|
$xmlrpc_request->method = $method;
|
||||||
$xmlrpc_request->args = $args;
|
$xmlrpc_request->args = $args;
|
||||||
@ -746,21 +791,22 @@ EOD;
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function xmlrpc_error($code = NULL, $message = NULL, $reset = FALSE) {
|
public function xmlrpc_error($code = null, $message = null, $reset = false)
|
||||||
|
{
|
||||||
static $xmlrpc_error;
|
static $xmlrpc_error;
|
||||||
if (isset($code)) {
|
if (!is_null($code)) {
|
||||||
$xmlrpc_error = new stdClass();
|
$xmlrpc_error = new stdClass();
|
||||||
$xmlrpc_error->is_error = TRUE;
|
$xmlrpc_error->is_error = true;
|
||||||
$xmlrpc_error->code = $code;
|
$xmlrpc_error->code = $code;
|
||||||
$xmlrpc_error->message = $message;
|
$xmlrpc_error->message = $message;
|
||||||
}
|
} elseif ($reset) {
|
||||||
elseif ($reset) {
|
$xmlrpc_error = null;
|
||||||
$xmlrpc_error = NULL;
|
|
||||||
}
|
}
|
||||||
return $xmlrpc_error;
|
return $xmlrpc_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
function xmlrpc_error_get_xml($xmlrpc_error) {
|
public function xmlrpc_error_get_xml($xmlrpc_error)
|
||||||
|
{
|
||||||
return <<<EOD
|
return <<<EOD
|
||||||
<methodResponse>
|
<methodResponse>
|
||||||
<fault>
|
<fault>
|
||||||
@ -782,9 +828,10 @@ EOD;
|
|||||||
EOD;
|
EOD;
|
||||||
}
|
}
|
||||||
|
|
||||||
function xmlrpc_date($time) {
|
public function xmlrpc_date($time)
|
||||||
|
{
|
||||||
$xmlrpc_date = new stdClass();
|
$xmlrpc_date = new stdClass();
|
||||||
$xmlrpc_date->is_date = TRUE;
|
$xmlrpc_date->is_date = true;
|
||||||
// $time can be a PHP timestamp or an ISO one
|
// $time can be a PHP timestamp or an ISO one
|
||||||
if (is_numeric($time)) {
|
if (is_numeric($time)) {
|
||||||
$xmlrpc_date->year = gmdate('Y', $time);
|
$xmlrpc_date->year = gmdate('Y', $time);
|
||||||
@ -794,8 +841,7 @@ EOD;
|
|||||||
$xmlrpc_date->minute = gmdate('i', $time);
|
$xmlrpc_date->minute = gmdate('i', $time);
|
||||||
$xmlrpc_date->second = gmdate('s', $time);
|
$xmlrpc_date->second = gmdate('s', $time);
|
||||||
$xmlrpc_date->iso8601 = gmdate('Ymd\TH:i:s', $time);
|
$xmlrpc_date->iso8601 = gmdate('Ymd\TH:i:s', $time);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$xmlrpc_date->iso8601 = $time;
|
$xmlrpc_date->iso8601 = $time;
|
||||||
$time = str_replace(array('-', ':'), '', $time);
|
$time = str_replace(array('-', ':'), '', $time);
|
||||||
$xmlrpc_date->year = substr($time, 0, 4);
|
$xmlrpc_date->year = substr($time, 0, 4);
|
||||||
@ -808,18 +854,28 @@ EOD;
|
|||||||
return $xmlrpc_date;
|
return $xmlrpc_date;
|
||||||
}
|
}
|
||||||
|
|
||||||
function xmlrpc_date_get_xml($xmlrpc_date) {
|
public function xmlrpc_date_get_xml($xmlrpc_date)
|
||||||
return '<dateTime.iso8601>'. $xmlrpc_date->year . $xmlrpc_date->month . $xmlrpc_date->day .'T'. $xmlrpc_date->hour .':'. $xmlrpc_date->minute .':'. $xmlrpc_date->second .'</dateTime.iso8601>';
|
{
|
||||||
|
return '<dateTime.iso8601>'
|
||||||
|
. $xmlrpc_date->year
|
||||||
|
. $xmlrpc_date->month
|
||||||
|
. $xmlrpc_date->day
|
||||||
|
. 'T' . $xmlrpc_date->hour
|
||||||
|
. ':'. $xmlrpc_date->minute
|
||||||
|
. ':'. $xmlrpc_date->second
|
||||||
|
. '</dateTime.iso8601>';
|
||||||
}
|
}
|
||||||
|
|
||||||
function xmlrpc_base64($data) {
|
public function xmlrpc_base64($data)
|
||||||
|
{
|
||||||
$xmlrpc_base64 = new stdClass();
|
$xmlrpc_base64 = new stdClass();
|
||||||
$xmlrpc_base64->is_base64 = TRUE;
|
$xmlrpc_base64->is_base64 = true;
|
||||||
$xmlrpc_base64->data = $data;
|
$xmlrpc_base64->data = $data;
|
||||||
return $xmlrpc_base64;
|
return $xmlrpc_base64;
|
||||||
}
|
}
|
||||||
|
|
||||||
function xmlrpc_base64_get_xml($xmlrpc_base64) {
|
public function xmlrpc_base64_get_xml($xmlrpc_base64)
|
||||||
|
{
|
||||||
return '<base64>'. base64_encode($xmlrpc_base64->data) .'</base64>';
|
return '<base64>'. base64_encode($xmlrpc_base64->data) .'</base64>';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -830,38 +886,43 @@ EOD;
|
|||||||
* @return
|
* @return
|
||||||
* A $xmlrpc_message object if the call succeeded; FALSE if the call failed
|
* A $xmlrpc_message object if the call succeeded; FALSE if the call failed
|
||||||
*/
|
*/
|
||||||
function _xmlrpc() {
|
public function _xmlrpc()
|
||||||
|
{
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
$url = array_shift($args);
|
$url = array_shift($args);
|
||||||
$this->xmlrpc_clear_error();
|
$this->xmlrpc_clear_error();
|
||||||
if (is_array($args[0])) {
|
if (is_array($args[0])) {
|
||||||
$method = 'system.multicall';
|
$method = 'system.multicall';
|
||||||
$multicall_args = array();
|
$multicall_args = [];
|
||||||
foreach ($args[0] as $call) {
|
foreach ($args[0] as $call) {
|
||||||
$multicall_args[] = array('methodName' => array_shift($call), 'params' => $call);
|
$multicall_args[] = [
|
||||||
|
'methodName' => array_shift($call),
|
||||||
|
'params' => $call,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
$args = array($multicall_args);
|
$args = [$multicall_args];
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$method = array_shift($args);
|
$method = array_shift($args);
|
||||||
}
|
}
|
||||||
$xmlrpc_request = $this->xmlrpc_request($method, $args);
|
$xmlrpc_request = $this->xmlrpc_request($method, $args);
|
||||||
$result = $this->http_request($url, array("Content-Type" => "text/xml"), 'POST', $xmlrpc_request->xml);
|
$result = $this->http_request($url, [
|
||||||
if ($result->code != 200) {
|
'Content-Type' => 'text/xml',
|
||||||
|
], 'POST', $xmlrpc_request->xml);
|
||||||
|
if ($result->code !== 200) {
|
||||||
$this->xmlrpc_error($result->code, $result->error);
|
$this->xmlrpc_error($result->code, $result->error);
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
$message = $this->xmlrpc_message($result->data);
|
$message = $this->xmlrpc_message($result->data);
|
||||||
// Now parse what we've got back
|
// Now parse what we've got back
|
||||||
if (!$this->xmlrpc_message_parse($message)) {
|
if (!$this->xmlrpc_message_parse($message)) {
|
||||||
// XML error
|
// XML error
|
||||||
$this->xmlrpc_error(-32700, t('Parse error. Not well formed'));
|
$this->xmlrpc_error(-32700, t('Parse error. Not well formed'));
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
// Is the message a fault?
|
// Is the message a fault?
|
||||||
if ($message->messagetype == 'fault') {
|
if ($message->messagetype === 'fault') {
|
||||||
$this->xmlrpc_error($message->fault_code, $message->fault_string);
|
$this->xmlrpc_error($message->fault_code, $message->fault_string);
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
// Message must be OK
|
// Message must be OK
|
||||||
return $message->params[0];
|
return $message->params[0];
|
||||||
@ -870,23 +931,24 @@ EOD;
|
|||||||
/**
|
/**
|
||||||
* Returns the last XML-RPC client error number
|
* Returns the last XML-RPC client error number
|
||||||
*/
|
*/
|
||||||
function xmlrpc_errno() {
|
public function xmlrpc_errno()
|
||||||
$error = $this->xmlrpc_error();
|
{
|
||||||
return ($error != NULL ? $error->code : NULL);
|
return $this->xmlrpc_error()->code ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the last XML-RPC client error message
|
* Returns the last XML-RPC client error message
|
||||||
*/
|
*/
|
||||||
function xmlrpc_error_msg() {
|
public function xmlrpc_error_msg()
|
||||||
$error = xmlrpc_error();
|
{
|
||||||
return ($error != NULL ? $error->message : NULL);
|
return xmlrpc_error()->message ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears any previous error.
|
* Clears any previous error.
|
||||||
*/
|
*/
|
||||||
function xmlrpc_clear_error() {
|
public function xmlrpc_clear_error()
|
||||||
$this->xmlrpc_error(NULL, NULL, TRUE);
|
{
|
||||||
|
$this->xmlrpc_error(null, null, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -964,7 +964,10 @@ class Ostatus_profile extends Managed_DataObject
|
|||||||
$best = false;
|
$best = false;
|
||||||
// Take the exact-size avatar, or the largest avatar, or the first avatar if all sizeless
|
// Take the exact-size avatar, or the largest avatar, or the first avatar if all sizeless
|
||||||
foreach ($object->avatarLinks as $avatar) {
|
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!
|
// Exact match!
|
||||||
$best = $avatar;
|
$best = $avatar;
|
||||||
break;
|
break;
|
||||||
|
@ -1,44 +1,38 @@
|
|||||||
<?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, the distributed open-source microblogging tool
|
|
||||||
*
|
|
||||||
* Superclass for sitemap-generating actions
|
* 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
|
* @category Sitemap
|
||||||
* @package StatusNet
|
* @package GNUsocial
|
||||||
* @author Evan Prodromou <evan@status.net>
|
* @author Evan Prodromou <evan@status.net>
|
||||||
* @copyright 2010 StatusNet, Inc.
|
* @copyright 2010 StatusNet, Inc.
|
||||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||||
* @link http://status.net/
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('STATUSNET')) {
|
defined('GNUSOCIAL') || die();
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* superclass for sitemap actions
|
* superclass for sitemap actions
|
||||||
*
|
*
|
||||||
* @category Sitemap
|
* @category Sitemap
|
||||||
* @package StatusNet
|
* @package GNUsocial
|
||||||
* @author Evan Prodromou <evan@status.net>
|
* @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
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||||
* @link http://status.net/
|
|
||||||
*/
|
*/
|
||||||
class SitemapAction extends Action
|
class SitemapAction extends Action
|
||||||
{
|
{
|
||||||
@ -49,7 +43,7 @@ class SitemapAction extends Action
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
parent::handle();
|
parent::handle();
|
||||||
|
|
||||||
@ -58,8 +52,8 @@ class SitemapAction extends Action
|
|||||||
|
|
||||||
$this->elementStart('urlset', array('xmlns' => 'http://www.sitemaps.org/schemas/sitemap/0.9'));
|
$this->elementStart('urlset', array('xmlns' => 'http://www.sitemaps.org/schemas/sitemap/0.9'));
|
||||||
|
|
||||||
while (list($url, $lm, $cf, $p) = $this->nextUrl()) {
|
while (!is_null($next = $this->nextUrl())) {
|
||||||
$this->showUrl($url, $lm, $cf, $p);
|
$this->showUrl(...$next);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->elementEnd('urlset');
|
$this->elementEnd('urlset');
|
||||||
@ -67,7 +61,7 @@ class SitemapAction extends Action
|
|||||||
$this->endXML();
|
$this->endXML();
|
||||||
}
|
}
|
||||||
|
|
||||||
function lastModified()
|
public function lastModified()
|
||||||
{
|
{
|
||||||
$y = $this->trimmed('year');
|
$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->elementStart('url');
|
||||||
$this->element('loc', null, $url);
|
$this->element('loc', null, $url);
|
||||||
if (!is_null($lastMod)) {
|
if (!is_null($lastMod)) {
|
||||||
@ -104,12 +102,12 @@ class SitemapAction extends Action
|
|||||||
$this->elementEnd('url');
|
$this->elementEnd('url');
|
||||||
}
|
}
|
||||||
|
|
||||||
function nextUrl()
|
public function nextUrl()
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isReadOnly()
|
public function isReadOnly()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1,29 +1,28 @@
|
|||||||
<?php
|
<?php
|
||||||
/*
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
||||||
* StatusNet - the distributed open-source microblogging tool
|
//
|
||||||
* Copyright (C) 2010, StatusNet, Inc.
|
// GNU social is free software: you can redistribute it and/or modify
|
||||||
*
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
* This program is free software: you can redistribute it and/or modify
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
// (at your option) any later version.
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
//
|
||||||
* (at your option) any later version.
|
// GNU social is distributed in the hope that it will be useful,
|
||||||
*
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* This program is distributed in the hope that it will be useful,
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
// GNU Affero General Public License for more details.
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
//
|
||||||
* GNU Affero General Public License for more details.
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
*
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @package WebFingerPlugin
|
* @package WebFingerPlugin
|
||||||
* @author James Walker <james@status.net>
|
* @author James Walker <james@status.net>
|
||||||
* @author Mikael Nordfeldth <mmn@hethane.se>
|
* @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
|
class OwnerxrdAction extends WebfingerAction
|
||||||
{
|
{
|
||||||
@ -49,7 +48,7 @@ class OwnerxrdAction extends WebfingerAction
|
|||||||
|
|
||||||
// Check to see if a $config['webfinger']['owner'] has been set
|
// Check to see if a $config['webfinger']['owner'] has been set
|
||||||
// and then make sure 'subject' is set to that primary identity.
|
// 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->aliases[] = $this->xrd->subject;
|
||||||
$this->xrd->subject = Discovery::normalize($owner);
|
$this->xrd->subject = Discovery::normalize($owner);
|
||||||
} else {
|
} else {
|
||||||
|
@ -67,7 +67,10 @@ call_user_func(function () {
|
|||||||
|
|
||||||
// Find composer.json
|
// Find composer.json
|
||||||
if (is_file($path . '/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') {
|
if (isset($cfg['name']) && $cfg['name'] === 'psy/psysh') {
|
||||||
// We're inside the psysh project. Let's use the local
|
// We're inside the psysh project. Let's use the local
|
||||||
// Composer autoload.
|
// Composer autoload.
|
||||||
@ -82,7 +85,10 @@ call_user_func(function () {
|
|||||||
|
|
||||||
// Or a composer.lock
|
// Or a composer.lock
|
||||||
if (is_file($path . '/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) {
|
foreach (array_merge($cfg['packages'], $cfg['packages-dev']) as $pkg) {
|
||||||
if (isset($pkg['name']) && $pkg['name'] === 'psy/psysh') {
|
if (isset($pkg['name']) && $pkg['name'] === 'psy/psysh') {
|
||||||
// We're inside a project which requires psysh. We'll
|
// We're inside a project which requires psysh. We'll
|
||||||
|
@ -1,21 +1,23 @@
|
|||||||
#!/usr/bin/env php
|
#!/usr/bin/env php
|
||||||
<?php
|
<?php
|
||||||
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
||||||
|
//
|
||||||
|
// GNU social is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// GNU social is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* StatusNet - a distributed open-source microblogging tool
|
* @copyright 2010 StatusNet, Inc.
|
||||||
* Copyright (C) 2010 StatusNet, Inc.
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||||
*
|
|
||||||
* 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/>.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
define('INSTALLDIR', dirname(__DIR__));
|
define('INSTALLDIR', dirname(__DIR__));
|
||||||
@ -71,16 +73,19 @@ function get_max_profile_id()
|
|||||||
*/
|
*/
|
||||||
function get_missing_profiles($start, $end)
|
function get_missing_profiles($start, $end)
|
||||||
{
|
{
|
||||||
$query = sprintf("SELECT id FROM profile WHERE id BETWEEN %d AND %d",
|
$query = sprintf(
|
||||||
$start, $end);
|
'SELECT id FROM profile WHERE id BETWEEN %d AND %d',
|
||||||
|
$start,
|
||||||
|
$end
|
||||||
|
);
|
||||||
|
|
||||||
$profile = new Profile();
|
$profile = new Profile();
|
||||||
$profile->query($query);
|
$profile->query($query);
|
||||||
|
|
||||||
$all = range($start, $end);
|
$all = range($start, $end);
|
||||||
$known = array();
|
$known = [];
|
||||||
while ($row = $profile->fetch()) {
|
while ($profile->fetch()) {
|
||||||
$known[] = intval($profile->id);
|
$known[] = (int) $profile->id;
|
||||||
}
|
}
|
||||||
unset($profile);
|
unset($profile);
|
||||||
|
|
||||||
@ -164,4 +169,3 @@ for ($start = $begin; $start <= $final; $start += $chunk) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
echo "done.\n";
|
echo "done.\n";
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user