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

Ticket #4558 - Build-in API support: Timeline event - content array filtration.

AntonLV 1 год назад
Родитель
Сommit
b64fc55a21

+ 11 - 8
modules/base/general/classes/BxBaseModGeneralModule.php

@@ -4273,14 +4273,9 @@ class BxBaseModGeneralModule extends BxDolModule
             if ($oCategory)
                 $sCategory = $oCategory->getCategoryTitle($aContentInfo[$CNF['FIELD_CATEGORY']]);
         } 
-        
-    	return array(
-            'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
-            'sample_wo_article' => $CNF['T']['txt_sample_single'],
-            'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
-            'url' => $sUrl,
+
+        $aResult = [
             'title' => $sTitle,
-            'category' => $sCategory,
             'text' => $sText,
             'images' => $aImages,
             'images_attach' => $aImagesAttach,
@@ -4288,7 +4283,15 @@ class BxBaseModGeneralModule extends BxDolModule
             'videos_attach' => $aVideosAttach,
             'files' => $aFiles,
             'files_attach' => $aFilesAttach
-        );
+        ];
+
+        return $this->_bIsApi ? $aResult : array_merge($aResult, [
+            'sample' => isset($CNF['T']['txt_sample_single_with_article']) ? $CNF['T']['txt_sample_single_with_article'] : $CNF['T']['txt_sample_single'],
+            'sample_wo_article' => $CNF['T']['txt_sample_single'],
+            'sample_action' => isset($CNF['T']['txt_sample_action']) ? $CNF['T']['txt_sample_action'] : '',
+            'url' => $sUrl,
+            'category' => $sCategory,
+        ]);
     }
 
     protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())

+ 15 - 10
modules/boonex/ads/classes/BxAdsModule.php

@@ -2689,17 +2689,11 @@ class BxAdsModule extends BxBaseModTextModule
             ]);
 
         $aResult = parent::_getContentForTimelinePost($aEvent, $aContentInfo, $aBrowseParams);
-        if(empty($aResult['raw']))
-            $aResult['raw'] = '';
 
-        if($this->_bIsApi)
-            $aResult = array_merge($aResult, [
-                'price' => $sPrice,
-                'category_title' => $sCategory,
-                'register_click' => $this->_oConfig->isPromotion() ? 'bx_ads/register_click&params[]=' . $aContentInfo[$CNF['FIELD_ID']] : false,
-                'register_impression' => $this->_oConfig->isPromotion() ? 'bx_ads/register_impression&params[]=' . $aContentInfo[$CNF['FIELD_ID']] : false,
-            ]);
-        else
+        if(!$this->_bIsApi) {
+            if(empty($aResult['raw']))
+                $aResult['raw'] = '';
+
             $aResult['text'] = $this->_oTemplate->parseHtmlByName('timeline_post_text.html', [
                 'category_link' => $sCategoryLink,
                 'category_title' => $sCategory,
@@ -2707,10 +2701,21 @@ class BxAdsModule extends BxBaseModTextModule
                 'price' => $sPrice,
                 'text' => $aResult['text']
             ]);
+        }
+        else
+            $aResult = array_merge($aResult, [
+                'price' => $sPrice,
+                'category_title' => $sCategory,
+                'register_click' => $this->_oConfig->isPromotion() ? 'bx_ads/register_click&params[]=' . $aContentInfo[$CNF['FIELD_ID']] : false,
+                'register_impression' => $this->_oConfig->isPromotion() ? 'bx_ads/register_impression&params[]=' . $aContentInfo[$CNF['FIELD_ID']] : false,
+            ]);
 
         if($this->_oConfig->isSources() && !empty($aContentInfo[$CNF['FIELD_URL']]))
             $aResult['url'] = $aContentInfo[$CNF['FIELD_URL']];
 
+        if($this->_bIsApi)
+            return $aResult;
+
         if($this->_oConfig->isPromotion()) {
             $sJsObject = $this->_oConfig->getJsObject('main');
             $sHtmlId = $this->_oConfig->getHtmlIds('unit') . $aContentInfo[$CNF['FIELD_ID']] . '-' . time() . '-' . mt_rand(0, 100);

+ 16 - 15
modules/boonex/events/classes/BxEventsModule.php

@@ -770,21 +770,22 @@ class BxEventsModule extends BxBaseModGroupsModule implements iBxDolCalendarServ
         $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
         $sLocationString = $oMetatags ? $oMetatags->locationsString($aContentInfo[$CNF['FIELD_ID']], false) : false;
 
-        $a['content']['raw'] = $this->_oTemplate->parseHtmlByName('timeline_post.html', [
-            'title' => $a['content']['title'],
-            'title_attr' => bx_html_attribute($a['content']['title']),
-            'url' => $a['content']['url'],
-            'bx_if:date' => [
-                'condition' => $oDateStart,
-                'content' => [
-                    'date' => $oDateStart ? bx_time_js($aContentInfo['date_start'], BX_FORMAT_DATE_TIME, true) : '',
-                    'date_c' => $oDateStart->format('c'),
-            ]],
-            'bx_if:location' => array(
-                'condition' => !!$sLocationString,
-                'content' => array('location' => $sLocationString),
-            ),
-        ]);
+        if(!$this->_bIsApi)
+            $a['content']['raw'] = $this->_oTemplate->parseHtmlByName('timeline_post.html', [
+                'title' => $a['content']['title'],
+                'title_attr' => bx_html_attribute($a['content']['title']),
+                'url' => $a['content']['url'],
+                'bx_if:date' => [
+                    'condition' => $oDateStart,
+                    'content' => [
+                        'date' => $oDateStart ? bx_time_js($aContentInfo['date_start'], BX_FORMAT_DATE_TIME, true) : '',
+                        'date_c' => $oDateStart->format('c'),
+                ]],
+                'bx_if:location' => array(
+                    'condition' => !!$sLocationString,
+                    'content' => array('location' => $sLocationString),
+                ),
+            ]);
 
         return $a;
     }

+ 12 - 0
modules/boonex/timeline/classes/BxTimelineTemplate.php

@@ -2081,9 +2081,15 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
             $aEvent['cmts']['count'] = $aEvent['comments']['count'];
         }
 
+        /**
+         * 
+         * Disabled because it wilter out non-standard fields, 
+         * like price from Ads or dates from Events.
+         * 
         $aEvent['content'] = array_intersect_key($aEvent['content'], array_flip([
             'object_id', 'title', 'text', 'links', 'images', 'images_attach', 'videos', 'videos_attach', 'files', 'files_attach', 'parse_type', 'owner_name', 'embed'
         ]));
+         */
 
         return array_intersect_key($aEvent, array_flip([
             'id', 'type', 'object_privacy_view', 'content', 'labels', 'date', 'menu_actions', 'menu_counters', 'menu_manage', 'author_data', 'author_actions', 'url', 'owners', 'cmts'
@@ -3261,6 +3267,12 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
         }
 
         $this->_preparetDataActions(true, $aEvent, $aResult);
+
+        if($this->_bIsApi)
+            $aResult['content'] = array_intersect_key($aResult['content'], array_flip([
+                'object_id', 'title', 'text', 'links', 'images', 'images_attach', 'videos', 'videos_attach', 'files', 'files_attach', 'parse_type', 'owner_name', 'embed'
+            ]));
+
         return $aResult;
     }