From 7845fe3100375f0dc7c2515cfa935187efa1c0c8 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 16 Jun 2009 21:00:53 -0700 Subject: typos in README; dependencies --- README | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README b/README index 57ff72f66..3279f7bba 100644 --- a/README +++ b/README @@ -178,8 +178,8 @@ and the URLs are listed here for your convenience. - Facebook library. Used for the Facebook application. - PEAR Services_oEmbed. Used for some multimedia integration. - PEAR HTTP_Request is an oEmbed dependency. -- PEAR Validat is an oEmbed dependency.e -- PEAR Net_URL is an oEmbed dependency.2 +- PEAR Validate is an oEmbed dependency. +- PEAR Net_URL2 is an oEmbed dependency. A design goal of Laconica is that the basic Web functionality should work on even the most restrictive commercial hosting services. -- cgit v1.2.3-54-g00ecf From 90b2b3f9d19196a6961fb7a115b48b2cbdf966ce Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 16 Jun 2009 21:37:04 -0700 Subject: names for Notice is_local states --- classes/Notice.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/classes/Notice.php b/classes/Notice.php index 68602b1f7..333832d0b 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -29,6 +29,11 @@ require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; define('NOTICE_CACHE_WINDOW', 61); +define('NOTICE_LOCAL_PUBLIC', 1); +define('NOTICE_REMOTE_OMB', 0); +define('NOTICE_LOCAL_NONPUBLIC', -1); +define('NOTICE_GATEWAY', -2); + class Notice extends Memcached_DataObject { ###START_AUTOCODE @@ -793,7 +798,7 @@ class Notice extends Memcached_DataObject $inbox = new Notice_inbox(); $UT = common_config('db','type')=='pgsql'?'"user"':'user'; $qry = 'INSERT INTO notice_inbox (user_id, notice_id, created, source) ' . - "SELECT $UT.id, " . $this->id . ", '" . $this->created . "', 2 " . + "SELECT $UT.id, " . $this->id . ", '" . $this->created . "', " . NOTICE_INBOX_SOURCE_GROUP . " " . "FROM $UT JOIN group_member ON $UT.id = group_member.profile_id " . 'WHERE group_member.group_id = ' . $group->id . ' ' . 'AND NOT EXISTS (SELECT user_id, notice_id ' . -- cgit v1.2.3-54-g00ecf From 312fd855324b680c45b71c683b9589f24e1b31a9 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 16 Jun 2009 21:37:19 -0700 Subject: names for Notice_inbox source values --- classes/Notice_inbox.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/classes/Notice_inbox.php b/classes/Notice_inbox.php index 673e187c7..367a35f1f 100644 --- a/classes/Notice_inbox.php +++ b/classes/Notice_inbox.php @@ -25,6 +25,10 @@ require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; define('INBOX_CACHE_WINDOW', 101); +define('NOTICE_INBOX_SOURCE_SUB', 1); +define('NOTICE_INBOX_SOURCE_GROUP', 2); +define('NOTICE_INBOX_SOURCE_GATEWAY', -1); + class Notice_inbox extends Memcached_DataObject { ###START_AUTOCODE -- cgit v1.2.3-54-g00ecf From 0e4d8c416db4c838e94df3df77c2e4b14a0e1851 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Wed, 17 Jun 2009 07:49:41 +0000 Subject: Removed NoticeHover from JavaScript for speed gain. Using CSS instead to handle the notice hover state. The difference is only seen in the conversation page. --- js/util.js | 13 +------------ theme/default/css/display.css | 13 +++++++------ theme/identica/css/display.css | 13 +++++++------ 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/js/util.js b/js/util.js index fd2500d44..ce0c20d31 100644 --- a/js/util.js +++ b/js/util.js @@ -230,21 +230,10 @@ $(document).ready(function(){ }; $("#form_notice").ajaxForm(PostNotice); $("#form_notice").each(addAjaxHidden); - NoticeHover(); NoticeReply(); NoticeAttachments(); }); - -function NoticeHover() { - function mouseHandler(e) { - $(e.target).closest('li.hentry')[(e.type === 'mouseover') ? 'addClass' : 'removeClass']('hover'); - }; - $('#content .notices').mouseover(mouseHandler); - $('#content .notices').mouseout(mouseHandler); -} - - function NoticeReply() { if ($('#notice_data-text').length > 0) { $('#content .notice').each(function() { @@ -319,4 +308,4 @@ function NoticeAttachments() { $(this).closest(".entry-title").removeClass('ov'); } ); -} +} \ No newline at end of file diff --git a/theme/default/css/display.css b/theme/default/css/display.css index f0d6dace8..8dd5ca32c 100644 --- a/theme/default/css/display.css +++ b/theme/default/css/display.css @@ -226,13 +226,11 @@ background:transparent url(../../base/images/icons/twotone/green/trash.gif) no-r } .notices div.entry-content, -.notices div.notice-options, -.notices li.hover .notices div.entry-content, -.notices li.hover .notices div.notice-options { +.notices div.notice-options { opacity:0.4; } -.notices li.hover div.entry-content, -.notices li.hover div.notice-options { +.notices li:hover div.entry-content, +.notices li:hover div.notice-options { opacity:1; } div.entry-content { @@ -242,9 +240,12 @@ div.notice-options a, div.notice-options input { font-family:sans-serif; } -.notices li.hover { +.notices li:hover { background-color:#FCFCFC; } +#conversation .notices li:hover { +background-color:transparent; +} .notices .notices { background-color:rgba(200, 200, 200, 0.050); diff --git a/theme/identica/css/display.css b/theme/identica/css/display.css index 25a01abe0..975702faa 100644 --- a/theme/identica/css/display.css +++ b/theme/identica/css/display.css @@ -226,13 +226,11 @@ background:transparent url(../../base/images/icons/twotone/green/trash.gif) no-r } .notices div.entry-content, -.notices div.notice-options, -.notices li.hover .notices div.entry-content, -.notices li.hover .notices div.notice-options { +.notices div.notice-options { opacity:0.4; } -.notices li.hover div.entry-content, -.notices li.hover div.notice-options { +.notices li:hover div.entry-content, +.notices li:hover div.notice-options { opacity:1; } div.entry-content { @@ -242,9 +240,12 @@ div.notice-options a, div.notice-options input { font-family:sans-serif; } -.notices li.hover { +.notices li:hover { background-color:#FCFCFC; } +#conversation .notices li:hover { +background-color:transparent; +} .notices .notices { background-color:rgba(200, 200, 200, 0.050); -- cgit v1.2.3-54-g00ecf From 4c640aace978a2a57b6d2d4658febde3f9826efa Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Wed, 17 Jun 2009 08:14:01 +0000 Subject: Updated markup yes/no form actions to be consistent with the rest of the site --- actions/block.php | 17 ++++++++++------- actions/groupblock.php | 17 ++++++++++------- theme/base/css/display.css | 3 ++- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/actions/block.php b/actions/block.php index 0efee5932..441016d4e 100644 --- a/actions/block.php +++ b/actions/block.php @@ -125,16 +125,18 @@ class BlockAction extends Action function areYouSureForm() { $id = $this->profile->id; + $this->elementStart('form', array('id' => 'block-' . $id, + 'method' => 'post', + 'class' => 'form_settings form_entity_block', + 'action' => common_local_url('block'))); + $this->elementStart('fieldset'); + $this->hidden('token', common_session_token()); + $this->element('legend', _('Block user')); $this->element('p', null, _('Are you sure you want to block this user? '. 'Afterwards, they will be unsubscribed from you, '. 'unable to subscribe to you in the future, and '. 'you will not be notified of any @-replies from them.')); - $this->elementStart('form', array('id' => 'block-' . $id, - 'method' => 'post', - 'class' => 'block', - 'action' => common_local_url('block'))); - $this->hidden('token', common_session_token()); $this->element('input', array('id' => 'blockto-' . $id, 'name' => 'blockto', 'type' => 'hidden', @@ -144,8 +146,9 @@ class BlockAction extends Action $this->hidden($k, $v); } } - $this->submit('no', _('No')); - $this->submit('yes', _('Yes')); + $this->submit('form_action-no', _('No'), 'submit form_action-primary', 'no', _("Do not block this user from this group")); + $this->submit('form_action-yes', _('Yes'), 'submit form_action-secondary', 'yes', _('Block this user from this group')); + $this->elementEnd('fieldset'); $this->elementEnd('form'); } diff --git a/actions/groupblock.php b/actions/groupblock.php index 93662da79..28685b1d5 100644 --- a/actions/groupblock.php +++ b/actions/groupblock.php @@ -151,17 +151,19 @@ class GroupblockAction extends Action function areYouSureForm() { $id = $this->profile->id; + $this->elementStart('form', array('id' => 'block-' . $id, + 'method' => 'post', + 'class' => 'form_settings form_entity_block', + 'action' => common_local_url('groupblock'))); + $this->elementStart('fieldset'); + $this->hidden('token', common_session_token()); + $this->element('legend', null, _('Block user')); $this->element('p', null, sprintf(_('Are you sure you want to block user "%s" from the group "%s"? '. 'They will be removed from the group, unable to post, and '. 'unable to subscribe to the group in the future.'), $this->profile->getBestName(), $this->group->getBestName())); - $this->elementStart('form', array('id' => 'block-' . $id, - 'method' => 'post', - 'class' => 'block', - 'action' => common_local_url('groupblock'))); - $this->hidden('token', common_session_token()); $this->hidden('blockto-' . $this->profile->id, $this->profile->id, 'blockto'); @@ -173,8 +175,9 @@ class GroupblockAction extends Action $this->hidden($k, $v); } } - $this->submit('no', _('No')); - $this->submit('yes', _('Yes')); + $this->submit('form_action-no', _('No'), 'submit form_action-primary', 'no', _("Do not block this user from this group")); + $this->submit('form_action-yes', _('Yes'), 'submit form_action-secondary', 'yes', _('Block this user from this group')); + $this->elementEnd('fieldset'); $this->elementEnd('form'); } diff --git a/theme/base/css/display.css b/theme/base/css/display.css index 49907058e..403a9c37f 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -154,7 +154,8 @@ font-weight:bold; #form_invite legend, #form_notice_delete legend, #form_password_recover legend, -#form_password_change legend { +#form_password_change legend, +.form_entity_block legend { display:none; } -- cgit v1.2.3-54-g00ecf From 85a4e32f30fcc1b081cde7c8e0267b4fd0c83e16 Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Wed, 17 Jun 2009 09:03:59 +0000 Subject: Updated input submit for making a user admin of a group --- theme/base/css/display.css | 3 ++- theme/base/images/icons/twotone/green/admin.gif | Bin 0 -> 100 bytes theme/default/css/display.css | 9 +++++++-- theme/identica/css/display.css | 9 +++++++-- 4 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 theme/base/images/icons/twotone/green/admin.gif diff --git a/theme/base/css/display.css b/theme/base/css/display.css index 403a9c37f..9e35d015d 100644 --- a/theme/base/css/display.css +++ b/theme/base/css/display.css @@ -622,7 +622,8 @@ display:block; .entity_send-a-message a, .entity_edit a, .form_user_nudge input.submit, -.entity_nudge p { +.entity_nudge p, +.form_make_admin input.submit { border:0; padding-left:20px; } diff --git a/theme/base/images/icons/twotone/green/admin.gif b/theme/base/images/icons/twotone/green/admin.gif new file mode 100644 index 000000000..10fa431ce Binary files /dev/null and b/theme/base/images/icons/twotone/green/admin.gif differ diff --git a/theme/default/css/display.css b/theme/default/css/display.css index 8dd5ca32c..935116a74 100644 --- a/theme/default/css/display.css +++ b/theme/default/css/display.css @@ -65,7 +65,8 @@ div.notice-options input, .entity_send-a-message a, .form_user_nudge input.submit, .entity_nudge p, -.form_settings input.form_action-primary { +.form_settings input.form_action-primary, +.form_make_admin input.submit { color:#002E6E; } @@ -166,7 +167,8 @@ background-image:url(../../base/images/icons/icon_foaf.gif); .form_user_unblock input.submit, .form_group_block input.submit, .form_group_unblock input.submit, -.entity_nudge p { +.entity_nudge p, +.form_make_admin input.submit { background-position: 0 40%; background-repeat: no-repeat; background-color:transparent; @@ -200,6 +202,9 @@ background-image:url(../../base/images/icons/twotone/green/mail.gif); .form_group_unblock input.submit { background-image:url(../../base/images/icons/twotone/green/shield.gif); } +.form_make_admin input.submit { +background-image:url(../../base/images/icons/twotone/green/admin.gif); +} /* NOTICES */ .notice .attachment { diff --git a/theme/identica/css/display.css b/theme/identica/css/display.css index 975702faa..6845fda5f 100644 --- a/theme/identica/css/display.css +++ b/theme/identica/css/display.css @@ -65,7 +65,8 @@ div.notice-options input, .entity_send-a-message a, .form_user_nudge input.submit, .entity_nudge p, -.form_settings input.form_action-primary { +.form_settings input.form_action-primary, +.form_make_admin input.submit { color:#002E6E; } @@ -166,7 +167,8 @@ background-image:url(../../base/images/icons/icon_foaf.gif); .form_user_unblock input.submit, .form_group_block input.submit, .form_group_unblock input.submit, -.entity_nudge p { +.entity_nudge p, +.form_make_admin input.submit { background-position: 0 40%; background-repeat: no-repeat; background-color:transparent; @@ -200,6 +202,9 @@ background-image:url(../../base/images/icons/twotone/green/mail.gif); .form_group_unblock input.submit { background-image:url(../../base/images/icons/twotone/green/shield.gif); } +.form_make_admin input.submit { +background-image:url(../../base/images/icons/twotone/green/admin.gif); +} /* NOTICES */ .notice .attachment { -- cgit v1.2.3-54-g00ecf From 2fbd141361b6ddab0e036b52fc23f2bfcdfd0075 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 17 Jun 2009 08:21:53 -0700 Subject: correct arguments for ProfileList --- actions/featured.php | 5 ++--- actions/peopletag.php | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/actions/featured.php b/actions/featured.php index 79eba2aa6..04365687d 100644 --- a/actions/featured.php +++ b/actions/featured.php @@ -32,7 +32,7 @@ if (!defined('LACONICA')) { exit(1); } -require_once(INSTALLDIR.'/lib/profilelist.php'); +require_once INSTALLDIR.'/lib/profilelist.php'; require_once INSTALLDIR.'/lib/publicgroupnav.php'; /** @@ -107,7 +107,6 @@ class FeaturedAction extends Action $featured_nicks = common_config('nickname', 'featured'); - if (count($featured_nicks) > 0) { $quoted = array(); @@ -136,7 +135,7 @@ class FeaturedAction extends Action $cnt = $profile->find(); if ($cnt > 0) { - $featured = new ProfileList($profile, null, $this); + $featured = new ProfileList($profile, $this); $featured->show(); } diff --git a/actions/peopletag.php b/actions/peopletag.php index 5add75485..dd3c1c089 100644 --- a/actions/peopletag.php +++ b/actions/peopletag.php @@ -124,7 +124,7 @@ class PeopletagAction extends Action $profile->query(sprintf($qry, $this->tag, $lim)); - $pl = new ProfileList($profile, null, $this); + $pl = new ProfileList($profile, $this); $cnt = $pl->show(); $this->pagination($this->page > 1, -- cgit v1.2.3-54-g00ecf From 1505e3a4c3dda7030bb92a2071ec58af2972bed7 Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Wed, 17 Jun 2009 16:21:50 -0400 Subject: Fixed recent attachment bug that required URLs to be posted twice to be taken into account. --- classes/File.php | 2 -- classes/Notice.php | 8 ++++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/classes/File.php b/classes/File.php index 24ab11b8e..08320faf8 100644 --- a/classes/File.php +++ b/classes/File.php @@ -79,7 +79,6 @@ class File extends Memcached_DataObject && ('text/html' === substr($redir_data['type'], 0, 9)) && ($oembed_data = File_oembed::_getOembed($given_url)) && isset($oembed_data['json'])) { - File_oembed::saveNew($oembed_data['json'], $file_id); } return $x; @@ -98,7 +97,6 @@ class File extends Memcached_DataObject if ($redir_url === $given_url) { $x = File::saveNew($redir_data, $given_url); $file_id = $x->id; - } else { $x = File::processNew($redir_url, $notice_id); $file_id = $x->id; diff --git a/classes/Notice.php b/classes/Notice.php index 770b5d78b..e0bb90ba6 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -218,6 +218,12 @@ class Notice extends Memcached_DataObject $notice->addToInboxes(); $notice->saveGroups(); $notice->saveUrls(); + $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'); @@ -237,8 +243,6 @@ class Notice extends Memcached_DataObject * follow redirects and save all available file information * (mimetype, date, size, oembed, etc.) * - * @param class $notice Notice to pull URLs from - * * @return void */ function saveUrls() { -- cgit v1.2.3-54-g00ecf From 28d02ec8cdd0278c802c8fee30acddecca9ca01f Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Wed, 17 Jun 2009 16:44:33 -0400 Subject: Make oohembed endpoint configurable. --- README | 8 ++++++++ classes/File_oembed.php | 2 +- config.php.sample | 1 + lib/common.php | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README b/README index 3279f7bba..7b22e3c5e 100644 --- a/README +++ b/README @@ -1246,6 +1246,14 @@ Options for group functionality. maxaliases: maximum number of aliases a group can have. Default 3. Set to 0 or less to prevent aliases in a group. + +oohembed +-------- + +oEmbed endpoint for multimedia attachments (links in posts). + +endpoint: oohembed endpoint using http://oohembed.com/ software. + Troubleshooting =============== diff --git a/classes/File_oembed.php b/classes/File_oembed.php index f1b2cb13c..6bf972f8f 100644 --- a/classes/File_oembed.php +++ b/classes/File_oembed.php @@ -53,7 +53,7 @@ class File_oembed extends Memcached_DataObject function _getOembed($url, $maxwidth = 500, $maxheight = 400, $format = 'json') { - $cmd = 'http://oohembed.com/oohembed/?url=' . urlencode($url); + $cmd = common_config('oohembed', 'endpoint') . '?url=' . urlencode($url); if (is_int($maxwidth)) $cmd .= "&maxwidth=$maxwidth"; if (is_int($maxheight)) $cmd .= "&maxheight=$maxheight"; if (is_string($format)) $cmd .= "&format=$format"; diff --git a/config.php.sample b/config.php.sample index 636f4cf8e..ed70f85fb 100644 --- a/config.php.sample +++ b/config.php.sample @@ -223,3 +223,4 @@ $config['sphinx']['port'] = 3312; // $config['attachments']['user_quota'] = 50000000; // $config['attachments']['monthly_quota'] = 15000000; +// $config['oohembed']['endpoint'] = 'http://oohembed.com/oohembed/'; diff --git a/lib/common.php b/lib/common.php index 51204cede..9c015a15d 100644 --- a/lib/common.php +++ b/lib/common.php @@ -203,6 +203,7 @@ $config = ), 'group' => array('maxaliases' => 3), + 'oohembed' => array('endpoint' => 'http://oohembed.com/oohembed/') ); $config['db'] = &PEAR::getStaticProperty('DB_DataObject','options'); -- cgit v1.2.3-54-g00ecf From b58dc5e96117bdb4de899d37c6eb94ebf1c3dfe6 Mon Sep 17 00:00:00 2001 From: Robin Millette Date: Wed, 17 Jun 2009 16:55:01 -0400 Subject: Added config option to enable or disable file uploads with notices. --- README | 1 + config.php.sample | 1 + lib/common.php | 1 + lib/noticeform.php | 18 +++++++++++------- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/README b/README index 7b22e3c5e..5aa7270ee 100644 --- a/README +++ b/README @@ -1223,6 +1223,7 @@ supported: an array of mime types you accept to store and distribute, like 'image/gif', 'video/mpeg', 'audio/mpeg', etc. Make sure you setup your server to properly reckognize the types you want to support. +uploads: false to disable uploading files with notices (true by default). For quotas, be sure you've set the upload_max_filesize and post_max_size in php.ini to be large enough to handle your upload. In httpd.conf diff --git a/config.php.sample b/config.php.sample index ed70f85fb..7649c5262 100644 --- a/config.php.sample +++ b/config.php.sample @@ -222,5 +222,6 @@ $config['sphinx']['port'] = 3312; // $config['attachments']['file_quota'] = 5000000; // $config['attachments']['user_quota'] = 50000000; // $config['attachments']['monthly_quota'] = 15000000; +// $config['attachments']['uploads'] = true; // $config['oohembed']['endpoint'] = 'http://oohembed.com/oohembed/'; diff --git a/lib/common.php b/lib/common.php index 9c015a15d..bbd9f78c3 100644 --- a/lib/common.php +++ b/lib/common.php @@ -200,6 +200,7 @@ $config = 'file_quota' => 5000000, 'user_quota' => 50000000, 'monthly_quota' => 15000000, + 'uploads' => true, ), 'group' => array('maxaliases' => 3), diff --git a/lib/noticeform.php b/lib/noticeform.php index 0ad365856..a36b7f31f 100644 --- a/lib/noticeform.php +++ b/lib/noticeform.php @@ -90,7 +90,9 @@ class NoticeForm extends Form $this->user = common_current_user(); } - $this->enctype = 'multipart/form-data'; + if (common_config('attachments', 'uploads')) { + $this->enctype = 'multipart/form-data'; + } } /** @@ -148,12 +150,14 @@ class NoticeForm extends Form $this->out->element('dd', array('id' => 'notice_text-count'), '140'); $this->out->elementEnd('dl'); - $this->out->element('label', array('for' => 'notice_data-attach'),_('Attach')); - $this->out->element('input', array('id' => 'notice_data-attach', - 'type' => 'file', - 'name' => 'attach', - 'title' => _('Attach a file'))); - $this->out->hidden('MAX_FILE_SIZE', common_config('attachments', 'file_quota')); + if (common_config('attachments', 'uploads')) { + $this->out->hidden('MAX_FILE_SIZE', common_config('attachments', 'file_quota')); + $this->out->element('label', array('for' => 'notice_data-attach'),_('Attach')); + $this->out->element('input', array('id' => 'notice_data-attach', + 'type' => 'file', + 'name' => 'attach', + 'title' => _('Attach a file'))); + } if ($this->action) { $this->out->hidden('notice_return-to', $this->action, 'returnto'); } -- cgit v1.2.3-54-g00ecf From 7e25a7f3aa2a308ddfc141e2e88fd52c042cb931 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Wed, 17 Jun 2009 14:32:36 -0700 Subject: Output XML and JSON error msgs for API calls --- lib/twitterapi.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/twitterapi.php b/lib/twitterapi.php index 569bc6d7a..269b60efc 100644 --- a/lib/twitterapi.php +++ b/lib/twitterapi.php @@ -545,7 +545,7 @@ class TwitterapiAction extends Action $this->init_twitter_atom(); break; default: - $this->client_error(_('Not a supported data format.')); + $this->clientError(_('Not a supported data format.')); break; } @@ -573,13 +573,13 @@ class TwitterapiAction extends Action $this->end_twitter_rss(); break; default: - $this->client_error(_('Not a supported data format.')); + $this->clientError(_('Not a supported data format.')); break; } return; } - function client_error($msg, $code = 400, $content_type = 'json') + function clientError($msg, $code = 400, $content_type = 'json') { static $status = array(400 => 'Bad Request', @@ -666,7 +666,7 @@ class TwitterapiAction extends Action $this->show_json_objects($profile_array); break; default: - $this->client_error(_('Not a supported data format.')); + $this->clientError(_('Not a supported data format.')); return; } return; -- cgit v1.2.3-54-g00ecf From 8992e8fa7a3c694cc9d424b3e50cf4d87519fa28 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Wed, 17 Jun 2009 14:34:04 -0700 Subject: Ticket 1612 - make destory (and create) favorites work via API --- actions/twitapifavorites.php | 65 +++++++++++++++++++++++++++++++++++++++----- lib/router.php | 3 +- 2 files changed, 60 insertions(+), 8 deletions(-) diff --git a/actions/twitapifavorites.php b/actions/twitapifavorites.php index 8656adbe8..2266ba11c 100644 --- a/actions/twitapifavorites.php +++ b/actions/twitapifavorites.php @@ -34,6 +34,11 @@ class TwitapifavoritesAction extends TwitterapiAction $user = $this->get_user($apidata['api_arg'], $apidata); if (empty($user)) { + if ($apidata['content-type'] == 'xml') { + $this->show_single_xml_status($notice); + } elseif ($apidata['content-type'] == 'json') { + $this->show_single_json_status($notice); + } $this->clientError('Not Found', 404, $apidata['content-type']); return; } @@ -91,7 +96,6 @@ class TwitapifavoritesAction extends TwitterapiAction // Check for RESTfulness if (!in_array($_SERVER['REQUEST_METHOD'], array('POST', 'DELETE'))) { - // XXX: Twitter just prints the err msg, no XML / JSON. $this->clientError(_('This method requires a POST or DELETE.'), 400, $apidata['content-type']); return; @@ -102,10 +106,9 @@ class TwitapifavoritesAction extends TwitterapiAction return; } - $user = $apidata['user']; // Always the auth user - + $user = $apidata['user']; // Always the auth user $notice_id = $apidata['api_arg']; - $notice = Notice::staticGet($notice_id); + $notice = Notice::staticGet($notice_id); if (empty($notice)) { $this->clientError(_('No status found with that ID.'), @@ -115,7 +118,7 @@ class TwitapifavoritesAction extends TwitterapiAction // XXX: Twitter lets you fave things repeatedly via api. if ($user->hasFave($notice)) { - $this->clientError(_('This notice is already a favorite!'), + $this->clientError(_('This status is already a favorite!'), 403, $apidata['content-type']); return; } @@ -123,7 +126,7 @@ class TwitapifavoritesAction extends TwitterapiAction $fave = Fave::addNew($user, $notice); if (empty($fave)) { - $this->serverError(_('Could not create favorite.')); + $this->clientError(_('Could not create favorite.')); return; } @@ -141,7 +144,55 @@ class TwitapifavoritesAction extends TwitterapiAction function destroy($args, $apidata) { parent::handle($args); - $this->serverError(_('API method under construction.'), $code=501); + + // Check for RESTfulness + if (!in_array($_SERVER['REQUEST_METHOD'], array('POST', 'DELETE'))) { + $this->clientError(_('This method requires a POST or DELETE.'), + 400, $apidata['content-type']); + return; + } + + if (!in_array($apidata['content-type'], array('xml', 'json'))) { + $this->clientError(_('API method not found!'), $code = 404); + return; + } + + $user = $apidata['user']; // Always the auth user + $notice_id = $apidata['api_arg']; + $notice = Notice::staticGet($notice_id); + + if (empty($notice)) { + $this->clientError(_('No status found with that ID.'), + 404, $apidata['content-type']); + return; + } + + $fave = new Fave(); + $fave->user_id = $this->id; + $fave->notice_id = $notice->id; + + if (!$fave->find(true)) { + $this->clientError(_('That status is not a favorite!'), + 403, $apidata['content-type']); + return; + } + + $result = $fave->delete(); + + if (!$result) { + common_log_db_error($fave, 'DELETE', __FILE__); + $this->clientError(_('Could not delete favorite.'), 404); + return; + } + + $user->blowFavesCache(); + + if ($apidata['content-type'] == 'xml') { + $this->show_single_xml_status($notice); + } elseif ($apidata['content-type'] == 'json') { + $this->show_single_json_status($notice); + } + } // XXX: these two funcs swiped from faves. diff --git a/lib/router.php b/lib/router.php index 0fbaba9ed..8b6f63618 100644 --- a/lib/router.php +++ b/lib/router.php @@ -351,7 +351,8 @@ class Router $m->connect('api/favorites/:method/:argument', array('action' => 'api', - 'apiaction' => 'favorites')); + 'apiaction' => 'favorites', + array('method' => '(create|destroy)'))); $m->connect('api/favorites/:argument', array('action' => 'api', -- cgit v1.2.3-54-g00ecf