From 8510748b19c7b25635f988801630c38e904ff6bf Mon Sep 17 00:00:00 2001 From: Friendika Date: Sun, 22 May 2011 01:15:04 -0700 Subject: [PATCH 1/5] friendika page hook for German impressum --- mod/friendika.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mod/friendika.php b/mod/friendika.php index c7d8b5b81..8bd6e3437 100644 --- a/mod/friendika.php +++ b/mod/friendika.php @@ -62,7 +62,9 @@ function friendika_content(&$a) { } else $o .= '

' . t('No installed plugins/addons/apps'); - + + call_hooks('about_hook', $o); + return $o; } From f4e47f168feb1075c30ba478e823f61dbcd26e02 Mon Sep 17 00:00:00 2001 From: Friendika Date: Sun, 22 May 2011 06:05:01 -0700 Subject: [PATCH 2/5] if xml doesn't parse, don't process it further --- boot.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/boot.php b/boot.php index 0704c2305..9581541bd 100644 --- a/boot.php +++ b/boot.php @@ -1508,6 +1508,8 @@ function lrdd($uri) { logger('lrdd: host_meta: ' . $xml, LOGGER_DATA); $h = parse_xml_string($xml); + if(! $h) + return array(); $arr = convert_xml_element_to_array($h); @@ -1672,6 +1674,9 @@ function fetch_xrd_links($url) { logger('fetch_xrd_links: ' . $xml, LOGGER_DATA); $h = parse_xml_string($xml); + if(! $h) + return array(); + $arr = convert_xml_element_to_array($h); $links = array(); From 4c7522a131bfa93dff127a706606d587176fb2cf Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Sun, 22 May 2011 22:39:43 +0200 Subject: [PATCH 3/5] added support for pre configured StatusNet credentials --- addon/statusnet/statusnet.php | 168 +++++++++++++++++++++------------- 1 file changed, 104 insertions(+), 64 deletions(-) diff --git a/addon/statusnet/statusnet.php b/addon/statusnet/statusnet.php index 1d12292c8..25aad028d 100644 --- a/addon/statusnet/statusnet.php +++ b/addon/statusnet/statusnet.php @@ -86,69 +86,91 @@ function statusnet_settings_post ($a,$post) { if(! local_user()) return; if (isset($_POST['statusnet-disconnect'])) { - /*** - * if the statusnet-disconnect checkbox is set, clear the statusnet configuration - * TODO can we revoke the access tokens at Twitter and do we need to do so? - */ - del_pconfig( local_user(), 'statusnet', 'consumerkey' ); - del_pconfig( local_user(), 'statusnet', 'consumersecret' ); - del_pconfig( local_user(), 'statusnet', 'post' ); - del_pconfig( local_user(), 'statusnet', 'post_by_default' ); - del_pconfig( local_user(), 'statusnet', 'oauthtoken' ); + /*** + * if the statusnet-disconnect checkbox is set, clear the statusnet configuration + * TODO can we revoke the access tokens at Twitter and do we need to do so? + */ + del_pconfig( local_user(), 'statusnet', 'consumerkey' ); + del_pconfig( local_user(), 'statusnet', 'consumersecret' ); + del_pconfig( local_user(), 'statusnet', 'post' ); + del_pconfig( local_user(), 'statusnet', 'post_by_default' ); + del_pconfig( local_user(), 'statusnet', 'oauthtoken' ); del_pconfig( local_user(), 'statusnet', 'oauthsecret' ); del_pconfig( local_user(), 'statusnet', 'baseapi' ); } else { - if (isset($_POST['statusnet-consumersecret'])) { - // check if we can reach the API of the StatusNet server - // we'll check the API Version for that, if we don't get one we'll try to fix the path but will - // resign quickly after this one try to fix the path ;-) - $apibase = $_POST['statusnet-baseapi']; - $c = fetch_url( $apibase . 'statusnet/version.xml' ); - if (strlen($c) > 0) { - // ok the API path is correct, let's save the settings - set_pconfig(local_user(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']); - set_pconfig(local_user(), 'statusnet', 'consumersecret', $_POST['statusnet-consumersecret']); - set_pconfig(local_user(), 'statusnet', 'baseapi', $apibase ); + if (isset($_POST['statusnet-preconf-apiurl'])) { + /*** + * If the user used one of the preconfigured StatusNet server credentials + * use them. All the data are available in the global config. + * Check the API Url never the less and blame the admin if it's not working ^^ + */ + $globalsn = get_config('statusnet', 'sites'); + foreach ( $globalsn as $asn) { + if ($asn['apiurl'] == $_POST['statusnet-preconf-apiurl'] ) { + $apibase = $asn['apiurl']; + $c = fetch_url( $apibase . 'statusnet/version.xml' ); + if (strlen($c) > 0) { + set_pconfig(local_user(), 'statusnet', 'consumerkey', $asn['consumerkey'] ); + set_pconfig(local_user(), 'statusnet', 'consumersecret', $asn['consumersecret'] ); + set_pconfig(local_user(), 'statusnet', 'baseapi', $asn['apiurl'] ); + } else { + notice( t('Please contact your site administrator.
The provided API URL is not valid.').EOL.$asn['apiurl'].EOL ); + } + } + } + goaway($a->get_baseurl().'/settings/addon'); } else { - // the API path is not correct, maybe missing trailing / ? - $apibase = $apibase . '/'; + if (isset($_POST['statusnet-consumersecret'])) { + // check if we can reach the API of the StatusNet server + // we'll check the API Version for that, if we don't get one we'll try to fix the path but will + // resign quickly after this one try to fix the path ;-) + $apibase = $_POST['statusnet-baseapi']; $c = fetch_url( $apibase . 'statusnet/version.xml' ); if (strlen($c) > 0) { - // ok the API path is now correct, let's save the settings + // ok the API path is correct, let's save the settings set_pconfig(local_user(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']); set_pconfig(local_user(), 'statusnet', 'consumersecret', $_POST['statusnet-consumersecret']); set_pconfig(local_user(), 'statusnet', 'baseapi', $apibase ); } else { - // still not the correct API base, let's do noting - notice( t('We could not contact the StatusNet API with the Path you entered.').EOL ); + // the API path is not correct, maybe missing trailing / ? + $apibase = $apibase . '/'; + $c = fetch_url( $apibase . 'statusnet/version.xml' ); + if (strlen($c) > 0) { + // ok the API path is now correct, let's save the settings + set_pconfig(local_user(), 'statusnet', 'consumerkey', $_POST['statusnet-consumerkey']); + set_pconfig(local_user(), 'statusnet', 'consumersecret', $_POST['statusnet-consumersecret']); + set_pconfig(local_user(), 'statusnet', 'baseapi', $apibase ); + } else { + // still not the correct API base, let's do noting + notice( t('We could not contact the StatusNet API with the Path you entered.').EOL ); + } } - } - goaway($a->get_baseurl().'/settings/addon'); - } else { - if (isset($_POST['statusnet-pin'])) { - // if the user supplied us with a PIN from Twitter, let the magic of OAuth happen - logger('got a StatusNet security code'); - $api = get_pconfig(local_user(), 'statusnet', 'baseapi'); - $ckey = get_pconfig(local_user(), 'statusnet', 'consumerkey' ); - $csecret = get_pconfig(local_user(), 'statusnet', 'consumersecret' ); - // the token and secret for which the PIN was generated were hidden in the settings - // form as token and token2, we need a new connection to Twitter using these token - // and secret to request a Access Token with the PIN - $connection = new StatusNetOAuth($api, $ckey, $csecret, $_POST['statusnet-token'], $_POST['statusnet-token2']); - $token = $connection->getAccessToken( $_POST['statusnet-pin'] ); - // ok, now that we have the Access Token, save them in the user config - set_pconfig(local_user(),'statusnet', 'oauthtoken', $token['oauth_token']); - set_pconfig(local_user(),'statusnet', 'oauthsecret', $token['oauth_token_secret']); - set_pconfig(local_user(),'statusnet', 'post', 1); - // reload the Addon Settings page, if we don't do it see Bug #42 - goaway($a->get_baseurl().'/settings/addon'); - } else { - // if no PIN is supplied in the POST variables, the user has changed the setting - // to post a tweet for every new __public__ posting to the wall - set_pconfig(local_user(),'statusnet','post',intval($_POST['statusnet-enable'])); - set_pconfig(local_user(),'statusnet','post_by_default',intval($_POST['statusnet-default'])); - notice( t('StatusNet settings updated.') . EOL); - }}} + goaway($a->get_baseurl().'/settings/addon'); + } else { + if (isset($_POST['statusnet-pin'])) { + // if the user supplied us with a PIN from Twitter, let the magic of OAuth happen + logger('got a StatusNet security code'); + $api = get_pconfig(local_user(), 'statusnet', 'baseapi'); + $ckey = get_pconfig(local_user(), 'statusnet', 'consumerkey' ); + $csecret = get_pconfig(local_user(), 'statusnet', 'consumersecret' ); + // the token and secret for which the PIN was generated were hidden in the settings + // form as token and token2, we need a new connection to Twitter using these token + // and secret to request a Access Token with the PIN + $connection = new StatusNetOAuth($api, $ckey, $csecret, $_POST['statusnet-token'], $_POST['statusnet-token2']); + $token = $connection->getAccessToken( $_POST['statusnet-pin'] ); + // ok, now that we have the Access Token, save them in the user config + set_pconfig(local_user(),'statusnet', 'oauthtoken', $token['oauth_token']); + set_pconfig(local_user(),'statusnet', 'oauthsecret', $token['oauth_token_secret']); + set_pconfig(local_user(),'statusnet', 'post', 1); + // reload the Addon Settings page, if we don't do it see Bug #42 + goaway($a->get_baseurl().'/settings/addon'); + } else { + // if no PIN is supplied in the POST variables, the user has changed the setting + // to post a tweet for every new __public__ posting to the wall + set_pconfig(local_user(),'statusnet','post',intval($_POST['statusnet-enable'])); + set_pconfig(local_user(),'statusnet','post_by_default',intval($_POST['statusnet-default'])); + notice( t('StatusNet settings updated.') . EOL); + }}}} } function statusnet_settings(&$a,&$s) { if(! local_user()) @@ -175,19 +197,37 @@ function statusnet_settings(&$a,&$s) { if ( (!$ckey) && (!$csecret) ) { /*** * no consumer keys - */ - $s .= '

