Kaynağa Gözat

Ticket #4630 - Content filter issues. Point 1.

AntonLV 2 yıl önce
ebeveyn
işleme
18bd472c44

+ 35 - 7
inc/classes/BxDolContentFilter.php

@@ -64,11 +64,35 @@ class BxDolContentFilter extends BxDolFactory implements iBxDolSingleton
 
         return $aValues;
     }
+    
+    public function getUnauthenticated()
+    {
+        $sValues = getParam('sys_cf_unauthenticated');
+        if(!$sValues)
+            return [];
+
+        $aValues = explode(',', $sValues);
+        if(!$aValues)
+            return [];
+
+        return $aValues;
+    }
 
     public function getDefaultValue()
     {
         return $this->_iDefaultValue;
     }
+    
+    public function getDefaultValueUnauthenticated()
+    {
+        $aFilters = $this->getUnauthenticated();
+
+        $iCfwValue = 0;
+        foreach($aFilters as $iFilter)
+            $iCfwValue |= (1 << ($iFilter - 1));
+
+        return $iCfwValue;
+    }
 
     public function getValues()
     {
@@ -181,11 +205,13 @@ class BxDolContentFilter extends BxDolFactory implements iBxDolSingleton
             $iViewerId = $this->_iViewerId;
 
         $aViewerInfo = BxDolProfileQuery::getInstance()->getInfoById($iViewerId);
-        if(empty($aViewerInfo) || !is_array($aViewerInfo))
-            return [];
+        if(is_array($aViewerInfo) && isset($aViewerInfo['cfw_value']))
+            $iViewerCfwValue = $aViewerInfo['cfw_value'];
+        else
+            $iViewerCfwValue = $this->getDefaultValueUnauthenticated();
 
         return [
-            'where' => " AND 1 << (`" . $sContentTable . "`.`" . $sContentField . "` - 1) & " . $aViewerInfo['cfw_value']
+            'where' => " AND 1 << (`" . $sContentTable . "`.`" . $sContentField . "` - 1) & " . $iViewerCfwValue
         ];
     }
 
@@ -224,11 +250,13 @@ class BxDolContentFilter extends BxDolFactory implements iBxDolSingleton
             $iViewerId = $this->_iViewerId;
 
         $aViewerInfo = BxDolProfileQuery::getInstance()->getInfoById($iViewerId);
-        if(empty($aViewerInfo) || !is_array($aViewerInfo))
-            return;
-
+        if(is_array($aViewerInfo) && isset($aViewerInfo['cfw_value']))
+            $iViewerCfwValue = $aViewerInfo['cfw_value'];
+        else
+            $iViewerCfwValue = $this->getDefaultValueUnauthenticated();
+    
         return [
-            'value' => $aViewerInfo['cfw_value'],
+            'value' => $iViewerCfwValue,
             'field' => $sContentField,
             'operator' => 'in_set',
             'table' => $sContentTable

+ 1 - 0
install/sql/system.sql

@@ -524,6 +524,7 @@ INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `ex
 (@iCategoryId, 'sys_cf_enable', '_adm_stg_cpt_option_sys_cf_enable', '', 'checkbox', '', '', '', 40),
 (@iCategoryId, 'sys_cf_enable_comments', '_adm_stg_cpt_option_sys_cf_enable_comments', '', 'checkbox', '', '', '', 41),
 (@iCategoryId, 'sys_cf_prohibited', '_adm_stg_cpt_option_sys_cf_prohibited', '', 'list', 'a:4:{s:6:"module";s:6:"system";s:6:"method";s:25:"get_options_cf_prohibited";s:6:"params";a:0:{}s:5:"class";s:13:"TemplServices";}', '', '', 42),
+(@iCategoryId, 'sys_cf_unauthenticated', '_adm_stg_cpt_option_sys_cf_unauthenticated', '1', 'list', 'a:4:{s:6:"module";s:6:"system";s:6:"method";s:30:"get_options_cf_unauthenticated";s:6:"params";a:0:{}s:5:"class";s:13:"TemplServices";}', '', '', 43),
 
 (@iCategoryId, 'sys_lock_from_unauthenticated', '_adm_stg_cpt_option_sys_lock_from_unauthenticated', '', 'checkbox', '', '', '', 50),
 (@iCategoryId, 'sys_lock_from_unauthenticated_exceptions', '_adm_stg_cpt_option_sys_lock_from_unauthenticated_exceptions', 'login,forgot-password,create-account,confirm-email,terms,privacy,contact,about,home', 'text', '', '', '', 52);

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

@@ -1600,6 +1600,7 @@
     <string name="_adm_stg_cpt_option_sys_cf_enable"><![CDATA[Enable content filters]]></string>
     <string name="_adm_stg_cpt_option_sys_cf_enable_comments"><![CDATA[Enable content filters for comments]]></string>
     <string name="_adm_stg_cpt_option_sys_cf_prohibited"><![CDATA[Prohibited content]]></string>
+    <string name="_adm_stg_cpt_option_sys_cf_unauthenticated"><![CDATA[Content visible to unauthenticated users]]></string>
     <string name="_adm_stg_cpt_option_sys_confirmation_before_redirect"><![CDATA[Ask user confirmation before redirecting user to the external site]]></string>
     <string name="_adm_stg_cpt_option_sys_email_attachable_email_templates"><![CDATA[Attachable email templates list]]></string>
     <string name="_adm_stg_cpt_option_sys_db_cache_enable"><![CDATA[Enable DB cache]]></string>

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

@@ -1575,6 +1575,7 @@
     <string name="_adm_stg_cpt_option_sys_cf_enable"><![CDATA[Включить контентные фильтры]]></string>
     <string name="_adm_stg_cpt_option_sys_cf_enable_comments"><![CDATA[Включить контентные фильтры для комментариев]]></string>
     <string name="_adm_stg_cpt_option_sys_cf_prohibited"><![CDATA[Запрещенный контент]]></string>
+    <string name="_adm_stg_cpt_option_sys_cf_unauthenticated"><![CDATA[Контент, видимый неавторизованным пользователям]]></string>
     <string name="_adm_stg_cpt_option_sys_confirmation_before_redirect"><![CDATA[Требовать подтверждение перед переходом по ссылке на внешний сайт]]></string>
     <string name="_adm_stg_cpt_option_sys_email_attachable_email_templates"><![CDATA[Список присоединяемых email темплейтов]]></string>
     <string name="_adm_stg_cpt_option_sys_db_cache_enable"><![CDATA[Задействовать кэш БД]]></string>

+ 5 - 0
template/scripts/BxBaseServices.php

@@ -1309,6 +1309,11 @@ class BxBaseServices extends BxDol implements iBxDolProfileService
         return BxDolFormQuery::getDataItems('sys_content_filter');
     }
 
+    public function serviceGetOptionsCfUnauthenticated()
+    {
+        return BxDolFormQuery::getDataItems('sys_content_filter');
+    }
+
     public function serviceGetOptionsTaiwindDefault()
     {
         $sPath = BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'tailwind/css';