Relocate functions in items.php into several classes

This commit is contained in:
Michael 2018-01-20 23:52:54 +00:00
parent 3ac1992237
commit efa8dbcfb3
7 changed files with 304 additions and 285 deletions

View file

@ -1037,7 +1037,7 @@ class DFRN
XML::addElement($doc, $entry, "dfrn:diaspora_signature", $sign);
}
XML::addElement($doc, $entry, "activity:verb", construct_verb($item));
XML::addElement($doc, $entry, "activity:verb", self::constructVerb($item));
if ($item['object-type'] != "") {
XML::addElement($doc, $entry, "activity:object-type", $item['object-type']);
@ -3073,4 +3073,19 @@ class DFRN
return;
}
/**
* @brief Returns the activity verb
*
* @param array $item Item array
*
* @return string activity verb
*/
private static function constructVerb(array $item)
{
if ($item['verb']) {
return $item['verb'];
}
return ACTIVITY_POST;
}
}

View file

@ -8,6 +8,7 @@ namespace Friendica\Protocol;
use Friendica\Database\DBM;
use Friendica\Core\System;
use Friendica\Model\Item;
use dba;
use DOMDocument;
use DOMXPath;
@ -357,7 +358,7 @@ class Feed {
// remove the content of the title if it is identically to the body
// This helps with auto generated titles e.g. from tumblr
if (title_is_body($item["title"], $body)) {
if (self::titleIsBody($item["title"], $body)) {
$item["title"] = "";
}
$item["body"] = html2bbcode($body, $basepath);
@ -426,7 +427,7 @@ class Feed {
// Distributed items should have a well formatted URI.
// Additionally we have to avoid conflicts with identical URI between imported feeds and these items.
if ($notify) {
$item['guid'] = uri_to_guid($orig_plink, $a->get_hostname());
$item['guid'] = Item::GuidFromUri($orig_plink, $a->get_hostname());
unset($item['uri']);
unset($item['parent-uri']);
}
@ -446,4 +447,30 @@ class Feed {
return ["header" => $author, "items" => $items];
}
}
private static function titleIsBody($title, $body)
{
$title = strip_tags($title);
$title = trim($title);
$title = html_entity_decode($title, ENT_QUOTES, 'UTF-8');
$title = str_replace(["\n", "\r", "\t", " "], ["", "", "", ""], $title);
$body = strip_tags($body);
$body = trim($body);
$body = html_entity_decode($body, ENT_QUOTES, 'UTF-8');
$body = str_replace(["\n", "\r", "\t", " "], ["", "", "", ""], $body);
if (strlen($title) < strlen($body)) {
$body = substr($body, 0, strlen($title));
}
if (($title != $body) && (substr($title, -3) == "...")) {
$pos = strrpos($title, "...");
if ($pos > 0) {
$title = substr($title, 0, $pos);
$body = substr($body, 0, $pos);
}
}
return ($title == $body);
}
}

View file

@ -11,6 +11,7 @@ use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Model\GContact;
use Friendica\Model\Conversation;
use Friendica\Network\Probe;
use Friendica\Object\Image;
use Friendica\Util\Lock;
@ -700,7 +701,7 @@ class OStatus
}
if (($item['author-link'] != '') && !empty($item['protocol'])) {
$item = store_conversation($item);
$item = Conversation::insert($item);
}
self::$itemlist[] = $item;
@ -843,7 +844,7 @@ class OStatus
}
logger('Store conversation data for uri '.$conv_data['uri'], LOGGER_DEBUG);
store_conversation($conv_data);
Conversation::insert($conv_data);
}
}