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

Ticket #4148 - Build-in API support: Page block submenu.

AntonLV 3 лет назад
Родитель
Сommit
946c7ac980

+ 1 - 1
modules/boonex/api/classes/BxApiModule.php

@@ -126,7 +126,7 @@ class BxApiModule extends BxDolModule
             );
         }
 
-        return $oPage->getPage ();
+        return $oPage->getPageAPI();
     }
 
     /**

+ 5 - 2
modules/boonex/timeline/classes/BxTimelineTemplate.php

@@ -210,8 +210,11 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
         $sTitle = _t('_bx_timeline_page_block_title_views_' . $aParams['view']);
 
         if (bx_is_api())
-            return [bx_api_get_block('browse', ['unit' => 'feed', 'data' => $this->getViewBlock($aParams)])];
-        
+            return [
+                'content' => [bx_api_get_block('browse', ['unit' => 'feed', 'data' => $this->getViewBlock($aParams)])],
+                'menu' => $oMenu->getCodeAPI()
+            ];
+
         return [
             'content' => $this->parseHtmlByName('block_views.html', [
                 'style_prefix' => $sStylePrefix,

+ 3 - 0
template/scripts/BxBaseMenuCustom.php

@@ -84,6 +84,9 @@ class BxBaseMenuCustom extends BxTemplMenuMoreAuto
             if($aItem === false)
                 return false;
 
+            if($this->_bIsApi)
+                return $aItem;
+
             $mixedItem = $this->_getMenuItemDefault($aItem);
     	}
 

+ 23 - 20
template/scripts/BxBasePage.php

@@ -398,7 +398,7 @@ class BxBasePage extends BxDolPage
     /**
      * Get page array with all cells and blocks
      */
-    public function getPage ()
+    public function getPageAPI ()
     {
         $a = [
             'id' => $this->_aObject['id'],
@@ -409,7 +409,7 @@ class BxBasePage extends BxDolPage
             'module' => $this->getModule (),
             'type' => $this->getType (),
             'layout' => $this->_aObject['layout_id'],
-            'elements' => $this->getPageBlocks (),
+            'elements' => $this->getPageBlocksAPI(),
         ];
 
         if (($oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu')) !== false) {
@@ -435,30 +435,33 @@ class BxBasePage extends BxDolPage
         return $a;
     }
 
-    public function getPageBlocks ()
+    public function getPageBlocksAPI()
     {
-        $aFieldsUnset = array('cell_id', 'active', 'copyable', 'deletable', 'object', 'text', 'text_updated', 'title_system', 'visible_for_levels');
+        $aFieldsUnset = ['cell_id', 'active', 'copyable', 'deletable', 'object', 'text', 'text_updated', 'title_system', 'visible_for_levels'];
+
         $aCells = $this->_oQuery->getPageBlocks();
-        foreach ($aCells as $sKey => &$aCell) {
-            foreach ($aCell as $i => $aBlock) {     
-                if (!$this->_isVisibleBlock($aBlock) || (bx_is_api() && $aCells[$sKey][$i]['hidden_on'] > 0 && ((int)$aCells[$sKey][$i]['hidden_on'] & 8) > 0)){
+        foreach($aCells as $sKey => &$aCell) {
+            foreach($aCell as $i => $aBlock) {     
+                if(!$this->_isVisibleBlock($aBlock) || ($aCells[$sKey][$i]['hidden_on'] > 0 && ((int)$aCells[$sKey][$i]['hidden_on'] & 8) > 0)) {
                     unset($aCells[$sKey][$i]);
+                    continue;
                 }
-                else{
-                    $this->processPageBlock($aCells[$sKey][$i], true);
-                    $aBlock = $aCells[$sKey][$i];
-
-                    $sFunc = '_getBlock' . ucfirst($aBlock['type']);
-                    $aCells[$sKey][$i]['content'] = method_exists($this, $sFunc) ? $this->$sFunc($aBlock) : $aBlock['content'];
-                    $aCells[$sKey][$i]['title'] = $this->getBlockTitle($aBlock);
-                    foreach ($aFieldsUnset as $s)
-                        unset($aCells[$sKey][$i][$s]);
-                }
+
+                $this->processPageBlock($aCells[$sKey][$i], true);
+                $aBlock = $aCells[$sKey][$i];
+
+                $sFunc = '_getBlock' . ucfirst($aBlock['type']);
+                $mBlock = method_exists($this, $sFunc) ? $this->$sFunc($aBlock) : $aBlock['content'];
+
+                $aCells[$sKey][$i]['title'] = isset($mBlock['title']) ? $mBlock['title'] : $this->getBlockTitle($aBlock);
+                $aCells[$sKey][$i]['content'] = isset($mBlock['content']) ? $mBlock['content'] : $mBlock;
+                $aCells[$sKey][$i]['menu'] = isset($mBlock['menu']) ? $mBlock['menu'] : '';
+
+                $aCells[$sKey][$i] = array_diff_key($aCells[$sKey][$i], array_flip($aFieldsUnset));
             }
         }
-        
-        $aCells = array_map('array_values', $aCells);
-        return $aCells;
+
+        return array_map('array_values', $aCells);
     }
 
     /**

+ 1 - 1
template/scripts/BxBaseServicePages.php

@@ -42,7 +42,7 @@ class BxBaseServicePages extends BxDol
             $aRes = ['redirect' => $sUrl];
         }
         elseif (($oPage = $mixed) && is_object($oPage)) {
-            return $oPage->getPage();
+            return $oPage->getPageAPI();
         }
         else {
             $aRes = ['code' => 404, 'error' => _t("_sys_request_page_not_found_cpt")];

+ 8 - 3
template/scripts/BxBaseServices.php

@@ -606,9 +606,6 @@ class BxBaseServices extends BxDol implements iBxDolProfileService
      */
     public function serviceGetCreatePostForm($mixedContextId = false, $sDefault = '', $aCustom = array())
     {
-        if (bx_is_api())
-            return ;
-        
     	if(!isLogged() || ($mixedContextId !== false && !is_numeric($mixedContextId)))
             return '';
 
@@ -657,6 +654,14 @@ class BxBaseServices extends BxDol implements iBxDolProfileService
                 $aPreloadingList[$sModule] = $aModule['uri'];
             }
 
+        if(bx_is_api()) {
+            return [
+                'title' => $sTitle,
+                'content' => '',
+                'menu' => $oMenu->getCodeAPI()
+            ];
+        }
+
     	$sJsObject = 'oBxDolCreatePost';
         $sJsContent = $oTemplate->_wrapInTagJsCode("var " . $sJsObject . " = new BxDolCreatePost(" . json_encode([
             'sObjName' => $sJsObject,