summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--actions/api.php2
-rw-r--r--actions/twitapigroups.php97
-rw-r--r--actions/twitapitags.php4
-rw-r--r--classes/File.php8
-rw-r--r--classes/Notice.php13
-rw-r--r--lib/twitterapi.php46
-rw-r--r--lib/util.php77
7 files changed, 181 insertions, 66 deletions
diff --git a/actions/api.php b/actions/api.php
index 93e33085f..f425a8dcd 100644
--- a/actions/api.php
+++ b/actions/api.php
@@ -133,6 +133,8 @@ class ApiAction extends Action
'groups/show',
'groups/timeline',
'groups/list_all',
+ 'groups/membership',
+ 'groups/is_member',
'groups/timeline');
static $bareauth = array('statuses/user_timeline',
diff --git a/actions/twitapigroups.php b/actions/twitapigroups.php
index 214fa8214..4deb1b764 100644
--- a/actions/twitapigroups.php
+++ b/actions/twitapigroups.php
@@ -21,7 +21,7 @@
*
* @category Twitter
* @package StatusNet
- * @author Craig Andrews
+ * @author Craig Andrews <candrews@integralblue.com>
* @author Zach Copley <zach@status.net>
* @copyright 2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
@@ -41,7 +41,7 @@ require_once INSTALLDIR.'/lib/twitterapi.php';
*
* @category Twitter
* @package StatusNet
- * @author Craig Andrews
+ * @author Craig Andrews <candrews@integralblue.com>
* @author Zach Copley <zach@status.net>
* @copyright 2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
@@ -233,4 +233,97 @@ require_once INSTALLDIR.'/lib/twitterapi.php';
}
}
+ function membership($args, $apidata)
+ {
+ parent::handle($args);
+
+ common_debug("in groups api action");
+
+ $this->auth_user = $apidata['user'];
+ $group = $this->get_group($apidata['api_arg'], $apidata);
+
+ if (empty($group)) {
+ $this->clientError('Not Found', 404, $apidata['content-type']);
+ return;
+ }
+
+ $sitename = common_config('site', 'name');
+ $title = sprintf(_("Members of %s group"), $group->nickname);
+ $taguribase = common_config('integration', 'taguri');
+ $id = "tag:$taguribase:GroupMembership:".$group->id;
+ $link = common_local_url('showgroup',
+ array('nickname' => $group->nickname));
+ $subtitle = sprintf(_('Members of %1$s on %2$s'),
+ $group->nickname, $sitename);
+
+ $page = (int)$this->arg('page', 1);
+ $count = (int)$this->arg('count', 20);
+ $max_id = (int)$this->arg('max_id', 0);
+ $since_id = (int)$this->arg('since_id', 0);
+ $since = $this->arg('since');
+
+ $member = $group->getMembers(($page-1)*$count,
+ $count, $since_id, $max_id, $since);
+
+ switch($apidata['content-type']) {
+ case 'xml':
+ $this->show_twitter_xml_users($member);
+ break;
+ //TODO implement the RSS and ATOM content types
+ /*case 'rss':
+ $this->show_rss_users($member, $title, $link, $subtitle);
+ break;*/
+ /*case 'atom':
+ if (isset($apidata['api_arg'])) {
+ $selfuri = common_root_url() .
+ 'api/statusnet/groups/membership/' .
+ $apidata['api_arg'] . '.atom';
+ } else {
+ $selfuri = common_root_url() .
+ 'api/statusnet/groups/membership.atom';
+ }
+ $this->show_atom_users($member, $title, $id, $link,
+ $subtitle, null, $selfuri);
+ break;*/
+ case 'json':
+ $this->show_json_users($member);
+ break;
+ default:
+ $this->clientError(_('API method not found!'), $code = 404);
+ }
+ }
+
+ function is_member($args, $apidata)
+ {
+ parent::handle($args);
+
+ common_debug("in groups api action");
+
+ $this->auth_user = $apidata['user'];
+ $group = User_group::staticGet($args['group_id']);
+ if(! $group){
+ $this->clientError(_('Group not found'), $code = 500);
+ }
+ $user = User::staticGet('id', $args['user_id']);
+ if(! $user){
+ $this->clientError(_('User not found'), $code = 500);
+ }
+
+ $is_member=$user->isMember($group);
+
+ switch($apidata['content-type']) {
+ case 'xml':
+ $this->init_document('xml');
+ $this->element('is_member', null, $is_member);
+ $this->end_document('xml');
+ break;
+ case 'json':
+ $this->init_document('json');
+ $this->show_json_objects(array('is_member'=>$is_member));
+ $this->end_document('json');
+ break;
+ default:
+ $this->clientError(_('API method not found!'), $code = 404);
+ }
+ }
}
diff --git a/actions/twitapitags.php b/actions/twitapitags.php
index 2bb7ee01a..0bcc55d37 100644
--- a/actions/twitapitags.php
+++ b/actions/twitapitags.php
@@ -21,7 +21,7 @@
*
* @category Twitter
* @package StatusNet
- * @author Craig Andrews
+ * @author Craig Andrews <candrews@integralblue.com>
* @author Zach Copley <zach@status.net>
* @copyright 2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
@@ -41,7 +41,7 @@ require_once INSTALLDIR.'/lib/twitterapi.php';
*
* @category Twitter
* @package StatusNet
- * @author Craig Andrews
+ * @author Craig Andrews <candrews@integralblue.com>
* @author Zach Copley <zach@status.net>
* @copyright 2009 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
diff --git a/classes/File.php b/classes/File.php
index 0cebfc55e..f4d0a3a48 100644
--- a/classes/File.php
+++ b/classes/File.php
@@ -85,7 +85,7 @@ class File extends Memcached_DataObject
return $x;
}
- function processNew($given_url, $notice_id) {
+ function processNew($given_url, $notice_id=null) {
if (empty($given_url)) return -1; // error, no url to process
$given_url = File_redirection::_canonUrl($given_url);
if (empty($given_url)) return -1; // error, no url to process
@@ -96,7 +96,7 @@ class File extends Memcached_DataObject
$redir_data = File_redirection::where($given_url);
$redir_url = $redir_data['url'];
// TODO: max field length
- if ($redir_url === $given_url || strlen($redir_url) > 255) {
+ if ($redir_url === $given_url || strlen($redir_url) > 255) {
$x = File::saveNew($redir_data, $given_url);
$file_id = $x->id;
} else {
@@ -119,7 +119,9 @@ class File extends Memcached_DataObject
}
}
- File_to_post::processNew($file_id, $notice_id);
+ if (!empty($notice_id)) {
+ File_to_post::processNew($file_id, $notice_id);
+ }
return $x;
}
diff --git a/classes/Notice.php b/classes/Notice.php
index e59712864..28d5b8ddf 100644
--- a/classes/Notice.php
+++ b/classes/Notice.php
@@ -58,7 +58,7 @@ class Notice extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
- /* Notice types */
+ /* Notice types */
const LOCAL_PUBLIC = 1;
const REMOTE_OMB = 0;
const LOCAL_NONPUBLIC = -1;
@@ -248,17 +248,6 @@ class Notice extends Memcached_DataObject
$notice->saveUrls();
- // FIXME: why do we have to re-render the content?
- // Remove this if it's not necessary.
-
- $orig2 = clone($notice);
-
- $notice->rendered = common_render_content($final, $notice);
- if (!$notice->update($orig2)) {
- common_log_db_error($notice, 'UPDATE', __FILE__);
- return _('Problem saving notice.');
- }
-
$notice->query('COMMIT');
Event::handle('EndNoticeSave', array($notice));
diff --git a/lib/twitterapi.php b/lib/twitterapi.php
index c8099978f..638efba24 100644
--- a/lib/twitterapi.php
+++ b/lib/twitterapi.php
@@ -791,6 +791,52 @@ class TwitterapiAction extends Action
$this->end_document('xml');
}
+ function show_twitter_xml_users($user)
+ {
+
+ $this->init_document('xml');
+ $this->elementStart('users', array('type' => 'array'));
+
+ if (is_array($user)) {
+ foreach ($group as $g) {
+ $twitter_user = $this->twitter_user_array($g);
+ $this->show_twitter_xml_user($twitter_user,'user');
+ }
+ } else {
+ while ($user->fetch()) {
+ $twitter_user = $this->twitter_user_array($user);
+ $this->show_twitter_xml_user($twitter_user);
+ }
+ }
+
+ $this->elementEnd('users');
+ $this->end_document('xml');
+ }
+
+ function show_json_users($user)
+ {
+
+ $this->init_document('json');
+
+ $users = array();
+
+ if (is_array($user)) {
+ foreach ($user as $u) {
+ $twitter_user = $this->twitter_user_array($u);
+ array_push($users, $twitter_user);
+ }
+ } else {
+ while ($user->fetch()) {
+ $twitter_user = $this->twitter_user_array($user);
+ array_push($users, $twitter_user);
+ }
+ }
+
+ $this->show_json_objects($users);
+
+ $this->end_document('json');
+ }
+
function show_single_json_group($group)
{
$this->init_document('json');
diff --git a/lib/util.php b/lib/util.php
index cedb70873..8a56be55d 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -457,7 +457,7 @@ function callback_helper($matches, $callback, $notice_id) {
$url=$matches[1];
$left = strpos($matches[0],$url);
$right = $left+strlen($url);
-
+
$groupSymbolSets=array(
array(
'left'=>'(',
@@ -491,9 +491,7 @@ function callback_helper($matches, $callback, $notice_id) {
$url=substr($url,0,-1);
}
}while($original_url!=$url);
-
-
-
+
if(empty($notice_id)){
$result = call_user_func_array($callback,$url);
}else{
@@ -508,16 +506,13 @@ function curry($fn) {
array_shift($args);
$id = uniqid('_partial');
$GLOBALS[$id] = array($fn, $args);
- return create_function(
- '',
- '
- $args = func_get_args();
- return call_user_func_array(
- $GLOBALS["'.$id.'"][0],
- array_merge(
- $args,
- $GLOBALS["'.$id.'"][1]));
- ');
+ return create_function('',
+ '$args = func_get_args(); '.
+ 'return call_user_func_array('.
+ '$GLOBALS["'.$id.'"][0],'.
+ 'array_merge('.
+ '$args,'.
+ '$GLOBALS["'.$id.'"][1]));');
}
function common_linkify($url) {
@@ -525,7 +520,7 @@ function common_linkify($url) {
// functions
$url = htmlspecialchars_decode($url);
- if(strpos($url, '@')!==false && strpos($url, ':')===false){
+ if(strpos($url, '@') !== false && strpos($url, ':') === false) {
//url is an email address without the mailto: protocol
return XMLStringer::estring('a', array('href' => "mailto:$url", 'rel' => 'external'), $url);
}
@@ -547,42 +542,30 @@ function common_linkify($url) {
$attachment_id = null;
$has_thumb = false;
- // Check to see whether there's a filename associated with this URL.
- // If there is, it's an upload and qualifies as an attachment
+ // Check to see whether this is a known "attachment" URL.
- $localfile = File::staticGet('url', $longurl);
+ $f = File::staticGet('url', $longurl);
- if (!empty($localfile)) {
- if (isset($localfile->filename)) {
- $is_attachment = true;
- $attachment_id = $localfile->id;
- }
+ if (empty($f)) {
+ // XXX: this writes to the database. :<
+ $f = File::processNew($longurl);
}
- // if this URL is an attachment, then we set class='attachment' and id='attahcment-ID'
- // where ID is the id of the attachment for the given URL.
- //
- // we need a better test telling what can be shown as an attachment
- // we're currently picking up oembeds only.
- // I think the best option is another file_view table in the db
- // and associated dbobject.
-
- $query = "select file_oembed.file_id as file_id from file join file_oembed on file.id = file_oembed.file_id where file.url='$longurl'";
- $file = new File;
- $file->query($query);
- $file->fetch();
-
- if (!empty($file->file_id)) {
- $is_attachment = true;
- $attachment_id = $file->file_id;
-
- $query = "select file_thumbnail.file_id as file_id from file join file_thumbnail on file.id = file_thumbnail.file_id where file.url='$longurl'";
- $file2 = new File;
- $file2->query($query);
- $file2->fetch();
-
- if (!empty($file2)) {
- $has_thumb = true;
+ if (!empty($f)) {
+ if (isset($f->filename)) {
+ $is_attachment = true;
+ $attachment_id = $f->id;
+ } else { // if it has OEmbed info, it's an attachment, too
+ $foe = File_oembed::staticGet('file_id', $f->id);
+ if (!empty($foe)) {
+ $is_attachment = true;
+ $attachment_id = $f->id;
+
+ $thumb = File_thumbnail::staticGet('file_id', $f->id);
+ if (!empty($thumb)) {
+ $has_thumb = true;
+ }
+ }
}
}