The Hubzilla
 All Classes Namespaces Files Functions Variables Pages
feedutils.php File Reference

Some functions to work with XML feeds. More...

Functions

 get_public_feed ($channel, $params)
 Return an Atom feed for channel. More...
 
 get_feed_for ($channel, $observer_hash, $params)
 Create an atom feed for $channel from template. More...
 
 construct_verb ($item)
 Return the verb for an item, or fall back to ACTIVITY_POST. More...
 
 construct_activity_object ($item)
 
 construct_activity_target ($item)
 
 get_atom_elements ($feed, $item, &$author)
 Return an array with a parsed atom item. More...
 
 feed_get_reshare (&$res, $item)
 
 encode_rel_links ($links)
 Encodes SimplePie_Item link arrays. More...
 
 process_feed_tombstones ($feed, $importer, $contact, $pass)
 
 consume_feed ($xml, $importer, &$contact, $pass=0)
 Process atom feed and update anything/everything we might need to update. More...
 
 feed_conversation_fetch ($importer, $contact, $parent_link)
 
 normalise_id ($id)
 Normalise an id. More...
 
 process_salmon_feed ($xml, $importer)
 Process atom feed and return the first post and structure. More...
 
 feed_meta ($xml)
 Given an xml (atom) feed, find author and hub links. More...
 
 update_feed_item ($uid, $datarray)
 Not yet implemented function to update feed item. More...
 
 handle_feed ($uid, $abook_id, $url)
 Fetch the content of a feed and further consume it. More...
 
 atom_author ($tag, $nick, $name, $uri, $h, $w, $type, $photo)
 Return a XML tag with author information. More...
 
 atom_render_author ($tag, $xchan)
 Return an atom tag with author information from an xchan. More...
 
 compat_photos_list ($s)
 
 atom_entry ($item, $type, $author, $owner, $comment=false, $cid=0, $compat=false)
 Create an item for the Atom feed. More...
 

Detailed Description

Some functions to work with XML feeds.

Function Documentation

atom_author (   $tag,
  $nick,
  $name,
  $uri,
  $h,
  $w,
  $type,
  $photo 
)

Return a XML tag with author information.

Parameters
string$tagThe XML tag to create
string$nickpreferred username
string$namedisplayed name of the author
string$uri
int$himage height
int$wimage width
string$typeprofile photo mime type
string$photoFully qualified URL to a profile/avator photo
Returns
string XML tag
Hooks:
atom_author Possibility to add further tags to returned XML string
  • string - The created XML tag as a string without closing tag
atom_entry (   $item,
  $type,
  $author,
  $owner,
  $comment = false,
  $cid = 0,
  $compat = false 
)

Create an item for the Atom feed.

See Also
get_feed_for()
Parameters
array$item
string$type
array$author
array$owner
string$commentdefault false
number$ciddefault 0
boolean$compatdefault false
Returns
void|string
Hooks:
atom_entry
  • array item
  • string type
  • array author
  • array owner
  • string comment
  • number abook_id
  • string entry - The generated entry and what will get returned

Referenced by Zotlabs\Module\Display\get(), and get_feed_for().

atom_render_author (   $tag,
  $xchan 
)

Return an atom tag with author information from an xchan.

Parameters
string$tag
array$xchan
Returns
string
Hooks:
atom_render_author Possibility to add further tags to returned XML string.
  • string The created XML tag as a string without closing tag

Referenced by atom_entry(), and get_feed_for().

compat_photos_list (   $s)

Referenced by atom_entry().

construct_activity_object (   $item)
Fixme:
!!

Referenced by atom_entry().

construct_activity_target (   $item)
Fixme:
!!!

Referenced by atom_entry().

construct_verb (   $item)

Return the verb for an item, or fall back to ACTIVITY_POST.

Parameters
array$iteman associative array with
  • string verb
Returns
string item's verb if set, default ACTIVITY_POST see boot.php

Referenced by atom_entry().

consume_feed (   $xml,
  $importer,
$contact,
  $pass = 0 
)

Process atom feed and update anything/everything we might need to update.

