فهرست منبع

Ticket #5273 - Get rid of duplicates in code.

AntonLV 11 ماه پیش
والد
کامیت
7b46fc4e71

+ 23 - 39
inc/classes/BxDolTemplate.php

@@ -199,6 +199,7 @@ class BxDolTemplate extends BxDolFactory implements iBxDolSingleton
     protected $_sFolderImages;
     protected $_sFolderIcons;
     protected $_aTemplates;
+    protected $_aTemplatePatterns;
 
     protected $_aLocations;
     protected $_aLocationsJs;
@@ -281,7 +282,24 @@ class BxDolTemplate extends BxDolFactory implements iBxDolSingleton
         $this->_sFolderCss = 'css/';
         $this->_sFolderImages = 'images/';
         $this->_sFolderIcons = 'images/icons/';
-        $this->_aTemplates = array('html_tags', 'menu_item_addon', 'menu_item_addon_small', 'menu_item_addon_middle');
+        $this->_aTemplates = ['html_tags', 'menu_item_addon', 'menu_item_addon_small', 'menu_item_addon_middle'];
+        $this->_aTemplatePatterns = [
+            "'<bx_include_auto:([^\s]+) \/>'s" => BX_DOL_TEMPLATE_CHECK_IN_BOTH,
+            "'<bx_include_auto_mod_general:([^\s]+) \/>'s" => ['in' => BX_DOL_TEMPLATE_CHECK_IN_BOTH, 'sub' => 'mod_general'],
+            "'<bx_include_auto_mod_profile:([^\s]+) \/>'s" => ['in' => BX_DOL_TEMPLATE_CHECK_IN_BOTH, 'sub' => 'mod_profile'],
+            "'<bx_include_auto_mod_group:([^\s]+) \/>'s" => ['in' => BX_DOL_TEMPLATE_CHECK_IN_BOTH, 'sub' => 'mod_group'],
+            "'<bx_include_auto_mod_text:([^\s]+) \/>'s" => ['in' => BX_DOL_TEMPLATE_CHECK_IN_BOTH, 'sub' => 'mod_text'],
+            "'<bx_include_base:([^\s]+) \/>'s" => BX_DOL_TEMPLATE_CHECK_IN_BASE,
+            "'<bx_include_base_mod_general:([^\s]+) \/>'s" => ['in' => BX_DOL_TEMPLATE_CHECK_IN_BASE, 'sub' => 'mod_general'],
+            "'<bx_include_base_mod_profile:([^\s]+) \/>'s" => ['in' => BX_DOL_TEMPLATE_CHECK_IN_BASE, 'sub' => 'mod_profile'],
+            "'<bx_include_base_mod_group:([^\s]+) \/>'s" => ['in' => BX_DOL_TEMPLATE_CHECK_IN_BASE, 'sub' => 'mod_group'],
+            "'<bx_include_base_mod_text:([^\s]+) \/>'s" => ['in' => BX_DOL_TEMPLATE_CHECK_IN_BASE, 'sub' => 'mod_text'],
+            "'<bx_include_tmpl:([^\s]+) \/>'s" => BX_DOL_TEMPLATE_CHECK_IN_TMPL,
+            "'<bx_include_tmpl_mod_general:([^\s]+) \/>'s" => ['in' => BX_DOL_TEMPLATE_CHECK_IN_TMPL, 'sub' => 'mod_general'],
+            "'<bx_include_tmpl_mod_profile:([^\s]+) \/>'s" => ['in' => BX_DOL_TEMPLATE_CHECK_IN_TMPL, 'sub' => 'mod_profile'],
+            "'<bx_include_tmpl_mod_group:([^\s]+) \/>'s" => ['in' => BX_DOL_TEMPLATE_CHECK_IN_TMPL, 'sub' => 'mod_group'],
+            "'<bx_include_tmpl_mod_text:([^\s]+) \/>'s" => ['in' => BX_DOL_TEMPLATE_CHECK_IN_TMPL, 'sub' => 'mod_text']
+        ];
 
         $this->addLocation('system', $this->_sRootPath, $this->_sRootUrl);
 
@@ -314,8 +332,8 @@ class BxDolTemplate extends BxDolFactory implements iBxDolSingleton
         $this->_bJsArchive = $this->_bJsCache && $bArchive;
         $this->_sJsCachePrefix = $this->_sCacheFilePrefix . 'js_';
 
