Ver Fonte

#2579 Search in pages blocks

Alex Trofimov há 6 anos atrás
pai
commit
7d1016c5d8

+ 11 - 5
inc/classes/BxDolAcl.php

@@ -199,13 +199,19 @@ class BxDolAcl extends BxDolFactory implements iBxDolSingleton
         if(!$iPermissions)
             return false;
 
-        if(false === $iProfileId) {
-            $oProfile = BxDolProfile::getInstance();
-            $iProfileId = $oProfile ? $oProfile->id() : 0;
-        }
+        return ($iPermissions & $this->getMemberLevelBit($iProfileId));
+    }
+
+    /**
+     * Get user's membership level bit for bitwise operarions
+     */
+    public function getMemberLevelBit($iProfileId = 0)
+    {
+        if (!$iProfileId)
+            $iProfileId = bx_get_logged_profile_id();
 
         $aACL = $this->getMemberMembershipInfo($iProfileId);
-        return ($iPermissions & pow(2, $aACL['id'] - 1));
+        return pow(2, $aACL['id'] - 1);
     }
 
     /**

+ 8 - 1
install/sql/system.sql

@@ -1118,6 +1118,9 @@ CREATE TABLE `sys_objects_search` (
   PRIMARY KEY  (`ID`)
 );
 
+INSERT INTO `sys_objects_search` (`ObjectName`, `Title`, `Order`, `ClassName`, `ClassPath`) VALUES
+('sys_pages', '_sys_pages', 1, 'BxTemplPagesSearchResult', '');
+
 -- --------------------------------------------------------
 
 --
@@ -4686,11 +4689,15 @@ CREATE TABLE IF NOT EXISTS `sys_pages_blocks` (
   `hidden_on` varchar(255) NOT NULL DEFAULT '',
   `type` enum('raw','html','lang','image','rss','menu','service','wiki') NOT NULL DEFAULT 'raw',
   `content` text NOT NULL,
+  `text` mediumtext NOT NULL,
+  `text_updated` int(11) NOT NULL,
   `deletable` tinyint(4) NOT NULL DEFAULT '1',
   `copyable` tinyint(4) NOT NULL DEFAULT '1',
   `active` tinyint(4) NOT NULL DEFAULT '1',
   `order` int(11) NOT NULL,
-  PRIMARY KEY (`id`)
+  PRIMARY KEY (`id`),
+  KEY `object` (`object`),
+  FULLTEXT KEY `text` (`text`)
 );
 
 -- skeleton blocks

+ 18 - 0
modules/boonex/decorous/data/template/system/scripts/BxTemplPagesSearchResult.php

@@ -0,0 +1,18 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaTemplate UNA Template Classes
+ * @{
+ */
+
+class BxTemplPagesSearchResult extends BxBasePagesSearchResult
+{
+    function __construct()
+    {
+        parent::__construct();
+    }
+}
+
+/** @} */

+ 1 - 0
modules/boonex/english/data/langs/system/en.xml

@@ -2670,6 +2670,7 @@ If it is not enabled then please consider implement this optimization, since it
     <string name="_sys_not_specified"><![CDATA[Not Specified]]></string>
     <string name="_sys_on"><![CDATA[on]]></string>
     <string name="_sys_off"><![CDATA[off]]></string>
+    <string name="_sys_pages"><![CDATA[Pages]]></string>
 	<string name="_sys_page_block_title_about"><![CDATA[About]]></string>
 	<string name="_sys_page_block_title_account_profile_create"><![CDATA[Create a profile...]]></string>
 	<string name="_sys_page_block_title_account_profile_switcher"><![CDATA[Use site as ...]]></string>

+ 18 - 0
modules/boonex/lucid/data/template/system/scripts/BxTemplPagesSearchResult.php

