AntonLV 9 лет назад
Родитель
Сommit
e85fab993d

+ 56 - 70
inc/classes/BxDolTemplate.php

@@ -19,6 +19,14 @@ define('BX_DOL_TEMPLATE_CHECK_IN_BOTH', 'both');
 define('BX_DOL_TEMPLATE_CHECK_IN_BASE', 'base');
 define('BX_DOL_TEMPLATE_CHECK_IN_TMPL', 'tmpl');
 
+define('BX_DOL_TEMPLATE_TAG_I', 'i');
+define('BX_DOL_TEMPLATE_TAG_SPAN', 'span');
+define('BX_DOL_TEMPLATE_TAG_DIV', 'div');
+define('BX_DOL_TEMPLATE_TAG_IMG', 'img');
+define('BX_DOL_TEMPLATE_TAG_A', 'a');
+define('BX_DOL_TEMPLATE_TAG_BUTTON', 'button');
+define('BX_DOL_TEMPLATE_TAG_CUSTOM', 'custom');
+
 define('BX_DOL_COLOR_BG', 'bg');
 define('BX_DOL_COLOR_FT', 'ft');
 
@@ -247,7 +255,7 @@ class BxDolTemplate extends BxDolFactory implements iBxDolSingleton
         $this->_sFolderCss = 'css/';
         $this->_sFolderImages = 'images/';
         $this->_sFolderIcons = 'images/icons/';
-        $this->_aTemplates = array('menu_item_addon');
+        $this->_aTemplates = array('html_tags', 'menu_item_addon');
 
         $this->addLocation('system', $this->_sRootPath, $this->_sRootUrl);
 
@@ -1378,42 +1386,47 @@ class BxDolTemplate extends BxDolFactory implements iBxDolSingleton
         return $sRet;
     }
     
-    protected function _parseHtmlTag($sTemplate, $sContent, $aAttrs = array())
+    /**
+     * 
+     * Enter description here ...
+     * @param string $sName tag name (i, span, div, img, a, button, custom)
+     * @param string $sContent tag content (HTML)
+     * @param array $aAttrs an array of key - value pairs of attributes
+     * @param string $sTemplate
+     */
+    public function parseHtmlTag($sName, $sContent, $aAttrs = array(), $sTemplate = 'html_tags')
     {
+        $aTags = array(BX_DOL_TEMPLATE_TAG_I, BX_DOL_TEMPLATE_TAG_SPAN, BX_DOL_TEMPLATE_TAG_DIV, BX_DOL_TEMPLATE_TAG_IMG, BX_DOL_TEMPLATE_TAG_A, BX_DOL_TEMPLATE_TAG_BUTTON, BX_DOL_TEMPLATE_TAG_CUSTOM);
+
         $aTmplVarsAttrs = array();
         foreach($aAttrs as $sKey => $sValue)
             $aTmplVarsAttrs[] = array('key' => $sKey, 'value' => bx_html_attribute($sValue));
 
-        return $this->parseHtmlByContent($sTemplate, array(
-            'content' => $sContent,
-            'bx_repeat:attrs' => $aTmplVarsAttrs
-        ));
-    }
-
-	/**
-     * Parse tag <DIV>
-     * 
-     * @param string $sContent content
-     * @param array $aAttrs an array of key => value pairs
-     */
-    function parseDiv($sContent, $aAttrs = array())
-    {
-        $sTemplate = '<div <bx_repeat:attrs>__key__="__value__"</bx_repeat:attrs>>__content__</div>';
-
-        return $this->_parseHtmlTag($sTemplate, $sContent, $aAttrs);
-    }
+        $aTmplVars = array();
+        foreach($aTags as $sTag) {
+            $aTmplVarsTag = array();
+            $bTmplVarsTag = $sTag == $sName;
+            if($bTmplVarsTag)
+                $aTmplVarsTag = array(
+                    'content' => $sContent,
+                    'bx_repeat:attrs' => $aTmplVarsAttrs
+                );
+
+            $aTmplVars['bx_if:' . $sTag] = array(
+            	'condition' => $bTmplVarsTag,
+                'content' => $aTmplVarsTag
+            );
+        }
 
