/**
  * login() method return succeeded HTML message of connector
  *
  * @param $sData
  * @return string
  */
 protected function login($sData = '')
 {
     $sLink = '';
     // get back URI
     $sBackURI = self::$oSession->get('back');
     if (!empty($sBackURI)) {
         $sLink = urldecode($sBackURI);
     } else {
         if (version_compare(_PS_VERSION_, '1.4', '>')) {
             $sLink = BT_FPCModuleTools::getAccountPageLink();
         } else {
             global $smarty;
             $sLink = $smarty->_tpl_vars['base_dir_ssl'] . 'my-account.php';
         }
     }
     if (!empty($sData)) {
         $sLink .= (strstr($sLink, '?') ? '&' : '?') . 'data=' . $sData;
     }
     // detect user agent to redirect or close the popup windows and reload the current page
     if (!empty($_SERVER['HTTP_USER_AGENT']) && (stristr($_SERVER['HTTP_USER_AGENT'], 'iphone') || stristr($_SERVER['HTTP_USER_AGENT'], 'mobile'))) {
         header("Location: " . $sLink);
         exit(0);
     } else {
         return '<script>' . '     window.opener.location.href = "' . $sLink . '";' . '     window.opener.focus();' . '     window.close();' . '</script>';
     }
 }
Exemplo n.º 2
0
 /**
  * run() method detect warnings and display them
  */
 public function run($sType, $mValue, array $aParams = array(), $bStop = false)
 {
     $bWarning = false;
     switch ($sType) {
         case 'configuration':
             if (!Configuration::get($mValue)) {
                 $bWarning = true;
             }
             break;
         case 'directive':
             if (!ini_get($mValue)) {
                 $bWarning = true;
             }
             break;
         case 'module':
             // get module's vars to check
             $aModuleVars = !empty($aParams['vars']) && is_array($aParams['vars']) ? $aParams['vars'] : array();
             // if only activated
             $bActivatedOnly = !empty($aParams['installed']) ? $aParams['installed'] : false;
             if (!BT_FPCModuleTools::isInstalled($mValue, $aModuleVars, false, $bActivatedOnly)) {
                 $bWarning = true;
             }
             break;
         case 'function':
             if (!function_exists($mValue)) {
                 $bWarning = true;
             }
             break;
         case 'callback':
             $mReturn = call_user_func_array($mValue, array($aParams));
             if ($mReturn) {
                 $bWarning = true;
             }
             break;
         case 'file-permission':
             // use case - check file permission
             if (!is_writable($mValue)) {
                 $bWarning = true;
             }
             break;
         default:
             $bWarning = false;
             break;
     }
     if ($bWarning && $bStop) {
         $this->bStopExecution = true;
     }
     return $bWarning;
 }
 /**
  * run() method execute hook
  *
  * @param array $aParams
  * @return array
  */
 public function run(array $aParams)
 {
     $aAssign = array();
     try {
         // get connector
         $oConnector = BT_BaseConnector::get($this->_sConnectorType, $aParams);
         // first connection
         if (empty($aParams['activecallback'])) {
             $mContent = $oConnector->connect();
         } else {
             // exec callback for some connectors which need to use redirection and callback
             $mContent = $oConnector->callback($aParams);
         }
         $aAssign['content'] = $mContent;
     } catch (BT_ConnectorException $e) {
         $aAssign['aErrors'][] = array('msg' => $e->getMessage(), 'code' => $e->getCode());
         $aAssign['sErrorInclude'] = BT_FPCModuleTools::getTemplatePath(_FPC_PATH_TPL_NAME . _FPC_TPL_ERROR);
     }
     return $aAssign;
 }
