function encode_item($item, $mirror = false) { $x = array(); $x['type'] = 'activity'; $x['encoding'] = 'zot'; // logger('encode_item: ' . print_r($item,true)); $r = q("select channel_r_stream, channel_w_comment from channel where channel_id = %d limit 1", intval($item['uid'])); if ($r) { $comment_scope = $r[0]['channel_w_comment']; } else { $comment_scope = 0; } $scope = $item['public_policy']; if (!$scope) { $scope = 'public'; } $c_scope = map_scope($comment_scope); $key = get_config('system', 'prvkey'); if (array_key_exists('item_obscured', $item) && intval($item['item_obscured'])) { if ($item['title']) { $item['title'] = crypto_unencapsulate(json_decode_plus($item['title']), $key); } if ($item['body']) { $item['body'] = crypto_unencapsulate(json_decode_plus($item['body']), $key); } } // If we're trying to backup an item so that it's recoverable or for export/imprt, // add all the attributes we need to recover it if ($mirror) { $x['id'] = $item['id']; $x['parent'] = $item['parent']; $x['uid'] = $item['uid']; $x['allow_cid'] = $item['allow_cid']; $x['allow_gid'] = $item['allow_gid']; $x['deny_cid'] = $item['deny_cid']; $x['deny_gid'] = $item['deny_gid']; $x['revision'] = $item['revision']; $x['layout_mid'] = $item['layout_mid']; $x['postopts'] = $item['postopts']; $x['resource_id'] = $item['resource_id']; $x['resource_type'] = $item['resource_type']; $x['attach'] = $item['attach']; $x['item_origin'] = $item['item_origin']; $x['item_unseen'] = $item['item_unseen']; $x['item_starred'] = $item['item_starred']; $x['item_uplink'] = $item['item_uplink']; $x['item_consensus'] = $item['item_consensus']; $x['item_wall'] = $item['item_wall']; $x['item_thread_top'] = $item['item_thread_top']; $x['item_notshown'] = $item['item_notshown']; $x['item_nsfw'] = $item['item_nsfw']; $x['item_relay'] = $item['item_relay']; $x['item_mentionsme'] = $item['item_mentionsme']; $x['item_nocomment'] = $item['item_nocomment']; $x['item_obscured'] = $item['item_obscured']; $x['item_verified'] = $item['item_verified']; $x['item_retained'] = $item['item_retained']; $x['item_rss'] = $item['item_rss']; $x['item_deleted'] = $item['item_deleted']; $x['item_type'] = $item['item_type']; $x['item_hidden'] = $item['item_hidden']; $x['item_unpublished'] = $item['item_unpublished']; $x['item_delayed'] = $item['item_delayed']; $x['item_pending_remove'] = $item['item_pending_remove']; $x['item_blocked'] = $item['item_blocked']; } $x['message_id'] = $item['mid']; $x['message_top'] = $item['parent_mid']; $x['message_parent'] = $item['thr_parent']; $x['created'] = $item['created']; $x['edited'] = $item['edited']; // always send 0's over the wire $x['expires'] = $item['expires'] == '0001-01-01 00:00:00' ? '0000-00-00 00:00:00' : $item['expires']; $x['commented'] = $item['commented']; $x['mimetype'] = $item['mimetype']; $x['title'] = $item['title']; $x['body'] = $item['body']; $x['app'] = $item['app']; $x['verb'] = $item['verb']; $x['object_type'] = $item['obj_type']; $x['target_type'] = $item['tgt_type']; $x['permalink'] = $item['plink']; $x['location'] = $item['location']; $x['longlat'] = $item['coord']; $x['signature'] = $item['sig']; $x['route'] = $item['route']; $x['owner'] = encode_item_xchan($item['owner']); $x['author'] = encode_item_xchan($item['author']); if ($item['object']) { $x['object'] = json_decode_plus($item['object']); } if ($item['target']) { $x['target'] = json_decode_plus($item['target']); } if ($item['attach']) { $x['attach'] = json_decode_plus($item['attach']); } if ($y = encode_item_flags($item)) { $x['flags'] = $y; } if ($item['comments_closed'] !== NULL_DATE) { $x['comments_closed'] = $item['comments_closed']; } $x['public_scope'] = $scope; if ($item['item_nocomment']) { $x['comment_scope'] = 'none'; } else { $x['comment_scope'] = $c_scope; } if ($item['term']) { $x['tags'] = encode_item_terms($item['term'], $mirror); } if ($item['diaspora_meta']) { $z = json_decode($item['diaspora_meta'], true); if ($z) { if (is_array($z) && array_key_exists('iv', $z)) { $x['diaspora_signature'] = crypto_unencapsulate($z, $key); } else { $x['diaspora_signature'] = $z; } if (!is_array($z)) { logger('encode_item: diaspora meta is not an array: ' . print_r($z, true)); } } } logger('encode_item: ' . print_r($x, true), LOGGER_DATA); return $x; }
function encode_item($item, $mirror = false) { $x = array(); $x['type'] = 'activity'; $x['encoding'] = 'zot'; // logger('encode_item: ' . print_r($item,true)); $r = q("select channel_r_stream, channel_w_comment from channel where channel_id = %d limit 1", intval($item['uid'])); if ($r) { $comment_scope = $r[0]['channel_w_comment']; } else { $comment_scope = 0; } $scope = $item['public_policy']; if (!$scope) { $scope = 'public'; } $c_scope = map_scope($comment_scope); $key = get_config('system', 'prvkey'); if (array_key_exists('item_flags', $item) && $item['item_flags'] & ITEM_OBSCURED) { if ($item['title']) { $item['title'] = crypto_unencapsulate(json_decode_plus($item['title']), $key); } if ($item['body']) { $item['body'] = crypto_unencapsulate(json_decode_plus($item['body']), $key); } } // If we're trying to backup an item so that it's recoverable or for export/imprt, // add all the attributes we need to recover it if ($mirror) { $x['id'] = $item['id']; $x['parent'] = $item['parent']; $x['uid'] = $item['uid']; $x['allow_cid'] = $item['allow_cid']; $x['allow_gid'] = $item['allow_gid']; $x['deny_cid'] = $item['deny_cid']; $x['deny_gid'] = $item['deny_gid']; $x['revision'] = $item['revision']; $x['layout_mid'] = $item['layout_mid']; $x['postopts'] = $item['postopts']; $x['resource_id'] = $item['resource_id']; $x['resource_type'] = $item['resource_type']; $x['item_restrict'] = $item['item_restrict']; $x['item_flags'] = $item['item_flags']; $x['item_unseen'] = $item['item_unseen']; $x['attach'] = $item['attach']; if (array_key_exists('item_starred', $item) && intval($item['item_starred'])) { $x['item_flags'] |= ITEM_STARRED; } if (array_key_exists('item_uplink', $item) && intval($item['item_uplink'])) { $x['item_flags'] |= ITEM_UPLINK; } if (array_key_exists('item_consensus', $item) && intval($item['item_consensus'])) { $x['item_flags'] |= ITEM_CONSENSUS; } if (array_key_exists('item_wall', $item) && intval($item['item_wall'])) { $x['item_flags'] |= ITEM_WALL; } if (array_key_exists('item_thread_top', $item) && intval($item['item_thread_top'])) { $x['item_flags'] |= ITEM_THREAD_TOP; } if (array_key_exists('item_notshown', $item) && intval($item['item_notshown'])) { $x['item_flags'] |= ITEM_NOTSHOWN; } if (array_key_exists('item_nsfw', $item) && intval($item['item_nsfw'])) { $x['item_flags'] |= ITEM_NSFW; } if (array_key_exists('item_mentionsme', $item) && intval($item['item_mentionsme'])) { $x['item_flags'] |= ITEM_MENTIONSME; } if (array_key_exists('item_nocomment', $item) && intval($item['item_nocomment'])) { $x['item_flags'] |= ITEM_NOCOMMENT; } if (array_key_exists('item_retained', $item) && intval($item['item_retained'])) { $x['item_flags'] |= ITEM_RETAINED; } if (array_key_exists('item_rss', $item) && intval($item['item_rss'])) { $x['item_flags'] |= ITEM_RSS; } if (array_key_exists('item_deleted', $item) && intval($item['item_deleted'])) { $x['item_restrict'] |= ITEM_DELETED; } if (array_key_exists('item_hidden', $item) && intval($item['item_hidden'])) { $x['item_restrict'] |= ITEM_HIDDEN; } if (array_key_exists('item_unpublished', $item) && intval($item['item_unpublished'])) { $x['item_restrict'] |= ITEM_UNPUBLISHED; } if (array_key_exists('item_delayed', $item) && intval($item['item_delayed'])) { $x['item_restrict'] |= ITEM_DELAYED_PUBLISH; } if (array_key_exists('item_pending_remove', $item) && intval($item['item_pending_remove'])) { $x['item_restrict'] |= ITEM_PENDING_REMOVE; } if (array_key_exists('item_blocked', $item) && intval($item['item_blocked'])) { $x['item_flags'] |= ITEM_BLOCKED; } if (array_key_exists('item_', $item) && intval($item['item_'])) { $x['item_flags'] |= ITEM_; } if (array_key_exists('item_type', $item) && intval($item['item_type'])) { switch (intval($item['item_type'])) { case 1: $x['item_restrict'] |= ITEM_BUILDBLOCK; break; case 2: $x['item_restrict'] |= ITEM_PDL; break; case 3: $x['item_restrict'] |= ITEM_WEBPAGE; break; case 4: $x['item_restrict'] |= ITEM_BUG; break; case 5: $x['item_restrict'] |= ITEM_DOC; break; default: break; } } } $x['message_id'] = $item['mid']; $x['message_top'] = $item['parent_mid']; $x['message_parent'] = $item['thr_parent']; $x['created'] = $item['created']; $x['edited'] = $item['edited']; // always send 0's over the wire $x['expires'] = $item['expires'] == '0001-01-01 00:00:00' ? '0000-00-00 00:00:00' : $item['expires']; $x['commented'] = $item['commented']; $x['mimetype'] = $item['mimetype']; $x['title'] = $item['title']; $x['body'] = $item['body']; $x['app'] = $item['app']; $x['verb'] = $item['verb']; $x['object_type'] = $item['obj_type']; $x['target_type'] = $item['tgt_type']; $x['permalink'] = $item['plink']; $x['location'] = $item['location']; $x['longlat'] = $item['coord']; $x['signature'] = $item['sig']; $x['route'] = $item['route']; $x['owner'] = encode_item_xchan($item['owner']); $x['author'] = encode_item_xchan($item['author']); if ($item['object']) { $x['object'] = json_decode_plus($item['object']); } if ($item['target']) { $x['target'] = json_decode_plus($item['target']); } if ($item['attach']) { $x['attach'] = json_decode_plus($item['attach']); } if ($y = encode_item_flags($item)) { $x['flags'] = $y; } if ($item['comments_closed'] !== NULL_DATE) { $x['comments_closed'] = $item['comments_closed']; } $x['public_scope'] = $scope; if ($item['item_flags'] & ITEM_NOCOMMENT) { $x['comment_scope'] = 'none'; } else { $x['comment_scope'] = $c_scope; } if ($item['term']) { $x['tags'] = encode_item_terms($item['term']); } if ($item['diaspora_meta']) { $x['diaspora_signature'] = crypto_unencapsulate(json_decode($item['diaspora_meta'], true), $key); } logger('encode_item: ' . print_r($x, true), LOGGER_DATA); return $x; }
function encode_item($item) { $x = array(); $x['type'] = 'activity'; $x['encoding'] = 'zot'; // logger('encode_item: ' . print_r($item,true)); $r = q("select channel_r_stream, channel_w_comment from channel where channel_id = %d limit 1", intval($item['uid'])); if ($r) { $comment_scope = $r[0]['channel_w_comment']; } else { $comment_scope = 0; } $scope = $item['public_policy']; if (!$scope) { $scope = 'public'; } $c_scope = map_scope($comment_scope); if (array_key_exists('item_flags', $item) && $item['item_flags'] & ITEM_OBSCURED) { $key = get_config('system', 'prvkey'); if ($item['title']) { $item['title'] = crypto_unencapsulate(json_decode_plus($item['title']), $key); } if ($item['body']) { $item['body'] = crypto_unencapsulate(json_decode_plus($item['body']), $key); } } $x['message_id'] = $item['mid']; $x['message_top'] = $item['parent_mid']; $x['message_parent'] = $item['thr_parent']; $x['created'] = $item['created']; $x['edited'] = $item['edited']; $x['expires'] = $item['expires']; $x['commented'] = $item['commented']; $x['mimetype'] = $item['mimetype']; $x['title'] = $item['title']; $x['body'] = $item['body']; $x['app'] = $item['app']; $x['verb'] = $item['verb']; $x['object_type'] = $item['obj_type']; $x['target_type'] = $item['tgt_type']; $x['permalink'] = $item['plink']; $x['location'] = $item['location']; $x['longlat'] = $item['coord']; $x['signature'] = $item['sig']; $x['route'] = $item['route']; $x['owner'] = encode_item_xchan($item['owner']); $x['author'] = encode_item_xchan($item['author']); if ($item['object']) { $x['object'] = json_decode_plus($item['object']); } if ($item['target']) { $x['target'] = json_decode_plus($item['target']); } if ($item['attach']) { $x['attach'] = json_decode_plus($item['attach']); } if ($y = encode_item_flags($item)) { $x['flags'] = $y; } if ($item['comments_closed'] !== NULL_DATE) { $x['comments_closed'] = $item['comments_closed']; } $x['public_scope'] = $scope; if ($item['item_flags'] & ITEM_NOCOMMENT) { $x['comment_scope'] = 'none'; } else { $x['comment_scope'] = $c_scope; } if ($item['term']) { $x['tags'] = encode_item_terms($item['term']); } logger('encode_item: ' . print_r($x, true), LOGGER_DATA); return $x; }