1
0
Fork 0

The feed is now a class

This commit is contained in:
Michael 2017-12-13 07:03:42 +00:00
parent fc55a4b9c0
commit 74ba0c896a

View file

@ -1,11 +1,24 @@
<?php <?php
/**
* @file src/Protocol/Feed.php
* @brief Imports RSS/RDF/Atom feeds
*
*/
namespace Friendica\Protocol;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Core\System; use Friendica\Core\System;
use dba;
require_once("include/html2bbcode.php"); require_once("include/html2bbcode.php");
require_once("include/items.php"); require_once("include/items.php");
/** /**
* @brief This class contain functions to import feeds
*
*/
class Feed {
/**
* @brief Read a RSS/RDF/Atom feed and create an item entry for it * @brief Read a RSS/RDF/Atom feed and create an item entry for it
* *
* @param string $xml The feed data * @param string $xml The feed data
@ -16,7 +29,7 @@ require_once("include/items.php");
* *
* @return array In simulation mode it returns the header and the first item * @return array In simulation mode it returns the header and the first item
*/ */
function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) { function import($xml, $importer, &$contact, &$hub, $simulate = false) {
$a = get_app(); $a = get_app();
@ -236,10 +249,11 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
$item["parent-uri"] = $item["uri"]; $item["parent-uri"] = $item["uri"];
if (!$simulate) { if (!$simulate) {
$r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s', '%s')", $condition = ["`uid` = ? AND `uri` = ? AND `network` IN (?, ?)",
intval($importer["uid"]), dbesc($item["uri"]), dbesc(NETWORK_FEED), dbesc(NETWORK_DFRN)); $importer["uid"], $item["uri"], NETWORK_FEED, NETWORK_DFRN];
if (DBM::is_result($r)) { $previous = dba::select('item', ['id'], $condition, ['limit' => 1]);
logger("Item with uri ".$item["uri"]." for user ".$importer["uid"]." already existed under id ".$r[0]["id"], LOGGER_DEBUG); if (DBM::is_result($previous)) {
logger("Item with uri ".$item["uri"]." for user ".$importer["uid"]." already existed under id ".$previous["id"], LOGGER_DEBUG);
continue; continue;
} }
} }
@ -435,4 +449,5 @@ function feed_import($xml,$importer,&$contact, &$hub, $simulate = false) {
if ($simulate) { if ($simulate) {
return array("header" => $author, "items" => $items); return array("header" => $author, "items" => $items);
} }
}
} }