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

Ticket #4558 - Build-in API support: Overwrite page code.

AntonLV 1 год назад
Родитель
Сommit
ac44850e35
2 измененных файлов с 31 добавлено и 24 удалено
  1. 0 21
      template/scripts/BxBasePage.php
  2. 31 3
      template/scripts/BxBaseServicePages.php

+ 0 - 21
template/scripts/BxBasePage.php

@@ -647,33 +647,12 @@ class BxBasePage extends BxDolPage
             $o = BxDolProfile::getInstance();
             $a['user'] = BxDolProfile::getDataForPage($o);
         }
-        
-        $aExtras = [
-            'page' => $this,
-            'blocks' => $aBlocks,
-            'data' => &$a,
-        ];
 
         if(!$bIsAvailable)
             $a['page_status'] = 404;
         else if(!$bIsVisible)
             $a['page_status'] = 403;
 
-        /**
-         * @hooks
-         * @hookdef hook-system-get_page_api 'system', 'get_page_api' - hook to override page peremeters, is used in API calls
-         * - $unit_name - equals `system`
-         * - $action - equals `get_page_api`
-         * - $object_id - not used
-         * - $sender_id - not used
-         * - $extra_params - array of additional params with the following array keys:
-         *      - `page` - [object] an instance of page class, @see BxDolPage 
-         *      - `blocks` - [array] array with page blocks
-         *      - `data` - [array] by ref, page peremeters array as key&value pairs, can be overridden in hook processing
-         * @hook @ref hook-system-get_page_api
-         */
-        bx_alert('system', 'get_page_api', 0, 0, $aExtras);
-
         return $a;
     }
 

+ 31 - 3
template/scripts/BxBaseServicePages.php

@@ -54,18 +54,29 @@ class BxBaseServicePages extends BxDol
             }
             $mixed = BxDolPage::getPageBySeoLink($sRequest);
         }
-       
+
+        $aExtras = [
+            'request' => $sRequest,
+        ];
 
         if (($sUrl = $mixed) && is_string($sUrl)) {
             $aRes = ['redirect' => $sUrl];
+
+            $aExtras = array_merge($aExtras, [
+                'url' => $sUrl
+            ]);
         }
         elseif (($oPage = $mixed) && is_object($oPage)) {
-			
             $aBlocks = [];
             if(!empty($sBlocks))
                 $aBlocks = explode(',', $sBlocks);
 
-            return $oPage->getPageAPI($aBlocks);
+            $aRes = $oPage->getPageAPI($aBlocks);
+
+            $aExtras = array_merge($aExtras, [
+                'page' => $oPage,
+                'blocks' => $aBlocks
+            ]);
         }
         else {
             $aRes = ['code' => 404, 'error' => _t("_sys_request_page_not_found_cpt"), 'data' => ['page_status' => 404]];
@@ -74,6 +85,23 @@ class BxBaseServicePages extends BxDol
                 $aRes['data']['user'] = BxDolProfile::getDataForPage();
         }
 
+        $aExtras['data'] = &$aRes;
+
+        /**
+         * @hooks
+         * @hookdef hook-system-get_page_api 'system', 'get_page_api' - hook to override page peremeters, is used in API calls
+         * - $unit_name - equals `system`
+         * - $action - equals `get_page_api`
+         * - $object_id - not used
+         * - $sender_id - not used
+         * - $extra_params - array of additional params with the following array keys:
+         *      - `page` - [object] an instance of page class, @see BxDolPage 
+         *      - `blocks` - [array] array with page blocks
+         *      - `data` - [array] by ref, page peremeters array as key&value pairs, can be overridden in hook processing
+         * @hook @ref hook-system-get_page_api
+         */
+        bx_alert('system', 'get_page_api', 0, 0, $aExtras);
+
         return $aRes;
     }