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

Items related functions. More...

Functions

 collect_recipients ($item, &$private_envelope)
 Collects recipients. More...
 
 comments_are_now_closed ($item)
 
 item_normal ()
 
 item_normal_search ()
 
 item_normal_update ()
 
 is_item_normal ($item)
 This is a compatibility function primarily for plugins, because in earlier DB schemas this was a much simpler single integer compare. More...
 
 can_comment_on_post ($observer_xchan, $item)
 Decide if current observer has sufficient privileges to comment on item. More...
 
 add_source_route ($iid, $hash)
 Adds $hash to the item source route specified by $iid. More...
 
 post_activity_item ($arr, $allow_code=false, $deliver=true)
 Post an activity. More...
 
 validate_item_elements ($message, $arr)
 
 limit_body_size ($body)
 Limit length on imported system messages. More...
 
 title_is_body ($title, $body)
 
 get_item_elements ($x, $allow_code=false)
 
 import_author_xchan ($x)
 
 import_author_rss ($x)
 Imports an author from a RSS feed. More...
 
 import_author_unknown ($x)
 
 encode_item ($item, $mirror=false)
 
 map_scope ($scope, $strip=false)
 
 translate_scope ($scope)
 Returns a descriptive text for a given $scope. More...
 
 encode_item_xchan ($xchan)
 
 encode_item_terms ($terms, $mirror=false)
 
 encode_item_meta ($meta, $mirror=false)
 
 decode_item_meta ($meta)
 
 termtype ($t)
 
 decode_tags ($t)
 
 activity_sanitise ($arr)
 Santise a potentially complex array. More...
 
 array_sanitise ($arr)
 Sanitise a simple linear array. More...
 
 encode_item_flags ($item)
 
 encode_mail ($item, $extended=false)
 
 get_mail_elements ($x)
 
 get_profile_elements ($x)
 
 item_sign (&$item)
 Signs an item body. More...
 
 item_store ($arr, $allow_exec=false, $deliver=true)
 Stores an item type record. More...
 
 item_store_update ($arr, $allow_exec=false, $deliver=true)
 Update a stored item. More...
 
 send_status_notifications ($post_id, $item)
 
 get_item_contact ($item, $contacts)
 
 tag_deliver ($uid, $item_id)
 Called when we deliver things that might be tagged in ways that require delivery processing. More...
 
 tgroup_check ($uid, $item)
 This function is called pre-deliver to see if a post matches the criteria to be tag delivered. More...
 
 start_delivery_chain ($channel, $item, $item_id, $parent)
 
 check_item_source ($uid, $item)
 Checks to see if this item owner is referenced as a source for this channel and if the post matches the rules for inclusion in this channel. Returns true if we should create a second delivery chain and false if none of the rules apply, or if the item is private. More...
 
 post_is_importable ($item, $abook)
 
 mail_store ($arr)
 
 fix_private_photos ($s, $uid, $item=null, $cid=0)
 
 has_permissions ($obj)
 
 compare_permissions ($obj1, $obj2)
 
 enumerate_permissions ($obj)
 Returns an array of contact-ids that are allowed to see this object. More...
 
 item_getfeedtags ($item)
 
 item_getfeedattach ($item)
 
 item_expire ($uid, $days)
 
 retain_item ($id)
 
 drop_items ($items, $interactive=false, $stage=DROPITEM_NORMAL, $force=false)
 
 drop_item ($id, $interactive=true, $stage=DROPITEM_NORMAL, $force=false)
 
 delete_item_lowlevel ($item, $stage=DROPITEM_NORMAL, $force=false)
 
 first_post_date ($uid, $wall=false)
 Return the first post date. More...
 
 list_post_dates ($uid, $wall, $mindate)
 
 posted_dates ($uid, $wall)
 
 fetch_post_tags ($items, $link=false)
 Extend an item array with the associated tags of the posts. More...
 
 zot_feed ($uid, $observer_hash, $arr)
 
 items_fetch ($arr, $channel=null, $observer_hash=null, $client_mode=CLIENT_MODE_NORMAL, $module= 'network')
 
 webpage_to_namespace ($webpage)
 
 update_remote_id ($channel, $post_id, $webpage, $pagetitle, $namespace, $remote_id, $mid)
 
 item_add_cid ($xchan_hash, $mid, $uid)
 Change access control for item with message_id $mid and channel_id $uid. More...
 
 item_remove_cid ($xchan_hash, $mid, $uid)
 
 set_linkified_perms ($linkified, &$str_contact_allow, &$str_group_allow, $profile_uid, $parent_item=false, &$private)
 
 comment_local_origin ($item)
 
 send_profile_photo_activity ($channel, $photo, $profile)
 
 sync_an_item ($channel_id, $item_id)
 
 fix_attached_photo_permissions ($uid, $xchan_hash, $body, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny)
 
 fix_attached_file_permissions ($channel, $observer_hash, $body, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny)
 
 item_create_edit_activity ($post)
 
 copy_of_pubitem ($channel, $mid)
 copies an entire conversation from the pubstream to this channel's stream which will allow you to interact with it. More...
 

