]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch 'testing' of git@gitorious.org:statusnet/mainline into 0.9.x
authorBrion Vibber <brion@pobox.com>
Fri, 19 Mar 2010 00:19:28 +0000 (17:19 -0700)
committerBrion Vibber <brion@pobox.com>
Fri, 19 Mar 2010 00:19:28 +0000 (17:19 -0700)
14 files changed:
README
actions/apistatusesupdate.php
actions/avatarsettings.php
classes/Subscription.php
classes/User.php
lib/activity.php
lib/usernoprofileexception.php [new file with mode: 0644]
plugins/OStatus/OStatusPlugin.php
plugins/OStatus/actions/ostatussub.php
plugins/OStatus/classes/Ostatus_profile.php
plugins/OStatus/lib/discoveryhints.php
plugins/OStatus/lib/linkheader.php
plugins/OStatus/scripts/updateostatus.php
scripts/xmppdaemon.php

diff --git a/README b/README
index 45b72e9acc62e91b5f3754158596945f2d571ceb..c5adda17768d7c298be21d41d99e7d8554ae06bd 100644 (file)
--- a/README
+++ b/README
@@ -137,7 +137,9 @@ run correctly.
 
 - PHP 5.2.3+. It may be possible to run this software on earlier
   versions of PHP, but many of the functions used are only available
-  in PHP 5.2 or above.
+  in PHP 5.2 or above. 5.2.6 or later is needed for XMPP background
+  daemons on 64-bit platforms. PHP 5.3.x should work but is known
+  to cause some failures for OpenID.
 - MySQL 5.x. The StatusNet database is stored, by default, in a MySQL
   server. It has been primarily tested on 5.x servers, although it may
   be possible to install on earlier (or later!) versions. The server
index bf367e1e181741e4d5626bd6332f0ae5432cc713..1956c85863d747173b4a15c8cc30e10f9caefe43 100644 (file)
@@ -244,11 +244,17 @@ class ApiStatusesUpdateAction extends ApiAuthAction
                 $options = array_merge($options, $locOptions);
             }
 
-            $this->notice =
-              Notice::saveNew($this->auth_user->id,
-                              $content,
-                              $this->source,
-                              $options);
+            try {
+                $this->notice = Notice::saveNew(
+                    $this->auth_user->id,
+                    $content,
+                    $this->source,
+                    $options
+                );
+            } catch (Exception $e) {
+                $this->clientError($e->getMessage());
+                return;
+            }
 
             if (isset($upload)) {
                 $upload->attachToNotice($this->notice);
index 6a7398746ae8f8ec2a5916812f588202c2487f8d..d4ea11cb7e9deb03b3857e4abff3ee4608d5cd76 100644 (file)
@@ -301,6 +301,10 @@ class AvatarsettingsAction extends AccountSettingsAction
             $this->showForm($e->getMessage());
             return;
         }
+        if ($imagefile === null) {
+            $this->showForm(_('No file uploaded.'));
+            return;
+        }
 
         $cur = common_current_user();
 