Exemplo n.º 4
0
 /**
  * _updateBasic() method update basic settings
  *
  * @param array $aPost
  * @return array
  */
 private function _updateBasic(array $aPost)
 {
     // clean headers
     @ob_end_clean();
     // set
     $aUpdate = array();
     try {
         // use case - check display fancy popin for asking to associate FB account with PS
         $bDisplayAskFbPopin = Tools::getIsset(strtolower(_FPC_MODULE_NAME) . 'DisplayFbPopin') && Tools::getValue(strtolower(_FPC_MODULE_NAME) . 'DisplayFbPopin') == 'true' ? true : false;
         if (!Configuration::updateValue(_FPC_MODULE_NAME . '_DISPLAY_FB_POPIN', $bDisplayAskFbPopin)) {
             throw new Exception(FacebookPsConnect::$oModule->l('An error occurred during FB association popin update', 'admin-update_class') . '.', 110);
         }
         // use case - check display block
         $bDisplayBlock = Tools::getIsset(strtolower(_FPC_MODULE_NAME) . 'DisplayBlock') && Tools::getValue(strtolower(_FPC_MODULE_NAME) . 'DisplayBlock') == 'true' ? true : false;
         if (!Configuration::updateValue(_FPC_MODULE_NAME . '_DISPLAY_BLOCK', $bDisplayBlock)) {
             throw new Exception(FacebookPsConnect::$oModule->l('An error occurred during block display update', 'admin-update_class') . '.', 111);
         }
         // use case - check display account information block
         $bDisplayBlockInfoAccount = Tools::getIsset(strtolower(_FPC_MODULE_NAME) . 'DisplayBlockInfoAccount') && Tools::getValue(strtolower(_FPC_MODULE_NAME) . 'DisplayBlockInfoAccount') == 'true' ? true : false;
         if (!Configuration::updateValue(_FPC_MODULE_NAME . '_DISPLAY_BLOCK_INFO_ACCOUNT', $bDisplayBlockInfoAccount)) {
             throw new Exception(FacebookPsConnect::$oModule->l('An error occurred during block display update', 'admin-update_class') . '.', 112);
         }
         // use case - check display cart information block
         $bDisplayBlockInfoCart = Tools::getIsset(strtolower(_FPC_MODULE_NAME) . 'DisplayBlockInfoCart') && Tools::getValue(strtolower(_FPC_MODULE_NAME) . 'DisplayBlockInfoCart') == 'true' ? true : false;
         if (!Configuration::updateValue(_FPC_MODULE_NAME . '_DISPLAY_BLOCK_INFO_CART', $bDisplayBlockInfoCart)) {
             throw new Exception(FacebookPsConnect::$oModule->l('An error occurred during block display update', 'admin-update_class') . '.', 113);
         }
         // use case - set  default customer group
         if (Tools::getIsset(strtolower(_FPC_MODULE_NAME) . 'DefaultGroup')) {
             $iDefaultCustGroup = Tools::getValue(strtolower(_FPC_MODULE_NAME) . 'DefaultGroup');
             if (is_numeric($iDefaultCustGroup)) {
                 if (!Configuration::updateValue(_FPC_MODULE_NAME . '_DEFAULT_CUSTOMER_GROUP', $iDefaultCustGroup)) {
                     throw new Exception(FacebookPsConnect::$oModule->l('An error occurred during default customer group update', 'admin-update_class') . '.', 114);
                 }
             } else {
                 throw new Exception(FacebookPsConnect::$oModule->l('Default customer group is not a numeric', 'admin-update_class') . '.', 115);
             }
         }
         // use case - set  default API request method
         if (Tools::getIsset(strtolower(_FPC_MODULE_NAME) . 'ApiRequestType')) {
             $iDefaultApiMethod = Tools::getValue(strtolower(_FPC_MODULE_NAME) . 'ApiRequestType');
             if (!empty($iDefaultApiMethod)) {
                 if (!Configuration::updateValue(_FPC_MODULE_NAME . '_API_REQUEST_METHOD', $iDefaultApiMethod)) {
                     throw new Exception(FacebookPsConnect::$oModule->l('An error occurred during default API request method update', 'admin-update_class') . '.', 116);
                 }
             }
         }
         // use case - if OPC activate, update block's text below connectors' button
         if (Tools::getIsset(strtolower(_FPC_MODULE_NAME) . 'DisplayBlockInfoCart')) {
             $bDisplayBlockOpc = Tools::getValue(strtolower(_FPC_MODULE_NAME) . 'DisplayBlockInfoCart') == 'true' ? true : false;
             if (!Configuration::updateValue(_FPC_MODULE_NAME . '_DISPLAY_BLOCK_INFO_CART', $bDisplayBlockOpc)) {
                 throw new Exception(FacebookPsConnect::$oModule->l('An error occurred during display block cart update', 'admin-update_class') . '.', 117);
             }
         }
     } catch (Exception $e) {
         $aUpdate['aErrors'][] = array('msg' => $e->getMessage(), 'code' => $e->getCode());
     }
     // get configuration options
     BT_FPCModuleTools::getConfiguration();
     // require admin configure class - to factorise
     require_once _FPC_PATH_LIB_ADMIN . 'admin-display_class.php';
     // get run of admin display in order to display first page of admin with basic settings updated
     $aData = BT_AdminDisplay::create()->run(array('sType' => 'basic'));
     // use case - empty error and updating status
     $aData['assign'] = array_merge($aData['assign'], array('iActiveTab' => 1, 'bUpdate' => empty($aUpdate['aErrors']) ? true : false), $aUpdate);
     // destruct
     unset($aUpdate);
     return $aData;
 }
 /**
  * callback() method check exchanged code and connect the customer
  *
  * @params array $aParams
  */
 public function callback(array $aParams = null)
 {
     if (!empty($aParams['state']) && self::$oSession->get('state') == $aParams['state'] && !empty($aParams['code'])) {
         // get oauth_token
         $sResponse = BT_FPCModuleTools::fileGetContent($this->sGraphUrl . '&code=' . $aParams['code']);
         if (!empty($sResponse)) {
             // set params
             $aQUERY = array();
             // parse URI
             parse_str($sResponse, $aQUERY);
             if (!empty($aQUERY['access_token'])) {
                 // set session
                 self::$oSession->set('access_token', $aQUERY['access_token']);
                 return $this->connect(array('code' => $aParams['code'], 'access_token' => $aQUERY['access_token']));
             }
         } else {
             throw new BT_FacebookException(FacebookPsConnect::$oModule->l('Internal server error. Facebook access token is empty or the connect method to the Facebook URL with HTTPS is not allowed. Please contact the merchant to warn him', 'facebook-connect_class'), 523);
         }
     } else {
         throw new BT_FacebookException(FacebookPsConnect::$oModule->l('The state doesn\'t match. You may be a victim of cross-site request forgery or you decided to cancel your connect processing. Please close this window', 'facebook-connector_class'), 524);
     }
 }
