Browse Source

#251 Facebook Connect module - redirects to different pages

Alex Trofimov 11 năm trước cách đây
mục cha
commit
01f01d16c7

+ 15 - 0
modules/base/connect/classes/BxBaseModConnectAlerts.php

@@ -17,10 +17,25 @@ class BxBaseModConnectAlerts extends BxDolAlertsResponse
     {
         if ($o->sUnit == 'profile') {
             switch ($o->sAction) {
+
                 case 'delete':
                     // remove remote account
                     $this->oModule->_oDb->deleteRemoteAccount($o->iObject);
                     break;
+
+                case 'add':
+                    // add remote account and local profile association
+                    bx_import('BxDolSession');
+                    $oSession = BxDolSession::getInstance();
+
+                    $iRemoteProfileId = $oSession->getValue($this->oModule->_oConfig->sSessionUid);
+                    if ($iRemoteProfileId) {
+                        $oSession->unsetValue($this->oModule->_oConfig->sSessionUid);
+                        $this->oModule->_oDb->saveRemoteId($o->iObject, $iRemoteProfileId);
+                    }
+
+                    break;
+
             }
         }
     }

+ 1 - 1
modules/base/connect/classes/BxBaseModConnectConfig.php

@@ -25,7 +25,7 @@ class BxBaseModConnectConfig extends BxBaseModGeneralConfig
     {
         parent::__construct($aModule);
 
-        $this->sDefaultRedirectUrl = BX_DOL_URL_ROOT . 'member.php';
+        $this->sDefaultRedirectUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=dashboard');
     }
 }
 

+ 12 - 27
modules/base/connect/classes/BxBaseModConnectModule.php

@@ -147,7 +147,7 @@ class BxBaseModConnectModule extends BxDolModule
 
         // check redirect page
         if ('join' == $this->_oConfig->sRedirectPage && !$oExistingAccount)
-            return array('remote_profile_info' => $aProfileInfo, 'profile_fields' => $aProfileFields, 'join_page_redirect' => true);
+            return array('remote_profile_info' => $aProfileInfo, 'profile_fields' => $aFieldsAccount, 'join_page_redirect' => true);
 
         // create new profile
         if ($oExistingAccount) {
@@ -230,19 +230,11 @@ class BxBaseModConnectModule extends BxDolModule
         $oSession = BxDolSession::getInstance();
         $oSession->setValue($this->_oConfig->sSessionUid, $iRemoteProfileId);
 
-        bx_import("BxDolJoinProcessor");
+        $oPage = BxDolPage::getObjectInstanceByURI('create-account');
 
-        $GLOBALS['oSysTemplate']->addJsTranslation('_Errors in join form');
-        $GLOBALS['oSysTemplate']->addJs(array('join.js', 'jquery.form.min.js'));
+        BxBaseAccountForms::$PROFILE_FIELDS = $aProfileFields;
 
-        $oJoin = new BxDolJoinProcessor();
-
-        // process received fields
-        foreach($aProfileFields as $sFieldName => $sValue)
-            $oJoin -> aValues[0][$sFieldName] = $sValue;
-
-        $this->_oTemplate->getPage(_t('_JOIN_H'), $oJoin->process());
-        exit;
+        $this->_oTemplate->getPage($oPage->getCode());
     }
 
     /**
@@ -253,29 +245,22 @@ class BxBaseModConnectModule extends BxDolModule
      */
     function _getRedirectUrl($iProfileId, $isExistingProfile = false)
     {
-        if ($isExistingProfile)
-            return 'index' == $this->_oConfig->sRedirectPage ? BX_DOL_URL_ROOT : BX_DOL_URL_ROOT . 'member.php';
-
         $sRedirectUrl = $this->_oConfig->sDefaultRedirectUrl;
 
         switch($this->_oConfig->sRedirectPage) {
-            case 'join':
-            case 'pedit':
-                $sRedirectUrl = BX_DOL_URL_ROOT . 'pedit.php?ID=' . (int)$iProfileId;
-                break;
-
-            case 'avatar':
-                if(BxDolInstallerUtils::isModuleInstalled('avatar') && BxDolService::call('avatar', 'join', array($iProfileId, '_Join complete')))
-                    exit;
-                break;
-
             case 'index':
                 $sRedirectUrl = BX_DOL_URL_ROOT;
                 break;
 
-            case 'member':
+            case 'settings':
+                if (!$isExistingProfile) { 
+                    $sRedirectUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=account-settings-email');
+                    break;
+                }
+
+            case 'dashboard':
             default:
-                $sRedirectUrl = BX_DOL_URL_ROOT . 'member.php';
+                $sRedirectUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=dashboard');
                 break;
             }
 

+ 7 - 43
modules/base/connect/classes/BxBaseModConnectTemplate.php

@@ -18,52 +18,16 @@ class BxBaseModConnectTemplate extends BxDolModuleTemplate
         parent::__construct($oConfig, $oDb);
     }
 
