|
@@ -0,0 +1,112 @@
|
|
1
|
+<?php
|
|
2
|
+
|
|
3
|
+namespace Muzich\CoreBundle\Twig\Extensions;
|
|
4
|
+
|
|
5
|
+class MuzichTwigSocialBar extends \Twig_Extension{
|
|
6
|
+
|
|
7
|
+ protected $container;
|
|
8
|
+ protected $translator;
|
|
9
|
+
|
|
10
|
+ /**
|
|
11
|
+ * Constructor.
|
|
12
|
+ *
|
|
13
|
+ * @param ContainerInterface $container
|
|
14
|
+ */
|
|
15
|
+ public function __construct($container, $translator)
|
|
16
|
+ {
|
|
17
|
+ $this->container = $container;
|
|
18
|
+ $this->translator = $translator;
|
|
19
|
+ }
|
|
20
|
+
|
|
21
|
+ public function getName()
|
|
22
|
+ {
|
|
23
|
+ return 'muzich_social_bar';
|
|
24
|
+ }
|
|
25
|
+
|
|
26
|
+ public function getFunctions()
|
|
27
|
+ {
|
|
28
|
+ return array(
|
|
29
|
+ 'socialButtons' => new \Twig_Function_Method($this, 'getSocialButtons' ,array('is_safe' => array('html'))),
|
|
30
|
+ 'facebookButton' => new \Twig_Function_Method($this, 'getFacebookLikeButton' ,array('is_safe' => array('html'))),
|
|
31
|
+ 'twitterButton' => new \Twig_Function_Method($this, 'getTwitterButton' ,array('is_safe' => array('html'))),
|
|
32
|
+ 'googlePlusButton' => new \Twig_Function_Method($this, 'getGooglePlusButton' ,array('is_safe' => array('html'))),
|
|
33
|
+ );
|
|
34
|
+ }
|
|
35
|
+
|
|
36
|
+ public function getSocialButtons($parameters = array())
|
|
37
|
+ {
|
|
38
|
+ // no parameters were defined, keeps default values
|
|
39
|
+ if (!array_key_exists('facebook', $parameters)){
|
|
40
|
+ $render_parameters['facebook'] = array();
|
|
41
|
+ // parameters are defined, overrides default values
|
|
42
|
+ }else if(is_array($parameters['facebook'])){
|
|
43
|
+ $render_parameters['facebook'] = $parameters['facebook'];
|
|
44
|
+ // the button is not displayed
|
|
45
|
+ }else{
|
|
46
|
+ $render_parameters['facebook'] = false;
|
|
47
|
+ }
|
|
48
|
+
|
|
49
|
+ if (!array_key_exists('twitter', $parameters)){
|
|
50
|
+ $render_parameters['twitter'] = array();
|
|
51
|
+ }else if(is_array($parameters['twitter'])){
|
|
52
|
+ $render_parameters['twitter'] = $parameters['twitter'];
|
|
53
|
+ }else{
|
|
54
|
+ $render_parameters['twitter'] = false;
|
|
55
|
+ }
|
|
56
|
+
|
|
57
|
+ if (!array_key_exists('googleplus', $parameters)){
|
|
58
|
+ $render_parameters['googleplus'] = array();
|
|
59
|
+ }else if(is_array($parameters['googleplus'])){
|
|
60
|
+ $render_parameters['googleplus'] = $parameters['googleplus'];
|
|
61
|
+ }else{
|
|
62
|
+ $render_parameters['googleplus'] = false;
|
|
63
|
+ }
|
|
64
|
+
|
|
65
|
+ // get the helper service and display the template
|
|
66
|
+ return $this->container->get('muzich.socialBarHelper')->socialButtons($render_parameters);
|
|
67
|
+ }
|
|
68
|
+
|
|
69
|
+ // https://developers.facebook.com/docs/reference/plugins/like/
|
|
70
|
+ public function getFacebookLikeButton($parameters = array())
|
|
71
|
+ {
|
|
72
|
+ // default values, you can override the values by setting them
|
|
73
|
+ $parameters = $parameters + array(
|
|
74
|
+ 'url' => null,
|
|
75
|
+ 'locale' => 'fr_FR',
|
|
76
|
+ 'send' => false,
|
|
77
|
+ 'width' => 300,
|
|
78
|
+ 'showFaces' => false,
|
|
79
|
+ 'layout' => 'button_count'
|
|
80
|
+ );
|
|
81
|
+
|
|
82
|
+ return $this->container->get('muzich.socialBarHelper')->facebookButton($parameters);
|
|
83
|
+ }
|
|
84
|
+
|
|
85
|
+ public function getTwitterButton($parameters = array())
|
|
86
|
+ {
|
|
87
|
+ $parameters = $parameters + array(
|
|
88
|
+ 'url' => null,
|
|
89
|
+ 'locale' => 'fr',
|
|
90
|
+ 'message' => $this->translator->trans('element.share.twitter.text', array(), 'userui'),
|
|
91
|
+ 'text' => 'Tweet',
|
|
92
|
+ 'via' => 'Muzich_Official',
|
|
93
|
+ 'tag' => 'music'
|
|
94
|
+ );
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+ return $this->container->get('muzich.socialBarHelper')->twitterButton($parameters);
|
|
98
|
+ }
|
|
99
|
+
|
|
100
|
+ public function getGooglePlusButton($parameters = array())
|
|
101
|
+ {
|
|
102
|
+ $parameters = $parameters + array(
|
|
103
|
+ 'url' => null,
|
|
104
|
+ 'locale' => 'en',
|
|
105
|
+ 'size' => 'medium',
|
|
106
|
+ 'annotation' => 'bubble',
|
|
107
|
+ 'width' => '300'
|
|
108
|
+ );
|
|
109
|
+
|
|
110
|
+ return $this->container->get('muzich.socialBarHelper')->googlePlusButton($parameters);
|
|
111
|
+ }
|
|
112
|
+}
|