Skip to content

Commit

Permalink
Merge pull request #5 from ogioncz/master
Browse files Browse the repository at this point in the history
Update for flarum 0.1.0-beta.8
  • Loading branch information
AmauryCarrade authored Mar 23, 2019
2 parents 88fd56c + e1604b9 commit 3d74000
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 148 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"license": "CECILL-B",
"type": "flarum-extension",
"require": {
"flarum/core": "^0.1.0-beta.6"
"flarum/core": "^0.1.0-beta.8"
},
"extra": {
"flarum-extension": {
"title": "Syndication",
"icon": {
"name": "rss",
"name": "fas fa-rss",
"backgroundColor": "#e28f12",
"backgroundRepeat": "no-repeat",
"backgroundPosition": "center",
Expand Down
19 changes: 11 additions & 8 deletions bootstrap.php → extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,18 @@
* knowledge of the CeCILL-B license and that you accept its terms.
*/

use Flarum\Extend;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Contracts\View\Factory;

use AmauryCarrade\FlarumFeeds\Listener;

return function (Dispatcher $events, Factory $views)
{
$events->subscribe(Listener\AddFeedsRoutes::class);
$events->subscribe(Listener\AddClientAssetsAndLinks::class);

$views->addNamespace('flarum-feeds', __DIR__.'/views');
};
return [
new Extend\Locales(__DIR__ . '/resources/locale'),
new Extend\Compat(function (Dispatcher $events) {
$events->subscribe(Listener\AddFeedsRoutes::class);
}),
(new Extend\Frontend('forum'))->content(Listener\AddClientLinks::class),
function (Factory $views) {
$views->addNamespace('flarum-feeds', __DIR__.'/views');
},
];
File renamed without changes.
File renamed without changes.
30 changes: 16 additions & 14 deletions src/Controller/AbstractFeedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@
use DateTime;
use Flarum\Http\Exception\RouteNotFoundException;
use Psr\Http\Message\ServerRequestInterface as Request;
use Flarum\Core\User;
use Flarum\Forum\UrlGenerator;
use Flarum\Http\Controller\ControllerInterface;
use Flarum\User\User;
use Flarum\Http\UrlGenerator;
use Flarum\Api\Client as ApiClient;
use Illuminate\Contracts\View\Factory;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Zend\Diactoros\Response;

Expand All @@ -54,7 +56,7 @@
*
* @package AmauryCarrade\FlarumFeeds\Controller
*/
abstract class AbstractFeedController implements ControllerInterface
abstract class AbstractFeedController implements RequestHandlerInterface
{
/**
* @var ApiClient
Expand Down Expand Up @@ -98,14 +100,14 @@ public function __construct(Factory $view, ApiClient $api, TranslatorInterface $
$this->api = $api;
$this->translator = $translator;

$this->url = app('Flarum\Forum\UrlGenerator');
$this->url = app('Flarum\Http\UrlGenerator');
}

/**
* @param Request $request
* @return \Zend\Diactoros\Response
* @param ServerRequestInterface $request
* @return ResponseInterface
*/
public function handle(Request $request)
public function handle(ServerRequestInterface $request): ResponseInterface
{
$feed_type = $this->getFeedType($request);
$feed_type = in_array($feed_type, ['rss', 'atom']) ? $feed_type : 'rss';
Expand All @@ -122,10 +124,10 @@ public function handle(Request $request)
}

/**
* @param Request $request A request.
* @param ServerRequestInterface $request A request.
* @return User The actor for this request.
*/
protected function getActor(Request $request)
protected function getActor(ServerRequestInterface $request)
{
return $request->getAttribute('actor');
}
Expand Down Expand Up @@ -207,16 +209,16 @@ protected function parseDate($date)
}

/**
* @param Request $request
* @param ServerRequestInterface $request
* @return array
*/
abstract protected function getFeedContent(Request $request);
abstract protected function getFeedContent(ServerRequestInterface $request);

/**
* @param Request $request The request
* @param ServerRequestInterface $request The request
* @return string 'rss' or 'atom', defaults to 'rss'.
*/
protected function getFeedType(Request $request)
protected function getFeedType(ServerRequestInterface $request)
{
$path = strtolower($request->getUri()->getPath());
return starts_with($path, '/atom') ? 'atom' : 'rss';
Expand Down
10 changes: 5 additions & 5 deletions src/Controller/DiscussionFeedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
namespace AmauryCarrade\FlarumFeeds\Controller;

use Flarum\Api\Client as ApiClient;
use Flarum\Core\User;
use Flarum\User\User;
use Flarum\Http\Exception\RouteNotFoundException;
use Illuminate\Contracts\View\Factory;
use Symfony\Component\Translation\TranslatorInterface;
Expand Down Expand Up @@ -84,7 +84,7 @@ protected function getFeedContent(Request $request)
'offset' => 0,
'limit' => 20
],
'sort' => '-time'
'sort' => '-createdAt'
]);

$entries = [];
Expand All @@ -98,16 +98,16 @@ protected function getFeedContent(Request $request)
'title' => $discussion->attributes->title,
'description' => $this->summary($post->attributes->contentHtml),
'content' => $post->attributes->contentHtml,
'permalink' => $this->url->toRoute('discussion', ['id' => $discussion->id . '-' . $discussion->attributes->slug, 'near' => $post->attributes->number]) . '/' . $post->attributes->number, // TODO check out why the near parameter refuses to work
'pubdate' => $this->parseDate($post->attributes->time),
'permalink' => $this->url->to('forum')->route('discussion', ['id' => $discussion->id . '-' . $discussion->attributes->slug, 'near' => $post->attributes->number]) . '/' . $post->attributes->number, // TODO check out why the near parameter refuses to work
'pubdate' => $this->parseDate($post->attributes->createdAt),
'author' => $this->getRelationship($posts, $post->relationships->user)->username
];
}

