Просмотр исходного кода

Ticket #4148 - Build-in API support: Fix for relative URLs.

AntonLV 3 лет назад
Родитель
Сommit
23f9c53b55

+ 5 - 1
inc/classes/BxDolMenu.php

@@ -125,10 +125,14 @@ class BxDolMenu extends BxDolFactory implements iBxDolFactoryObject, iBxDolRepla
         ]);
 
         if(isLogged() && ($oProfile = BxDolProfile::getInstance()) !== false) {
+            $sUrl = $oProfile->getUrl();
+            if($this->_bIsApi)
+                $sUrl = bx_api_get_relative_url($sUrl);
+
             $this->addMarkers([
                 'member_id' => $oProfile->id(),
                 'member_display_name' => $oProfile->getDisplayName(),
-                'member_url' => bx_relative_url($oProfile->getUrl()),
+                'member_url' => $sUrl,
                 'content_id' => $oProfile->getContentId()
             ]);
         }

+ 1 - 1
inc/classes/BxDolProfile.php

@@ -145,7 +145,7 @@ class BxDolProfile extends BxDolFactory implements iBxDolProfile
             'id' => $oProfile->id(),
             'display_type' =>  $sDisplayType,
             'display_name' => $oProfile->getDisplayName(),
-            'url' => bx_relative_url($oProfile->getUrl()),
+            'url' => bx_api_get_relative_url($oProfile->getUrl()),
             'url_avatar' => $oProfile->getAvatar(),
             'module' => $oProfile->getModule(),
         ];

+ 5 - 5
inc/utils.inc.php

@@ -2322,11 +2322,6 @@ function is_private_ip ($sIp)
     return filter_var($sIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== $sIp;
 }
 
-function bx_relative_url($sUrl, $sPrefix = BX_DOL_URL_ROOT)
-{
-    return '/' . bx_ltrim_str($sUrl, $sPrefix);
-}
-
 function bx_absolute_url($sUrl, $sPrefix = BX_DOL_URL_ROOT)
 {
     if (!preg_match('/^https?:\/\//', $sUrl))
@@ -2395,6 +2390,11 @@ function bx_api_check_access()
     // check_logged();
 }
 
+function bx_api_get_relative_url($sUrl, $sPrefix = BX_DOL_URL_ROOT)
+{
+    return '/' . bx_ltrim_str($sUrl, $sPrefix);
+}
+
 function bx_api_get_block($sType, $sData, $aParams = [])
 {   $aData = ['id' => isset($aParams['id']) ? $aParams['id'] : 1 , 'type' => $sType, 'data' => $sData];
     if (isset($aParams['ext']))

+ 5 - 1
modules/base/general/classes/BxBaseModGeneralSearchResult.php

@@ -213,7 +213,11 @@ class BxBaseModGeneralSearchResult extends BxTemplSearchResult
 
     function decodeDataUrl ($oContentInfo, $r)
     {
-        return bx_relative_url($oContentInfo->getContentLink($r['id']));
+        $sLink = $oContentInfo->getContentLink($r['id']);
+        if(bx_is_api())
+            $sLink = bx_api_get_relative_url($sLink);
+
+        return $sLink;
     }
 
     function decodeDataSummaryPlain ($oContentInfo, $r)

+ 1 - 1
modules/boonex/timeline/classes/BxTimelineMenuItemActions.php

@@ -390,7 +390,7 @@ class BxTimelineMenuItemActions extends BxTemplMenuCustom
                 $aItem['link'] = $this->_oModule->_oConfig->getItemViewUrl($this->_aEvent);
                 if($this->_oModule->_oConfig->isSystem($sType, $sAction) && !empty($this->_aEvent['content']['url']))
                     $aItem['link'] = $this->_aEvent['content']['url'];
-                $aItem['link'] = bx_relative_url($aItem['link']);
+                $aItem['link'] = bx_api_get_relative_url($aItem['link']);
                 break;
         }