1
0
mirror of https://github.com/flarum/core.git synced 2025-08-15 12:54:47 +02:00

Update for composer branch

This commit is contained in:
Toby Zerner
2015-10-11 23:17:51 +10:30
parent 5bb266ec3b
commit 2bc9b942ed
20 changed files with 261 additions and 187 deletions

View File

@@ -1,23 +0,0 @@
<?php
/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Flarum\Akismet;
use Flarum\Support\Extension as BaseExtension;
use Illuminate\Events\Dispatcher;
class Extension extends BaseExtension
{
public function listen(Dispatcher $events)
{
$events->subscribe('Flarum\Akismet\Listeners\AddClientAssets');
$events->subscribe('Flarum\Akismet\Listeners\ValidatePost');
}
}

View File

@@ -0,0 +1,47 @@
<?php
/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Flarum\Akismet\Listener;
use Flarum\Event\ConfigureClientView;
use Illuminate\Contracts\Events\Dispatcher;
class AddClientAssets
{
/**
* @param Dispatcher $events
*/
public function subscribe(Dispatcher $events)
{
$events->listen(ConfigureClientView::class, [$this, 'addAssets']);
}
/**
* @param ConfigureClientView $event
*/
public function addAssets(ConfigureClientView $event)
{
if ($event->isForum()) {
$event->addAssets([
__DIR__.'/../../js/forum/dist/extension.js'
]);
$event->addBootstrapper('flarum/akismet/main');
$event->addTranslations('flarum-akismet.forum');
}
if ($event->isAdmin()) {
$event->addAssets([
__DIR__ . '/../../js/admin/dist/extension.js'
]);
$event->addBootstrapper('flarum/akismet/main');
$event->addTranslations('flarum-akismet.admin');
}
}
}

View File

@@ -8,32 +8,51 @@
* file that was distributed with this source code.
*/
namespace Flarum\Akismet\Listeners;
namespace Flarum\Akismet\Listener;
use Flarum\Events\PostWillBeSaved;
use Flarum\Approval\Event\PostWasApproved;
use Flarum\Core;
use Flarum\Event\PostWillBeSaved;
use Flarum\Flags\Flag;
use Flarum\Foundation\Application;
use Flarum\Settings\SettingsRepository;
use Illuminate\Contracts\Events\Dispatcher;
use TijsVerkoyen\Akismet\Akismet;
use Flarum\Core;
use Flarum\Core\Posts\CommentPost;
use Flarum\Core\Settings\SettingsRepository;
use Flarum\Flags\Flag;
use Flarum\Approval\Events\PostWasApproved;
class ValidatePost
class FilterNewPosts
{
/**
* @var SettingsRepository
*/
protected $settings;
public function __construct(SettingsRepository $settings)
/**
* @var Application
*/
protected $app;
/**
* @param SettingsRepository $settings
* @param Application $app
*/
public function __construct(SettingsRepository $settings, Application $app)
{
$this->settings = $settings;
$this->app = $app;
}
/**
* @param Dispatcher $events
*/
public function subscribe(Dispatcher $events)
{
$events->listen(PostWillBeSaved::class, [$this, 'validatePost']);
$events->listen(PostWasApproved::class, [$this, 'submitHam']);
}
/**
* @param PostWillBeSaved $event
*/
public function validatePost(PostWillBeSaved $event)
{
$post = $event->post;
@@ -42,7 +61,7 @@ class ValidatePost
return;
}
$akismet = new Akismet($this->settings->get('akismet.api_key'), Core::url());
$akismet = new Akismet($this->settings->get('flarum-akismet.api_key'), $this->app->url());
$isSpam = $akismet->isSpam(
$post->content,
@@ -70,6 +89,9 @@ class ValidatePost
}
}
/**
* @param PostWasApproved $event
*/
public function submitHam(PostWasApproved $event)
{
// TODO

View File

@@ -1,52 +0,0 @@
<?php
/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Flarum\Akismet\Listeners;
use Flarum\Events\RegisterLocales;
use Flarum\Events\BuildClientView;
use Illuminate\Contracts\Events\Dispatcher;
class AddClientAssets
{
public function subscribe(Dispatcher $events)
{
$events->listen(RegisterLocales::class, [$this, 'addLocale']);
$events->listen(BuildClientView::class, [$this, 'addAssets']);
}
public function addLocale(RegisterLocales $event)
{
$event->addTranslations('en', __DIR__.'/../../locale/en.yml');
}
public function addAssets(BuildClientView $event)
{
$event->forumAssets([
__DIR__.'/../../js/forum/dist/extension.js'
]);
$event->forumBootstrapper('akismet/main');
$event->forumTranslations([
// 'akismet.hello_world'
]);
$event->adminAssets([
__DIR__.'/../../js/admin/dist/extension.js'
]);
$event->adminBootstrapper('akismet/main');
$event->adminTranslations([
// 'akismet.hello_world'
]);
}
}