-
Notifications
You must be signed in to change notification settings - Fork 0
/
SocialLikes.php
197 lines (178 loc) · 4.96 KB
/
SocialLikes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?php
/**
* Social Likes code generation widget
*
* Beautiful share buttons with counters for popular social networks:
* Facebook, Twitter, Google+, Pinterest, Vkontakte, etc. Uses jQuery.
* Based on http://sapegin.github.io/social-likes/ru/
*
* @copyright © Serge Larin <serge.larin@gmail.com> 2014
* @license http://opensource.org/licenses/MIT MIT
*
*/
/**
* Social Likes widget class.
*
* @author Serge Larin
*/
namespace assayerpro\SocialLikes;
use yii\base\Widget;
use yii\helpers\Html;
/**
* SocialLikes widget
*
* @package assayerpro\SocialLikes\SocialLikes
*/
class SocialLikes extends Widget
{
/**
* @var string The skin (classic, flat, birman). By default, classic.
*/
public $skin = 'classic';
/**
* @var string look (horizontal, vertical, single). By default, horizontal
*/
public $look = 'horizontal';
/**
* @var string single title
*/
public $singleTitle = 'Поделиться';
/**
* @var boolean show counters. By default, true
*/
public $showCounters = true;
/**
* @var string URL. When buttons used on different page
*/
public $url = '';
/**
* @var string Title. When differs from current page's title
*/
public $title = '';
/**
* @var boolean. Icons only.
*/
public $iconsOnly = false;
/**
* @var string.
*/
public $twitterVia = '';
/**
* @var string.
*/
public $twitterRelated = '';
/**
* @var string.
*/
public $pinterestMedia = '';
/**
* @var boolean. Show counters even when number is 0. Default: false;
*/
public $zeroes = false;
/**
* @var hash. Buttons configuration
*/
public $buttons = [
'facebook' => [
'title' => 'Поделиться ссылкой на Фейсбуке',
'name' => 'Facebook',
'show' => true,
],
'twitter' => [
'title' => 'Поделиться ссылкой в Твиттере',
'name' => 'Twitter',
'show' => true,
],
'mailru' => [
'title' => 'Поделиться ссылкой в Моём мире',
'name' => 'Мой мир',
'show' => true,
],
'vkontakte' => [
'title' => 'Поделиться ссылкой во Вконтакте',
'name' => 'Вконтакте',
'show' => true,
],
'odnoklassniki' => [
'title' => 'Поделиться ссылкой в Одноклассниках',
'name' => 'Одноклассники',
'show' => true,
],
'plusone' => [
'title' => 'Поделиться ссылкой в Гугл-плюсе',
'name' => 'Google+',
'show' => true,
],
'pinterest' => [
'title' => 'Поделиться ссылкой на Пинтересте',
'name' => 'Pinterest',
'show' => true,
],
];
/**
* skinAssets
*
* @var hash. skinAssets classes
* @access public
*/
public $skinAssets = [
'classic' => 'assayerpro\SocialLikes\SocialAssetClassic',
'flat' => 'assayerpro\SocialLikes\SocialAssetFlat',
'birman' => 'assayerpro\SocialLikes\SocialAssetBirman',
];
/**
* Initializes the widget.
*/
public function init ()
{
parent::init();
}
/**
* Renders the widget.
*/
public function run()
{
$htmlClass = 'social-likes' .
($this->look == 'horizontal' || empty($this->look)?'':' social-likes_'.$this->look) .
($this->iconsOnly?' social-likes_notext':'');
$options = array_filter([
'class' => $htmlClass,
'data-zeroes' => $this->zeroes?'yes':'no',
'data-title' => $this->title,
'data-counters' => $this->showCounters?'yes':'no',
'data-url' => $this->url,
'data-single-title' => $this->look == 'single'?$this->singleTitle:'',
]);
$asset = $this->skinAssets[$this->skin];
$asset::register($this->getView());
return Html::tag('div', $this->renderItems(), $options);
}
/**
* Renders widget items.
*/
public function renderItems()
{
$items = '';
foreach ($this->buttons as $class => $button) {
if ($button['show']) {
$items .= $this->renderItem($button,$class) ;
}
}
return $items;
}
/**
* Renders a widget's item.
* @param string|array $item the item to render.
* @return string the rendering result.
* @throws InvalidConfigException
*/
public function renderItem($item, $class)
{
$options = [
'class' => $class,
'title' => $item['title']
];
$name = $this->iconsOnly?'':$item['name'];
return Html::tag('div', $name, $options);
}
}