<commit_before><?php

namespace Coyote\Http\Middleware;

use Closure;
use Coyote\Repositories\Contracts\UserRepositoryInterface as UserRepository;

class PostSubmitResponse
{
    /**
     * @var UserRepository
     */
    private $user;

    /**
     * @param UserRepository $user
     */
    public function __construct(UserRepository $user)
    {
        $this->user = $user;
    }

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function handle($request, Closure $next)
    {
        /** @var \Illuminate\Http\Response $response */
        $response = $next($request);

        // is this a quick edit (via ajax)?
        if ($request->ajax()) {
            $post = $response->getOriginalContent();
            $data = ['post' => ['text' => $post->text, 'attachments' => $post->attachments()->get()]];

            if ($request->user()->allow_sig && $post->user_id) {
                $parser = app('parser.sig');
                $user = $this->user->find($post->user_id, ['sig']);

                if ($user->sig) {
                    $data['post']['sig'] = $parser->parse($user->sig);
                }
            }

            $view = (string) view('forum.partials.text', $data)->render();
            return response($view);
        } elseif ($request->attributes->has('url')) {
            return redirect()->to($request->attributes->get('url'));
        } else {
            return $response;
        }
    }
}<commit_msg>poprawiony bug szybkiej odpowiedzi w przypadku braku wpisania tresci<commit_after><?php

namespace Coyote\Http\Middleware;

use Closure;
use Coyote\Repositories\Contracts\UserRepositoryInterface as UserRepository;
use Illuminate\Http\Response;

class PostSubmitResponse
{
    /**
     * @var UserRepository
     */
    private $user;

    /**
     * @param UserRepository $user
     */
    public function __construct(UserRepository $user)
    {
        $this->user = $user;
    }

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function handle($request, Closure $next)
    {
        /** @var \Illuminate\Http\Response $response */
        $response = $next($request);

        // is this a quick edit (via ajax)?
        // we need to be sure, that response is really instance of Response class.
        // if there is an error, $response will be instance of JsonResponse.
        if ($request->ajax() && $response instanceof Response) {
            $post = $response->getOriginalContent();
            $data = ['post' => ['text' => $post->text, 'attachments' => $post->attachments()->get()]];

            if ($request->user()->allow_sig && $post->user_id) {
                $parser = app('parser.sig');
                $user = $this->user->find($post->user_id, ['sig']);

                if ($user->sig) {
                    $data['post']['sig'] = $parser->parse($user->sig);
                }
            }

            $view = (string) view('forum.partials.text', $data)->render();
            return response($view);
        } elseif ($request->attributes->has('url')) {
            return redirect()->to($request->attributes->get('url'));
        } else {
            return $response;
        }
    }
}
{'fraction_non_alphanumeric': 0.15839584535487594, 'fraction_numerical': 0.0, 'mean_word_length': 2.08726625111309, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1875027', 'n_tokens_mistral': 994, 'n_tokens_neox': 971, 'n_words': 213}