Detailed Description

Items related functions.

Function Documentation

activity_sanitise (   $arr)

Santise a potentially complex array.

Parameters
array$arr
Returns
array|string

Referenced by get_item_elements(), get_mail_elements(), item_store(), and item_store_update().

add_source_route (   $iid,
  $hash 
)

Adds $hash to the item source route specified by $iid.

$item['route'] contains a comma-separated list of xchans that sent the current message, somewhat analogous to the * Received: header line in email. We can use this to perform loop detection and to avoid sending a particular item to any "upstream" sender (they already have a copy because they sent it to us).

Modifies item in the database pointed to by $iid.

Parameters
integer$iiditem['id'] of target item
string$hashxchan_hash of the channel that sent the item

Referenced by process_delivery().

array_sanitise (   $arr)

Sanitise a simple linear array.

Parameters
array$arr
Returns
array|string

Referenced by get_profile_elements().

can_comment_on_post (   $observer_xchan,
  $item 
)

Decide if current observer has sufficient privileges to comment on item.

This function examines the comment_policy attached to an item and decides if the current observer has sufficient privileges to comment. This will normally be called on a remote site where perm_is_allowed() will not be suitable because the post owner does not have a local channel_id. Generally we should look at the item - in particular the author['abook_flags'] and see if ABOOK_FLAG_SELF is set. If it is, you should be able to use perm_is_allowed( ... 'post_comments'), and if it isn't you need to call can_comment_on_post() We also check the comments_closed date/time on the item if this is set.

Parameters
string$observer_xchan
array$item
Returns
boolean
Hooks:
can_comment_on_post Called when deciding whether or not to present a comment box for a post.
  • string observer_hash
  • array item
  • boolean allowed - return value

Referenced by Zotlabs\Lib\ThreadStream\add_thread(), Zotlabs\Module\Like\get(), and Zotlabs\Module\Item\post().

check_item_source (   $uid,
  $item 
)

Checks to see if this item owner is referenced as a source for this channel and if the post matches the rules for inclusion in this channel. Returns true if we should create a second delivery chain and false if none of the rules apply, or if the item is private.

Parameters
int$uid
array$item

Referenced by process_delivery(), start_delivery_chain(), and tag_deliver().

collect_recipients (   $item,
$private_envelope 
)

Collects recipients.

Parameters
array$item
[out]boolean$private_envelope
Returns
array containing the recipients

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

comment_local_origin (   $item)

We can't trust ITEM_ORIGIN to tell us if this is a local comment which needs to be relayed, because it was misconfigured at one point for several months and set for some remote items (in alternate delivery chains). This could cause looping, so use this hackish but accurate method.

Parameters
array$item
Returns
boolean

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

comments_are_now_closed (   $item)
compare_permissions (   $obj1,
  $obj2 
)

Referenced by fix_private_photos().

copy_of_pubitem (   $channel,
  $mid 
)

copies an entire conversation from the pubstream to this channel's stream which will allow you to interact with it.

Referenced by Zotlabs\Module\React\get(), Zotlabs\Module\Tagger\get(), Zotlabs\Module\Subthread\get(), Zotlabs\Module\Like\get(), and Zotlabs\Module\Item\post().

decode_item_meta (   $meta)

Referenced by get_item_elements().

decode_tags (   $t)
Parameters
array$t
Returns
array|string empty string or array containing associative arrays with
  • string term
  • string url
  • int type

Referenced by get_item_elements().

delete_item_lowlevel (   $item,
  $stage = DROPITEM_NORMAL,
  $force = false 
)
Warning
This function does not check for permission and does not send notifications and does not check recursion. It merely destroys all resources associated with an item. Please do not use without a suitable wrapper.
Parameters
array$item
int$stage
boolean$force
Returns
boolean
Fixme:
remove notifications for this item