Parameters
string$xmlThe (atom) feed to consume - RSS isn't as fully supported but may work for simple feeds.
array$importerThe contact_record (joined to user_record) of the local user who owns this relationship. It is this person's stuff that is going to be updated.
[in,out]array$contactThe person who is sending us stuff. If not set, we MAY be processing a "follow" activity from an external network and MAY create an appropriate contact record. Otherwise, we MUST have a contact record.
int$passby default ($pass = 0) we cannot guarantee that a parent item has been imported prior to its children being seen in the stream unless we are certain of how the feed is arranged/ordered.
  • With $pass = 1, we only pull parent items out of the stream.
  • With $pass = 2, we only pull children (comments/likes).

So running this twice, first with pass 1 and then with pass 2 will do the right thing regardless of feed ordering. This won't be adequate in a fully-threaded model where comments can have sub-threads. That would require some massive sorting to get all the feed items into a mostly linear ordering, and might still require recursion.

Fixme:
check for and process ostatus autofriend otherwise ignore this author.

Referenced by feed_conversation_fetch(), and handle_feed().

encode_rel_links (   $links)

Encodes SimplePie_Item link arrays.

Parameters
array$linksArray with SimplePie_Item link tags
Returns
array

Referenced by feed_get_reshare(), and get_atom_elements().

feed_conversation_fetch (   $importer,
  $contact,
  $parent_link 
)

Referenced by consume_feed().

feed_get_reshare ( $res,
  $item 
)

Referenced by get_atom_elements().

feed_meta (   $xml)

Given an xml (atom) feed, find author and hub links.

Parameters
string$xml
Returns
array
get_atom_elements (   $feed,
  $item,
$author 
)

Return an array with a parsed atom item.

Parameters
SimplePie$feed
array$item
[out]array$author
Returns
array Associative array with the parsed item data
Hooks:
parse_atom
  • SimplePie feed - The original SimplePie feed
  • array item
  • array author
  • array result - the result array that will also get returned

Referenced by consume_feed(), and process_salmon_feed().

get_feed_for (   $channel,
  $observer_hash,
  $params 
)

Create an atom feed for $channel from template.

Parameters
array$channel
string$observer_hashxchan_hash from observer
array$params
Returns
string with an atom feed
Hooks:
atom_feed_top
  • string xml - the generated feed and what will get returned from the hook
  • array channel
  • string observer_hash
  • array params
Hooks:
atom_feed A much simpler interface than atom_feed_top.
  • string - the feed after atom_feed_top hook
Hooks:
atom_feed_end string - The created XML feed as a string without closing tag

Referenced by get_public_feed().

get_public_feed (   $channel,
  $params 
)

Return an Atom feed for channel.

See Also
get_feed_for()
Parameters
array$channel
array$paramsassociative array which configures the feed
Returns
string with an atom feed

Referenced by Zotlabs\Module\Feed\init(), and Zotlabs\Module\Ofeed\init().

handle_feed (   $uid,
  $abook_id,
  $url 
)

Fetch the content of a feed and further consume it.

It will first process parent items and in a second run child items.

See Also
consume_feed()
Parameters
int$uid
int$abook_id
string$urlURL of the feed

Referenced by Zotlabs\Daemon\Onepoll\run().

normalise_id (   $id)

Normalise an id.

Strip "X-ZOT:" from $id.

Parameters
string$id
Returns
string

Referenced by consume_feed(), get_atom_elements(), process_feed_tombstones(), and process_salmon_feed().

process_feed_tombstones (   $feed,
  $importer,
  $contact,
  $pass 
)

Referenced by consume_feed().

process_salmon_feed (   $xml,
  $importer 
)

Process atom feed and return the first post and structure.

Parameters
string$xmlThe (atom) feed to consume - RSS isn't as fully supported but may work for simple feeds.
array$importer(unused) The contact_record (joined to user_record) of the local user who owns this relationship. It is this person's stuff that is going to be updated.
update_feed_item (   $uid,
  $datarray 
)

Not yet implemented function to update feed item.

Parameters
int$uid
array$datarray

Referenced by consume_feed().