Bastien Sevajol пре 11 година
родитељ
комит
097843e595

+ 2 - 0
app/Resources/translations/userui.en.yml Прегледај датотеку

@@ -246,6 +246,8 @@ element:
246 246
       no:                No
247 247
   share:
248 248
     share_button:        Share
249
+    twitter:            
250
+      text:              "Some music ? "
249 251
     
250 252
 comment:
251 253
   report:

+ 2 - 0
app/Resources/translations/userui.fr.yml Прегледај датотеку

@@ -258,6 +258,8 @@ element:
258 258
       no:                Non
259 259
   share:
260 260
     share_button:        Partager
261
+    twitter:            
262
+      text:              "Un peu de musique ? "
261 263
     
262 264
 comment:
263 265
   report:

+ 1 - 1
src/Muzich/CoreBundle/Resources/config/routing.yml Прегледај датотеку

@@ -124,7 +124,7 @@ element_remove_from_group:
124 124
 
125 125
 element_show_one:
126 126
   pattern: /song/{element_id}/{element_slug}
127
-  defaults: { _controller: MuzichHomeBundle:Home:showOneElement }
127
+  defaults: { _controller: MuzichHomeBundle:Home:showOneElement, element_slug: null }
128 128
 
129 129
 ##
130 130
 

+ 17 - 0
src/Muzich/CoreBundle/Resources/public/css/main.css Прегледај датотеку

@@ -2516,6 +2516,23 @@ div#share_from_message
2516 2516
   font-size: 115%;
2517 2517
 }
2518 2518
 
