Example #1
0
function diaspora_asphoto($importer, $xml, $msg)
{
    // This call is believed to be obsolete since 2011-2012 and has not been ported
    // from the original Friendica implementation. The code remains in case it is
    // ever reimplemented in Diaspora, though it is unlikely that will occur in the
    // same context.
    logger('diaspora_asphoto called');
    $a = get_app();
    $guid = notags(unxmlify($xml['guid']));
    $diaspora_handle = notags(diaspora_get_author($xml));
    if ($diaspora_handle != $msg['author']) {
        logger('diaspora_post: Potential forgery. Message handle is not the same as envelope sender.');
        return 202;
    }
    $contact = diaspora_get_contact_by_handle($importer['channel_id'], $diaspora_handle);
    if (!$contact) {
        return;
    }
    if (!$importer['system'] && !perm_is_allowed($importer['channel_id'], $contact['xchan_hash'], 'send_stream')) {
        logger('diaspora_asphoto: Ignoring this author.');
        return 202;
    }
    $message_id = $diaspora_handle . ':' . $guid;
    $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `guid` = '%s' LIMIT 1", intval($importer['channel_id']), dbesc($message_id), dbesc($guid));
    if (count($r)) {
        logger('diaspora_asphoto: message exists: ' . $guid);
        return;
    }
    // allocate a guid on our system - we aren't fixing any collisions.
    // we're ignoring them
    $g = q("select * from guid where guid = '%s' limit 1", dbesc($guid));
    if (!count($g)) {
        q("insert into guid ( guid ) values ( '%s' )", dbesc($guid));
    }
    $created = unxmlify($xml['created_at']);
    $private = unxmlify($xml['public']) == 'false' ? 1 : 0;
    if (strlen($xml['objectId']) && $xml['objectId'] != 0 && $xml['image_url']) {
        $body = '[url=' . notags(unxmlify($xml['image_url'])) . '][img]' . notags(unxmlify($xml['objectId'])) . '[/img][/url]' . "\n";
        $body = scale_external_images($body, false);
    } elseif ($xml['image_url']) {
        $body = '[img]' . notags(unxmlify($xml['image_url'])) . '[/img]' . "\n";
        $body = scale_external_images($body);
    } else {
        logger('diaspora_asphoto: no photo url found.');
        return;
    }
    $plink = service_plink($contact, $guid);
    $datarray = array();
    $datarray['uid'] = $importer['channel_id'];
    $datarray['contact-id'] = $contact['id'];
    $datarray['wall'] = 0;
    $datarray['network'] = NETWORK_DIASPORA;
    $datarray['guid'] = $guid;
    $datarray['uri'] = $datarray['parent-uri'] = $message_id;
    $datarray['changed'] = $datarray['created'] = $datarray['edited'] = datetime_convert('UTC', 'UTC', $created);
    $datarray['private'] = $private;
    $datarray['parent'] = 0;
    $datarray['plink'] = $plink;
    $datarray['owner-name'] = $contact['name'];
    $datarray['owner-link'] = $contact['url'];
    //$datarray['owner-avatar'] = $contact['thumb'];
    $datarray['owner-avatar'] = x($contact, 'thumb') ? $contact['thumb'] : $contact['photo'];
    $datarray['author-name'] = $contact['name'];
    $datarray['author-link'] = $contact['url'];
    $datarray['author-avatar'] = $contact['thumb'];
    $datarray['body'] = $body;
    $datarray['app'] = 'Diaspora/Cubbi.es';
    $result = item_store($datarray);
    if ($result['success']) {
        sync_an_item($importer['channel_id'], $result['item_id']);
    }
    return;
}
Example #2
0
function diaspora_asphoto($importer, $xml, $msg)
{
    logger('diaspora_asphoto called');
    $a = get_app();
    $guid = notags(unxmlify($xml->guid));
    $diaspora_handle = notags(unxmlify($xml->diaspora_handle));
    if ($diaspora_handle != $msg['author']) {
        logger('diaspora_post: Potential forgery. Message handle is not the same as envelope sender.');
        return 202;
    }
    $contact = diaspora_get_contact_by_handle($importer['channel_id'], $diaspora_handle);
    if (!$contact) {
        return;
    }
    if (!$importer['system'] && !perm_is_allowed($importer['channel_id'], $contact['xchan_hash'], 'send_stream')) {
        logger('diaspora_asphoto: Ignoring this author.');
        return 202;
    }
    $message_id = $diaspora_handle . ':' . $guid;
    $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `guid` = '%s' LIMIT 1", intval($importer['channel_id']), dbesc($message_id), dbesc($guid));
    if (count($r)) {
        logger('diaspora_asphoto: message exists: ' . $guid);
        return;
    }
    // allocate a guid on our system - we aren't fixing any collisions.
    // we're ignoring them
    $g = q("select * from guid where guid = '%s' limit 1", dbesc($guid));
    if (!count($g)) {
        q("insert into guid ( guid ) values ( '%s' )", dbesc($guid));
    }
    $created = unxmlify($xml->created_at);
    $private = unxmlify($xml->public) == 'false' ? 1 : 0;
    if (strlen($xml->objectId) && $xml->objectId != 0 && $xml->image_url) {
        $body = '[url=' . notags(unxmlify($xml->image_url)) . '][img]' . notags(unxmlify($xml->objectId)) . '[/img][/url]' . "\n";
        $body = scale_external_images($body, false);
    } elseif ($xml->image_url) {
        $body = '[img]' . notags(unxmlify($xml->image_url)) . '[/img]' . "\n";
        $body = scale_external_images($body);
    } else {
        logger('diaspora_asphoto: no photo url found.');
        return;
    }
    $plink = service_plink($contact, $guid);
    $datarray = array();
    $datarray['uid'] = $importer['channel_id'];
    $datarray['contact-id'] = $contact['id'];
    $datarray['wall'] = 0;
    $datarray['network'] = NETWORK_DIASPORA;
    $datarray['guid'] = $guid;
    $datarray['uri'] = $datarray['parent-uri'] = $message_id;
    $datarray['changed'] = $datarray['created'] = $datarray['edited'] = datetime_convert('UTC', 'UTC', $created);
    $datarray['private'] = $private;
    $datarray['parent'] = 0;
    $datarray['plink'] = $plink;
    $datarray['owner-name'] = $contact['name'];
    $datarray['owner-link'] = $contact['url'];
    //$datarray['owner-avatar'] = $contact['thumb'];
    $datarray['owner-avatar'] = x($contact, 'thumb') ? $contact['thumb'] : $contact['photo'];
    $datarray['author-name'] = $contact['name'];
    $datarray['author-link'] = $contact['url'];
    $datarray['author-avatar'] = $contact['thumb'];
    $datarray['body'] = $body;
    $datarray['app'] = 'Diaspora/Cubbi.es';
    $message_id = item_store($datarray);
    //if($message_id) {
    //	q("update item set plink = '%s' where id = %d",
    //		dbesc($a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id),
    //		intval($message_id)
    //	);
    //}
    return;
}
Example #3
0
function diaspora_reshare($importer, $xml, $msg)
{
    logger('diaspora_reshare: init: ' . print_r($xml, true), LOGGER_DATA);
    $a = get_app();
    $guid = notags(unxmlify($xml['guid']));
    $diaspora_handle = notags(diaspora_get_author($xml));
    if ($diaspora_handle != $msg['author']) {
        logger('Potential forgery. Message handle is not the same as envelope sender.');
        return 202;
    }
    $contact = diaspora_get_contact_by_handle($importer['channel_id'], $diaspora_handle);
    if (!$contact) {
        return;
    }
    $search_guid = strlen($guid) == 64 ? $guid . '%' : $guid;
    $r = q("SELECT id FROM item WHERE uid = %d AND mid like '%s' LIMIT 1", intval($importer['channel_id']), dbesc($search_guid));
    if ($r) {
        logger('diaspora_reshare: message exists: ' . $guid);
        return;
    }
    $orig_author = notags(diaspora_get_root_author($xml));
    $orig_guid = notags(unxmlify($xml['root_guid']));
    $source_url = 'https://' . substr($orig_author, strpos($orig_author, '@') + 1) . '/p/' . $orig_guid . '.xml';
    $orig_url = 'https://' . substr($orig_author, strpos($orig_author, '@') + 1) . '/posts/' . $orig_guid;
    $source_xml = get_diaspora_reshare_xml($source_url);
    if ($source_xml['status_message']) {
        $body = diaspora2bb(diaspora_get_body($source_xml['status_message']));
        $orig_author = diaspora_get_author($source_xml['status_message']);
        $orig_guid = notags(unxmlify($source_xml['status_message']['guid']));
        // Checking for embedded pictures
        if ($source_xml['status_message']['photo']['remote_photo_path'] && $source_xml['status_message']['photo']['remote_photo_name']) {
            $remote_photo_path = notags(unxmlify($source_xml['status_message']['photo']['remote_photo_path']));
            $remote_photo_name = notags(unxmlify($source_xml['status_message']['photo']['remote_photo_name']));
            $body = '[img]' . $remote_photo_path . $remote_photo_name . '[/img]' . "\n" . $body;
            logger('diaspora_reshare: embedded picture link found: ' . $body, LOGGER_DEBUG);
        }
        $body = scale_external_images($body);
        // Add OEmbed and other information to the body
        //		$body = add_page_info_to_body($body, false, true);
    } else {
        // Maybe it is a reshare of a photo that will be delivered at a later time (testing)
        logger('diaspora_reshare: no reshare content found: ' . print_r($source_xml, true));
        $body = "";
        //return;
    }
    $maxlen = get_max_import_size();
    if ($maxlen && mb_strlen($body) > $maxlen) {
        $body = mb_substr($body, 0, $maxlen, 'UTF-8');
        logger('message length exceeds max_import_size: truncated');
    }
    $person = find_diaspora_person_by_handle($orig_author);
    if ($person) {
        $orig_author_name = $person['xchan_name'];
        $orig_author_link = $person['xchan_url'];
        $orig_author_photo = $person['xchan_photo_m'];
    }
    $created = unxmlify($xml['created_at']);
    $private = unxmlify($xml['public']) == 'false' ? 1 : 0;
    $datarray = array();
    // Look for tags and linkify them
    $results = linkify_tags(get_app(), $body, $importer['channel_id'], true);
    $datarray['term'] = array();
    if ($results) {
        foreach ($results as $result) {
            $success = $result['success'];
            if ($success['replaced']) {
                $datarray['term'][] = array('uid' => $importer['channel_id'], 'ttype' => $success['termtype'], 'otype' => TERM_OBJ_POST, 'term' => $success['term'], 'url' => $success['url']);
            }
        }
    }
    $cnt = preg_match_all('/@\\[url=(.*?)\\](.*?)\\[\\/url\\]/ism', $body, $matches, PREG_SET_ORDER);
    if ($cnt) {
        foreach ($matches as $mtch) {
            $datarray['term'][] = array('uid' => $importer['channel_id'], 'ttype' => TERM_MENTION, 'otype' => TERM_OBJ_POST, 'term' => $mtch[2], 'url' => $mtch[1]);
        }
    }
    $cnt = preg_match_all('/@\\[zrl=(.*?)\\](.*?)\\[\\/zrl\\]/ism', $body, $matches, PREG_SET_ORDER);
    if ($cnt) {
        foreach ($matches as $mtch) {
            // don't include plustags in the term
            $term = substr($mtch[2], -1, 1) === '+' ? substr($mtch[2], 0, -1) : $mtch[2];
            $datarray['term'][] = array('uid' => $importer['channel_id'], 'ttype' => TERM_MENTION, 'otype' => TERM_OBJ_POST, 'term' => $term, 'url' => $mtch[1]);
        }
    }
    $newbody = "[share author='" . urlencode($orig_author_name) . "' profile='" . $orig_author_link . "' avatar='" . $orig_author_photo . "' link='" . $orig_url . "' posted='" . datetime_convert('UTC', 'UTC', unxmlify($source_xml['status_message']['created_at'])) . "' message_id='" . unxmlify($source_xml['status_message']['guid']) . "']" . $body . "[/share]";
    $plink = service_plink($contact, $guid);
    $datarray['aid'] = $importer['channel_account_id'];
    $datarray['uid'] = $importer['channel_id'];
    $datarray['mid'] = $datarray['parent_mid'] = $guid;
    $datarray['changed'] = $datarray['created'] = $datarray['edited'] = datetime_convert('UTC', 'UTC', $created);
    $datarray['item_private'] = $private;
    $datarray['plink'] = $plink;
    $datarray['owner_xchan'] = $contact['xchan_hash'];
    $datarray['author_xchan'] = $contact['xchan_hash'];
    $datarray['body'] = $newbody;
    $datarray['app'] = 'Diaspora';
    $tgroup = tgroup_check($importer['channel_id'], $datarray);
    if (!$importer['system'] && !perm_is_allowed($importer['channel_id'], $contact['xchan_hash'], 'send_stream') && !$tgroup) {
        logger('diaspora_reshare: Ignoring this author.');
        return 202;
    }
    if (!post_is_importable($datarray, $contact)) {
        logger('diaspora_reshare: filtering this author.');
        return 202;
    }
    $result = item_store($datarray);
    if ($result['success']) {
        sync_an_item($importer['channel_id'], $result['item_id']);
    }
    return;
}