Procházet zdrojové kódy

Ticket #4543 - Invitations: (API)

roman.lesnikov@gmail.com před 2 roky
rodič
revize
2d26621fc0

+ 14 - 3
modules/boonex/invites/classes/BxInvModule.php

@@ -29,8 +29,9 @@ class BxInvModule extends BxDolModule
     /**
      * ACTION METHODS
      */
-    function actionGetLink()
+    function serviceGetLink()
     {
+        
         $iProfileId = $this->getProfileId();
         $iAccountId = $this->getAccountId($iProfileId);
 
@@ -40,12 +41,12 @@ class BxInvModule extends BxDolModule
 
         if(!isAdmin($iAccountId)) {
             if($this->_oConfig->getCountPerUser() <= 0)
-                return echoJson(array('message' => _t('_bx_invites_err_limit_reached')));
+                return bx_is_api() ? [bx_api_get_msg(_t('_bx_invites_err_limit_reached'))] : echoJson(array('message' => _t('_bx_invites_err_limit_reached')));
         }
 
         $oKeys = BxDolKey::getInstance();
         if(!$oKeys)
-            return  echoJson(array('message' => _t('_bx_invites_err_not_available')));
+            return bx_is_api() ? [bx_api_get_msg(_t('_bx_invites_err_not_available'))] : echoJson(array('message' => _t('_bx_invites_err_not_available')));
 
         $sKey = $oKeys->getNewKey(false, $this->_oConfig->getKeyLifetime());       
 
@@ -65,11 +66,20 @@ class BxInvModule extends BxDolModule
         ));
         $this->onInvite($iProfileId);
 
+        if (bx_is_api()){
+            return ['link' => bx_api_get_relative_url($this->getJoinLink($sKey))];
+        }
+        
         echoJson(array('popup' => $this->_oTemplate->getLinkPopup(
             $this->getJoinLink($sKey)
         )));
     }
     
+    function actionGetLink()
+    {
+        $this->serviceGetLink();
+    }
+    
     public function actionSetSeenMark($Code)
     {
         header('Content-Type: image/png');
@@ -87,6 +97,7 @@ class BxInvModule extends BxDolModule
             'GetBlockInvite' => '',
             'GetBlockFormInvite' => '',
             'GetBlockFormRequest' => '',
+            'GetLink' => '',
         );
     }
 

+ 4 - 0
modules/boonex/invites/classes/BxInvTemplate.php

@@ -66,6 +66,10 @@ class BxInvTemplate extends BxBaseModGeneralTemplate
         if($mInvitesRemain === true)
             $mInvitesRemain = _t('_bx_invites_txt_unlimited');
 
+        if(bx_is_api()){
+            return [bx_api_get_block('invite', ['remain' => $mInvitesRemain, 'request_url' => 'bx_invites/get_link/'])];
+        }
+        
         $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink($this->_oConfig->CNF['URL_INVITE']));
 
         if($bRedirect) {

+ 4 - 3
template/scripts/BxBaseAccountForms.php

@@ -59,15 +59,16 @@ class BxBaseAccountForms extends BxDolProfileForms
         ));
 
         if (!$oForm->isSubmittedAndValid()) {
-            if($bIsApi)
-                return $oForm->getCodeAPI();
-
+            
             $sCode = $oForm->getCode();
 
             bx_alert('account', 'add_form', 0, 0, array(
                     'form_object' => &$oForm,
                     'form_code' => &$sCode
             ));
+            
+            if($bIsApi)
+                return $oForm->getCodeAPI();
 
             return $sCode;
         }

+ 1 - 1
template/scripts/BxBasePage.php

@@ -417,7 +417,7 @@ class BxBasePage extends BxDolPage
         if (isset(bx_get('params')[2]) && bx_get('params')[2] != ''){
             $array = json_decode(bx_get('params')[2], true);
             $query_string = http_build_query($array);
-
+            parse_str($query_string, $_GET);
         }
         $a = [
             'id' => $this->_aObject['id'],

+ 14 - 2
template/scripts/BxBaseServiceAccount.php

@@ -66,11 +66,23 @@ class BxBaseServiceAccount extends BxDol
                         'request' => ['url' => '/api.php?r=system/create_account_form/TemplServiceAccount', 'immutable' => true]
                     ]
                 ])];
-            else if($mixedResult === true)
+            else if($mixedResult === true){
+                $sRedirectUrl = BxDolForm::getSubmittedValue('relocate','post');
+                if(trim($sRedirectUrl) == ''){
+                    $RedirectUrl = '/';
+                }
+                else{
+                    $parts = parse_url($sRedirectUrl);
+                    parse_str($parts['query'], $query);
+                    unset($query['_q']);
+                    $parts['query'] = http_build_query($query);
+                    $sRedirectUrl = $parts['path'] . (!empty($parts['query']) ? '?' . $parts['query'] : '');
+                }
                 return [
-                    bx_api_get_block('redirect', ['uri' => '/']),
+                    bx_api_get_block('redirect', ['uri' => $sRedirectUrl]),
                     bx_api_get_block('login', ['session' => BxDolSession::getInstance()->getId()], ['id' => 2]),
                 ];
+            }
             else
                 return bx_api_get_msg($mixedResult);
         }