-	/**
-     * Parse tag <SPAN>
-     * 
-     * @param string $sContent content
-     * @param array $aAttrs an array of key => value pairs
-     */
-    function parseSpan($sContent, $aAttrs = array())
-    {
-        $sTemplate = '<span <bx_repeat:attrs>__key__="__value__"</bx_repeat:attrs>>__content__</span>';
+        $sMethod = '';
+        if(strpos($sTemplate, '.') !== false)
+            $sMethod = 'parseHtmlByName';
+        else if(array_key_exists($sTemplate, $this->_aTemplates))
+            $sMethod = 'parseHtmlByTemplateName';
+        else
+            $sMethod = 'parseHtmlByContent';
 
-        return $this->_parseHtmlTag($sTemplate, $sContent, $aAttrs);
+        return $this->$sMethod($sTemplate, $aTmplVars);
     }
 
     /**
@@ -1425,17 +1438,12 @@ class BxDolTemplate extends BxDolFactory implements iBxDolSingleton
      */
     function parseLink($sLink, $sContent, $aAttrs = array())
     {
-        $sTemplate = '<a href="__link__" <bx_repeat:attrs>__key__="__value__"</bx_repeat:attrs>>__content__</a>';
+        if(!is_array($aAttrs))
+            $aAttrs = array();
 
-        $aTmplVarsAttrs = array();
-        foreach($aAttrs as $sKey => $sValue)
-            $aTmplVarsAttrs[] = array('key' => $sKey, 'value' => bx_html_attribute($sValue));
+        $aAttrs['href'] = $sLink;
 
-        return $this->parseHtmlByContent($sTemplate, array(
-            'link' => $sLink,
-            'content' => $sContent,
-            'bx_repeat:attrs' => $aTmplVarsAttrs
-        ));
+        return $this->parseHtmlTag(BX_DOL_TEMPLATE_TAG_A, $sContent, $aAttrs);
     }
 
     /**
@@ -1446,16 +1454,7 @@ class BxDolTemplate extends BxDolFactory implements iBxDolSingleton
      */
     function parseButton($sContent, $aAttrs = array())
     {
-        $sTemplate = '<button <bx_repeat:attrs>__key__="__value__"</bx_repeat:attrs>>__content__</button>';
-
-        $aTmplVarsAttrs = array();
-        foreach($aAttrs as $sKey => $sValue)
-            $aTmplVarsAttrs[] = array('key' => $sKey, 'value' => bx_html_attribute($sValue));
-
-        return $this->parseHtmlByContent($sTemplate, array(
-            'content' => $sContent,
-            'bx_repeat:attrs' => $aTmplVarsAttrs
-        ));
+        return $this->parseHtmlTag(BX_DOL_TEMPLATE_TAG_BUTTON, $sContent, $aAttrs);
     }
 
     /**
@@ -1466,16 +1465,12 @@ class BxDolTemplate extends BxDolFactory implements iBxDolSingleton
      */
     function parseImage($sLink, $aAttrs = array())
     {
-        $sTemplate = '<img src="__link__" <bx_repeat:attrs>__key__="__value__"</bx_repeat:attrs> />';
+        if(!is_array($aAttrs))
+            $aAttrs = array();
 
-        $aTmplVarsAttrs = array();
-        foreach($aAttrs as $sKey => $sValue)
-            $aTmplVarsAttrs[] = array('key' => $sKey, 'value' => bx_html_attribute($sValue));
+        $aAttrs['src'] = $sLink;
 
-        return $this->parseHtmlByContent($sTemplate, array(
-            'link' => $sLink,
-            'bx_repeat:attrs' => $aTmplVarsAttrs
-        ));
+        return $this->parseHtmlTag(BX_DOL_TEMPLATE_TAG_IMG, '', $aAttrs);
     }
 
     /**
@@ -1486,21 +1481,12 @@ class BxDolTemplate extends BxDolFactory implements iBxDolSingleton
      */
     function parseIcon($sName, $aAttrs = array())
     {
-        $sTemplate = '<i class="sys-icon __name__"  <bx_repeat:attrs>__key__="__value__"</bx_repeat:attrs>></i>';
-
-        if(!empty($aAttrs['class'])) {
-            $sName .= ' ' . $aAttrs['class'];
-            unset($aAttrs['class']);
-        }
+        if(!is_array($aAttrs))
+            $aAttrs = array();
 
-        $aTmplVarsAttrs = array();
-        foreach($aAttrs as $sKey => $sValue)
-            $aTmplVarsAttrs[] = array('key' => $sKey, 'value' => bx_html_attribute($sValue));
+        $aAttrs['class'] = 'sys-icon ' . $sName . (!empty($aAttrs['class']) ? ' ' . $aAttrs['class'] : '');
 
-        return $this->parseHtmlByContent($sTemplate, array(
-            'name' => $sName,
-            'bx_repeat:attrs' => $aTmplVarsAttrs
-        ));
+        return $this->parseHtmlTag(BX_DOL_TEMPLATE_TAG_I, '', $aAttrs);
     }
 
     function getCacheFilePrefix($sType)