'. t('No consumer key pair for StatusNet found. Register your Friendika Account as an desktop client on your StatusNet account, copy the consumer key pair here and enter the API base root.
Before you register your own OAuth key pair ask the administrator if there is already a key pair for this Friendika installation at your favorited StatusNet installation.') .'

'; - $s .= '
'; - $s .= ''; - $s .= ''; - $s .= '
'; - $s .= ''; - $s .= ''; - $s .= '
'; - $s .= ''; - $s .= ''; - $s .= '
'; + */ + $globalsn = get_config('statusnet', 'sites'); + /*** + * lets check if we have one or more globally configured StatusNet + * server OAuth credentials in the configuration. If so offer them + * with a little explanation to the user as choice - otherwise + * ignore this option entirely. + */ + if (! $globalsn == null) { + $s .= '

' . t('Globally Available StatusNet OAuthKeys') . '

'; + $s .= '

'. t('There are preconfigured OAuth key pairs for some StatusNet servers available. If you are useing one of them, please use these credentials. If not feel free to connect to any other StatusNet instance (see below).') .'

'; + $s .= '
'; + foreach ($globalsn as $asn) { + $s .= ''. $asn['sitename'] .'
'; + } + $s .= '

'; $s .= '
'; + } + $s .= '

' . t('Provide your own OAuth Credentials') . '

'; + $s .= '

'. t('No consumer key pair for StatusNet found. Register your Friendika Account as an desktop client on your StatusNet account, copy the consumer key pair here and enter the API base root.
Before you register your own OAuth key pair ask the administrator if there is already a key pair for this Friendika installation at your favorited StatusNet installation.') .'

'; + $s .= '
'; + $s .= ''; + $s .= '
'; + $s .= '
'; + $s .= ''; + $s .= '
'; + $s .= '
'; + $s .= ''; + $s .= '
'; + $s .= '

'; + $s .= '
'; } else { /*** * ok we have a consumer key pair now look into the OAuth stuff From ea0a28ebfb10e1a42e2f28b076b8d4e8d79f8e53 Mon Sep 17 00:00:00 2001 From: Friendika Date: Sun, 22 May 2011 14:20:31 -0700 Subject: [PATCH 4/5] removed buggy debug code ;) --- boot.php | 2 +- include/conversation.php | 2 +- mod/item.php | 3 --- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/boot.php b/boot.php index 9581541bd..1a6bf622c 100644 --- a/boot.php +++ b/boot.php @@ -4,7 +4,7 @@ set_time_limit(0); ini_set('pcre.backtrack_limit', 250000); -define ( 'FRIENDIKA_VERSION', '2.2.987' ); +define ( 'FRIENDIKA_VERSION', '2.2.988' ); define ( 'DFRN_PROTOCOL_VERSION', '2.21' ); define ( 'DB_UPDATE_VERSION', 1054 ); diff --git a/include/conversation.php b/include/conversation.php index 5f761ccf0..4fa4b92ad 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -357,7 +357,7 @@ function conversation(&$a, $items, $mode, $update) { if($page_writeable) { if($toplevelpost) { - $likebuttons = replace_macros((($item['private']) ? $noshare_tpl : $like_tpl),array( + $likebuttons = replace_macros((($item['private'] || ($profile_owner != local_user())) ? $noshare_tpl : $like_tpl),array( '$id' => $item['id'], '$likethis' => t("I like this \x28toggle\x29"), '$nolike' => t("I don't like this \x28toggle\x29"), diff --git a/mod/item.php b/mod/item.php index 8c9e004c3..66fdc13af 100644 --- a/mod/item.php +++ b/mod/item.php @@ -589,9 +589,6 @@ function item_post(&$a) { dbesc(datetime_convert()), intval($post_id) ); - foreach( $r as $key => $val) { - logger("key: " . $key . " val: " . $val); - } // photo comments turn the corresponding item visible to the profile wall // This way we don't see every picture in your new photo album posted to your wall at once. From 44a22c29155fa3beeed7cd5d0add30818e409891 Mon Sep 17 00:00:00 2001 From: Friendika Date: Sun, 22 May 2011 18:40:00 -0700 Subject: [PATCH 5/5] more improvements in twitter handling, reduce duplicates from FB when double friended --- include/Scrape.php | 138 ++++++++++++++++++++++++++------------------- include/items.php | 8 +++ mod/follow.php | 10 +++- 3 files changed, 96 insertions(+), 60 deletions(-) diff --git a/include/Scrape.php b/include/Scrape.php index 7fc0c964b..1a9c03c8e 100644 --- a/include/Scrape.php +++ b/include/Scrape.php @@ -292,7 +292,9 @@ function probe_url($url) { $diaspora = false; $email_conversant = false; - if($url) { + $twitter = ((strpos($url,'twitter.com') !== false) ? true : false); + + if(! $twitter) { $links = lrdd($url); if(count($links)) { @@ -413,76 +415,94 @@ function probe_url($url) { $profile = $url; } + if($twitter) { + logger('twitter: setup'); + $tid = basename($url); + $tapi = 'https://api.twitter.com/1/statuses/user_timeline.rss'; + if(intval($tid)) + $poll = $tapi . '?user_id=' . $tid; + else + $poll = $tapi . '?screen_name=' . $tid; + $profile = 'http://twitter.com/!#/' . $tid; + } + if(! x($vcard,'fn')) if(x($vcard,'nick')) $vcard['fn'] = $vcard['nick']; - if((! isset($vcard)) && (! $poll)) { + + if(((! isset($vcard)) && (! $poll)) || ($twitter)) { - $ret = scrape_feed($url); - logger('probe_url: scrape_feed returns: ' . print_r($ret,true), LOGGER_DATA); - if(count($ret) && ($ret['feed_atom'] || $ret['feed_rss'])) { - $poll = ((x($ret,'feed_atom')) ? unamp($ret['feed_atom']) : unamp($ret['feed_rss'])); + $feedret = scrape_feed($url); + logger('probe_url: scrape_feed returns: ' . print_r($feedret,true), LOGGER_DATA); + if(count($feedret) && ($feedret['feed_atom'] || $feedret['feed_rss'])) { + $poll = ((x($feedret,'feed_atom')) ? unamp($feedret['feed_atom']) : unamp($feedret['feed_rss'])); $vcard = array(); - if(x($ret,'photo')) - $vcard['photo'] = $ret['photo']; - require_once('simplepie/simplepie.inc'); - $feed = new SimplePie(); - $xml = fetch_url($poll); + } - $feed->set_raw_data($xml); + if(x($feedret,'photo')) + $vcard['photo'] = $feedret['photo']; + require_once('simplepie/simplepie.inc'); + $feed = new SimplePie(); + $xml = fetch_url($poll); - $feed->init(); + $feed->set_raw_data($xml); - if(! x($vcard,'photo')) - $vcard['photo'] = $feed->get_image_url(); - $author = $feed->get_author(); - if($author) { - $vcard['fn'] = unxmlify(trim($author->get_name())); - if(! $vcard['fn']) - $vcard['fn'] = trim(unxmlify($author->get_email())); - if(strpos($vcard['fn'],'@') !== false) - $vcard['fn'] = substr($vcard['fn'],0,strpos($vcard['fn'],'@')); - $vcard['nick'] = strtolower(notags(unxmlify($vcard['fn']))); - if(strpos($vcard['nick'],' ')) - $vcard['nick'] = trim(substr($vcard['nick'],0,strpos($vcard['nick'],' '))); - $email = unxmlify($author->get_email()); - } - else { - $item = $feed->get_item(0); - if($item) { - $author = $item->get_author(); - if($author) { - $vcard['fn'] = trim(unxmlify($author->get_name())); - if(! $vcard['fn']) - $vcard['fn'] = trim(unxmlify($author->get_email())); - if(strpos($vcard['fn'],'@') !== false) - $vcard['fn'] = substr($vcard['fn'],0,strpos($vcard['fn'],'@')); - $vcard['nick'] = strtolower(unxmlify($vcard['fn'])); - if(strpos($vcard['nick'],' ')) - $vcard['nick'] = trim(substr($vcard['nick'],0,strpos($vcard['nick'],' '))); - $email = unxmlify($author->get_email()); - } - if(! $vcard['photo']) { - $rawmedia = $item->get_item_tags('http://search.yahoo.com/mrss/','thumbnail'); - if($rawmedia && $rawmedia[0]['attribs']['']['url']) - $vcard['photo'] = unxmlify($rawmedia[0]['attribs']['']['url']); - } + $feed->init(); + + if(! x($vcard,'photo')) + $vcard['photo'] = $feed->get_image_url(); + $author = $feed->get_author(); + if($author) { + $vcard['fn'] = unxmlify(trim($author->get_name())); + if(! $vcard['fn']) + $vcard['fn'] = trim(unxmlify($author->get_email())); + if(strpos($vcard['fn'],'@') !== false) + $vcard['fn'] = substr($vcard['fn'],0,strpos($vcard['fn'],'@')); + $email = unxmlify($author->get_email()); + } + else { + $item = $feed->get_item(0); + if($item) { + $author = $item->get_author(); + if($author) { + $vcard['fn'] = trim(unxmlify($author->get_name())); + if(! $vcard['fn']) + $vcard['fn'] = trim(unxmlify($author->get_email())); + if(strpos($vcard['fn'],'@') !== false) + $vcard['fn'] = substr($vcard['fn'],0,strpos($vcard['fn'],'@')); + $email = unxmlify($author->get_email()); + } + if(! $vcard['photo']) { + $rawmedia = $item->get_item_tags('http://search.yahoo.com/mrss/','thumbnail'); + if($rawmedia && $rawmedia[0]['attribs']['']['url']) + $vcard['photo'] = unxmlify($rawmedia[0]['attribs']['']['url']); } } - if((! $vcard['photo']) && strlen($email)) - $vcard['photo'] = gravatar_img($email); - if($poll === $profile) - $lnk = $feed->get_permalink(); - if(isset($lnk) && strlen($lnk)) - $profile = $lnk; - if(! (x($vcard,'fn'))) - $vcard['fn'] = notags($feed->get_title()); - if(! (x($vcard,'fn'))) - $vcard['fn'] = notags($feed->get_description()); - $network = 'feed'; - $priority = 2; } + if((! $vcard['photo']) && strlen($email)) + $vcard['photo'] = gravatar_img($email); + if($poll === $profile) + $lnk = $feed->get_permalink(); + if(isset($lnk) && strlen($lnk)) + $profile = $lnk; + + if(! (x($vcard,'fn'))) + $vcard['fn'] = notags($feed->get_title()); + if(! (x($vcard,'fn'))) + $vcard['fn'] = notags($feed->get_description()); + + if(strpos($vcard['fn'],'Twitter / ') !== false) { + $vcard['fn'] = substr($vcard['fn'],strpos($vcard['fn'],'/')+1); + $vcard['fn'] = trim($vcard['fn']); + } + if(! x($vcard,'nick')) { + $vcard['nick'] = strtolower(notags(unxmlify($vcard['fn']))); + if(strpos($vcard['nick'],' ')) + $vcard['nick'] = trim(substr($vcard['nick'],0,strpos($vcard['nick'],' '))); + } + $network = 'feed'; + $priority = 2; } } diff --git a/include/items.php b/include/items.php index 55b17158a..cbf5e4d24 100644 --- a/include/items.php +++ b/include/items.php @@ -384,6 +384,9 @@ function get_atom_elements($feed,$item) { else $res['private'] = 0; + $extid = $item->get_item_tags(NAMESPACE_DFRN,'extid'); + if($extid && $extid[0]['data']) + $res['extid'] = $extid[0]['data']; $rawlocation = $item->get_item_tags(NAMESPACE_DFRN, 'location'); if($rawlocation) @@ -634,6 +637,7 @@ function item_store($arr,$force_parent = false) { $arr['wall'] = ((x($arr,'wall')) ? intval($arr['wall']) : 0); $arr['uri'] = ((x($arr,'uri')) ? notags(trim($arr['uri'])) : random_string()); + $arr['extid'] = ((x($arr,'extid')) ? notags(trim($arr['extid'])) : ''); $arr['author-name'] = ((x($arr,'author-name')) ? notags(trim($arr['author-name'])) : ''); $arr['author-link'] = ((x($arr,'author-link')) ? notags(trim($arr['author-link'])) : ''); $arr['author-avatar'] = ((x($arr,'author-avatar')) ? notags(trim($arr['author-avatar'])) : ''); @@ -1568,6 +1572,10 @@ function atom_entry($item,$type,$author,$owner,$comment = false) { if(($item['private']) || strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])) $o .= '1' . "\r\n"; + if($item['extid']) + $o .= '' . $item['extid'] . '' . "\r\n"; + + $verb = construct_verb($item); $o .= '' . xmlify($verb) . '' . "\r\n"; $actobj = construct_activity_object($item); diff --git a/mod/follow.php b/mod/follow.php index 6786e9039..9a9f9da7d 100644 --- a/mod/follow.php +++ b/mod/follow.php @@ -12,7 +12,7 @@ function follow_post(&$a) { $url = $orig_url = notags(trim($_POST['url'])); - // remove ajax junk + // remove ajax junk, e.g. Twitter $url = str_replace('/#!/','/',$url); @@ -41,6 +41,14 @@ function follow_post(&$a) { if(! ((x($ret,'name')) && (x($ret,'poll')) && ((x($ret,'url')) || (x($ret,'addr'))))) { notice( t('The profile address specified does not provide adequate information.') . EOL); + if(! x($ret,'poll')) + notice( t('No compatible communication protocols or feeds were discovered.') . EOL); + if(! x($ret,'name')) + notice( t('An author or name was not found.') . EOL); + if(! x($ret,'url')) + notice( t('No browser URL could be matched to this address.') . EOL); + if(strpos($url,'@') !== false) + notice('Unable to match @-style Identity Address with a known protocol or email contact'); goaway($_SESSION['return_url']); }