]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch 'testing' of gitorious.org:statusnet/mainline into 0.9.x
authorBrion Vibber <brion@pobox.com>
Sat, 26 Jun 2010 14:17:36 +0000 (10:17 -0400)
committerBrion Vibber <brion@pobox.com>
Sat, 26 Jun 2010 14:17:36 +0000 (10:17 -0400)
Conflicts:
plugins/OpenID/openidserver.php (cleaned up mismatched comment)

23 files changed:
actions/apiaccountverifycredentials.php
actions/apisearchatom.php [new file with mode: 0644]
actions/apisearchjson.php [new file with mode: 0644]
actions/apisubscriptions.php
actions/apitrends.php [new file with mode: 0644]
actions/showgroup.php
actions/twitapisearchatom.php [deleted file]
actions/twitapisearchjson.php [deleted file]
actions/twitapitrends.php [deleted file]
classes/Notice.php
classes/Profile.php
classes/Status_network.php
classes/User_group.php
lib/apiaction.php
lib/atomgroupnoticefeed.php
lib/atomnoticefeed.php
lib/avatarlink.php
lib/installer.php
lib/router.php
plugins/OpenID/openidserver.php
plugins/Recaptcha/RecaptchaPlugin.php
plugins/Sitemap/SitemapPlugin.php
plugins/Sitemap/sitemapadminpanel.php [new file with mode: 0644]