index 5ac95f92222a1aa9b80f12b5610859645a9b1510..60c12cccc3d8d67545679355d2eb944e6e9f0612 100644 (file)
@@ -62,6 +62,14 @@ class Subscription extends Memcached_DataObject
 
     static function start($subscriber, $other)
     {
+        // @fixme should we enforce this as profiles in callers instead?
+        if ($subscriber instanceof User) {
+            $subscriber = $subscriber->getProfile();
+        }
+        if ($other instanceof User) {
+            $other = $other->getProfile();
+        }
+
         if (!$subscriber->hasRight(Right::SUBSCRIBE)) {
             throw new Exception(_('You have been banned from subscribing.'));
         }
@@ -75,20 +83,7 @@ class Subscription extends Memcached_DataObject
         }
 
         if (Event::handle('StartSubscribe', array($subscriber, $other))) {
-
-            $sub = new Subscription();
-
-            $sub->subscriber = $subscriber->id;
-            $sub->subscribed = $other->id;
-            $sub->created    = common_sql_now();
-
-            $result = $sub->insert();
-
-            if (!$result) {
-                common_log_db_error($sub, 'INSERT', __FILE__);
-                throw new Exception(_('Could not save subscription.'));
-            }
-
+            $sub = self::saveNew($subscriber->id, $other->id);
             $sub->notify();
 
             self::blow('user:notices_with_friends:%d', $subscriber->id);
@@ -103,20 +98,11 @@ class Subscription extends Memcached_DataObject
                 !self::exists($other, $subscriber) &&
                 !$subscriber->hasBlocked($other)) {
 
-                $auto = new Subscription();
-
-                $auto->subscriber = $other->id;
-                $auto->subscribed = $subscriber->id;
-                $auto->created    = common_sql_now();
-
-                $result = $auto->insert();
-
-                if (!$result) {
-                    common_log_db_error($auto, 'INSERT', __FILE__);
-                    throw new Exception(_('Could not save subscription.'));
+                try {
+                    self::start($other, $subscriber);
+                } catch (Exception $e) {
+                    common_log(LOG_ERR, "Exception during autosubscribe of {$other->nickname} to profile {$subscriber->id}: {$e->getMessage()}");
                 }
-
-                $auto->notify();
             }
 
             Event::handle('EndSubscribe', array($subscriber, $other));
@@ -125,6 +111,30 @@ class Subscription extends Memcached_DataObject
         return true;
     }
 
+    /**
+     * Low-level subscription save.
+     * Outside callers should use Subscription::start()
+     */
+    protected function saveNew($subscriber_id, $other_id)
+    {
+        $sub = new Subscription();
+
+        $sub->subscriber = $subscriber_id;
+        $sub->subscribed = $other_id;
+        $sub->jabber     = 1;
+        $sub->sms        = 1;
+        $sub->created    = common_sql_now();
+
+        $result = $sub->insert();
+
+        if (!$result) {
+            common_log_db_error($sub, 'INSERT', __FILE__);
+            throw new Exception(_('Could not save subscription.'));
+        }
+
+        return $sub;
+    }
+
     function notify()
     {
         # XXX: add other notifications (Jabber, SMS) here
index ee1006ee1857c1ea6aa2ed6f6e29f359f207503b..8ad2ec63d5c81d12cbf6c3b35c7eb41b8cac5e60 100644 (file)
@@ -75,7 +75,11 @@ class User extends Memcached_DataObject
 
     function getProfile()
     {
-        return Profile::staticGet('id', $this->id);
+        $profile = Profile::staticGet('id', $this->id);
+        if (empty($profile)) {
+            throw new UserNoProfileException($this);
+        }
+        return $profile;
     }
 
     function isSubscribed($other)
@@ -141,9 +145,6 @@ class User extends Memcached_DataObject
     function getCurrentNotice()
     {
         $profile = $this->getProfile();
-        if (!$profile) {
-            return null;
-        }
         return $profile->getCurrentNotice();
     }
 
@@ -152,19 +153,12 @@ class User extends Memcached_DataObject
         return Sms_carrier::staticGet('id', $this->carrier);
     }
 
+    /**
+     * @deprecated use Subscription::start($sub, $other);
+     */
     function subscribeTo($other)
     {
-        $sub = new Subscription();
-        $sub->subscriber = $this->id;
-        $sub->subscribed = $other->id;
-
-        $sub->created = common_sql_now(); // current time
-
-        if (!$sub->insert()) {
-            return false;
-        }
-
-        return true;
+        return Subscription::start($this->getProfile(), $other);
     }
 
     function hasBlocked($other)
@@ -345,17 +339,7 @@ class User extends Memcached_DataObject
                     common_log(LOG_WARNING, sprintf("Default user %s does not exist.", $defnick),
                                __FILE__);
                 } else {
-                    $defsub = new Subscription();
-                    $defsub->subscriber = $user->id;
-                    $defsub->subscribed = $defuser->id;
-                    $defsub->created = $user->created;
-
-                    $result = $defsub->insert();
-
-                    if (!$result) {
-                        common_log_db_error($defsub, 'INSERT', __FILE__);
-                        return false;
-                    }
+                    Subscription::start($user, $defuser);
                 }
             }
 
