فهرست منبع

Ticket #4148 - Build-in API support: Author block.

AntonLV 3 سال پیش
والد
کامیت
88ebaf9130

+ 11 - 38
modules/base/text/classes/BxBaseModTextTemplate.php

@@ -90,19 +90,22 @@ class BxBaseModTextTemplate extends BxBaseModGeneralTemplate
 
         if (!$iProfileId)
             $iProfileId = $aData[$CNF['FIELD_AUTHOR']];
-        
+
+        if(bx_is_api())
+            return [bx_api_get_block('entity_author', [
+                'author_data' => BxDolProfile::getData($iProfileId),
+                'entry_date' => !empty($CNF['FIELD_ADDED']) && !empty($aData[$CNF['FIELD_ADDED']]) ? $aData[$CNF['FIELD_ADDED']] : '',
+                'menu_manage' => $oModule->getEntryAllActions()
+            ])];
+
         $oProfile = BxDolProfile::getInstanceMagic($iProfileId);
         $sName = $oProfile->getDisplayName();
         $sAddon = $sFuncAuthorAddon && is_a($oProfile, 'BxDolProfile') ? $this->$sFuncAuthorAddon($aData, $oProfile) : '';        
 
-        $bIsApi = bx_is_api();
-        if($bIsApi)
-            $sFuncAuthorDesc .= 'API';
-
-        $aVars = [
+        return $this->parseHtmlByName($sTemplateName, [
             'author_url' => $oProfile->getUrl(),
             'author_thumb_url' => $oProfile->getThumb(),
-            'author_unit' => $bIsApi ? BxDolProfile::getData($oProfile, ['display_type' => 'unit_wo_info']) : $oProfile->getUnit(0, ['template' => 'unit_wo_info']),
+            'author_unit' => $oProfile->getUnit(0, ['template' => 'unit_wo_info']),
             'author_title' => $sName,
             'author_title_attr' => bx_html_attribute($sName),
             'author_desc' => $sFuncAuthorDesc ? $this->$sFuncAuthorDesc($aData, $oProfile) : '',
@@ -113,12 +116,7 @@ class BxBaseModTextTemplate extends BxBaseModGeneralTemplate
                     'content' => $sAddon,
                 ],
             ],
-        ];
-
-        return $bIsApi ? [bx_api_get_block('entity_author', [
-            'author' => $aVars, 
-            'menu_manage' => $oModule->getEntryAllActions()
-        ])] : $this->parseHtmlByName($sTemplateName, $aVars);
+        ]);
     }
 
     public function entryBreadcrumb($aContentInfo, $aTmplVarsItems = array())
@@ -807,31 +805,6 @@ class BxBaseModTextTemplate extends BxBaseModGeneralTemplate
         ));
     }
 
