Changes:
- added some documentation - fixed some documentation - changed more double-quotes to singl
This commit is contained in:
parent
ba45e59313
commit
101cd2dd10
|
@ -284,7 +284,7 @@ abstract class BaseModule implements ICanHandleRequests
|
||||||
/**
|
/**
|
||||||
* Fetch a request value and apply default values and check against minimal and maximal values
|
* Fetch a request value and apply default values and check against minimal and maximal values
|
||||||
*
|
*
|
||||||
* @param array $input Input viels
|
* @param array $input Input fields
|
||||||
* @param string $parameter Parameter
|
* @param string $parameter Parameter
|
||||||
* @param mixed $default Default
|
* @param mixed $default Default
|
||||||
* @param mixed $minimal_value Minimal value
|
* @param mixed $minimal_value Minimal value
|
||||||
|
|
|
@ -1247,16 +1247,28 @@ class BBCode
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function expandLinksCallback($match)
|
/**
|
||||||
|
* Callback: Expands links from given $match array
|
||||||
|
*
|
||||||
|
* @param arrat $match Array with link match
|
||||||
|
* @return string BBCode
|
||||||
|
*/
|
||||||
|
private static function expandLinksCallback(array $match): string
|
||||||
{
|
{
|
||||||
if (($match[3] == '') || ($match[2] == $match[3]) || stristr($match[2], $match[3])) {
|
if (($match[3] == '') || ($match[2] == $match[3]) || stristr($match[2], $match[3])) {
|
||||||
return ($match[1] . "[url]" . $match[2] . "[/url]");
|
return ($match[1] . '[url]' . $match[2] . '[/url]');
|
||||||
} else {
|
} else {
|
||||||
return ($match[1] . $match[3] . " [url]" . $match[2] . "[/url]");
|
return ($match[1] . $match[3] . ' [url]' . $match[2] . '[/url]');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function cleanPictureLinksCallback($match)
|
/**
|
||||||
|
* Callback: Cleans picture links
|
||||||
|
*
|
||||||
|
* @param arrat $match Array with link match
|
||||||
|
* @return string BBCode
|
||||||
|
*/
|
||||||
|
private static function cleanPictureLinksCallback(array $match): string
|
||||||
{
|
{
|
||||||
// When the picture link is the own photo path then we can avoid fetching the link
|
// When the picture link is the own photo path then we can avoid fetching the link
|
||||||
$own_photo_url = preg_quote(Strings::normaliseLink(DI::baseUrl()->get()) . '/photos/');
|
$own_photo_url = preg_quote(Strings::normaliseLink(DI::baseUrl()->get()) . '/photos/');
|
||||||
|
@ -1325,7 +1337,13 @@ class BBCode
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function cleanPictureLinks($text)
|
/**
|
||||||
|
* Cleans picture links
|
||||||
|
*
|
||||||
|
* @param string $text HTML/BBCode string
|
||||||
|
* @return string Cleaned HTML/BBCode
|
||||||
|
*/
|
||||||
|
public static function cleanPictureLinks(string $text): string
|
||||||
{
|
{
|
||||||
DI::profiler()->startRecording('rendering');
|
DI::profiler()->startRecording('rendering');
|
||||||
$return = preg_replace_callback("&\[url=([^\[\]]*)\]\[img=(.*)\](.*)\[\/img\]\[\/url\]&Usi", 'self::cleanPictureLinksCallback', $text);
|
$return = preg_replace_callback("&\[url=([^\[\]]*)\]\[img=(.*)\](.*)\[\/img\]\[\/url\]&Usi", 'self::cleanPictureLinksCallback', $text);
|
||||||
|
@ -1334,7 +1352,13 @@ class BBCode
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function removeLinks(string $bbcode)
|
/**
|
||||||
|
* Removes links
|
||||||
|
*
|
||||||
|
* @param string $text HTML/BBCode string
|
||||||
|
* @return string Cleaned HTML/BBCode
|
||||||
|
*/
|
||||||
|
public static function removeLinks(string $bbcode): string
|
||||||
{
|
{
|
||||||
DI::profiler()->startRecording('rendering');
|
DI::profiler()->startRecording('rendering');
|
||||||
$bbcode = preg_replace("/\[img\=(.*?)\](.*?)\[\/img\]/ism", ' $1 ', $bbcode);
|
$bbcode = preg_replace("/\[img\=(.*?)\](.*?)\[\/img\]/ism", ' $1 ', $bbcode);
|
||||||
|
@ -1350,10 +1374,10 @@ class BBCode
|
||||||
/**
|
/**
|
||||||
* Replace names in mentions with nicknames
|
* Replace names in mentions with nicknames
|
||||||
*
|
*
|
||||||
* @param string $body
|
* @param string $body HTML/BBCode
|
||||||
* @return string Body with replaced mentions
|
* @return string Body with replaced mentions
|
||||||
*/
|
*/
|
||||||
public static function setMentionsToNicknames(string $body):string
|
public static function setMentionsToNicknames(string $body): string
|
||||||
{
|
{
|
||||||
DI::profiler()->startRecording('rendering');
|
DI::profiler()->startRecording('rendering');
|
||||||
$regexp = "/([@!])\[url\=([^\[\]]*)\].*?\[\/url\]/ism";
|
$regexp = "/([@!])\[url\=([^\[\]]*)\].*?\[\/url\]/ism";
|
||||||
|
@ -1366,10 +1390,10 @@ class BBCode
|
||||||
* Callback function to replace a Friendica style mention in a mention with the nickname
|
* Callback function to replace a Friendica style mention in a mention with the nickname
|
||||||
*
|
*
|
||||||
* @param array $match Matching values for the callback
|
* @param array $match Matching values for the callback
|
||||||
* @return string Replaced mention
|
* @return string Replaced mention or empty string
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
*/
|
*/
|
||||||
private static function mentionCallback($match)
|
private static function mentionCallback(array $match): string
|
||||||
{
|
{
|
||||||
if (empty($match[2])) {
|
if (empty($match[2])) {
|
||||||
return '';
|
return '';
|
||||||
|
@ -1407,7 +1431,7 @@ class BBCode
|
||||||
* @return string
|
* @return string
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
*/
|
*/
|
||||||
public static function convertForUriId(int $uriid = null, string $text = null, int $simple_html = self::INTERNAL)
|
public static function convertForUriId(int $uriid = null, string $text = null, int $simple_html = self::INTERNAL): string
|
||||||
{
|
{
|
||||||
$try_oembed = ($simple_html == self::INTERNAL);
|
$try_oembed = ($simple_html == self::INTERNAL);
|
||||||
|
|
||||||
|
@ -1437,10 +1461,10 @@ class BBCode
|
||||||
* @param int $simple_html
|
* @param int $simple_html
|
||||||
* @param bool $for_plaintext
|
* @param bool $for_plaintext
|
||||||
* @param int $uriid
|
* @param int $uriid
|
||||||
* @return string
|
* @return string Converted code or empty string
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
*/
|
*/
|
||||||
public static function convert(string $text = null, $try_oembed = true, $simple_html = self::INTERNAL, $for_plaintext = false, $uriid = 0)
|
public static function convert(string $text = null, bool $try_oembed = true, int $simple_html = self::INTERNAL, bool $for_plaintext = false, int $uriid = 0): string
|
||||||
{
|
{
|
||||||
// Accounting for null default column values
|
// Accounting for null default column values
|
||||||
if (is_null($text) || $text === '') {
|
if (is_null($text) || $text === '') {
|
||||||
|
@ -2142,7 +2166,7 @@ class BBCode
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
* @throws \ImagickException
|
||||||
*/
|
*/
|
||||||
private static function bbCodeMention2DiasporaCallback($match)
|
private static function bbCodeMention2DiasporaCallback(array $match): string
|
||||||
{
|
{
|
||||||
$contact = Contact::getByURL($match[3], false, ['addr']);
|
$contact = Contact::getByURL($match[3], false, ['addr']);
|
||||||
if (empty($contact['addr'])) {
|
if (empty($contact['addr'])) {
|
||||||
|
@ -2164,7 +2188,7 @@ class BBCode
|
||||||
* @return string
|
* @return string
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
*/
|
*/
|
||||||
public static function toMarkdown($text, $for_diaspora = true)
|
public static function toMarkdown(string $text, bool $for_diaspora = true): string
|
||||||
{
|
{
|
||||||
DI::profiler()->startRecording('rendering');
|
DI::profiler()->startRecording('rendering');
|
||||||
$original_text = $text;
|
$original_text = $text;
|
||||||
|
@ -2249,7 +2273,7 @@ class BBCode
|
||||||
*
|
*
|
||||||
* @return array List of tag and person names
|
* @return array List of tag and person names
|
||||||
*/
|
*/
|
||||||
public static function getTags($string)
|
public static function getTags(string $string): array
|
||||||
{
|
{
|
||||||
DI::profiler()->startRecording('rendering');
|
DI::profiler()->startRecording('rendering');
|
||||||
$ret = [];
|
$ret = [];
|
||||||
|
@ -2309,10 +2333,10 @@ class BBCode
|
||||||
/**
|
/**
|
||||||
* Expand tags to URLs, checks the tag is at the start of a line or preceded by a non-word character
|
* Expand tags to URLs, checks the tag is at the start of a line or preceded by a non-word character
|
||||||
*
|
*
|
||||||
* @param string $body
|
* @param string $body HTML/BBCode
|
||||||
* @return string body with expanded tags
|
* @return string body with expanded tags
|
||||||
*/
|
*/
|
||||||
public static function expandTags(string $body)
|
public static function expandTags(string $body): string
|
||||||
{
|
{
|
||||||
return preg_replace_callback("/(?<=\W|^)([!#@])([^\^ \x0D\x0A,;:?'\"]*[^\^ \x0D\x0A,;:?!'\".])/",
|
return preg_replace_callback("/(?<=\W|^)([!#@])([^\^ \x0D\x0A,;:?'\"]*[^\^ \x0D\x0A,;:?!'\".])/",
|
||||||
function ($match) {
|
function ($match) {
|
||||||
|
@ -2336,7 +2360,7 @@ class BBCode
|
||||||
/**
|
/**
|
||||||
* Perform a custom function on a text after having escaped blocks enclosed in the provided tag list.
|
* Perform a custom function on a text after having escaped blocks enclosed in the provided tag list.
|
||||||
*
|
*
|
||||||
* @param string $text
|
* @param string $text HTML/BBCode
|
||||||
* @param array $tagList A list of tag names, e.g ['noparse', 'nobb', 'pre']
|
* @param array $tagList A list of tag names, e.g ['noparse', 'nobb', 'pre']
|
||||||
* @param callable $callback
|
* @param callable $callback
|
||||||
* @return string
|
* @return string
|
||||||
|
@ -2352,14 +2376,14 @@ class BBCode
|
||||||
/**
|
/**
|
||||||
* Replaces mentions in the provided message body in BBCode links for the provided user and network if any
|
* Replaces mentions in the provided message body in BBCode links for the provided user and network if any
|
||||||
*
|
*
|
||||||
* @param $body
|
* @param string $body HTML/BBCode
|
||||||
* @param $profile_uid
|
* @param int $profile_uid Profile user id
|
||||||
* @param $network
|
* @param string $network Network name
|
||||||
* @return string
|
* @return string HTML/BBCode with inserted images
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
* @throws \ImagickException
|
||||||
*/
|
*/
|
||||||
public static function setMentions($body, $profile_uid = 0, $network = '')
|
public static function setMentions(string $body, $profile_uid = 0, $network = '')
|
||||||
{
|
{
|
||||||
DI::profiler()->startRecording('rendering');
|
DI::profiler()->startRecording('rendering');
|
||||||
$body = self::performWithEscapedTags($body, ['noparse', 'pre', 'code', 'img'], function ($body) use ($profile_uid, $network) {
|
$body = self::performWithEscapedTags($body, ['noparse', 'pre', 'code', 'img'], function ($body) use ($profile_uid, $network) {
|
||||||
|
@ -2406,7 +2430,7 @@ class BBCode
|
||||||
* @return string
|
* @return string
|
||||||
* @TODO Rewrite to handle over whole record array
|
* @TODO Rewrite to handle over whole record array
|
||||||
*/
|
*/
|
||||||
public static function getShareOpeningTag(string $author, string $profile, string $avatar, string $link, string $posted, string $guid = null)
|
public static function getShareOpeningTag(string $author, string $profile, string $avatar, string $link, string $posted, string $guid = null): string
|
||||||
{
|
{
|
||||||
DI::profiler()->startRecording('rendering');
|
DI::profiler()->startRecording('rendering');
|
||||||
$header = "[share author='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $author) .
|
$header = "[share author='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $author) .
|
||||||
|
|
|
@ -74,9 +74,9 @@ class Tag
|
||||||
* Store tag/mention elements
|
* Store tag/mention elements
|
||||||
*
|
*
|
||||||
* @param integer $uriid URI id
|
* @param integer $uriid URI id
|
||||||
* @param integer $type Type
|
* @param integer $type Tag type
|
||||||
* @param string $name Name
|
* @param string $name Tag name
|
||||||
* @param string $url URL
|
* @param string $url Contact URL (optional)
|
||||||
* @param integer $target Target (default: null)
|
* @param integer $target Target (default: null)
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -141,7 +141,7 @@ class Probe
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Probes for webfinger path via 'host-meta'
|
* Probes for webfinger path via "host-meta"
|
||||||
*
|
*
|
||||||
* We have to check if the servers in the future still will offer this.
|
* We have to check if the servers in the future still will offer this.
|
||||||
* It seems as if it was dropped from the standard.
|
* It seems as if it was dropped from the standard.
|
||||||
|
@ -1160,7 +1160,6 @@ class Probe
|
||||||
} elseif (($link['rel'] == 'diaspora-public-key') && !empty($link['href'])) {
|
} elseif (($link['rel'] == 'diaspora-public-key') && !empty($link['href'])) {
|
||||||
$data['pubkey'] = base64_decode($link['href']);
|
$data['pubkey'] = base64_decode($link['href']);
|
||||||
|
|
||||||
//if (strstr($data['pubkey'], 'RSA ') || ($link['type'] == 'RSA'))
|
|
||||||
if (strstr($data['pubkey'], 'RSA ')) {
|
if (strstr($data['pubkey'], 'RSA ')) {
|
||||||
$data['pubkey'] = Crypto::rsaToPem($data['pubkey']);
|
$data['pubkey'] = Crypto::rsaToPem($data['pubkey']);
|
||||||
}
|
}
|
||||||
|
@ -1323,7 +1322,7 @@ class Probe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Older Friendica versions had used the 'uid' field differently than newer versions
|
// Older Friendica versions had used the "uid" field differently than newer versions
|
||||||
if (!empty($data['nick']) && !empty($data['guid']) && ($data['nick'] == $data['guid'])) {
|
if (!empty($data['nick']) && !empty($data['guid']) && ($data['nick'] == $data['guid'])) {
|
||||||
unset($data['guid']);
|
unset($data['guid']);
|
||||||
}
|
}
|
||||||
|
@ -1367,7 +1366,6 @@ class Probe
|
||||||
} elseif (($link['rel'] == 'diaspora-public-key') && !empty($link['href'])) {
|
} elseif (($link['rel'] == 'diaspora-public-key') && !empty($link['href'])) {
|
||||||
$data['pubkey'] = base64_decode($link['href']);
|
$data['pubkey'] = base64_decode($link['href']);
|
||||||
|
|
||||||
//if (strstr($data['pubkey'], 'RSA ') || ($link['type'] == 'RSA'))
|
|
||||||
if (strstr($data['pubkey'], 'RSA ')) {
|
if (strstr($data['pubkey'], 'RSA ')) {
|
||||||
$data['pubkey'] = Crypto::rsaToPem($data['pubkey']);
|
$data['pubkey'] = Crypto::rsaToPem($data['pubkey']);
|
||||||
}
|
}
|
||||||
|
@ -1417,7 +1415,7 @@ class Probe
|
||||||
$data['addr'] = strtolower($data['addr']);
|
$data['addr'] = strtolower($data['addr']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We have to overwrite the detected value for 'notify' since Hubzilla doesn't send it
|
// We have to overwrite the detected value for "notify" since Hubzilla doesn't send it
|
||||||
$data['notify'] = $data['baseurl'] . '/receive/users/' . $data['guid'];
|
$data['notify'] = $data['baseurl'] . '/receive/users/' . $data['guid'];
|
||||||
$data['batch'] = $data['baseurl'] . '/receive/public';
|
$data['batch'] = $data['baseurl'] . '/receive/public';
|
||||||
} else {
|
} else {
|
||||||
|
@ -1977,7 +1975,7 @@ class Probe
|
||||||
* Fetch the last activity date from the "noscrape" endpoint
|
* Fetch the last activity date from the "noscrape" endpoint
|
||||||
*
|
*
|
||||||
* @param array $data Probing result
|
* @param array $data Probing result
|
||||||
* @return string last activity or bool 'true' if update was successful or the server was unreachable
|
* @return string last activity or true if update was successful or the server was unreachable
|
||||||
*/
|
*/
|
||||||
private static function updateFromNoScrape(array $data)
|
private static function updateFromNoScrape(array $data)
|
||||||
{
|
{
|
||||||
|
|
|
@ -198,8 +198,6 @@ class DFRN
|
||||||
$root->setAttribute('xmlns:ostatus', ActivityNamespace::OSTATUS);
|
$root->setAttribute('xmlns:ostatus', ActivityNamespace::OSTATUS);
|
||||||
$root->setAttribute('xmlns:statusnet', ActivityNamespace::STATUSNET);
|
$root->setAttribute('xmlns:statusnet', ActivityNamespace::STATUSNET);
|
||||||
|
|
||||||
//$root = self::addHeader($doc, $owner, 'dfrn:owner', '', false);
|
|
||||||
|
|
||||||
foreach ($items as $item) {
|
foreach ($items as $item) {
|
||||||
$entry = self::entry($doc, $type, $item, $owner, true, 0);
|
$entry = self::entry($doc, $type, $item, $owner, true, 0);
|
||||||
if (isset($entry)) {
|
if (isset($entry)) {
|
||||||
|
@ -1662,7 +1660,7 @@ class DFRN
|
||||||
*/
|
*/
|
||||||
private static function processVerbs(int $entrytype, array $importer, array &$item, bool &$is_like)
|
private static function processVerbs(int $entrytype, array $importer, array &$item, bool &$is_like)
|
||||||
{
|
{
|
||||||
Logger::info("Process verb " . $item['verb'] . " and object-type " . $item['object-type'] . " for entrytype " . $entrytype);
|
Logger::info('Process verb ' . $item['verb'] . ' and object-type ' . $item['object-type'] . ' for entrytype ' . $entrytype);
|
||||||
|
|
||||||
if (($entrytype == DFRN::TOP_LEVEL) && !empty($importer['id'])) {
|
if (($entrytype == DFRN::TOP_LEVEL) && !empty($importer['id'])) {
|
||||||
// The filling of the the "contact" variable is done for legcy reasons
|
// The filling of the the "contact" variable is done for legcy reasons
|
||||||
|
@ -2209,18 +2207,18 @@ class DFRN
|
||||||
$condition = ['uri' => $uri, 'uid' => $importer['importer_uid']];
|
$condition = ['uri' => $uri, 'uid' => $importer['importer_uid']];
|
||||||
$item = Post::selectFirst(['id', 'parent', 'contact-id', 'uri-id', 'deleted', 'gravity'], $condition);
|
$item = Post::selectFirst(['id', 'parent', 'contact-id', 'uri-id', 'deleted', 'gravity'], $condition);
|
||||||
if (!DBA::isResult($item)) {
|
if (!DBA::isResult($item)) {
|
||||||
Logger::info("Item with uri " . $uri . " for user " . $importer['importer_uid'] . " wasn't found.");
|
Logger::info('Item with URI ' . $uri . ' for user ' . $importer['importer_uid'] . ' was not found.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DBA::exists('post-category', ['uri-id' => $item['uri-id'], 'uid' => $importer['importer_uid'], 'type' => Post\Category::FILE])) {
|
if (DBA::exists('post-category', ['uri-id' => $item['uri-id'], 'uid' => $importer['importer_uid'], 'type' => Post\Category::FILE])) {
|
||||||
Logger::notice("Item is filed. It won't be deleted.", ['uri' => $uri, 'uri-id' => $item['uri_id'], 'uid' => $importer['importer_uid']]);
|
Logger::notice('Item is filed. It will not be deleted.', ['uri' => $uri, 'uri-id' => $item['uri_id'], 'uid' => $importer['importer_uid']]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// When it is a starting post it has to belong to the person that wants to delete it
|
// When it is a starting post it has to belong to the person that wants to delete it
|
||||||
if (($item['gravity'] == GRAVITY_PARENT) && ($item['contact-id'] != $importer['id'])) {
|
if (($item['gravity'] == GRAVITY_PARENT) && ($item['contact-id'] != $importer['id'])) {
|
||||||
Logger::info("Item with uri " . $uri . " don't belong to contact " . $importer['id'] . " - ignoring deletion.");
|
Logger::info('Item with URI ' . $uri . ' do not belong to contact ' . $importer['id'] . ' - ignoring deletion.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2228,7 +2226,7 @@ class DFRN
|
||||||
if (($item['gravity'] != GRAVITY_PARENT) && ($item['contact-id'] != $importer['id'])) {
|
if (($item['gravity'] != GRAVITY_PARENT) && ($item['contact-id'] != $importer['id'])) {
|
||||||
$condition = ['id' => $item['parent'], 'contact-id' => $importer['id']];
|
$condition = ['id' => $item['parent'], 'contact-id' => $importer['id']];
|
||||||
if (!Post::exists($condition)) {
|
if (!Post::exists($condition)) {
|
||||||
Logger::info("Item with uri " . $uri . " wasn't found or mustn't be deleted by contact " . $importer['id'] . " - ignoring deletion.");
|
Logger::info('Item with URI ' . $uri . ' was not found or must not be deleted by contact ' . $importer['id'] . ' - ignoring deletion.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -406,37 +406,37 @@ class Email
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert iri (?) to message id
|
* Convert item URI to message id
|
||||||
*
|
*
|
||||||
* @param string $iri Iri string
|
* @param string $itemUri Item URI
|
||||||
* @return string Message it
|
* @return string Message id
|
||||||
*/
|
*/
|
||||||
public static function iri2msgid(string $iri): string
|
public static function iri2msgid(string $itemUri): string
|
||||||
{
|
{
|
||||||
$msgid = $iri;
|
$msgid = $itemUri;
|
||||||
|
|
||||||
if (!strpos($iri, '@')) {
|
if (!strpos($itemUri, '@')) {
|
||||||
$msgid = preg_replace("/urn:(\S+):(\S+)\.(\S+):(\d+):(\S+)/i", "urn!$1!$4!$5@$2.$3", $iri);
|
$msgid = preg_replace("/urn:(\S+):(\S+)\.(\S+):(\d+):(\S+)/i", "urn!$1!$4!$5@$2.$3", $itemUri);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $msgid;
|
return $msgid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts message id to iri
|
* Converts message id to item URI
|
||||||
*
|
*
|
||||||
* @param string $msgid Message id
|
* @param string $msgid Message id
|
||||||
* @return string Iri
|
* @return string Item URI
|
||||||
*/
|
*/
|
||||||
public static function msgid2iri(string $msgid): string
|
public static function msgid2iri(string $msgid): string
|
||||||
{
|
{
|
||||||
$iri = $msgid;
|
$itemUri = $msgid;
|
||||||
|
|
||||||
if (strpos($msgid, '@')) {
|
if (strpos($msgid, '@')) {
|
||||||
$iri = preg_replace("/urn!(\S+)!(\d+)!(\S+)@(\S+)\.(\S+)/i", "urn:$1:$4.$5:$2:$3", $msgid);
|
$itemUri = preg_replace("/urn!(\S+)!(\d+)!(\S+)@(\S+)\.(\S+)/i", "urn:$1:$4.$5:$2:$3", $msgid);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $iri;
|
return $itemUri;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -67,7 +67,7 @@ class Feed
|
||||||
if ($dryRun) {
|
if ($dryRun) {
|
||||||
Logger::info("Test Atom/RSS feed");
|
Logger::info("Test Atom/RSS feed");
|
||||||
} else {
|
} else {
|
||||||
Logger::info("Import Atom/RSS feed '" . $contact['name'] . "' (Contact " . $contact['id'] . ") for user " . $importer['uid']);
|
Logger::info('Import Atom/RSS feed "' . $contact['name'] . '" (Contact ' . $contact['id'] . ') for user ' . $importer['uid']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$xml = trim($xml);
|
$xml = trim($xml);
|
||||||
|
@ -379,7 +379,7 @@ class Feed
|
||||||
if (DBA::isResult($previous)) {
|
if (DBA::isResult($previous)) {
|
||||||
// Use the creation date when the post had been stored. It can happen this date changes in the feed.
|
// Use the creation date when the post had been stored. It can happen this date changes in the feed.
|
||||||
$creation_dates[] = $previous['created'];
|
$creation_dates[] = $previous['created'];
|
||||||
Logger::info("Item with uri " . $item['uri'] . " for user " . $importer['uid'] . " already existed under id " . $previous['id']);
|
Logger::info('Item with URI ' . $item['uri'] . ' for user ' . $importer['uid'] . ' already existed under id ' . $previous['id']);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$creation_dates[] = DateTimeFormat::utc($item['created']);
|
$creation_dates[] = DateTimeFormat::utc($item['created']);
|
||||||
|
|
|
@ -224,7 +224,7 @@ class OStatus
|
||||||
Contact::update($contact, ['id' => $contact['id']], $current);
|
Contact::update($contact, ['id' => $contact['id']], $current);
|
||||||
|
|
||||||
if (!empty($author['author-avatar']) && ($author['author-avatar'] != $current['avatar'])) {
|
if (!empty($author['author-avatar']) && ($author['author-avatar'] != $current['avatar'])) {
|
||||||
Logger::info("Update profile picture for contact ".$contact["id"]);
|
Logger::info('Update profile picture for contact ' . $contact['id']);
|
||||||
Contact::updateAvatar($contact['id'], $author['author-avatar']);
|
Contact::updateAvatar($contact['id'], $author['author-avatar']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -380,7 +380,7 @@ class OStatus
|
||||||
foreach ($hub_attributes as $hub_attribute) {
|
foreach ($hub_attributes as $hub_attribute) {
|
||||||
if ($hub_attribute->name == 'href') {
|
if ($hub_attribute->name == 'href') {
|
||||||
$hub = $hub_attribute->textContent;
|
$hub = $hub_attribute->textContent;
|
||||||
Logger::info("Found hub ", ['hub' => $hub]);
|
Logger::info('Found hub ', ['hub' => $hub]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -458,7 +458,7 @@ class OStatus
|
||||||
|
|
||||||
if (in_array($item['verb'], [Activity::O_UNFAVOURITE, Activity::UNFAVORITE])) {
|
if (in_array($item['verb'], [Activity::O_UNFAVOURITE, Activity::UNFAVORITE])) {
|
||||||
// Ignore "Unfavorite" message
|
// Ignore "Unfavorite" message
|
||||||
Logger::info("Ignore unfavorite message ", ['item' => $item]);
|
Logger::info('Ignore unfavorite message ', ['item' => $item]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -472,13 +472,13 @@ class OStatus
|
||||||
|
|
||||||
if ($item['verb'] == Activity::JOIN) {
|
if ($item['verb'] == Activity::JOIN) {
|
||||||
// ignore "Join" messages
|
// ignore "Join" messages
|
||||||
Logger::info("Ignore join message ", ['item' => $item]);
|
Logger::info('Ignore join message ', ['item' => $item]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($item['verb'] == 'http://mastodon.social/schema/1.0/block') {
|
if ($item['verb'] == 'http://mastodon.social/schema/1.0/block') {
|
||||||
// ignore mastodon "block" messages
|
// ignore mastodon "block" messages
|
||||||
Logger::info("Ignore block message ", ['item' => $item]);
|
Logger::info('Ignore block message ', ['item' => $item]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -495,7 +495,7 @@ class OStatus
|
||||||
|
|
||||||
if ($item['verb'] == Activity::FAVORITE) {
|
if ($item['verb'] == Activity::FAVORITE) {
|
||||||
$orig_uri = $xpath->query('activity:object/atom:id', $entry)->item(0)->nodeValue;
|
$orig_uri = $xpath->query('activity:object/atom:id', $entry)->item(0)->nodeValue;
|
||||||
Logger::notice("Favorite", ['uri' => $orig_uri, 'item' => $item]);
|
Logger::notice('Favorite', ['uri' => $orig_uri, 'item' => $item]);
|
||||||
|
|
||||||
$item['verb'] = Activity::LIKE;
|
$item['verb'] = Activity::LIKE;
|
||||||
$item['thr-parent'] = $orig_uri;
|
$item['thr-parent'] = $orig_uri;
|
||||||
|
@ -505,7 +505,7 @@ class OStatus
|
||||||
|
|
||||||
// http://activitystrea.ms/schema/1.0/rsvp-yes
|
// http://activitystrea.ms/schema/1.0/rsvp-yes
|
||||||
if (!in_array($item['verb'], [Activity::POST, Activity::LIKE, Activity::SHARE])) {
|
if (!in_array($item['verb'], [Activity::POST, Activity::LIKE, Activity::SHARE])) {
|
||||||
Logger::info("Unhandled verb", ['verb' => $item['verb'], 'item' => $item]);
|
Logger::info('Unhandled verb', ['verb' => $item['verb'], 'item' => $item]);
|
||||||
}
|
}
|
||||||
|
|
||||||
self::processPost($xpath, $entry, $item, $importer);
|
self::processPost($xpath, $entry, $item, $importer);
|
||||||
|
@ -521,10 +521,10 @@ class OStatus
|
||||||
$valid = !$uid || DI::pConfig()->get($uid, 'system', 'accept_only_sharer') != Item::COMPLETION_NONE;
|
$valid = !$uid || DI::pConfig()->get($uid, 'system', 'accept_only_sharer') != Item::COMPLETION_NONE;
|
||||||
|
|
||||||
if ($valid) {
|
if ($valid) {
|
||||||
Logger::info("Item with uri " . self::$itemlist[0]['uri'] . " will be imported due to the system settings.");
|
Logger::info('Item with URI ' . self::$itemlist[0]['uri'] . ' will be imported due to the system settings.');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Logger::info("Item with uri " . self::$itemlist[0]['uri'] . " belongs to a contact (" . self::$itemlist[0]['contact-id'] . "). It will be imported.");
|
Logger::info('Item with URI ' . self::$itemlist[0]['uri'] . ' belongs to a contact (' . self::$itemlist[0]['contact-id'] . '). It will be imported.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($valid && DI::pConfig()->get($uid, 'system', 'accept_only_sharer') != Item::COMPLETION_LIKE) {
|
if ($valid && DI::pConfig()->get($uid, 'system', 'accept_only_sharer') != Item::COMPLETION_LIKE) {
|
||||||
|
@ -537,7 +537,7 @@ class OStatus
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($valid) {
|
if ($valid) {
|
||||||
Logger::info("Item with URI " . self::$itemlist[0]['uri'] . " will be imported since the thread contains posts or shares.");
|
Logger::info('Item with URI ' . self::$itemlist[0]['uri'] . ' will be imported since the thread contains posts or shares.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -556,12 +556,12 @@ class OStatus
|
||||||
foreach (self::$itemlist as $item) {
|
foreach (self::$itemlist as $item) {
|
||||||
$found = Post::exists(['uid' => $importer['uid'], 'uri' => $item['uri']]);
|
$found = Post::exists(['uid' => $importer['uid'], 'uri' => $item['uri']]);
|
||||||
if ($found) {
|
if ($found) {
|
||||||
Logger::notice("Item with uri " . $item['uri'] . " for user " . $importer['uid'] . " already exists.");
|
Logger::notice('Item with URI ' . $item['uri'] . ' for user ' . $importer['uid'] . ' already exists.');
|
||||||
} elseif ($item['contact-id'] < 0) {
|
} elseif ($item['contact-id'] < 0) {
|
||||||
Logger::notice("Item with uri " . $item['uri'] . " is from a blocked contact.");
|
Logger::notice('Item with URI ' . $item['uri'] . ' is from a blocked contact.');
|
||||||
} else {
|
} else {
|
||||||
$ret = Item::insert($item);
|
$ret = Item::insert($item);
|
||||||
Logger::info("Item with uri " . $item['uri'] . " for user " . $importer['uid'] . " stored. Return value: " . $ret);
|
Logger::info('Item with URI ' . $item['uri'] . ' for user ' . $importer['uid'] . ' stored. Return value: ' . $ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1019,7 +1019,7 @@ class OStatus
|
||||||
$conversation = DBA::selectFirst('conversation', ['source'], $condition);
|
$conversation = DBA::selectFirst('conversation', ['source'], $condition);
|
||||||
if (DBA::isResult($conversation)) {
|
if (DBA::isResult($conversation)) {
|
||||||
$stored = true;
|
$stored = true;
|
||||||
Logger::info('Got cached XML from conversation for URI '.$related_uri);
|
Logger::info('Got cached XML from conversation for URI ' . $related_uri);
|
||||||
$xml = $conversation['source'];
|
$xml = $conversation['source'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1027,7 +1027,7 @@ class OStatus
|
||||||
if ($xml != '') {
|
if ($xml != '') {
|
||||||
self::process($xml, $importer, $contact, $hub, $stored, false, Conversation::PULL);
|
self::process($xml, $importer, $contact, $hub, $stored, false, Conversation::PULL);
|
||||||
} else {
|
} else {
|
||||||
Logger::info("XML couldn't be fetched for URI: " . $related_uri . " - href: " . $related);
|
Logger::info('XML could not be fetched for URI: ' . $related_uri . ' - href: ' . $related);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1168,7 +1168,7 @@ class OStatus
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Logger::warning('Unsupported rel=' . $attribute['rel'] . ',href=' . $attribute['href'] . ',object-type=' . $attribute['object-type']);
|
Logger::warning('Unsupported rel=' . $attribute['rel'] . ', href=' . $attribute['href'] . ', object-type=' . $attribute['object-type']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1239,7 +1239,7 @@ class OStatus
|
||||||
$url = $siteinfo['image'];
|
$url = $siteinfo['image'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$body = trim($siteinfo['text']) . " [url]" . $url . "[/url]\n[img]" . $preview . "[/img]";
|
$body = trim($siteinfo['text']) . ' [url]' . $url . "[/url]\n[img]" . $preview . '[/img]';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $body;
|
return $body;
|
||||||
|
@ -1591,7 +1591,7 @@ class OStatus
|
||||||
private static function likeEntry(DOMDocument $doc, array $item, array $owner, bool $toplevel): DOMElement
|
private static function likeEntry(DOMDocument $doc, array $item, array $owner, bool $toplevel): DOMElement
|
||||||
{
|
{
|
||||||
if (($item['gravity'] != GRAVITY_PARENT) && (Strings::normaliseLink($item['author-link']) != Strings::normaliseLink($owner['url']))) {
|
if (($item['gravity'] != GRAVITY_PARENT) && (Strings::normaliseLink($item['author-link']) != Strings::normaliseLink($owner['url']))) {
|
||||||
Logger::info("OStatus entry is from author " . $owner['url'] . " - not from " . $item['author-link'] . ". Quitting.");
|
Logger::info('OStatus entry is from author ' . $owner['url'] . ' - not from ' . $item['author-link'] . '. Quitting.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$entry = self::entryHeader($doc, $owner, $item, $toplevel);
|
$entry = self::entryHeader($doc, $owner, $item, $toplevel);
|
||||||
|
@ -1741,17 +1741,17 @@ class OStatus
|
||||||
private static function noteEntry(DOMDocument $doc, array $item, array $owner, bool $toplevel): DOMElement
|
private static function noteEntry(DOMDocument $doc, array $item, array $owner, bool $toplevel): DOMElement
|
||||||
{
|
{
|
||||||
if (($item['gravity'] != GRAVITY_PARENT) && (Strings::normaliseLink($item['author-link']) != Strings::normaliseLink($owner['url']))) {
|
if (($item['gravity'] != GRAVITY_PARENT) && (Strings::normaliseLink($item['author-link']) != Strings::normaliseLink($owner['url']))) {
|
||||||
Logger::info("OStatus entry is from author " . $owner['url'] . " - not from " . $item['author-link'] . ". Quitting.");
|
Logger::info('OStatus entry is from author ' . $owner['url'] . ' - not from ' . $item['author-link'] . '. Quitting.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$toplevel) {
|
if (!$toplevel) {
|
||||||
if (!empty($item['title'])) {
|
if (!empty($item['title'])) {
|
||||||
$title = BBCode::convertForUriId($item['uri-id'], $item['title'], BBCode::OSTATUS);
|
$title = BBCode::convertForUriId($item['uri-id'], $item['title'], BBCode::OSTATUS);
|
||||||
} else {
|
} else {
|
||||||
$title = sprintf("New note by %s", $owner['nick']);
|
$title = sprintf('New note by %s', $owner['nick']);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$title = sprintf("New comment by %s", $owner['nick']);
|
$title = sprintf('New comment by %s', $owner['nick']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$entry = self::entryHeader($doc, $owner, $item, $toplevel);
|
$entry = self::entryHeader($doc, $owner, $item, $toplevel);
|
||||||
|
@ -1832,7 +1832,7 @@ class OStatus
|
||||||
$body = self::formatPicturePost($body, $item['uri-id']);
|
$body = self::formatPicturePost($body, $item['uri-id']);
|
||||||
|
|
||||||
if (!empty($item['title'])) {
|
if (!empty($item['title'])) {
|
||||||
$body = "[b]" . $item['title'] . "[/b]\n\n" . $body;
|
$body = '[b]' . $item['title'] . "[/b]\n\n" . $body;
|
||||||
}
|
}
|
||||||
|
|
||||||
$body = BBCode::convertForUriId($item['uri-id'], $body, BBCode::OSTATUS);
|
$body = BBCode::convertForUriId($item['uri-id'], $body, BBCode::OSTATUS);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user