/**
* 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 mixed $default Default
* @param mixed $minimal_value Minimal value
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])) {
- return ($match[1] . "[url]" . $match[2] . "[/url]");
+ return ($match[1] . '[url]' . $match[2] . '[/url]');
} 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
$own_photo_url = preg_quote(Strings::normaliseLink(DI::baseUrl()->get()) . '/photos/');
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');
$return = preg_replace_callback("&\[url=([^\[\]]*)\]\[img=(.*)\](.*)\[\/img\]\[\/url\]&Usi", 'self::cleanPictureLinksCallback', $text);
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');
$bbcode = preg_replace("/\[img\=(.*?)\](.*?)\[\/img\]/ism", ' $1 ', $bbcode);
/**
* Replace names in mentions with nicknames
*
- * @param string $body
+ * @param string $body HTML/BBCode
* @return string Body with replaced mentions
*/
- public static function setMentionsToNicknames(string $body):string
+ public static function setMentionsToNicknames(string $body): string
{
DI::profiler()->startRecording('rendering');
$regexp = "/([@!])\[url\=([^\[\]]*)\].*?\[\/url\]/ism";
* Callback function to replace a Friendica style mention in a mention with the nickname
*
* @param array $match Matching values for the callback
- * @return string Replaced mention
+ * @return string Replaced mention or empty string
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- private static function mentionCallback($match)
+ private static function mentionCallback(array $match): string
{
if (empty($match[2])) {
return '';
* @return string
* @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);
* @param int $simple_html
* @param bool $for_plaintext
* @param int $uriid
- * @return string
+ * @return string Converted code or empty string
* @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
if (is_null($text) || $text === '') {
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- private static function bbCodeMention2DiasporaCallback($match)
+ private static function bbCodeMention2DiasporaCallback(array $match): string
{
$contact = Contact::getByURL($match[3], false, ['addr']);
if (empty($contact['addr'])) {
* @return string
* @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');
$original_text = $text;
*
* @return array List of tag and person names
*/
- public static function getTags($string)
+ public static function getTags(string $string): array
{
DI::profiler()->startRecording('rendering');
$ret = [];
/**
* 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
*/
- public static function expandTags(string $body)
+ public static function expandTags(string $body): string
{
return preg_replace_callback("/(?<=\W|^)([!#@])([^\^ \x0D\x0A,;:?'\"]*[^\^ \x0D\x0A,;:?!'\".])/",
function ($match) {
/**
* 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 callable $callback
* @return string
/**
* Replaces mentions in the provided message body in BBCode links for the provided user and network if any
*
- * @param $body
- * @param $profile_uid
- * @param $network
- * @return string
+ * @param string $body HTML/BBCode
+ * @param int $profile_uid Profile user id
+ * @param string $network Network name
+ * @return string HTML/BBCode with inserted images
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @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');
$body = self::performWithEscapedTags($body, ['noparse', 'pre', 'code', 'img'], function ($body) use ($profile_uid, $network) {
* @return string
* @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');
$header = "[share author='" . str_replace(["'", "[", "]"], ["'", "[", "]"], $author) .
* Store tag/mention elements
*
* @param integer $uriid URI id
- * @param integer $type Type
- * @param string $name Name
- * @param string $url URL
+ * @param integer $type Tag type
+ * @param string $name Tag name
+ * @param string $url Contact URL (optional)
* @param integer $target Target (default: null)
* @return void
*/
}
/**
- * 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.
* It seems as if it was dropped from the standard.
} elseif (($link['rel'] == 'diaspora-public-key') && !empty($link['href'])) {
$data['pubkey'] = base64_decode($link['href']);
- //if (strstr($data['pubkey'], 'RSA ') || ($link['type'] == 'RSA'))
if (strstr($data['pubkey'], 'RSA ')) {
$data['pubkey'] = Crypto::rsaToPem($data['pubkey']);
}
}
}
- // 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'])) {
unset($data['guid']);
}
} elseif (($link['rel'] == 'diaspora-public-key') && !empty($link['href'])) {
$data['pubkey'] = base64_decode($link['href']);
- //if (strstr($data['pubkey'], 'RSA ') || ($link['type'] == 'RSA'))
if (strstr($data['pubkey'], 'RSA ')) {
$data['pubkey'] = Crypto::rsaToPem($data['pubkey']);
}
$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['batch'] = $data['baseurl'] . '/receive/public';
} else {
* Fetch the last activity date from the "noscrape" endpoint
*
* @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)
{
$root->setAttribute('xmlns:ostatus', ActivityNamespace::OSTATUS);
$root->setAttribute('xmlns:statusnet', ActivityNamespace::STATUSNET);
- //$root = self::addHeader($doc, $owner, 'dfrn:owner', '', false);
-
foreach ($items as $item) {
$entry = self::entry($doc, $type, $item, $owner, true, 0);
if (isset($entry)) {
*/
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'])) {
// The filling of the the "contact" variable is done for legcy reasons
$condition = ['uri' => $uri, 'uid' => $importer['importer_uid']];
$item = Post::selectFirst(['id', 'parent', 'contact-id', 'uri-id', 'deleted', 'gravity'], $condition);
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;
}
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;
}
// 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'])) {
- 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;
}
if (($item['gravity'] != GRAVITY_PARENT) && ($item['contact-id'] != $importer['id'])) {
$condition = ['id' => $item['parent'], 'contact-id' => $importer['id']];
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;
}
}
}
/**
- * Convert iri (?) to message id
+ * Convert item URI to message id
*
- * @param string $iri Iri string
- * @return string Message it
+ * @param string $itemUri Item URI
+ * @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, '@')) {
- $msgid = preg_replace("/urn:(\S+):(\S+)\.(\S+):(\d+):(\S+)/i", "urn!$1!$4!$5@$2.$3", $iri);
+ if (!strpos($itemUri, '@')) {
+ $msgid = preg_replace("/urn:(\S+):(\S+)\.(\S+):(\d+):(\S+)/i", "urn!$1!$4!$5@$2.$3", $itemUri);
}
return $msgid;
}
/**
- * Converts message id to iri
+ * Converts message id to item URI
*
* @param string $msgid Message id
- * @return string Iri
+ * @return string Item URI
*/
public static function msgid2iri(string $msgid): string
{
- $iri = $msgid;
+ $itemUri = $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;
}
/**
if ($dryRun) {
Logger::info("Test Atom/RSS feed");
} 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);
if (DBA::isResult($previous)) {
// Use the creation date when the post had been stored. It can happen this date changes in the feed.
$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;
}
$creation_dates[] = DateTimeFormat::utc($item['created']);
Contact::update($contact, ['id' => $contact['id']], $current);
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']);
}
foreach ($hub_attributes as $hub_attribute) {
if ($hub_attribute->name == 'href') {
$hub = $hub_attribute->textContent;
- Logger::info("Found hub ", ['hub' => $hub]);
+ Logger::info('Found hub ', ['hub' => $hub]);
}
}
}
if (in_array($item['verb'], [Activity::O_UNFAVOURITE, Activity::UNFAVORITE])) {
// Ignore "Unfavorite" message
- Logger::info("Ignore unfavorite message ", ['item' => $item]);
+ Logger::info('Ignore unfavorite message ', ['item' => $item]);
continue;
}
if ($item['verb'] == Activity::JOIN) {
// ignore "Join" messages
- Logger::info("Ignore join message ", ['item' => $item]);
+ Logger::info('Ignore join message ', ['item' => $item]);
continue;
}
if ($item['verb'] == 'http://mastodon.social/schema/1.0/block') {
// ignore mastodon "block" messages
- Logger::info("Ignore block message ", ['item' => $item]);
+ Logger::info('Ignore block message ', ['item' => $item]);
continue;
}
if ($item['verb'] == Activity::FAVORITE) {
$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['thr-parent'] = $orig_uri;
// http://activitystrea.ms/schema/1.0/rsvp-yes
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);
$valid = !$uid || DI::pConfig()->get($uid, 'system', 'accept_only_sharer') != Item::COMPLETION_NONE;
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 {
- 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) {
- 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 {
foreach (self::$itemlist as $item) {
$found = Post::exists(['uid' => $importer['uid'], 'uri' => $item['uri']]);
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) {
- 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 {
$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);
}
}
}
$conversation = DBA::selectFirst('conversation', ['source'], $condition);
if (DBA::isResult($conversation)) {
$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'];
}
}
if ($xml != '') {
self::process($xml, $importer, $contact, $hub, $stored, false, Conversation::PULL);
} 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;
}
break;
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']);
}
}
}
$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;
if ($owner['contact-type'] == Contact::TYPE_COMMUNITY) {
$members = DBA::count('contact', [
- 'uid' => $owner['uid'],
- 'self' => false,
+ 'uid' => $owner['uid'],
+ 'self' => false,
'pending' => false,
'archive' => false,
- 'hidden' => false,
+ 'hidden' => false,
'blocked' => false,
]);
XML::addElement($doc, $root, 'statusnet:group_info', '', ['member_count' => $members]);
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']))) {
- 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);
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']))) {
- 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 (!empty($item['title'])) {
$title = BBCode::convertForUriId($item['uri-id'], $item['title'], BBCode::OSTATUS);
} else {
- $title = sprintf("New note by %s", $owner['nick']);
+ $title = sprintf('New note by %s', $owner['nick']);
}
} else {
- $title = sprintf("New comment by %s", $owner['nick']);
+ $title = sprintf('New comment by %s', $owner['nick']);
}
$entry = self::entryHeader($doc, $owner, $item, $toplevel);
$body = self::formatPicturePost($body, $item['uri-id']);
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);
$contact = Contact::getByURL($mention, false, ['contact-type']);
if (!empty($contact) && ($contact['contact-type'] == Contact::TYPE_COMMUNITY)) {
XML::addElement($doc, $entry, 'link', '', [
- 'rel' => 'mentioned',
- 'ostatus:object-type' => Activity\ObjectType::GROUP,
- 'href' => $mention,
+ 'rel' => 'mentioned',
+ 'ostatus:object-type' => Activity\ObjectType::GROUP,
+ 'href' => $mention,
]);
} else {
XML::addElement($doc, $entry, 'link', '', [
- 'rel' => 'mentioned',
- 'ostatus:object-type' => Activity\ObjectType::PERSON,
+ 'rel' => 'mentioned',
+ 'ostatus:object-type' => Activity\ObjectType::PERSON,
'href' => $mention,
]);
}