@@ -471,21 +455,13 @@ class User extends Memcached_DataObject
 
     function getTaggedNotices($tag, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0) {
         $profile = $this->getProfile();
-        if (!$profile) {
-            return null;
-        } else {
-            return $profile->getTaggedNotices($tag, $offset, $limit, $since_id, $before_id);
-        }
+        return $profile->getTaggedNotices($tag, $offset, $limit, $since_id, $before_id);
     }
 
     function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
     {
         $profile = $this->getProfile();
-        if (!$profile) {
-            return null;
-        } else {
-            return $profile->getNotices($offset, $limit, $since_id, $before_id);
-        }
+        return $profile->getNotices($offset, $limit, $since_id, $before_id);
     }
 
     function favoriteNotices($offset=0, $limit=NOTICES_PER_PAGE, $own=false)
@@ -626,14 +602,12 @@ class User extends Memcached_DataObject
     function getSubscriptions($offset=0, $limit=null)
     {
         $profile = $this->getProfile();
-        assert(!empty($profile));
         return $profile->getSubscriptions($offset, $limit);
     }
 
     function getSubscribers($offset=0, $limit=null)
     {
         $profile = $this->getProfile();
-        assert(!empty($profile));
         return $profile->getSubscribers($offset, $limit);
     }
 
@@ -697,9 +671,7 @@ class User extends Memcached_DataObject
     function delete()
     {
         $profile = $this->getProfile();
-        if ($profile) {
-            $profile->delete();
-        }
+        $profile->delete();
 
         $related = array('Fave',
                          'Confirm_address',
index 4b724ee90e8192ab4c9d5bd03c50d32f280c055b..23cf50f70cedc0d2324152124b45cf1b00088f03 100644 (file)
@@ -723,7 +723,7 @@ class ActivityObject
         }
     }
 
-    static function fromNotice($notice)
+    static function fromNotice(Notice $notice)
     {
         $object = new ActivityObject();
 
@@ -737,7 +737,7 @@ class ActivityObject
         return $object;
     }
 