index ea61a3205945c12f3c10afc62ecbef0e31c3e08b..79416e9b262099df3e2cc4c228844a04a55363de 100644 (file)
@@ -75,7 +75,7 @@ class ApiAccountVerifyCredentialsAction extends ApiAuthAction
 
         if ($this->format == 'xml') {
             $this->initDocument('xml');
-            $this->showTwitterXmlUser($twitter_user);
+            $this->showTwitterXmlUser($twitter_user, 'user', true);
             $this->endDocument('xml');
         } elseif ($this->format == 'json') {
             $this->initDocument('json');
diff --git a/actions/apisearchatom.php b/actions/apisearchatom.php
new file mode 100644 (file)
index 0000000..60bb8b0
--- /dev/null
@@ -0,0 +1,408 @@
+<?php
+/**
+ * StatusNet, the distributed open-source microblogging tool
+ *
+ * Action for showing Twitter-like Atom search results
+ *
+ * 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  Search
+ * @package   StatusNet
+ * @author    Zach Copley <zach@status.net>
+ * @copyright 2008-2010 StatusNet, Inc.
+ * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link      http://status.net/
+ */
+
+if (!defined('STATUSNET') && !defined('LACONICA')) {
+    exit(1);
+}
+
+require_once INSTALLDIR.'/lib/apiprivateauth.php';
+
+/**
+ * Action for outputting search results in Twitter compatible Atom
+ * format.
+ *
+ * TODO: abstract Atom stuff into a ruseable base class like
+ * RSS10Action.
+ *
+ * @category Search
+ * @package  StatusNet
+ * @author   Zach Copley <zach@status.net>
+ * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link     http://status.net/
+ *
+ * @see      ApiPrivateAuthAction
+ */
+
+class ApiSearchAtomAction extends ApiPrivateAuthAction
+{
+
+    var $cnt;
+    var $query;
+    var $lang;
+    var $rpp;
+    var $page;
+    var $since_id;
+    var $geocode;
+
+    /**
+     * Constructor
+     *
+     * Just wraps the Action constructor.
+     *
+     * @param string  $output URI to output to, default = stdout
+     * @param boolean $indent Whether to indent output, default true
+     *
+     * @see Action::__construct
+     */
+
+    function __construct($output='php://output', $indent=null)
+    {
+        parent::__construct($output, $indent);
+    }
+
+    /**
+     * Do we need to write to the database?
+     *
+     * @return boolean true
+     */
+
+    function isReadonly()
+    {
+        return true;
+    }
+
+    /**
+     * Read arguments and initialize members
+     *
+     * @param array $args Arguments from $_REQUEST
+     *
+     * @return boolean success
+     *
+     */
+
+    function prepare($args)
+    {
+        common_debug("in apisearchatom prepare()");
+
+        parent::prepare($args);
+
+
+        $this->query = $this->trimmed('q');
+        $this->lang  = $this->trimmed('lang');
+        $this->rpp   = $this->trimmed('rpp');
+
+        if (!$this->rpp) {
+            $this->rpp = 15;
+        }
+
+        if ($this->rpp > 100) {
+            $this->rpp = 100;
+        }
+
+        $this->page = $this->trimmed('page');
+
+        if (!$this->page) {
+            $this->page = 1;
+        }
+
+        // TODO: Suppport since_id -- we need to tweak the backend
+        // Search classes to support it.
+
+        $this->since_id = $this->trimmed('since_id');
+        $this->geocode  = $this->trimmed('geocode');
+
+        // TODO: Also, language and geocode
+
+        return true;
+    }
+
+    /**
+     * Handle a request
+     *
+     * @param array $args Arguments from $_REQUEST
+     *
+     * @return void
+     */
+
+    function handle($args)
+    {
+        parent::handle($args);
+        common_debug("In apisearchatom handle()");
+        $this->showAtom();
+    }
+
+    /**
+     * Get the notices to output as results. This also sets some class
+     * attrs so we can use them to calculate pagination, and output
+     * since_id and max_id.
+     *
+     * @return array an array of Notice objects sorted in reverse chron
+     */
+
+    function getNotices()
+    {
+        // TODO: Support search operators like from: and to:, boolean, etc.
+
+        $notices = array();
+        $notice = new Notice();
+
+        // lcase it for comparison
+        $q = strtolower($this->query);
+
+        $search_engine = $notice->getSearchEngine('notice');
+        $search_engine->set_sort_mode('chron');
+        $search_engine->limit(($this->page - 1) * $this->rpp,
+            $this->rpp + 1, true);
+        if (false === $search_engine->query($q)) {
+            $this->cnt = 0;
+        } else {
+            $this->cnt = $notice->find();
+        }
+
+        $cnt = 0;
+        $this->max_id = 0;
+
+        if ($this->cnt > 0) {
+            while ($notice->fetch()) {
+
+                ++$cnt;
+
+                if (!$this->max_id) {
+                    $this->max_id = $notice->id;
+                }
+
+                if ($cnt > $this->rpp) {
+                    break;
+                }
+
+                $notices[] = clone($notice);
+            }
+        }
+
+        return $notices;
+    }
+
+    /**
+     * Output search results as an Atom feed
+     *
+     * @return void
+     */
+
+    function showAtom()
+    {
+        $notices = $this->getNotices();
+
+        $this->initAtom();
+        $this->showFeed();
+
+        foreach ($notices as $n) {
+
+            $profile = $n->getProfile();
+
+            // Don't show notices from deleted users
+
+            if (!empty($profile)) {
+                $this->showEntry($n);
+            }
+        }
+
+        $this->endAtom();
+    }
+
+    /**
+     * Show feed specific Atom elements
+     *
+     * @return void
+     */
+
+    function showFeed()
+    {
+        // TODO: A9 OpenSearch stuff like search.twitter.com?
+
+        $server   = common_config('site', 'server');
+        $sitename = common_config('site', 'name');
+
+        // XXX: Use xmlns:statusnet instead?
+
+        $this->elementStart('feed',
+            array('xmlns' => 'http://www.w3.org/2005/Atom',
+
+                             // XXX: xmlns:twitter causes Atom validation to fail
+                             // It's used for the source attr on notices
+
+                             'xmlns:twitter' => 'http://api.twitter.com/',
+                             'xml:lang' => 'en-US')); // XXX Other locales ?
+
+        $taguribase = TagURI::base();
+        $this->element('id', null, "tag:$taguribase:search/$server");
+
+        $site_uri = common_path(false);
+
+        $search_uri = $site_uri . 'api/search.atom?q=' . urlencode($this->query);
+
+        if ($this->rpp != 15) {
+            $search_uri .= '&rpp=' . $this->rpp;
+        }
+
+        // FIXME: this alternate link is not quite right because our
+        // web-based notice search doesn't support a rpp (responses per
+        // page) param yet
+
+        $this->element('link', array('type' => 'text/html',
+                                     'rel'  => 'alternate',
+                                     'href' => $site_uri . 'search/notice?q=' .
+                                        urlencode($this->query)));
+
+        // self link
+
+        $self_uri = $search_uri;
+        $self_uri .= ($this->page > 1) ? '&page=' . $this->page : '';
+
+        $this->element('link', array('type' => 'application/atom+xml',
+                                     'rel'  => 'self',
+                                     'href' => $self_uri));
+
+        $this->element('title', null, "$this->query - $sitename Search");
+        $this->element('updated', null, common_date_iso8601('now'));
+
+        // XXX: The below "rel" links are not valid Atom, but it's what
+        // Twitter does...
+
+        // refresh link
+
+        $refresh_uri = $search_uri . "&since_id=" . $this->max_id;
+
+        $this->element('link', array('type' => 'application/atom+xml',
+                                     'rel'  => 'refresh',
+                                     'href' => $refresh_uri));
+
+        // pagination links
+
+        if ($this->cnt > $this->rpp) {
+
+            $next_uri = $search_uri . "&max_id=" . $this->max_id .
+                '&page=' . ($this->page + 1);
+
+            $this->element('link', array('type' => 'application/atom+xml',
+                                         'rel'  => 'next',
+                                         'href' => $next_uri));
+        }
+
+        if ($this->page > 1) {
+
+            $previous_uri = $search_uri . "&max_id=" . $this->max_id .
+                '&page=' . ($this->page - 1);
+
+            $this->element('link', array('type' => 'application/atom+xml',
+                                         'rel'  => 'previous',
+                                         'href' => $previous_uri));
+        }
+
+    }
+
+    /**
+     * Build an Atom entry similar to search.twitter.com's based on
+     * a given notice
+     *
+     * @param Notice $notice the notice to use
+     *
+     * @return void
+     */
+
+    function showEntry($notice)
+    {
+        $server  = common_config('site', 'server');
+        $profile = $notice->getProfile();
+        $nurl    = common_local_url('shownotice', array('notice' => $notice->id));
+
+        $this->elementStart('entry');
+
+        $taguribase = TagURI::base();
+
+        $this->element('id', null, "tag:$taguribase:$notice->id");
+        $this->element('published', null, common_date_w3dtf($notice->created));
+        $this->element('link', array('type' => 'text/html',
+                                     'rel'  => 'alternate',
+                                     'href' => $nurl));
+        $this->element('title', null, common_xml_safe_str(trim($notice->content)));
+        $this->element('content', array('type' => 'html'), $notice->rendered);
+        $this->element('updated', null, common_date_w3dtf($notice->created));
+        $this->element('link', array('type' => 'image/png',
+                                     // XXX: Twitter uses rel="image" (not valid)
+                                     'rel' => 'related',
+                                     'href' => $profile->avatarUrl()));
+
+        // @todo: Here is where we'd put in a link to an atom feed for threads
+
+        $source = null;
+
+        $ns = $notice->getSource();
+        if ($ns) {
+            if (!empty($ns->name) && !empty($ns->url)) {
+                $source = '<a href="'
+                  . htmlspecialchars($ns->url)
+                  . '" rel="nofollow">'
+                  . htmlspecialchars($ns->name)
+                  . '</a>';
+            } else {
+                $source = $ns->code;
+            }
+        }
+
+        $this->element("twitter:source", null, $source);
+
+        $this->elementStart('author');
+
+        $name = $profile->nickname;
+
+        if ($profile->fullname) {
+            $name .= ' (' . $profile->fullname . ')';
+        }
+
+        $this->element('name', null, $name);
+        $this->element('uri', null, common_profile_uri($profile));
+        $this->elementEnd('author');
+
+        $this->elementEnd('entry');
+    }
+
+    /**
+     * Initialize the Atom output, send headers
+     *
+     * @return void
+     */
+
+    function initAtom()
+    {
+        header('Content-Type: application/atom+xml; charset=utf-8');
+        $this->startXml();
+    }
+
+    /**
+     * End the Atom feed
+     *
+     * @return void
+     */
+
+    function endAtom()
+    {
+        $this->elementEnd('feed');
+    }
+
+}
diff --git a/actions/apisearchjson.php b/actions/apisearchjson.php
new file mode 100644 (file)
index 0000000..e446346
--- /dev/null
@@ -0,0 +1,154 @@
+<?php
+/**
+ * StatusNet, the distributed open-source microblogging tool
+ *
+ * Action for showing Twitter-like JSON search results
+ *
+ * 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  Search
+ * @package   StatusNet
+ * @author    Zach Copley <zach@status.net>
+ * @copyright 2008-2010 StatusNet, Inc.
+ * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link      http://status.net/
+ */
+
+if (!defined('STATUSNET') && !defined('LACONICA')) {
+    exit(1);
+}
+
+require_once INSTALLDIR.'/lib/apiprivateauth.php';
+require_once INSTALLDIR.'/lib/jsonsearchresultslist.php';
+
+/**
+ * Action handler for Twitter-compatible API search
+ *
+ * @category Search
+ * @package  StatusNet
+ * @author   Zach Copley <zach@status.net>
+ * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link     http://status.net/
+ * @see      ApiAction
+ */
+
+class ApiSearchJSONAction extends ApiPrivateAuthAction
+{
+    var $query;
+    var $lang;
+    var $rpp;
+    var $page;
+    var $since_id;
+    var $limit;
+    var $geocode;
+
+    /**
+     * Initialization.
+     *
+     * @param array $args Web and URL arguments
+     *
+     * @return boolean true if nothing goes wrong
+     */
+
+    function prepare($args)
+    {
+        common_debug("apisearchjson prepare()");
+
+        parent::prepare($args);
+
+        $this->query = $this->trimmed('q');
+        $this->lang  = $this->trimmed('lang');
+        $this->rpp   = $this->trimmed('rpp');
+
+        if (!$this->rpp) {
+            $this->rpp = 15;
+        }
+
+        if ($this->rpp > 100) {
+            $this->rpp = 100;
+        }
+
+        $this->page = $this->trimmed('page');
+
+        if (!$this->page) {
+            $this->page = 1;
+        }
+
+        $this->since_id = $this->trimmed('since_id');
+        $this->geocode  = $this->trimmed('geocode');
+
+        return true;
+    }
+
+    /**
+     * Handle a request
+     *
+     * @param array $args Arguments from $_REQUEST
+     *
+     * @return void
+     */
+
+    function handle($args)
+    {
+        parent::handle($args);
+        $this->showResults();
+    }
+
+    /**
+     * Show search results
+     *
+     * @return void
+     */
+
+    function showResults()
+    {
+
+        // TODO: Support search operators like from: and to:, boolean, etc.
+
+        $notice = new Notice();
+
+        // lcase it for comparison
+        $q = strtolower($this->query);
+
+        $search_engine = $notice->getSearchEngine('notice');
+        $search_engine->set_sort_mode('chron');
+        $search_engine->limit(($this->page - 1) * $this->rpp, $this->rpp + 1, true);
+        if (false === $search_engine->query($q)) {
+            $cnt = 0;
+        } else {
+            $cnt = $notice->find();
+        }
+
+        // TODO: since_id, lang, geocode
+
+        $results = new JSONSearchResultsList($notice, $q, $this->rpp, $this->page);
+
+        $this->initDocument('json');
+        $results->show();
+        $this->endDocument('json');
+    }
+
+    /**
+     * Do we need to write to the database?
+     *
+     * @return boolean true
+     */
+
+    function isReadOnly($args)
+    {
+        return true;
+    }
+}
index 0ba324057e753d84cd22463d13f51584f5de60e9..63d65f2893ca51e37002153b9defd2eac4008d53 100644 (file)
@@ -206,7 +206,8 @@ class ApiSubscriptionsAction extends ApiBareAuthAction
     {
         switch ($this->format) {
         case 'xml':
-            $this->elementStart('users', array('type' => 'array'));
+            $this->elementStart('users', array('type' => 'array',
+                                               'xmlns:statusnet' => 'http://status.net/schema/api/1/'));
             foreach ($this->profiles as $profile) {
                 $this->showProfile(
                     $profile,
diff --git a/actions/apitrends.php b/actions/apitrends.php
new file mode 100644 (file)
index 0000000..5b74636
--- /dev/null
@@ -0,0 +1,90 @@
+<?php
+/**
+ * StatusNet, the distributed open-source microblogging tool
+ *
+ * List of replies
+ *
+ * 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  Search
+ * @package   StatusNet
+ * @author    Zach Copley <zach@status.net>
+ * @copyright 2008-2010 StatusNet, Inc.
+ * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link      http://status.net/
+ */
+
+if (!defined('STATUSNET') && !defined('LACONICA')) {
+    exit(1);
+}
+
+require_once INSTALLDIR.'/lib/apiprivateauth.php';
+
+/**
+ *  Returns the top ten queries that are currently trending
+ *
+ * @category Search
+ * @package  StatusNet
+ * @author   Zach Copley <zach@status.net>
+ * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link     http://status.net/
+ *
+ * @see      ApiAction
+ */
+
+class ApiTrendsAction extends ApiPrivateAuthAction
+{
+
+    var $callback;
+
+    /**
+     * Initialization.
+     *
+     * @param array $args Web and URL arguments
+     *
+     * @return boolean false if user doesn't exist
+     */
+    function prepare($args)
+    {
+        parent::prepare($args);
+        return true;
+    }
+
+    /**
+     * Handle a request
+     *
+     * @param array $args Arguments from $_REQUEST
+     *
+     * @return void
+     */
+
+    function handle($args)
+    {
+        parent::handle($args);
+        $this->showTrends();
+    }
+
+    /**
+     * Output the trends
+     *
+     * @return void
+     */
+    function showTrends()
+    {
+        $this->serverError(_('API method under construction.'), 501);
+    }
+
+}
\ No newline at end of file
index 3d369e9ebfbf7d46577be5ba3f0b31d559b76640..17c37e4d79f82c15cf2ab5aad846b78f1625a9e8 100644 (file)
@@ -430,14 +430,6 @@ class ShowgroupAction extends GroupDesignAction
 
     function showStatistics()
     {
-        // XXX: WORM cache this
-        $members = $this->group->getMembers();
-        $members_count = 0;
-        /** $member->count() doesn't work. */
-        while ($members->fetch()) {
-            $members_count++;
-        }
-
         $this->elementStart('div', array('id' => 'entity_statistics',
                                          'class' => 'section'));
 
@@ -451,7 +443,7 @@ class ShowgroupAction extends GroupDesignAction
 
         $this->elementStart('dl', 'entity_members');
         $this->element('dt', null, _('Members'));
-        $this->element('dd', null, (is_int($members_count)) ? $members_count : '0');
+        $this->element('dd', null, $this->group->getMemberCount());
         $this->elementEnd('dl');
 
         $this->elementEnd('div');
diff --git a/actions/twitapisearchatom.php b/actions/twitapisearchatom.php
deleted file mode 100644 (file)
index 51e8a88..0000000
+++ /dev/null
@@ -1,402 +0,0 @@
-<?php
-/**
- * StatusNet, the distributed open-source microblogging tool
- *
- * Action for showing Twitter-like Atom search results
- *
- * 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  Search
- * @package   StatusNet
- * @author    Zach Copley <zach@status.net>
- * @copyright 2008-2009 StatusNet, Inc.
- * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link      http://status.net/
- */
-
-if (!defined('STATUSNET') && !defined('LACONICA')) {
-    exit(1);
-}
-
-/**
- * Action for outputting search results in Twitter compatible Atom
- * format.
- *
- * TODO: abstract Atom stuff into a ruseable base class like
- * RSS10Action.
- *
- * @category Search
- * @package  StatusNet
- * @author   Zach Copley <zach@status.net>
- * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link     http://status.net/
- *
- * @see      ApiAction
- */
-
-class TwitapisearchatomAction extends ApiAction
-{
-
-    var $cnt;
-    var $query;
-    var $lang;
-    var $rpp;
-    var $page;
-    var $since_id;
-    var $geocode;
-
-    /**
-     * Constructor
-     *
-     * Just wraps the Action constructor.
-     *
-     * @param string  $output URI to output to, default = stdout
-     * @param boolean $indent Whether to indent output, default true
-     *
-     * @see Action::__construct
-     */
-
-    function __construct($output='php://output', $indent=null)
-    {
-        parent::__construct($output, $indent);
-    }
-
-    /**
-     * Do we need to write to the database?
-     *
-     * @return boolean true
-     */
-
-    function isReadonly()
-    {
-        return true;
-    }
-
-    /**
-     * Read arguments and initialize members
-     *
-     * @param array $args Arguments from $_REQUEST
-     *
-     * @return boolean success
-     *
-     */
-
-    function prepare($args)
-    {
-        parent::prepare($args);
-
-        $this->query = $this->trimmed('q');
-        $this->lang  = $this->trimmed('lang');
-        $this->rpp   = $this->trimmed('rpp');
-
-        if (!$this->rpp) {
-            $this->rpp = 15;
-        }
-
-        if ($this->rpp > 100) {
-            $this->rpp = 100;
-        }
-
-        $this->page = $this->trimmed('page');
-
-        if (!$this->page) {
-            $this->page = 1;
-        }
-
-        // TODO: Suppport since_id -- we need to tweak the backend
-        // Search classes to support it.
-
-        $this->since_id = $this->trimmed('since_id');
-        $this->geocode  = $this->trimmed('geocode');
-
-        // TODO: Also, language and geocode
-
-        return true;
-    }
-
-    /**
-     * Handle a request
-     *
-     * @param array $args Arguments from $_REQUEST
-     *
-     * @return void
-     */
-
-    function handle($args)
-    {
-        parent::handle($args);
-        $this->showAtom();
-    }
-
-    /**
-     * Get the notices to output as results. This also sets some class
-     * attrs so we can use them to calculate pagination, and output
-     * since_id and max_id.
-     *
-     * @return array an array of Notice objects sorted in reverse chron
-     */
-
-    function getNotices()
-    {
-        // TODO: Support search operators like from: and to:, boolean, etc.
-
-        $notices = array();
-        $notice = new Notice();
-
-        // lcase it for comparison
-        $q = strtolower($this->query);
-
-        $search_engine = $notice->getSearchEngine('notice');
-        $search_engine->set_sort_mode('chron');
-        $search_engine->limit(($this->page - 1) * $this->rpp,
-            $this->rpp + 1, true);
-        if (false === $search_engine->query($q)) {
-            $this->cnt = 0;
-        } else {
-            $this->cnt = $notice->find();
-        }
-
-        $cnt = 0;
-        $this->max_id = 0;
-
-        if ($this->cnt > 0) {
-            while ($notice->fetch()) {
-
-                ++$cnt;
-
-                if (!$this->max_id) {
-                    $this->max_id = $notice->id;
-                }
-
-                if ($cnt > $this->rpp) {
-                    break;
-                }
-
-                $notices[] = clone($notice);
-            }
-        }
-
-        return $notices;
-    }
-
-    /**
-     * Output search results as an Atom feed
-     *
-     * @return void
-     */
-
-    function showAtom()
-    {
-        $notices = $this->getNotices();
-
-        $this->initAtom();
-        $this->showFeed();
-
-        foreach ($notices as $n) {
-
-            $profile = $n->getProfile();
-
-            // Don't show notices from deleted users
-
-            if (!empty($profile)) {
-                $this->showEntry($n);
-            }
-        }
-
-        $this->endAtom();
-    }
-
-    /**
-     * Show feed specific Atom elements
-     *
-     * @return void
-     */
-
-    function showFeed()
-    {
-        // TODO: A9 OpenSearch stuff like search.twitter.com?
-
-        $server   = common_config('site', 'server');
-        $sitename = common_config('site', 'name');
-
-        // XXX: Use xmlns:statusnet instead?
-
-        $this->elementStart('feed',
-            array('xmlns' => 'http://www.w3.org/2005/Atom',
-
-                             // XXX: xmlns:twitter causes Atom validation to fail
-                             // It's used for the source attr on notices
-
-                             'xmlns:twitter' => 'http://api.twitter.com/',
-                             'xml:lang' => 'en-US')); // XXX Other locales ?
-
-        $taguribase = TagURI::base();
-        $this->element('id', null, "tag:$taguribase:search/$server");
-
-        $site_uri = common_path(false);
-
-        $search_uri = $site_uri . 'api/search.atom?q=' . urlencode($this->query);
-
-        if ($this->rpp != 15) {
-            $search_uri .= '&rpp=' . $this->rpp;
-        }
-
-        // FIXME: this alternate link is not quite right because our
-        // web-based notice search doesn't support a rpp (responses per
-        // page) param yet
-
-        $this->element('link', array('type' => 'text/html',
-                                     'rel'  => 'alternate',
-                                     'href' => $site_uri . 'search/notice?q=' .
-                                        urlencode($this->query)));
-
-        // self link
-
-        $self_uri = $search_uri;
-        $self_uri .= ($this->page > 1) ? '&page=' . $this->page : '';
-
-        $this->element('link', array('type' => 'application/atom+xml',
-                                     'rel'  => 'self',
-                                     'href' => $self_uri));
-
-        $this->element('title', null, "$this->query - $sitename Search");
-        $this->element('updated', null, common_date_iso8601('now'));
-
-        // XXX: The below "rel" links are not valid Atom, but it's what
-        // Twitter does...
-
-        // refresh link
-
-        $refresh_uri = $search_uri . "&since_id=" . $this->max_id;
-
-        $this->element('link', array('type' => 'application/atom+xml',
-                                     'rel'  => 'refresh',
-                                     'href' => $refresh_uri));
-
-        // pagination links
-
-        if ($this->cnt > $this->rpp) {
-
-            $next_uri = $search_uri . "&max_id=" . $this->max_id .
-                '&page=' . ($this->page + 1);
-
-            $this->element('link', array('type' => 'application/atom+xml',
-                                         'rel'  => 'next',
-                                         'href' => $next_uri));
-        }
-
-        if ($this->page > 1) {
-
-            $previous_uri = $search_uri . "&max_id=" . $this->max_id .
-                '&page=' . ($this->page - 1);
-
-            $this->element('link', array('type' => 'application/atom+xml',
-                                         'rel'  => 'previous',
-                                         'href' => $previous_uri));
-        }
-
-    }
-
-    /**
-     * Build an Atom entry similar to search.twitter.com's based on
-     * a given notice
-     *
-     * @param Notice $notice the notice to use
-     *
-     * @return void
-     */
-
-    function showEntry($notice)
-    {
-        $server  = common_config('site', 'server');
-        $profile = $notice->getProfile();
-        $nurl    = common_local_url('shownotice', array('notice' => $notice->id));
-
-        $this->elementStart('entry');
-
-        $taguribase = TagURI::base();
-
-        $this->element('id', null, "tag:$taguribase:$notice->id");
-        $this->element('published', null, common_date_w3dtf($notice->created));
-        $this->element('link', array('type' => 'text/html',
-                                     'rel'  => 'alternate',
-                                     'href' => $nurl));
-        $this->element('title', null, common_xml_safe_str(trim($notice->content)));
-        $this->element('content', array('type' => 'html'), $notice->rendered);
-        $this->element('updated', null, common_date_w3dtf($notice->created));
-        $this->element('link', array('type' => 'image/png',
-                                     // XXX: Twitter uses rel="image" (not valid)
-                                     'rel' => 'related',
-                                     'href' => $profile->avatarUrl()));
-
-        // @todo: Here is where we'd put in a link to an atom feed for threads
-
-        $source = null;
-
-        $ns = $notice->getSource();
-        if ($ns) {
-            if (!empty($ns->name) && !empty($ns->url)) {
-                $source = '<a href="'
-                  . htmlspecialchars($ns->url)
-                  . '" rel="nofollow">'
-                  . htmlspecialchars($ns->name)
-                  . '</a>';
-            } else {
-                $source = $ns->code;
-            }
-        }
-
-        $this->element("twitter:source", null, $source);
-
-        $this->elementStart('author');
-
-        $name = $profile->nickname;
-
-        if ($profile->fullname) {
-            $name .= ' (' . $profile->fullname . ')';
-        }
-
-        $this->element('name', null, $name);
-        $this->element('uri', null, common_profile_uri($profile));
-        $this->elementEnd('author');
-
-        $this->elementEnd('entry');
-    }
-
-    /**
-     * Initialize the Atom output, send headers
-     *
-     * @return void
-     */
-
-    function initAtom()
-    {
-        header('Content-Type: application/atom+xml; charset=utf-8');
-        $this->startXml();
-    }
-
-    /**
-     * End the Atom feed
-     *
-     * @return void
-     */
-
-    function endAtom()
-    {
-        $this->elementEnd('feed');
-    }
-
-}
diff --git a/actions/twitapisearchjson.php b/actions/twitapisearchjson.php
deleted file mode 100644 (file)
index b5c006a..0000000
+++ /dev/null
@@ -1,151 +0,0 @@
-<?php
-/**
- * StatusNet, the distributed open-source microblogging tool
- *
- * Action for showing Twitter-like JSON search results
- *
- * 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  Search
- * @package   StatusNet
- * @author    Zach Copley <zach@status.net>
- * @copyright 2008-2009 StatusNet, Inc.
- * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link      http://status.net/
- */
-
-if (!defined('STATUSNET') && !defined('LACONICA')) {
-    exit(1);
-}
-
-require_once INSTALLDIR.'/lib/jsonsearchresultslist.php';
-
-/**
- * Action handler for Twitter-compatible API search
- *
- * @category Search
- * @package  StatusNet
- * @author   Zach Copley <zach@status.net>
- * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link     http://status.net/
- * @see      ApiAction
- */
-
-class TwitapisearchjsonAction extends ApiAction
-{
-    var $query;
-    var $lang;
-    var $rpp;
-    var $page;
-    var $since_id;
-    var $limit;
-    var $geocode;
-
-    /**
-     * Initialization.
-     *
-     * @param array $args Web and URL arguments
-     *
-     * @return boolean true if nothing goes wrong
-     */
-
-    function prepare($args)
-    {
-        parent::prepare($args);
-
-        $this->query = $this->trimmed('q');
-        $this->lang  = $this->trimmed('lang');
-        $this->rpp   = $this->trimmed('rpp');
-
-        if (!$this->rpp) {
-            $this->rpp = 15;
-        }
-
-        if ($this->rpp > 100) {
-            $this->rpp = 100;
-        }
-
-        $this->page = $this->trimmed('page');
-
-        if (!$this->page) {
-            $this->page = 1;
-        }
-
-        $this->since_id = $this->trimmed('since_id');
-        $this->geocode  = $this->trimmed('geocode');
-
-        return true;
-    }
-
-    /**
-     * Handle a request
-     *
-     * @param array $args Arguments from $_REQUEST
-     *
-     * @return void
-     */
-
-    function handle($args)
-    {
-        parent::handle($args);
-        $this->showResults();
-    }
-
-    /**
-     * Show search results
-     *
-     * @return void
-     */
-
-    function showResults()
-    {
-
-        // TODO: Support search operators like from: and to:, boolean, etc.
-
-        $notice = new Notice();
-
-        // lcase it for comparison
-        $q = strtolower($this->query);
-
-        $search_engine = $notice->getSearchEngine('notice');
-        $search_engine->set_sort_mode('chron');
-        $search_engine->limit(($this->page - 1) * $this->rpp, $this->rpp + 1, true);
-        if (false === $search_engine->query($q)) {
-            $cnt = 0;
-        } else {
-            $cnt = $notice->find();
-        }
-
-        // TODO: since_id, lang, geocode
-
-        $results = new JSONSearchResultsList($notice, $q, $this->rpp, $this->page);
-
-        $this->initDocument('json');
-        $results->show();
-        $this->endDocument('json');
-    }
-
-    /**
-     * Do we need to write to the database?
-     *
-     * @return boolean true
-     */
-
-    function isReadOnly($args)
-    {
-        return true;
-    }
-}
diff --git a/actions/twitapitrends.php b/actions/twitapitrends.php
deleted file mode 100644 (file)
index 5a04569..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-<?php
-/**
- * StatusNet, the distributed open-source microblogging tool
- *
- * List of replies
- *
- * 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  Search
- * @package   StatusNet
- * @author    Zach Copley <zach@status.net>
- * @copyright 2008-2009 StatusNet, Inc.
- * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link      http://status.net/
- */
-
-if (!defined('STATUSNET') && !defined('LACONICA')) {
-    exit(1);
-}
-
-/**
- *  Returns the top ten queries that are currently trending
- *
- * @category Search
- * @package  StatusNet
- * @author   Zach Copley <zach@status.net>
- * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link     http://status.net/
- *
- * @see      ApiAction
- */
-
-class TwitapitrendsAction extends ApiAction
-{
-
-    var $callback;
-
-    /**
-     * Initialization.
-     *
-     * @param array $args Web and URL arguments
-     *
-     * @return boolean false if user doesn't exist
-     */
-    function prepare($args)
-    {
-        parent::prepare($args);
-        return true;
-    }
-
-    /**
-     * Handle a request
-     *
-     * @param array $args Arguments from $_REQUEST
-     *
-     * @return void
-     */
-
-    function handle($args)
-    {
-        parent::handle($args);
-        $this->showTrends();
-    }
-
-    /**
-     * Output the trends
-     *
-     * @return void
-     */
-    function showTrends()
-    {
-        $this->serverError(_('API method under construction.'), $code = 501);
-    }
-
-}
\ No newline at end of file
index fd8ad5493d0cc1a7a2d4e50b91ebc96530a94aaf..482bc550b9d093880d2d181b4355e6b9bfab3549 100644 (file)
@@ -1192,7 +1192,7 @@ class Notice extends Memcached_DataObject
                            'xmlns:media' => 'http://purl.org/syndication/atommedia',
                            'xmlns:poco' => 'http://portablecontacts.net/spec/1.0',
                            'xmlns:ostatus' => 'http://ostatus.org/schema/1.0',
-                           'xmlns:statusnet' => 'http://status.net/ont/');
+                           'xmlns:statusnet' => 'http://status.net/schema/api/1/');
         } else {
             $attrs = array();
         }
@@ -1227,7 +1227,7 @@ class Notice extends Memcached_DataObject
         $xs->element('title', null, common_xml_safe_str($this->content));
 
         if ($author) {
-            $xs->raw($profile->asAtomAuthor());
+            $xs->raw($profile->asAtomAuthor($cur));
             $xs->raw($profile->asActivityActor());
         }
 
@@ -1240,9 +1240,25 @@ class Notice extends Memcached_DataObject
         $xs->element('published', null, common_date_w3dtf($this->created));
         $xs->element('updated', null, common_date_w3dtf($this->created));
 
+        $source = null;
+
+        $ns = $this->getSource();
+
+        if ($ns) {
+            if (!empty($ns->name) && !empty($ns->url)) {
+                $source = '<a href="'
+                  . htmlspecialchars($ns->url)
+                  . '" rel="nofollow">'
+                  . htmlspecialchars($ns->name)
+                   . '</a>';
+            } else {
+                $source = $ns->code;
+            }
+        }
+
         $noticeInfoAttr = array(
-            'local_id'   => $this->id,    // local notice ID (useful to clients for ordering)
-            'source'     => $this->source, // the client name (source attribution)
+            'local_id'   => $this->id, // local notice ID (useful to clients for ordering)
+            'source'     => $source,   // the client name (source attribution)
         );
 
         $ns = $this->getSource();
@@ -1254,8 +1270,8 @@ class Notice extends Memcached_DataObject
 
         if (!empty($cur)) {
             $noticeInfoAttr['favorite'] = ($cur->hasFave($this)) ? "true" : "false";
-           $profile = $cur->getProfile();
-           $noticeInfoAttr['repeated'] = ($profile->hasRepeated($this->id)) ? "true" : "false";
+            $profile = $cur->getProfile();
+            $noticeInfoAttr['repeated'] = ($profile->hasRepeated($this->id)) ? "true" : "false";
         }
 
         if (!empty($this->repeat_of)) {
index 54f557ea7cee40201f631ca7aa1416731b3693b4..a303469e96851652b18b49009f7aeda5a7fc063c 100644 (file)
@@ -849,15 +849,23 @@ class Profile extends Memcached_DataObject
      *
      * Assumes that Atom has been previously set up as the base namespace.
      *
+     * @param Profile $cur the current authenticated user
+     *
      * @return string
      */
-    function asAtomAuthor()
+    function asAtomAuthor($cur = null)
     {
         $xs = new XMLStringer(true);
 
         $xs->elementStart('author');
         $xs->element('name', null, $this->nickname);
         $xs->element('uri', null, $this->getUri());
+        if ($cur != null) {
+            $attrs = Array();
+            $attrs['following'] = $cur->isSubscribed($this) ? 'true' : 'false';
+            $attrs['blocking']  = $cur->hasBlocked($this) ? 'true' : 'false';
+            $xs->element('statusnet:profile_info', $attrs, null);
+        }
         $xs->elementEnd('author');
 
         return $xs->getString();
index 4a1f2c37475a4ef4a91ff26d7fd8260669387688..64016dd790c06233587ab8b80a651571fe75d80a 100644 (file)
@@ -144,6 +144,35 @@ class Status_network extends Safe_DataObject
         return parent::update($orig);
     }
 
+    /**
+     * DB_DataObject doesn't allow updating keys (even non-primary)
+     */
+    function updateKeys(&$orig)
+    {
+        $this->_connect();
+        foreach (array('hostname', 'pathname') as $k) {
+            if (strcmp($this->$k, $orig->$k) != 0) {
+                $parts[] = $k . ' = ' . $this->_quote($this->$k);
+            }
+        }
+        if (count($parts) == 0) {
+            // No changes
+            return true;
+        }
+
+        $toupdate = implode(', ', $parts);
+
+        $table = common_database_tablename($this->tableName());
+        $qry = 'UPDATE ' . $table . ' SET ' . $toupdate .
+            ' WHERE nickname = ' . $this->_quote($this->nickname);
+        $orig->decache();
+        $result = $this->query($qry);
+        if ($result) {
+            $this->encache();
+        }
+        return $result;
+    }
+    
     function delete()
     {
         $this->decache(); # while we still have the values!
index 110f0830125f0cbe64389e61d2d5d510281c5697..e04c46626635fad66821bd3b1d75af0be8063d19 100644 (file)
@@ -154,6 +154,21 @@ class User_group extends Memcached_DataObject
         return $members;
     }
 
+    function getMemberCount()
+    {
+        // XXX: WORM cache this
+
+        $members = $this->getMembers();
+        $member_count = 0;
+
+        /** $member->count() doesn't work. */
+        while ($members->fetch()) {
+            $member_count++;
+        }
+
+        return $member_count;
+    }
+
     function getAdmins($offset=0, $limit=null)
     {
         $qry =
index 27df558928f003e5bd1457fec0aec05c18db7ee4..89a4871029d3efc208cd3fc512c777bb8f0840cc 100644 (file)
@@ -271,11 +271,13 @@ class ApiAction extends Action
 
         // Is the requesting user following this user?
         $twitter_user['following'] = false;
+        $twitter_user['statusnet:blocking'] = false;
         $twitter_user['notifications'] = false;
 
         if (isset($this->auth_user)) {
 
             $twitter_user['following'] = $this->auth_user->isSubscribed($profile);
+            $twitter_user['statusnet:blocking']  = $this->auth_user->hasBlocked($profile);
 
             // Notifications on?
             $sub = Subscription::pkeyGet(array('subscriber' =>
@@ -409,20 +411,32 @@ class ApiAction extends Action
 
     function twitterGroupArray($group)
     {
-        $twitter_group=array();
-        $twitter_group['id']=$group->id;
-        $twitter_group['url']=$group->permalink();
-        $twitter_group['nickname']=$group->nickname;
-        $twitter_group['fullname']=$group->fullname;
-        $twitter_group['original_logo']=$group->original_logo;
-        $twitter_group['homepage_logo']=$group->homepage_logo;
-        $twitter_group['stream_logo']=$group->stream_logo;
-        $twitter_group['mini_logo']=$group->mini_logo;
-        $twitter_group['homepage']=$group->homepage;
-        $twitter_group['description']=$group->description;
-        $twitter_group['location']=$group->location;
-        $twitter_group['created']=$this->dateTwitter($group->created);
-        $twitter_group['modified']=$this->dateTwitter($group->modified);
+        $twitter_group = array();
+
+        $twitter_group['id'] = $group->id;
+        $twitter_group['url'] = $group->permalink();
+        $twitter_group['nickname'] = $group->nickname;
+        $twitter_group['fullname'] = $group->fullname;
+
+        if (isset($this->auth_user)) {
+            $twitter_group['member'] = $this->auth_user->isMember($group);
+            $twitter_group['blocked'] = Group_block::isBlocked(
+                $group,
+                $this->auth_user->getProfile()
+            );
+        }
+
+        $twitter_group['member_count'] = $group->getMemberCount();
+        $twitter_group['original_logo'] = $group->original_logo;
+        $twitter_group['homepage_logo'] = $group->homepage_logo;
+        $twitter_group['stream_logo'] = $group->stream_logo;
+        $twitter_group['mini_logo'] = $group->mini_logo;
+        $twitter_group['homepage'] = $group->homepage;
+        $twitter_group['description'] = $group->description;
+        $twitter_group['location'] = $group->location;
+        $twitter_group['created'] = $this->dateTwitter($group->created);
+        $twitter_group['modified'] = $this->dateTwitter($group->modified);
+
         return $twitter_group;
     }
 
index c7c36af82571faf995447e5e5c3bc2ac8fa57a2a..39a1fd456efa02a3a89f553d4469f8ddbbf705a2 100644 (file)
@@ -96,4 +96,23 @@ class AtomGroupNoticeFeed extends AtomNoticeFeed
         return $this->group;
     }
 
+    function initFeed()
+    {
+        parent::initFeed();
+
+        $attrs = array();
+
+        if (!empty($this->cur)) {
+            $attrs['member'] = $this->cur->isMember($this->group)
+                ? 'true' : 'false';
+            $attrs['blocked'] = Group_block::isBlocked(
+                $this->group,
+                $this->cur->getProfile()
+            ) ? 'true' : 'false';
+        }
+
+        $attrs['member_count'] = $this->group->getMemberCount();
+
+        $this->element('statusnet:group_info', $attrs, null);
+    }
 }
index ef44de4b6ce615bdafe4fc7e34f315ed06bceb01..6ed803ce4ebb35a0350f669b26fc098b896a3585 100644 (file)
@@ -95,7 +95,7 @@ class AtomNoticeFeed extends Atom10Feed
 
         $this->addNamespace(
             'statusnet',
-            'http://status.net/ont/'
+            'http://status.net/schema/api/1/'
         );
     }
 
index e67799e2ebee46f454fa67d7efd8bfe0c61b0d50..7d4256d6e10ab4979e741e274c9ac3ef4827d66b 100644 (file)
@@ -76,8 +76,8 @@ class AvatarLink
         $alink = new AvatarLink();
         $alink->url    = $filename;
         $alink->height = $size;
+        $alink->width  = $size;
         if (!empty($filename)) {
-            $alink->width  = $size;
             $alink->type   = self::mediatype($filename);
         } else {
             $alink->url    = User_group::defaultLogo($size);
index 56b9b6f4a25b510de25d7c02fd36c8ed6586e354..bd9d69cd4a0471cd86e8184ac684f18b26d9c4ce 100644 (file)
@@ -447,7 +447,7 @@ abstract class Installer
             case 'mysqli':
                 $res = $conn->query($stmt);
                 if ($res === false) {
-                    $error = $conn->error();
+                    $error = $conn->error;
                 }
                 break;
             case 'pgsql':
index f2b2b845f2836607e12f569b3246097250afdc12..7e1e6a2a47a1887781c3154cb1684e6d39d7b6e1 100644 (file)
@@ -263,7 +263,7 @@ class Router
             $m->connect('tag', array('action' => 'publictagcloud'));
             $m->connect('tag/:tag/rss',
                         array('action' => 'tagrss'),
-                        array('tag' => '[a-zA-Z0-9]+'));
+                        array('tag' => '[\pL\pN_\-\.]{1,64}'));
             $m->connect('tag/:tag',
                         array('action' => 'tag'),
                         array('tag' => '[\pL\pN_\-\.]{1,64}'));
@@ -667,9 +667,9 @@ class Router
             );
 
             // search
-            $m->connect('api/search.atom', array('action' => 'twitapisearchatom'));
-            $m->connect('api/search.json', array('action' => 'twitapisearchjson'));
-            $m->connect('api/trends.json', array('action' => 'twitapitrends'));
+            $m->connect('api/search.atom', array('action' => 'ApiSearchAtom'));
+            $m->connect('api/search.json', array('action' => 'ApiSearchJSON'));
+            $m->connect('api/trends.json', array('action' => 'ApiTrends'));
 
             $m->connect('api/oauth/request_token',
                         array('action' => 'apioauthrequesttoken'));
@@ -749,12 +749,12 @@ class Router
                 $m->connect('tag/:tag/rss',
                             array('action' => 'userrss',
                                   'nickname' => $nickname),
-                            array('tag' => '[a-zA-Z0-9]+'));
+                            array('tag' => '[\pL\pN_\-\.]{1,64}'));
 
                 $m->connect('tag/:tag',
                             array('action' => 'showstream',
                                   'nickname' => $nickname),
-                            array('tag' => '[a-zA-Z0-9]+'));
+                            array('tag' => '[\pL\pN_\-\.]{1,64}'));
 
                 $m->connect('rsd.xml',
                             array('action' => 'rsd',
@@ -815,12 +815,12 @@ class Router
                 $m->connect(':nickname/tag/:tag/rss',
                             array('action' => 'userrss'),
                             array('nickname' => '[a-zA-Z0-9]{1,64}'),
-                            array('tag' => '[a-zA-Z0-9]+'));
+                            array('tag' => '[\pL\pN_\-\.]{1,64}'));
 
                 $m->connect(':nickname/tag/:tag',
                             array('action' => 'showstream'),
                             array('nickname' => '[a-zA-Z0-9]{1,64}'),
-                            array('tag' => '[a-zA-Z0-9]+'));
+                            array('tag' => '[\pL\pN_\-\.]{1,64}'));
 
                 $m->connect(':nickname/rsd.xml',
                             array('action' => 'rsd'),
index 0e16881c5fa62706b4b62c875b8d118024ac92f5..b2cf1f8ac35fc3bed4351b7ec508a90ba99f6d31 100644 (file)
@@ -71,7 +71,11 @@ class OpenidserverAction extends Action
                     //cannot prompt the user to login in immediate mode, so answer false
                     $response = $this->generateDenyResponse($request);
                 }else{
-                    /* Go log in, and then come back. */
+                    // Go log in, and then come back.
+                    //
+                    // Note: 303 redirect rather than 307 to avoid
+                    // prompting user for form resubmission if we
+                    // were POSTed here.
                     common_set_returnto($_SERVER['REQUEST_URI']);
                     common_redirect(common_local_url('login'), 303);
                     return;
@@ -92,7 +96,12 @@ class OpenidserverAction extends Action
                         $this->oserver->encodeResponse($denyResponse); //sign the response
                         $_SESSION['openid_allow_url'] = $allowResponse->encodeToUrl();
                         $_SESSION['openid_deny_url'] = $denyResponse->encodeToUrl();
-                        //ask the user to trust this trust root
+
+                        // Ask the user to trust this trust root...
+                        //
+                        // Note: 303 redirect rather than 307 to avoid
+                        // prompting user for form resubmission if we
+                        // were POSTed here.
                         common_redirect(common_local_url('openidtrust'), 303);
                         return;
                     }
index c585da43c4eceefbee2db7039c1babc36480d971..7cc34c56863dcf1702e036857fbe678a48b30124 100644 (file)
@@ -62,12 +62,32 @@ class RecaptchaPlugin extends Plugin
     {
         $action->elementStart('li');
         $action->raw('<label for="recaptcha">Captcha</label>');
-        if($this->checkssl() === true) {
-            $action->raw(recaptcha_get_html($this->public_key), null, true);
-        } else { 
-            $action->raw(recaptcha_get_html($this->public_key));
-        }
+
+        // AJAX API will fill this div out.
+        // We're calling that instead of the regular one so we stay compatible
+        // with application/xml+xhtml output as for mobile.
+        $action->element('div', array('id' => 'recaptcha'));
         $action->elementEnd('li');
+        
+        $action->recaptchaPluginNeedsOutput = true;
+        return true;
+    }
+
+    function onEndShowScripts($action)
+    {
+        if (isset($action->recaptchaPluginNeedsOutput) && $action->recaptchaPluginNeedsOutput) {
+            // Load the AJAX API
+            if ($this->checkssl()) {
+                $url = "https://api-secure.recaptcha.net/js/recaptcha_ajax.js";
+            } else {
+                $url = "http://api.recaptcha.net/js/recaptcha_ajax.js";
+            }
+            $action->script($url);
+            
+            // And when we're ready, fill out the captcha!
+            $key = json_encode($this->public_key);
+            $action->inlinescript("\$(function(){Recaptcha.create($key, 'recaptcha');});");
+        }
         return true;
     }
 
index 7ef5f1aa9bfc088634f978dde77c3a65cd1a7c0c..d4d295237d842cf4425e34363c88660dd12dba3a 100644 (file)
@@ -71,6 +71,7 @@ class SitemapPlugin extends Plugin
         case 'SitemapindexAction':
         case 'NoticesitemapAction':
         case 'UsersitemapAction':
+        case 'SitemapadminpanelAction':
             require_once $dir . '/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
             return false;
         case 'SitemapAction':
@@ -124,6 +125,49 @@ class SitemapPlugin extends Plugin
                           'month' => '[01][0-9]',
                           'day' => '[0123][0-9]',
                           'index' => '[1-9][0-9]*'));
