summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/facebookaction.php15
-rw-r--r--lib/facebookutil.php61
-rw-r--r--lib/router.php20
-rw-r--r--lib/rssaction.php62
-rw-r--r--lib/twitterapi.php55
5 files changed, 186 insertions, 27 deletions
diff --git a/lib/facebookaction.php b/lib/facebookaction.php
index 1ae90d53b..5be2f2fe6 100644
--- a/lib/facebookaction.php
+++ b/lib/facebookaction.php
@@ -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()
{
@@ -504,7 +494,7 @@ class FacebookAction extends Action
$replyto = $this->trimmed('inreplyto');
$notice = Notice::saveNew($user->id, $content,
- 'Facebook', 1, ($replyto == 'false') ? null : $replyto);
+ 'web', 1, ($replyto == 'false') ? null : $replyto);
if (is_string($notice)) {
$this->showPage($notice);
@@ -514,8 +504,7 @@ class FacebookAction extends Action
common_broadcast_notice($notice);
// Also update the user's Facebook status
- $this->updateFacebookStatus($notice);
- $this->updateProfileBox($notice);
+ facebookBroadcastNotice($notice);
}
diff --git a/lib/facebookutil.php b/lib/facebookutil.php
index 632ec4bad..85077c254 100644
--- a/lib/facebookutil.php
+++ b/lib/facebookutil.php
@@ -86,13 +86,17 @@ function isFacebookBound($notice, $flink) {
// Check to see if the user has given the FB app status update perms
$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) {
$user = $flink->getUser();
$msg = "Not sending notice $notice->id to Facebook " .
"because user $user->nickname hasn't given the " .
- 'Facebook app \'status_update\' permission.';
+ 'Facebook app \'status_update\' or \'publish_stream\' permission.';
common_debug($msg);
$success = false;
}
@@ -138,7 +142,56 @@ function facebookBroadcastNotice($notice)
// Okay, we're good to go, update the FB status
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) {
common_log(LOG_ERR, $e->getMessage());
common_log(LOG_ERR,
@@ -150,7 +203,7 @@ function facebookBroadcastNotice($notice)
if ($code >= 200) {
// 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
remove_facebook_app($flink);
diff --git a/lib/router.php b/lib/router.php
index 75e72f932..e12138637 100644
--- a/lib/router.php
+++ b/lib/router.php
@@ -266,7 +266,7 @@ class Router
$m->connect('api/statuses/:method/:argument',
array('action' => 'api',
'apiaction' => 'statuses'),
- array('method' => '(user_timeline|friends_timeline|replies|mentions|show|destroy|friends|followers)'));
+ array('method' => '(|user_timeline|friends_timeline|replies|mentions|show|destroy|friends|followers)'));
// users
@@ -394,6 +394,24 @@ class Router
array('action' => 'api',
'apiaction' => 'laconica'));
+ // Groups
+ $m->connect('api/laconica/groups/:method/:argument',
+ array('action' => 'api',
+ 'apiaction' => 'groups'));
+
+ $m->connect('api/laconica/groups/:method',
+ array('action' => 'api',
+ 'apiaction' => 'groups'));
+
+ // Tags
+ $m->connect('api/laconica/tags/:method/:argument',
+ array('action' => 'api',
+ 'apiaction' => 'tags'));
+
+ $m->connect('api/laconica/tags/:method',
+ array('action' => 'api',
+ 'apiaction' => 'tags'));
+
// search
$m->connect('api/search.atom', array('action' => 'twitapisearchatom'));
$m->connect('api/search.json', array('action' => 'twitapisearchjson'));
diff --git a/lib/rssaction.php b/lib/rssaction.php
index 15c238bf9..40fe11c66 100644
--- a/lib/rssaction.php
+++ b/lib/rssaction.php
@@ -229,6 +229,24 @@ class Rss10Action extends Action
}
}
+ // XXX: Surely there should be a common function to do this?
+ function extract_tags ($string)
+ {
+ $count = preg_match_all('/(?:^|\s)#([A-Za-z0-9_\-\.]{1,64})/', strtolower($string), $match);
+ if (!count)
+ {
+ return array();
+ }
+
+ $rv = array();
+ foreach ($match[1] as $tag)
+ {
+ $rv[] = common_canonical_tag($tag);
+ }
+
+ return array_unique($rv);
+ }
+
function showItem($notice)
{
$profile = Profile::staticGet($notice->profile_id);
@@ -256,10 +274,46 @@ class Rss10Action extends Action
$attachments = $notice->attachments();
if($attachments){
foreach($attachments as $attachment){
- $this->element('enc:enclosure', array('rdf:resource'=>$attachment->url,'enc:type'=>$attachment->mimetype,'enc:length'=>$attachment->size), null);
+ if ($attachment->isEnclosure()) {
+ // DO NOT move xmlns declaration to root element. Making it
+ // the default namespace here improves compatibility with
+ // real-world feed readers.
+ $attribs = array(
+ 'rdf:resource' => $attachment->url,
+ 'url' => $attachment->url,
+ 'xmlns' => 'http://purl.oclc.org/net/rss_2.0/enc#'
+ );
+ if ($attachment->title) {
+ $attribs['dc:title'] = $attachment->title;
+ }
+ if ($attachment->modified) {
+ $attribs['dc:date'] = common_date_w3dtf($attachment->modified);
+ }
+ if ($attachment->size) {
+ $attribs['length'] = $attachment->size;
+ }
+ if ($attachment->mimetype) {
+ $attribs['type'] = $attachment->mimetype;
+ }
+ $this->element('enclosure', $attribs);
+ }
+ $this->element('sioc:links_to', array('rdf:resource'=>$attachment->url));
+ }
+ }
+ $tags = $this->extract_tags($notice->content);
+ if (!empty($tags)) {
+ foreach ($tags as $tag)
+ {
+ $tagpage = common_local_url('tag', array('tag' => $tag));
+ $tagrss = common_local_url('tagrss', array('tag' => $tag));
+ $this->elementStart('ctag:tagged');
+ $this->elementStart('ctag:Tag', array('rdf:about'=>$tagpage.'#concept', 'ctag:label'=>$tag));
+ $this->element('foaf:page', array('rdf:resource'=>$tagpage));
+ $this->element('rdfs:seeAlso', array('rdf:resource'=>$tagrss));
+ $this->elementEnd('ctag:Tag');
+ $this->elementEnd('ctag:tagged');
}
}
-
$this->elementEnd('item');
$this->creators[$creator_uri] = $profile;
}
@@ -295,8 +349,8 @@ class Rss10Action extends Action
'http://creativecommons.org/ns#',
'xmlns:content' =>
'http://purl.org/rss/1.0/modules/content/',
- 'xmlns:enc' =>
- 'http://purl.oclc.org/net/rss_2.0/enc#',
+ 'xmlns:ctag' =>
+ 'http://commontag.org/ns#',
'xmlns:foaf' =>
'http://xmlns.com/foaf/0.1/',
'xmlns:sioc' =>
diff --git a/lib/twitterapi.php b/lib/twitterapi.php
index f48513e67..749083c7c 100644
--- a/lib/twitterapi.php
+++ b/lib/twitterapi.php
@@ -186,6 +186,21 @@ class TwitterapiAction extends Action
$twitter_status['favorited'] = false;
}
+ # Enclosures
+ $attachments = $notice->attachments();
+ $twitter_status['attachments']=array();
+ if($attachments){
+ foreach($attachments as $attachment){
+ if ($attachment->isEnclosure()) {
+ $enclosure=array();
+ $enclosure['url']=$attachment->url;
+ $enclosure['mimetype']=$attachment->mimetype;
+ $enclosure['size']=$attachment->size;
+ $twitter_status['attachments'][]=$enclosure;
+ }
+ }
+ }
+
if ($include_user) {
# Don't get notice (recursive!)
$twitter_user = $this->twitter_user_array($profile, false);
@@ -218,11 +233,13 @@ class TwitterapiAction extends Action
if($attachments){
$entry['enclosures']=array();
foreach($attachments as $attachment){
- $enclosure=array();
- $enclosure['url']=$attachment->url;
- $enclosure['mimetype']=$attachment->mimetype;
- $enclosure['size']=$attachment->size;
- $entry['enclosures'][]=$enclosure;
+ if ($attachment->isEnclosure()) {
+ $enclosure=array();
+ $enclosure['url']=$attachment->url;
+ $enclosure['mimetype']=$attachment->mimetype;
+ $enclosure['size']=$attachment->size;
+ $entry['enclosures'][]=$enclosure;
+ }
}
}
@@ -774,6 +791,34 @@ class TwitterapiAction extends Action
}
}
+ function get_group($id, $apidata=null)
+ {
+ if (empty($id)) {
+
+ if (is_numeric($this->arg('id'))) {
+ return User_group::staticGet($this->arg('id'));
+ } else if ($this->arg('id')) {
+ $nickname = common_canonical_nickname($this->arg('id'));
+ return User_group::staticGet('nickname', $nickname);
+ } else if ($this->arg('group_id')) {
+ // This is to ensure that a non-numeric user_id still
+ // overrides screen_name even if it doesn't get used
+ if (is_numeric($this->arg('group_id'))) {
+ return User_group::staticGet('id', $this->arg('group_id'));
+ }
+ } else if ($this->arg('group_name')) {
+ $nickname = common_canonical_nickname($this->arg('group_name'));
+ return User_group::staticGet('nickname', $nickname);
+ }
+
+ } else if (is_numeric($id)) {
+ return User_group::staticGet($id);
+ } else {
+ $nickname = common_canonical_nickname($id);
+ return User_group::staticGet('nickname', $nickname);
+ }
+ }
+
function get_profile($id)
{
if (is_numeric($id)) {