-    function pageCodeAdminStart()
+    function getPage($sPageContent, $sPageCaption = false)
     {
-        ob_start();
-    }
-
-    function pageCodeAdmin ($sTitle)
-    {
-        global $_page;
-        global $_page_cont;
-
-        $_page['name_index'] = 9;
-
-        $_page['header'] = $sTitle ? $sTitle : $GLOBALS['site']['title'];
-        $_page['header_text'] = $sTitle;
-
-        $_page_cont[$_page['name_index']]['page_main_code'] = ob_get_clean();
-
-        PageCodeAdmin();
-    }
-
-    /**
-     * Function will generate default dolphin's page;
-     *
-     * @param  : $sPageCaption   (string) - page's title;
-     * @param  : $sPageContent   (string) - page's content;
-     * @return : (text) html presentation data;
-     */
-    function getPage($sPageCaption, $sPageContent)
-    {
-        global $_page;
-        global $_page_cont;
-
-        $_page['name_index'] = 0;
-
-        // set module's icon;
-        $GLOBALS['oTopMenu'] -> setCustomSubIconUrl(false === strpos($this->_sPageIcon, '.') ? $this->_sPageIcon : $this -> getIconUrl($this->_sPageIcon));
-        $GLOBALS['oTopMenu'] -> setCustomSubHeader($sPageCaption);
-
-        $_page['header'] = $sPageCaption;
-        $_page['header_text'] = $sPageCaption;
-
-        $_page_cont[0]['page_main_code'] = $sPageContent;
+        $oTemplate = BxDolTemplate::getInstance();
 
-        PageCode($this);
+        $oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
+        if ($sPageCaption)
+            $oTemplate->setPageTitle ($sPageCaption);
+        $oTemplate->setPageContent ('page_main_code', $sPageContent);
 
-        exit;
+        $oTemplate->getPageCode();
     }
 }
 

+ 1 - 4
modules/base/general/classes/BxBaseModGeneralFormsEntryHelper.php

@@ -70,7 +70,7 @@ class BxBaseModGeneralFormsEntryHelper extends BxDolProfileForms
                 return MsgBox(_t('_sys_txt_error_entry_creation'));
         }
 
-        $sResult = $this->onDataAddAfter (false, $iContentId);
+        $sResult = $this->onDataAddAfter (getLoggedId(), $iContentId);
         if ($sResult)
             return $sResult;
 