Referenced by drop_item().

drop_items (   $items,
  $interactive = false,
  $stage = DROPITEM_NORMAL,
  $force = false 
)
encode_item_flags (   $item)

Referenced by encode_item().

encode_item_meta (   $meta,
  $mirror = false 
)

Referenced by encode_item().

encode_item_terms (   $terms,
  $mirror = false 
)

Referenced by encode_item().

encode_item_xchan (   $xchan)
Parameters
array$xchan
Returns
array an associative array

Referenced by encode_item(), encode_mail(), and process_channel_sync_delivery().

enumerate_permissions (   $obj)

Returns an array of contact-ids that are allowed to see this object.

Parameters
object$obj
Returns
array

Referenced by compare_permissions(), and fix_private_photos().

fetch_post_tags (   $items,
  $link = false 
)

Extend an item array with the associated tags of the posts.

Parameters
array$items
boolean$link(optional) default false
Returns
array Return the provided $items array after extended the posts with tags

Referenced by api_photo_detail(), attach_export_data(), channel_export_items(), copy_of_pubitem(), event_addtocal(), event_store_item(), Zotlabs\Module\Pubstream\get(), Zotlabs\Module\Moderate\get(), Zotlabs\Module\Article_edit\get(), Zotlabs\Module\Card_edit\get(), Zotlabs\Module\Editpost\get(), Zotlabs\Module\Search\get(), Zotlabs\Module\Display\get(), Zotlabs\Module\Block\get(), Zotlabs\Module\Articles\get(), Zotlabs\Module\Cards\get(), Zotlabs\Module\Network\get(), Zotlabs\Module\Hq\get(), Zotlabs\Module\Cal\get(), Zotlabs\Module\Tagrm\get(), Zotlabs\Module\Channel\get(), Zotlabs\Module\Page\get(), Zotlabs\Module\Events\get(), Zotlabs\Module\Item\get(), identity_basic_export(), identity_export_year(), Zotlabs\Module\Bookmarks\init(), Zotlabs\Module\Starred\init(), item_create_edit_activity(), item_expire(), items_fetch(), Zotlabs\Lib\NativeWikiPage\load_page(), Zotlabs\Lib\NativeWikiPage\load_page_history(), Zotlabs\Module\Oep\oep_articles_reply(), Zotlabs\Module\Oep\oep_cards_reply(), Zotlabs\Module\Oep\oep_display_reply(), Zotlabs\Module\Oep\oep_mid_reply(), Zotlabs\Lib\NativeWikiPage\page_list(), Zotlabs\Module\Tagrm\post(), Zotlabs\Module\Events\post(), Zotlabs\Module\Item\post(), Zotlabs\Module\Photos\post(), Zotlabs\Daemon\Cron\run(), Zotlabs\Daemon\Notifier\run(), search_doc_files(), Zotlabs\Lib\NativeWiki\sync_a_wiki_item(), sync_an_item(), tag_deliver(), Zotlabs\Widget\Item\widget(), and zot_feed().

first_post_date (   $uid,
  $wall = false 
)

Return the first post date.

Parameters
int$uid
boolean$wall(optional) default false
Returns
string|boolean date string, otherwise false

Referenced by list_post_dates(), and posted_dates().

fix_attached_file_permissions (   $channel,
  $observer_hash,
  $body,
  $str_contact_allow,
  $str_group_allow,
  $str_contact_deny,
  $str_group_deny 
)
fix_attached_photo_permissions (   $uid,
  $xchan_hash,
  $body,
  $str_contact_allow,
  $str_group_allow,
  $str_contact_deny,
  $str_group_deny 
)
fix_private_photos (   $s,
  $uid,
  $item = null,
  $cid = 0 
)

Referenced by atom_entry().

get_item_contact (   $item,
  $contacts 
)
get_item_elements (   $x,
  $allow_code = false 
)
get_mail_elements (   $x)

Referenced by import_mail(), and zot_import().

get_profile_elements (   $x)

Referenced by zot_import().

has_permissions (   $obj)

Referenced by fix_private_photos().

import_author_rss (   $x)

Imports an author from a RSS feed.

Parameters
array$xan associative array with
  • string url
  • string name
  • string guid
Returns
boolean|string

Referenced by import_author_xchan().

import_author_unknown (   $x)
Hooks:
import_author
  • array author
  • boolean|string result - Return value, default false

Referenced by consume_feed(), and import_author_xchan().

