Ejemplo n.º 1
0
function atom_entry($item, $type, $author, $owner, $comment = false, $cid = 0)
{
    if (!$item['parent']) {
        return;
    }
    if ($item['deleted']) {
        return '<at:deleted-entry ref="' . xmlify($item['mid']) . '" when="' . xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00', ATOM_TIME)) . '" />' . "\r\n";
    }
    create_export_photo_body($item);
    if ($item['allow_cid'] || $item['allow_gid'] || $item['deny_cid'] || $item['deny_gid']) {
        $body = fix_private_photos($item['body'], $owner['uid'], $item, $cid);
    } else {
        $body = $item['body'];
    }
    $o = "\r\n\r\n<entry>\r\n";
    if (is_array($author)) {
        $o .= atom_author('author', $author['xchan_name'], $author['xchan_url'], 80, 80, $author['xchan_photo_mimetype'], $author['xchan_photo_m']);
    } else {
        $o .= atom_author('author', $item['author']['xchan_name'], $item['author']['xchan_url'], 80, 80, $item['author']['xchan_photo_mimetype'], $item['author']['xchan_photo_m']);
    }
    $o .= atom_author('zot:owner', $item['owner']['xchan_name'], $item['owner']['xchan_url'], 80, 80, $item['owner']['xchan_photo_mimetype'], $item['owner']['xchan_photo_m']);
    if ($item['parent'] != $item['id'] || $item['parent_mid'] !== $item['mid'] || $item['thr_parent'] !== '' && $item['thr_parent'] !== $item['mid']) {
        $parent_item = $item['thr_parent'] ? $item['thr_parent'] : $item['parent_mid'];
        $o .= '<thr:in-reply-to ref="' . xmlify($parent_item) . '" type="text/html" href="' . xmlify($item['plink']) . '" />' . "\r\n";
    }
    $o .= '<id>' . xmlify($item['mid']) . '</id>' . "\r\n";
    $o .= '<title>' . xmlify($item['title']) . '</title>' . "\r\n";
    $o .= '<published>' . xmlify(datetime_convert('UTC', 'UTC', $item['created'] . '+00:00', ATOM_TIME)) . '</published>' . "\r\n";
    $o .= '<updated>' . xmlify(datetime_convert('UTC', 'UTC', $item['edited'] . '+00:00', ATOM_TIME)) . '</updated>' . "\r\n";
    $o .= '<content type="' . $type . '" >' . xmlify(prepare_text($body, $item['mimetype'])) . '</content>' . "\r\n";
    $o .= '<link rel="alternate" type="text/html" href="' . xmlify($item['plink']) . '" />' . "\r\n";
    if ($item['location']) {
        $o .= '<zot:location>' . xmlify($item['location']) . '</zot:location>' . "\r\n";
        $o .= '<poco:address><poco:formatted>' . xmlify($item['location']) . '</poco:formatted></poco:address>' . "\r\n";
    }
    if ($item['coord']) {
        $o .= '<georss:point>' . xmlify($item['coord']) . '</georss:point>' . "\r\n";
    }
    if ($item['item_private'] || strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])) {
        $o .= '<zot:private>' . ($item['item_private'] ? $item['item_private'] : 1) . '</zot:private>' . "\r\n";
    }
    if ($item['app']) {
        $o .= '<statusnet:notice_info local_id="' . $item['id'] . '" source="' . xmlify($item['app']) . '" ></statusnet:notice_info>' . "\r\n";
    }
    $verb = construct_verb($item);
    $o .= '<as:verb>' . xmlify($verb) . '</as:verb>' . "\r\n";
    $actobj = construct_activity_object($item);
    if (strlen($actobj)) {
        $o .= $actobj;
    }
    $actarg = construct_activity_target($item);
    if (strlen($actarg)) {
        $o .= $actarg;
    }
    // FIXME
    //	$tags = item_getfeedtags($item);
    //	if(count($tags)) {
    //		foreach($tags as $t) {
    //			$o .= '<category scheme="X-DFRN:' . xmlify($t[0]) . ':' . xmlify($t[1]) . '" term="' . xmlify($t[2]) . '" />' . "\r\n";
    //		}
    //	}
    // FIXME
    //	$o .= item_getfeedattach($item);
    //	$mentioned = get_mentions($item,$tags);
    //	if($mentioned)
    //		$o .= $mentioned;
    call_hooks('atom_entry', $o);
    $o .= '</entry>' . "\r\n";
    return $o;
}
Ejemplo n.º 2
0
function bb2diaspora_itembody($item, $force_update = false)
{
    $matches = array();
    if ($item['diaspora_meta'] && !$force_update) {
        $diaspora_meta = json_decode($item['diaspora_meta'], true);
        if ($diaspora_meta) {
            if (array_key_exists('iv', $diaspora_meta)) {
                $key = get_config('system', 'prvkey');
                $meta = json_decode(crypto_unencapsulate($diaspora_meta, $key), true);
            } else {
                $meta = $diaspora_meta;
            }
            if ($meta) {
                logger('bb2diaspora_itembody: cached ');
                $newitem = $item;
                $newitem['body'] = $meta['body'];
                return $newitem['body'];
            }
        }
    }
    create_export_photo_body($item);
    $newitem = $item;
    if (array_key_exists('item_obscured', $item) && intval($item['item_obscured'])) {
        $key = get_config('system', 'prvkey');
        $b = json_decode($item['body'], true);
        // if called from diaspora_process_outbound, this decoding has already been done.
        // Everything else that calls us will not yet be decoded.
        if ($b && is_array($b) && array_key_exists('iv', $b)) {
            $newitem['title'] = $item['title'] ? crypto_unencapsulate(json_decode($item['title'], true), $key) : '';
            $newitem['body'] = $item['body'] ? crypto_unencapsulate(json_decode($item['body'], true), $key) : '';
        }
    }
    bb2diaspora_itemwallwall($newitem);
    $title = $newitem['title'];
    $body = preg_replace('/\\#\\^http/i', 'http', $newitem['body']);
    // protect tags and mentions from hijacking
    if (intval(get_pconfig($item['uid'], 'system', 'prevent_tag_hijacking'))) {
        $new_tag = html_entity_decode('&#x22d5;', ENT_COMPAT, 'UTF-8');
        $new_mention = html_entity_decode('&#xff20;', ENT_COMPAT, 'UTF-8');
        // #-tags
        $body = preg_replace('/\\#\\[url/i', $new_tag . '[url', $body);
        $body = preg_replace('/\\#\\[zrl/i', $new_tag . '[zrl', $body);
        // @-mentions
        $body = preg_replace('/\\@\\!?\\[url/i', $new_mention . '[url', $body);
        $body = preg_replace('/\\@\\!?\\[zrl/i', $new_mention . '[zrl', $body);
    }
    // remove multiple newlines
    do {
        $oldbody = $body;
        $body = str_replace("\n\n\n", "\n\n", $body);
    } while ($oldbody != $body);
    $body = bb2diaspora($body);
    if (strlen($title)) {
        $body = "## " . $title . "\n\n" . $body;
    }
    if ($item['attach']) {
        $cnt = preg_match_all('/href=\\"(.*?)\\"(.*?)title=\\"(.*?)\\"/ism', $item['attach'], $matches, PREG_SET_ORDER);
        if ($cnt) {
            $body .= "\n" . t('Attachments:') . "\n";
            foreach ($matches as $mtch) {
                $body .= '[' . $mtch[3] . '](' . $mtch[1] . ')' . "\n";
            }
        }
    }
    //	logger('bb2diaspora_itembody : ' . $body, LOGGER_DATA);
    return html_entity_decode($body);
}