-    static function fromProfile($profile)
+    static function fromProfile(Profile $profile)
     {
         $object = new ActivityObject();
 
diff --git a/lib/usernoprofileexception.php b/lib/usernoprofileexception.php
new file mode 100644 (file)
index 0000000..6744d25
--- /dev/null
@@ -0,0 +1,74 @@
+<?php
+/**
+ * StatusNet, the distributed open-source microblogging tool
+ *
+ * class for an exception when the user profile is missing
+ *
+ * PHP version 5
+ *
+ * LICENCE: This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category  Exception
+ * @package   StatusNet
+ * @author    Evan Prodromou <evan@status.net>
+ * @copyright 2010 StatusNet, Inc.
+ * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
+ * @link      http://status.net/
+ */
+
+if (!defined('STATUSNET')) {
+    exit(1);
+}
+
+/**
+ * Class for an exception when the user profile is missing
+ *
+ * @category Exception
+ * @package  StatusNet
+ * @author   Evan Prodromou <evan@status.net>
+ * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
+ * @link     http://status.net/
+ */
+
+class UserNoProfileException extends ServerException
+{
+    var $user = null;
+
+    /**
+     * constructor
+     *
+     * @param User $user User that's missing a profile
+     */
+
+    public function __construct($user)
+    {
+        $this->user = $user;
+
+        $message = sprintf(_("User %s (%d) has no profile record."),
+                           $user->nickname, $user->id);
+
+        parent::__construct($message);
+    }
+
+    /**
+     * Accessor for user
+     *
+     * @return User the user that triggered this exception
+     */
+
+    public function getUser()
+    {
+        return $this->user;
+    }
+}
index b472ae24207e35f4b558aba616c070787497c355..58f373e453fcbac25fa19bc7161c65214b20cf3b 100644 (file)
@@ -290,7 +290,7 @@ class OStatusPlugin extends Plugin
                     $url = "$scheme://$target";
                     $this->log(LOG_INFO, "Checking profile address '$url'");
                     try {
-                        $oprofile = Ostatus_profile::ensureProfile($url);
+                        $oprofile = Ostatus_profile::ensureProfileURL($url);
                         if ($oprofile && !$oprofile->isGroup()) {
                             $profile = $oprofile->localProfile();
                             $matches[$pos] = array('mentioned' => array($profile),
@@ -392,7 +392,7 @@ class OStatusPlugin extends Plugin
 
         foreach ($urls as $url) {
             try {
-                return Ostatus_profile::ensureProfile($url);
+                return Ostatus_profile::ensureProfileURL($url);
             } catch (Exception $e) {
                 common_log(LOG_ERR, 'Profile lookup failed for ' .
                                     $arg . ': ' . $e->getMessage());
index 07081c2c6f1629a07fceaf40702c2eb6ecfd2791..994af6e95ccc8e0929e172a7a63e364be7ad5a3b 100644 (file)
@@ -299,7 +299,7 @@ class OStatusSubAction extends Action
         if ($user->isSubscribed($local)) {
             // TRANS: OStatus remote subscription dialog error.
             $this->showForm(_m('Already subscribed!'));
-        } elseif ($this->oprofile->subscribeLocalToRemote($user)) {
+        } elseif (Subscription::start($user, $local)) {
             $this->success();
         } else {
             // TRANS: OStatus remote subscription dialog error.
index 7ea8ff633b96571d18b90677c429eba9bd0dd683..d37596d54268811bc000098f5ae5e2b1c93a0831 100644 (file)
@@ -194,52 +194,6 @@ class Ostatus_profile extends Memcached_DataObject
         }
     }
 
-    /**
-     * Subscribe a local user to this remote user.
-     * PuSH subscription will be started if necessary, and we'll
-     * send a Salmon notification to the remote server if available
-     * notifying them of the sub.
-     *
-     * @param User $user
-     * @return boolean success
-     * @throws FeedException
-     */
-    public function subscribeLocalToRemote(User $user)
-    {
-        if ($this->isGroup()) {
-            throw new ServerException("Can't subscribe to a remote group");
-        }
-
-        if ($this->subscribe()) {
-            if ($user->subscribeTo($this->localProfile())) {
-                $this->notify($user->getProfile(), ActivityVerb::FOLLOW, $this);
-                return true;
-            }
-        }
-        return false;
-    }
-
-    /**
-     * Mark this remote profile as subscribing to the given local user,
-     * and send appropriate notifications to the user.
-     *
-     * This will generally be in response to a subscription notification
-     * from a foreign site to our local Salmon response channel.
-     *
-     * @param User $user
-     * @return boolean success
-     */
-    public function subscribeRemoteToLocal(User $user)
-    {
-        if ($this->isGroup()) {
-            throw new ServerException("Remote groups can't subscribe to local users");
-        }
-
-        Subscription::start($this->localProfile(), $user->getProfile());
-
-        return true;
-    }
-
     /**
      * Send a subscription request to the hub for this feed.
      * The hub will later send us a confirmation POST to /main/push/callback.
@@ -1460,7 +1414,7 @@ class Ostatus_profile extends Memcached_DataObject
 
         if (array_key_exists('feedurl', $hints)) {
             try {
-                common_log(LOG_INFO, "Discovery on acct:$addr with feed URL $feedUrl");
+                common_log(LOG_INFO, "Discovery on acct:$addr with feed URL " . $hints['feedurl']);
                 $oprofile = self::ensureFeedURL($hints['feedurl'], $hints);
                 self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri);
                 return $oprofile;
@@ -1475,7 +1429,7 @@ class Ostatus_profile extends Memcached_DataObject
         if (array_key_exists('profileurl', $hints)) {
             try {
                 common_log(LOG_INFO, "Discovery on acct:$addr with profile URL $profileUrl");
-                $oprofile = self::ensureProfile($hints['profileurl'], $hints);
+                $oprofile = self::ensureProfileURL($hints['profileurl'], $hints);
                 self::cacheSet(sprintf('ostatus_profile:webfinger:%s', $addr), $oprofile->uri);
                 return $oprofile;
             } catch (Exception $e) {
index db13793ddef0a965be3938d032c0479d57a12cf1..4da2ec0f1e7cf375c95f1e9eff56bb2ded9efe99 100644 (file)
@@ -65,17 +65,22 @@ class DiscoveryHints {
     {
         common_debug("starting tidy");
 
-        $body = self::_tidy($body);
+        $body = self::_tidy($body, $url);
 
         common_debug("done with tidy");
 
         set_include_path(get_include_path() . PATH_SEPARATOR . INSTALLDIR . '/plugins/OStatus/extlib/hkit/');
         require_once('hkit.class.php');
 
-        $h     = new hKit;
+        // hKit code is not clean for notices and warnings
+        $old = error_reporting();
+        error_reporting($old & ~E_NOTICE & ~E_WARNING);
 
+        $h     = new hKit;
         $hcards = $h->getByString('hcard', $body);
 
+        error_reporting($old);
+
         if (empty($hcards)) {
             return array();
         }
@@ -144,39 +149,61 @@ class DiscoveryHints {
         return $hints;
     }
 
-    private static function _tidy($body)
+    /**
+     * hKit needs well-formed XML for its parsing.
+     * We'll take the HTML body here and normalize it to XML.
+     *
+     * @param string $body HTML document source, possibly not-well-formed
+     * @param string $url source URL
+     * @return string well-formed XML document source
+     * @throws Exception if HTML parsing failed.
+     */
+    private static function _tidy($body, $url)
     {
-        if (function_exists('tidy_parse_string')) {
-            common_debug("Tidying with extension");
-            $text = tidy_parse_string($body);
-            $text = tidy_clean_repair($text);
-            return $body;
-        } else if ($fullpath = self::_findProgram('tidy')) {
-            common_debug("Tidying with program $fullpath");
-            $tempfile = tempnam('/tmp', 'snht'); // statusnet hcard tidy
-            file_put_contents($tempfile, $source);
-            exec("$fullpath -utf8 -indent -asxhtml -numeric -bare -quiet $tempfile", $tidy);
-            unlink($tempfile);
-            return implode("\n", $tidy);
-        } else {
-            common_debug("Not tidying.");
-            return $body;
+        if (empty($body)) {
+            throw new Exception("Empty HTML could not be parsed.");
         }
-    }
-
-    private static function _findProgram($name)
-    {
-        $path = $_ENV['PATH'];
-
-        $parts = explode(':', $path);
-
-        foreach ($parts as $part) {
-            $fullpath = $part . '/' . $name;
-            if (is_executable($fullpath)) {
-                return $fullpath;
+        $dom = new DOMDocument();
+
+        // Some HTML errors will trigger warnings, but still work.
+        $old = error_reporting();
+        error_reporting($old & ~E_WARNING);
+        
+        $ok = $dom->loadHTML($body);
+
+        error_reporting($old);
+        
+        if ($ok) {
+            // hKit doesn't give us a chance to pass the source URL for
+            // resolving relative links, such as the avatar photo on a
+            // Google profile. We'll slip it into a <base> tag if there's
+            // not already one present.
+            $bases = $dom->getElementsByTagName('base');
+            if ($bases && $bases->length >= 1) {
+                $base = $bases->item(0);
+                if ($base->hasAttribute('href')) {
+                    $base->setAttribute('href', $url);
+                }
+            } else {
+                $base = $dom->createElement('base');
+                $base->setAttribute('href', $url);
+                $heads = $dom->getElementsByTagName('head');
+                if ($heads || $heads->length) {
+                    $head = $heads->item(0);
+                } else {
+                    $head = $dom->createElement('head');
+                    $root = $dom->documentRoot;
+                    if ($root->firstChild) {
+                        $root->insertBefore($head, $root->firstChild);
+                    } else {
+                        $root->appendChild($head);
+                    }
+                }
+                $head->appendChild($base);
             }
+            return $dom->saveXML();
+        } else {
+            throw new Exception("Invalid HTML could not be parsed.");
         }
-
-        return null;
     }
 }
index 2f6c66dc97acafec2a1c5567e7f56e66e2802671..afcd66d264d6be67b9337eeb6abddfd1d5cb6ea4 100644 (file)
@@ -43,21 +43,21 @@ class LinkHeader
     static function getLink($response, $rel=null, $type=null)
     {
         $headers = $response->getHeader('Link');
+        if ($headers) {
+            // Can get an array or string, so try to simplify the path
+            if (!is_array($headers)) {
+                $headers = array($headers);
+            }
 
-        // Can get an array or string, so try to simplify the path
-        if (!is_array($headers)) {
-            $headers = array($headers);
-        }
-
-        foreach ($headers as $header) {
-            $lh = new LinkHeader($header);
+            foreach ($headers as $header) {
+                $lh = new LinkHeader($header);
 
-            if ((is_null($rel) || $lh->rel == $rel) &&
-                (is_null($type) || $lh->type == $type)) {
-                return $lh->href;
+                if ((is_null($rel) || $lh->rel == $rel) &&
+                    (is_null($type) || $lh->type == $type)) {
+                    return $lh->href;
+                }
             }
         }
-
         return null;
     }
-}
\ No newline at end of file
+}
index d553a7d625cad22c118f3434c3b47b1a3d4c2dc5..622ded56ab9044d9d708c97fa372f75d20d0c34f 100644 (file)
@@ -56,7 +56,12 @@ try {
         $user = new User();
         if ($user->find()) {
             while ($user->fetch()) {
-                updateOStatus($user);
+                try {
+                    updateOStatus($user);
+                } catch (Exception $e) {
+                    common_log(LOG_NOTICE, "Couldn't convert OMB subscriptions ".
+                               "for {$user->nickname} to OStatus: " . $e->getMessage());
+                }
             }
         }
     } else {
@@ -98,7 +103,7 @@ function updateOStatus($user)
                 echo "Checking {$rp->nickname}...";
             }
 
-            $op = Ostatus_profile::ensureProfile($rp->profileurl);
+            $op = Ostatus_profile::ensureProfileURL($rp->profileurl);
 
             if (empty($op)) {
                 echo "can't convert.\n";
@@ -107,8 +112,8 @@ function updateOStatus($user)
                 if (!have_option('q', 'quiet')) {
                     echo "Converting...";
                 }
-                Subscription::cancel($up, $rp);
                 Subscription::start($up, $op->localProfile());
+                Subscription::cancel($up, $rp);
                 if (!have_option('q', 'quiet')) {
                     echo "done.\n";
                 }
@@ -118,8 +123,7 @@ function updateOStatus($user)
             if (!have_option('q', 'quiet')) {
                 echo "fail.\n";
             }
-            continue;
-            common_log(LOG_WARNING, "Couldn't convert OMB subscription (" . $up->nickname . ", " . $rp->nickname .
+            common_log(LOG_NOTICE, "Couldn't convert OMB subscription (" . $up->nickname . ", " . $rp->nickname .
                        ") to OStatus: " . $e->getMessage());
             continue;
         }
index 26c7991b885f43013decf5401302e29c119a64b7..abd7cc22b46bdad867b7317f7bfa2e7b24d49c04 100755 (executable)
@@ -98,7 +98,15 @@ class XmppMaster extends IoMaster
 // don't have to find an XMPP site to start up when using --all mode.
 if (common_config('xmpp','enabled')==false) {
     print "Aborting daemon - xmpp is disabled\n";
-    exit();
+    exit(1);
+}
+
+if (version_compare(PHP_VERSION, '5.2.6', '<')) {
+    $arch = php_uname('m');
+    if ($arch == 'x86_64' || $arch == 'amd64') {
+        print "Aborting daemon - 64-bit PHP prior to 5.2.6 has known bugs in stream_select; you are running " . PHP_VERSION . " on $arch.\n";
+        exit(1);
+    }
 }
 
 if (have_option('i', 'id')) {