import_author_xchan (   $x)
Hooks:
import_author_xchan Called when looking up an author of a post by xchan_hash to ensure they have an xchan record on our site.
  • array xchan
  • string xchan_hash - Thre returned value

Referenced by get_item_elements(), get_mail_elements(), get_profile_elements(), and process_channel_sync_delivery().

is_item_normal (   $item)

This is a compatibility function primarily for plugins, because in earlier DB schemas this was a much simpler single integer compare.

Parameters
array$item

Referenced by Zotlabs\Module\Item\post().

item_add_cid (   $xchan_hash,
  $mid,
  $uid 
)

Change access control for item with message_id $mid and channel_id $uid.

Parameters
string$xchan_hash
string$mid
int$uid
item_create_edit_activity (   $post)
item_expire (   $uid,
  $days 
)
item_getfeedattach (   $item)
item_getfeedtags (   $item)
item_normal_search ( )
item_remove_cid (   $xchan_hash,
  $mid,
  $uid 
)
item_sign ( $item)

Signs an item body.

Parameters
[in,out]array$item

Referenced by item_store(), and item_store_update().

item_store (   $arr,
  $allow_exec = false,
  $deliver = true 
)

Stores an item type record.

Parameters
array$arr
boolean$allow_exec(optional) default false
boolean$deliver(optional) default true
Returns
array
  • boolean success
  • int item_id
Hooks:
item_store Called when item_store() stores a record of type item.
  • array item
  • boolean allow_exec
Hooks:
item_translate Called from item_store and item_store_update after the post language has been autodetected.
  • array item
  • string from
  • string to
  • boolean translated
Hooks:
item_store Called when item_store() stores a record of type item.
Hooks:
post_remote Called when an activity arrives from another site. This hook remains for backward compatibility.
Hooks:
post_remote_end Called after processing a remote post.

Referenced by consume_feed(), copy_of_pubitem(), Zotlabs\Lib\NativeWiki\create_wiki(), delete_imported_item(), event_store_item(), Zotlabs\Module\React\get(), Zotlabs\Module\Like\get(), Zotlabs\Module\Subthread\get(), import_items(), import_webpage_element(), Zotlabs\Module\Impel\init(), Zotlabs\Module\Mood\init(), photo_upload(), photos_create_item(), Zotlabs\Module\Item\post(), post_activity_item(), process_delivery(), profile_activity(), refimport_content(), reflect_comment_store(), Zotlabs\Lib\NativeWikiPage\save_page(), and store_doc_file().

item_store_update (   $arr,
  $allow_exec = false,
  $deliver = true 
)

Update a stored item.

Parameters
array$arran item
boolean$allow_exec(optional) default false
boolean$deliver(optional) default true
Returns
array
Hooks:
item_store_update Called when item_store_update() is called to update a stored item. It overwrites the function's parameters $arr and $allow_exec.
  • array item
  • boolean allow_exec
Hooks:
item_translate Called from item_store() and item_store_update() after the post language has been autodetected.
  • array item - returned value
  • string from
  • string to
  • boolean translated - default false, set true if hook translated it and provide it in item
Hooks:
post_remote_update Called when processing a remote post that involved an edit or update.
Hooks:
post_remote_update_end Called after processing a remote post that involved an edit or update.

Referenced by Zotlabs\Module\Tagrm\get(), import_items(), import_webpage_element(), Zotlabs\Module\Impel\init(), photo_upload(), Zotlabs\Module\Tagrm\post(), Zotlabs\Module\Item\post(), Zotlabs\Module\Photos\post(), refimport_content(), reflect_comment_store(), store_doc_file(), update_feed_item(), update_imported_item(), and Zotlabs\Lib\NativeWiki\update_wiki().

items_fetch (   $arr,
  $channel = null,
  $observer_hash = null,
  $client_mode = CLIENT_MODE_NORMAL,
  $module = 'network' 
)
Fixme:
finish mark unseen sql

Referenced by api_network_stream(), get_feed_for(), and red_item().

limit_body_size (   $body)

Limit length on imported system messages.

The purpose of this function is to apply system message length limits to imported messages without including any embedded photos in the length.

Parameters
string$body
Returns
string

Referenced by get_atom_elements().

list_post_dates (   $uid,
  $wall,
  $mindate 
)

modified posted_dates() {below} to arrange the list in years, which we'll eventually use to make a menu of years with collapsible sub-menus for the months instead of the current flat list of all representative dates.

