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

Ticket #4624 - Refactor code related to page visibility/accessibility.

AntonLV 2 лет назад
Родитель
Сommit
5397c1cf80

+ 12 - 0
inc/classes/BxDolPage.php

@@ -810,8 +810,20 @@ class BxDolPage extends BxDolFactory implements iBxDolFactoryObject, iBxDolRepla
         return BxDolAcl::getInstance()->isMemberLevelInSet($a['visible_for_levels']);
     }
 
+    /**
+     * Check if page is available.
+     * @param type $a - page object.
+     * @return boolean true if available, false or a string with error message otherwise.
+     */
+    protected function _isAvailablePage ($a)
+    {
+        return true;
+    }
+
     /**
      * Check if page is visible.
+     * @param array $a - page object.
+     * @return boolean true if visible, false or a string with error message otherwise.
      */
     protected function _isVisiblePage ($a)
     {

+ 31 - 22
modules/base/general/classes/BxBaseModGeneralPageEntry.php

@@ -36,11 +36,6 @@ class BxBaseModGeneralPageEntry extends BxTemplPage
         ]);
     }
 
-    public function isActive()
-    {
-        return true;
-    }
-
     public function getContentInfo()
     {
         return $this->_aContentInfo;
@@ -50,27 +45,15 @@ class BxBaseModGeneralPageEntry extends BxTemplPage
     {
         $CNF = &$this->_oModule->_oConfig->CNF;
 
-        // check if content exists
-        if (!$this->_aContentInfo || !$this->isActive()) { // if entry is not found - display standard "404 page not found" page
+        if (!$this->_isAvailablePage($this->_aObject)) {
             $this->_oTemplate->displayPageNotFound();
             exit;
         }
 
-        if(!empty($CNF['FIELD_CF'])) {
-            $oCf = BxDolContentFilter::getInstance();
-            if($oCf->isEnabled() && !$oCf->isAllowed($this->_aContentInfo[$CNF['FIELD_CF']])) {
-                $this->_oTemplate->displayPageNotFound();
-                exit;
-            }
-        }
-
         $oCover = BxDolCover::getInstance($this->_oModule->_oTemplate);        
         if ($oCover)
             $oCover->setCoverClass($this->_sCoverClass);
 
-        // permissions check 
-        $this->_processPermissionsCheck ();
-
         // count views
         if(!empty($CNF['OBJECT_VIEWS'])) {
             $oView = BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $this->_aContentInfo[$CNF['FIELD_ID']]);
@@ -117,13 +100,39 @@ class BxBaseModGeneralPageEntry extends BxTemplPage
         return parent::getCode ();
     }
 
-    protected function _processPermissionsCheck ()
+    protected function _isAvailablePage ($a)
     {
-        if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedView($this->_aContentInfo))) {
-            $this->_oTemplate->displayAccessDenied($sMsg);
-            exit;
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        if(!$this->_aContentInfo)
+            return false;
+
+        if(!empty($CNF['FIELD_CF'])) {
+            $oCf = BxDolContentFilter::getInstance();
+            if($oCf->isEnabled() && !$oCf->isAllowed($this->_aContentInfo[$CNF['FIELD_CF']]))
+                return false;
         }
+
+        return parent::_isAvailablePage($a);
+    }
+
+    protected function _isVisiblePage ($a)
+    {
+        if(($mixedCheckResult = $this->_oModule->checkAllowedView($this->_aContentInfo)) !== CHECK_ACTION_RESULT_ALLOWED) 
+            return $mixedCheckResult;
+
+        if(!parent::_isVisiblePage($a))
+            return false;
+        
         $this->_oModule->checkAllowedView($this->_aContentInfo, true);
+        
+        return true;
+    }
+
+    protected function _getPageAccessDeniedMsg ($mixedMsg = false)
+    {
+        $this->_oTemplate->displayAccessDenied($mixedMsg);
+        exit;
     }
 
     protected function _getPageMetaDesc()

+ 37 - 29
modules/base/groups/classes/BxBaseModGroupsPageEntry.php

@@ -65,31 +65,6 @@ class BxBaseModGroupsPageEntry extends BxBaseModProfilePageEntry
         }
     }
 
