mirror of
https://github.com/flarum/framework.git
synced 2025-03-26 17:19:06 +08:00
Update for composer branch
This commit is contained in:
parent
5bb266ec3b
commit
2bc9b942ed
extensions/akismet
.gitignorebootstrap.phpcomposer.jsoncomposer.lockflarum.jsonicon.jpg
js
locale
scripts
src
2
extensions/akismet/.gitignore
vendored
2
extensions/akismet/.gitignore
vendored
@ -2,3 +2,5 @@
|
||||
composer.phar
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
bower_components
|
||||
node_modules
|
@ -9,6 +9,10 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
require __DIR__.'/vendor/autoload.php';
|
||||
use Flarum\Akismet\Listener;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
return 'Flarum\Akismet\Extension';
|
||||
return function (Dispatcher $events) {
|
||||
$events->subscribe(Listener\AddClientAssets::class);
|
||||
$events->subscribe(Listener\FilterNewPosts::class);
|
||||
};
|
@ -1,13 +1,37 @@
|
||||
{
|
||||
"name": "flarum/akismet",
|
||||
"description": "Stop spam using the Akismet anti-spam service.",
|
||||
"type": "flarum-extension",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Toby Zerner",
|
||||
"email": "toby.zerner@gmail.com"
|
||||
}
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/flarum/core/issues",
|
||||
"source": "https://github.com/flarum/akismet"
|
||||
},
|
||||
"require": {
|
||||
"flarum/core": "^0.1.0-beta.3",
|
||||
"flarum/approval": "^0.1.0-beta.3",
|
||||
"tijsverkoyen/akismet": "^1.1"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Flarum\\Akismet\\": "src/"
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
"tijsverkoyen/akismet": "^1.1"
|
||||
},
|
||||
"scripts": {
|
||||
"style": "phpcs --standard=PSR2 -np src"
|
||||
"extra": {
|
||||
"flarum-extension": {
|
||||
"title": "Akismet",
|
||||
"icon": {
|
||||
"image": "icon.jpg",
|
||||
"backgroundSize": "cover",
|
||||
"backgroundColor": "#5e8e14",
|
||||
"color": "#fff"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
57
extensions/akismet/composer.lock
generated
57
extensions/akismet/composer.lock
generated
@ -1,57 +0,0 @@
|
||||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"hash": "f4f26918432f8f6ed40008ffd516708d",
|
||||
"packages": [
|
||||
{
|
||||
"name": "tijsverkoyen/akismet",
|
||||
"version": "1.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/tijsverkoyen/Akismet.git",
|
||||
"reference": "0c5185956e11824ed310d134d38d0b2c936f3d3a"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/tijsverkoyen/Akismet/zipball/0c5185956e11824ed310d134d38d0b2c936f3d3a",
|
||||
"reference": "0c5185956e11824ed310d134d38d0b2c936f3d3a",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-curl": "*",
|
||||
"php": ">=5.2.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
""
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"BSD"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Tijs Verkoyen",
|
||||
"email": "akismet@verkoyen.eu",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"description": "Akismet is a wrapper-class to communicate with the Akismet API.",
|
||||
"homepage": "https://github.com/tijsverkoyen/Akismet",
|
||||
"time": "2012-10-13 17:59:41"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": [],
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": [],
|
||||
"platform-dev": []
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
{
|
||||
"name": "akismet",
|
||||
"title": "Akismet",
|
||||
"description": "Stop spam using the Akismet anti-spam service.",
|
||||
"keywords": [],
|
||||
"version": "0.1.0-beta.2",
|
||||
"author": {
|
||||
"name": "Toby Zerner",
|
||||
"email": "toby@flarum.org",
|
||||
"homepage": "http://tobyzerner.com"
|
||||
},
|
||||
"license": "MIT",
|
||||
"require": {
|
||||
"flarum": ">=0.1.0-beta.2",
|
||||
"reports": ">=0.1.0-beta.2"
|
||||
},
|
||||
"support": {
|
||||
"source": "https://github.com/flarum/akismet",
|
||||
"issues": "https://github.com/flarum/core/issues"
|
||||
},
|
||||
"icon": {
|
||||
"name": "filter",
|
||||
"backgroundColor": "#5e8e14",
|
||||
"color": "#fff"
|
||||
}
|
||||
}
|
BIN
extensions/akismet/icon.jpg
Normal file
BIN
extensions/akismet/icon.jpg
Normal file
Binary file not shown.
After ![]() (image error) Size: 5.4 KiB |
3
extensions/akismet/js/.gitignore
vendored
3
extensions/akismet/js/.gitignore
vendored
@ -1,3 +0,0 @@
|
||||
bower_components
|
||||
node_modules
|
||||
dist
|
@ -2,6 +2,6 @@ var gulp = require('flarum-gulp');
|
||||
|
||||
gulp({
|
||||
modules: {
|
||||
'akismet': 'src/**/*.js'
|
||||
'flarum/akismet': 'src/**/*.js'
|
||||
}
|
||||
});
|
||||
|
68
extensions/akismet/js/admin/dist/extension.js
vendored
Normal file
68
extensions/akismet/js/admin/dist/extension.js
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
System.register('flarum/akismet/main', ['flarum/app', 'flarum/akismet/components/AkismetSettingsModal'], function (_export) {
|
||||
'use strict';
|
||||
|
||||
var app, AkismetSettingsModal;
|
||||
return {
|
||||
setters: [function (_flarumApp) {
|
||||
app = _flarumApp['default'];
|
||||
}, function (_flarumAkismetComponentsAkismetSettingsModal) {
|
||||
AkismetSettingsModal = _flarumAkismetComponentsAkismetSettingsModal['default'];
|
||||
}],
|
||||
execute: function () {
|
||||
|
||||
app.initializers.add('flarum-akismet', function () {
|
||||
app.extensionSettings['flarum-akismet'] = function () {
|
||||
return app.modal.show(new AkismetSettingsModal());
|
||||
};
|
||||
});
|
||||
}
|
||||
};
|
||||
});;System.register('flarum/akismet/components/AkismetSettingsModal', ['flarum/components/SettingsModal'], function (_export) {
|
||||
'use strict';
|
||||
|
||||
var SettingsModal, AkismetSettingsModal;
|
||||
return {
|
||||
setters: [function (_flarumComponentsSettingsModal) {
|
||||
SettingsModal = _flarumComponentsSettingsModal['default'];
|
||||
}],
|
||||
execute: function () {
|
||||
AkismetSettingsModal = (function (_SettingsModal) {
|
||||
babelHelpers.inherits(AkismetSettingsModal, _SettingsModal);
|
||||
|
||||
function AkismetSettingsModal() {
|
||||
babelHelpers.classCallCheck(this, AkismetSettingsModal);
|
||||
babelHelpers.get(Object.getPrototypeOf(AkismetSettingsModal.prototype), 'constructor', this).apply(this, arguments);
|
||||
}
|
||||
|
||||
babelHelpers.createClass(AkismetSettingsModal, [{
|
||||
key: 'className',
|
||||
value: function className() {
|
||||
return 'AkismetSettingsModal Modal--small';
|
||||
}
|
||||
}, {
|
||||
key: 'title',
|
||||
value: function title() {
|
||||
return 'Akismet Settings';
|
||||
}
|
||||
}, {
|
||||
key: 'form',
|
||||
value: function form() {
|
||||
return [m(
|
||||
'div',
|
||||
{ className: 'Form-group' },
|
||||
m(
|
||||
'label',
|
||||
null,
|
||||
'API Key'
|
||||
),
|
||||
m('input', { className: 'FormControl', bidi: this.setting('flarum-akismet.api_key') })
|
||||
)];
|
||||
}
|
||||
}]);
|
||||
return AkismetSettingsModal;
|
||||
})(SettingsModal);
|
||||
|
||||
_export('default', AkismetSettingsModal);
|
||||
}
|
||||
};
|
||||
});
|
@ -13,7 +13,7 @@ export default class AkismetSettingsModal extends SettingsModal {
|
||||
return [
|
||||
<div className="Form-group">
|
||||
<label>API Key</label>
|
||||
<input className="FormControl" bidi={this.setting('akismet.api_key')}/>
|
||||
<input className="FormControl" bidi={this.setting('flarum-akismet.api_key')}/>
|
||||
</div>
|
||||
];
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import app from 'flarum/app';
|
||||
|
||||
import AkismetSettingsModal from 'akismet/components/AkismetSettingsModal';
|
||||
import AkismetSettingsModal from 'flarum/akismet/components/AkismetSettingsModal';
|
||||
|
||||
app.initializers.add('akismet', () => {
|
||||
app.extensionSettings.akismet = () => app.modal.show(new AkismetSettingsModal());
|
||||
app.initializers.add('flarum-akismet', () => {
|
||||
app.extensionSettings['flarum-akismet'] = () => app.modal.show(new AkismetSettingsModal());
|
||||
});
|
||||
|
@ -2,6 +2,6 @@ var gulp = require('flarum-gulp');
|
||||
|
||||
gulp({
|
||||
modules: {
|
||||
'akismet': 'src/**/*.js'
|
||||
'flarum/akismet': 'src/**/*.js'
|
||||
}
|
||||
});
|
||||
|
43
extensions/akismet/js/forum/dist/extension.js
vendored
Normal file
43
extensions/akismet/js/forum/dist/extension.js
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
System.register('flarum/akismet/main', ['flarum/extend', 'flarum/app', 'flarum/utils/PostControls', 'flarum/components/CommentPost'], function (_export) {
|
||||
'use strict';
|
||||
|
||||
var extend, override, app, PostControls, CommentPost;
|
||||
return {
|
||||
setters: [function (_flarumExtend) {
|
||||
extend = _flarumExtend.extend;
|
||||
override = _flarumExtend.override;
|
||||
}, function (_flarumApp) {
|
||||
app = _flarumApp['default'];
|
||||
}, function (_flarumUtilsPostControls) {
|
||||
PostControls = _flarumUtilsPostControls['default'];
|
||||
}, function (_flarumComponentsCommentPost) {
|
||||
CommentPost = _flarumComponentsCommentPost['default'];
|
||||
}],
|
||||
execute: function () {
|
||||
|
||||
app.initializers.add('flarum-akismet', function () {
|
||||
extend(PostControls, 'destructiveControls', function (items, post) {
|
||||
if (items.approve) {
|
||||
var flags = post.flags();
|
||||
|
||||
if (flags && flags.some(function (flag) {
|
||||
return flag.type() === 'akismet';
|
||||
})) {
|
||||
babelHelpers._extends(items.approve.content.props, {
|
||||
children: 'Not Spam'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
override(CommentPost.prototype, 'flagReason', function (original, flag) {
|
||||
if (flag.type() === 'akismet') {
|
||||
return 'Akismet flagged as Spam';
|
||||
}
|
||||
|
||||
return original(flag);
|
||||
});
|
||||
}, -20); // run after the approval extension
|
||||
}
|
||||
};
|
||||
});
|
@ -4,7 +4,7 @@ import app from 'flarum/app';
|
||||
import PostControls from 'flarum/utils/PostControls';
|
||||
import CommentPost from 'flarum/components/CommentPost';
|
||||
|
||||
app.initializers.add('akismet', () => {
|
||||
app.initializers.add('flarum-akismet', () => {
|
||||
extend(PostControls, 'destructiveControls', function(items, post) {
|
||||
if (items.approve) {
|
||||
const flags = post.flags();
|
||||
|
@ -1,2 +0,0 @@
|
||||
akismet:
|
||||
# hello_world: "Hello, world!"
|
27
extensions/akismet/scripts/compile.sh
Executable file
27
extensions/akismet/scripts/compile.sh
Executable file
@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# This script compiles the extension so that it can be used in a Flarum
|
||||
# installation. It should be run from the root directory of the extension.
|
||||
|
||||
base=$PWD
|
||||
|
||||
cd "${base}/js"
|
||||
|
||||
if [ -f bower.json ]; then
|
||||
bower install
|
||||
fi
|
||||
|
||||
for app in forum admin; do
|
||||
cd "${base}/js"
|
||||
|
||||
if [ -d $app ]; then
|
||||
cd $app
|
||||
|
||||
if [ -f bower.json ]; then
|
||||
bower install
|
||||
fi
|
||||
|
||||
npm install
|
||||
gulp --production
|
||||
fi
|
||||
done
|
@ -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');
|
||||
}
|
||||
}
|
47
extensions/akismet/src/Listener/AddClientAssets.php
Normal file
47
extensions/akismet/src/Listener/AddClientAssets.php
Normal 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');
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
@ -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'
|
||||
]);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user