Parameters
int$uid
boolean$wall
string$mindate
Returns
array

Referenced by Zotlabs\Widget\Archive\widget().

mail_store (   $arr)
Hooks:
post_mail Called when a mail message has been composed.
Hooks:
post_mail_end Called when a mail message has been delivered.

Referenced by import_mail(), and process_mail_delivery().

map_scope (   $scope,
  $strip = false 
)
post_activity_item (   $arr,
  $allow_code = false,
  $deliver = true 
)

Post an activity.

In its simplest form one needs only to set $arr['body'] to post a note to the logged in channel's wall. Much more complex activities can be created. Permissions are checked. No filtering, tag expansion or other processing is performed.

Parameters
array$arr
boolean$allow_code(optional) default false
boolean$deliver(optional) default true
Returns
array
  • boolean success true or false
  • array activity the resulting activity if successful
Hooks:
post_local Called when an item has been posted on this machine via mod/item.php (also via API).
Hooks:
post_local_end Called after a local post operation has completed.

Referenced by api_channel_stream(), Zotlabs\Lib\NativeWikiPage\create_page(), file_activity(), Zotlabs\Module\Tagger\get(), Zotlabs\Module\Thing\init(), Zotlabs\Module\Poke\init(), item_create_edit_activity(), Zotlabs\Module\Connedit\post(), Zotlabs\Module\Cover_photo\send_cover_photo_activity(), and send_profile_photo_activity().

post_is_importable (   $item,
  $abook 
)

Referenced by consume_feed(), and process_delivery().

posted_dates (   $uid,
  $wall 
)
send_profile_photo_activity (   $channel,
  $photo,
  $profile 
)
send_status_notifications (   $post_id,
  $item 
)

Referenced by item_store(), and item_store_update().

set_linkified_perms (   $linkified,
$str_contact_allow,
$str_group_allow,
  $profile_uid,
  $parent_item = false,
$private 
)
start_delivery_chain (   $channel,
  $item,
  $item_id,
  $parent 
)

Sourced and tag-delivered posts are re-targetted for delivery to the connections of the channel receiving the post. This starts the second delivery chain, by resetting permissions and ensuring that ITEM_UPLINK is set on the parent post, and storing the current owner_xchan as the source_xchan. We'll become the new owner. If called without $parent, this is the parent post.

Parameters
array$channel
array$item
int$item_id
boolean$parent

Referenced by tag_deliver().

sync_an_item (   $channel_id,
  $item_id 
)
tag_deliver (   $uid,
  $item_id 
)

Called when we deliver things that might be tagged in ways that require delivery processing.

Handles community tagging of posts and also look for mention tags and sets up a second delivery chain if appropriate.

Parameters
int$uid
int$item_id
Hooks:
tagged Called when a delivery is processed which results in you being tagged.
  • number channel_id
  • array item
  • string body

Referenced by delete_imported_item(), Zotlabs\Module\Item\get(), item_store(), and item_store_update().

termtype (   $t)
Parameters
int$t
Returns
string

Referenced by encode_item_terms().

tgroup_check (   $uid,
  $item 
)

This function is called pre-deliver to see if a post matches the criteria to be tag delivered.

We don't actually do anything except check that it matches the criteria. This is so that the channel with tag_delivery enabled can receive the post even if they turn off permissions for the sender to send their stream. tag_deliver() can't be called until the post is actually stored. By then it would be too late to reject it.

Parameters
number$uidA chnnel_id
array$item
Returns
boolean

Referenced by process_delivery().

title_is_body (   $title,
  $body 
)

Referenced by get_atom_elements().

translate_scope (   $scope)

Returns a descriptive text for a given $scope.

Parameters
string$scope
Returns
string translated string describing the scope

Referenced by Zotlabs\Module\Lockview\get(), and Zotlabs\Module\Profiles\get().

update_remote_id (   $channel,
  $post_id,
  $webpage,
  $pagetitle,
  $namespace,
  $remote_id,
  $mid 
)
validate_item_elements (   $message,
  $arr 
)

Referenced by zot_import().

webpage_to_namespace (   $webpage)
zot_feed (   $uid,
  $observer_hash,
  $arr 
)
Parameters
int$uid
string$observer_hash
array$arr
Returns
array

Referenced by api_channel_stream(), Zotlabs\Module\Zotfeed\init(), Zotlabs\Daemon\Onepoll\run(), and zot_reply_message_request().