-    function getAuthorDescAPI($aData, $oProfile)
-    {
-        $CNF = &$this->getModule()->_oConfig->CNF;
-
-        $aResult = ['object' => '', 'items' => []];
-        if(!empty($CNF['FIELD_ADDED']) && !empty($aData[$CNF['FIELD_ADDED']]))
-            $aResult['items'][] = [
-                'id' => 1,
-                'content_type' => 'time',
-                'title' => $aData[$CNF['FIELD_ADDED']]
-            ];
-
-        /*
-         * Isn't needed for now.
-        if(!empty($CNF['URI_AUTHOR_ENTRIES']))
-            $aResult['items'][] = [
-                'id' => 2,
-                'link' => BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_AUTHOR_ENTRIES'] . '&profile_id=' . $oProfile->id()),
-                'title' => _t($CNF['T']['txt_all_entries_by'], $this->getModule()->_oDb->getEntriesNumByAuthor($oProfile->id()))
-            ];
-        */
-
-        return $aResult;
-    }
-
     function getAuthorProfileDesc ($aData, $oProfile)
     {
         $aSnippetMeta = $this->getProfileSnippetMenu($aData);

+ 11 - 30
modules/boonex/timeline/classes/BxTimelineTemplate.php

@@ -628,45 +628,26 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
         $aResult = $this->getDataCached($aEvent);
         if($aResult === false)
             return '';
-        
-        if (bx_is_api()){
-            $oProfile = BxDolProfile::getInstanceMagic($aResult['object_owner_id']);
-            $sName = $oProfile->getDisplayName();
-            $sFuncAuthorAddon = '';
-            $sAddon = $sFuncAuthorAddon && is_a($oProfile, 'BxDolProfile') ? $this->$sFuncAuthorAddon($aData, $oProfile) : '';        
-            $sFuncAuthorDesc = '';
-         
-
-            $aVars = [
-                'author_url' => $oProfile->getUrl(),
-                'author_thumb_url' => $oProfile->getThumb(),
-                'author_unit' => BxDolProfile::getData($oProfile, ['display_type' => 'unit_wo_info']),
-                'author_title' => $sName,
-                'author_title_attr' => bx_html_attribute($sName),
-                'author_desc' => $sFuncAuthorDesc ? $this->$sFuncAuthorDesc($aData, $oProfile) : '',
-                'author_profile_desc' => '',
-                'bx_if:addon' => [
-                    'condition' => (bool)$sAddon,
-                    'content' => [
-                        'content' => $sAddon,
-                    ],
-                ],
-            ];
+
+        if(bx_is_api()) {
+            $oMenuManage = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_manage'));
+            $oMenuManage->setEvent($aEvent);
+
             return [bx_api_get_block('entity_author', [
-                'author' => $aVars, 
+                'author_data' => BxDolProfile::getData($aResult[$CNF['FIELD_OBJECT_OWNER_ID']]),
+                'entry_date' => !empty($aEvent[$CNF['FIELD_ADDED']]) ? $aEvent[$CNF['FIELD_ADDED']] : '',
+                'menu_manage' => $oMenuManage->getCodeApi()
             ])];
         }
 
-        $sAuthorUnit = $this->getModule()->getObjectUser($aResult['object_owner_id'])->getUnit();
-
         $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_post'), $this->_oConfig->getObject('form_display_post_view'), $this);
         $oForm->initChecker($aEvent);
 
-        return $this->parseHtmlByName('block_item_info.html', array(
+        return $this->parseHtmlByName('block_item_info.html', [
             'style_prefix' => $this->_oConfig->getPrefix('style'),
-            'author' => $sAuthorUnit,
+            'author' => $this->getModule()->getObjectUser($aResult['object_owner_id'])->getUnit(),
             'fields' => $oForm->getCode()
-        ));
+        ]);
     }
 
     public function getItemBlockComments($iId)

+ 6 - 6
template/scripts/BxBaseMenu.php

@@ -174,12 +174,7 @@ class BxBaseMenu extends BxDolMenu
         if ($this->_bIsApi) {
             list ($sIcon, $sIconUrl) = $this->_getMenuIcon($a);
 
-            if(($aMarkers = $this->_getMenuMarkers($a)) && is_array($aMarkers))
-                $this->addMarkers($aMarkers);
-
-            $a = $this->_replaceMarkers($a);
-
-            return [
+            $aResult = [
                 'id' => $a['id'],
                 'name' => $a['name'],
                 'title' => _t($a['title']),
@@ -188,6 +183,11 @@ class BxBaseMenu extends BxDolMenu
                 'image' => $sIconUrl ? $sIconUrl : '',
                 'submenu' => !empty($a['submenu_object']) ? $a['submenu_object'] : ''
             ];
+
+            if(($aMarkers = $this->_getMenuMarkers($a)) && is_array($aMarkers))
+                $this->addMarkers($aMarkers);
+
+            return $this->_replaceMarkers($aResult);
         }
 
         $a['object'] = $this->_sObject;