-        $this->aPage = array();
-        $this->aPageContent = array();
+        $this->aPage = [];
+        $this->aPageContent = [];
     }
 
     /**
@@ -3122,24 +3140,7 @@ class BxDolTemplate extends BxDolFactory implements iBxDolSingleton
         try {
             $oTemplate = &$this;
 
-            $aCallbackPatterns = array(
-                "'<bx_include_auto:([^\s]+) \/>'s" => BX_DOL_TEMPLATE_CHECK_IN_BOTH,
-                "'<bx_include_auto_mod_general:([^\s]+) \/>'s" => array('in' => BX_DOL_TEMPLATE_CHECK_IN_BOTH, 'sub' => 'mod_general'),
-                "'<bx_include_auto_mod_profile:([^\s]+) \/>'s" => array('in' => BX_DOL_TEMPLATE_CHECK_IN_BOTH, 'sub' => 'mod_profile'),
-                "'<bx_include_auto_mod_group:([^\s]+) \/>'s" => array('in' => BX_DOL_TEMPLATE_CHECK_IN_BOTH, 'sub' => 'mod_group'),
-                "'<bx_include_auto_mod_text:([^\s]+) \/>'s" => array('in' => BX_DOL_TEMPLATE_CHECK_IN_BOTH, 'sub' => 'mod_text'),
-                "'<bx_include_base:([^\s]+) \/>'s" => BX_DOL_TEMPLATE_CHECK_IN_BASE,
-                "'<bx_include_base_mod_general:([^\s]+) \/>'s" => array('in' => BX_DOL_TEMPLATE_CHECK_IN_BASE, 'sub' => 'mod_general'),
-                "'<bx_include_base_mod_profile:([^\s]+) \/>'s" => array('in' => BX_DOL_TEMPLATE_CHECK_IN_BASE, 'sub' => 'mod_profile'),
-                "'<bx_include_base_mod_group:([^\s]+) \/>'s" => array('in' => BX_DOL_TEMPLATE_CHECK_IN_BASE, 'sub' => 'mod_group'),
-                "'<bx_include_base_mod_text:([^\s]+) \/>'s" => array('in' => BX_DOL_TEMPLATE_CHECK_IN_BASE, 'sub' => 'mod_text'),
-                "'<bx_include_tmpl:([^\s]+) \/>'s" => BX_DOL_TEMPLATE_CHECK_IN_TMPL,
-                "'<bx_include_tmpl_mod_general:([^\s]+) \/>'s" => array('in' => BX_DOL_TEMPLATE_CHECK_IN_TMPL, 'sub' => 'mod_general'),
-                "'<bx_include_tmpl_mod_profile:([^\s]+) \/>'s" => array('in' => BX_DOL_TEMPLATE_CHECK_IN_TMPL, 'sub' => 'mod_profile'),
-                "'<bx_include_tmpl_mod_group:([^\s]+) \/>'s" => array('in' => BX_DOL_TEMPLATE_CHECK_IN_TMPL, 'sub' => 'mod_group'),
-                "'<bx_include_tmpl_mod_text:([^\s]+) \/>'s" => array('in' => BX_DOL_TEMPLATE_CHECK_IN_TMPL, 'sub' => 'mod_text')
-            );
-            foreach($aCallbackPatterns as $sPattern => $sCheckIn)
+            foreach($this->_aTemplatePatterns as $sPattern => $sCheckIn)
                 $sContent = preg_replace_callback($sPattern, function($aMatches) use($oTemplate, $aVariables, $mixedKeyWrapperHtml, $sCheckIn) {
                     return $oTemplate->parseHtmlByName($aMatches[1], $aVariables, $mixedKeyWrapperHtml, $sCheckIn);
                 }, $sContent);
@@ -3260,24 +3261,7 @@ class BxDolTemplate extends BxDolFactory implements iBxDolSingleton
         try {
             $oTemplate = &$this;
 
-            $aCallbackPatterns = array(
-                "'<bx_include_auto:([^\s]+) \/>'s" => BX_DOL_TEMPLATE_CHECK_IN_BOTH,
-                "'<bx_include_auto_mod_general:([^\s]+) \/>'s" => array('in' => BX_DOL_TEMPLATE_CHECK_IN_BOTH, 'sub' => 'mod_general'),
-                "'<bx_include_auto_mod_profile:([^\s]+) \/>'s" => array('in' => BX_DOL_TEMPLATE_CHECK_IN_BOTH, 'sub' => 'mod_profile'),
-                "'<bx_include_auto_mod_group:([^\s]+) \/>'s" => array('in' => BX_DOL_TEMPLATE_CHECK_IN_BOTH, 'sub' => 'mod_group'),
-                "'<bx_include_auto_mod_text:([^\s]+) \/>'s" => array('in' => BX_DOL_TEMPLATE_CHECK_IN_BOTH, 'sub' => 'mod_text'),
-                "'<bx_include_base:([^\s]+) \/>'s" => BX_DOL_TEMPLATE_CHECK_IN_BASE,
-                "'<bx_include_base_mod_general:([^\s]+) \/>'s" => array('in' => BX_DOL_TEMPLATE_CHECK_IN_BASE, 'sub' => 'mod_general'),
-                "'<bx_include_base_mod_profile:([^\s]+) \/>'s" => array('in' => BX_DOL_TEMPLATE_CHECK_IN_BASE, 'sub' => 'mod_profile'),
-                "'<bx_include_base_mod_group:([^\s]+) \/>'s" => array('in' => BX_DOL_TEMPLATE_CHECK_IN_BASE, 'sub' => 'mod_group'),
-                "'<bx_include_base_mod_text:([^\s]+) \/>'s" => array('in' => BX_DOL_TEMPLATE_CHECK_IN_BASE, 'sub' => 'mod_text'),
-                "'<bx_include_tmpl:([^\s]+) \/>'s" => BX_DOL_TEMPLATE_CHECK_IN_TMPL,
-                "'<bx_include_tmpl_mod_general:([^\s]+) \/>'s" => array('in' => BX_DOL_TEMPLATE_CHECK_IN_TMPL, 'sub' => 'mod_general'),
-                "'<bx_include_tmpl_mod_profile:([^\s]+) \/>'s" => array('in' => BX_DOL_TEMPLATE_CHECK_IN_TMPL, 'sub' => 'mod_profile'),
-                "'<bx_include_tmpl_mod_group:([^\s]+) \/>'s" => array('in' => BX_DOL_TEMPLATE_CHECK_IN_TMPL, 'sub' => 'mod_group'),
-                "'<bx_include_tmpl_mod_text:([^\s]+) \/>'s" => array('in' => BX_DOL_TEMPLATE_CHECK_IN_TMPL, 'sub' => 'mod_text')
-            );
-            foreach($aCallbackPatterns as $sPattern => $sCheckIn)
+            foreach($this->_aTemplatePatterns as $sPattern => $sCheckIn)
                 $sContent = preg_replace_callback($sPattern, function($aMatches) use($oTemplate, $aVarValues, $mixedKeyWrapperHtml, $sCheckIn) {
                     $mixedResult = $oTemplate->getCached($aMatches[1], $aVarValues, $mixedKeyWrapperHtml, $sCheckIn, false);
                     if($mixedResult === false)

+ 2 - 29
modules/boonex/forum/classes/BxForumGridCategories.php

@@ -399,38 +399,11 @@ class BxForumGridCategories extends BxTemplStudioGrid
         
         return new BxTemplStudioFormView($aForm);
     }
-    
+
     protected function _getIconPreview($iId, $sIconImage = '', $sIcon = '')
     {
-        $bIconImage = !empty($sIconImage);
-		
-        $aIcons = BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getIcon($sIcon);
-        $sIconHtml = $aIcons[2] . $aIcons[3] . $aIcons[4];
-		$bIconHtml = !empty($sIconHtml) && !$bIconImage;
-        
-        return $this->_oTemplate->parseHtmlByName('item_icon_preview.html', array(
-            'id' => $iId,
-            'bx_if:show_icon_empty' => array(
-                'condition' => !$bIconImage && !$bIconHtml,
-                'content' => array()
-            ),
-            'bx_if:show_icon_image' => array(
-                'condition' => $bIconImage,
-                'content' => array(
-                    'js_object' => $this->getJsObject(),
-                    'url' => $sIconImage,
-                    'id' => $iId
-                )
-            ),
-            'bx_if:show_icon_html' => array(
-                'condition' => $bIconHtml,
-                'content' => array(
-                    'icon' => $sIconHtml
-                )
-            )
-        ));
+        return BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getIconPreview($iId, $sIconImage, $sIcon);
     }
-        
 }
 
 /** @} */