Exemplo n.º 6
0
 /**
  * displayErrorModule() method displays view with error
  *
  * @param string $sTplName
  * @param array $aAssign
  * @return string html
  */
 public function displayErrorModule()
 {
     global $smarty;
     $smarty->assign(array('sHomeURI' => BT_FPCModuleTools::truncateUri(), 'aErrors' => $this->aErrors, 'sModuleName' => strtolower(_FPC_MODULE_NAME), 'bDebug' => _FPC_DEBUG));
     return $this->display(__FILE__, _FPC_PATH_TPL_NAME . _FPC_TPL_ERROR);
 }
Exemplo n.º 7
0
 /**
  * _displayAccount() method displays fancybox if customer do not use a social connector to link his PS account
  *
  * @category hook collection
  * @uses
  *
  * @param array $aParams
  * @return array
  */
 private function _displayAccount()
 {
     $aAssign = array('iCustomerId' => $this->iCustomerLogged, 'bUseJqueryUI' => true);
     $aAssign['bDisplay'] = false;
     // if one of connectors is active at least
     if (self::$bConnectorsActive) {
         require_once _FPC_PATH_LIB . 'module-dao_class.php';
         // include abstract connector
         require_once _FPC_PATH_LIB_CONNECTOR . 'base-connector_class.php';
         if (FacebookPsConnect::$aConfiguration[_FPC_MODULE_NAME . '_DISPLAY_FB_POPIN'] && !empty($GLOBALS[_FPC_MODULE_NAME . '_CONNECTORS']['facebook']['data']['activeConnector'])) {
             // set
             $bSocialCustomerExist = false;
             // loop on each connector to check if social account already exists - if not, display FB popin account association
             foreach ($GLOBALS[_FPC_MODULE_NAME . '_CONNECTORS'] as $sName => $aConnector) {
                 if (!empty($GLOBALS[_FPC_MODULE_NAME . '_CONNECTORS'][$sName]['data'])) {
                     // get connector options
                     $aParams = $GLOBALS[_FPC_MODULE_NAME . '_CONNECTORS'][$sName]['data'];
                     // get connector
                     $oConnector = BT_BaseConnector::get($sName, $aParams);
                     // check if customer is already logged from FB connector
                     if ($oConnector->existSocialAccount($aAssign['iCustomerId'], 'ps')) {
                         $bSocialCustomerExist = true;
                     }
                     unset($oConnector);
                 }
             }
             if (!BT_FPCModuleDao::existCustomerAssociationStatus(FacebookPsConnect::$iShopId, $this->iCustomerLogged) && empty($bSocialCustomerExist)) {
                 $aAssign['bDisplay'] = true;
                 $aAssign['bSocialCustomerExist'] = true;
                 $aAssign['sConnectorButtonFacebook'] = BT_FPCModuleTools::getTemplatePath(_FPC_PATH_TPL_NAME . _FPC_TPL_HOOK_PATH . _FPC_TPL_BUTTON_FB);
                 $aAssign['sModuleURI'] = $this->sModuleURI;
                 $aAssign['bFriendlyPermission'] = $GLOBALS[_FPC_MODULE_NAME . '_CONNECTORS']['facebook']['data']['permissions'];
                 $aAssign['sBackUri'] = self::$sCurrentURI;
             }
         }
         // get connector options
         $aParams = $GLOBALS[_FPC_MODULE_NAME . '_CONNECTORS']['twitter']['data'];
         // test if twitter is already configured
         if (!empty($aParams)) {
             // get connector
             $oConnector = BT_BaseConnector::get('twitter', $aParams);
             // check if customer is already logged from FB connector
             if ($oConnector->existSocialAccount($aAssign['iCustomerId'], 'ps') && strstr(FacebookPsConnect::$oCookie->email, 'twitter.com')) {
                 $aAssign['iCustomerId'] = md5(_FPC_MODULE_NAME . 'twitter' . $aAssign['iCustomerId']);
                 $aAssign['sConnector'] = 'twitter';
                 $aAssign['bTwitterCustomerExist'] = true;
                 $aAssign['bDisplay'] = true;
             }
             unset($oConnector);
         }
         // use case - data sent for collecting
         $sRequestData = Tools::getValue('data');
         if (!empty($sRequestData)) {
             $aRequestData = unserialize(gzuncompress(urldecode(base64_decode($sRequestData))));
             if (!empty($aRequestData)) {
                 if (empty($aRequestData['ci'])) {
                     $aRequestData['ci'] = md5('collect' . FacebookPsConnect::$oCookie->id_customer);
                     if (!empty($aRequestData['cn']) && !empty($aRequestData['ca']) && !empty($aRequestData['ct']) && !empty($aRequestData['oi'])) {
                         // execute social collect method
                         $sReturn = FacebookPsConnect::$oModule->HookSocialCollector(base64_decode($aRequestData['cn']), $aRequestData);
                         if (!empty($sReturn)) {
                             // get collect data array
                             $oResponse = BT_FPCModuleTools::jsonDecode($sReturn);
                             if (!empty($oResponse->status)) {
                                 $aAssign['bCustomerCollect'] = true;
                             }
                         }
                     }
                 }
             }
         }
     }
     $aAssign['sModuleURI'] = _FPC_MODULE_URL . 'ws-' . _FPC_MODULE_SET_NAME . '.php';
     return array('tpl' => _FPC_TPL_HOOK_PATH . _FPC_TPL_CONNECTOR_ACCOUNT, 'assign' => $aAssign);
 }
 /**
  * _displaySystemHealth() method displays system health information
  *
  * @param array $aPost
  * @return array
  */
 private function _displaySystemHealth(array $aPost)
 {
     $aAssign = array();
     $aAssign['iCurrentLang'] = intval(FacebookPsConnect::$iCurrentLang);
     // set
     $sIsoCode = FacebookPsConnect::$sCurrentLang;
     if ($sIsoCode !== 'fr') {
         $sIsoCode = 'en';
     }
     $aModules = array('facebookpsshoptab' => array('active' => true, 'min' => '3.3.2', 'name' => 'Facebook Ps Shop Tab', 'img' => _FPC_URL_IMG . 'admin/fb-ps-shop-tab.jpg', 'addons' => 'http://addons.prestashop.com/' . $sIsoCode . '/social-commerce-facebook-prestashop-modules/1048-facebook-ps-shop-tab.html'), 'facebookpsessentials' => array('active' => true, 'min' => '2.3.0', 'name' => 'Facebook Ps Essentials', 'img' => _FPC_URL_IMG . 'admin/fb-ps-essentials.jpg', 'addons' => 'http://addons.prestashop.com/' . $sIsoCode . '/social-commerce-facebook-prestashop-modules/5025-facebook-ps-essentials-facebook-like-twitter-etc.html'));
     unset($sIsoCode);
     foreach ($aModules as $sName => $aModule) {
         $aParams = $aModule;
         if (($oModule = BT_FPCModuleTools::isInstalled($sName, array(), true)) !== false) {
             // installed ok + min version
             $aParams['installed'] = true;
             $aParams['minVersion'] = version_compare($oModule->version, $aModule['min'], '>=') ? true : false;
         } else {
             $aParams['installed'] = false;
         }
         $aAssign['aModules'][$sName] = $aParams;
     }
     return array('tpl' => _FPC_TPL_ADMIN_PATH . _FPC_TPL_SYS_HEALTH_SETTINGS, 'assign' => $aAssign);
 }
