|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace app\modules\seo\models; |
|
4
|
|
|
|
|
5
|
|
|
use app\backend\BackendModule; |
|
6
|
|
|
use app\backend\components\BackendController; |
|
7
|
|
|
use devgroup\TagDependencyHelper\ActiveRecordHelper; |
|
8
|
|
|
use Yii; |
|
9
|
|
|
use yii\data\ActiveDataProvider; |
|
10
|
|
|
use yii\db\ActiveRecord; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* This is the model class for table "seo_meta". |
|
14
|
|
|
* |
|
15
|
|
|
* @property string $key |
|
16
|
|
|
* @property string $name |
|
17
|
|
|
* @property integer $content |
|
18
|
|
|
*/ |
|
19
|
|
|
class Meta extends ActiveRecord |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @inheritdoc |
|
23
|
|
|
*/ |
|
24
|
|
|
public static function tableName() |
|
25
|
|
|
{ |
|
26
|
|
|
return '{{%seo_meta}}'; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @inheritdoc |
|
31
|
|
|
*/ |
|
32
|
|
|
public function behaviors() |
|
33
|
|
|
{ |
|
34
|
|
|
return [ |
|
35
|
|
|
'class' => ActiveRecordHelper::className(), |
|
36
|
|
|
]; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @inheritdoc |
|
41
|
|
|
*/ |
|
42
|
|
|
public function rules() |
|
43
|
|
|
{ |
|
44
|
|
|
return [ |
|
45
|
|
|
[['key', 'name', 'content'], 'required'], |
|
46
|
|
|
[['key'], 'unique'], |
|
47
|
|
|
[['key', 'name', 'content'], 'string', 'max' => 255] |
|
48
|
|
|
]; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @inheritdoc |
|
53
|
|
|
*/ |
|
54
|
|
|
public function attributeLabels() |
|
55
|
|
|
{ |
|
56
|
|
|
return [ |
|
57
|
|
|
'key' => \Yii::t('app', 'Key'), |
|
58
|
|
|
'name' => \Yii::t('app', 'Name'), |
|
59
|
|
|
'content' => \Yii::t('app', 'Content'), |
|
60
|
|
|
]; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Search meta tags |
|
65
|
|
|
* @param $params |
|
66
|
|
|
* @return ActiveDataProvider |
|
67
|
|
|
*/ |
|
68
|
|
|
public function search($params) |
|
69
|
|
|
{ |
|
70
|
|
|
$this->load($params); |
|
71
|
|
|
$query = self::find(); |
|
72
|
|
|
foreach ($this->attributes as $name => $value) { |
|
73
|
|
|
if (!empty($value)) { |
|
74
|
|
|
$query->andWhere("`$name` LIKE :$name", [":$name" => "%$value%"]); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
$dataProvider = new ActiveDataProvider( |
|
78
|
|
|
[ |
|
79
|
|
|
'query' => $query, |
|
80
|
|
|
'pagination' => [ |
|
81
|
|
|
'pageSize' => 10, |
|
82
|
|
|
], |
|
83
|
|
|
] |
|
84
|
|
|
); |
|
85
|
|
|
return $dataProvider; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public static function registrationMeta() |
|
89
|
|
|
{ |
|
90
|
|
|
if (Yii::$app->request->isAjax === false && !BackendModule::isBackend()) { |
|
91
|
|
|
$cacheName = Yii::$app->getModule('seo')->cacheConfig['metaCache']['name']; |
|
92
|
|
|
$cacheExpire = Yii::$app->getModule('seo')->cacheConfig['metaCache']['expire']; |
|
93
|
|
|
$metas = Yii::$app->getCache()->get($cacheName); |
|
94
|
|
|
if ($metas === false) { |
|
95
|
|
|
$metas = Meta::find()->all(); |
|
|
|
|
|
|
96
|
|
|
Yii::$app->getCache()->set($cacheName, $metas, $cacheExpire); |
|
97
|
|
|
} |
|
98
|
|
|
foreach ($metas as $meta) { |
|
99
|
|
|
Yii::$app->controller->getView()->registerMetaTag( |
|
100
|
|
|
[ |
|
101
|
|
|
'name' => $meta->name, |
|
102
|
|
|
'content' => $meta->content, |
|
103
|
|
|
], |
|
104
|
|
|
$meta->key |
|
105
|
|
|
); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
This check looks for accesses to local static members using the fully qualified name instead of
self::.While this is perfectly valid, the fully qualified name of
Certificate::TRIPLEDES_CBCcould just as well be replaced byself::TRIPLEDES_CBC. Referencing local members withself::assured the access will still work when the class is renamed, makes it perfectly clear that the member is in fact local and will usually be shorter.