Przeglądaj źródła

Ticket #516 - Additional ACL actions.

AntonLV 9 lat temu
rodzic
commit
cceb5f3b49

+ 16 - 0
inc/classes/BxDolView.php

@@ -175,6 +175,22 @@ class BxDolView extends BxDolObject
         return false;
     }
 
+    public function isAllowedViewView($isPerformAction = false)
+    {
+        if(isAdmin())
+            return true;
+
+        return $this->checkAction('view_view', $isPerformAction);
+    }
+
+    public function isAllowedViewViewViewers($isPerformAction = false)
+    {
+        if(isAdmin())
+            return true;
+
+        return $this->checkAction('view_view_viewers', $isPerformAction);
+    }
+
 	/**
      * Internal functions
      */

+ 22 - 0
install/sql/system.sql

@@ -535,6 +535,14 @@ INSERT INTO `sys_acl_actions` (`Module`, `Name`, `AdditionalParamName`, `Title`,
 ('system', 'favorite_view', NULL, '_sys_acl_action_favorite_view', '', 0, 0);
 SET @iIdActionFavoriteView = LAST_INSERT_ID();
 
+INSERT INTO `sys_acl_actions` (`Module`, `Name`, `AdditionalParamName`, `Title`, `Desc`, `Countable`, `DisabledForLevels`) VALUES
+('system', 'view_view', NULL, '_sys_acl_action_view_view', '', 0, 0);
+SET @iIdActionViewView = LAST_INSERT_ID();
+
+INSERT INTO `sys_acl_actions` (`Module`, `Name`, `AdditionalParamName`, `Title`, `Desc`, `Countable`, `DisabledForLevels`) VALUES
+('system', 'view_view_viewers', NULL, '_sys_acl_action_view_view_viewers', '', 0, 0);
+SET @iIdActionViewViewViewers = LAST_INSERT_ID();
+
 INSERT INTO `sys_acl_actions` (`Module`, `Name`, `AdditionalParamName`, `Title`, `Desc`, `Countable`, `DisabledForLevels`) VALUES
 ('system', 'comments post', NULL, '_sys_acl_action_comments_post', '', 0, 3);
 SET @iIdActionCmtPost = LAST_INSERT_ID();
@@ -633,6 +641,20 @@ INSERT INTO `sys_acl_matrix` (`IDLevel`, `IDAction`) VALUES
 (@iAdministrator, @iIdActionFavoriteView),
 (@iPremium, @iIdActionFavoriteView),
 
+-- view view
+(@iUnauthenticated, @iIdActionViewView),
+(@iAccount, @iIdActionViewView),
+(@iStandard, @iIdActionViewView),
+(@iUnconfirmed, @iIdActionViewView),
+(@iPending, @iIdActionViewView),
+(@iModerator, @iIdActionViewView),
+(@iAdministrator, @iIdActionViewView),
+(@iPremium, @iIdActionViewView),
+
+-- view view viewers
+(@iModerator, @iIdActionViewViewViewers),
+(@iAdministrator, @iIdActionViewViewViewers),
+
 -- comments post
 (@iStandard, @iIdActionCmtPost),
 (@iModerator, @iIdActionCmtPost),

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

@@ -1494,6 +1494,8 @@
 	<string name="_sys_acl_action_every_period"><![CDATA[ every {4} hours]]></string>
 	<string name="_sys_acl_action_favorite"><![CDATA[Favorite]]></string>
 	<string name="_sys_acl_action_favorite_view"><![CDATA[View favorites]]></string>
+	<string name="_sys_acl_action_view_view"><![CDATA[View views]]></string>
+	<string name="_sys_acl_action_view_view_viewers"><![CDATA[View viewers]]></string>
 	<string name="_sys_acl_action_limit_reached"><![CDATA[You have reached your limit for now. Your current membership ({2}) allows you to {1} no more than {3} times]]></string>
 	<string name="_sys_acl_action_not_allowed"><![CDATA[Your current membership ({2}) doesn't allow you to '{1}'.]]></string>
 	<string name="_sys_acl_action_not_allowed_after"><![CDATA[Your current membership ({2}) stopped to allow you to '{1}' {5}.]]></string>

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

@@ -1492,6 +1492,8 @@
 	<string name="_sys_acl_action_every_period"><![CDATA[ каждые {4} часа]]></string>
 	<string name="_sys_acl_action_favorite"><![CDATA[Избранное - Добавлять]]></string>
 	<string name="_sys_acl_action_favorite_view"><![CDATA[Избранное - Просматривать]]></string>
+	<string name="_sys_acl_action_view_view"><![CDATA[Просмотры - Просматривать]]></string>
+	<string name="_sys_acl_action_view_view_viewers"><![CDATA[Просмотры - Просматривать смотревших]]></string>
 	<string name="_sys_acl_action_limit_reached"><![CDATA[Вы достигли лимита. Ваше текущее членство ({2}) позволяет {1} не более {3} раз]]></string>
 	<string name="_sys_acl_action_not_allowed"><![CDATA[Ваше текущее членство ({2}) не позволяет '{1}'.]]></string>
 	<string name="_sys_acl_action_not_allowed_after"><![CDATA[Ваше текущее членство ({2}) более не позволяет '{1}' {5}.]]></string>

+ 35 - 14
template/scripts/BxBaseView.php

@@ -103,6 +103,7 @@ class BxBaseView extends BxDolView
 
         $bShowDoViewAsButtonSmall = isset($aParams['show_do_view_as_button_small']) && $aParams['show_do_view_as_button_small'] == true;
         $bShowDoViewAsButton = !$bShowDoViewAsButtonSmall && isset($aParams['show_do_view_as_button']) && $aParams['show_do_view_as_button'] == true;
+        $bAllowedViewViewViewers = $this->isAllowedViewViewViewers();
 
         $aView = $this->_oQuery->getView($this->getId());
         $sClass = $this->_sStylePrefix . '-counter';
@@ -111,15 +112,31 @@ class BxBaseView extends BxDolView
         if($bShowDoViewAsButton)
             $sClass .= ' bx-btn-height';
 
+        $sContent = (int)$aView['count'] > 0 ? $this->_getLabelCounter($aView['count']) : '';
         return $this->_oTemplate->parseHtmlByName($this->_sTmplNameCounter, array(
-            'href' => 'javascript:void(0)',
-            'title' => _t('_view_do_view_by'),
-            'bx_repeat:attrs' => array(
-                array('key' => 'id', 'value' => $this->_aHtmlIds['counter']),
-                array('key' => 'class', 'value' => $sClass),
-                array('key' => 'onclick', 'value' => 'javascript:' . $sJsObject . '.toggleByPopup(this)')
+        	'bx_if:show_text' => array(
+                'condition' => !$bAllowedViewViewViewers,
+                'content' => array(
+                    'bx_repeat:attrs' => array(
+                        array('key' => 'id', 'value' => $this->_aHtmlIds['counter']),
+                        array('key' => 'class', 'value' => $sClass),
+                    ),
+                    'content' => $sContent
+                )
             ),
-            'content' => (int)$aView['count'] > 0 ? $this->_getLabelCounter($aView['count']) : ''
+            'bx_if:show_link' => array(
+                'condition' => $bAllowedViewViewViewers,
+                'content' => array(
+                    'bx_repeat:attrs' => array(
+                        array('key' => 'id', 'value' => $this->_aHtmlIds['counter']),
+                        array('key' => 'class', 'value' => $sClass),
+                        array('key' => 'href', 'value' => 'javascript:void(0)'),
+                        array('key' => 'onclick', 'value' => 'javascript:' . $sJsObject . '.toggleByPopup(this)'),
+                        array('key' => 'title', 'value' => _t('_view_do_view_by'))
+                    ),
+                    'content' => $sContent
+                )
+            )
         ));
     }
 
@@ -142,29 +159,33 @@ class BxBaseView extends BxDolView
     	$aParams = array_merge($this->_aElementDefaults, $aParams);
     	$bDynamicMode = isset($aParams['dynamic_mode']) && $aParams['dynamic_mode'] === true;
 
+    	$bAllowedView = $this->isAllowedView();
+    	$bAllowedViewView = $this->isAllowedViewView();
+
         $bShowDoView = !isset($aParams['show_do_view']) || $aParams['show_do_view'] == true;
         $bShowDoViewAsButtonSmall = isset($aParams['show_do_view_as_button_small']) && $aParams['show_do_view_as_button_small'] == true;
         $bShowDoViewAsButton = !$bShowDoViewAsButtonSmall && isset($aParams['show_do_view_as_button']) && $aParams['show_do_view_as_button'] == true;
-        $bShowCounter = isset($aParams['show_counter']) && $aParams['show_counter'] === true;
+        $bShowCounter = isset($aParams['show_counter']) && $aParams['show_counter'] === true && $bAllowedViewView;
 
 		$iObjectId = $this->getId();
 		$iAuthorId = $this->_getAuthorId();
 		$aView = $this->_oQuery->getView($iObjectId);
         $bCount = (int)$aView['count'] != 0;
 
-        $isAllowedView = $this->isAllowedView();
+        if(!$bAllowedView && (!$bAllowedViewView || !$bCount))
+            return '';
 
         //--- Do View
-        $bTmplVarsDoView = $bShowDoView && ($bCount || $isAllowedView);
+        $bTmplVarsDoView = $bShowDoView && ($bCount || $bAllowedView);
         $aTmplVarsDoView = array();
         if($bTmplVarsDoView)
         	$aTmplVarsDoView = array(
 				'style_prefix' => $this->_sStylePrefix,
-				'do_view' => $this->_getDoView($aParams, $isAllowedView),
+				'do_view' => $this->_getDoView($aParams, $bAllowedView),
 			);
 
         //--- Counter
-        $bTmplVarsCounter = $bShowCounter && ($bCount || $isAllowedView);
+        $bTmplVarsCounter = $bShowCounter && ($bCount || $bAllowedView);
         $aTmplVarsCounter = array();
         if($bTmplVarsCounter)
         	$aTmplVarsCounter = array(
@@ -197,11 +218,11 @@ class BxBaseView extends BxDolView
         ));
     }
 
-    protected function _getDoView($aParams = array(), $isAllowedView = true)
+    protected function _getDoView($aParams = array(), $bAllowedView = true)
     {
         $bShowDoViewAsButtonSmall = isset($aParams['show_do_view_as_button_small']) && $aParams['show_do_view_as_button_small'] == true;
         $bShowDoViewAsButton = !$bShowDoViewAsButtonSmall && isset($aParams['show_do_view_as_button']) && $aParams['show_do_view_as_button'] == true;
-		$bDisabled = !$isAllowedView;
+		$bDisabled = !$bAllowedView;
 
         $sClass = '';
 		if($bShowDoViewAsButton)

+ 6 - 1
template/view_counter.html

@@ -1 +1,6 @@
-<bx_include_auto:bx_a.html />
+<bx_if:show_text>
+    <span <bx_repeat:attrs>__key__="__value__"</bx_repeat:attrs>>__content__</span>
+</bx_if:show_text>
+<bx_if:show_link>
+    <a <bx_repeat:attrs>__key__="__value__"</bx_repeat:attrs>>__content__</a>
+</bx_if:show_link>