diff --git a/inc/classes/BxDolPage.php b/inc/classes/BxDolPage.php index 64953e8087..042769d00a 100644 --- a/inc/classes/BxDolPage.php +++ b/inc/classes/BxDolPage.php @@ -343,12 +343,13 @@ static public function deleteSeoLinkByModule ($sModule) } /** - * Process SEO links. It takes request part from SEO link and process it - * to make it work as regular page link + * Get page object by SEO link. It takes request part from SEO link and returns page object * @param $sRequest request URI with SEO link - * @return true - if page was found and processed correctly, false - if page wasn't found + * @return false - if page wasn't found, + * page object - on success, + * string URL - if permanent redirect is needed */ - static public function processSeoLink ($sRequest) + static public function getPageBySeoLink ($sRequest) { if (!$sRequest || '/' === $sRequest || !getParam('permalinks_seo_links')) return false; @@ -357,8 +358,7 @@ static public function processSeoLink ($sRequest) if ('/' === $sRequest[-1] || $sRequest != mb_strtolower($sRequest)) { unset($_GET['_q']); $sUrl = BX_DOL_URL_ROOT . bx_append_url_params(mb_strtolower(trim($sRequest, '/')), $_GET); - header('Location:' . $sUrl, true, 301); - exit; + return $sUrl; } // parse URL @@ -372,8 +372,7 @@ static public function processSeoLink ($sRequest) unset($_GET['_q']); $a[0] = $aSeoUriRewrites[$a[0]]; $sUrl = BX_DOL_URL_ROOT . bx_append_url_params(mb_strtolower(implode('/', $a)), $_GET); - header('Location:' . $sUrl, true, 301); - exit; + return $sUrl; } // check page URI rewrite @@ -403,18 +402,36 @@ static public function processSeoLink ($sRequest) $sLink = substr($sLink, strlen(BX_DOL_URL_ROOT)); $s = BxDolPage::multisiteLinkCheck ('', $a[0], $aPage['module'], $_GET); - if (false !== $s) { - header('Location:' . $s . $sLink, true, 301); - exit; - } + if (false !== $s) + return $s . $sLink; } // display page $_REQUEST['i'] = $_GET['i'] = $a[0]; $oPage = BxDolPage::getObjectInstanceByURI($a[0], false, true); - $oPage->displayPage(); - - return true; + return $oPage; + } + + /** + * Process SEO links. It takes request part from SEO link and process it + * to make it work as regular page link + * @param $sRequest request URI with SEO link + * @return true - if page was found and processed correctly, false - if page wasn't found + */ + static public function processSeoLink ($sRequest) + { + $mixed = self::getPageBySeoLink($sRequest); + if (($sUrl = $mixed) && is_string($sUrl)) { + header('Location:' . $sUrl, true, 301); + exit; + } + elseif (($oPage = $mixed) && is_object($oPage)) { + $oPage->displayPage(); + return true; + } + else { + return false; + } } /** diff --git a/modules/boonex/contact/classes/BxContactModule.php b/modules/boonex/contact/classes/BxContactModule.php index 24508701c7..91314a7ea5 100644 --- a/modules/boonex/contact/classes/BxContactModule.php +++ b/modules/boonex/contact/classes/BxContactModule.php @@ -125,7 +125,7 @@ public function serviceGetBlockForm() if (defined('BX_API')) return [ - ['id' => 1, 'type' => 'form', 'data' => $oForm->getCode(), 'request' => ['url' => '/api.php?r=bx_contact/get_block_form', 'immutable' => true]], + ['id' => 1, 'type' => 'form', 'data' => $oForm->getCodeAPI(), 'request' => ['url' => '/api.php?r=bx_contact/get_block_form', 'immutable' => true]], ['id' => 2, 'type' => 'msg', 'data' => $sResult], ]; diff --git a/template/scripts/BxBaseFormView.php b/template/scripts/BxBaseFormView.php index b3bfb1c43a..db5ec3a386 100644 --- a/template/scripts/BxBaseFormView.php +++ b/template/scripts/BxBaseFormView.php @@ -330,9 +330,6 @@ function getCode($bDynamicMode = false) 'include' => &$sInclude )); - if (defined('BX_API')) - return ['inputs' => $this->aInputs, 'attrs' => $this->aFormAttrs, 'params' => $this->aParams]; - if($this->sCode === false) $this->sCode = $this->genForm(); @@ -341,6 +338,15 @@ function getCode($bDynamicMode = false) return $sInclude . $sDynamicCssJs . $this->sCode; } + function getCodeAPI() + { + $this->aFormAttrs = $this->_replaceMarkers($this->aFormAttrs); + + // TODO: process inputs to translate titles, alerts, etc + + return ['inputs' => $this->aInputs, 'attrs' => $this->aFormAttrs, 'params' => $this->aParams]; + } + public function getJsClassName() { return $this->_sJsClassName; diff --git a/template/scripts/BxBaseServicePages.php b/template/scripts/BxBaseServicePages.php index 8295ba37cc..64909f9c53 100644 --- a/template/scripts/BxBaseServicePages.php +++ b/template/scripts/BxBaseServicePages.php @@ -21,10 +21,10 @@ public function __construct() * @page service Service Calls * @section bx_system_pages System Services * @subsection bx_system_pages-pages Pages - * @subsubsection bx_system_pages-get_page Get page + * @subsubsection bx_system_pages-get_page_by_request Get page by page URI * - * @code bx_srv('system', 'get_page', ['about'], 'TemplServicePages'); @endcode - * @code {{~system:get_page:TemplServicePages['about']~}} @endcode + * @code bx_srv('system', 'get_page_by_request', ['about'], 'TemplServicePages'); @endcode + * @code {{~system:get_page_by_request:TemplServicePages['about']~}} @endcode * * Test method which page data * @param $sURI page URI @@ -32,9 +32,43 @@ public function __construct() * @see BxBaseServicePages::serviceGetPage */ /** - * @ref bx_system_general-get_page "get_page" + * @ref bx_system_general-get_page_by_request "get_page_by_request" */ - public function serviceGetPage ($sURI) + public function serviceGetPageByRequest ($sRequest) + { + $mixed = BxDolPage::getPageBySeoLink($sRequest); + + if (($sUrl = $mixed) && is_string($sUrl)) { + $aRes = ['redirect' => $sUrl]; + } + elseif (($oPage = $mixed) && is_object($oPage)) { + return $oPage->getPage(); + } + else { + $aRes = ['error' => _t("_sys_request_page_not_found_cpt")]; + } + + return $aRes; + } + + /** + * @page service Service Calls + * @section bx_system_pages System Services + * @subsection bx_system_pages-pages Pages + * @subsubsection bx_system_pages-get_page_by_uri Get page by page URI + * + * @code bx_srv('system', 'get_page_by_uri', ['about'], 'TemplServicePages'); @endcode + * @code {{~system:get_page_by_uri:TemplServicePages['about']~}} @endcode + * + * Test method which page data + * @param $sURI page URI + * + * @see BxBaseServicePages::serviceGetPage + */ + /** + * @ref bx_system_general-get_page_by_uri "get_page_by_uri" + */ + public function serviceGetPageByUri ($sURI) { $oPage = BxDolPage::getObjectInstanceByURI($sURI, false, true); if (!$oPage) {