Issues (443)

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.

backend/controllers/MediaCommentController.php (10 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
 * @link http://www.writesdown.com/
4
 * @copyright Copyright (c) 2015 WritesDown
5
 * @license http://www.writesdown.com/license/
6
 */
7
8
namespace backend\controllers;
9
10
use common\models\Media;
11
use common\models\MediaComment;
12
use common\models\search\MediaComment as MediaCommentSearch;
13
use Yii;
14
use yii\filters\AccessControl;
15
use yii\filters\VerbFilter;
16
use yii\web\Controller;
17
use yii\web\NotFoundHttpException;
18
19
/**
20
 * Class MediaCommentController, controlling the actions for Media model.
21
 *
22
 * @author Agiel K. Saputra <[email protected]>
23
 * @since 0.1.0
24
 */
25
class MediaCommentController extends Controller
26
{
27
    /**
28
     * @inheritdoc
29
     */
30
    public function behaviors()
31
    {
32
        return [
33
            'access' => [
34
                'class' => AccessControl::className(),
35
                'rules' => [
36
                    [
37
                        'actions' => ['index', 'update', 'delete', 'bulk-action', 'reply'],
38
                        'allow' => true,
39
                        'roles' => ['editor'],
40
                    ],
41
                ],
42
            ],
43
            'verbs' => [
44
                'class' => VerbFilter::className(),
45
                'actions' => [
46
                    'delete' => ['post'],
47
                    'bulk-action' => ['post'],
48
                ],
49
            ],
50
        ];
51
    }
52
53
    /**
54
     * Lists all MediaComment models.
55
     * If there is media, the action will generate list of all MediaComment models based on Media ID.
56
     *
57
     * @param null|integer $media Media ID
58
     * @return mixed
59
     */
60
    public function actionIndex($media = null)
61
    {
62
        $mediaId = null;
63
64
        if ($media) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $media of type null|integer is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
65
            $media = $this->findMedia($media);
66
            $mediaId = $media->id;
67
        }
68
69
        $searchModel = new MediaCommentSearch();
70
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams, $mediaId);
71
72
        return $this->render('index', [
73
            'searchModel' => $searchModel,
74
            'dataProvider' => $dataProvider,
75
            'media' => $media,
76
        ]);
77
    }
78
79
    /**
80
     * Updates an existing MediaComment model.
81
     * If update is successful, the browser will be redirected to the 'update' page.
82
     *
83
     * @param integer $id
84
     * @return mixed
85
     */
86
    public function actionUpdate($id)
