]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch '0.8.x' of git@gitorious.org:+laconica-developers/laconica/dev into...
authorEvan Prodromou <evan@controlyourself.ca>
Wed, 17 Jun 2009 22:05:24 +0000 (15:05 -0700)
committerEvan Prodromou <evan@controlyourself.ca>
Wed, 17 Jun 2009 22:05:24 +0000 (15:05 -0700)
README
actions/twitapifavorites.php
classes/File.php
classes/File_oembed.php
classes/Notice.php
config.php.sample
lib/common.php
lib/noticeform.php
lib/router.php
lib/twitterapi.php

diff --git a/README b/README
index 3279f7bbaaf80405aae1319475b98396d4efbcdb..5aa7270eece7c2bf6ea98823c223e9c62b4e6668 100644 (file)
--- 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
@@ -1246,6 +1247,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
 ===============
 
index 8656adbe862d5a8419852ea1980dfd7bb9e81b8f..2266ba11c2126cf40c1aaaab9067d0fea9574609 100644 (file)
@@ -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.
index 24ab11b8eb12d595469c08aa2092dca65d013a6b..08320faf8f11fda1af215b127e890c303b0fb9c8 100644 (file)
@@ -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;
index f1b2cb13c02d90a0b50f2c8bf7e2b0c4d522ebda..6bf972f8fe4678a5c6498b0da907148a2b6a4f71 100644 (file)
@@ -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";
index 50242300da8c36c64f2c8967a55575448f5304ed..e621805dfc661038f22cc353901d192509e7ecd8 100644 (file)
@@ -223,6 +223,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');
 
@@ -242,8 +248,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() {
index 636f4cf8e22255322c0452e154727f1ff3cb0f41..7649c52623ca09ba1d7dc3fdda16dc9ad90239b3 100644 (file)
@@ -222,4 +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/';
index 51204cedeaa70e001d5c4020ba973d2b06ebc466..bbd9f78c3e1df660ff6c37fc9302a3da7a57b317 100644 (file)
@@ -200,9 +200,11 @@ $config =
         'file_quota' => 5000000,
         'user_quota' => 50000000,
         'monthly_quota' => 15000000,
+        'uploads' => true,
         ),
         'group' =>
         array('maxaliases' => 3),
+        'oohembed' => array('endpoint' => 'http://oohembed.com/oohembed/')
         );
 
 $config['db'] = &PEAR::getStaticProperty('DB_DataObject','options');
index 0ad36585662c3f9bf83baf730231b14b16150031..a36b7f31f752047e733f9d5fd41865923e283522 100644 (file)
@@ -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');
         }
index 0fbaba9ed5a9d1bb00c79d4a68b3d8752ed5ad09..8b6f636182d7e5fc16168e306ad8dd71976ad2f8 100644 (file)
@@ -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',
index 569bc6d7a21fb55194ea333b5ba4779967439bd2..269b60efc63eafb4fe180075376adaa45a3c93ac 100644 (file)
@@ -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;