+ 12 - 26
modules/base/text/classes/BxBaseModTextMenuSnippetMeta.php

@@ -31,19 +31,6 @@ class BxBaseModTextMenuSnippetMeta extends BxTemplMenuCustom
         $this->_aContentInfo = $this->_oModule->_oDb->getContentInfoById($this->_iContentId);
         if($this->_aContentInfo)
             $this->addMarkers(array('content_id' => (int)$this->_iContentId));
-    }  
-    
-    protected function _getMenuItem ($aItem)
-    {
-        $mixedResult = parent::_getMenuItem($aItem);
-        if(empty($mixedResult) || !is_array($mixedResult))
-            return $mixedResult;
-
-        $mixedResult['item'] = $this->_oTemplate->parseSpan('&#183;&nbsp;', array(
-        	'class' => 'bx-base-text-unit-meta-div bx-def-font-grayed'
-        )) . $mixedResult['item'];
-        
-        return $mixedResult;
     }
 
     protected function _getMenuItemAuthor($aItem)
@@ -54,18 +41,17 @@ class BxBaseModTextMenuSnippetMeta extends BxTemplMenuCustom
         if(!$oProfile) 
             $oProfile = BxDolProfileUndefined::getInstance();
 
-        $sAuthor = $oProfile->getDisplayName();
-		$sAuthorUrl = $oProfile->getUrl();
-        return $this->_oTemplate->parseLink($sAuthorUrl, $sAuthor, array('class' => 'bx-base-text-unit-author'));
+        return $this->_oTemplate->getUnitMetaItemLink($oProfile->getDisplayName(), array(
+            'href' => $oProfile->getUrl(),
+            'class' => 'bx-base-text-unit-author'
+        ));
     }
 
     protected function _getMenuItemDate($aItem)
     {
         $CNF = &$this->_oModule->_oConfig->CNF;
 
-        return $this->_oTemplate->parseSpan(bx_time_js($this->_aContentInfo[$CNF['FIELD_ADDED']], BX_FORMAT_DATE), array(
-        	'class' => 'bx-def-font-grayed'
-        ));
+        return $this->_oTemplate->getUnitMetaItemText(bx_time_js($this->_aContentInfo[$CNF['FIELD_ADDED']], BX_FORMAT_DATE));
     }
 
     protected function _getMenuItemCategory($aItem)
@@ -80,7 +66,7 @@ class BxBaseModTextMenuSnippetMeta extends BxTemplMenuCustom
             return false;
 
         $sTitle = $oCategory->getCategoryTitle($this->_aContentInfo[$CNF['FIELD_CATEGORY']]);
-        return $oCategory->getCategoryLink($sTitle, $this->_aContentInfo[$CNF['FIELD_CATEGORY']]);
+        return $this->_oTemplate->getUnitMetaItemCustom($oCategory->getCategoryLink($sTitle, $this->_aContentInfo[$CNF['FIELD_CATEGORY']]));
     }
 
     protected function _getMenuItemTags($aItem)
@@ -94,7 +80,7 @@ class BxBaseModTextMenuSnippetMeta extends BxTemplMenuCustom
         if(!$oMetatags || !$oMetatags->keywordsIsEnabled())
             return false;
 