return [
'title' => $this->translator->trans('amaurycarrade-syndication.forum.feeds.titles.discussion_title', ['{discussion_name}' => $discussion->attributes->title]),
'description' => $this->translator->trans('amaurycarrade-syndication.forum.feeds.titles.discussion_subtitle', ['{discussion_name}' => $discussion->attributes->title]),
'link' => $this->url->toRoute('discussion', ['id' => $discussion->id . '-' . $discussion->attributes->slug]),
'link' => $this->url->to('forum')->route('discussion', ['id' => $discussion->id . '-' . $discussion->attributes->slug]),
'pubDate' => new \DateTime(),
'entries' => $entries
];
Expand Down
24 changes: 12 additions & 12 deletions src/Controller/DiscussionsActivityFeedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
namespace AmauryCarrade\FlarumFeeds\Controller;

use Psr\Http\Message\ServerRequestInterface as Request;
use Flarum\Core\User;
use Flarum\User\User;
use Flarum\Api\Client as ApiClient;
use Illuminate\Contracts\View\Factory;
use Symfony\Component\Translation\TranslatorInterface;
Expand All @@ -59,10 +59,10 @@ class DiscussionsActivityFeedController extends AbstractFeedController
* @var array
*/
private $sortMap = [
'latest' => '-lastTime',
'top' => '-commentsCount',
'newest' => '-startTime',
'oldest' => 'startTime'
'latest' => '-lastPostedAt',
'top' => '-commentCount',
'newest' => '-createdAt',
'oldest' => 'createdAt'
];

/**
Expand Down Expand Up @@ -108,7 +108,7 @@ protected function getFeedContent(Request $request)
'sort' => $sort && isset($this->sortMap[$sort]) ? $this->sortMap[$sort] : ($this->lastTopics ? $this->sortMap['newest'] : $this->sortMap['latest']),
'filter' => compact('q'),
'page' => ['offset' => 0, 'limit' => 20],
'include' => $this->lastTopics ? 'startPost,startUser' : 'lastPost,lastUser'
'include' => $this->lastTopics ? 'firstPost,user' : 'lastPost,lastPostedUser'
];

$actor = $this->getActor($request);
Expand All @@ -121,9 +121,9 @@ protected function getFeedContent(Request $request)
{
if ($discussion->type != 'discussions') continue;

if ($this->lastTopics && isset($discussion->relationships->startPost))
if ($this->lastTopics && isset($discussion->relationships->firstPost))
{
$content = $this->getRelationship($last_discussions, $discussion->relationships->startPost);
$content = $this->getRelationship($last_discussions, $discussion->relationships->firstPost);
}
else if (isset($discussion->relationships->lastPost))
{
Expand All @@ -139,10 +139,10 @@ protected function getFeedContent(Request $request)
'title' => $discussion->attributes->title,
'description' => $this->summary($content->contentHtml),
'content' => $content->contentHtml,
'id' => $this->url->toRoute('discussion', ['id' => $discussion->id . '-' . $discussion->attributes->slug]),
'permalink' => $this->url->toRoute('discussion', ['id' => $discussion->id . '-' . $discussion->attributes->slug, 'near' => $content->number]) . '/' . $content->number, // TODO same than DiscussionFeedController
'pubdate' => $this->parseDate($this->lastTopics ? $discussion->attributes->startTime : $discussion->attributes->lastTime),
'author' => $this->getRelationship($last_discussions, $this->lastTopics ? $discussion->relationships->startUser : $discussion->relationships->lastUser)->username
'id' => $this->url->to('forum')->route('discussion', ['id' => $discussion->id . '-' . $discussion->attributes->slug]),
'permalink' => $this->url->to('forum')->route('discussion', ['id' => $discussion->id . '-' . $discussion->attributes->slug, 'near' => $content->number]) . '/' . $content->number, // TODO same than DiscussionFeedController
'pubdate' => $this->parseDate($this->lastTopics ? $discussion->attributes->createdAt : $discussion->attributes->lastPostedAt),
'author' => $this->getRelationship($last_discussions, $this->lastTopics ? $discussion->relationships->user : $discussion->relationships->lastPostedUser)->username
];
}

Expand Down
107 changes: 0 additions & 107 deletions src/Listener/AddClientAssetsAndLinks.php

This file was deleted.

Loading

0 comments on commit 3d74000

Please sign in to comment.