Merge pull request #1055 from annando/master

Working with GUID and Object-Type - bugfix for API
This commit is contained in:
Tobias Diekershoff 2014-07-24 08:40:29 +02:00
commit 1940905454
18 changed files with 252 additions and 165 deletions

View file

@ -120,7 +120,7 @@ function scrape_meta($url) {
$s = fetch_url($url);
if(! $s)
if(! $s)
return $ret;
$headers = $a->get_curl_headers();
@ -128,7 +128,7 @@ function scrape_meta($url) {
$lines = explode("\n",$headers);
if(count($lines)) {
foreach($lines as $line) {
foreach($lines as $line) {
// don't try and run feeds through the html5 parser
if(stristr($line,'content-type:') && ((stristr($line,'application/atom+xml')) || (stristr($line,'application/rss+xml'))))
return ret;
@ -169,13 +169,13 @@ function scrape_vcard($url) {
$s = fetch_url($url);
if(! $s)
if(! $s)
return $ret;
$headers = $a->get_curl_headers();
$lines = explode("\n",$headers);
if(count($lines)) {
foreach($lines as $line) {
foreach($lines as $line) {
// don't try and run feeds through the html5 parser
if(stristr($line,'content-type:') && ((stristr($line,'application/atom+xml')) || (stristr($line,'application/rss+xml'))))
return ret;
@ -236,14 +236,14 @@ function scrape_feed($url) {
logger('scrape_feed: returns: ' . $code . ' headers=' . $headers, LOGGER_DEBUG);
if(! $s) {
logger('scrape_feed: no data returned for ' . $url);
logger('scrape_feed: no data returned for ' . $url);
return $ret;
}
$lines = explode("\n",$headers);
if(count($lines)) {
foreach($lines as $line) {
foreach($lines as $line) {
if(stristr($line,'content-type:')) {
if(stristr($line,'application/atom+xml') || stristr($s,'<feed')) {
$ret['feed_atom'] = $url;
@ -299,7 +299,7 @@ function scrape_feed($url) {
if(! x($ret,'feed_rss'))
$ret['feed_rss'] = $item->getAttribute('href');
}
}
}
}
// Drupal and perhaps others only provide relative URL's. Turn them into absolute.
@ -617,7 +617,7 @@ function probe_url($url, $mode = PROBE_NORMAL) {
if(x($feedret,'photo') && (! x($vcard,'photo')))
$vcard['photo'] = $feedret['photo'];
require_once('library/simplepie/simplepie.inc');
$feed = new SimplePie();
$feed = new SimplePie();
$xml = fetch_url($poll);
logger('probe_url: fetch feed: ' . $poll . ' returns: ' . $xml, LOGGER_DATA);
@ -628,7 +628,7 @@ function probe_url($url, $mode = PROBE_NORMAL) {
// Don't try and parse an empty string
$feed->set_raw_data(($xml) ? $xml : '<?xml version="1.0" encoding="utf-8" ?><xml></xml>');
$feed->init();
$feed->init();
if($feed->error())
logger('probe_url: scrape_feed: Error parsing XML: ' . $feed->error());
@ -637,7 +637,7 @@ function probe_url($url, $mode = PROBE_NORMAL) {
$vcard['photo'] = $feed->get_image_url();
$author = $feed->get_author();
if($author) {
if($author) {
$vcard['fn'] = unxmlify(trim($author->get_name()));
if(! $vcard['fn'])
$vcard['fn'] = trim(unxmlify($author->get_email()));
@ -648,18 +648,18 @@ function probe_url($url, $mode = PROBE_NORMAL) {
$profile = trim(unxmlify($author->get_link()));
if(! $vcard['photo']) {
$rawtags = $feed->get_feed_tags( SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
if($rawtags) {
if($rawtags) {
$elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10];
if((x($elems,'link')) && ($elems['link'][0]['attribs']['']['rel'] === 'photo'))
$vcard['photo'] = $elems['link'][0]['attribs']['']['href'];
}
}
}
}
else {
$item = $feed->get_item(0);
if($item) {
$author = $item->get_author();
if($author) {
if($author) {
$vcard['fn'] = trim(unxmlify($author->get_name()));
if(! $vcard['fn'])
$vcard['fn'] = trim(unxmlify($author->get_email()));
@ -676,11 +676,11 @@ function probe_url($url, $mode = PROBE_NORMAL) {
}
if(! $vcard['photo']) {
$rawtags = $item->get_item_tags( SIMPLEPIE_NAMESPACE_ATOM_10, 'author');
if($rawtags) {
if($rawtags) {
$elems = $rawtags[0]['child'][SIMPLEPIE_NAMESPACE_ATOM_10];
if((x($elems,'link')) && ($elems['link'][0]['attribs']['']['rel'] === 'photo'))
$vcard['photo'] = $elems['link'][0]['attribs']['']['href'];
}
}
}
}
}
@ -690,8 +690,13 @@ function probe_url($url, $mode = PROBE_NORMAL) {
if($poll === $profile)
$lnk = $feed->get_permalink();
if(isset($lnk) && strlen($lnk))
$profile = $lnk;
$profile = $lnk;
if(! $network) {
$network = NETWORK_FEED;
// If it is a feed, don't take the author name as feed name
unset($vcard['fn']);
}
if(! (x($vcard,'fn')))
$vcard['fn'] = notags($feed->get_title());
if(! (x($vcard,'fn')))
@ -706,8 +711,6 @@ function probe_url($url, $mode = PROBE_NORMAL) {
if(strpos($vcard['nick'],' '))
$vcard['nick'] = trim(substr($vcard['nick'],0,strpos($vcard['nick'],' ')));
}
if(! $network)
$network = NETWORK_FEED;
if(! $priority)
$priority = 2;
}
@ -715,7 +718,7 @@ function probe_url($url, $mode = PROBE_NORMAL) {
if(! x($vcard,'photo')) {
$a = get_app();
$vcard['photo'] = $a->get_baseurl() . '/images/person-175.jpg' ;
$vcard['photo'] = $a->get_baseurl() . '/images/person-175.jpg' ;
}
if(! $profile)
@ -728,7 +731,7 @@ function probe_url($url, $mode = PROBE_NORMAL) {
$vcard['fn'] = notags($vcard['fn']);
$vcard['nick'] = str_replace(' ','',notags($vcard['nick']));
$result['name'] = $vcard['fn'];
$result['nick'] = $vcard['nick'];
$result['url'] = $profile;

View file

@ -769,7 +769,7 @@
$in_reply_to_status_id_str = NULL;
$in_reply_to_user_id_str = NULL;
$in_reply_to_screen_name = NULL;
if ($lastwall['parent']!=$lastwall['id']) {
if (intval($lastwall['parent']) != intval($lastwall['id'])) {
$in_reply_to_status_id= intval($lastwall['parent']);
$in_reply_to_status_id_str = (string) intval($lastwall['parent']);
@ -784,6 +784,18 @@
}
}
// There seems to be situation, where both fields are identical:
// https://github.com/friendica/friendica/issues/1010
// This is a bugfix for that.
if (intval($in_reply_to_status_id) == intval($lastwall['id'])) {
logger('api_status_show: this message should never appear: id: '.$lastwall['id'].' similar to reply-to: '.$in_reply_to_status_id, LOGGER_DEBUG);
$in_reply_to_status_id = NULL;
$in_reply_to_user_id = NULL;
$in_reply_to_status_id_str = NULL;
$in_reply_to_user_id_str = NULL;
$in_reply_to_screen_name = NULL;
}
$status_info = array(
'text' => trim(html2plain(bbcode(api_clean_plain_items($lastwall['body']), false, false, 2, true), 0)),
'truncated' => false,

View file

@ -1373,12 +1373,13 @@ function diaspora_comment($importer,$xml,$msg) {
$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)
);
}
//if($message_id) {
//q("update item set plink = '%s' where id = %d",
// //dbesc($a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id),
// dbesc($a->get_baseurl().'/display/'.$datarray['guid']),
// intval($message_id)
//);
//}
if(($parent_item['origin']) && (! $parent_author_signature)) {
q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",
@ -1422,7 +1423,8 @@ function diaspora_comment($importer,$xml,$msg) {
'to_email' => $importer['email'],
'uid' => $importer['uid'],
'item' => $datarray,
'link' => $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id,
//'link' => $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id,
'link' => $a->get_baseurl().'/display/'.$datarray['guid'],
'source_name' => $datarray['author-name'],
'source_link' => $datarray['author-link'],
'source_photo' => $datarray['author-avatar'],
@ -1957,7 +1959,8 @@ EOT;
$ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
$alink = '[url=' . $parent_item['author-link'] . ']' . $parent_item['author-name'] . '[/url]';
$plink = '[url=' . $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $parent_item['id'] . ']' . $post_type . '[/url]';
//$plink = '[url=' . $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $parent_item['id'] . ']' . $post_type . '[/url]';
$plink = '[url='.$a->get_baseurl().'/display/'.$guid.']'.$post_type.'[/url]';
$arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink );
$arr['app'] = 'Diaspora';
@ -1973,12 +1976,13 @@ EOT;
$message_id = item_store($arr);
if($message_id) {
q("update item set plink = '%s' where id = %d",
dbesc($a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id),
intval($message_id)
);
}
//if($message_id) {
// q("update item set plink = '%s' where id = %d",
// //dbesc($a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id),
// dbesc($a->get_baseurl().'/display/'.$guid),
// intval($message_id)
// );
//}
if(! $parent_author_signature) {
q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ",

View file

@ -385,13 +385,18 @@ function event_store($arr) {
$r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
intval($arr['uid'])
);
if(count($r))
$plink = $a->get_baseurl() . '/display/' . $r[0]['nickname'] . '/' . $item_id;
//if(count($r))
// $plink = $a->get_baseurl() . '/display/' . $r[0]['nickname'] . '/' . $item_id;
if($item_id) {
q("UPDATE `item` SET `plink` = '%s', `event-id` = %d WHERE `uid` = %d AND `id` = %d",
dbesc($plink),
//q("UPDATE `item` SET `plink` = '%s', `event-id` = %d WHERE `uid` = %d AND `id` = %d",
// dbesc($plink),
// intval($event['id']),
// intval($arr['uid']),
// intval($item_id)
//);
q("UPDATE `item` SET `event-id` = %d WHERE `uid` = %d AND `id` = %d",
intval($event['id']),
intval($arr['uid']),
intval($item_id)

View file

@ -678,8 +678,10 @@ function get_atom_elements($feed, $item, $contact = array()) {
if($rawgeo)
$res['coord'] = unxmlify($rawgeo[0]['data']);
if ($contact["network"] == NETWORK_FEED)
if ($contact["network"] == NETWORK_FEED) {
$res['verb'] = ACTIVITY_POST;
$res['object-type'] = ACTIVITY_OBJ_NOTE;
}
$rawverb = $item->get_item_tags(NAMESPACE_ACTIVITY, 'verb');
@ -866,6 +868,7 @@ function get_atom_elements($feed, $item, $contact = array()) {
if (isset($contact["network"]) AND ($contact["network"] == NETWORK_FEED) AND $contact['fetch_further_information']) {
$res["body"] = $res["title"].add_page_info($res['plink']);
$res["title"] = "";
$res["object-type"] = ACTIVITY_OBJ_BOOKMARK;
} elseif (isset($contact["network"]) AND ($contact["network"] == NETWORK_OSTATUS))
$res["body"] = add_page_info_to_body($res["body"]);
elseif (isset($contact["network"]) AND ($contact["network"] == NETWORK_FEED) AND strstr($res['plink'], ".app.net/")) {
@ -1093,9 +1096,14 @@ function item_store($arr,$force_parent = false) {
$arr['attach'] = ((x($arr,'attach')) ? notags(trim($arr['attach'])) : '');
$arr['app'] = ((x($arr,'app')) ? notags(trim($arr['app'])) : '');
$arr['origin'] = ((x($arr,'origin')) ? intval($arr['origin']) : 0 );
$arr['guid'] = ((x($arr,'guid')) ? notags(trim($arr['guid'])) : get_guid());
$arr['guid'] = ((x($arr,'guid')) ? notags(trim($arr['guid'])) : get_guid(30));
$arr['network'] = ((x($arr,'network')) ? trim($arr['network']) : '');
if ($arr['plink'] == "") {
$a = get_app();
$arr['plink'] = $a->get_baseurl().'/display/'.$arr['guid'];
}
if ($arr['network'] == "") {
$r = q("SELECT `network` FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($arr['contact-id']),
@ -1274,7 +1282,8 @@ function item_store($arr,$force_parent = false) {
'to_email' => $u[0]['email'],
'uid' => $u[0]['uid'],
'item' => $item[0],
'link' => $a->get_baseurl().'/display/'.$u[0]['nickname'].'/'.$current_post,
//'link' => $a->get_baseurl().'/display/'.$u[0]['nickname'].'/'.$current_post,
'link' => $a->get_baseurl().'/display/'.$arr['guid'],
'source_name' => $item[0]['author-name'],
'source_link' => $item[0]['author-link'],
'source_photo' => $item[0]['author-avatar'],
@ -1395,6 +1404,15 @@ function item_store($arr,$force_parent = false) {
return $current_post;
}
function get_item_guid($id) {
$r = q("SELECT `guid` FROM `item` WHERE `id` = %d LIMIT 1", intval($id));
if (count($r))
return($r[0]["guid"]);
else
return("");
}
// return - test
function get_item_contact($item,$contacts) {
if(! count($contacts) || (! is_array($item)))
@ -1494,7 +1512,8 @@ function tag_deliver($uid,$item_id) {
'to_email' => $u[0]['email'],
'uid' => $u[0]['uid'],
'item' => $item,
'link' => $a->get_baseurl() . '/display/' . $u[0]['nickname'] . '/' . $item['id'],
//'link' => $a->get_baseurl() . '/display/' . $u[0]['nickname'] . '/' . $item['id'],
'link' => $a->get_baseurl() . '/display/'.get_item_guid($item['id']),
'source_name' => $item['author-name'],
'source_link' => $item['author-link'],
'source_photo' => $photo,
@ -3309,7 +3328,8 @@ function local_delivery($importer,$data) {
'to_email' => $importer['email'],
'uid' => $importer['importer_uid'],
'item' => $datarray,
'link' => $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $posted_id,
//'link' => $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $posted_id,
'link' => $a->get_baseurl().'/display/'.get_item_guid($posted_id),
'source_name' => stripslashes($datarray['author-name']),
'source_link' => $datarray['author-link'],
'source_photo' => ((link_compare($datarray['author-link'],$importer['url']))
@ -3473,7 +3493,8 @@ function local_delivery($importer,$data) {
'to_email' => $importer['email'],
'uid' => $importer['importer_uid'],
'item' => $datarray,
'link' => $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $posted_id,
//'link' => $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $posted_id,
'link' => $a->get_baseurl().'/display/'.get_item_guid($posted_id),
'source_name' => stripslashes($datarray['author-name']),
'source_link' => $datarray['author-link'],
'source_photo' => ((link_compare($datarray['author-link'],$importer['url']))
@ -3626,7 +3647,8 @@ function local_delivery($importer,$data) {
'to_email' => $importer['email'],
'uid' => $importer['importer_uid'],
'item' => $datarray,
'link' => $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $posted_id,
//'link' => $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $posted_id,
'link' => $a->get_baseurl().'/display/'.get_item_guid($posted_id),
'source_name' => stripslashes($datarray['author-name']),
'source_link' => $datarray['author-link'],
'source_photo' => ((link_compare($datarray['author-link'],$importer['url']))
@ -3717,7 +3739,8 @@ function new_follower($importer,$contact,$datarray,$item,$sharing = false) {
group_add_member($r[0]['uid'],'',$contact_record['id'],$r[0]['def_gid']);
}
if(($r[0]['notify-flags'] & NOTIFY_INTRO) && ($r[0]['page-flags'] == PAGE_NORMAL)) {
if(($r[0]['notify-flags'] & NOTIFY_INTRO) &&
(($r[0]['page-flags'] == PAGE_NORMAL) OR ($r[0]['page-flags'] == PAGE_SOAPBOX))) {
$email_tpl = get_intltext_template('follow_notify_eml.tpl');
$email = replace_macros($email_tpl, array(
'$requestor' => ((strlen($name)) ? $name : t('[Name Withheld]')),

View file

@ -148,7 +148,7 @@ function nav_info(&$a) {
/* only show friend requests for normal pages. Other page types have automatic friendship. */
if($_SESSION['page_flags'] == PAGE_NORMAL || $_SESSION['page_flags'] == PAGE_PRVGROUP) {
if($_SESSION['page_flags'] == PAGE_NORMAL || $_SESSION['page_flags'] == PAGE_SOAPBOX || $_SESSION['page_flags'] == PAGE_PRVGROUP) {
$nav['introductions'] = array('notifications/intros', t('Introductions'), "", t('Friend Requests'));
$nav['notifications'] = array('notifications', t('Notifications'), "", t('Notifications'));
$nav['notifications']['all']=array('notifications/system', t('See all notifications'), "", "");
@ -166,12 +166,12 @@ function nav_info(&$a) {
}
$nav['delegations'] = Array('delegate', t('Delegations'), "", t('Delegate Page Management'));
$nav['settings'] = array('settings', t('Settings'),"", t('Account settings'));
if(feature_enabled(local_user(),'multi_profiles'))
$nav['profiles'] = array('profiles', t('Profiles'),"", t('Manage/Edit Profiles'));
$nav['contacts'] = array('contacts', t('Contacts'),"", t('Manage/edit friends and contacts'));
}

View file

@ -331,6 +331,7 @@ function onepoll_run(&$argv, &$argc){
$datarray = array();
$datarray['verb'] = ACTIVITY_POST;
$datarray['object-type'] = ACTIVITY_OBJ_NOTE;
// $meta = email_msg_meta($mbox,$msg_uid);
// $headers = email_msg_headers($mbox,$msg_uid);