-        return $oMetatags->getKeywordsList($this->_aContentInfo[$CNF['FIELD_ID']], 3);
+        return $this->_oTemplate->getUnitMetaItemCustom($oMetatags->getKeywordsList($this->_aContentInfo[$CNF['FIELD_ID']], 3));
     }
 
     protected function _getMenuItemViews($aItem)
@@ -104,9 +90,7 @@ class BxBaseModTextMenuSnippetMeta extends BxTemplMenuCustom
         if(empty($CNF['FIELD_VIEWS']) || empty($this->_aContentInfo[$CNF['FIELD_VIEWS']]))
             return false;
 
-        return $this->_oTemplate->parseSpan(_t('_view_n_views', $this->_aContentInfo[$CNF['FIELD_VIEWS']]), array(
-        	'class' => 'bx-def-font-grayed'
-        ));
+        return $this->_oTemplate->getUnitMetaItemText(_t('_view_n_views', $this->_aContentInfo[$CNF['FIELD_VIEWS']]));
     }
 
     protected function _getMenuItemRating($aItem)
@@ -120,7 +104,7 @@ class BxBaseModTextMenuSnippetMeta extends BxTemplMenuCustom
         if(!$oVotes)
             return false;
 
-        return $oVotes->getElementInline(array('show_counter' => true));
+        return $this->_oTemplate->getUnitMetaItemCustom($oVotes->getElementInline(array('show_counter' => true)));
     }
 
     protected function _getMenuItemComments($aItem)
@@ -134,7 +118,9 @@ class BxBaseModTextMenuSnippetMeta extends BxTemplMenuCustom
         if(!$oComments || !$oComments->isEnabled())
             return false;
 
-        return $this->_oTemplate->parseLink($oComments->getListUrl(), _t('_cmt_txt_n_comments', $this->_aContentInfo[$CNF['FIELD_COMMENTS']]));
+        return $this->_oTemplate->getUnitMetaItemLink(_t('_cmt_txt_n_comments', $this->_aContentInfo[$CNF['FIELD_COMMENTS']]), array(
+            'href' => $oComments->getListUrl()
+        ));
     }
 }
 

+ 21 - 1
modules/base/text/classes/BxBaseModTextTemplate.php

@@ -28,6 +28,26 @@ class BxBaseModTextTemplate extends BxBaseModGeneralTemplate
 		return $this->parseHtmlByName($sTemplateName, $this->getUnit($aData, $aParams));
     }
 