Exemplo n.º 9
0
 /**
  * _updateEmail() method update customer email
  *
  * @param array $aParams
  * @return bool
  */
 private function _updateEmail(array $aParams)
 {
     $aAssign = array();
     if (version_compare(_PS_VERSION_, '1.4', '>')) {
         $oLink = new Link();
         $sLink = $oLink->getPageLink('my-account.php');
         unset($oLink);
     } else {
         global $smarty;
         $sLink = $smarty->_tpl_vars['base_dir_ssl'] . 'my-account.php';
     }
     $aAssign['sLink'] = $sLink;
     // get serialized connector data
     BT_FPCModuleTools::getConnectorData();
     // check if customer is the same customer connected and if the e-mail is valid
     if (!empty($aParams['connector']) && !empty($GLOBALS[_FPC_MODULE_NAME . '_CONNECTORS'][$aParams['connector']]['data']['activeConnector']) && !empty($aParams['customerId']) && $aParams['customerId'] === md5(_FPC_MODULE_NAME . $aParams['connector'] . FacebookPsConnect::$oCookie->id_customer) && !empty($aParams['customerId']) && filter_var($aParams['socialEmail'], FILTER_VALIDATE_EMAIL) !== false) {
         // include
         require_once _FPC_PATH_LIB . 'module-dao_class.php';
         require_once _FPC_PATH_LIB . 'mail-send_class.php';
         // check if exists and return id customer if exists
         $iCustomerId = BT_FPCModuleDao::existCustomerEmail($aParams['socialEmail']);
         // if customer not exists
         if (empty($iCustomerId)) {
             if (BT_FPCModuleDao::updateCustomerEmail(FacebookPsConnect::$oCookie->id_customer, $aParams['socialEmail'])) {
                 $aAssign['sMsg'] = FacebookPsConnect::$oModule->l('Your information has been updated', 'hook-action_class');
                 // set the new e-mail in cookie
                 if (version_compare(_PS_VERSION_, '1.5', '>')) {
                     Context::getContext()->cookie->email = $aParams['socialEmail'];
                 } else {
                     global $cookie;
                     $cookie->email = $aParams['socialEmail'];
                 }
             } else {
                 $aAssign['aErrors'][] = array('msg' => FacebookPsConnect::$oModule->l('Internal server error. The customer e-mail has not been updated. Please try again by clicking on reload button below', 'hook-action_class') . '.', 'code' => 590);
             }
             // manage the update firstname and name for twitter connexion
             BT_FPCModuleDao::updateCustomerFirstName(FacebookPsConnect::$oCookie->id_customer, $aParams['socialFirstName']);
             BT_FPCModuleDao::updateCustomerName(FacebookPsConnect::$oCookie->id_customer, $aParams['socialName']);
             BT_FPCModuleDao::updateCustomerPassword(FacebookPsConnect::$oCookie->id_customer, $aParams['socialPassword']);
             BT_FpcMailSend::_updateEmailTwitter($aParams['socialFirstName'], $aParams['socialName'], $aParams['socialEmail'], $aParams['socialPassword'], FacebookPsConnect::$iCurrentLang, FacebookPsConnect::$iShopId);
         } else {
             $aAssign['aErrors'][] = array('msg' => FacebookPsConnect::$oModule->l('This e-mail address is already taken by a customer account or you already have linked this e-mail address with another network. Please try again by clicking on reload button below', 'hook-action_class') . '.', 'code' => 591);
         }
     } else {
         $aAssign['aErrors'][] = array('msg' => FacebookPsConnect::$oModule->l('Internal server error. The customer could not be identified. You may be a victim of cross-site request forgery', 'hook-action_class') . '.', 'code' => 592);
     }
     if (empty($aAssign['aErrors'])) {
         $sTpl = _FPC_TPL_CONFIRM;
     } else {
         $sTpl = _FPC_TPL_ERROR;
     }
     return array('tpl' => $sTpl, 'assign' => $aAssign);
 }
Exemplo n.º 10
0
 /**
  * getProfile() method returns the customer's profile
  *
  *
  * @param array $aToken
  * @return array
  */
 public function getProfile(array $aToken)
 {
     $sProfileUrl = sprintf("%s?schema=openid&access_token=%s", "https://api.paypal.com/v1/identity/openidconnect/userinfo/", $aToken['access_token']);
     return BT_FPCModuleTools::jsonDecode($this->runCurl($sProfileUrl));
 }