-    protected function _processPermissionsCheck ()
-    {
-        $CNF = &$this->_oModule->_oConfig->CNF;
-
-        $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
-        
-        $mixedAllowView = $this->_oModule->checkAllowedView($this->_aContentInfo);
-        if (!$oPrivacy->isPartiallyVisible($this->_aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) && CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $mixedAllowView)) {
-            $this->_oTemplate->displayAccessDenied([
-                'title' => $this->_oProfile->getDisplayName(),
-                'content' => $sMsg
-            ]);
-            exit;
-        }
-        elseif ($oPrivacy->isPartiallyVisible($this->_aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) && $CNF['OBJECT_PAGE_VIEW_ENTRY'] == $this->_sObject && CHECK_ACTION_RESULT_ALLOWED !== $mixedAllowView) {
-            // replace current page with different set of blocks
-            $aObject = BxDolPageQuery::getPageObject($CNF['OBJECT_PAGE_VIEW_ENTRY_CLOSED']);
-            $this->_sObject = $aObject['object'];
-            $this->_aObject = $aObject;
-            $this->_oQuery = new BxDolPageQuery($this->_aObject);
-        }
-
-        $this->_oModule->checkAllowedView($this->_aContentInfo, true);
-    }
-    
     protected function _getInvitationCode($aParams = [])
     {
         $CNF = &$this->_oModule->_oConfig->CNF;
@@ -128,14 +103,47 @@ class BxBaseModGroupsPageEntry extends BxBaseModProfilePageEntry
         return $sCode;
     }
 
-    public function isActive()
+    public function getCode ()
     {
-        return $this->_oModule->isEntryActive($this->_aContentInfo);
+        return $this->_getInvitationCode() . parent::getCode();
     }
 
-    public function getCode ()
+    protected function _isAvailablePage($a)
     {
-        return $this->_getInvitationCode() . parent::getCode();
+        if(!$this->_aContentInfo || !$this->_oModule->isEntryActive($this->_aContentInfo))
+            return false;
+        
+        return parent::_isAvailablePage($a);
+    }
+
+    protected function _isVisiblePage ($a)
+    {
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        if(($mixedAllowView = $this->_oModule->checkAllowedView($this->_aContentInfo)) !== CHECK_ACTION_RESULT_ALLOWED) {
+            $bPartiallyVisible = false;
+            if(!empty($CNF['OBJECT_PRIVACY_VIEW']) && ($oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW'])) !== false)
+                $bPartiallyVisible = $oPrivacy->isPartiallyVisible($this->_aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]);
+
+            /*
+             * If partially visible, replace current page with different set of blocks.
+             */
+            if($bPartiallyVisible && $this->_sObject == $CNF['OBJECT_PAGE_VIEW_ENTRY']) {
+                $aObject = BxDolPageQuery::getPageObject($CNF['OBJECT_PAGE_VIEW_ENTRY_CLOSED']);
+                $this->_sObject = $aObject['object'];
+                $this->_aObject = $aObject;
+                $this->_oQuery = new BxDolPageQuery($this->_aObject);
+            }
+            else
+                return $mixedAllowView;
+        }
+
+        if(!BxDolPage::_isVisiblePage($a))
+            return false;
+
+        $this->_oModule->checkAllowedView($this->_aContentInfo, true);
+
+        return true;
     }
 }
 

+ 15 - 15
modules/base/profile/classes/BxBaseModProfilePageEntry.php

@@ -45,7 +45,7 @@ class BxBaseModProfilePageEntry extends BxBaseModGeneralPageEntry
             $this->_aContentInfo = $this->_oModule->_oDb->getContentInfoById($this->_aProfileInfo['content_id']);
         }
 
-        if (!$this->_aContentInfo || !$this->_oProfile || !$this->isActive()) {
+        if (!$this->_isAvailablePage($this->_aObject) || !$this->_oProfile) {
             $this->setPageCover(false);
             return;
         }
@@ -127,33 +127,33 @@ class BxBaseModProfilePageEntry extends BxBaseModGeneralPageEntry
         return parent::getCode();
     }
 
