<?xml version="1.0" encoding="utf-8"?>
<modification>
    <name>So Social Login</name>
    <code>So-Social-Login</code>
    <version>1.1.3</version>
    <author>Opencartworks</author>
    <link>http://www.opencartworks.com/</link>
        
    <file path="catalog/view/theme/*/template/account/login.twig">
        <operation error="log">
            <search ><![CDATA[<div class="well">]]></search>
            <add position="replace"><![CDATA[
                <div class="well col-sm-12">    
            ]]></add>
        </operation>
        
        <operation error="log">
            <search ><![CDATA[<input type="submit" value="{{ button_login }}" class="btn btn-primary" />]]></search>
            <add position="replace"><![CDATA[
                <input type="submit" value="{{ button_login }}" class="btn btn-primary pull-left" />  
            ]]></add>
        </operation>
        
        <operation error="log">
            <search ><![CDATA[</form>]]></search>
            <add position="after"><![CDATA[
                {% if setting is defined and setting.so_sociallogin_enable %}
                    <column id="column-login" class="col-sm-8 pull-right">
                        <div class="row">
                            {% if warning is defined %}
                                <div class="alert alert-warning"><i class="fa fa-check-circle"></i> {{ warning }}</div>
                            {% endif %}
                          
                            <div class="social_login pull-right" id="so_sociallogin">
                                {% if setting.so_sociallogin_fbstatus %}
                                    {% if setting.so_sociallogin_button == 'image' %}
                                        <a class="social-icon"  href="{{ fblink }}">
                                            <img class="img-responsive" src="{{ fbimage }}" 
                                                data-toggle="tooltip" alt="{{ setting.so_sociallogin_fbtitle }}" 
                                                title="{{ setting.so_sociallogin_fbtitle }}"
                                            />
                                        </a>
                                    {% else %}
                                        <a href="{{ fblink }}" class="btn btn-social-icon btn-sm btn-facebook"><i class="fa fa-facebook fa-fw" aria-hidden="true"></i></a>
                                    {% endif %}
                                {% endif %}
                                
                                {% if setting.so_sociallogin_twitstatus %}
                                    {% if setting.so_sociallogin_button == 'image' %}
                                        <a class="social-icon"  href="{{ twitlink }}">
                                            <img class="img-responsive" src="{{ twitimage }}" 
                                                data-toggle="tooltip" alt="{{ setting.so_sociallogin_twittertitle }}" 
                                                title="{{ setting.so_sociallogin_twittertitle }}"
                                            />
                                        </a>
                                    {% else %}
                                        <a href="{{ twitlink }}" class="btn btn-social-icon btn-sm btn-twitter"><i class="fa fa-twitter fa-fw" aria-hidden="true"></i></a>
                                    {% endif %}
                                {% endif %}
                                
                                {% if setting.so_sociallogin_googlestatus %}
                                    {% if setting.so_sociallogin_button == 'image' %}
                                        <a class="social-icon" href="{{ googlelink }}">
                                            <img class="img-responsive" src="{{ googleimage }}" 
                                                data-toggle="tooltip" alt="{{ setting.so_sociallogin_googletitle }}" 
                                                title="{{ setting.so_sociallogin_googletitle }}" 
                                            />
                                        </a>
                                    {% else %}
                                        <a href="{{ googlelink }}" class="btn btn-social-icon btn-sm btn-google-plus"><i class="fa fa-google fa-fw" aria-hidden="true"></i></a>
                                    {% endif %}
                                {% endif %}
                                
                                {% if setting.so_sociallogin_linkstatus %}
                                    {% if setting.so_sociallogin_button == 'image' %}
                                        <a class="social-icon" href="{{ linkdinlink }}">
                                            <img class="img-responsive" src="{{ linkdinimage }}" 
                                                data-toggle="tooltip" alt="{{ setting.so_sociallogin_linkedintitle }}" 
                                                title="{{ setting.so_sociallogin_linkedintitle }}"
                                            />
                                        </a>
                                    {% else %}
                                        <a href="{{ linkdinlink }}" class="btn btn-social-icon btn-sm btn-linkdin"><i class="fa fa-linkedin fa-fw" aria-hidden="true"></i></a>
                                    {% endif %}
                                {% endif %}
                            </div>
                        </div>
                    </column>
                {% endif %}
            ]]></add>
        </operation>
        
        <operation error="log">
            <search ><![CDATA[{{ footer }}]]></search>
            <add position="before"><![CDATA[
                <style>
                @media(max-width:991px){
                    #column-login,.social_login,.socalicon{
                        float:none !important;
                        width:100%;
                    }
                    .account-login .btn-primary{
                        float:none !important;
                    }
                    .social_login {
                        padding:0 10px;
                    }
                }
                </style>
            ]]></add>
        </operation>
    </file>
    
    <file path="catalog/controller/account/login.php">
        <operation error="log">
            <search ><![CDATA[$data['header'] = $this->load->controller('common/header');]]></search>
            <add position="after"><![CDATA[
                /* xml */
                $this->load->model('setting/setting');
                $this->load->model('tool/image');
                $setting = $this->model_setting_setting->getSetting('so_sociallogin');
                if (isset($setting['so_sociallogin_enable']) && $setting['so_sociallogin_enable'] && $this->config->get('so_sociallogin_enable')) {
                    if(isset($this->session->data['route']))
                    {
                        $location = $this->url->link($this->session->data['route'], "", 'SSL');
                    }
                    else
                    {
                        $location = $this->url->link("account/account", "", 'SSL');
                    }
                    
                    /* Facebook Library */
                    require_once (DIR_SYSTEM.'library/so_social/Facebook/autoload.php');
                    
                    /* Facebook  Login link code */
                    $fb = new Facebook\Facebook ([
                        'app_id'                    => $setting['so_sociallogin_fbapikey'], 
                        'app_secret'                => $setting['so_sociallogin_fbsecretapi'],
                        'default_graph_version'     => 'v2.4',
                    ]);

                    $helper = $fb->getRedirectLoginHelper();

                    /*
                    try {
                        $accessToken = $helper->getAccessToken();
                    } catch(Facebook\Exceptions\FacebookResponseException $e) {
                        // When Graph returns an error
                        echo 'Graph returned an error: ' . $e->getMessage();
                        exit;
                    } catch(Facebook\Exceptions\FacebookSDKException $e) {
                        // When validation fails or other local issues
                        echo 'Facebook SDK returned an error: ' . $e->getMessage();
                        exit;
                    }
                    */    
                    
                    $data['fblink'] = $helper->getLoginUrl($this->url->link('extension/module/so_sociallogin/FacebookLogin', '', 'SSL'), array('public_profile','email'));
                    /* Facebook  Login link code */
            
                    /* Google Libery file inculde */
                    require_once DIR_SYSTEM.'library/so_social/src/Google_Client.php';
                    require_once DIR_SYSTEM.'library/so_social/src/contrib/Google_Oauth2Service.php';
                    
                    /* Google Login link code */
                    $gClient = new Google_Client();
                    $gClient->setApplicationName($setting['so_sociallogin_googletitle']);
                    $gClient->setClientId($setting['so_sociallogin_googleapikey']);
                    $gClient->setClientSecret($setting['so_sociallogin_googlesecretapi']);
                    $gClient->setRedirectUri($this->url->link('extension/module/so_sociallogin/GoogleLogin', '', 'SSL'));
                    $google_oauthV2 = new Google_Oauth2Service($gClient);
                    $data['googlelink']  = $gClient->createAuthUrl();
                    
                    /* Twitter Login */                     
                    $data['twitlink'] =  $this->url->link('extension/module/so_sociallogin/TwitterLogin', '', 'SSL');
                    
                    /* Linkedin Login */
                    $data['linkdinlink'] = $this->url->link('extension/module/so_sociallogin/LinkedinLogin', '', 'SSL');
                    
                    /* Get Image */
                    $sociallogin_width = 130;
                    $sociallogin_height = 35;
                    if (isset($setting['so_sociallogin_width']) && is_numeric($setting['so_sociallogin_width'])) {
                        $sociallogin_width = $setting['so_sociallogin_width'];
                    }
                    if (isset($setting['so_sociallogin_height']) && is_numeric($setting['so_sociallogin_height'])) {
                        $sociallogin_height = $setting['so_sociallogin_height'];
                    }
                    if ($setting['so_sociallogin_fbimage']) {
                        $fbicon = $this->model_tool_image->resize($setting['so_sociallogin_fbimage'], $sociallogin_width, $sociallogin_height);
                    } else {
                        $fbicon = $this->model_tool_image->resize('placeholder.png', $sociallogin_width, $sociallogin_height);
                    }
                        
                    if ($setting['so_sociallogin_twitimage']) {
                        $twiticon = $this->model_tool_image->resize($setting['so_sociallogin_twitimage'], $sociallogin_width, $sociallogin_height);
                    } else {
                        $twiticon = $this->model_tool_image->resize('placeholder.png', $sociallogin_width, $sociallogin_height);
                    }
                        
                    if ($setting['so_sociallogin_googleimage']) {
                        $googleicon = $this->model_tool_image->resize($setting['so_sociallogin_googleimage'], $sociallogin_width, $sociallogin_height);
                    } else {
                        $googleicon = $this->model_tool_image->resize('placeholder.png', $sociallogin_width, $sociallogin_height);
                    }
                    
                    if ($setting['so_sociallogin_linkdinimage']) {
                        $linkdinicon = $this->model_tool_image->resize($setting['so_sociallogin_linkdinimage'], $sociallogin_width, $sociallogin_height);
                    } else {
                        $linkdinicon = $this->model_tool_image->resize('placeholder.png', $sociallogin_width, $sociallogin_height);
                    }
                    
                    $data['iconwidth']  = $sociallogin_width;
                    $data['iconheight'] = $sociallogin_height;
                    $data['status']     = $setting['so_sociallogin_enable'];
                    $data['fbimage']    = $fbicon;
                    $data['twitimage']  = $twiticon;
                    $data['googleimage'] = $googleicon;
                    $data['linkdinimage'] = $linkdinicon;
                    
                    $data['setting'] = $setting;
                }
                /* xml */   
            ]]></add>
        </operation>
    </file>
    
    <file path="catalog/controller/common/header.php">
        <operation error="log">
            <search ><![CDATA[$data['title'] = $this->document->getTitle();]]></search>
            <add position="after"><![CDATA[
                $this->document->addStyle('catalog/view/javascript/so_sociallogin/css/so_sociallogin.css');
                $this->load->model('setting/setting');
                $this->load->model('tool/image');
                $setting = $this->model_setting_setting->getSetting('so_sociallogin');
                
                if (isset($setting['so_sociallogin_enable']) && $setting['so_sociallogin_enable'] && $this->config->get('so_sociallogin_enable')) {
                    if(isset($this->session->data['route']))
                    {
                        $location = $this->url->link($this->session->data['route'], "", 'SSL');
                    }
                    else
                    {
                        $location = $this->url->link("account/account", "", 'SSL');
                    }
                
                    /* Facebook Library */
                    require_once (DIR_SYSTEM.'library/so_social/Facebook/autoload.php');
                    
                    $fb = new Facebook\Facebook ([
                        'app_id'                    => $setting['so_sociallogin_fbapikey'], 
                        'app_secret'                => $setting['so_sociallogin_fbsecretapi'],
                        'default_graph_version'     => 'v2.4',
                    ]);

                    $helper = $fb->getRedirectLoginHelper();

                    /*
                    try {
                        $accessToken = $helper->getAccessToken();
                    } catch(Facebook\Exceptions\FacebookResponseException $e) {
                        // When Graph returns an error
                        //echo 'Graph returned an error: ' . $e->getMessage();
                        //exit;
                    } catch(Facebook\Exceptions\FacebookSDKException $e) {
                        // When validation fails or other local issues
                        //echo 'Facebook SDK returned an error: ' . $e->getMessage();
                        //exit;
                    }
                    */    
                    
                    $data['fblink'] = $helper->getLoginUrl($this->url->link('extension/module/so_sociallogin/FacebookLogin', '', 'SSL'), array('public_profile','email'));
                    /* Facebook  Login link code */
            
                    /* Google Libery file inculde */
                    require_once DIR_SYSTEM.'library/so_social/src/Google_Client.php';
                    require_once DIR_SYSTEM.'library/so_social/src/contrib/Google_Oauth2Service.php';
                    
                    /* Google Login link code */
                    $gClient = new Google_Client();
                    $gClient->setApplicationName($setting['so_sociallogin_googletitle']);
                    $gClient->setClientId($setting['so_sociallogin_googleapikey']);
                    $gClient->setClientSecret($setting['so_sociallogin_googlesecretapi']);
                    $gClient->setRedirectUri($this->url->link('extension/module/so_sociallogin/GoogleLogin', '', 'SSL'));
                    $google_oauthV2 = new Google_Oauth2Service($gClient);
                    $data['googlelink']  = $gClient->createAuthUrl();
                    
                    /* Twitter Login */                     
                    $data['twitlink'] =  $this->url->link('extension/module/so_sociallogin/TwitterLogin', '', 'SSL');
                    
                    /* Linkedin Login */
                    $data['linkdinlink'] = $this->url->link('extension/module/so_sociallogin/LinkedinLogin', '', 'SSL');
                    
                    /* Get Image */
                    $sociallogin_width = 130;
                    $sociallogin_height = 35;
                    if (isset($setting['so_sociallogin_width']) && is_numeric($setting['so_sociallogin_width'])) {
                        $sociallogin_width = $setting['so_sociallogin_width'];
                    }
                    if (isset($setting['so_sociallogin_height']) && is_numeric($setting['so_sociallogin_height'])) {
                        $sociallogin_height = $setting['so_sociallogin_height'];
                    }
                    if ($setting['so_sociallogin_fbimage']) {
                        $fbicon = $this->model_tool_image->resize($setting['so_sociallogin_fbimage'], $sociallogin_width, $sociallogin_height);
                    } else {
                        $fbicon = $this->model_tool_image->resize('placeholder.png', $sociallogin_width, $sociallogin_height);
                    }
                        
                    if ($setting['so_sociallogin_twitimage']) {
                        $twiticon = $this->model_tool_image->resize($setting['so_sociallogin_twitimage'], $sociallogin_width, $sociallogin_height);
                    } else {
                        $twiticon = $this->model_tool_image->resize('placeholder.png', $sociallogin_width, $sociallogin_height);
                    }
                        
                    if ($setting['so_sociallogin_googleimage']) {
                        $googleicon = $this->model_tool_image->resize($setting['so_sociallogin_googleimage'], $sociallogin_width, $sociallogin_height);
                    } else {
                        $googleicon = $this->model_tool_image->resize('placeholder.png', $sociallogin_width, $sociallogin_height);
                    }
                    
                    if ($setting['so_sociallogin_linkdinimage']) {
                        $linkdinicon = $this->model_tool_image->resize($setting['so_sociallogin_linkdinimage'], $sociallogin_width, $sociallogin_height);
                    } else {
                        $linkdinicon = $this->model_tool_image->resize('placeholder.png', $sociallogin_width, $sociallogin_height);
                    }
                    
                    $data['iconwidth']  = $sociallogin_width;
                    $data['iconheight'] = $sociallogin_height;
                    $data['status']     = $setting['so_sociallogin_enable'];
                    $data['fbimage']    = $fbicon;
                    $data['twitimage']  = $twiticon;
                    $data['googleimage'] = $googleicon;
                    $data['linkdinimage'] = $linkdinicon;
                    
                    $data['setting'] = $setting;
    
                    $this->load->language('extension/module/so_sociallogin');
                    $data['text_colregister']   = $this->language->get('text_colregister');
                    $data['text_create_account']   = $this->language->get('text_create_account');
                    $data['link_forgot_password']   = $this->url->link('account/forgotten', '', true);
                    $data['text_forgot_password']   = $this->language->get('text_forgot_password');
                    $data['text_title_popuplogin']   = $this->language->get('text_title_popuplogin');
                    $data['text_title_login_with_social']   = $this->language->get('text_title_login_with_social');
                }
            ]]></add>
        </operation>
    </file>
    
    <file path="catalog/view/theme/*/template/common/header.twig">
        <operation error="log">
            <search><![CDATA[</header>]]></search>
            <add position="after"><![CDATA[
                {% if setting is defined and setting.so_sociallogin_enable and setting.so_sociallogin_popuplogin %}
                    <div class="modal fade in" id="so_sociallogin" tabindex="-1" role="dialog" aria-labelledby="popupLoginLabel" aria-hidden="true">
                        <div class="modal-dialog block-popup-login">
                            <a href="javascript:void(0)" title="Close" class="close close-login fa fa-times-circle" data-dismiss="modal"></a>
                            <div class="tt_popup_login"><strong>{{ text_title_popuplogin }}</strong></div>
                            <div class="block-content">
                                <div class=" col-reg registered-account">
                                    <div class="block-content">
                                        <form class="form form-login" action="{{ login }}" method="post" id="login-form">
                                            <fieldset class="fieldset login" data-hasrequired="* Required Fields">
                                                <div class="field email required email-input">
                                                    <div class="control">
                                                        <input name="email" value="" autocomplete="off" id="email" type="email" class="input-text" title="Email" placeholder="E-mail Address" />
                                                    </div>
                                                </div>
                                                <div class="field password required pass-input">
                                                    <div class="control">
                                                        <input name="password" type="password" autocomplete="off" class="input-text" id="pass" title="Password" placeholder="Password" />
                                                    </div>
                                                </div>
                                                {% if setting.so_sociallogin_enable %}
                                                <div class=" form-group">
                                                    <label class="control-label">{{ text_title_login_with_social }}</label>
                                                    <div>
                                                        {% if setting.so_sociallogin_googlestatus %}
                                                            {% if setting.so_sociallogin_button == 'icon' %}
                                                                <a href="{{ googlelink }}" class="btn btn-social-icon btn-sm btn-google-plus"><i class="fa fa-google fa-fw" aria-hidden="true"></i></a>
                                                            {% else %}
                                                                <a class="social-icon" href="{{ googlelink }}">
                                                                    <img class="img-responsive" src="{{ googleimage }}" 
                                                                        data-toggle="tooltip" alt="{{ setting.so_sociallogin_googletitle }}" 
                                                                        title="{{ setting.so_sociallogin_googletitle }}" 
                                                                    />
                                                                </a>
                                                            {% endif %}
                                                        {% endif %}
                                                        {% if setting.so_sociallogin_fbstatus %}
                                                            {% if setting.so_sociallogin_button == 'icon' %}
                                                                <a href="{{ fblink }}" class="btn btn-social-icon btn-sm btn-facebook"><i class="fa fa-facebook fa-fw" aria-hidden="true"></i></a>
                                                            {% else %}
                                                                <a href="{{ fblink }}" class="social-icon">
                                                                    <img class="img-responsive" src="{{ fbimage }}" 
                                                                        data-toggle="tooltip" alt="{{ setting.so_sociallogin_fbtitle }}" 
                                                                        title="{{ setting.so_sociallogin_fbtitle }}"
                                                                    />
                                                                </a>
                                                            {% endif %}
                                                        {% endif %}
                                                        {% if setting.so_sociallogin_twitstatus %}
                                                            {% if setting.so_sociallogin_button == 'icon' %}
                                                                <a href="{{ twitlink }}" class="btn btn-social-icon btn-sm btn-twitter"><i class="fa fa-twitter fa-fw" aria-hidden="true"></i></a>
                                                            {% else %}
                                                                <a class="social-icon"  href="{{ twitlink }}">
                                                                    <img class="img-responsive" src="{{ twitimage }}" 
                                                                        data-toggle="tooltip" alt="{{ setting.so_sociallogin_twittertitle }}" 
                                                                        title="{{ setting.so_sociallogin_twittertitle }}"
                                                                    />
                                                                </a>
                                                            {% endif %}
                                                        {% endif %}
                                                        {% if setting.so_sociallogin_linkstatus %}
                                                            {% if setting.so_sociallogin_button == 'icon' %}
                                                                <a href="{{ linkdinlink }}" class="btn btn-social-icon btn-sm btn-linkdin"><i class="fa fa-linkedin fa-fw" aria-hidden="true"></i></a>
                                                            {% else %}
                                                                <a class="social-icon"  href="{{ linkdinlink }}">
                                                                    <img class="img-responsive" src="{{ linkdinimage }}" 
                                                                        data-toggle="tooltip" alt="{{ setting.so_sociallogin_linkedintitle }}" 
                                                                        title="{{ setting.so_sociallogin_linkedintitle }}"
                                                                    />
                                                                </a>
                                                            {% endif %}
                                                        {% endif %}
                                                    </div>
                                                </div>
                                                {% endif %}
                                                <div class="secondary ft-link-p"><a class="action remind" href="{{ link_forgot_password }}"><span>{{ text_forgot_password }}</span></a></div>
                                                <div class="actions-toolbar">
                                                    <div class="primary"><button type="submit" class="action login primary" name="send" id="send2"><span>{{ text_login }}</span></button></div>
                                                </div>
                                            </fieldset>
                                        </form>
                                    </div>
                                </div>      
                                <div class="col-reg login-customer">
                                    {{ text_colregister }}
                                    <a class="btn-reg-popup" title="{{ text_register }}" href="{{ register }}">{{ text_create_account }}</a>
                                </div>
                                <div style="clear:both;"></div>
                            </div>
                        </div>
                    </div>
                    <script type="text/javascript">
                        jQuery(document).ready(function($) {
                            var $window = $(window);
                            function checkWidth() {
                                var windowsize = $window.width();
                                if (windowsize > 767) {
                                    $('a[href*="account/login"]').click(function (e) {
                                        e.preventDefault();
                                        $("#so_sociallogin").modal('show');
                                    });
                                }
                            }
                            checkWidth();
                            $(window).resize(checkWidth);
                        });
                    </script>
                {% endif %}
            ]]></add>
        </operation>
    </file>
</modification>