+ 157 - 0
modules/boonex/invites/classes/BxInvGrid.php

@@ -0,0 +1,157 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    Invites Invites
+ * @ingroup     UnaModules
+ * 
+ * @{
+ */
+
+class BxInvGrid extends BxTemplGrid
+{
+    protected $_sModule;
+    protected $_oModule;
+
+    protected $_sFilter1Name;
+    protected $_sFilter1Value;
+    protected $_aFilter1Values;
+    protected $_sParamsDivider;
+    
+    public function __construct ($aOptions, $oTemplate = false)
+    {
+        parent::__construct ($aOptions, $oTemplate);
+
+        $this->_sModule = 'bx_invites';
+        $this->_oModule = BxDolModule::getInstance($this->_sModule);
+
+        $this->_sParamsDivider = '#-#';
+    }
+
+    public function getFormCallBackUrlAPI($sAction, $iId = 0)
+    {
+         return '/api.php?r=system/perfom_action_api/TemplServiceGrid/&params[]=&o=' . $this->_sObject . '&a=' . $sAction;
+    }
+
+    public function performActionAdd()
+    {
+        $sAction = 'add';
+
+        $oForm = $this->_oModule->getFormObjectInvite();
+        if(!$oForm)
+            return $this->_getActionResult([]);
+
+        $oForm->aInputs['text']['value'] = _t('_bx_invites_msg_invitation');
+        $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . 'grid.php?' . bx_encode_url_params($_GET, array('ids', '_r'));
+        $oForm->initChecker();
+
+        $aResult = [];
+        if($oForm->isSubmittedAndValid()) {
+            $sResult = $this->_oModule->processFormObjectInvite($oForm);
+            if($this->_bIsApi)
+                $aResult = [bx_api_get_msg($sResult)];
+            else
+                $aResult = ['msg' => $sResult];
+        }
+        else {
+            if($this->_bIsApi)
+                $aResult = $this->getFormBlockAPI($oForm, $sAction);
+            else
+                $aResult = ['popup' => [
+                    'html' => BxTemplFunctions::getInstance()->popupBox('_bx_invites_form_invite', _t('_bx_invites_form_invite'), $this->_oModule->_oTemplate->parseHtmlByName('popup_invite.html', [
+                        'form_id' => $oForm->id,
+                        'form' => $oForm->getCode(true),
+                        'object' => $this->_sObject,
+                        'action' => $sAction
+                    ])), 
+                    'options' => ['closeOnOuterClick' => true]
+                ]];
+        }
+
+        return $this->_getActionResult($aResult);
+    }
+
+    protected function _getFilterControls ()
+    {
+        parent::_getFilterControls();
+        return  $this->_getFilterSelectOne($this->_sFilter1Name, $this->_sFilter1Value, $this->_aFilter1Values) . $this->_getSearchInput();
+    }
+    
+    protected function _getSearchInput()
+    {
+        $sJsObject = $this->_oModule->_oConfig->getJsObject('main');
+        $aInputSearch = [
+            'type' => 'text',
+            'name' => 'search',
+            'attrs' => [
+                'id' => 'bx-grid-search-' . $this->_sObject,
+                'onKeyup' => 'javascript:$(this).off(\'keyup focusout\'); ' . $sJsObject . '.onChangeFilter(this)',
+                'onBlur' => 'javascript:' . $sJsObject . '.onChangeFilter(this)',
+            ]
+        ];
+
+        $oForm = new BxTemplFormView([]);
+        return $oForm->genRow($aInputSearch);
+    }
+    
+    protected function _getFilterSelectOne($sFilterName, $sFilterValue, $aFilterValues)
+    {
+        if(empty($sFilterName) || empty($aFilterValues))
+            return '';
+
+        $CNF = &$this->_oModule->_oConfig->CNF;
+        $sJsObject = $this->_oModule->_oConfig->getJsObject('main');
+
+        foreach($aFilterValues as $sKey => $sValue)
+            $aFilterValues[$sKey] = _t($sValue);
+
+        $aInputModules = [
+            'type' => 'select',
+            'name' => $sFilterName,
+            'attrs' => [
+                'id' => 'bx-grid-' . $sFilterName . '-' . $this->_sObject,
+                'onChange' => 'javascript:' . $sJsObject . '.onChangeFilter(this)'
+            ],
+            'value' => $sFilterValue,
+            'values' => $aFilterValues
+        ];
+
+        $oForm = new BxTemplFormView([]);
+        return $oForm->genRow($aInputModules);
+    }
+
+    protected function _getId()
+    {
+        $iId = 0;
+
+        if(($aIds = bx_get('ids')) !== false) {
+            if(!$aIds || !is_array($aIds))
+                return 0;
+
+            $iId = (int)array_shift($aIds);
+        }
+        else if(($iId = bx_get('id')) !== false)
+            $iId = (int)$iId;
+        
+        return $iId;
+    }
+
+    protected function _getIds()
+    {
+        $aIds = [];
+
+        if(($aIds = bx_get('ids')) !== false) {
+            if(!$aIds || !is_array($aIds))
+                return [];
+
+            $aIds = bx_process_input($aIds, BX_DATA_INT);
+        }
+        else if(($iId = bx_get('id')) !== false)
+            $aIds = [(int)$iId];
+
+        return $aIds;
+    }
+}
+
+/** @} */

+ 1 - 27
studio/template/scripts/BxBaseStudioNavigationItems.php

@@ -993,33 +993,7 @@ class BxBaseStudioNavigationItems extends BxDolStudioNavigationItems
 
     protected function _getIconPreview($iId, $sIconImage = '', $sIcon = '')
     {
-        $bIconImage = !empty($sIconImage);
-		
-        $aIcons = BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getIcon($sIcon);
-        $sIconHtml = $aIcons[2] . $aIcons[3] . $aIcons[4];
-		$bIconHtml = !empty($sIconHtml) && !$bIconImage;
-		
-        return $this->_oTemplate->parseHtmlByName('item_icon_preview.html', array(
-            'id' => $iId,
-            'bx_if:show_icon_empty' => array(
-                'condition' => !$bIconImage && !$bIconHtml,
-                'content' => array()
-            ),
-            'bx_if:show_icon_image' => array(
-                'condition' => $bIconImage,
-                'content' => array(
-                    'js_object' => $this->getJsObject(),
-                    'url' => $sIconImage,
-                    'id' => $iId
-                )
-            ),
-            'bx_if:show_icon_html' => array(
-                'condition' => $bIconHtml,
-                'content' => array(
-                    'icon' => $sIconHtml
-                )
-            )
-        ));
+        return BxTemplFunctions::getInstanceWithTemplate($this->_oTemplate)->getIconPreview($iId, $sIconImage, $sIcon);
     }
 
     protected function _isEditable(&$aRow)

+ 13 - 47
template/scripts/BxBaseCmtsServices.php

@@ -437,27 +437,7 @@ class BxBaseCmtsServices extends BxDol
         if(!$oCmts || !$oCmts->isEnabled())
             return [];
 
-        $iCmtId = (int)$aCmtInfo['cmt_id'];
-        $sCmtUrl = str_replace(BX_DOL_URL_ROOT, '{bx_url_root}', $oCmts->serviceGetLink($iCmtId));
-        $sCmtCaption = strmaxtextlen($oCmts->serviceGetText($iCmtId), 20, '...');
-
-        $sCmtUrlApi = '';
-        if(bx_is_api() && getParam('sys_api_comment_notif_link_content') == 'on') {
-            $aCmt = $oCmts->getCommentsBy(['type' => 'uniq_id', 'uniq_id' => $iCmtIdUnique]);
-            if(!empty($aCmt) && is_array($aCmt)) {
-                $oCmts->init($aCmt['cmt_object_id']);
-
-                $sCmtUrlApi = $oCmts->getBaseUrl('{bx_url_root}') . '#cid=' . $iCmtId;
-            }
-        }
-
-        return [
-            'entry_sample' => $oCmts->getLanguageKey('txt_sample_single'),
-            'entry_url' => $sCmtUrl,
-            'entry_url_api' => $sCmtUrlApi,
-            'entry_caption' => $sCmtCaption,
-            'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
-        ];
+        return $this->_getNotificationsData($iCmtIdUnique, (int)$aCmtInfo['cmt_id'], $oCmts);
     }
 
     /**
@@ -498,30 +478,11 @@ class BxBaseCmtsServices extends BxDol
         else
             $aSubentrySampleParams[] = '_undefined';
 
-        $iCmtId = (int)$aCmtInfo['cmt_id'];
-        $sCmtUrl = str_replace(BX_DOL_URL_ROOT, '{bx_url_root}', $oCmts->serviceGetLink($iCmtId));
-        $sCmtCaption = strmaxtextlen($oCmts->serviceGetText($iCmtId), 20, '...');
-
-        $sCmtUrlApi = '';
-        if(bx_is_api() && getParam('sys_api_comment_notif_link_content') == 'on') {
-            $aCmt = $oCmts->getCommentsBy(['type' => 'uniq_id', 'uniq_id' => $iCmtIdUnique]);
-            if(!empty($aCmt) && is_array($aCmt)) {
-                $oCmts->init($aCmt['cmt_object_id']);
-
-                $sCmtUrlApi = $oCmts->getBaseUrl('{bx_url_root}') . '#cid=' . $iCmtId;
-            }
-        }
-
-        return array(
-            'entry_sample' => $oCmts->getLanguageKey('txt_sample_single'),
-            'entry_url' => $sCmtUrl,
-            'entry_url_api' => $sCmtUrlApi,
-            'entry_caption' => $sCmtCaption,
+        return array_merge($this->_getNotificationsData($iCmtIdUnique, (int)$aCmtInfo['cmt_id'], $oCmts), [
             'entry_author' => $aCmtInfo['author_id'],
             'subentry_sample' => $oCmts->getLanguageKey('txt_sample_reaction_single'),
-            'subentry_sample_params' => $aSubentrySampleParams,
-            'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
-        );
+            'subentry_sample_params' => $aSubentrySampleParams
+        ]);
     }
 
     /**
@@ -556,7 +517,14 @@ class BxBaseCmtsServices extends BxDol
         if(!$oAction)
             return [];
 
-        $iCmtId = (int)$aCmtInfo['cmt_id'];
+        return array_merge($this->_getNotificationsData($iCmtIdUnique, (int)$aCmtInfo['cmt_id'], $oCmts), [
+            'entry_author' => $aCmtInfo['author_id'],
+            'subentry_sample' => $oCmts->getLanguageKey('txt_sample_' . $sAction . ($sType ? '_' . $sType : '') . '_single'),
+        ]);
+    }
+
+    protected function _getNotificationsData($iCmtIdUnique, $iCmtId, $oCmts)
+    {
         $sCmtUrl = str_replace(BX_DOL_URL_ROOT, '{bx_url_root}', $oCmts->serviceGetLink($iCmtId));
         $sCmtCaption = strmaxtextlen($oCmts->serviceGetText($iCmtId), 20, '...');
 
@@ -575,12 +543,10 @@ class BxBaseCmtsServices extends BxDol
             'entry_url' => $sCmtUrl,
             'entry_url_api' => $sCmtUrlApi,
             'entry_caption' => $sCmtCaption,
-            'entry_author' => $aCmtInfo['author_id'],
-            'subentry_sample' => $oCmts->getLanguageKey('txt_sample_' . $sAction . ($sType ? '_' . $sType : '') . '_single'),
             'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
         ];
     }
-    
+
     /**
      * @page service Service Calls
      * @section bx_system_cmts System Services 

+ 30 - 0
template/scripts/BxBaseFunctions.php

@@ -295,6 +295,36 @@ class BxBaseFunctions extends BxDolFactory implements iBxDolSingleton
         $aIcons = $this->getIcon($sCode, $aAttrs);
         return $aIcons[3] . $aIcons[4]; 
     }
+    
+    function getIconPreview($iId, $sIconImage = '', $sIcon = '')
+    {
+        $bIconImage = !empty($sIconImage);
+
+        $aIcons = $this->getIcon($sIcon);
+        $sIconHtml = $aIcons[2] . $aIcons[3] . $aIcons[4];
+        $bIconHtml = !empty($sIconHtml) && !$bIconImage;
+
+        return $this->_oTemplate->parseHtmlByName('item_icon_preview.html', [
+            'id' => $iId,
+            'bx_if:show_icon_empty' => [
+                'condition' => !$bIconImage && !$bIconHtml,
+                'content' => []
+            ],
+            'bx_if:show_icon_image' => [
+                'condition' => $bIconImage,
+                'content' => [
+                    'url' => $sIconImage,
+                    'id' => $iId
+                ]
+            ],
+            'bx_if:show_icon_html' => [
+                'condition' => $bIconHtml,
+                'content' => [
+                    'icon' => $sIconHtml
+                ]
+            ]
+        ]);
+    }
 
     function getTemplateIcon($sName)
     {

+ 61 - 93
template/scripts/BxBaseServicePages.php

@@ -36,55 +36,11 @@ class BxBaseServicePages extends BxDol
      */
     public function serviceGetPageByRequest ($sRequest, $sBlocks = '', $sParams = '')
     {
-        $mixed = null;
-
-        if (substr_count($sRequest, 'page/')> 0){
-            $_GET['i'] = str_replace('page/', '', $sRequest);
-            $aParams = json_decode($sParams, true);
-            if(!empty($aParams) && is_array($aParams))
-                $_GET = array_merge($_GET, $aParams);
-            
-            $mixed = BxDolPage::getObjectInstanceByURI();
-        }
-        else{
-            if(!empty($sParams)) {
-                $aParams = json_decode($sParams, true);
-                if(!empty($aParams) && is_array($aParams))
-                    $_GET = array_merge($_GET, $aParams);
-            }
-            $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);
-
-            $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]];
-
-            if(isLogged())
-                $aRes['data']['user'] = BxDolProfile::getDataForPage();
-        }
+        list($aRes, $aExtras) = $this->_getByRequest('page', $sRequest, $sBlocks, $sParams);
 
