Пример #1
0
function diaspora_profile($importer, $xml, $msg)
{
    $a = get_app();
    $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['uid'], $diaspora_handle);
    if (!$contact) {
        return;
    }
    if ($contact['blocked']) {
        logger('diaspora_post: Ignoring this author.');
        return 202;
    }
    $name = unxmlify($xml->first_name) . (strlen($xml->last_name) ? ' ' . unxmlify($xml->last_name) : '');
    $image_url = unxmlify($xml->image_url);
    $birthday = unxmlify($xml->birthday);
    $location = diaspora2bb(unxmlify($xml->location));
    $about = diaspora2bb(unxmlify($xml->bio));
    $gender = unxmlify($xml->gender);
    $tags = unxmlify($xml->tag_string);
    $tags = explode("#", $tags);
    $keywords = array();
    foreach ($tags as $tag) {
        $tag = trim(strtolower($tag));
        if ($tag != "") {
            $keywords[] = $tag;
        }
    }
    $keywords = implode(", ", $keywords);
    $handle_parts = explode("@", $diaspora_handle);
    if ($name === '') {
        $name = $handle_parts[0];
    }
    if (preg_match("|^https?://|", $image_url) === 0) {
        $image_url = "http://" . $handle_parts[1] . $image_url;
    }
    /*	$r = q("SELECT DISTINCT ( `resource-id` ) FROM `photo` WHERE  `uid` = %d AND `contact-id` = %d AND `album` = 'Contact Photos' ",
    		intval($importer['uid']),
    		intval($contact['id'])
    	);
    	$oldphotos = ((count($r)) ? $r : null);*/
    require_once 'include/Photo.php';
    $images = import_profile_photo($image_url, $importer['uid'], $contact['id']);
    // Generic birthday. We don't know the timezone. The year is irrelevant.
    $birthday = str_replace('1000', '1901', $birthday);
    $birthday = datetime_convert('UTC', 'UTC', $birthday, 'Y-m-d');
    // this is to prevent multiple birthday notifications in a single year
    // if we already have a stored birthday and the 'm-d' part hasn't changed, preserve the entry, which will preserve the notify year
    if (substr($birthday, 5) === substr($contact['bd'], 5)) {
        $birthday = $contact['bd'];
    }
    // TODO: update name on item['author-name'] if the name changed. See consume_feed()
    // Not doing this currently because D* protocol is scheduled for revision soon.
    $r = q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' , `bd` = '%s', `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `id` = %d AND `uid` = %d", dbesc($name), dbesc(datetime_convert()), dbesc($images[0]), dbesc($images[1]), dbesc($images[2]), dbesc(datetime_convert()), dbesc($birthday), dbesc($location), dbesc($about), dbesc($keywords), dbesc($gender), intval($contact['id']), intval($importer['uid']));
    if (unxmlify($xml->searchable) == "true") {
        require_once 'include/socgraph.php';
        poco_check($contact['url'], $name, NETWORK_DIASPORA, $images[0], $about, $location, $gender, $keywords, "", datetime_convert(), 2, $contact['id'], $importer['uid']);
    }
    $profileurl = "";
    $author = q("SELECT * FROM `unique_contacts` WHERE `url`='%s' LIMIT 1", dbesc(normalise_link($contact['url'])));
    if (count($author) == 0) {
        q("INSERT INTO `unique_contacts` (`url`, `name`, `avatar`, `location`, `about`) VALUES ('%s', '%s', '%s', '%s', '%s')", dbesc(normalise_link($contact['url'])), dbesc($name), dbesc($location), dbesc($about), dbesc($images[0]));
        $author = q("SELECT id FROM unique_contacts WHERE url='%s' LIMIT 1", dbesc(normalise_link($contact['url'])));
    } else {
        if (normalise_link($contact['url']) . $name . $location . $about != normalise_link($author[0]["url"]) . $author[0]["name"] . $author[0]["location"] . $author[0]["about"]) {
            q("UPDATE unique_contacts SET name = '%s', avatar = '%s', `location` = '%s', `about` = '%s' WHERE url = '%s'", dbesc($name), dbesc($images[0]), dbesc($location), dbesc($about), dbesc(normalise_link($contact['url'])));
        }
    }
    /*	if($r) {
    		if($oldphotos) {
    			foreach($oldphotos as $ph) {
    				q("DELETE FROM `photo` WHERE `uid` = %d AND `contact-id` = %d AND `album` = 'Contact Photos' AND `resource-id` = '%s' ",
    					intval($importer['uid']),
    					intval($contact['id']),
    					dbesc($ph['resource-id'])
    				);
    			}
    		}
    	}	*/
    return;
}
Пример #2
0
function diaspora_profile($importer, $xml)
{
    $a = get_app();
    $diaspora_handle = notags(unxmlify($xml->diaspora_handle));
    $contact = diaspora_get_contact_by_handle($importer['uid'], $diaspora_handle);
    if (!$contact) {
        return;
    }
    if ($contact['blocked']) {
        logger('diaspora_post: Ignoring this author.');
        return 202;
    }
    $name = unxmlify($xml->first_name) . (strlen($xml->last_name) ? ' ' . unxmlify($xml->last_name) : '');
    $image_url = unxmlify($xml->image_url);
    $birthday = unxmlify($xml->birthday);
    $r = q("SELECT DISTINCT ( `resource-id` ) FROM `photo` WHERE  `uid` = %d AND `contact-id` = %d AND `album` = 'Contact Photos' ", intval($importer['uid']), intval($contact['id']));
    $oldphotos = count($r) ? $r : null;
    require_once 'include/Photo.php';
    $images = import_profile_photo($image_url, $importer['uid'], $contact['id']);
    // Generic birthday. We don't know the timezone. The year is irrelevant.
    $birthday = str_replace('1000', '1901', $birthday);
    $birthday = datetime_convert('UTC', 'UTC', $birthday, 'Y-m-d');
    // this is to prevent multiple birthday notifications in a single year
    // if we already have a stored birthday and the 'm-d' part hasn't changed, preserve the entry, which will preserve the notify year
    if (substr($birthday, 5) === substr($contact['bd'], 5)) {
        $birthday = $contact['bd'];
    }
    $r = q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' , `bd` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1", dbesc($name), dbesc(datetime_convert()), dbesc($images[0]), dbesc($images[1]), dbesc($images[2]), dbesc(datetime_convert()), dbesc($birthday), intval($contact['id']), intval($importer['uid']));
    if ($r) {
        if ($oldphotos) {
            foreach ($oldphotos as $ph) {
                q("DELETE FROM `photo` WHERE `uid` = %d AND `contact-id` = %d AND `album` = 'Contact Photos' AND `resource-id` = '%s' ", intval($importer['uid']), intval($contact['id']), dbesc($ph['resource-id']));
            }
        }
    }
    return;
}
Пример #3
0
function diaspora_profile($importer, $xml, $msg)
{
    $a = get_app();
    $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 ($contact['blocked']) {
        logger('diaspora_post: Ignoring this author.');
        return 202;
    }
    $name = unxmlify($xml->first_name) . (strlen($xml->last_name) ? ' ' . unxmlify($xml->last_name) : '');
    $image_url = unxmlify($xml->image_url);
    $birthday = unxmlify($xml->birthday);
    $handle_parts = explode("@", $diaspora_handle);
    if ($name === '') {
        $name = $handle_parts[0];
    }
    if (preg_match("|^https?://|", $image_url) === 0) {
        $image_url = "http://" . $handle_parts[1] . $image_url;
    }
    /*	$r = q("SELECT DISTINCT ( `resource-id` ) FROM `photo` WHERE  `uid` = %d AND `contact-id` = %d AND `album` = 'Contact Photos' ",
    		intval($importer['channel_id']),
    		intval($contact['id'])
    	);
    	$oldphotos = ((count($r)) ? $r : null);*/
    require_once 'include/Photo.php';
    $images = import_profile_photo($image_url, $importer['channel_id'], $contact['id']);
    // Generic birthday. We don't know the timezone. The year is irrelevant.
    $birthday = str_replace('1000', '1901', $birthday);
    $birthday = datetime_convert('UTC', 'UTC', $birthday, 'Y-m-d');
    // this is to prevent multiple birthday notifications in a single year
    // if we already have a stored birthday and the 'm-d' part hasn't changed, preserve the entry, which will preserve the notify year
    if (substr($birthday, 5) === substr($contact['bd'], 5)) {
        $birthday = $contact['bd'];
    }
    // TODO: update name on item['author-name'] if the name changed. See consume_feed()
    // Not doing this currently because D* protocol is scheduled for revision soon.
    $r = q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' , `bd` = '%s' WHERE `id` = %d AND `uid` = %d", dbesc($name), dbesc(datetime_convert()), dbesc($images[0]), dbesc($images[1]), dbesc($images[2]), dbesc(datetime_convert()), dbesc($birthday), intval($contact['id']), intval($importer['channel_id']));
    /*	if($r) {
    		if($oldphotos) {
    			foreach($oldphotos as $ph) {
    				q("DELETE FROM `photo` WHERE `uid` = %d AND `contact-id` = %d AND `album` = 'Contact Photos' AND `resource-id` = '%s' ",
    					intval($importer['channel_id']),
    					intval($contact['id']),
    					dbesc($ph['resource-id'])
    				);
    			}
    		}
    	}	*/
    return;
}
Пример #4
0
function diaspora_profile($importer, $xml, $msg)
{
    $a = get_app();
    $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 ($contact['blocked']) {
        logger('diaspora_post: Ignoring this author.');
        return 202;
    }
    $name = unxmlify($xml->first_name) . (strlen($xml->last_name) ? ' ' . unxmlify($xml->last_name) : '');
    $image_url = unxmlify($xml->image_url);
    $birthday = unxmlify($xml->birthday);
    $handle_parts = explode("@", $diaspora_handle);
    if ($name === '') {
        $name = $handle_parts[0];
    }
    if (preg_match("|^https?://|", $image_url) === 0) {
        $image_url = "http://" . $handle_parts[1] . $image_url;
    }
    require_once 'include/photo/photo_driver.php';
    $images = import_profile_photo($image_url, $contact['xchan_hash']);
    // Generic birthday. We don't know the timezone. The year is irrelevant.
    $birthday = str_replace('1000', '1901', $birthday);
    $birthday = datetime_convert('UTC', 'UTC', $birthday, 'Y-m-d');
    // this is to prevent multiple birthday notifications in a single year
    // if we already have a stored birthday and the 'm-d' part hasn't changed, preserve the entry, which will preserve the notify year
    if (substr($birthday, 5) === substr($contact['bd'], 5)) {
        $birthday = $contact['bd'];
    }
    $r = q("update xchan set xchan_name = '%s', xchan_name_date = '%s', xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s' where xchan_hash = '%s' ", dbesc($name), dbesc(datetime_convert()), dbesc($images[0]), dbesc($images[1]), dbesc($images[2]), dbesc($images[3]), dbesc(datetime_convert()), intval($contact['xchan_hash']));
    return;
}