Commit bdbc858e1c877cb40a32e783875210f76359d272
1 parent
28143a3c
test
Showing
2 changed files
with
14 additions
and
1 deletions
Show diff stats
common/components/Request.php
... | ... | @@ -37,4 +37,16 @@ class Request extends \yii\web\Request |
37 | 37 | |
38 | 38 | } |
39 | 39 | |
40 | + public static function getIsLocal($url) | |
41 | + { | |
42 | + $server_name = \Yii::$app->request->serverName; | |
43 | + $server_name = str_replace('.', '\.', $server_name); | |
44 | + $pattern = '/^(?:https?:\/\/)?\/?(?:www\.)?'.$server_name.'(?:\/.*)?$/'; | |
45 | + if(preg_match($pattern, $url)) { | |
46 | + return true; | |
47 | + } else { | |
48 | + return false; | |
49 | + } | |
50 | + } | |
51 | + | |
40 | 52 | } |
41 | 53 | \ No newline at end of file | ... | ... |
frontend/views/accounts/_blog_form.php
... | ... | @@ -2,6 +2,7 @@ |
2 | 2 | /** |
3 | 3 | * @var Blog $blog |
4 | 4 | */ |
5 | + use common\components\Request; | |
5 | 6 | use common\models\Blog; |
6 | 7 | use common\widgets\ImageUploader; |
7 | 8 | use mihaildev\ckeditor\CKEditor; |
... | ... | @@ -87,7 +88,7 @@ use yii\helpers\Html; |
87 | 88 | </div> |
88 | 89 | |
89 | 90 | <div class="admin-back-note"> |
90 | - <?= Html::a('вернуться', [ 'accounts/blog' ]) ?> | |
91 | + <?= Html::a('вернуться', Request::getIsLocal(\Yii::$app->request->referrer)?\Yii::$app->request->referrer:['accounts/blog' ]) ?> | |
91 | 92 | </div> |
92 | 93 | </div> |
93 | 94 | </div> | ... | ... |