Issues (15)

Security Analysis    not enabled

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.

src/ThemeManager.php (1 issue)

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
 * Pluggable themes for Yii2
4
 *
5
 * @link      https://github.com/hiqdev/yii2-thememanager
6
 * @package   yii2-thememanager
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\thememanager;
12
13
use hiqdev\thememanager\models\Settings;
14
use hiqdev\thememanager\storage\SettingsStorageInterface;
15
use Yii;
16
use yii\base\InvalidConfigException;
17
use yii\web\AssetBundle;
18
use yii\web\Controller;
19
20
/**
21
 * Theme Manager. Provides:.
22
 *
23
 * - theme initialization
24
 * - pathMap building
25
 *
26
 * Usage, in config:
27
 *
28
 * ```php
29
 * 'components' => [
30
 *     'themeManager' => [
31
 *         'class' => \hiqdev\thememanager\ThemeManager::class,
32
 *     ],
33
 * ]
34
 * ```
35
 *
36
 * @author Andrii Vasyliev <[email protected]>
37
 */
38
class ThemeManager extends \hiqdev\yii2\collection\Manager implements \yii\base\BootstrapInterface
39
{
40
    /**
41
     * @var array basic pathMap for all themes, will be merged with theme own pathMap
42
     */
43
    public $pathMap = [];
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    protected $_itemClass = Theme::class;
49
50
    /**
51
     * @var string default theme name
52
     */
53
    protected $_defaultTheme;
54
55
    /**
56
     * Sets the default theme name.
57
     *
58
     * @param string $theme default theme name
59
     */
60
    public function setDefaultTheme($theme)
61
    {
62
        $this->_defaultTheme = $theme;
63
    }
64
65
    /**
66
     * Returns the default theme. Returns the first of available themes by default.
67
     *
68
     * @return string default theme name
69
     */
70
    public function getDefaultTheme()
71
    {
72
        if (!$this->_defaultTheme) {
73
            $keys = $this->keys(); /// shame to PHP it can't be done in single line :(
74
            $this->_defaultTheme = reset($keys);
75
        }
76
77
        return $this->_defaultTheme;
78
    }
79
80
    protected $_view;
81
82
    /**
83
     * @return \yii\web\View
84
     * @see setView
85
     */
86
    public function getView()
87
    {
88
        if ($this->_view === null) {
89
            $this->_view = Yii::$app->getView();
90
        }
91
92
        return $this->_view;
93
    }
94
95
    /**
96
     * You can change the View for theme manager.
97
     * @param \yii\web\View $view the view object that will be used to render views or view files
98
     */
99
    public function setView($view)
100
    {
101
        $this->_view = $view;
102
    }
103
104
    /**
105
     * @var Theme current theme object
106
     */
107
    protected $_theme;
108
109
    /**
110
     * Changes theme.
111
     * @param string theme name
112
     * @throws InvalidConfigException
113
     */
114
    public function setTheme($name)
115
    {
116
        if (!$name) {
117
            throw new InvalidConfigException('no theme to set');
118
        }
119
        $this->_theme = $name;
120
    }
121
122
    public function getTheme()
123
    {
124
        if (is_string($this->_theme)) {
125
            if (!$this->has($this->_theme)) {
126
                throw new InvalidConfigException('unknown theme: ' . $this->_theme);
127
            }
128
            $this->_theme = $this->getItem($this->_theme);
129
            $this->getView()->theme = $this->_theme;
130
        }
131
132
        return $this->_theme;
133
    }
134
135
    public function getSettings()
136
    {
137
        return $this->getTheme()->getSettings();
138
    }
139
140
    /**
141
     * @return bool
142
     */
143
    public static function isHomePage()
144
    {
145
        // todo: if route is change during the request processing the result will be outdated
146
        static $result = null;
147
148
        if ($result === null) {
149
            /** @var Controller $controller */
150
            $actualRoute = Yii::$app->controller->getRoute();
151
152
            list($controller, $actionId) = Yii::$app->createController('');
153
            $actionId = !empty($actionId) ? $actionId : $controller->defaultAction;
154
            $defaultRoute = $controller->getUniqueId() . '/' . $actionId;
155
156
            $result = $actualRoute === $defaultRoute;
157
        }
158
159
        return $result;
160
    }
161
162
    /**
163
     * @var AssetBundle[] assets to be registered at bootstrap
164
     */
165
    public $assets = [];
166
167
    /**
168
     * Register all the assets.
169
     */
170
    public function registerAssets()
171
    {
172
        foreach (array_merge($this->assets, $this->getTheme()->assets) as $asset) {
173
            /** @var AssetBundle $asset */
174
            $asset::register($this->getView());
175
        }
176
    }
177
178
    /**
179
     * @var bool is already bootstrapped
180
     */
181
    protected $_isBootstrapped = false;
182
183
    /**
184
     * {@inheritdoc}
185
     */
186
    public function bootstrap($app)
187
    {
188
        if ($this->_isBootstrapped) {
189
            return;
190
        }
191
        $this->_isBootstrapped = true;
192
193
        Yii::trace('Bootstrap themes', get_called_class() . '::bootstrap');
0 ignored issues
show
Deprecated Code introduced by
The method yii\BaseYii::trace() has been deprecated with message: since 2.0.14. Use [[debug()]] instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
194
195
        $data = $this->getSettingsStorage()->get();
196
        $model = new Settings();
197
        $model->load($data);
198
        $theme = $this->hasItem($model->theme) ? $model->theme : null;
199
        $theme = $theme ?: $this->getDefaultTheme();
200
        $this->setTheme($theme);
201
        $this->getTheme();
202
    }
203
204
    /**
205
     * @return SettingsStorageInterface
206
     */
207
    public function getSettingsStorage()
208
    {
209
        return Yii::$app->get('themeSettingsStorage');
210
    }
211
212
    /**
213
     * @return array
214
     */
215
    public function getThemeSettings()
216
    {
217
        return $this->getSettingsStorage()->get();
218
    }
219
}
220