Support multiple attachments per facebook update
This commit is contained in:
parent
0b884ed915
commit
b7beac36c2
@ -178,20 +178,38 @@ function format_attachments($attachments)
|
|||||||
$fbattachment = array();
|
$fbattachment = array();
|
||||||
$fbattachment['media'] = array();
|
$fbattachment['media'] = array();
|
||||||
|
|
||||||
// Facebook only supports one attachment per item
|
foreach($attachments as $attachment)
|
||||||
|
{
|
||||||
|
$fbmedia = get_fbmedia_for_attachment($attachment);
|
||||||
|
if($fbmedia){
|
||||||
|
$fbattachment['media'][]=$fbmedia;
|
||||||
|
}else{
|
||||||
|
$fbattachment['name'] = ($attachment->title ?
|
||||||
|
$attachment->title : $attachment->url);
|
||||||
|
$fbattachment['href'] = $attachment->url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(count($fbattachment['media'])>0){
|
||||||
|
unset($fbattachment['name']);
|
||||||
|
unset($fbattachment['href']);
|
||||||
|
}
|
||||||
|
return $fbattachment;
|
||||||
|
}
|
||||||
|
|
||||||
$attachment = $attachments[0];
|
/**
|
||||||
|
* given an File objects, returns an associative array suitable for Facebook media
|
||||||
|
*/
|
||||||
|
function get_fbmedia_for_attachment($attachment)
|
||||||
|
{
|
||||||
$fbmedia = array();
|
$fbmedia = array();
|
||||||
|
|
||||||
if (strncmp($attachment->mimetype, 'image/', strlen('image/')) == 0) {
|
if (strncmp($attachment->mimetype, 'image/', strlen('image/')) == 0) {
|
||||||
$fbmedia['type'] = 'image';
|
$fbmedia['type'] = 'image';
|
||||||
$fbmedia['src'] = $attachment->url;
|
$fbmedia['src'] = $attachment->url;
|
||||||
$fbmedia['href'] = $attachment->url;
|
$fbmedia['href'] = $attachment->url;
|
||||||
$fbattachment['media'][] = $fbmedia;
|
|
||||||
} else if ($attachment->mimetype == 'audio/mpeg') {
|
} else if ($attachment->mimetype == 'audio/mpeg') {
|
||||||
$fbmedia['type'] = 'mp3';
|
$fbmedia['type'] = 'mp3';
|
||||||
$fbmedia['src'] = $attachment->url;
|
$fbmedia['src'] = $attachment->url;
|
||||||
$fbattachment['media'][] = $fbmedia;
|
|
||||||
}else if ($attachment->mimetype == 'application/x-shockwave-flash') {
|
}else if ($attachment->mimetype == 'application/x-shockwave-flash') {
|
||||||
$fbmedia['type'] = 'flash';
|
$fbmedia['type'] = 'flash';
|
||||||
|
|
||||||
@ -200,14 +218,10 @@ function format_attachments($attachments)
|
|||||||
// $fbmedia['imgsrc']='';
|
// $fbmedia['imgsrc']='';
|
||||||
|
|
||||||
$fbmedia['swfsrc'] = $attachment->url;
|
$fbmedia['swfsrc'] = $attachment->url;
|
||||||
$fbattachment['media'][] = $fbmedia;
|
|
||||||
}else{
|
}else{
|
||||||
$fbattachment['name'] = ($attachment->title ?
|
return false;
|
||||||
$attachment->title : $attachment->url);
|
|
||||||
$fbattachment['href'] = $attachment->url;
|
|
||||||
}
|
}
|
||||||
|
return $fbmedia;
|
||||||
return $fbattachment;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function remove_facebook_app($flink)
|
function remove_facebook_app($flink)
|
||||||
|
Loading…
Reference in New Issue
Block a user