Răsfoiți Sursa

Ticket #3764 - Categories/Hashtags: PHP notice on home page.

AntonLV 4 ani în urmă
părinte
comite
6cb29d3ee0

+ 23 - 14
inc/utils.inc.php

@@ -941,7 +941,7 @@ function bx_file_get_contents($sFileUrl, $aParams = array(), $sMethod = 'get', $
         if ($aHeaders)
             curl_setopt($rConnect, CURLOPT_HTTPHEADER, $aHeaders);
 
-        if (defined('BX_DOL_URL_ROOT') && 0 === strpos($sFileUrl, BX_DOL_URL_ROOT)) {
+        if (0 === strpos($sFileUrl, BX_DOL_URL_ROOT)) {
             $sAllCookies = '';
             foreach($_COOKIE as $sKey => $mValue){
                 if(is_array($mValue)){
@@ -1324,20 +1324,29 @@ function bx_get_base_url($sPageLink)
 
 function bx_get_page_info()
 {
-    $a = bx_get_base_url_inline();
-    $oPage = BxDolPage::getObjectInstanceByURI($a[1]['i']);
-    $oServ = bx_instance('BxTemplServices');
-    if ($oServ->serviceIsModuleContext($oPage->getModule())){
-        $oProfile = BxDolProfile::getInstanceByContentAndType($a[1]['id'], $oPage->getModule());
-        return ['context_module' => $oPage->getModule(), 'context_id' => isset($a[1]['id']) ? $a[1]['id'] : '', 'profile_context_id' => $oProfile->id()];
+    list($sPageLink, $aPageParams) = bx_get_base_url_inline();
+
+    if(isset($aPageParams['i'], $aPageParams['id']) && ($oPage = BxDolPage::getObjectInstanceByURI($aPageParams['i'])) !== false) {
+        $sPageModule = $oPage->getModule();
+        if(bx_srv('system', 'is_module_context', [$sPageModule]) && ($oProfile = BxDolProfile::getInstanceByContentAndType($aPageParams['id'], $sPageModule)) !== false)
+            return [
+                'context_module' => $sPageModule, 
+                'context_id' => $aPageParams['id'], 
+                'context_profile_id' => $oProfile->id()
+            ];
     }
-    
-    if (isset($a[1]['profile_id'])){
-        $oProfile = BxDolProfile::getInstance($a[1]['profile_id']);
-        if($oProfile  && $oServ->serviceIsModuleContext($oProfile->getModule())){
-            return ['context_module' => $oProfile->getModule(), 'context_id' => $oProfile->getContentId(), 'profile_context_id' => $a[1]['profile_id']];
-        }
+
+    if(isset($aPageParams['profile_id']) && ($oProfile = BxDolProfile::getInstance($aPageParams['profile_id'])) !== false) {
+        $sProfileModule = $oProfile->getModule();
+        if(bx_srv('system', 'is_module_context', [$sProfileModule]))
+            return [
+                'context_module' => $sProfileModule, 
+                'context_id' => $oProfile->getContentId(), 
+                'context_profile_id' => $aPageParams['profile_id']
+            ];
     }
+
+    return false;
 }
 
 function bx_get_location_bounds_latlng($fLatitude, $fLongitude, $iRadiusInKm)
@@ -2110,7 +2119,7 @@ function bx_get_device_pixel_ratio()
  */
 function bx_log($sObject, $mixed)
 {
-    if (class_exists('BxDolLogs', true) && $o = BxDolLogs::getObjectInstance($sObject))
+    if ($o = BxDolLogs::getObjectInstance($sObject))
         return $o->add($mixed);
     else
         return false;

+ 4 - 4
modules/base/general/classes/BxBaseModGeneralModule.php

@@ -2391,12 +2391,12 @@ class BxBaseModGeneralModule extends BxDolModule
     public function serviceCategoriesMultiList($bDisplayEmptyCats = true)
     {
         $aContextInfo = bx_get_page_info();
+
         $mProfileContextId = false;
-        if (isset($aContextInfo['context_module']) && isset($aContextInfo['profile_context_id'])){
-            $mProfileContextId = $aContextInfo['profile_context_id'];
-        }
+        if ($aContextInfo !== false)
+            $mProfileContextId = $aContextInfo['context_profile_id'];
         
-		$oCategories = BxDolCategories::getInstance();
+        $oCategories = BxDolCategories::getInstance();
         if ($mProfileContextId)
             $aCats = $oCategories->getData([
                 'type' => 'by_module&context_with_num', 

+ 3 - 3
template/scripts/BxBaseCategory.php

@@ -70,10 +70,10 @@ class BxBaseCategory extends BxDolCategory
     public function getCategoriesList($bDisplayEmptyCats = true, $bAsArray = false)
     {
         $aContextInfo = bx_get_page_info();
+
         $mProfileContextId = false;
-        if (isset($aContextInfo['context_module']) && isset($aContextInfo['profile_context_id'])){
-            $mProfileContextId = $aContextInfo['profile_context_id'];
-        }
+        if ($aContextInfo !== false)
+            $mProfileContextId = $aContextInfo['context_profile_id'];
         
         $a = BxDolForm::getDataItems($this->_aObject['list_name']);
         if (!$a)

+ 6 - 7
template/scripts/BxBaseServiceMetatags.php

@@ -52,16 +52,15 @@ class BxBaseServiceMetatags extends BxDol
     	$bShowEmpty = isset($aParams['show_empty']) ? (bool)$aParams['show_empty'] : false;
 
         $aContextInfo = bx_get_page_info();
-        if (isset($aContextInfo['context_module']) && isset($aContextInfo['profile_context_id'])){
-            $sResult = BxDolMetatags::getObjectInstance($sObject)->getKeywordsCloud($mixedSection, $iMaxCount, false, ['context_id' => $aContextInfo['profile_context_id']]);
-        }
-        else{
+        if ($aContextInfo !== false)
+            $sResult = BxDolMetatags::getObjectInstance($sObject)->getKeywordsCloud($mixedSection, $iMaxCount, false, ['context_id' => $aContextInfo['context_profile_id']]);
+        else
             $sResult = BxDolMetatags::getObjectInstance($sObject)->getKeywordsCloud($mixedSection, $iMaxCount);
-        }
+
         if(empty($sResult))
-			return $bShowEmpty ? MsgBox(_t('_Empty')) : '';
+            return $bShowEmpty ? MsgBox(_t('_Empty')) : '';
 
-		return $sResult;
+        return $sResult;
     }
 
     public function serviceBrowseLabels($aParams = array())