This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * @author Nikita Melnikov <[email protected]>, Vladimir Utenkov <[email protected]> |
||
4 | * @link https://github.com/shogodev/argilla/ |
||
5 | * @copyright Copyright © 2003-2014 Shogo |
||
6 | * @license http://argilla.ru/LICENSE |
||
7 | * @package frontend.models.seo |
||
8 | * |
||
9 | * Class Link Ссылка на ресурс по теме. |
||
10 | * |
||
11 | * @method static Link model(string $className = __CLASS__) |
||
12 | * @method Link visible() |
||
13 | * |
||
14 | * @property integer $id |
||
15 | * @property integer $section_id |
||
16 | * @property string $title |
||
17 | * @property string $content |
||
18 | * @property string $email |
||
19 | * @property string $region |
||
20 | * @property string $url |
||
21 | * @property string $date |
||
22 | * @property integer $page |
||
23 | * @property boolean $visible |
||
24 | * @property integer $position |
||
25 | * |
||
26 | * @property LinkSection $section Секция, к которой принадлежит данная ссылка. |
||
27 | */ |
||
28 | class Link extends FActiveRecord |
||
29 | { |
||
30 | const LINKS_PER_PAGE = 10; |
||
31 | |||
32 | 21 | public function tableName() |
|
33 | { |
||
34 | 21 | return '{{seo_link}}'; |
|
35 | } |
||
36 | |||
37 | public function rules() |
||
38 | { |
||
39 | return [ |
||
40 | ['title, url, section_id, email', 'required'], |
||
41 | ['title, url, region', 'length', 'max' => 255, 'min' => 3], |
||
42 | ['url', 'url'], |
||
43 | ['email', 'email'], |
||
44 | ['section_id', 'numerical', 'integerOnly' => true], |
||
45 | ['title, url, content', 'filter', 'filter' => 'htmlspecialchars'], |
||
46 | ]; |
||
47 | } |
||
48 | |||
49 | public function attributeLabels() |
||
50 | { |
||
51 | return [ |
||
52 | 'url' => 'URL сайта', |
||
53 | 'title' => 'Название сайта', |
||
54 | 'content' => 'Описание сайта', |
||
55 | 'section_id' => 'Категория', |
||
56 | 'email' => 'E-mail', |
||
57 | ]; |
||
58 | } |
||
59 | |||
60 | 1 | public function relations() |
|
61 | { |
||
62 | return [ |
||
63 | 1 | 'section' => [self::BELONGS_TO, 'LinkSection', 'section_id'], |
|
64 | 1 | ]; |
|
65 | } |
||
66 | |||
67 | /** |
||
68 | * Ссылки отсортированные по атрибуту 'position' по возрастанию. |
||
69 | * |
||
70 | * @return array |
||
71 | */ |
||
72 | 16 | public function defaultScope() |
|
73 | { |
||
74 | return [ |
||
75 | 16 | 'order' => 'IF(position, position, 999999999)', |
|
76 | 16 | ]; |
|
77 | } |
||
78 | |||
79 | 11 | public function scopes() |
|
80 | { |
||
81 | return [ |
||
82 | 'visible' => [ |
||
83 | 11 | 'condition' => 'visible = :visible', |
|
84 | 'params' => [ |
||
85 | 11 | ':visible' => '1', |
|
86 | 11 | ], |
|
87 | 11 | ], |
|
88 | 11 | ]; |
|
89 | } |
||
90 | |||
91 | /** |
||
92 | * Ссылки на указанной странице. |
||
93 | * |
||
94 | * @param int $page Номер страницы, для которой нужно найти ссылки. |
||
95 | * |
||
96 | * @return Link |
||
97 | */ |
||
98 | 7 | View Code Duplication | public function onPage($page) |
0 ignored issues
–
show
|
|||
99 | { |
||
100 | 7 | $this->getDbCriteria()->mergeWith([ |
|
101 | 7 | 'condition' => 'page = :page', |
|
102 | 'params' => [ |
||
103 | 7 | ':page' => strval($page), |
|
104 | 7 | ], |
|
105 | 7 | ]); |
|
106 | |||
107 | 7 | return $this; |
|
108 | } |
||
109 | |||
110 | /** |
||
111 | * Ссылки в указанной секции. |
||
112 | * |
||
113 | * @param int $sectionId ID секции, для которой искать ссылки. |
||
114 | * |
||
115 | * @return Link |
||
116 | */ |
||
117 | 7 | View Code Duplication | public function inSection($sectionId) |
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. ![]() |
|||
118 | { |
||
119 | 7 | $this->getDbCriteria()->mergeWith([ |
|
120 | 7 | 'condition' => 'section_id = :sectionId', |
|
121 | 'params' => [ |
||
122 | 7 | ':sectionId' => strval($sectionId), |
|
123 | 7 | ], |
|
124 | 7 | ]); |
|
125 | |||
126 | 7 | return $this; |
|
127 | } |
||
128 | |||
129 | /** |
||
130 | * Ссылки на всех страницах перед указанной. |
||
131 | * |
||
132 | * @param int $page Страница до которой искать ссылки. |
||
133 | * |
||
134 | * @return Link |
||
135 | */ |
||
136 | 3 | public function linksOnPagesBefore($page) |
|
137 | { |
||
138 | 3 | $this->getDbCriteria()->mergeWith([ |
|
139 | 3 | 'condition' => 'page < :page', |
|
140 | 'params' => [ |
||
141 | ':page' => $page |
||
142 | 3 | ] |
|
143 | 3 | ]); |
|
144 | |||
145 | 3 | return $this; |
|
146 | } |
||
147 | |||
148 | 2 | public function beforeSave() |
|
149 | { |
||
150 | 2 | if( parent::beforeSave() ) |
|
151 | 2 | { |
|
152 | 2 | if( $this->isNewRecord ) |
|
153 | 2 | { |
|
154 | 2 | $this->date = new CDbExpression('NOW()'); |
|
155 | 2 | $this->page = empty($this->page) || intval($this->page) < 1 ? 1 : $this->page; |
|
156 | 2 | $this->page = $this->choosePage($this->page); |
|
157 | 2 | $this->visible = 0; |
|
158 | 2 | } |
|
159 | |||
160 | 2 | return true; |
|
161 | } |
||
162 | |||
163 | return false; |
||
164 | } |
||
165 | |||
166 | /** |
||
167 | * Выбирает страницу для новой ссылки. |
||
168 | * |
||
169 | * @param int $page Начальная страница. |
||
170 | * |
||
171 | * @return int Выбранная страница. |
||
172 | */ |
||
173 | 2 | private function choosePage($page) |
|
174 | { |
||
175 | 2 | $linksOnPage = self::model()->inSection($this->section_id)->onPage($page)->count(); |
|
176 | |||
177 | 2 | if( $linksOnPage < self::LINKS_PER_PAGE ) |
|
178 | 2 | { |
|
179 | 2 | return $page; |
|
180 | } |
||
181 | else |
||
182 | { |
||
183 | 2 | return $this->choosePage(++$page); |
|
184 | } |
||
185 | } |
||
186 | } |
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.