@@ -268,9 +268,6 @@ class BxBaseModGeneralFormsEntryHelper extends BxDolProfileForms
 
     public function onDataAddAfter ($iAccountId, $iContentId)
     {
-        if (false === $iAccountId)
-            $iAccountId = getLoggedId();
-
         if (!empty($CNF['OBJECT_METATAGS'])) {
             list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
             $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);

+ 2 - 0
modules/boonex/facebook_connect/classes/BxFaceBookConnectModule.php

@@ -133,6 +133,8 @@ class BxFaceBookConnectModule extends BxBaseModConnectModule
         }
 
         if (!$this -> _oConfig -> mApiID || !$this -> _oConfig -> mApiSecret) {
+            require_once(BX_DIRECTORY_PATH_INC . 'design.inc.php');
+            bx_import('BxDolLanguages');
             $this->_setLastError(_t('_bx_facebook_profile_error_api_keys'));
         } 
         else {

+ 3 - 10
modules/boonex/facebook_connect/classes/BxFaceBookConnectTemplate.php

@@ -14,7 +14,6 @@ class BxFaceBookConnectTemplate extends BxBaseModConnectTemplate
     function __construct($oConfig, $oDb)
     {
         parent::__construct($oConfig, $oDb);
-        $this->_sPageIcon = 'facebook';
     }
 
     function dislayPageError() 
@@ -22,16 +21,10 @@ class BxFaceBookConnectTemplate extends BxBaseModConnectTemplate
         $oPage = BxDolPage::getObjectInstance('bx_facebook_error');
         $oTemplate = BxDolTemplate::getInstance();
 
-        if ($oPage) {
-
-            $oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
-            $oTemplate->setPageContent ('page_main_code', $oPage->getCode());
-            $oTemplate->getPageCode();
-
-        } else {
-
+        if (!$oPage)
             $oTemplate->displayPageNotFound();
-        }
+        else
+            parent::getPage($oPage->getCode());
     }
 }
 

+ 2 - 2
modules/boonex/facebook_connect/install/langs/en.xml

@@ -11,8 +11,8 @@
 	<string name="_bx_facebook_auth_title"><![CDATA[Facebook Connect]]></string>
 	<string name="_bx_facebook_error"><![CDATA[Error]]></string>
 
-    <string name="_bx_smtp_adm_stg_cpt_type"><![CDATA[Facebook Connect]]></string>
-    <string name="_bx_smtp_adm_stg_cpt_category_general"><![CDATA[General]]></string>
+    <string name="_bx_facebook_adm_stg_cpt_type"><![CDATA[Facebook Connect]]></string>
+    <string name="_bx_facebook_adm_stg_cpt_category_general"><![CDATA[General]]></string>
     <string name="_bx_facebook_option_app_id"><![CDATA[Facebook App ID]]></string>
     <string name="_bx_facebook_option_app_secret"><![CDATA[Facebook App Secret]]></string>
     <string name="_bx_facebook_option_redirect"><![CDATA[Redirect page after first sign in]]></string>

+ 3 - 2
modules/boonex/facebook_connect/install/sql/enable.sql

@@ -17,7 +17,8 @@ SET @iHandlerId := (SELECT `id` FROM `sys_alerts_handlers`  WHERE `name` = 'bx_f
 
 INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
 ('account', 'logout', @iHandlerId),
-('profile', 'delete', @iHandlerId);
+('profile', 'delete', @iHandlerId),
+('profile', 'add', @iHandlerId);
 
 -- SETTINGS
 
@@ -33,7 +34,7 @@ SET @iCategId = LAST_INSERT_ID();
 INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `type`, `check`, `check_error`, `order`, `extra`) VALUES
 ('bx_facebook_connect_api_key', '', @iCategId, '_bx_facebook_option_app_id', 'digit', '', '', 10, ''),
 ('bx_facebook_connect_secret', '', @iCategId, '_bx_facebook_option_app_secret', 'digit', '', '', 20, ''),
-('bx_facebook_connect_redirect_page', 'member', @iCategId, '_bx_facebook_option_redirect', 'select', '', '', 30, 'join,pedit,avatar,member,index'),
+('bx_facebook_connect_redirect_page', 'dashboard', @iCategId, '_bx_facebook_option_redirect', 'select', '', '', 30, 'join,settings,dashboard,index'),
 ('bx_facebook_connect_auto_friends', 'on', @iCategId, '_bx_facebook_option_auto_friends', 'checkbox', '', '', 40, ''),
 ('bx_facebook_connect_extended_info', '', @iCategId, '_bx_facebook_option_fetch_extended_info', 'checkbox', '', '', 50, ''),
 ('bx_facebook_connect_module', 'bx_persons', @iCategId, '_bx_facebook_option_module', 'select', '', '', 60, 'a:2:{s:6:"module";s:11:"bx_facebook";s:6:"method";s:20:"get_profiles_modules";}'),

