1 | <?php |
||||
2 | |||||
3 | namespace Yajra\Disqus; |
||||
4 | |||||
5 | use Closure; |
||||
6 | use Illuminate\Support\Str; |
||||
7 | |||||
8 | class DisqusMiddleware |
||||
9 | { |
||||
10 | /** |
||||
11 | * Handle an incoming request. |
||||
12 | * |
||||
13 | * @param \Illuminate\Http\Request $request |
||||
0 ignored issues
–
show
|
|||||
14 | * @param \Closure $next |
||||
15 | * @return mixed |
||||
16 | */ |
||||
17 | public function handle($request, Closure $next) |
||||
18 | { |
||||
19 | $response = $next($request); |
||||
20 | |||||
21 | if (config('disqus.enabled', false) && ! empty(config('disqus.username'))) { |
||||
0 ignored issues
–
show
The function
config was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
22 | $this->appendDisqusScript($request, $response); |
||||
23 | } |
||||
24 | |||||
25 | return $response; |
||||
26 | } |
||||
27 | |||||
28 | /** |
||||
29 | * Append disqus script on the end of the page. |
||||
30 | * |
||||
31 | * @param \Illuminate\Http\Request $request |
||||
32 | * @param \Illuminate\Http\Response $response |
||||
0 ignored issues
–
show
The type
Illuminate\Http\Response was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||
33 | * @return mixed |
||||
34 | */ |
||||
35 | protected function appendDisqusScript($request, $response) |
||||
36 | { |
||||
37 | $content = $response->getContent(); |
||||
38 | |||||
39 | if (! Str::contains($content, '<div id="disqus_thread"></div>')) { |
||||
40 | return; |
||||
41 | } |
||||
42 | |||||
43 | $uri = $request->getRequestUri(); |
||||
44 | $pageUrl = url($uri); |
||||
0 ignored issues
–
show
The function
url was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
45 | $pageId = 'route'.implode('.', explode('/', $uri)); |
||||
46 | $username = config('disqus.username'); |
||||
0 ignored issues
–
show
The function
config was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
47 | |||||
48 | $disqusHtml = <<<CDATA |
||||
49 | <script> |
||||
50 | var disqus_config = function () { |
||||
51 | this.page.url = '$pageUrl'; |
||||
52 | this.page.identifier = '$pageId'; |
||||
53 | }; |
||||
54 | |||||
55 | (function() { |
||||
56 | var d = document, s = d.createElement('script'); |
||||
57 | |||||
58 | s.src = '//$username.disqus.com/embed.js'; |
||||
59 | |||||
60 | s.setAttribute('data-timestamp', +new Date()); |
||||
61 | (d.head || d.body).appendChild(s); |
||||
62 | })(); |
||||
63 | </script> |
||||
64 | <noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript" rel="nofollow">comments powered by Disqus.</a></noscript> |
||||
65 | CDATA; |
||||
66 | |||||
67 | $bodyPosition = strripos($content, '</body>'); |
||||
68 | |||||
69 | if (false !== $bodyPosition) { |
||||
70 | $content = substr($content, 0, $bodyPosition).$disqusHtml.substr($content, $bodyPosition); |
||||
71 | } |
||||
72 | |||||
73 | $response->setContent($content); |
||||
74 | } |
||||
75 | } |
||||
76 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths