function bb2diaspora_itembody($item, $force_update = false, $have_channel = false)
{
    if (!get_iconfig($item, 'diaspora', 'fields')) {
        $force_update = true;
    }
    $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) : '';
        }
    }
    if (!$have_channel) {
        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('⋕', ENT_COMPAT, 'UTF-8');
        $new_mention = html_entity_decode('@', 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);
}
示例#2
0
function diaspora_send_downstream($item, $owner, $contact, $public_batch = false)
{
    $a = get_app();
    $myaddr = $owner['channel_address'] . '@' . App::get_hostname();
    $text = bb2diaspora_itembody($item);
    $body = $text;
    // Diaspora doesn't support threaded comments, but some
    // versions of Diaspora (i.e. Diaspora-pistos) support
    // likes on comments
    // That version is now dead so detect a "sublike" and
    // just send it as an activity.
    $sublike = false;
    if ($item['verb'] === ACTIVITY_LIKE) {
        if ($item['thr_parent'] && $item['thr_parent'] !== $item['parent_mid']) {
            $sublike = true;
        }
    }
    // The first item in the `item` table with the parent id is the parent. However, MySQL doesn't always
    // return the items ordered by `item`.`id`, in which case the wrong item is chosen as the parent.
    // The only item with `parent` and `id` as the parent id is the parent item.
    $p = q("select * from item where parent = %d and id = %d limit 1", intval($item['parent']), intval($item['parent']));
    if ($p) {
        $parent = $p[0];
    } else {
        logger('diaspora_send_downstream: no parent');
        return;
    }
    $xmlout = diaspora_fields_to_xml(get_iconfig($item, 'diaspora', 'fields'));
    $like = false;
    $relay_retract = false;
    $sql_sign_id = 'iid';
    if (intval($item['item_deleted'])) {
        $relay_retract = true;
        $target_type = $item['verb'] === ACTIVITY_LIKE && !$sublike ? 'Like' : 'Comment';
        $sql_sign_id = 'retract_iid';
        $tpl = get_markup_template('diaspora_relayable_retraction.tpl', 'addon/diaspora');
    } elseif ($item['verb'] === ACTIVITY_LIKE && !$sublike && $xmlout) {
        $like = true;
        $target_type = $parent['mid'] === $parent['parent_mid'] ? 'Post' : 'Comment';
        //		$positive = (intval($item['item_deleted']) ? 'false' : 'true');
        $positive = 'true';
        $tpl = get_markup_template('diaspora_like_relay.tpl', 'addon/diaspora');
    } else {
        // item is a comment
        $tpl = get_markup_template('diaspora_comment_relay.tpl', 'addon/diaspora');
    }
    $diaspora_meta = $item['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;
        }
        $sender_signed_text = $meta['signed_text'];
        $authorsig = $meta['signature'];
        $handle = $meta['signer'];
        $text = $meta['body'];
    } else {
        logger('diaspora_send_downstream: original author signature not found');
    }
    /* Since the author signature is only checked by the parent, not by the relay recipients,
     * I think it may not be necessary for us to do so much work to preserve all the original
     * signatures. The important thing that Diaspora DOES need is the original creator's handle.
     * Let's just generate that and forget about all the original author signature stuff.
     *
     * Note: this might be more of an problem if we want to support likes on comments for older
     * versions of Diaspora (diaspora-pistos), but since there are a number of problems with
     * doing that, let's ignore it for now.
     *
     *
     */
    // bug - nomadic identity may/will affect diaspora_handle_from_contact
    if (!$handle) {
        $handle = $owner['channel_address'] . '@' . App::get_hostname();
    }
    if (!$sender_signed_text) {
        if ($relay_retract) {
            $sender_signed_text = $item['mid'] . ';' . $target_type;
        } elseif ($like) {
            $sender_signed_text = $positive . ';' . $item['mid'] . ';' . $target_type . ';' . $parent['mid'] . ';' . $handle;
        } else {
            $sender_signed_text = $item['mid'] . ';' . $parent['mid'] . ';' . $text . ';' . $handle;
        }
    }
    // The relayable may have arrived from somebody who provided no Diaspora Comment Virus.
    // We check for this above in bb2diaspora_itembody. In that case we will have generated
    // the body as a "wall-to-wall" post, and the author_signature will now be our own.
    if (!$xmlout && !$authorsig) {
        $authorsig = base64_encode(rsa_sign($sender_signed_text, $owner['channel_prvkey'], 'sha256'));
    }
    // Sign the relayable with the top-level owner's signature
    $parentauthorsig = base64_encode(rsa_sign($sender_signed_text, $owner['channel_prvkey'], 'sha256'));
    if (!$text) {
        logger('diaspora_send_downstream: no text');
    }
    $msg = replace_macros($tpl, array('$xml' => $xmlout, '$guid' => xmlify($item['mid']), '$parent_guid' => xmlify($parent['mid']), '$target_type' => xmlify($target_type), '$authorsig' => xmlify($authorsig), '$parentsig' => xmlify($parentauthorsig), '$body' => xmlify($text), '$positive' => xmlify($positive), '$handle' => xmlify($handle)));
    logger('diaspora_send_downstream: base message: ' . $msg, LOGGER_DATA);
    $slap = 'xml=' . urlencode(urlencode(diaspora_msg_build($msg, $owner, $contact, $owner['channel_prvkey'], $contact['xchan_pubkey'], $public_batch)));
    return diaspora_queue($owner, $contact, $slap, $public_batch, $item['mid']);
}
示例#3
0
function wiki_get_wiki($resource_id)
{
    $item = q("SELECT * FROM item WHERE resource_type = '%s' AND resource_id = '%s' AND item_deleted = 0 limit 1", dbesc(WIKI_ITEM_RESOURCE_TYPE), dbesc($resource_id));
    if (!$item) {
        return array('wiki' => null, 'path' => null);
    } else {
        $w = $item[0];
        // wiki item table record
        // Get wiki metadata
        $rawName = get_iconfig($w, 'wiki', 'rawName');
        $htmlName = get_iconfig($w, 'wiki', 'htmlName');
        $urlName = get_iconfig($w, 'wiki', 'urlName');
        $path = get_iconfig($w, 'wiki', 'path');
        if (!realpath(__DIR__ . '/../' . $path)) {
            return array('wiki' => null, 'path' => null);
        }
        // Path to wiki exists
        $abs_path = realpath(__DIR__ . '/../' . $path);
        return array('wiki' => $w, 'path' => $abs_path, 'rawName' => $rawName, 'htmlName' => $htmlName, 'urlName' => $urlName);
    }
}