1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @link https://github.com/yiimaker/yii2-social-share |
5
|
|
|
* @copyright Copyright (c) 2017-2021 Volodymyr Kupriienko |
6
|
|
|
* @license BSD 3-Clause License |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace ymaker\social\share\configurators; |
10
|
|
|
|
11
|
|
|
use yii\base\BaseObject; |
12
|
|
|
use yii\helpers\ArrayHelper; |
13
|
|
|
use ymaker\social\share\drivers\Facebook; |
14
|
|
|
use ymaker\social\share\drivers\Gmail; |
15
|
|
|
use ymaker\social\share\drivers\GooglePlus; |
16
|
|
|
use ymaker\social\share\drivers\LinkedIn; |
17
|
|
|
use ymaker\social\share\drivers\Pinterest; |
18
|
|
|
use ymaker\social\share\drivers\Telegram; |
19
|
|
|
use ymaker\social\share\drivers\Trello; |
20
|
|
|
use ymaker\social\share\drivers\Tumblr; |
21
|
|
|
use ymaker\social\share\drivers\Twitter; |
22
|
|
|
use ymaker\social\share\drivers\WhatsApp; |
23
|
|
|
use ymaker\social\share\drivers\Yahoo; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Configurator for social network drivers. |
27
|
|
|
* |
28
|
|
|
* @author Vladimir Kuprienko <[email protected]> |
29
|
|
|
* |
30
|
|
|
* @since 1.0 |
31
|
|
|
*/ |
32
|
|
|
class Configurator extends BaseObject implements ConfiguratorInterface, IconsConfigInterface, SeoConfigInterface |
33
|
|
|
{ |
34
|
|
|
const DEFAULT_ICONS_MAP = [ |
35
|
|
|
Facebook::class => 'si si-facebook', |
36
|
|
|
Twitter::class => 'si si-twitter', |
37
|
|
|
GooglePlus::class => 'si si-google-plus', |
38
|
|
|
LinkedIn::class => 'si si-linkedin', |
39
|
|
|
Pinterest::class => 'si si-pinterest', |
40
|
|
|
Telegram::class => 'si si-telegram', |
41
|
|
|
WhatsApp::class => 'si si-whatsapp', |
42
|
|
|
Gmail::class => 'si si-gmail', |
43
|
|
|
Tumblr::class => 'si si-tumblr', |
44
|
|
|
Yahoo::class => 'si si-yahoo', |
45
|
|
|
Trello::class => 'si si-trello', |
46
|
|
|
]; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Configuration of social network drivers. |
50
|
|
|
* |
51
|
|
|
* @var array |
52
|
|
|
*/ |
53
|
|
|
public $socialNetworks = []; |
54
|
|
|
/** |
55
|
|
|
* CSS options for share links. |
56
|
|
|
* |
57
|
|
|
* @var array |
58
|
|
|
*/ |
59
|
|
|
public $options = []; |
60
|
|
|
/** |
61
|
|
|
* Enable SEO options for share links. |
62
|
|
|
* |
63
|
|
|
* @var bool |
64
|
|
|
*/ |
65
|
|
|
public $enableSeoOptions = true; |
66
|
|
|
/** |
67
|
|
|
* HTML attributes from this option will be applied if `enableSeoOptions` is true. |
68
|
|
|
* |
69
|
|
|
* @var array |
70
|
|
|
*/ |
71
|
|
|
public $seoOptions = []; |
72
|
|
|
/** |
73
|
|
|
* Enable default icons instead labels for social networks. |
74
|
|
|
* |
75
|
|
|
* @var bool |
76
|
|
|
* |
77
|
|
|
* @deprecated since 2.3 |
78
|
|
|
*/ |
79
|
|
|
public $enableDefaultIcons = false; |
80
|
|
|
/** |
81
|
|
|
* Enable icons instead of text labels. |
82
|
|
|
* |
83
|
|
|
* @var bool |
84
|
|
|
* |
85
|
|
|
* @since 2.3 |
86
|
|
|
*/ |
87
|
|
|
public $enableIcons = false; |
88
|
|
|
/** |
89
|
|
|
* Enable default icons asset. |
90
|
|
|
* |
91
|
|
|
* @var bool |
92
|
|
|
* |
93
|
|
|
* @since 2.3 |
94
|
|
|
*/ |
95
|
|
|
public $enableDefaultAsset = true; |
96
|
|
|
/** |
97
|
|
|
* Configuration of icons for social network drivers. |
98
|
|
|
* |
99
|
|
|
* @var array |
100
|
|
|
*/ |
101
|
|
|
public $icons = []; |
102
|
|
|
/** |
103
|
|
|
* Enable registering of drivers meta tags. |
104
|
|
|
* |
105
|
|
|
* @var bool |
106
|
|
|
* |
107
|
|
|
* @since 2.1 |
108
|
|
|
*/ |
109
|
|
|
public $registerMetaTags = true; |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Set default values for special link options. |
113
|
|
|
*/ |
114
|
|
|
public function init() |
115
|
|
|
{ |
116
|
|
|
if ($this->isSeoEnabled() && empty($this->seoOptions)) { |
117
|
|
|
$this->seoOptions = [ |
118
|
|
|
'target' => '_blank', |
119
|
|
|
'rel' => 'noopener', |
120
|
|
|
]; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
if ($this->enableIcons || $this->enableDefaultIcons) { |
|
|
|
|
124
|
|
|
$this->icons = ArrayHelper::merge(self::DEFAULT_ICONS_MAP, $this->icons); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* {@inheritdoc} |
130
|
|
|
*/ |
131
|
|
|
public function getSocialNetworks() |
132
|
|
|
{ |
133
|
|
|
return $this->socialNetworks; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* {@inheritdoc} |
138
|
|
|
*/ |
139
|
|
|
public function getOptions() |
140
|
|
|
{ |
141
|
|
|
return $this->isSeoEnabled() |
142
|
|
|
? ArrayHelper::merge($this->options, $this->seoOptions) |
143
|
|
|
: $this->options; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* {@inheritdoc} |
148
|
|
|
*/ |
149
|
|
|
public function canRegisterMetaTags() |
150
|
|
|
{ |
151
|
|
|
return $this->registerMetaTags; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* {@inheritdoc} |
156
|
|
|
*/ |
157
|
|
|
public function isIconsEnabled() |
158
|
|
|
{ |
159
|
|
|
return $this->enableIcons || $this->enableDefaultIcons; |
|
|
|
|
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* {@inheritdoc} |
164
|
|
|
*/ |
165
|
|
|
public function isDefaultAssetEnabled() |
166
|
|
|
{ |
167
|
|
|
return $this->enableDefaultAsset || $this->enableDefaultIcons; |
|
|
|
|
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* {@inheritdoc} |
172
|
|
|
* |
173
|
|
|
* @param string $driverName class name of the needed driver |
174
|
|
|
*/ |
175
|
|
|
public function getIconSelector($driverName) |
176
|
|
|
{ |
177
|
|
|
return isset($this->icons[$driverName]) ? $this->icons[$driverName] : ''; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* {@inheritdoc} |
182
|
|
|
*/ |
183
|
|
|
public function isSeoEnabled() |
184
|
|
|
{ |
185
|
|
|
return $this->enableSeoOptions; |
186
|
|
|
} |
187
|
|
|
} |
188
|
|
|
|
This property has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.