Issues (4)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

Plugin.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace GinoPane\BlogTimeToRead;
4
5
use System\Classes\PluginBase;
6
use RainLab\Blog\Models\Post as PostModel;
7
use GinoPane\BlogTimeToRead\Models\Settings;
8
use GinoPane\BlogTimeToRead\Helpers\TimeToRead;
9
use GinoPane\BlogTimeToRead\Components\TimeToRead as TimeToReadComponent;
10
11
/**
12
 * Class Plugin
13
 *
14
 * @package GinoPane\BlogTimeToRead
15
 */
16
class Plugin extends PluginBase
17
{
18
    const DEFAULT_ICON = 'icon-clock-o';
19
20
    const LOCALIZATION_KEY = 'ginopane.blogtimetoread::lang.';
21
22
    /**
23
     * @var array   Require some plugins
24
     */
25
    public $require = [
26
        'RainLab.Blog',
27
        'RainLab.Translate'
28
    ];
29
30
    /** @var TimeToRead  */
31
    private $helper;
32
33
    /**
34
     * Returns information about this plugin
35
     *
36
     * @return  array
0 ignored issues
show
Consider making the return type a bit more specific; maybe use array<string,string>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
37
     */
38
    public function pluginDetails()
39
    {
40
        return [
41
            'name'        => self::LOCALIZATION_KEY . 'plugin.name',
42
            'description' => self::LOCALIZATION_KEY . 'plugin.description',
43
            'author'      => 'Siarhei <Gino Pane> Karavai',
44
            'icon'        => self::DEFAULT_ICON,
45
            'homepage'    => 'https://github.com/GinoPane/oc-blogtimetoread-plugin'
46
        ];
47
    }
48
49
    /**
50
     * Boot method, called right before the request route
51
     */
52
    public function boot()
53
    {
54
        $this->helper = new TimeToRead(Settings::instance());
55
56
        // extend the post model
57
        $this->extendModel();
58
    }
59
60
    /**
61
     * Register components
62
     *
63
     * @return  array
64
     */
65
    public function registerComponents()
66
    {
67
        return [
68
            TimeToReadComponent::class => TimeToReadComponent::NAME,
69
        ];
70
    }
71
72
    /**
73
     * Register plugin settings
74
     *
75
     * @return array
0 ignored issues
show
Consider making the return type a bit more specific; maybe use array<string,array<string,string|integer>>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
76
     */
77
    public function registerSettings(){
78
        return [
79
            'settings' => [
80
                'label'       => self::LOCALIZATION_KEY . 'settings.name',
81
                'description' => self::LOCALIZATION_KEY . 'settings.description',
82
                'icon'        => self::DEFAULT_ICON,
83
                'class'       => Settings::class,
84
                'order'       => 800,
85
                'category'    => 'rainlab.blog::lang.blog.menu_label'
86
            ]
87
        ];
88
    }
89
90
    /**
91
     * @return array
0 ignored issues
show
Consider making the return type a bit more specific; maybe use array<string,array<string,array<Plugin|string>>>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
92
     */
93
    public function registerMarkupTags()
94
    {
95
        return [
96
            'filters' => [
97
                'timeToRead' => [$this, 'getTimeToRead']
98
            ]
99
        ];
100
    }
101
102
    /**
103
     * @param      $text
104
     * @param null $speed
105
     * @param null $roundingEnabled
106
     *
107
     * @return int
108
     */
109
    public function getTimeToRead($text, $speed = null, $roundingEnabled = null)
110
    {
111
        return $this->helper->calculate(
112
            $text,
113
            array_filter([
114
                Settings::READING_SPEED_KEY => $speed,
115
                Settings::ROUNDING_UP_ENABLED_KEY => $roundingEnabled
116
            ])
117
        );
118
    }
119
120
    /**
121
     * Extend RainLab Post model
122
     */
123
    private function extendModel()
124
    {
125
        PostModel::extend(function ($model) {
126
            $model->addDynamicMethod('getTimeToReadAttribute', function() use ($model) {
127
                return $this->helper->calculate($model->content);
128
            });
129
        });
130
    }
131
}
132