forked from GNUsocial/gnu-social
Merge branch '0.8.x' of git@gitorious.org:laconica/mainline into 0.8.x
* '0.8.x' of git@gitorious.org:laconica/mainline: When a notice is posted with an attachment, the facebook stream update has media displayed inline, or as links.
This commit is contained in:
commit
49e4f958eb
@ -57,7 +57,7 @@ class FacebookhomeAction extends FacebookAction
|
|||||||
|
|
||||||
// If this is the first time the user has started the app
|
// If this is the first time the user has started the app
|
||||||
// prompt for Facebook status update permission
|
// prompt for Facebook status update permission
|
||||||
if (!$this->facebook->api_client->users_hasAppPermission('status_update')) {
|
if (!$this->facebook->api_client->users_hasAppPermission('publish_stream')) {
|
||||||
|
|
||||||
if ($this->facebook->api_client->data_getUserPreference(
|
if ($this->facebook->api_client->data_getUserPreference(
|
||||||
FACEBOOK_PROMPTED_UPDATE_PREF) != 'true') {
|
FACEBOOK_PROMPTED_UPDATE_PREF) != 'true') {
|
||||||
@ -203,7 +203,7 @@ class FacebookhomeAction extends FacebookAction
|
|||||||
$api_key = common_config('facebook', 'apikey');
|
$api_key = common_config('facebook', 'apikey');
|
||||||
|
|
||||||
$auth_url = 'http://www.facebook.com/authorize.php?api_key=' .
|
$auth_url = 'http://www.facebook.com/authorize.php?api_key=' .
|
||||||
$api_key . '&v=1.0&ext_perm=status_update&next=' . $next .
|
$api_key . '&v=1.0&ext_perm=publish_stream&next=' . $next .
|
||||||
'&next_cancel=' . $next . '&submit=skip';
|
'&next_cancel=' . $next . '&submit=skip';
|
||||||
|
|
||||||
$this->elementStart('span', array('class' => 'facebook-button'));
|
$this->elementStart('span', array('class' => 'facebook-button'));
|
||||||
|
@ -31,7 +31,7 @@ class FacebookinviteAction extends FacebookAction
|
|||||||
$this->error = $error;
|
$this->error = $error;
|
||||||
|
|
||||||
if ($this->flink) {
|
if ($this->flink) {
|
||||||
if (!$this->facebook->api_client->users_hasAppPermission('status_update') &&
|
if (!$this->facebook->api_client->users_hasAppPermission('publish_stream') &&
|
||||||
$this->facebook->api_client->data_getUserPreference(
|
$this->facebook->api_client->data_getUserPreference(
|
||||||
FACEBOOK_PROMPTED_UPDATE_PREF) == 'true') {
|
FACEBOOK_PROMPTED_UPDATE_PREF) == 'true') {
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ class FacebookinviteAction extends FacebookAction
|
|||||||
|
|
||||||
// If this is the first time the user has started the app
|
// If this is the first time the user has started the app
|
||||||
// prompt for Facebook status update permission
|
// prompt for Facebook status update permission
|
||||||
if (!$this->facebook->api_client->users_hasAppPermission('status_update')) {
|
if (!$this->facebook->api_client->users_hasAppPermission('publish_stream')) {
|
||||||
|
|
||||||
if ($this->facebook->api_client->data_getUserPreference(
|
if ($this->facebook->api_client->data_getUserPreference(
|
||||||
FACEBOOK_PROMPTED_UPDATE_PREF) != 'true') {
|
FACEBOOK_PROMPTED_UPDATE_PREF) != 'true') {
|
||||||
|
@ -78,7 +78,7 @@ class FacebooksettingsAction extends FacebookAction
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->facebook->api_client->users_hasAppPermission('status_update')) {
|
if ($this->facebook->api_client->users_hasAppPermission('publish_stream')) {
|
||||||
|
|
||||||
$this->elementStart('form', array('method' => 'post',
|
$this->elementStart('form', array('method' => 'post',
|
||||||
'id' => 'facebook_settings'));
|
'id' => 'facebook_settings'));
|
||||||
@ -131,7 +131,7 @@ class FacebooksettingsAction extends FacebookAction
|
|||||||
|
|
||||||
$this->elementStart('ul', array('id' => 'fb-permissions-list'));
|
$this->elementStart('ul', array('id' => 'fb-permissions-list'));
|
||||||
$this->elementStart('li', array('id' => 'fb-permissions-item'));
|
$this->elementStart('li', array('id' => 'fb-permissions-item'));
|
||||||
$this->elementStart('fb:prompt-permission', array('perms' => 'status_update',
|
$this->elementStart('fb:prompt-permission', array('perms' => 'publish_stream',
|
||||||
'next_fbjs' => 'document.setLocation(\'' . "$this->app_uri/settings.php" . '\')'));
|
'next_fbjs' => 'document.setLocation(\'' . "$this->app_uri/settings.php" . '\')'));
|
||||||
$this->element('span', array('class' => 'facebook-button'),
|
$this->element('span', array('class' => 'facebook-button'),
|
||||||
sprintf(_('Allow %s to update my Facebook status'), common_config('site', 'name')));
|
sprintf(_('Allow %s to update my Facebook status'), common_config('site', 'name')));
|
||||||
|
@ -460,16 +460,6 @@ class FacebookAction extends Action
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateFacebookStatus($notice)
|
|
||||||
{
|
|
||||||
$prefix = $this->facebook->api_client->data_getUserPreference(FACEBOOK_NOTICE_PREFIX, $this->fbuid);
|
|
||||||
$content = "$prefix $notice->content";
|
|
||||||
|
|
||||||
if ($this->facebook->api_client->users_hasAppPermission('status_update', $this->fbuid)) {
|
|
||||||
$this->facebook->api_client->users_setStatus($content, $this->fbuid, false, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function saveNewNotice()
|
function saveNewNotice()
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -504,7 +494,7 @@ class FacebookAction extends Action
|
|||||||
$replyto = $this->trimmed('inreplyto');
|
$replyto = $this->trimmed('inreplyto');
|
||||||
|
|
||||||
$notice = Notice::saveNew($user->id, $content,
|
$notice = Notice::saveNew($user->id, $content,
|
||||||
'Facebook', 1, ($replyto == 'false') ? null : $replyto);
|
'web', 1, ($replyto == 'false') ? null : $replyto);
|
||||||
|
|
||||||
if (is_string($notice)) {
|
if (is_string($notice)) {
|
||||||
$this->showPage($notice);
|
$this->showPage($notice);
|
||||||
@ -514,8 +504,7 @@ class FacebookAction extends Action
|
|||||||
common_broadcast_notice($notice);
|
common_broadcast_notice($notice);
|
||||||
|
|
||||||
// Also update the user's Facebook status
|
// Also update the user's Facebook status
|
||||||
$this->updateFacebookStatus($notice);
|
facebookBroadcastNotice($notice);
|
||||||
$this->updateProfileBox($notice);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,13 +86,17 @@ function isFacebookBound($notice, $flink) {
|
|||||||
|
|
||||||
// Check to see if the user has given the FB app status update perms
|
// Check to see if the user has given the FB app status update perms
|
||||||
$result = $facebook->api_client->
|
$result = $facebook->api_client->
|
||||||
users_hasAppPermission('status_update', $fbuid);
|
users_hasAppPermission('publish_stream', $fbuid);
|
||||||
|
|
||||||
|
if ($result != 1) {
|
||||||
|
$result = $facebook->api_client->
|
||||||
|
users_hasAppPermission('status_update', $fbuid);
|
||||||
|
}
|
||||||
if ($result != 1) {
|
if ($result != 1) {
|
||||||
$user = $flink->getUser();
|
$user = $flink->getUser();
|
||||||
$msg = "Not sending notice $notice->id to Facebook " .
|
$msg = "Not sending notice $notice->id to Facebook " .
|
||||||
"because user $user->nickname hasn't given the " .
|
"because user $user->nickname hasn't given the " .
|
||||||
'Facebook app \'status_update\' permission.';
|
'Facebook app \'status_update\' or \'publish_stream\' permission.';
|
||||||
common_debug($msg);
|
common_debug($msg);
|
||||||
$success = false;
|
$success = false;
|
||||||
}
|
}
|
||||||
@ -138,7 +142,56 @@ function facebookBroadcastNotice($notice)
|
|||||||
// Okay, we're good to go, update the FB status
|
// Okay, we're good to go, update the FB status
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$facebook->api_client->users_setStatus($status, $fbuid, false, true);
|
$result = $facebook->api_client->
|
||||||
|
users_hasAppPermission('publish_stream', $fbuid);
|
||||||
|
if($result == 1){
|
||||||
|
// authorized to use the stream api, so use it
|
||||||
|
$fbattachment = null;
|
||||||
|
$attachments = $notice->attachments();
|
||||||
|
if($attachments){
|
||||||
|
$fbattachment=array();
|
||||||
|
$fbattachment['media']=array();
|
||||||
|
//facebook only supports one attachment per item
|
||||||
|
$attachment = $attachments[0];
|
||||||
|
$fbmedia=array();
|
||||||
|
if(strncmp($attachment->mimetype,'image/',strlen('image/'))==0){
|
||||||
|
$fbmedia['type']='image';
|
||||||
|
$fbmedia['src']=$attachment->url;
|
||||||
|
$fbmedia['href']=$attachment->url;
|
||||||
|
$fbattachment['media'][]=$fbmedia;
|
||||||
|
/* Video doesn't seem to work. The notice never makes it to facebook, and no error is reported.
|
||||||
|
}else if(strncmp($attachment->mimetype,'video/',strlen('image/'))==0 || $attachment->mimetype="application/ogg"){
|
||||||
|
$fbmedia['type']='video';
|
||||||
|
$fbmedia['video_src']=$attachment->url;
|
||||||
|
// http://wiki.developers.facebook.com/index.php/Attachment_%28Streams%29
|
||||||
|
// says that preview_img is required... but we have no value to put in it
|
||||||
|
// $fbmedia['preview_img']=$attachment->url;
|
||||||
|
if($attachment->title){
|
||||||
|
$fbmedia['video_title']=$attachment->title;
|
||||||
|
}
|
||||||
|
$fbmedia['video_type']=$attachment->mimetype;
|
||||||
|
$fbattachment['media'][]=$fbmedia;
|
||||||
|
*/
|
||||||
|
}else if($attachment->mimetype=='audio/mpeg'){
|
||||||
|
$fbmedia['type']='mp3';
|
||||||
|
$fbmedia['src']=$attachment->url;
|
||||||
|
$fbattachment['media'][]=$fbmedia;
|
||||||
|
}else if($attachment->mimetype=='application/x-shockwave-flash'){
|
||||||
|
$fbmedia['type']='flash';
|
||||||
|
// http://wiki.developers.facebook.com/index.php/Attachment_%28Streams%29
|
||||||
|
// says that imgsrc is required... but we have no value to put in it
|
||||||
|
// $fbmedia['imgsrc']='';
|
||||||
|
$fbmedia['swfsrc']=$attachment->url;
|
||||||
|
$fbattachment['media'][]=$fbmedia;
|
||||||
|
}else{
|
||||||
|
$fbattachment['name']=($attachment->title?$attachment->title:$attachment->url);
|
||||||
|
$fbattachment['href']=$attachment->url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$facebook->api_client->stream_publish($status, $fbattachment, null, null, $fbuid);
|
||||||
|
}else{
|
||||||
|
$facebook->api_client->users_setStatus($status, $fbuid, false, true);
|
||||||
|
}
|
||||||
} catch(FacebookRestClientException $e) {
|
} catch(FacebookRestClientException $e) {
|
||||||
common_log(LOG_ERR, $e->getMessage());
|
common_log(LOG_ERR, $e->getMessage());
|
||||||
common_log(LOG_ERR,
|
common_log(LOG_ERR,
|
||||||
@ -150,7 +203,7 @@ function facebookBroadcastNotice($notice)
|
|||||||
if ($code >= 200) {
|
if ($code >= 200) {
|
||||||
|
|
||||||
// 200 The application does not have permission to operate on the passed in uid parameter.
|
// 200 The application does not have permission to operate on the passed in uid parameter.
|
||||||
// 250 Updating status requires the extended permission status_update.
|
// 250 Updating status requires the extended permission status_update or publish_stream.
|
||||||
// see: http://wiki.developers.facebook.com/index.php/Users.setStatus#Example_Return_XML
|
// see: http://wiki.developers.facebook.com/index.php/Users.setStatus#Example_Return_XML
|
||||||
|
|
||||||
remove_facebook_app($flink);
|
remove_facebook_app($flink);
|
||||||
|
Loading…
Reference in New Issue
Block a user