87
    {
88
        $model = $this->findModel($id);
89
90
        if ($model->load(Yii::$app->request->post())) {
0 ignored issues
show
The method load cannot be called on $model (of type array|boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
91
            $model->date = date('Y-m-d H:i:s', strtotime($model->date));
92
            if ($model->save()) {
0 ignored issues
show
The method save cannot be called on $model (of type array|boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
93
                return $this->redirect(['update', 'id' => $model->id]);
94
            }
95
        }
96
97
        return $this->render('update', [
98
            'model' => $model,
99
        ]);
100
    }
101
102
    /**
103
     * Deletes an existing MediaComment model.
104
     * If deletion is successful, the browser will be redirected to the 'index' page.
105
     *
106
     * @param integer $id
107
     * @return mixed
108
     */
109 View Code Duplication
    public function actionDelete($id)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
110
    {
111
        $model = $this->findModel($id);
112
        $media = $model->commentMedia;
113
114
        if ($model->delete()) {
0 ignored issues
show
The method delete cannot be called on $model (of type array|boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
115
            if (!$model->parent) {
116
                $media->updateAttributes(['comment_count', --$media->comment_count]);
117
            }
118
            MediaComment::deleteAll(['parent' => $model->id]);
119
        }
120
121
        return $this->redirect(['index']);
122
    }
123
124
    /**
125
     * Bulk action for MediaComment triggered when button 'Apply' clicked.
126
     * The action depends on the value of the dropdown next to the button.
127
     * Only accept POST HTTP method.
128
     */
129 View Code Duplication
    public function actionBulkAction()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
130
    {
131
        if (Yii::$app->request->post('action') === MediaComment::STATUS_APPROVED) {
132
            foreach (Yii::$app->request->post('ids', []) as $id) {
133
                $this->findModel($id)->updateAttributes(['status' => MediaComment::STATUS_APPROVED]);
0 ignored issues
show
The method updateAttributes cannot be called on $this->findModel($id) (of type array|boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
134
            }
135
        } elseif (Yii::$app->request->post('action') === MediaComment::STATUS_NOT_APPROVED) {
136
            foreach (Yii::$app->request->post('ids', []) as $id) {
137
                $this->findModel($id)->updateAttributes(['status' => MediaComment::STATUS_NOT_APPROVED]);
0 ignored issues
show
The method updateAttributes cannot be called on $this->findModel($id) (of type array|boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
138
            }
139
        } elseif (Yii::$app->request->post('action') === MediaComment::STATUS_TRASHED) {
140
            foreach (Yii::$app->request->post('ids', []) as $id) {
141
                $this->findModel($id)->updateAttributes(['status' => MediaComment::STATUS_TRASHED]);
0 ignored issues
show
The method updateAttributes cannot be called on $this->findModel($id) (of type array|boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
142
            }
143
        } elseif (Yii::$app->request->post('action') === 'delete') {
144
            foreach (Yii::$app->request->post('ids', []) as $id) {
145
                $model = $this->findModel($id);
146
                $media = $model->commentMedia;
147
                if ($model->delete()) {
0 ignored issues
show
The method delete cannot be called on $model (of type array|boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
148
                    if (!$model->parent) {
149
                        $media->updateAttributes(['comment_count', --$media->comment_count]);
150
                    }
151
                    MediaComment::deleteAll(['parent' => $model->id]);
152
                }
153
            }
154
        }
155
    }
156
157
    /**
158
     * Reply an existing MediaComment model.
159
     * If reply is successful, the browser will be redirected to 'update' page.
160
     *
161
     * @param int $id Find MediaComment model based on id as its parent
162
     * @return string
163
     */
164
    public function actionReply($id)
165
    {
166
        $commentParent = $this->findModel($id);
167
        $model = new MediaComment(['scenario' => 'reply']);
168
169
        if ($model->load(Yii::$app->request->post())) {
170
            $model->setAttributes([
171
                'media_id' => $commentParent->media_id,
172
                'parent' => $commentParent->id,
173
            ]);
174
            if ($model->save()) {
175
                $this->redirect(['/media-comment/update', 'id' => $model->id]);
176
            }
177
        }
178
179
        return $this->render('reply', [
180
            'commentParent' => $commentParent,
181
            'model' => $model,
182
        ]);
183
    }
184
185
    /**
186
     * Finds the MediaComment model based on its primary key value.
187
     * If the model is not found, a 404 HTTP exception will be thrown.
188
     *
189
     * @param integer $id
190
     * @return MediaComment the loaded model
191
     * @throws NotFoundHttpException if the model cannot be found
192
     */
193
    protected function findModel($id)
194
    {
195
        if (($model = MediaComment::findOne($id)) !== null) {
196
            return $model;
197
        }
198
199
        throw new NotFoundHttpException(Yii::t('writesdown', 'The requested page does not exist.'));
200
    }
201
202
    /**
203
     * Finds the Media model based on its primary key value.
204
     * If the model is not found, a 404 HTTP exception will be thrown.
205
     *
206
     * @param integer $id
207
     * @return Media the loaded model
208
     * @throws NotFoundHttpException if the model cannot be found
209
     */
210
    protected function findMedia($id)
211
    {
212
        if (($model = Media::findOne($id)) !== null) {
213
            return $model;
214
        }
215
216
        throw new NotFoundHttpException(Yii::t('writesdown', 'The requested page does not exist.'));
217
    }
218
}
219