+    function getUnitMetaItemLink($sContent, $aAttrs = array())
+    {
+        return $this->parseHtmlTag(BX_DOL_TEMPLATE_TAG_A, $sContent, $aAttrs, 'unit_meta_item.html');
+    }
+
+    function getUnitMetaItemText($sContent, $aAttrs = array())
+    {
+        if(!is_array($aAttrs))
+            $aAttrs = array();
+
+        $aAttrs['class'] = (!empty($aAttrs['class']) ? $aAttrs['class'] . ' ' : '') . 'bx-def-font-grayed';
+
+        return $this->parseHtmlTag(BX_DOL_TEMPLATE_TAG_SPAN, $sContent, $aAttrs, 'unit_meta_item.html');
+    }
+
+    function getUnitMetaItemCustom($sContent)
+    {
+        return $this->parseHtmlTag(BX_DOL_TEMPLATE_TAG_CUSTOM, $sContent, array(), 'unit_meta_item.html');
+    }
+
     function entryAuthor ($aData, $iProfileId = false, $sFuncAuthorDesc = 'getAuthorDesc', $sTemplateName = 'author.html', $sFuncAuthorAddon = 'getAuthorAddon')
     {
         $CNF = &$this->getModule()->_oConfig->CNF;
@@ -169,7 +189,7 @@ class BxBaseModTextTemplate extends BxBaseModGeneralTemplate
             $oMenuMeta = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SNIPPET_META'], $this);
             if($oMenuMeta) {
                 $oMenuMeta->setContentId($aData[$CNF['FIELD_ID']]);
-                $sMeta = $this->parseDiv($oMenuMeta->getCode(), array(
+                $sMeta = $this->parseHtmlTag(BX_DOL_TEMPLATE_TAG_DIV, $oMenuMeta->getCode(), array(
                     'class' => 'bx-base-text-unit-meta' 
                 ));
             }

+ 3 - 0
modules/base/text/template/unit_meta_item.html

@@ -0,0 +1,3 @@
+<bx_if:span><span class="bx-base-text-unit-meta-div bx-def-font-grayed">&#183;&nbsp;</span><span <bx_repeat:attrs>__key__="__value__"</bx_repeat:attrs>>__content__</span></bx_if:span>
+<bx_if:a><span class="bx-base-text-unit-meta-div bx-def-font-grayed">&#183;&nbsp;</span><a <bx_repeat:attrs>__key__="__value__"</bx_repeat:attrs>>__content__</a></bx_if:a>
+<bx_if:custom><span class="bx-base-text-unit-meta-div bx-def-font-grayed">&#183;&nbsp;</span>__content__</bx_if:custom>

+ 1 - 1
modules/boonex/albums/classes/BxAlbumsTemplate.php

@@ -66,7 +66,7 @@ class BxAlbumsTemplate extends BxBaseModTextTemplate
             $oMenuMeta = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SNIPPET_META'], $this);
             if($oMenuMeta) {
                 $oMenuMeta->setContentId($aData[$CNF['FIELD_ID']]);
-                $sMeta = $this->parseDiv($oMenuMeta->getCode(), array(
+                $sMeta = $this->parseHtmlTag(BX_DOL_TEMPLATE_TAG_DIV, $oMenuMeta->getCode(), array(
                 	'class' => 'bx-base-text-unit-meta' 
                 ));
             }

+ 1 - 0
modules/boonex/albums/template/unit_meta_item.html

@@ -0,0 +1 @@
+<bx_include_base:../modules/base/text/template/unit_meta_item.html />

+ 1 - 0
modules/boonex/files/template/unit_meta_item.html

@@ -0,0 +1 @@
+<bx_include_base:../modules/base/text/template/unit_meta_item.html />

+ 1 - 1
modules/boonex/market/classes/BxMarketMenuSnippetMeta.php

@@ -26,7 +26,7 @@ class BxMarketMenuSnippetMeta extends BxBaseModTextMenuSnippetMeta
         if(!$oProfile) 
             $oProfile = BxDolProfileUndefined::getInstance();
 
-        return $this->_oTemplate->parseSpan($oProfile->getDisplayName(), array('class' => 'bx-def-font-grayed'));
+        return $this->_oTemplate->getUnitMetaItemText($oProfile->getDisplayName());
     }
 }
 

+ 1 - 0
modules/boonex/market/template/unit_meta_item.html

@@ -0,0 +1 @@
+<bx_include_base:../modules/base/text/template/unit_meta_item.html />

+ 1 - 0
modules/boonex/polls/template/unit_meta_item.html

@@ -0,0 +1 @@
+<bx_include_base:../modules/base/text/template/unit_meta_item.html />

+ 1 - 0
modules/boonex/posts/template/unit_meta_item.html

@@ -0,0 +1 @@
+<bx_include_base:../modules/base/text/template/unit_meta_item.html />

+ 1 - 0
modules/boonex/shopify/template/unit_meta_item.html

@@ -0,0 +1 @@
+<bx_include_base:../modules/base/text/template/unit_meta_item.html />

+ 1 - 0
modules/boonex/snipcart/template/unit_meta_item.html

@@ -0,0 +1 @@
+<bx_include_base:../modules/base/text/template/unit_meta_item.html />

+ 1 - 0
modules/boonex/videos/template/unit_meta_item.html

@@ -0,0 +1 @@
+<bx_include_base:../modules/base/text/template/unit_meta_item.html />

+ 1 - 1
template/metatags_keywords_list.html

@@ -1,3 +1,3 @@
 <span class="bx-metatags-keywords-list">
-	<bx_repeat:units><a class="bx-metatags-keyword" href="__href__">__keyword__</a></bx_repeat:units>
+	<bx_repeat:units> <a class="bx-metatags-keyword" href="__href__">__keyword__</a></bx_repeat:units>
 </span>