+ 2 - 2
modules/boonex/russian/data/langs/bx_facebook/ru.xml

@@ -11,8 +11,8 @@
 	<string name="_bx_facebook_auth_title"><![CDATA[Facebook-соединение]]></string>
 	<string name="_bx_facebook_error"><![CDATA[Ошибка]]></string>
 
-    <string name="_bx_smtp_adm_stg_cpt_type"><![CDATA[Facebook-соединение]]></string>
-    <string name="_bx_smtp_adm_stg_cpt_category_general"><![CDATA[Общие]]></string>
+    <string name="_bx_facebook_adm_stg_cpt_type"><![CDATA[Facebook-соединение]]></string>
+    <string name="_bx_facebook_adm_stg_cpt_category_general"><![CDATA[Общие]]></string>
     <string name="_bx_facebook_option_app_id"><![CDATA[Facebook App ID]]></string>
     <string name="_bx_facebook_option_app_secret"><![CDATA[Facebook App Secret]]></string>
     <string name="_bx_facebook_option_redirect"><![CDATA[Перенаправления после захода на сайт]]></string>

+ 1 - 1
modules/boonex/russian/data/langs/system/ru.xml

@@ -2048,7 +2048,7 @@
 	<string name="_sys_txt_account_profile_context_change_suggestion"><![CDATA[Это Ваш профиль, Вы можете <a href="{0}">изменить свой текущий профиль</a> на этот]]></string>
 	<string name="_sys_txt_account_profile_context_changed_success"><![CDATA[Текущий профиль удачно изменён на: <b>{0}</b>]]></string>
 	<string name="_sys_txt_account_suspended"><![CDATA[Ваш аккаунт заблокирован.]]></string>
-	<string name="_sys_txt_account_unconfirmed"><![CDATA[Ваш имейл неподтверждён. Пожалуйста, проверьте свой эл. ящик ({1}) на наличие письма подтверждения и перейдите по ссылке в нём. Не можете найти письмо? Проверьте папку SPAM или <a href="{0}">снова запросите письмо верификации</a>.]]></string>
+	<string name="_sys_txt_account_unconfirmed"><![CDATA[Ваш емейл не подтверждён. Пожалуйста, проверьте свой эл. ящик ({1}) на наличие письма подтверждения и перейдите по ссылке в нём. <br />Не можете найти письмо? Проверьте папку "спам" или <a href="{0}">снова запросите письмо верификации</a>.]]></string>
 	<string name="_sys_txt_account_profile_system"><![CDATA[У Вас нет созданных профилей, поэтому Вы не можете пользоваться сайтом, пожалуйста, <a href="{0}">создайте профиль</a>.]]></string>
 	<string name="_sys_txt_captcha_not_available"><![CDATA[CAPTCHA недоступна]]></string>
     <string name="_sys_txt_change_image"><![CDATA[Изменить Картинку]]></string>

+ 5 - 1
template/scripts/BxBaseAccountForms.php

@@ -15,6 +15,8 @@ class BxBaseAccountForms extends BxDolProfileForms
 {
     protected $_iProfileId;
 
+    static public $PROFILE_FIELDS = array();
+
     public function __construct()
     {
         parent::__construct();
@@ -47,7 +49,9 @@ class BxBaseAccountForms extends BxDolProfileForms
         if (!$oForm)
             return MsgBox(_t('_sys_txt_error_occured'));
 
-        $oForm->initChecker();
+        $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=create-account');
+        $oForm->initChecker(self::$PROFILE_FIELDS);
+
         if (!$oForm->isSubmittedAndValid()) {
         	$sCode = $oForm->getCode();