1
|
|
|
<?php
|
2
|
|
|
/**
|
3
|
|
|
* @author Sergey Glagolev <[email protected]>
|
4
|
|
|
* @link https://github.com/shogodev/argilla/
|
5
|
|
|
* @copyright Copyright © 2003-2014 Shogo
|
6
|
|
|
* @license http://argilla.ru/LICENSE
|
7
|
|
|
* @package frontend.widgets
|
8
|
|
|
*
|
9
|
|
|
* Виджеты ВКотакте
|
10
|
|
|
*
|
11
|
|
|
* Examples:
|
12
|
|
|
* <pre>
|
13
|
|
|
* $this->widget('VKWidget', array('method' => 'like'));
|
14
|
|
|
*
|
15
|
|
|
* $this->widget('VKWidget', array('method' => 'comments'));
|
16
|
|
|
*
|
17
|
|
|
* $this->widget('VKWidget', array('method' => 'share'));
|
18
|
|
|
* </pre>
|
19
|
|
|
*/
|
20
|
|
|
class VKWidget extends CWidget
|
21
|
|
|
{
|
22
|
|
|
public $apiId = 3520584;
|
23
|
|
|
|
24
|
|
|
public $openApiScript = '//vk.com/js/api/openapi.js?86';
|
25
|
|
|
|
26
|
|
|
public $shareScript = 'http://vk.com/js/api/share.js?11';
|
27
|
|
|
|
28
|
|
|
public $method;
|
29
|
|
|
|
30
|
|
|
public $parameters;
|
31
|
|
|
|
32
|
|
|
protected $container;
|
33
|
|
|
|
34
|
|
|
protected $script;
|
35
|
|
|
|
36
|
|
|
public function init()
|
37
|
|
|
{
|
38
|
|
|
$js = "if( window.VK ){VK.init({apiId: ".$this->apiId.", onlyWidgets: true});}";
|
39
|
|
|
Yii::app()->clientScript->registerScript(__CLASS__, $js, CClientScript::POS_END);
|
40
|
|
|
}
|
41
|
|
|
|
42
|
|
|
public function run()
|
43
|
|
|
{
|
44
|
|
|
if( !$this->method )
|
45
|
|
|
throw new CHttpException(500, 'Не задан обязательный параметр method');
|
46
|
|
|
|
47
|
|
|
$widgetMethod = 'widget'.ucfirst($this->method);
|
48
|
|
|
|
49
|
|
|
if( !method_exists($this, $widgetMethod) )
|
50
|
|
|
throw new CHttpException(500, 'Метод '.$this->method.' виджета '.__CLASS__.' не существует');
|
51
|
|
|
|
52
|
|
|
$this->container = 'vk_'.$this->method;
|
53
|
|
|
|
54
|
|
|
$this->{$widgetMethod}();
|
55
|
|
|
$this->renderWidget();
|
56
|
|
|
}
|
57
|
|
|
|
58
|
|
|
protected function widgetLike()
|
59
|
|
|
{
|
60
|
|
|
Yii::app()->clientScript->registerScriptFile($this->openApiScript);
|
61
|
|
|
|
62
|
|
|
if( !$this->parameters )
|
63
|
|
|
{
|
64
|
|
|
$this->parameters = array(
|
65
|
|
|
'type' => 'mini',
|
66
|
|
|
);
|
67
|
|
|
}
|
68
|
|
|
|
69
|
|
|
$this->script = "VK.Widgets.Like('".$this->container."', ".CJavaScript::encode($this->parameters).");";
|
70
|
|
|
}
|
71
|
|
|
|
72
|
|
|
protected function widgetComments()
|
73
|
|
|
{
|
74
|
|
|
Yii::app()->clientScript->registerScriptFile($this->openApiScript);
|
75
|
|
|
|
76
|
|
|
if( !$this->parameters )
|
|
|
|
|
77
|
|
|
{
|
78
|
|
|
$this->parameters = array(
|
79
|
|
|
'limit' => 10,
|
80
|
|
|
'width' => 500,
|
81
|
|
|
'attach' => 'photo,video',
|
82
|
|
|
);
|
83
|
|
|
}
|
84
|
|
|
|
85
|
|
|
$this->script = "VK.Widgets.Comments('".$this->container."', ".CJavaScript::encode($this->parameters).");";
|
86
|
|
|
}
|
87
|
|
|
|
88
|
|
|
protected function widgetShare()
|
89
|
|
|
{
|
90
|
|
|
Yii::app()->clientScript->registerScriptFile($this->shareScript);
|
91
|
|
|
|
92
|
|
|
if( !$this->parameters )
|
|
|
|
|
93
|
|
|
{
|
94
|
|
|
$this->parameters = array(
|
95
|
|
|
'type' => 'button',
|
96
|
|
|
'text' => 'Сохранить',
|
97
|
|
|
);
|
98
|
|
|
}
|
99
|
|
|
|
100
|
|
|
echo "<script type='text/javascript'>document.write(VK.Share.button(false, ".CJavaScript::encode($this->parameters)."));</script>";
|
101
|
|
|
$this->container = false;
|
102
|
|
|
}
|
103
|
|
|
|
104
|
|
|
protected function renderWidget()
|
105
|
|
|
{
|
106
|
|
|
if( $this->script )
|
107
|
|
|
Yii::app()->clientScript->registerScript(__CLASS__.$this->method, 'if( window.VK ){'.$this->script.'}', CClientScript::POS_END);
|
108
|
|
|
|
109
|
|
|
if( $this->container )
|
|
|
|
|
110
|
|
|
echo CHtml::tag('div', array('id' => $this->container), null, true);
|
111
|
|
|
}
|
112
|
|
|
} |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.