Favorite functionality put into plugin (not done yet)

Now we have to fix any code in the core which directly uses the Fave class
or any other favorite stuff, since it is pluginised and thus might not be
available on some installations.
This commit is contained in:
Mikael Nordfeldth 2014-06-24 15:52:54 +02:00
parent 67ed1ec77e
commit db7cc7fa75
20 changed files with 115 additions and 61 deletions

View File

@ -294,6 +294,7 @@ $default =
array('core' => array(
'AuthCrypt' => array(),
'Cronish' => array(),
'Favorite' => array(),
'LRDD' => array(),
'StrictTransportSecurity' => array(),
),

View File

@ -143,7 +143,7 @@ class Router
$main = array('login', 'logout', 'register', 'subscribe',
'unsubscribe', 'cancelsubscription', 'approvesub',
'confirmaddress', 'recoverpassword',
'invite', 'favor', 'disfavor', 'sup',
'invite', 'sup',
'block', 'unblock', 'subedit',
'groupblock', 'groupunblock',
'sandbox', 'unsandbox',
@ -454,11 +454,6 @@ class Router
'format' => '(xml|json)'));
// START qvitter API additions
$m->connect('api/statuses/favs/:id.:format',
array('action' => 'ApiStatusesFavs',
'id' => '[0-9]+',
'format' => '(xml|json)'));
$m->connect('api/attachment/:id.:format',
array('action' => 'ApiAttachment',
@ -595,39 +590,6 @@ class Router
$m->connect('api/account/rate_limit_status.:format',
array('action' => 'ApiAccountRateLimitStatus'));
// favorites
$m->connect('api/favorites/create.:format',
array('action' => 'ApiFavoriteCreate',
'format' => '(xml|json)'));
$m->connect('api/favorites/destroy.:format',
array('action' => 'ApiFavoriteDestroy',
'format' => '(xml|json)'));
$m->connect('api/favorites/list.:format',
array('action' => 'ApiTimelineFavorites',
'format' => '(xml|json|rss|atom|as)'));
$m->connect('api/favorites/:id.:format',
array('action' => 'ApiTimelineFavorites',
'id' => Nickname::INPUT_FMT,
'format' => '(xml|json|rss|atom|as)'));
$m->connect('api/favorites.:format',
array('action' => 'ApiTimelineFavorites',
'format' => '(xml|json|rss|atom|as)'));
$m->connect('api/favorites/create/:id.:format',
array('action' => 'ApiFavoriteCreate',
'id' => '[0-9]+',
'format' => '(xml|json)'));
$m->connect('api/favorites/destroy/:id.:format',
array('action' => 'ApiFavoriteDestroy',
'id' => '[0-9]+',
'format' => '(xml|json)'));
// blocks
$m->connect('api/blocks/create/:id.:format',
@ -921,16 +883,12 @@ class Router
'nickname' => $nickname));
}
foreach (array('all', 'replies', 'favorites') as $a) {
foreach (array('all', 'replies') as $a) {
$m->connect($a.'/rss',
array('action' => $a.'rss',
'nickname' => $nickname));
}
$m->connect('favorites',
array('action' => 'showfavorites',
'nickname' => $nickname));
$m->connect('avatar',
array('action' => 'avatarbynickname',
'nickname' => $nickname));
@ -1011,11 +969,8 @@ class Router
$m->connect('', array('action' => 'public'));
$m->connect('rss', array('action' => 'publicrss'));
$m->connect('featuredrss', array('action' => 'featuredrss'));
$m->connect('favoritedrss', array('action' => 'favoritedrss'));
$m->connect('featured/', array('action' => 'featured'));
$m->connect('featured', array('action' => 'featured'));
$m->connect('favorited/', array('action' => 'favorited'));
$m->connect('favorited', array('action' => 'favorited'));
$m->connect('rsd.xml', array('action' => 'rsd'));
foreach (array('subscriptions', 'subscribers',
@ -1096,16 +1051,12 @@ class Router
array('nickname' => Nickname::DISPLAY_FMT));
}
foreach (array('all', 'replies', 'favorites') as $a) {
foreach (array('all', 'replies') as $a) {
$m->connect(':nickname/'.$a.'/rss',
array('action' => $a.'rss'),
array('nickname' => Nickname::DISPLAY_FMT));
}
$m->connect(':nickname/favorites',
array('action' => 'showfavorites'),
array('nickname' => Nickname::DISPLAY_FMT));
$m->connect(':nickname/avatar',
array('action' => 'avatarbynickname'),
array('nickname' => Nickname::DISPLAY_FMT));
@ -1155,15 +1106,6 @@ class Router
array('action' => 'AtomPubSubscriptionFeed'),
array('subscriber' => '[0-9]+'));
$m->connect('api/statusnet/app/favorites/:profile/:notice.atom',
array('action' => 'AtomPubShowFavorite'),
array('profile' => '[0-9]+',
'notice' => '[0-9]+'));
$m->connect('api/statusnet/app/favorites/:profile.atom',
array('action' => 'AtomPubFavoriteFeed'),
array('profile' => '[0-9]+'));
$m->connect('api/statusnet/app/memberships/:profile/:group.atom',
array('action' => 'AtomPubShowMembership'),
array('profile' => '[0-9]+',

View File

@ -0,0 +1,111 @@
<?php
/*
* GNU Social - a federating social network
* Copyright (C) 2014, Free Software Foundation, Inc.
*
* 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/>.
*/
if (!defined('GNUSOCIAL')) { exit(1); }
/**
* @package UI
* @maintainer Mikael Nordfeldth <mmn@hethane.se>
*/
class FavoritePlugin extends Plugin
{
public function onRouterInitialized(URLMapper $m)
{
// Web UI actions
$m->connect('main/favor', array('action' => 'favor'));
$m->connect('main/disfavor', array('action' => 'disfavor'));
if (common_config('singleuser', 'enabled')) {
$nickname = User::singleUserNickname();
$m->connect('favorites',
array('action' => 'showfavorites',
'nickname' => $nickname));
$m->connect('favoritesrss',
array('action' => 'favoritesrss',
'nickname' => $nickname));
} else {
$m->connect('favoritedrss', array('action' => 'favoritedrss'));
$m->connect('favorited/', array('action' => 'favorited'));
$m->connect('favorited', array('action' => 'favorited'));
$m->connect(':nickname/favorites',
array('action' => 'showfavorites'),
array('nickname' => Nickname::DISPLAY_FMT));
$m->connect(':nickname/favorites/rss',
array('action' => 'favoritesrss'),
array('nickname' => Nickname::DISPLAY_FMT));
}
// Favorites for API
$m->connect('api/favorites/create.:format',
array('action' => 'ApiFavoriteCreate',
'format' => '(xml|json)'));
$m->connect('api/favorites/destroy.:format',
array('action' => 'ApiFavoriteDestroy',
'format' => '(xml|json)'));
$m->connect('api/favorites/list.:format',
array('action' => 'ApiTimelineFavorites',
'format' => '(xml|json|rss|atom|as)'));
$m->connect('api/favorites/:id.:format',
array('action' => 'ApiTimelineFavorites',
'id' => Nickname::INPUT_FMT,
'format' => '(xml|json|rss|atom|as)'));
$m->connect('api/favorites.:format',
array('action' => 'ApiTimelineFavorites',
'format' => '(xml|json|rss|atom|as)'));
$m->connect('api/favorites/create/:id.:format',
array('action' => 'ApiFavoriteCreate',
'id' => '[0-9]+',
'format' => '(xml|json)'));
$m->connect('api/favorites/destroy/:id.:format',
array('action' => 'ApiFavoriteDestroy',
'id' => '[0-9]+',
'format' => '(xml|json)'));
// AtomPub API
$m->connect('api/statusnet/app/favorites/:profile/:notice.atom',
array('action' => 'AtomPubShowFavorite'),
array('profile' => '[0-9]+',
'notice' => '[0-9]+'));
$m->connect('api/statusnet/app/favorites/:profile.atom',
array('action' => 'AtomPubFavoriteFeed'),
array('profile' => '[0-9]+'));
// Required for qvitter API
$m->connect('api/statuses/favs/:id.:format',
array('action' => 'ApiStatusesFavs',
'id' => '[0-9]+',
'format' => '(xml|json)'));
}
public function onPluginVersion(array &$versions)
{
$versions[] = array('name' => 'Favorite',
'version' => GNUSOCIAL_VERSION,
'author' => 'Mikael Nordfeldth',
'homepage' => 'http://gnu.io/',
'rawdescription' =>
// TRANS: Plugin description.
_m('Favorites (likes) using ActivityStreams.'));
return true;
}
}