-    protected function _processPermissionsCheck ()
+    protected function _isVisiblePage ($a)
     {
         $CNF = &$this->_oModule->_oConfig->CNF;
 
         bx_import('BxDolPrivacy');
 
-        $mixedAllowView = $this->_oModule->checkAllowedView($this->_aContentInfo);
-        if ($CNF['OBJECT_PAGE_VIEW_ENTRY'] == $this->_sObject) {
-            if ((BX_DOL_PG_HIDDEN == $this->_aContentInfo['allow_view_to'] || BX_DOL_PG_MEONLY == $this->_aContentInfo['allow_view_to']) && CHECK_ACTION_RESULT_ALLOWED !== $mixedAllowView) {
-                $this->_oTemplate->displayAccessDenied($mixedAllowView);
-                exit;
-            }
-            elseif (CHECK_ACTION_RESULT_ALLOWED !== $mixedAllowView) {
-                // replace current page with different set of blocks
+        if(($mixedAllowView = $this->_oModule->checkAllowedView($this->_aContentInfo)) !== CHECK_ACTION_RESULT_ALLOWED) {
+            /*
+             * If visible by privacy, replace current page with different set of blocks.
+             */
+            if(!in_array($this->_aContentInfo['allow_view_to'], [BX_DOL_PG_HIDDEN, BX_DOL_PG_MEONLY]) && $this->_sObject == $CNF['OBJECT_PAGE_VIEW_ENTRY']) {
                 $aObject = BxDolPageQuery::getPageObject($CNF['OBJECT_PAGE_VIEW_ENTRY_CLOSED']);
                 $this->_sObject = $aObject['object'];
                 $this->_aObject = $aObject;
                 $this->_oQuery = new BxDolPageQuery($this->_aObject);
             }
-        } 
-        elseif (CHECK_ACTION_RESULT_ALLOWED !== $mixedAllowView) {
-            $this->_oTemplate->displayAccessDenied($mixedAllowView);
-            exit;
+            else 
+                return $mixedAllowView;
         }
 
+        if(!BxDolPage::_isVisiblePage($a))
+            return false;
+        
         $this->_oModule->checkAllowedView($this->_aContentInfo, true);
-    }    
+        
+        return true;
+    }
 }
 
 /** @} */

+ 8 - 5
modules/base/text/classes/BxBaseModTextPageEntry.php

@@ -105,11 +105,6 @@ class BxBaseModTextPageEntry extends BxBaseModGeneralPageEntry
         }
     }
 
-    public function isActive()
-    {
-        return $this->_oModule->isEntryActive($this->_aContentInfo);
-    }
-
     public function getCode ()
     {
         $mixedResult = parent::getCode();
@@ -125,6 +120,14 @@ class BxBaseModTextPageEntry extends BxBaseModGeneralPageEntry
         return $mixedResult;
     }
 
+    protected function _isAvailablePage($a)
+    {
+        if(!$this->_aContentInfo || !$this->_oModule->isEntryActive($this->_aContentInfo))
+            return false;
+        
+        return parent::_isAvailablePage($a);
+    }
+
     protected function _setSubmenu($aParams)
     {
     	$CNF = &$this->_oModule->_oConfig->CNF;

+ 12 - 12
modules/boonex/market/classes/BxMarketPageEntry.php

@@ -20,9 +20,19 @@ class BxMarketPageEntry extends BxBaseModTextPageEntry
         parent::__construct($aObject, $oTemplate);
     }
 
-    public function isActive()
+    public function getCode ()
+    {
+        $sResult = parent::getCode();
+        $sResult .= $this->_oModule->_oTemplate->getJsCode('entry');
+
+        $this->_oModule->_oTemplate->addJs(array('fancybox/jquery.fancybox.pack.js', 'entry.js'));
+        $this->_oModule->_oTemplate->addCss(array(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'fancybox/|jquery.fancybox.css', 'entry.css'));
+        return $sResult;
+    }
+
+    protected function _isAvailablePage($a)
     {
-        if(parent::isActive())
+        if(parent::_isAvailablePage($a))
             return true;
 
         $CNF = &$this->_oModule->_oConfig->CNF;
@@ -33,16 +43,6 @@ class BxMarketPageEntry extends BxBaseModTextPageEntry
 
         return false;
     }
-
-    public function getCode ()
-    {
-        $sResult = parent::getCode();
-        $sResult .= $this->_oModule->_oTemplate->getJsCode('entry');
-
-        $this->_oModule->_oTemplate->addJs(array('fancybox/jquery.fancybox.pack.js', 'entry.js'));
-        $this->_oModule->_oTemplate->addCss(array(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'fancybox/|jquery.fancybox.css', 'entry.css'));
-        return $sResult;
-    }
 }
 
 /** @} */

+ 16 - 11
modules/boonex/photos/classes/BxPhotosPageEntryBrief.php

@@ -36,21 +36,26 @@ class BxPhotosPageEntryBrief extends BxTemplPage
             $this->_aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
     }
 
-    public function isActive()
+    protected function _isAvailablePage($a)
     {
-        return $this->_oModule->isEntryActive($this->_aContentInfo);
-    }
+        if(!$this->_aContentInfo || !$this->_oModule->isEntryActive($this->_aContentInfo))
+            return false;
 
