public function validatePost(PostWillBeSaved $event) { $post = $event->post; if ($post->exists || $post->user->groups()->count()) { return; } $akismet = new Akismet($this->settings->get('akismet.api_key'), Core::url()); $isSpam = $akismet->isSpam($post->content, $post->user->username, $post->user->email, null, 'comment'); if ($isSpam) { $post->hide(); $this->savingPost = $post; CommentPost::saved(function (CommentPost $post) { if ($post !== $this->savingPost) { return; } $report = new Report(); $report->post_id = $post->id; $report->reporter = 'Akismet'; $report->reason = 'spam'; $report->time = time(); $report->save(); $this->savingPost = null; }); } }
/** * {@inheritdoc} */ protected function getDefaultAttributes($forum) { $attributes = ['title' => Core::config('forum_title'), 'baseUrl' => Core::url(), 'basePath' => parse_url(Core::url(), PHP_URL_PATH) ?: '', 'debug' => Core::inDebugMode(), 'apiUrl' => Core::url('api'), 'welcomeTitle' => Core::config('welcome_title'), 'welcomeMessage' => Core::config('welcome_message'), 'themePrimaryColor' => Core::config('theme_primary_color'), 'canView' => $forum->can($this->actor, 'view'), 'canStartDiscussion' => $forum->can($this->actor, 'startDiscussion'), 'allowSignUp' => (bool) Core::config('allow_sign_up'), 'defaultRoute' => Core::config('default_route')]; if ($this->actor->isAdmin()) { $attributes['adminUrl'] = Core::url('admin'); $attributes['version'] = Application::VERSION; } return $attributes; }
public function handle(Request $request) { $images = $request->http->getUploadedFiles()['images']; $results = []; foreach ($images as $image_key => $image) { $tmpFile = tempnam(sys_get_temp_dir(), 'image'); $image->moveTo($tmpFile); $urlGenerator = app('Flarum\\Http\\UrlGeneratorInterface'); $dir = 'uploads/' . date('Ym/d'); $path = './assets/' . $dir; $mount = new MountManager(['source' => new Filesystem(new Local(pathinfo($tmpFile, PATHINFO_DIRNAME))), 'target' => new Filesystem(new Local($path))]); $uploadName = Str::lower(Str::quickRandom()) . '.jpg'; $mount->move("source://" . pathinfo($tmpFile, PATHINFO_BASENAME), "target://{$uploadName}"); $results['img_' . $image_key] = Core::url() . '/assets/' . $dir . '/' . $uploadName; } return new JsonResponse($results); }
/** * @param RequestPasswordReset $command * @return \Flarum\Core\Users\User * @throws ModelNotFoundException */ public function handle(RequestPasswordReset $command) { $user = $this->users->findByEmail($command->email); if (!$user) { throw new ModelNotFoundException(); } $token = PasswordToken::generate($user->id); $token->save(); // TODO: Need to use UrlGenerator, but since this is part of core we // don't know that the forum routes will be loaded. Should the reset // password route be part of core?? $data = ['username' => $user->username, 'url' => Core::url() . '/reset/' . $token->id, 'forumTitle' => $this->settings->get('forum_title')]; $this->mailer->send(['text' => 'flarum::emails.resetPassword'], $data, function (Message $message) use($user) { $message->to($user->email); $message->subject('Reset Your Password'); }); return $user; }
/** * @param string $url * @return RedirectResponse */ protected function redirectTo($url) { $url = Core::url() . $url; $content = sprintf(' <!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <meta http-equiv="refresh" content="1;url=%1$s" /> <title>Redirecting to %1$s</title> </head> <body> Redirecting to <a href="%1$s">%1$s</a>. </body> </html>', htmlspecialchars($url, ENT_QUOTES, 'UTF-8')); $response = new RedirectResponse($url); $response->getBody()->write($content); return $response; }
public function validatePost(PostWillBeSaved $event) { $post = $event->post; if ($post->exists || $post->user->groups()->count()) { return; } $akismet = new Akismet($this->settings->get('akismet.api_key'), Core::url()); $isSpam = $akismet->isSpam($post->content, $post->user->username, $post->user->email, null, 'comment'); if ($isSpam) { $post->is_approved = false; // TODO: // $post->is_spam = true; $post->afterSave(function ($post) { $flag = new Flag(); $flag->post_id = $post->id; $flag->type = 'akismet'; $flag->time = time(); $flag->save(); }); } }
*/ use Flarum\Core; use Flarum\Forum\Middleware\HandleErrors; use Franzl\Middleware\Whoops\Middleware as WhoopsMiddleware; use Zend\Diactoros\Server; use Zend\Stratigility\MiddlewarePipe; $app = (require __DIR__ . '/flarum/bootstrap.php'); // If Flarum's configuration exists, then we can assume that installation has // been completed. We will set up a middleware pipe to route the request through // to one of the main forum actions. if (Core::isInstalled()) { $app->register('Flarum\\Forum\\ForumServiceProvider'); $flarum = new MiddlewarePipe(); $flarum->pipe($app->make('Flarum\\Forum\\Middleware\\LoginWithCookie')); $flarum->pipe($app->make('Flarum\\Api\\Middleware\\ReadJsonParameters')); $basePath = parse_url(Core::url(), PHP_URL_PATH); $router = $app->make('Flarum\\Http\\RouterMiddleware', ['routes' => $app->make('flarum.forum.routes')]); $flarum->pipe($basePath, $router); if (Core::inDebugMode()) { $flarum->pipe(new WhoopsMiddleware()); } else { $flarum->pipe(new HandleErrors(base_path('error'))); } } else { $app->register('Flarum\\Install\\InstallServiceProvider'); $flarum = new MiddlewarePipe(); $basePath = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); $router = $app->make('Flarum\\Http\\RouterMiddleware', ['routes' => $app->make('flarum.install.routes')]); $flarum->pipe($basePath, $router); $flarum->pipe(new WhoopsMiddleware()); }
public function toAsset($path) { return Core::url() . "/assets/{$path}"; }
<?php /* * This file is part of Flarum. * * (c) Toby Zerner <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ use Flarum\Api\Middleware\JsonApiErrors; use Flarum\Core; use Franzl\Middleware\Whoops\Middleware as WhoopsMiddleware; use Zend\Diactoros\Server; use Zend\Stratigility\MiddlewarePipe; $app = (require __DIR__ . '/flarum/bootstrap.php'); $app->register('Flarum\\Api\\ApiServiceProvider'); $api = new MiddlewarePipe(); $api->pipe($app->make('Flarum\\Api\\Middleware\\ReadJsonParameters')); $api->pipe($app->make('Flarum\\Api\\Middleware\\LoginWithHeader')); $apiPath = parse_url(Core::url('api'), PHP_URL_PATH); $router = $app->make('Flarum\\Http\\RouterMiddleware', ['routes' => $app->make('flarum.api.routes')]); $api->pipe($apiPath, $router); if (Core::inDebugMode()) { $api->pipe(new WhoopsMiddleware()); } else { $api->pipe(new JsonApiErrors()); } $server = Server::createServer($api, $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES); $server->listen();
/** * Get the data that should be made available to email templates. * * @param User $user * @param string $email * * @return array */ protected function getEmailData(User $user, $email) { $token = $this->generateToken($user, $email); // TODO: Need to use UrlGenerator, but since this is part of core we // don't know that the forum routes will be loaded. Should the confirm // email route be part of core?? return ['username' => $user->username, 'url' => Core::url() . '/confirm/' . $token->id, 'forumTitle' => $this->settings->get('forum_title')]; }
<?php /* * This file is part of Flarum. * * (c) Toby Zerner <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ use Flarum\Core; use Flarum\Forum\Middleware\HandleErrors; use Franzl\Middleware\Whoops\Middleware as WhoopsMiddleware; use Zend\Diactoros\Server; use Zend\Stratigility\MiddlewarePipe; $app = (require __DIR__ . '/flarum/bootstrap.php'); $app->register('Flarum\\Admin\\AdminServiceProvider'); $admin = new MiddlewarePipe(); $admin->pipe($app->make('Flarum\\Api\\Middleware\\ReadJsonParameters')); $admin->pipe($app->make('Flarum\\Admin\\Middleware\\LoginWithCookieAndCheckAdmin')); $adminPath = parse_url(Core::url('admin'), PHP_URL_PATH); $router = $app->make('Flarum\\Http\\RouterMiddleware', ['routes' => $app->make('flarum.admin.routes')]); $admin->pipe($adminPath, $router); if (Core::inDebugMode()) { $admin->pipe(new WhoopsMiddleware()); } else { $admin->pipe(new HandleErrors(base_path('error'))); } $server = Server::createServer($admin, $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES); $server->listen();
public function toAsset($path) { return Core::url($this->prefix) . "/assets/{$path}"; }