@@ -0,0 +1,18 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaTemplate UNA Template Classes
+ * @{
+ */
+
+class BxTemplPagesSearchResult extends BxBasePagesSearchResult
+{
+    function __construct()
+    {
+        parent::__construct();
+    }
+}
+
+/** @} */

+ 18 - 0
modules/boonex/ocean/data/template/system/scripts/BxTemplPagesSearchResult.php

@@ -0,0 +1,18 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaTemplate UNA Template Classes
+ * @{
+ */
+
+class BxTemplPagesSearchResult extends BxBasePagesSearchResult
+{
+    function __construct()
+    {
+        parent::__construct();
+    }
+}
+
+/** @} */

+ 18 - 0
modules/boonex/protean/data/template/system/scripts/BxTemplPagesSearchResult.php

@@ -0,0 +1,18 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaTemplate UNA Template Classes
+ * @{
+ */
+
+class BxTemplPagesSearchResult extends BxBasePagesSearchResult
+{
+    function __construct()
+    {
+        parent::__construct();
+    }
+}
+
+/** @} */

+ 1 - 0
modules/boonex/russian/data/langs/system/ru.xml

@@ -2655,6 +2655,7 @@
     <string name="_sys_not_specified"><![CDATA[Не указано]]></string>
     <string name="_sys_on"><![CDATA[вкл.]]></string>
     <string name="_sys_off"><![CDATA[выкл.]]></string>
+    <string name="_sys_pages"><![CDATA[Страницы]]></string>
 	<string name="_sys_page_block_title_about"><![CDATA[Об...]]></string>
 	<string name="_sys_page_block_title_account_profile_create"><![CDATA[Создать профиль...]]></string>
 	<string name="_sys_page_block_title_account_profile_switcher"><![CDATA[Использовать сайт как ...]]></string>

+ 12 - 1
modules/boonex/wiki/classes/BxWikiConfig.php

@@ -9,11 +9,22 @@
  * @{
  */
 
-class BxWikiConfig extends BxDolModuleConfig
+class BxWikiConfig extends BxBaseModGeneralConfig
 {
     function __construct($aModule)
     {
         parent::__construct($aModule);
+
+        $this->CNF = array_merge($this->CNF, array (
+
+            // module icon
+            'ICON' => 'fab wikipedia-w',
+
+            // some language keys
+            'T' => array (
+                'txt_sample_single' => '_bx_wiki_txt_sample_single',
+            ),
+        ));
     }
 }
 

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

@@ -2,6 +2,7 @@
 <resources name="en" flag="gb" title="English">
     <string name="_sys_module_wiki"><![CDATA[Wiki]]></string>
     <string name="_bx_wiki"><![CDATA[Wiki]]></string>
+    <string name="_bx_wiki_txt_sample_single"><![CDATA[wiki]]></string>
     <string name="_bx_wiki_object_title"><![CDATA[Wiki]]></string>
     <string name="_bx_wiki_page_home"><![CDATA[Wiki Home]]></string>
     <string name="_bx_wiki_block_home"><![CDATA[Wiki Home]]></string>

+ 7 - 0
template/css/general.css

@@ -472,3 +472,10 @@ video.bx-player-embed {
     width:100vw;
     height:100vh;
 }
+
+/* --------------- Search */
+
+.bx-sys-search-results-pages {
+    text-align:left;
+    line-height:150%;
+}

+ 99 - 0
template/scripts/BxBasePagesSearchResult.php

@@ -0,0 +1,99 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaBaseView UNA Base Representation Classes
+ * @{
+ */
+
+class BxBasePagesSearchResult extends BxTemplSearchResult
+{
+    function __construct()
+    {
+        parent::__construct();
+
+        $this->aCurrent = array(
+            'name' => 'sys_pages',
+            'module_name' => 'system',
+            'title' => _t('_sys_pages'),
+            'table' => 'sys_pages_blocks',
+            'ownFields' => array('text_updated`, MAX(`text_updated`) AS `updated_max'),
+            'searchFields' => array('text'),
+            'restriction' => array(
+                'visible_for_levels' => array('value' => '', 'field' => 'visible_for_levels', 'operator' => '&'),
+            ),
+            'join' => array(
+                'albums' => array(
+                    'type' => 'INNER',
+                    'table' => 'sys_objects_page',
+                    'mainField' => 'object',
+                    'onField' => 'object',
+                    'joinFields' => array('id', 'title', 'url', 'module'),
+                    'groupTable' => 'sys_objects_page', 
+                    'groupField' => 'object',
+                ),
+            ),            
+            'paginate' => array('perPage' => 10, 'start' => 0),
+            'sorting' => 'last',
+            'ident' => 'id',
+        );
+
+        $this->sBrowseUrl = BX_DOL_SEARCH_KEYWORD_PAGE;
+
+        $this->aCurrent['restriction']['visible_for_levels']['value'] = 1; // for guests
+        if (isAdmin()) {
+            // admin can view anything
+            $this->aCurrent['restriction']['visible_for_levels']['value'] = '';
+        }
+        elseif ($iProfileId = bx_get_logged_profile_id()) {
+            $oAcl = BxDolAcl::getInstance();
+            $iProfileAclBit = $oAcl->getMemberLevelBit($iProfileId);
+            if ($iProfileAclBit) 
+                $this->aCurrent['restriction']['visible_for_levels']['value'] = $iProfileAclBit;
+        }
+        // TODO: check for privacy
+    }
+
+    function displaySearchUnit($aData)
+    {
+        $sModule = $aData['module'];
+        $sIcon = 'file-alt';
+        if ('system' == $sModule || 'custom' == $sModule) {
+            $sModule = '';
+        }
+        elseif (($oModule = BxDolModule::getInstance($aData['module'])) && isset($oModule->_oConfig->CNF)) {
+            $CNF = $oModule->_oConfig->CNF;
+            if (isset($CNF['T']['txt_sample_single']))
+                $sModule = _t($CNF['T']['txt_sample_single']);
+            if (isset($CNF['ICON']))
+                $sIcon = $CNF['ICON'];
+        }
+        $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($aData['url']);
+        $aVars = array(
+            'title' => _t($aData['title']),
+            'content_url' => $sUrl,
+            'updated' => $aData['updated_max'] ? bx_time_js($aData['updated_max']) : '',
+            'ts' => $aData['updated_max'],
+            'module_name' => $sModule,
+            'icon' => $sIcon,
+        );
+        if ($this->_bLiveSearch) {
+            $sTemplate = 'search_pages_results_live.html';
+        }
+        else {
+            $sTemplate = 'search_pages_results.html';
+        }
+        return BxDolTemplate::getInstance()->parseHtmlByName($sTemplate, $aVars);
+    }
+
+    function getAlterOrder()
+    {
+        if($this->aCurrent['sorting'] == 'last')
+            return array('order' => " ORDER BY `text_updated` DESC");
+
+        return array();
+    }
+}
+
+/** @} */

+ 4 - 0
template/search_pages_results.html

@@ -0,0 +1,4 @@
+<div class="bx-sys-search-results-pages">
+    <a href="__content_url__">__title__</a>
+    <span class="bx-def-font-small bx-def-font-grayed">__updated__</span>
+</div>

+ 3 - 0
template/search_pages_results_live.html

@@ -0,0 +1,3 @@
+<div class="bx-base-general-unit bx-def-unit bx-def-unit-live-search bx-def-margin-sec-bottom" data-ts="__ts__">
+    <a href="__content_url__"><div class="bx-def-unit-img"><div class="bx-def-unit-img-empty bx-def-thumb-size bx-def-round-corners bx-def-box bx-def-color-bg-box bx-def-box-sizing"><i class="sys-icon __icon__"></i></div></div></a><div class="bx-def-unit-info bx-def-thumb-size-max-height bx-def-padding-sec-left"><a href="__content_url__">__title__</a><br /><span class="bx-def-font-grayed bx-def-font-small">__module_name__</span></div>
+</div>