-    public function getCode ()
-    {
-        if(!$this->_aContentInfo || !$this->isActive())
-            return MsgBox(_t('_Empty'));
+        if(!empty($CNF['FIELD_CF'])) {
+            $oCf = BxDolContentFilter::getInstance();
+            if($oCf->isEnabled() && !$oCf->isAllowed($this->_aContentInfo[$CNF['FIELD_CF']]))
+                return false;
+        }
 
-        $sCheckAllowed = $this->_oModule->checkAllowedView($this->_aContentInfo);
-        if($sCheckAllowed !== CHECK_ACTION_RESULT_ALLOWED) 
-            return MsgBox($sCheckAllowed);
+        return parent::_isAvailablePage($a);
+    }
+    
+    protected function _isVisiblePage ($a)
+    {
+        if(($mixedCheckResult = $this->_oModule->checkAllowedView($this->_aContentInfo)) !== CHECK_ACTION_RESULT_ALLOWED) 
+            return $mixedCheckResult;
 
-        return parent::getCode();
+        return parent::_isVisiblePage($a);
     }
 }
 

+ 8 - 7
modules/boonex/stream/classes/BxStrmPageEntry.php

@@ -20,6 +20,14 @@ class BxStrmPageEntry extends BxBaseModTextPageEntry
         parent::__construct($aObject, $oTemplate);
     }
 
+    protected function _isAvailablePage($a)
+    {
+        if(!$this->_aContentInfo || (!$this->_oModule->isEntryActive($this->_aContentInfo) && !getParam('bx_stream_always_accessible')))
+            return false;
+        
+        return BxBaseModGeneralPageEntry::_isAvailablePage($a);
+    }
+
     protected function _setSubmenu($aParams)
     {
     	parent::_setSubmenu(array_merge($aParams, array(
@@ -27,13 +35,6 @@ class BxStrmPageEntry extends BxBaseModTextPageEntry
     		'icon' => ''
     	)));
     }
-
-    public function isActive()
-    {
-        if (getParam('bx_stream_always_accessible'))
-            return true;
-        return parent::isActive();
-    }
 }
 
 /** @} */

+ 3 - 3
modules/boonex/stream/install/config.php

@@ -18,12 +18,12 @@ $aConfig = array(
     'name' => 'bx_stream',
     'title' => 'Stream',
     'note' => 'Live streaming module.',
-    'version' => '13.0.9.DEV',
-    'vendor' => 'BoonEx',
+    'version' => '14.0.0.DEV',
+    'vendor' => 'UNA INC',
     'help_url' => 'http://feed.una.io/?section={module_name}',
 
     'compatible_with' => array(
-        '13.0.x'
+        '14.0.x'
     ),
 
     /**

+ 23 - 8
template/scripts/BxBasePage.php

@@ -192,8 +192,11 @@ class BxBasePage extends BxDolPage
             exit;
         }
 
-        if (!$this->_isVisiblePage($this->_aObject))
-            return $this->_getPageAccessDeniedMsg ();
+        if (($mixedAvailable = $this->_isAvailablePage($this->_aObject)) !== true) 
+            return $this->_getPageNotFoundMsg($mixedAvailable);
+
+        if (($mixedVisible = $this->_isVisiblePage($this->_aObject)) !== true)
+            return $this->_getPageAccessDeniedMsg($mixedVisible);
 
         $this->_addJsCss();
 
@@ -531,10 +534,12 @@ class BxBasePage extends BxDolPage
             'blocks' => $aBlocks,
             'data' => &$a,
         ];
-        
-        if (!$this->_isVisiblePage($this->_aObject))
+
+        if(!$this->_isAvailablePage($this->_aObject))
+            $a['page_status'] = 404;
+        else if(!$this->_isVisiblePage($this->_aObject))
             $a['page_status'] = 403;
-        
+
         bx_alert('system', 'get_page_api', 0, 0, $aExtras);
 
         return $a;
@@ -1085,12 +1090,22 @@ class BxBasePage extends BxDolPage
     }
 
     /**
-     * Get access denied message HTML.
+     * Get page not found message.
+     * @return string
+     */
+    protected function _getPageNotFoundMsg ($mixedMsg = false)
+    {
+        $this->_oTemplate->displayPageNotFound();
+        exit;
+    }
+
+    /**
+     * Get access denied message.
      * @return string
      */
-    protected function _getPageAccessDeniedMsg ()
+    protected function _getPageAccessDeniedMsg ($mixedMsg = false)
     {
-        return MsgBox(_t('_Access denied'));
+        return MsgBox($mixedMsg !== false ? $mixedMsg : _t('_Access denied'));
     }
 
     /**