]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch 'testing' of git@gitorious.org:statusnet/mainline into testing
authorEvan Prodromou <evan@status.net>
Sun, 21 Feb 2010 01:27:04 +0000 (20:27 -0500)
committerEvan Prodromou <evan@status.net>
Sun, 21 Feb 2010 01:27:04 +0000 (20:27 -0500)
Conflicts:
plugins/OStatus/OStatusPlugin.php

21 files changed:
actions/apidirectmessage.php
actions/apigrouplist.php
actions/apigrouplistall.php
actions/apitimelinefavorites.php
actions/apitimelinefriends.php
actions/apitimelinegroup.php
actions/apitimelinehome.php
actions/apitimelinementions.php
actions/apitimelinepublic.php
actions/apitimelineretweetedtome.php
actions/apitimelineretweetsofme.php
actions/apitimelinetag.php
actions/apitimelineuser.php
actions/twitapisearchatom.php
lib/api.php
lib/default.php
lib/taguri.php [new file with mode: 0644]
plugins/OStatus/OStatusPlugin.php
plugins/OStatus/classes/Ostatus_profile.php
plugins/OStatus/lib/activity.php
tests/TagURITest.php [new file with mode: 0644]

index 5fbc46518b2f5ec884d2bad3b81c01a52ac25a15..5355acf8253805796cfa5411a857b8a5947d2310 100644 (file)
@@ -79,7 +79,7 @@ class ApiDirectMessageAction extends ApiAuthAction
         }
 
         $server   = common_root_url();
