Issues (2)

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/Gallery.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
 * @link https://github.com/2amigos/yii2-gallery-widget
4
 * @copyright Copyright (c) 2013-2016 2amigOS! Consulting Group LLC
5
 * @license http://opensource.org/licenses/BSD-3-Clause
6
 */
7
8
namespace dosamigos\gallery;
9
10
use yii\base\Widget;
11
use yii\helpers\ArrayHelper;
12
use yii\helpers\Html;
13
use yii\helpers\Json;
14
use yii\web\JsExpression;
15
16
/**
17
 * Gallery renders a BlueImp Gallery items
18
 *
19
 * @author Alexander Kochetov <[email protected]>
20
 */
21
class Gallery extends Widget
22
{
23
    /**
24
     * @var array the HTML attributes for the links container tag.
25
     * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
26
     */
27
    public $options = [];
28
    /**
29
     * @var array the HTML attributes for the lightbox container tag.
30
     * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
31
     */
32
    public $templateOptions = [];
33
    /**
34
     * @var array the options for the BlueImp Gallery plugin.
35
     * Please refer to the BlueImp Gallery plugin Web page for possible options.
36
     * @see https://github.com/blueimp/Gallery/blob/master/README.md#setup
37
     */
38
    public $clientOptions = [];
39
    /**
40
     * @var array the event handlers for the underlying Bootstrap Switch 3 input JS plugin.
41
     * Please refer to the [BlueImp Gallery plugin](https://github.com/blueimp/Gallery/blob/master/README.md#event-callbacks)
42
     * for information about their callbacks.
43
     */
44
    public $clientEvents = [];
45
    /**
46
     * @var array The array of items that compound the gallery. The syntax is as follows:
47
     *
48
     * - src: string, the image to display
49
     * - url: string, the image to display on the lightbox. If none found, will display `src`
50
     * - options: HTML attributes of the link
51
     * - imageOptions: HTML attributes of the image to be displayed
52
     */
53
    public $items = array();
54
    /**
55
     * @var bool whether to display the controls on initialization
56
     */
57
    public $showControls = true;
58
59
    /**
60
     * @inheritdoc
61
     */
62 6
    public function init()
63
    {
64 6
        parent::init();
65 6
        if (!isset($this->options['id'])) {
66 6
            $this->options['id'] = $this->getId();
67 6
        }
68 6
        $this->templateOptions['id'] = ArrayHelper::getValue($this->templateOptions, 'id', 'blueimp-gallery');
69 6
        Html::addCssClass($this->templateOptions, 'blueimp-gallery');
70 6
        if ($this->showControls) {
71 6
            Html::addCssClass($this->templateOptions, 'blueimp-gallery-controls');
72 6
        }
73
74 6
        foreach($this->clientEvents as $key => $event) {
75 6
            if(!($event instanceof JsExpression)) {
76 6
                $this->clientOptions[$key] = new JsExpression($event);
77 6
            }
78 6
        }
79 6
    }
80
81
    /**
82
     * @inheritdoc
83
     */
84 6
    public function run()
85
    {
86 6
        if (empty($this->items)) {
87 6
            return null;
88
        }
89 6
        echo $this->renderItems();
90 6
        echo $this->renderTemplate();
91 6
        $this->registerClientScript();
92 6
    }
93
94
    /**
95
     * @return string the items that are need to be rendered.
96
     */
97 6
    public function renderItems()
98
    {
99 6
        $items = [];
100 6
        foreach ($this->items as $item) {
101 6
            $items[] = $this->renderItem($item);
102 6
        }
103 6
        return Html::tag('div', implode("\n", array_filter($items)), $this->options);
104
    }
105
106
    /**
107
     * @param mixed $item
108
     * @return null|string the item to render
109
     */
110 6
    public function renderItem($item)
111
    {
112 6
        if (is_string($item)) {
113 3
            return Html::a(Html::img($item), $item, ['class' => 'gallery-item']);
114
        }
115 6
        $src = ArrayHelper::getValue($item, 'src');
116 6
        if ($src === null) {
117 3
            return null;
118
        }
119 6
        $url = ArrayHelper::getValue($item, 'url', $src);
120 6
        $options = ArrayHelper::getValue($item, 'options', []);
121 6
        $imageOptions = ArrayHelper::getValue($item, 'imageOptions', []);
122 6
        Html::addCssClass($options, 'gallery-item');
123
124 6
        return Html::a(Html::img($src, $imageOptions), $url, $options);
125
    }
126
127
    /**
128
     * Renders the template to display the images on a lightbox
129
     * @return string the template
130
     */
131 3
    public function renderTemplate()
132
    {
133 3
        $template[] = '<div class="slides"></div>';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$template was never initialized. Although not strictly required by PHP, it is generally a good practice to add $template = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
134 3
        $template[] = '<h3 class="title"></h3>';
135 3
        $template[] = '<a class="prev">‹</a>';
136 3
        $template[] = '<a class="next">›</a>';
137 3
        $template[] = '<a class="close">×</a>';
138 3
        $template[] = '<a class="play-pause"></a>';
139 3
        $template[] = '<ol class="indicator"></ol>';
140
141 3
        return Html::tag('div', implode("\n", $template), $this->templateOptions);
142
    }
143
144
    /**
145
     * Registers the client script required for the plugin
146
     */
147 3
    public function registerClientScript()
148
    {
149 3
        $view = $this->getView();
150 3
        GalleryAsset::register($view);
151 3
        DosamigosAsset::register($view);
152
153 3
        $id = $this->options['id'];
154 3
        $options = Json::encode($this->clientOptions);
155 3
        $js = "dosamigos.gallery.registerLightBoxHandlers('#$id a', $options);";
156 3
        $view->registerJs($js);
157
158 3
        if (!empty($this->clientEvents)) {
159 3
            $js = [];
160 3
            foreach ($this->clientEvents as $event => $handler) {
161 3
                $js[] = "jQuery('$id').on('$event', $handler);";
162 3
            }
163 3
            $view->registerJs(implode("\n", $js));
164 3
        }
165 3
    }
166
}
167