Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a40a5f7

Browse files
committed
Add Providers config to socializer
1 parent 38fd758 commit a40a5f7

7 files changed

Lines changed: 125 additions & 8 deletions

File tree

DependencyInjection/GigyaExtension.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ private function socializerLoad(array $configs, ContainerBuilder $container)
5050
if (isset($config['namespace'])) {
5151
$container->setParameter('gigya.socializer.namespace', $config['namespace']);
5252
}
53+
if (isset($config['providers'])) {
54+
$container->setParameter('gigya.socializer.providers', $config['providers']);
55+
}
5356
}
5457
}
5558

Helper/SocializerHelper.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,46 @@ public function __construct(Socializer $socializer, $namespace)
1616
$this->socializer = $socializer;
1717
}
1818

19-
/**
19+
/**
2020
* @return string $apiKey
2121
*/
2222
public function getApiKey()
2323
{
24-
return $this->socializer->getApiKey();
24+
return $this->socializer->getApiKey();
2525
}
2626

27-
/**
27+
/**
2828
* @return string $name
2929
*/
3030
public function getNamespace()
3131
{
32-
return $this->namespace;
32+
return $this->namespace;
3333
}
3434

3535
/**
3636
* @return string $loginFunctionName
3737
*/
3838
public function getLoginFunctionName()
39+
{
40+
return $this->namespace.".login";
41+
}
42+
43+
/**
44+
* @return string $loginUiFunctionName
45+
*/
46+
public function getLoginUiFunctionName()
3947
{
4048
return $this->namespace.".showLoginUI";
4149
}
4250

51+
/**
52+
* @return array $providers
53+
*/
54+
public function getProviders()
55+
{
56+
return $this->providers;
57+
}
58+
4359
/**
4460
* @param string $key
4561
* @return string $shareFunctionName
@@ -49,7 +65,7 @@ public function getShareFunctionName($key)
4965
return $this->namespace.".showShareUI_".$key;
5066
}
5167

52-
/**
68+
/**
5369
* @param string $key
5470
* @return AntiMattr\GigyaBundle\Socializer\UserAction $userAction
5571
*/

Resources/config/socializer.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
<parameters>
66
<parameter key="gigya.socializer.api_key" type="string" />
77
<parameter key="gigya.socializer.namespace" type="string">window</parameter>
8+
<parameter key="gigya.socializer.providers" type="collection" />
89
<parameter key="gigya.client.class">Buzz\Client\FileGetContents</parameter>
910
<parameter key="gigya.client.message_factory.class">OpenSky\Bundle\GigyaBundle\Socializer\Buzz\MessageFactory</parameter>
1011
</parameters>
1112