+
+        $m->connect('admin/sitemap',
+                    array('action' => 'sitemapadminpanel'));
+
+        return true;
+    }
+
+    /**
+     * Meta tags for "claiming" a site
+     *
+     * We add extra meta tags that search engines like Yahoo!, Google, and Bing
+     * require to let you claim your site.
+     *
+     * @param Action $action Action being executed
+     *
+     * @return boolean hook value.
+     */
+
+    function onStartShowHeadElements($action)
+    {
+        $actionName = $action->trimmed('action');
+
+        $singleUser = common_config('singleuser', 'enabled');
+
+        // Different "top" pages if it's single user or not
+
+        if (($singleUser && $actionName == 'showstream') ||
+            (!$singleUser && $actionName == 'public')) {
+
+            $keys = array('googlekey' => 'google-site-verification',
+                          'yahookey' => 'y_key',
+                          'bingkey' => 'msvalidate.01'); // XXX: is this the same for all sites?
+
+            foreach ($keys as $config => $metaname) {
+                $content = common_config('sitemap', $config);
+
+                if (!empty($content)) {
+                    $action->element('meta', array('name' => $metaname,
+                                                   'content' => $content));
+                }
+            }
+        }
+
         return true;
     }
 
@@ -160,4 +204,15 @@ class SitemapPlugin extends Plugin
 
         return true;
     }