2519
+div.social_buttons ul
2520
+{
2521
+  list-style-type: none;
2522
+  margin-left: 0;
2523
+}
2524
+
2525
+div.social_buttons ul li
2526
+{
2527
+  display : inline;
2528
+  margin-left: 5px;
2529
+  float:left;
2530
+}
2531
+
2532
+div.social_buttons ul li.googleplus {
2533
+    margin-left: -25px;
2534
+}
2535
+
2519 2536
 /*
2520 2537
 *
2521 2538
 *

+ 31 - 0
src/Muzich/CoreBundle/Resources/views/SearchElement/element.html.twig Прегледај датотеку

@@ -410,6 +410,37 @@
410 410
       {% endif %}
411 411
       
412 412
       
413
+      <div class="social_buttons">
414
+        <ul>
415
+          <li class="facebook">
416
+            {{ facebookButton( {
417
+              'locale': 'fr_FR', 
418
+              'url': 'http:' ~ url('element_show_one', {
419
+                'element_id' : element.id,
420
+                'element_slug' : element.slug
421
+              }, true) })
422
+            }}
423
+          </li>
424
+          <li class="twitter">
425
+            {{ twitterButton( {
426
+              'locale': 'fr_FR', 
427
+              'url': 'http:' ~ url('element_show_one', {
428
+                'element_id' : element.id
429
+              }, true) }) 
430
+            }}
431
+          </li>
432
+          <li class="googleplus">
433
+            {{ googlePlusButton( {
434
+              'locale': 'fr_FR', 'url': 
435
+              'http:' ~ url('element_show_one', {
436
+                'element_id' : element.id,
437
+                'element_slug' : element.slug
438
+              }, true) }) 
439
+            }}
440
+          </li>
441
+        </ul>
442
+      </div>
443
+      
413 444
     </td>
414 445
   </tr>
415 446
 </table>

+ 18 - 0
src/Muzich/CoreBundle/Resources/views/helper/facebookButton.html.twig Прегледај датотеку

@@ -0,0 +1,18 @@
1
+{% if url is not defined or url == null %}
2
+    {% set url = app.request.uri %}
3
+{% endif %}
4
+
5
+{% spaceless %}
6
+ {# initialize facebook SDK #}
7
+ <div id="fb-root"></div>
8
+ <script>$(document).ready(function() {  (function(d, s, id) {
9
+   var js, fjs = d.getElementsByTagName(s)[0];
10
+   if (d.getElementById(id)) return;
11
+   js = d.createElement(s); js.id = id;
12
+   js.src = "//connect.facebook.net/{{locale}}/all.js#xfbml=1";
13
+   fjs.parentNode.insertBefore(js, fjs);
14
+ }(document, 'script', 'facebook-jssdk'));  });</script>
15
+
16
+ <div class="fb-like" data-href="{{url}}" data-send="{{send}}" data-layout="{{layout}}" data-width="{{width}}" data-show-faces="{{showFaces}}"></div>
17
+
18
+{% endspaceless %}

+ 18 - 0
src/Muzich/CoreBundle/Resources/views/helper/googlePlusButton.html.twig Прегледај датотеку

@@ -0,0 +1,18 @@
1
+{% if url is not defined or url == null %}
2
+    {% set url = app.request.uri %}
3
+{% endif %}
4
+
5
+{% spaceless %}
6
+ <div class="g-plusone" data-size="{{size}}" data-annotation="{{annotation}}" data-width="{{width}}" data-href="{{url}}"></div>
7
+
8
+ <script type="text/javascript">
9
+   window.___gcfg = {lang: '{{locale}}'};
10
+
11
+   (function() {
12
+     var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
13
+     po.src = 'https://apis.google.com/js/plusone.js';
14
+     var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
15
+   })();
16
+ </script>
17
+
18
+{% endspaceless %}

+ 18 - 0
src/Muzich/CoreBundle/Resources/views/helper/socialButtons.html.twig Прегледај датотеку

@@ -0,0 +1,18 @@
1
+
2
+  {% if facebook is not sameas(false) %}
3
+    <div class="facebookButton">
4
+      {{ facebookButton(facebook) }}
5
+    </div>
6
+  {% endif %}
7
+
8
+  {% if googleplus is not sameas(false) %}
9
+    <div class="googleplus">
10
+      {{ googlePlusButton(googleplus) }}
11
+    </div>
12
+  {% endif %}
13
+
14
+  {% if twitter is not sameas(false) %}
15
+    <div class="twitterButton">
16
+      {{ twitterButton(twitter) }}
17
+    </div>
18
+  {% endif %}

+ 22 - 0
src/Muzich/CoreBundle/Resources/views/helper/twitterButton.html.twig Прегледај датотеку

@@ -0,0 +1,22 @@
1
+{% if url is not defined or url == null %}
2
+    {% set url = app.request.uri %}
3
+{% endif %}
4
+
5
+{% spaceless %}
6
+ <a href="https://twitter.com/share" class="twitter-share-button"
7
+
8
+   data-text="{{message}}" 
9
+   data-url="{{url}}"
10
+   data-lang="{{locale}}"
11
+
12
+   {% if via is not sameas(false) %}
13
+     data-via="{{via}}"
14
+   {% endif %}
15
+
16
+   {% if tag is not sameas(false) %}
17
+     data-hashtags="{{tag}}"
18
+   {% endif %}
19
+ >{{text}}</a>
20
+
21
+ <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
22
+{% endspaceless %}

+ 42 - 0
src/Muzich/CoreBundle/Templating/Helper/SocialBarHelper.php Прегледај датотеку

@@ -0,0 +1,42 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\Templating\Helper;
4
+
5
+use Symfony\Component\Templating\Helper\Helper;
6
+use Symfony\Component\Templating\EngineInterface;
7
+
8
+class SocialBarHelper extends Helper
9
+{
10
+    protected $templating;
11
+
12
+    public function __construct(EngineInterface $templating)
13
+    {
14
+        $this->templating  = $templating;
15
+    }
16
+
17
+
18
+    public function socialButtons($parameters)
19
+    {
20
+      return $this->templating->render('MuzichCoreBundle:helper:socialButtons.html.twig', $parameters);
21
+    }
22
+
23
+    public function facebookButton($parameters)
24
+    {
25
+      return $this->templating->render('MuzichCoreBundle:helper:facebookButton.html.twig', $parameters);
26
+    }
27
+
28
+    public function twitterButton($parameters)
29
+    {
30
+      return $this->templating->render('MuzichCoreBundle:helper:twitterButton.html.twig', $parameters);
31
+    }
32
+
33
+    public function googlePlusButton($parameters)
34
+    {
35
+      return $this->templating->render('MuzichCoreBundle:helper:googlePlusButton.html.twig', $parameters);
36
+    }
37
+
38
+    public function getName()
39
+    {
40
+        return 'socialButtons';
41
+    }
42
+}

+ 112 - 0
src/Muzich/CoreBundle/Twig/Extensions/MuzichTwigSocialBar.php Прегледај датотеку

@@ -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
+}

src/Muzich/CoreBundle/Extension/MyTwigExtension.php → src/Muzich/CoreBundle/Twig/Extensions/MyTwigExtension.php Прегледај датотеку

@@ -1,6 +1,6 @@
1 1
 <?php
2 2
 
3
-namespace Muzich\CoreBundle\Extension;
3
+namespace Muzich\CoreBundle\Twig\Extensions;
4 4
 
5 5
 use Symfony\Bundle\FrameworkBundle\Translation\Translator;
6 6
 use Muzich\CoreBundle\Entity\Event;