1213
<services>
1314
<service id="gigya.socializer" class="OpenSky\Bundle\GigyaBundle\Socializer\Socializer">
1415
<argument>%gigya.socializer.api_key%</argument>
16+
<argument>%gigya.socializer.providers%</argument>
1517
<argument type="service" id="gigya.client" />
1618
<argument type="service" id="gigya.client.message_factory" />
1719
</service>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{#
2+
# @param string provider [facebook, twitter, yahoo, messenger, google, etc...]
3+
# @param string redirectURL
4+
# @param boolean pendingRegistration [default == false]
5+
# @param integer sessionExpiration [default == 0]
6+
# @param string facebookExtraPermissions [optional] rsvp_event,sms
7+
# @param boolean authCodeOnly [default == false]
8+
# @param string callback [optional]
9+
# @param string cid [optional]
10+
# @param string context [optional]
11+
#}
12+
13+
{% set apiKey = gigya_socializer.apiKey %}
14+
{% set namespace = gigya_socializer.namespace %}
15+
{% set loginFunctionName = gigya_socializer.loginFunctionName %}
16+
17+
<script type="text/javascript">
18+
{% if namespace != 'window' %}
19+
if ({{ namespace }} == null || typeof({{ namespace }}) != 'object') { var {{ namespace }} = window.{{ namespace }} = {}; }
20+
{% endif %}
21+
22+
{{ loginFunctionName }} = function() {
23+
if (typeof gigya != 'undefined') {
24+
if (typeof console != 'undefined') console.log('Gigya:\n-- {{ loginFunctionName }} executed and source library already instantiated');
25+
26+
var conf = {
27+
APIKey: '{{ apiKey }}'
28+
};
29+
30+
// Parameters for the showLoginUI method
31+
var params = {
32+
containerID: '{{ containerID }}' // The container for the component
33+
{% if redirectURL %}
34+
,redirectURL: '{{ redirectURL }}' //
35+
{% endif %}
36+
,height: {{ height | escape('js') }}
37+
,width: {{ width | escape('js') }}
38+
{% if showTermsLink %}
39+
,showTermsLink: {{ showTermsLink }} // remove 'Terms' link
40+
{% else %}
41+
,showTermsLink: false // remove 'Terms' link
42+
{% endif %}
43+
{% if hideGigyaLink %}
44+
,hideGigyaLink: {{ hideGigyaLink }} // remove 'Gigya' link
45+
{% else %}
46+
,hideGigyaLink: true // remove 'Gigya' link
47+
{% endif %}
48+
{% if not buttonsStyle %}
49+
,buttonsStyle: 'standard' // Change the default buttons design to "Full Logos" design
50+
{% else %}
51+
,buttonsStyle: '{{ buttonsStyle }}' // Change the default buttons design to "Full Logos" design
52+
{% endif %}
53+
{% if showWhatsThis %}
54+
,showWhatsThis: {{ showWhatsThis }} // Pop-up a hint describing the Login Plugin, when the user rolls over the Gigya link.
55+
{% else %}
56+
,showWhatsThis: true // Pop-up a hint describing the Login Plugin, when the user rolls over the Gigya link.
57+
{% endif %}
58+
{% if cid %}
59+
,cid: '{{ cid }}'
60+
{% else %}
61+
,cid: ''
62+
{% endif %}
63+
};
64+
65+
// Show the "login" widget
66+
gigya.services.socialize.login(conf, params);
67+
} else {
68+
if (typeof console != 'undefined') console.log("Gigya:\n-- typeof gigya == "+typeof gigya+"\n-- Reattempting instantiation in 100 milliseconds");
69+
setTimeout(function(){
70+
{{ loginFunctionName }}();
71+
},100);
72+
}
73+
}
74+
75+
{{ loginFunctionName }}();
76+
</script>
77+
78+
{# TODO Support other javascript libraries #}
79+
{% if library == 'jquery' %}
80+
{% include "GigyaBundle:Socializer:login_handlers_jquery.html.twig" with { 'onLoginHandler': onLoginHandler, 'onLogoutHandler': onLogoutHandler, 'onLogoutParams': onLogoutParams} %}
81+
{% else %}
82+
{% include "GigyaBundle:Socializer:login_handlers_jquery.html.twig" with { 'onLoginHandler': onLoginHandler, 'onLogoutHandler': onLogoutHandler, 'onLogoutParams': onLogoutParams} %}
83+
{% endif %}

Resources/views/Socializer/login_popup.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
{% set apiKey = gigya_socializer.apiKey %}
1818
{% set namespace = gigya_socializer.namespace %}
19-
{% set loginFunctionName = gigya_socializer.loginFunctionName %}
19+
{% set loginFunctionName = gigya_socializer.loginFunctionUiName %}
2020

2121
<script type="text/javascript">
2222
{% if namespace != 'window' %}

Socializer/Socializer.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ class Socializer
1919
);
2020

2121
private $apiKey;
22+
private $providers = array();
2223
private $userActions = array();
2324
private $client;
2425
private $factory;
2526

26-
public function __construct($apiKey, ClientInterface $client, MessageFactory $factory)
27+
public function __construct($apiKey, array $providers = array(), ClientInterface $client, MessageFactory $factory)
2728
{
2829
$this->apiKey = (string) $apiKey;
30+
$this->providers = $providers;
2931
$this->client = $client;
3032
$this->factory = $factory;
3133
}
@@ -47,6 +49,14 @@ public function getApiKey()
4749
return $this->apiKey;
4850
}
4951

52+
/**
53+
* @return array $providers
54+
*/
55+
public function getProviders()
56+
{
57+
return $this->providers;
58+
}
59+
5060
/**
5161
* @param string $key
5262
* @return boolean $hasUserActionByKey

Tests/Socializer/SocializerTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,24 @@ class SocializerTest extends \PHPUnit_Framework_TestCase
1111
{
1212
private $socializer;
1313
private $apiKey;
14+
private $providers;
1415
private $client;
1516
private $factory;
1617

1718
public function setUp()
1819
{
1920
parent::setup();
2021
$this->apiKey = 'xxxx';
22+
$this->providers = array(1, 2, 3);
2123
$this->client = $this->getMockClient();
2224
$this->factory = $this->getMockMessageFactory();
23-
$this->socializer = new Socializer($this->apiKey, $this->client, $this->factory);
25+
$this->socializer = new Socializer($this->apiKey, $this->providers, $this->client, $this->factory);
2426
}
2527

2628
public function testConstructor()
2729
{
2830
$this->assertEquals($this->apiKey, $this->socializer->getApiKey());
31+
$this->assertEquals($this->providers, $this->socializer->getProviders());
2932
}
3033

3134
public function testHasSetGetUserActionByKey()

0 commit comments

Comments
 (0)