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

#87 - popular keywords (like tags cloud) block

Alex Trofimov 12 лет назад
Родитель
Сommit
e03fdd577a

+ 4 - 0
inc/classes/BxDolMetatags.php

@@ -269,6 +269,10 @@ class BxDolMetatags extends BxDol implements iBxDolFactoryObject
         );
     }
 
+    public function keywordsPopularList($iLimit)
+    {
+        return $this->_oQuery->keywordsPopularList($iLimit);
+    }
 
 
     /**

+ 6 - 0
inc/classes/BxDolMetatagsQuery.php

@@ -58,6 +58,12 @@ class BxDolMetatagsQuery extends BxDolDb
         return $this->getColumn($sQuery);
     }
 
+    public function keywordsPopularList($iLimit)
+    {
+        $sQuery = $this->prepare("SELECT `keyword`, COUNT(*) as `count` FROM `{$this->_aObject['table_keywords']}` GROUP BY `keyword` ORDER BY `count` DESC LIMIT ?", $iLimit);
+        return $this->getPairs($sQuery, 'keyword', 'count');
+    }    
+
 
 
     public function locationsAdd($mixedContentId, $fLat, $fLng, $sCountryCode, $sState, $sCity, $sZip)

+ 19 - 0
modules/boonex/lagoon/data/template/system/scripts/BxTemplServiceMetatags.php

@@ -0,0 +1,19 @@
+<?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
+ * @{
+ */
+
+bx_import('BxBaseServiceMetatags');
+
+/**
+ * @see BxBaseServiceMetatags
+ */
+class BxTemplServiceMetatags extends BxBaseServiceMetatags
+{
+}
+
+/** @} */

+ 19 - 0
modules/boonex/ocean/data/template/system/scripts/BxTemplServiceMetatags.php