+
+    function onEndAdminPanelNav($menu) {
+        if (AdminPanelAction::canAdmin('sitemap')) {
+            // TRANS: Menu item title/tooltip
+            $menu_title = _('Sitemap configuration');
+            // TRANS: Menu item for site administration
+            $menu->out->menuItem(common_local_url('sitemapadminpanel'), _('Sitemap'),
+                                 $menu_title, $action_name == 'sitemapadminpanel', 'nav_sitemap_admin_panel');
+        }
+        return true;
+    }
 }
diff --git a/plugins/Sitemap/sitemapadminpanel.php b/plugins/Sitemap/sitemapadminpanel.php
new file mode 100644 (file)
index 0000000..3c295b0
--- /dev/null
@@ -0,0 +1,205 @@
+<?php
+/**
+ * StatusNet, the distributed open-source microblogging tool
+ *
+ * Sitemap administration panel
+ *
+ * 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  Sitemap
+ * @package   StatusNet
+ * @author    Evan Prodromou <evan@status.net>
+ * @copyright 2010 StatusNet, Inc.
+ * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link      http://status.net/
+ */
+
+if (!defined('STATUSNET')) {
+    exit(1);
+}
+
+/**
+ * Administer sitemap settings
+ *
+ * @category Sitemap
+ * @package  StatusNet
+ * @author   Evan Prodromou <evan@status.net>
+ * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link     http://status.net/
+ */
+
+class SitemapadminpanelAction extends AdminPanelAction
+{
+    /**
+     * Returns the page title
+     *
+     * @return string page title
+     */
+
+    function title()
+    {
+        return _('Sitemap');
+    }
+
+    /**
+     * Instructions for using this form.
+     *
+     * @return string instructions
+     */
+
+    function getInstructions()
+    {
+        return _('Sitemap settings for this StatusNet site');
+    }
+
+    /**
+     * Show the site admin panel form
+     *
+     * @return void
+     */
+
+    function showForm()
+    {
+        $form = new SitemapAdminPanelForm($this);
+        $form->show();
+        return;
+    }
+
+    /**
+     * Save settings from the form
+     *
+     * @return void
+     */
+
+    function saveSettings()
+    {
+        static $settings = array('sitemap' => array('googlekey', 'yahookey', 'bingkey'));
+
+        $values = array();
+
+        foreach ($settings as $section => $parts) {
+            foreach ($parts as $setting) {
+                $values[$section][$setting] = $this->trimmed($setting);
+            }
+        }
+
+        // This throws an exception on validation errors
+
+        $this->validate($values);
+
+        // assert(all values are valid);
+
+        $config = new Config();
+
+        $config->query('BEGIN');
+
+        foreach ($settings as $section => $parts) {
+            foreach ($parts as $setting) {
+                Config::save($section, $setting, $values[$section][$setting]);
+            }
+        }
+
+        $config->query('COMMIT');
+
+        return;
+    }
+
+    function validate(&$values)
+    {
+    }
+}
+
+/**
+ * Form for the sitemap admin panel
+ */
+
+class SitemapAdminPanelForm extends AdminForm
+{
+    /**
+     * ID of the form
+     *
+     * @return int ID of the form
+     */
+
+    function id()
+    {
+        return 'form_sitemap_admin_panel';
+    }
+
+    /**
+     * class of the form
+     *
+     * @return string class of the form
+     */
+
+    function formClass()
+    {
+        return 'form_sitemap';
+    }
+
+    /**
+     * Action of the form
+     *
+     * @return string URL of the action
+     */
+
+    function action()
+    {
+        return common_local_url('sitemapadminpanel');
+    }
+
+    /**
+     * Data elements of the form
+     *
+     * @return void
+     */
+
+    function formData()
+    {
+        $this->out->elementStart('fieldset', array('id' => 'sitemap_admin'));
+        $this->out->elementStart('ul', 'form_data');
+        $this->li();
+        $this->input('googlekey',
+                     _('Google key'),
+                     _('Google Webmaster Tools verification key'),
+                     'sitemap');
+        $this->unli();
+        $this->li();
+        $this->input('yahookey',
+                     _('Yahoo key'),
+                     _('Yahoo! Site Explorer verification key'),
+                     'sitemap');
+        $this->unli();
+        $this->li();
+        $this->input('bingkey',
+                     _('Bing key'),
+                     _('Bing Webmaster Tools verification key'),
+                     'sitemap');
+        $this->unli();
+        $this->out->elementEnd('ul');
+    }
+
+    /**
+     * Action elements
+     *
+     * @return void
+     */
+
+    function formActions()
+    {
+        $this->out->submit('submit', _('Save'), 'submit', null, _('Save sitemap settings'));
+    }
+}