+        if(isset($aRes['code'], $aRes['data']) && (int)$aRes['code'] == 404 && isLogged())
+            $aRes['data']['user'] = BxDolProfile::getDataForPage();
+        
         $aExtras['data'] = &$aRes;
 
         /**
@@ -107,51 +63,7 @@ class BxBaseServicePages extends BxDol
 
     public function serviceGetPageContentByRequest ($sRequest, $sBlocks = '', $sParams = '')
     {
-        $mixed = null;
-
-        if (substr_count($sRequest, 'page/')> 0){
-            $_GET['i'] = str_replace('page/', '', $sRequest);
-            $aParams = json_decode($sParams, true);
-            if(!empty($aParams) && is_array($aParams))
-                $_GET = array_merge($_GET, $aParams);
-            
-            $mixed = BxDolPage::getObjectInstanceByURI();
-        }
-        else{
-            if(!empty($sParams)) {
-                $aParams = json_decode($sParams, true);
-                if(!empty($aParams) && is_array($aParams))
-                    $_GET = array_merge($_GET, $aParams);
-            }
-            $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);
-
-            $aRes = $oPage->getPageContentAPI($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]];
-        }
+        list($aRes, $aExtras) = $this->_getByRequest('page_content', $sRequest, $sBlocks, $sParams);
 
         $aExtras['data'] = &$aRes;
 
@@ -222,6 +134,62 @@ class BxBaseServicePages extends BxDol
         $oEmbed = BxDolEmbed::getObjectInstance('sys_system');
         return $oEmbed->getData($sUrl, '');
     }
+
+    protected function _getByRequest($sType, $sRequest, $sBlocks = '', $sParams = '')
+    {
+        $mixed = null;
+
+        if (substr_count($sRequest, 'page/')> 0){
+            $_GET['i'] = str_replace('page/', '', $sRequest);
+            $aParams = json_decode($sParams, true);
+            if(!empty($aParams) && is_array($aParams))
+                $_GET = array_merge($_GET, $aParams);
+            
+            $mixed = BxDolPage::getObjectInstanceByURI();
+        }
+        else{
+            if(!empty($sParams)) {
+                $aParams = json_decode($sParams, true);
+                if(!empty($aParams) && is_array($aParams))
+                    $_GET = array_merge($_GET, $aParams);
+            }
+            $mixed = BxDolPage::getPageBySeoLink($sRequest);
+        }
+
+        $aExtras = [
+            'request' => $sRequest,
+        ];
+
+        if(($sUrl = $mixed) && is_string($sUrl)) {
+            $aResult = ['redirect' => $sUrl];
+
+            $aExtras = array_merge($aExtras, [
+                'url' => $sUrl
+            ]);
+        }
+        else if(($oPage = $mixed) && is_object($oPage)) {
+            $aBlocks = [];
+            if(!empty($sBlocks))
+                $aBlocks = explode(',', $sBlocks);
+
+            $aResult = $oPage->{'get' . bx_gen_method_name($sType) . 'API'}($aBlocks);
+
+            $aExtras = array_merge($aExtras, [
+                'page' => $oPage,
+                'blocks' => $aBlocks
+            ]);
+        }
+        else
+            $aResult = [
+                'code' => 404, 
+                'error' => _t("_sys_request_page_not_found_cpt"), 
+                'data' => [
+                    'page_status' => 404
+                ]
+            ];
+
+        return [$aResult, $aExtras];
+    }
 }
 
 /** @} */