Преглед изворни кода

Ticket #367 - Metatags improvements.

AntonLV пре 10 година
родитељ
комит
aa1657150d

+ 3 - 1
inc/classes/BxDolMetatags.php

@@ -159,7 +159,9 @@ class BxDolMetatags extends BxDol implements iBxDolFactoryObject
         if (!$aObject || !is_array($aObject))
             return false;
 
-        $sClass = $aObject['override_class_name'] ? $aObject['override_class_name'] : 'BxDolMetatags';
+        $sClass = 'BxTemplMetatags';
+        if (!empty($aObject['override_class_name']))
+            $sClass = $aObject['override_class_name'];
         if (!empty($aObject['override_class_file']))
             require_once(BX_DIRECTORY_PATH_ROOT . $aObject['override_class_file']);
 

+ 17 - 0
modules/boonex/air/data/template/system/scripts/BxTemplMetatags.php

@@ -0,0 +1,17 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    TridentCore Trident Core
+ * @{
+ */
+
+/**
+ * @see BxDolMetatags
+ */
+class BxTemplMetatags extends BxBaseMetatags
+{
+}
+
+/** @} */

+ 17 - 0
modules/boonex/ocean/data/template/system/scripts/BxTemplMetatags.php

@@ -0,0 +1,17 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    TridentCore Trident Core
+ * @{
+ */
+
+/**
+ * @see BxDolMetatags
+ */
+class BxTemplMetatags extends BxBaseMetatags
+{
+}
+
+/** @} */

+ 17 - 0
modules/boonex/protean/data/template/system/scripts/BxTemplMetatags.php

@@ -0,0 +1,17 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    TridentCore Trident Core
+ * @{
+ */
+
+/**
+ * @see BxDolMetatags
+ */
+class BxTemplMetatags extends BxBaseMetatags
+{
+}
+
+/** @} */

+ 105 - 0
template/scripts/BxBaseMetatags.php

@@ -0,0 +1,105 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    TridentCore Trident Core
+ * @{
+ */
+
+/**
+ * Metatags objects representation.
+ * 
+ * @see BxDolMetatags
+ */
+class BxBaseMetatags extends BxDolMetatags
+{
+    protected $_oTemplate;
+
+    protected $_sBrowseUrl;
+    protected $_iKeywordsCloudFontSizeMin = 14;
+    protected $_iKeywordsCloudFontSizeMax = 32;
+
+    public function __construct ($aObject, $oTemplate = null)
+    {
+        parent::__construct ($aObject);
+
+        if ($oTemplate)
+            $this->_oTemplate = $oTemplate;
+        else
+            $this->_oTemplate = BxDolTemplate::getInstance();
+
+		$this->_sBrowseUrl = bx_append_url_params('searchKeyword.php', array(
+    		'type' => 'keyword', 
+    		'keyword' => '{keyword}'
+    	)) . '{sections}';
+    }
+
+    public function getKeywordsCloud($mixedSection, $iMaxCount)
+    {
+        $aKeywords = $this->keywordsPopularList($iMaxCount);
+        if(!$aKeywords)
+			return '';
+
+        ksort($aKeywords, SORT_LOCALE_STRING);
+
+        $iFontDiff = floor($this->_iKeywordsCloudFontSizeMax - $this->_iKeywordsCloudFontSizeMin);
+        $iMinRating = min($aKeywords);
+        $iMaxRating = max($aKeywords);
+
+        $iRatingDiff = $iMaxRating - $iMinRating;
+        $iRatingDiff = $iRatingDiff == 0 ? 1 : $iRatingDiff;
+
+        $sSectionPart = '';
+        if (is_array($mixedSection))
+            $sSectionPart = '&section[]=' . implode('&section[]=', $mixedSection);
+        elseif (is_string($mixedSection))
+            $sSectionPart = '&section[]=' . $mixedSection;
+
+        $aUnits = array();
+        foreach($aKeywords as $sKeyword => $iCount) {
+            $aUnits[] = array(
+                'size' => $this->_iKeywordsCloudFontSizeMin + floor($iFontDiff * (($iCount - $iMinRating) / $iRatingDiff)),
+                'href' => BX_DOL_URL_ROOT . bx_replace_markers($this->_sBrowseUrl, array(
+            		'keyword' => rawurlencode($sKeyword),
+            		'sections' => $sSectionPart
+            	)),
+                'count' => $iCount,
+                'keyword' => htmlspecialchars_adv($sKeyword),
+            );
+        }
+
+        $aVars = array (
+            'bx_repeat:units' => $aUnits,
+        );
+
+        $this->addCssJs();
+        return $this->_oTemplate->parseHtmlByName('metatags_keywords_cloud.html', $aVars);
+    }
+
+	public function getLocationsMap($iId, $sMapSize = '1000x144')
+    {
+        $sLocationHtml = $this->locationsString($iId);
+        if(!$sLocationHtml)
+			return '';
+
+		$sMapKey = trim(getParam('sys_maps_api_key'));
+        $sLocationEncoded = rawurlencode(strip_tags($sLocationHtml));
+        $sProto = (0 == strncmp('https', BX_DOL_URL_ROOT, 5)) ? 'https' : 'http';
+        $iScale = isset($_COOKIE['devicePixelRatio']) && (int)$_COOKIE['devicePixelRatio'] >= 2 ? 2 : 1;
+        $sLang = bx_lang_name();
+
+        $this->addCssJs();
+        return $this->_oTemplate->parseHtmlByName('metatags_locations_map.html', array (
+            'map_img' => $sProto . '://maps.googleapis.com/maps/api/staticmap?center=' . $sLocationEncoded . '&zoom=7&size=' . $sMapSize . '&maptype=roadmap&markers=size:small%7C' . $sLocationEncoded . '&scale=' . $iScale . '&language=' . $sLang  . ($sMapKey ? '&key=' . $sMapKey : ''),
+            'location_string' => $sLocationHtml,
+        ));
+    }
+
+    public function addCssJs()
+    {
+        $this->_oTemplate->addCss('metatags.css');
+    }
+}
+
+/** @} */

+ 7 - 71
template/scripts/BxBaseServiceMetatags.php

@@ -14,9 +14,6 @@ define('BX_METATAGS_KEYWORDS_IN_CLOUD', 32); ///< default number of tags in tags
  */
 class BxBaseServiceMetatags extends BxDol
 {
-    protected $_iKeywordsCloudFontSizeMin = 14;
-    protected $_iKeywordsCloudFontSizeMax = 32;
-
     public function __construct()
     {
         parent::__construct();
@@ -29,54 +26,16 @@ class BxBaseServiceMetatags extends BxDol
      * @param $iMaxCount number of tags in keywords cloud, by default @see BX_METATAGS_KEYWORDS_IN_CLOUD
      * @return tags cloud HTML string
      */
-    public function serviceKeywordsCloud ($sObject, $mixedSection, $aParams = array())
+    public function serviceKeywordsCloud($sObject, $mixedSection, $aParams = array())
     {
     	$iMaxCount = isset($aParams['max_count']) ? (int)$aParams['max_count'] : BX_METATAGS_KEYWORDS_IN_CLOUD;
     	$bShowEmpty = isset($aParams['show_empty']) ? (bool)$aParams['show_empty'] : false;
-    	$sBrowseUrl = isset($aParams['browse_url']) ? $aParams['browse_url'] : bx_append_url_params('searchKeyword.php', array(
-    		'type' => 'keyword', 
-    		'keyword' => '{keyword}'
-    	)) . '{sections}';
-
-        $o = BxDolMetatags::getObjectInstance($sObject);
-        $aKeywords = $o->keywordsPopularList($iMaxCount);
-        if (!$aKeywords)
-            return $bShowEmpty ? MsgBox(_t('_Empty')) : '';
-
-        ksort($aKeywords, SORT_LOCALE_STRING);
-
-        $iFontDiff = floor($this->_iKeywordsCloudFontSizeMax - $this->_iKeywordsCloudFontSizeMin);
-        $iMinRating = min($aKeywords);
-        $iMaxRating = max($aKeywords);
-
-        $iRatingDiff = $iMaxRating - $iMinRating;
-        $iRatingDiff = $iRatingDiff == 0 ? 1 : $iRatingDiff;
-
-        $sSectionPart = '';
-        if (is_array($mixedSection))
-            $sSectionPart = '&section[]=' . implode('&section[]=', $mixedSection);
-        elseif (is_string($mixedSection))
-            $sSectionPart = '&section[]=' . $mixedSection;
-
-        $aUnits = array();
-        foreach($aKeywords as $sKeyword => $iCount) {
-            $aUnits[] = array(
-                'size' => $this->_iKeywordsCloudFontSizeMin + floor($iFontDiff * (($iCount - $iMinRating) / $iRatingDiff)),
-                'href' => BX_DOL_URL_ROOT . bx_replace_markers($sBrowseUrl, array(
-            		'keyword' => rawurlencode($sKeyword),
-            		'sections' => $sSectionPart
-            	)),
-                'count' => $iCount,
-                'keyword' => htmlspecialchars_adv($sKeyword),
-            );
-        }
 
-        $aVars = array (
-            'bx_repeat:units' => $aUnits,
-        );
+        $sResult = BxDolMetatags::getObjectInstance($sObject)->getKeywordsCloud($mixedSection, $iMaxCount);
+        if(empty($sResult))
+			return $bShowEmpty ? MsgBox(_t('_Empty')) : '';
 
-        $this->addCssJs();
-        return BxDolTemplate::getInstance()->parseHtmlByName('metatags_keywords_cloud.html', $aVars);
+		return $sResult;
     }
 
     /**
@@ -85,32 +44,9 @@ class BxBaseServiceMetatags extends BxDol
      * @param $iId content id
      * @return map HTML string
      */
-    public function serviceLocationsMap ($sObject, $iId, $sMapSize = '1000x144')
-    {
-        $sMapKey = trim(getParam('sys_maps_api_key'));
-
-        $o = BxDolMetatags::getObjectInstance($sObject);
-        $sLocationHtml = $o->locationsString($iId);
-        if (!$sLocationHtml)
-            return '';
-
-        $sLocationEncoded = rawurlencode(strip_tags($sLocationHtml));
-        $sProto = (0 == strncmp('https', BX_DOL_URL_ROOT, 5)) ? 'https' : 'http';
-        $iScale = isset($_COOKIE['devicePixelRatio']) && (int)$_COOKIE['devicePixelRatio'] >= 2 ? 2 : 1;
-        $sLang = bx_lang_name();
-        $aVars = array (
-            'map_img' => $sProto . '://maps.googleapis.com/maps/api/staticmap?center=' . $sLocationEncoded . '&zoom=7&size=' . $sMapSize . '&maptype=roadmap&markers=size:small%7C' . $sLocationEncoded . '&scale=' . $iScale . '&language=' . $sLang  . ($sMapKey ? '&key=' . $sMapKey : ''),
-            'location_string' => $sLocationHtml,
-        );
-
-        $this->addCssJs();
-        return BxDolTemplate::getInstance()->parseHtmlByName('metatags_locations_map.html', $aVars);
-    }
-
-    public function addCssJs()
+    public function serviceLocationsMap($sObject, $iId, $sMapSize = '1000x144')
     {
-        $oTemplate = BxDolTemplate::getInstance();
-        $oTemplate->addCss('metatags.css');
+        return BxDolMetatags::getObjectInstance($sObject)->getLocationsMap($iId, $sMapSize);
     }
 }