-        $taguribase = common_config('integration', 'taguri');
+        $taguribase = TagURI::base();
 
         if ($this->arg('sent')) {
 
index 66b67a030e0899bf3aceb60e6ae568d748d6af59..605b3823261338bcf750b5c1a74ad9c5fae28983 100644 (file)
@@ -93,7 +93,7 @@ class ApiGroupListAction extends ApiBareAuthAction
 
         $sitename   = common_config('site', 'name');
         $title      = sprintf(_("%s's groups"), $this->user->nickname);
-        $taguribase = common_config('integration', 'taguri');
+        $taguribase = TagURI::base();
         $id         = "tag:$taguribase:Groups";
         $link       = common_local_url(
             'usergroups',
index 1921c1f193f3396e4c5d42c2007515487b649280..d2ef2978aa5427cf1e0ec5dfb6b65b8332e48e2e 100644 (file)
@@ -88,7 +88,7 @@ class ApiGroupListAllAction extends ApiPrivateAuthAction
 
         $sitename   = common_config('site', 'name');
         $title      = sprintf(_("%s groups"), $sitename);
-        $taguribase = common_config('integration', 'taguri');
+        $taguribase = TagURI::base();
         $id         = "tag:$taguribase:Groups";
         $link       = common_local_url('groups');
         $subtitle   = sprintf(_("groups on %s"), $sitename);
index f7f900ddfb5d6382f70c4a1752de799f2473038d..c89d02247acda2edbfcff97d87d5bb9f9c2e860b 100644 (file)
@@ -110,7 +110,7 @@ class ApiTimelineFavoritesAction extends ApiBareAuthAction
             $this->user->nickname
         );
 
-        $taguribase = common_config('integration', 'taguri');
+        $taguribase = TagURI::base();
         $id         = "tag:$taguribase:Favorites:" . $this->user->id;
 
         $subtitle = sprintf(
index 0af04fe4fb2cef71c07b1ce90528e4016806a349..2db76857e3c7615d43647f24ad27f7867a33fcd8 100644 (file)
@@ -112,7 +112,7 @@ class ApiTimelineFriendsAction extends ApiBareAuthAction
         $avatar     = $profile->getAvatar(AVATAR_PROFILE_SIZE);
         $sitename   = common_config('site', 'name');
         $title      = sprintf(_("%s and friends"), $this->user->nickname);
-        $taguribase = common_config('integration', 'taguri');
+        $taguribase = TagURI::base();
         $id         = "tag:$taguribase:FriendsTimeline:" . $this->user->id;
 
         $subtitle = sprintf(
index 3c74e36b566ec0c964d16c7a1d5127a0bc6a71cf..1d0c4afdd0cf812487822159364f5f83191514ba 100644 (file)
@@ -107,7 +107,7 @@ class ApiTimelineGroupAction extends ApiPrivateAuthAction
         $sitename   = common_config('site', 'name');
         $avatar     = $this->group->homepage_logo;
         $title      = sprintf(_("%s timeline"), $this->group->nickname);
-        $taguribase = common_config('integration', 'taguri');
+        $taguribase = TagURI::base();
         $id         = "tag:$taguribase:GroupTimeline:" . $this->group->id;
 
         $subtitle   = sprintf(
index ae41680702fd6484349eba4ff178edd589abdc1d..0c72f4020c47d77229bb798752bb482dbaac25c3 100644 (file)
@@ -113,7 +113,7 @@ class ApiTimelineHomeAction extends ApiBareAuthAction
         $avatar     = $profile->getAvatar(AVATAR_PROFILE_SIZE);
         $sitename   = common_config('site', 'name');
         $title      = sprintf(_("%s and friends"), $this->user->nickname);
-        $taguribase = common_config('integration', 'taguri');
+        $taguribase = TagURI::base();
         $id         = "tag:$taguribase:HomeTimeline:" . $this->user->id;
 
         $subtitle   = sprintf(
index d2e31d0bdd095fe40e592b98647dd14ee50a5689..a39c63346abfa2dc990c8a2c806fed835c1924b7 100644 (file)
@@ -117,7 +117,7 @@ class ApiTimelineMentionsAction extends ApiBareAuthAction
             _('%1$s / Updates mentioning %2$s'),
             $sitename, $this->user->nickname
         );
-        $taguribase = common_config('integration', 'taguri');
+        $taguribase = TagURI::base();
         $id         = "tag:$taguribase:Mentions:" . $this->user->id;
         $link       = common_local_url(
             'replies',
index c1fa72a3ee372f72e944931f86c6480bff17aabc..1ff0fd26172892defc5d48c047fe9da50ffb4423 100644 (file)
@@ -109,7 +109,7 @@ class ApiTimelinePublicAction extends ApiPrivateAuthAction
         $sitename   = common_config('site', 'name');
         $sitelogo   = (common_config('site', 'logo')) ? common_config('site', 'logo') : Theme::path('logo.png');
         $title      = sprintf(_("%s public timeline"), $sitename);
-        $taguribase = common_config('integration', 'taguri');
+        $taguribase = TagURI::base();
         $id         = "tag:$taguribase:PublicTimeline";
         $link       = common_root_url();
         $subtitle   = sprintf(_("%s updates from everyone!"), $sitename);
index e47bc30b854cb9a93e69cd2d229186668a5964e4..73e35c86bf81a2ecb8c7d88b661760f1891dcb2c 100644 (file)
@@ -109,7 +109,7 @@ class ApiTimelineRetweetedToMeAction extends ApiAuthAction
             $profile    = $this->auth_user->getProfile();
 
             $title      = sprintf(_("Repeated to %s"), $this->auth_user->nickname);
-            $taguribase = common_config('integration', 'taguri');
+            $taguribase = TagURI::base();
             $id         = "tag:$taguribase:RepeatedToMe:" . $this->auth_user->id;
             $link       = common_local_url('all',
                                            array('nickname' => $this->auth_user->nickname));
index 26706a75e7650c1c65717bd79237676e635d36b5..c77912fd0f24e209bed482232be7110eb7dd45be 100644 (file)
@@ -112,7 +112,7 @@ class ApiTimelineRetweetsOfMeAction extends ApiAuthAction
             $profile    = $this->auth_user->getProfile();
 
             $title      = sprintf(_("Repeats of %s"), $this->auth_user->nickname);
-            $taguribase = common_config('integration', 'taguri');
+            $taguribase = TagURI::base();
             $id         = "tag:$taguribase:RepeatsOfMe:" . $this->auth_user->id;
 
             header('Content-Type: application/atom+xml; charset=utf-8');
index 5b6ded4c048d6b08fe77838b2ced98b674484e51..a29061fccfcbc50d35eef9c27ee3e79ad94ea3c1 100644 (file)
@@ -105,7 +105,7 @@ class ApiTimelineTagAction extends ApiPrivateAuthAction
             $this->tag,
             $sitename
         );
-        $taguribase = common_config('integration', 'taguri');
+        $taguribase = TagURI::base();
         $id         = "tag:$taguribase:TagTimeline:".$tag;
 
         switch($this->format) {
index 9f7ec4c2363ab7bdac8490f7796c3fd04c377327..3e849cc786c56b69c77b67c5ae6eee3685cdbd8b 100644 (file)
@@ -116,7 +116,7 @@ class ApiTimelineUserAction extends ApiBareAuthAction
 
         $sitename   = common_config('site', 'name');
         $title      = sprintf(_("%s timeline"), $this->user->nickname);
-        $taguribase = common_config('integration', 'taguri');
+        $taguribase = TagURI::base();
         $id         = "tag:$taguribase:UserTimeline:" . $this->user->id;
         $link       = common_local_url(
             'showstream',
index baed2a0c7c24107cb15731489fc312974ea267c6..e389ddec84f43b2bf44428d7bbf99314e19eed6c 100644 (file)
@@ -245,7 +245,7 @@ class TwitapisearchatomAction extends ApiAction
                              'xmlns:twitter' => 'http://api.twitter.com/',
                              'xml:lang' => 'en-US')); // XXX Other locales ?
 
-        $taguribase = common_config('integration', 'taguri');
+        $taguribase = TagURI::base();
         $this->element('id', null, "tag:$taguribase:search/$server");
 
         $site_uri = common_path(false);
@@ -329,7 +329,7 @@ class TwitapisearchatomAction extends ApiAction
 
         $this->elementStart('entry');
 
-        $taguribase = common_config('integration', 'taguri');
+        $taguribase = TagURI::base();
 
         $this->element('id', null, "tag:$taguribase:$notice->id");
         $this->element('published', null, common_date_w3dtf($notice->created));
index 22eef7436dfc8ac1f010882f699786e480ff1b8a..0bcf4cc21afbdc870aee26b5e307b62ccc66db8a 100644 (file)
@@ -358,7 +358,7 @@ class ApiAction extends Action
         $entry['link'] = common_local_url('shownotice', array('notice' => $notice->id));
         $entry['published'] = common_date_iso8601($notice->created);
 
-        $taguribase = common_config('integration', 'taguri');
+        $taguribase = TagURI::base();
         $entry['id'] = "tag:$taguribase:$entry[link]";
 
         $entry['updated'] = $entry['published'];
@@ -802,7 +802,7 @@ class ApiAction extends Action
         $entry['link'] = common_local_url('showmessage', array('message' => $message->id));
         $entry['published'] = common_date_iso8601($message->created);
 
-        $taguribase = common_config('integration', 'taguri');
+        $taguribase = TagURI::base();
 
         $entry['id'] = "tag:$taguribase:$entry[link]";
         $entry['updated'] = $entry['published'];
index 4f3ea00f2abc11a8bebed8527257e2b0273fa686..bb7708bfcdfc077750e43e13eba82c55b9da64f7 100644 (file)
@@ -175,7 +175,7 @@ $default =
         array('enabled' => false),
         'integration' =>
         array('source' => 'StatusNet', # source attribute for Twitter
-              'taguri' => $_server.',2009'), # base for tag URIs
+              'taguri' => null), # base for tag URIs
         'twitter' =>
         array('enabled'       => true,
               'consumer_key'    => null,
diff --git a/lib/taguri.php b/lib/taguri.php
new file mode 100644 (file)
index 0000000..d8398ed
--- /dev/null
@@ -0,0 +1,96 @@
+<?php
+/**
+ * StatusNet, the distributed open-source microblogging tool
+ *
+ * Utility for creating new tag: URIs
+ *
+ * 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  URI
+ * @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);
+}
+
+/**
+ * Mint tag: URIs
+ *
+ * tag: URIs are unique identifiers according to http://tools.ietf.org/html/rfc4151.
+ *
+ * We use them for creating URIs for things that can't be HTTP retrieved.
+ *
+ * @category URI
+ * @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 TagURI
+{
+    /**
+     * Return the base part of a tag URI
+     *
+     * Note: use mint() instead.
+     *
+     * @return string Tag URI base to use
+     */
+
+    static function base()
+    {
+        $base = common_config('integration', 'taguri');
+
+        if (empty($base)) {
+
+            $base = common_config('site', 'server').','.date('Y-m-d');
+
+            $pathPart = trim(common_config('site', 'path'), '/');
+
+            if (!empty($pathPart)) {
+                $base .= ':'.str_replace('/', ':', $pathPart);
+            }
+        }
+
+        return $base;
+    }
+
+    /**
+     * Make a new tag URI
+     *
+     * Builds the proper base and creates all the parts
+     *
+     * @return string minted URI
+     */
+
+    static function mint()
+    {
+        $base = self::base();
+
+        $args = func_get_args();
+
+        $format = array_shift($args);
+
+        $extra = vsprintf($format, $args);
+
+        return 'tag:'.$base.':'.$extra;
+    }
+}
index 4cbf78e638740d41ecd3ff77516be630d5c4a615..5081c4d983fc1340ad60de7894ff61d8323273a4 100644 (file)
@@ -255,7 +255,7 @@ class OStatusPlugin extends Plugin
     {
         if ($user instanceof Profile) {
             $profile = $user;
-        } else if ($user instanceof Profile) {
+        } else if ($user instanceof User) {
             $profile = $user->getProfile();
         }
         $oprofile = Ostatus_profile::staticGet('profile_id', $other->id);
@@ -353,7 +353,7 @@ class OStatusPlugin extends Plugin
         // We have a local user subscribing to a remote profile; make the
         // magic happen!
 
-        $oprofile->notify($subscriber, ActivityVerb::FOLLOW);
+        $oprofile->notify($subscriber, ActivityVerb::FOLLOW, $oprofile);
 
         return true;
     }
index 4dd565288696c47559f704188f6bc55b834941fa..5bd899bc46ab38500c02bcb38211184bed0b2390 100644 (file)
@@ -307,7 +307,7 @@ class Ostatus_profile extends Memcached_DataObject
      *
      * @param Profile $actor
      * @param $verb eg Activity::SUBSCRIBE or Activity::JOIN
-     * @param $object object of the action; if null, the remote entity itself is assumed
+     * @param string $object object of the action; if null, the remote entity itself is assumed
      */
     public function notify($actor, $verb, $object=null)
     {
@@ -319,7 +319,7 @@ class Ostatus_profile extends Memcached_DataObject
             throw new ServerException("Invalid actor passed to " . __METHOD__ . ": " . $type);
         }
         if ($object == null) {
-            $object = $this;
+            $object = $this->asActivityNoun('object');
         }
         if ($this->salmonuri) {
             $text = 'update'; // @fixme
@@ -345,7 +345,7 @@ class Ostatus_profile extends Memcached_DataObject
             $entry->element('activity:verb', null, $verb);
             $entry->raw($actor->asAtomAuthor());
             $entry->raw($actor->asActivityActor());
-            $entry->raw($object->asActivityNoun('object'));
+            $entry->raw($object);
             $entry->elementEnd('entry');
 
             $xml = $entry->getString();
index 5bc8f78e52de2d5a2d32842749b3c24f2a5b831b..6d15f85b0d4f70f0763cf6a27d5424dddcf8601c 100644 (file)
@@ -199,7 +199,7 @@ class ActivityObject
     public $link;
     public $source;
 
-    /**
+   /**
      * Constructor
      *
      * This probably needs to be refactored
@@ -209,8 +209,12 @@ class ActivityObject
      * @param DOMElement $element DOM thing to turn into an Activity thing
      */
 
-    function __construct($element)
+    function __construct($element = null)
     {
+        if (empty($element)) {
+            return;
+        }
+
         $this->element = $element;
 
         if ($element->tagName == 'author') {
@@ -279,6 +283,53 @@ class ActivityObject
             }
         }
     }
+
+    static fromNotice($notice)
+    {
+        $object = new ActivityObject();
+
+        $object->type    = ActivityObject::NOTE;
+
+        $object->id      = $notice->uri;
+        $object->title   = $notice->content;
+        $object->content = $notice->rendered;
+        $object->link    = $notice->bestUrl();
+
+        return $object;
+    }
+
+    function asString($tag='activity:object')
+    {
+        $xs = new XMLStringer(true);
+
+        $xs->elementStart($tag);
+
+        $xs->element('activity:object-type', null, $this->type);
+
+        $xs->element(self::ID, null, $this->id);
+
+        if (!empty($this->title)) {
+            $xs->element(self::TITLE, null, $this->title);
+        }
+
+        if (!empty($this->summary)) {
+            $xs->element(self::SUMMARY, null, $this->summary);
+        }
+
+        if (!empty($this->content)) {
+            // XXX: assuming HTML content here
+            $xs->element(self::CONTENT, array('type' => 'html'), $this->content);
+        }
+
+        if (!empty($this->link)) {
+            $xs->element('link', array('rel' => 'alternate', 'type' => 'text/html'),
+                         $this->content);
+        }
+
+        $xs->elementEnd($tag);
+
+        return $xs->getString();
+    }
 }
 
 /**
diff --git a/tests/TagURITest.php b/tests/TagURITest.php
new file mode 100644 (file)
index 0000000..d23f8bf
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+
+if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
+    print "This script must be run from the command line\n";
+    exit();
+}
+
+define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
+define('STATUSNET', true);
+
+require_once INSTALLDIR . '/lib/common.php';
+
+$config['site']['server'] = 'example.net';
+$config['site']['path']   = '/apps/statusnet';
+
+class TagURITest extends PHPUnit_Framework_TestCase
+{
+    /**
+     * @dataProvider provider
+     */
+    public function testProduction($format, $args, $uri)
+    {
+        $minted = call_user_func_array(array('TagURI', 'mint'),
+                                       array_merge(array($format), $args));
+
+        $this->assertEquals($uri, $minted);
+    }
+
+    static public function provider()
+    {
+        return array(array('favorite:%d:%d',
+                           array(1, 3),
+                           'tag:example.net,'.date('Y-m-d').':apps:statusnet:favorite:1:3'));
+    }
+}
+