@@ -0,0 +1,19 @@
+<?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
+ * @{
+ */
+
+bx_import('BxBaseServiceMetatags');
+
+/**
+ * @see BxBaseServiceMetatags
+ */
+class BxTemplServiceMetatags extends BxBaseServiceMetatags
+{
+}
+
+/** @} */

+ 1 - 0
modules/boonex/posts/install/langs/en.xml

@@ -75,6 +75,7 @@
 	<string name="_bx_posts_page_title_sys_manage"><![CDATA[Manage Posts]]></string>
 	<string name="_bx_posts_page_title_manage"><![CDATA[Manage Posts]]></string>
 	<string name="_bx_posts_page_block_title_manage"><![CDATA[Manage Posts]]></string>    
+	<string name="_bx_posts_page_block_title_popular_keywords"><![CDATA[Popular Keywords]]></string>
 
     <string name="_bx_posts_menu_set_title_view_entry"><![CDATA[View Post]]></string>
     <string name="_bx_posts_menu_title_view_entry"><![CDATA[View Post]]></string>

+ 5 - 4
modules/boonex/posts/install/sql/enable.sql

@@ -86,11 +86,12 @@ INSERT INTO `sys_pages_blocks`(`object`, `cell_id`, `module`, `title`, `designbo
 
 -- PAGE: module home
 
-INSERT INTO `sys_objects_page`(`object`, `title_system`, `title`, `module`, `layout_id`, `visible_for_levels`, `visible_for_levels_editable`, `uri`, `url`, `meta_description`, `meta_keywords`, `meta_robots`, `cache_lifetime`, `cache_editable`, `deletable`, `override_class_name`, `override_class_file`) VALUES 
-('bx_posts_home', '_bx_posts_page_title_sys_home', '_bx_posts_page_title_home', 'bx_posts', 5, 2147483647, 1, 'posts-home', 'page.php?i=posts-home', '', '', '', 0, 1, 0, 'BxPostsPageBrowse', 'modules/boonex/posts/classes/BxPostsPageBrowse.php');
+INSERT INTO `sys_objects_page`(`object`, `uri`, `title_system`, `title`, `module`, `layout_id`, `visible_for_levels`, `visible_for_levels_editable`, `url`, `meta_description`, `meta_keywords`, `meta_robots`, `cache_lifetime`, `cache_editable`, `deletable`, `override_class_name`, `override_class_file`) VALUES 
+('bx_posts_home', 'posts-home', '_bx_posts_page_title_sys_home', '_bx_posts_page_title_home', 'bx_posts', 2, 2147483647, 1, 'page/posts-home', '', '', '', 0, 1, 0, 'BxPostsPageBrowse', 'modules/boonex/posts/classes/BxPostsPageBrowse.php');
 
-INSERT INTO `sys_pages_blocks`(`object`, `cell_id`, `module`, `title`, `designbox_id`, `visible_for_levels`, `type`, `content`, `deletable`, `copyable`, `order`) VALUES 
-('bx_posts_home', 1, 'bx_posts', '_bx_posts_page_block_title_recent_entries', 11, 2147483647, 'service', 'a:2:{s:6:\"module\";s:8:\"bx_posts\";s:6:\"method\";s:13:\"browse_public\";}', 0, 1, 0);
+INSERT INTO `sys_pages_blocks`(`object`, `cell_id`, `module`, `title`, `designbox_id`, `visible_for_levels`, `type`, `content`, `deletable`, `copyable`, `active`, `order`) VALUES 
+('bx_posts_home', 1, 'bx_posts', '_bx_posts_page_block_title_recent_entries', 11, 2147483647, 'service', 'a:2:{s:6:\"module\";s:8:\"bx_posts\";s:6:\"method\";s:13:\"browse_public\";}', 0, 1, 1, 0),
+('bx_posts_home', 2, 'bx_posts', '_bx_posts_page_block_title_popular_keywords', 11, 2147483647, 'service', 'a:4:{s:6:\"module\";s:6:\"system\";s:6:\"method\";s:14:\"keywords_cloud\";s:6:\"params\";a:1:{i:0;s:8:\"bx_posts\";}s:5:\"class\";s:20:\"TemplServiceMetatags\";}', 0, 1, 1, 0);
 
 -- PAGE: module manage
 INSERT INTO `sys_objects_page`(`object`, `title_system`, `title`, `module`, `layout_id`, `visible_for_levels`, `visible_for_levels_editable`, `uri`, `url`, `meta_description`, `meta_keywords`, `meta_robots`, `cache_lifetime`, `cache_editable`, `deletable`, `override_class_name`, `override_class_file`) VALUES 

+ 8 - 0
template/css/metatags.css

@@ -0,0 +1,8 @@
+.bx-metatags-keywords-container {
+    text-align:center;
+}
+
+.bx-metatags-keyword {
+    line-height:2rem;
+    margin: 0 0.25rem 0 0;
+}

+ 5 - 0
template/metatags_keywords_cloud.html

@@ -0,0 +1,5 @@
+<div class="bx-metatags-keywords-container">
+<bx_repeat:units>
+    <a class="bx-metatags-keyword" href="__href__" style="font-size:__size__px;" title="<bx_text_attribute:_Count />: __count__">__keyword__</a>
+</bx_repeat:units>
+</div>

+ 73 - 0
template/scripts/BxBaseServiceMetatags.php

@@ -0,0 +1,73 @@
+<?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
+ * @{
+ */
+
+define('BX_METATAGS_KEYWORDS_IN_CLOUD', 32); ///< default number of tags in tags cloud
+
+/**
+ * System services for metatags functionality.
+ */
+class BxBaseServiceMetatags extends BxDol
+{
+    protected $_iKeywordsCloudFontSizeMin = 14;
+    protected $_iKeywordsCloudFontSizeMax = 32;
+
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    /**
+     * Get keywords cloud.
+     * @param $sObject metatgs object to get keywords cloud for
+     * @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, $iMaxCount = BX_METATAGS_KEYWORDS_IN_CLOUD)
+    {
+        bx_import('BxDolMetatags');
+        $o = BxDolMetatags::getObjectInstance($sObject);
+        $aKeywords = $o->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;
+
+        $aUnits = array();
+        foreach($aKeywords as $sKeyword => $iCount) {
+            $aUnits[] = array(
+                'size' => $this->_iKeywordsCloudFontSizeMin + floor($iFontDiff * (($iCount - $iMinRating) / $iRatingDiff)),
+                'href' => BX_DOL_URL_ROOT . 'searchKeyword.php?type=keyword&keyword=' . rawurlencode($sKeyword),
+                'count' => $iCount,
+                'keyword' => htmlspecialchars_adv($sKeyword),
+            );
+        }
+
+        $aVars = array (
+            'bx_repeat:units' => $aUnits,
+        );
+
+        $this->addCssJs();
+        return BxDolTemplate::getInstance()->parseHtmlByName('metatags_keywords_cloud.html', $aVars);
+    }
+
+    public function addCssJs()
+    {
+        $oTemplate = BxDolTemplate::getInstance();
+        $oTemplate->addCss('metatags.css');
+    }
+}
+
+/** @} */