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

Ticket #3731 - Timeline: Add reposts counter in update's Counters menu.

AntonLV 4 лет назад
Родитель
Сommit
df323d331a

+ 1 - 1
modules/base/general/classes/BxBaseModGeneralMenuViewActions.php

@@ -365,7 +365,7 @@ class BxBaseModGeneralMenuViewActions extends BxTemplMenuCustom
         if(!empty($CNF['FIELD_PUBLISHED']) && isset($aContentInfo[$CNF['FIELD_PUBLISHED']]) && (int)$aContentInfo[$CNF['FIELD_PUBLISHED']] > time())
         if(!empty($CNF['FIELD_PUBLISHED']) && isset($aContentInfo[$CNF['FIELD_PUBLISHED']]) && (int)$aContentInfo[$CNF['FIELD_PUBLISHED']] > time())
             return '';
             return '';
 
 
-        if(!empty($CNF['FIELD_ALLOW_VIEW_TO']) && isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) && !in_array((int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']], array(BX_DOL_PG_ALL, BX_DOL_PG_MEMBERS)))
+        if(!empty($CNF['FIELD_ALLOW_VIEW_TO']) && isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) && (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] > 0 && !in_array((int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']], array(BX_DOL_PG_ALL, BX_DOL_PG_MEMBERS)))
             return '';
             return '';
 
 
         $sStatus = 'active';
         $sStatus = 'active';

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

@@ -370,6 +370,7 @@
     <string name="_bx_timeline_txt_new_content"><![CDATA[Новый контент]]></string>
     <string name="_bx_timeline_txt_new_content"><![CDATA[Новый контент]]></string>
 
 
     <string name="_bx_timeline_txt_do_repost"><![CDATA[Сделать репост]]></string>
     <string name="_bx_timeline_txt_do_repost"><![CDATA[Сделать репост]]></string>
+    <string name="_bx_timeline_txt_repost_counter"><![CDATA[{0}]]></string>
     <string name="_bx_timeline_txt_reposted"><![CDATA[Сделал репост {0} {1}.]]></string>
     <string name="_bx_timeline_txt_reposted"><![CDATA[Сделал репост {0} {1}.]]></string>
     <string name="_bx_timeline_txt_reposted_by"><![CDATA[Сделал репост]]></string>
     <string name="_bx_timeline_txt_reposted_by"><![CDATA[Сделал репост]]></string>
     <string name="_bx_timeline_txt_err_cannot_repost"><![CDATA[Невозможно сделать репост. Пожалуйста, сообщите нам об этой проблеме.]]></string>
     <string name="_bx_timeline_txt_err_cannot_repost"><![CDATA[Невозможно сделать репост. Пожалуйста, сообщите нам об этой проблеме.]]></string>

+ 7 - 0
modules/boonex/timeline/classes/BxTimelineConfig.php

@@ -336,8 +336,15 @@ class BxTimelineConfig extends BxBaseModNotificationsConfig
             'show_do_repost_image' => false,
             'show_do_repost_image' => false,
             'show_do_repost_icon' => true,
             'show_do_repost_icon' => true,
             'show_do_repost_text' => false,
             'show_do_repost_text' => false,
+
+            //--- Counter
+            'show_counter_label_icon' => false,
+            'show_counter_label_text' => true,
             'show_counter' => true,
             'show_counter' => true,
 
 
+            //--- JS script
+            'show_script' => true,
+
             //--- Images
             //--- Images
             'image_do_repost' => '',
             'image_do_repost' => '',
 
 

+ 29 - 0
modules/boonex/timeline/classes/BxTimelineMenuItemActions.php

@@ -294,6 +294,35 @@ class BxTimelineMenuItemActions extends BxTemplMenuCustom
         return $this->_oModule->getReportObject($sReportsSystem, $iReportsObject)->$sReportsMethod($aReportsParams);
         return $this->_oModule->getReportObject($sReportsSystem, $iReportsObject)->$sReportsMethod($aReportsParams);
     }
     }
 
 
+    protected function _getMenuItemItemRepost($aItem)
+    {
+        if(!isset($this->_aEvent['reposts'])) 
+            return false;
+
+        $aRepostsParams = array(
+            'show_do_repost_text' => $this->_bShowTitles,
+            'show_counter' => $this->_bShowCounters,
+            'show_counter_label_icon' => $this->_bShowCountersIcons,
+            'dynamic_mode' => $this->_bDynamicMode
+        );
+
+        $sMethodName = '';
+        $aMethodParams = [];
+        switch($this->_sMode) {
+            case self::$_sModeActions:
+                $sMethodName = 'serviceGetRepostElementBlock';
+                $aMethodParams = [$this->_aEvent['owner_id'], $this->_aEvent['type'], $this->_aEvent['action'], $this->_aEvent['object_id'], $aRepostsParams];
+                break;
+
+            case self::$_sModeCounters:
+                $sMethodName = 'serviceGetRepostCounter';
+                $aMethodParams = [$this->_aEvent['type'], $this->_aEvent['action'], $this->_aEvent['object_id'], $aRepostsParams];
+                break;
+        }
+
+        return call_user_func_array([$this->_oModule, $sMethodName], $aMethodParams);
+    }
+
     protected function _getMenuItemDefault ($aItem)
     protected function _getMenuItemDefault ($aItem)
     {
     {
         if(!isset($aItem['class_link']))
         if(!isset($aItem['class_link']))

+ 7 - 6
modules/boonex/timeline/classes/BxTimelineModule.php

@@ -2472,10 +2472,10 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
     /** 
     /** 
      * @ref bx_timeline-get_repost_element_block "get_repost_element_block"
      * @ref bx_timeline-get_repost_element_block "get_repost_element_block"
      */
      */
-    public function serviceGetRepostElementBlock($iOwnerId, $sType, $sAction, $iObjectId, $aParams = array())
+    public function serviceGetRepostElementBlock($iOwnerId, $sType, $sAction, $iObjectId, $aParams = [])
     {
     {
     	if(!$this->isEnabled())
     	if(!$this->isEnabled())
-    		return '';
+            return '';
 
 
         $aParams = array_merge($this->_oConfig->getRepostDefaults(), $aParams);
         $aParams = array_merge($this->_oConfig->getRepostDefaults(), $aParams);
         return $this->_oTemplate->getRepostElement($iOwnerId, $sType, $sAction, $iObjectId, $aParams);
         return $this->_oTemplate->getRepostElement($iOwnerId, $sType, $sAction, $iObjectId, $aParams);
@@ -2501,14 +2501,15 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
     /** 
     /** 
      * @ref bx_timeline-get_repost_counter "get_repost_counter"
      * @ref bx_timeline-get_repost_counter "get_repost_counter"
      */
      */
-    public function serviceGetRepostCounter($sType, $sAction, $iObjectId)
+    public function serviceGetRepostCounter($sType, $sAction, $iObjectId, $aParams = [])
     {
     {
     	if(!$this->isEnabled())
     	if(!$this->isEnabled())
-    		return '';
+            return '';
 
 
-		$aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
+        $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
 
 
-        return $this->_oTemplate->getRepostCounter($aReposted);
+        $aParams = array_merge($this->_oConfig->getRepostDefaults(), $aParams);
+        return $this->_oTemplate->getRepostCounter($aReposted, $aParams);
     }
     }
 
 
     /**
     /**

+ 51 - 14
modules/boonex/timeline/classes/BxTimelineTemplate.php

@@ -994,18 +994,18 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
         ));
         ));
     }
     }
 
 
-    public function getRepostElement($iOwnerId, $sType, $sAction, $iObjectId, $aParams = array())
+    public function getRepostElement($iOwnerId, $sType, $sAction, $iObjectId, $aParams = [])
     {
     {
         $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
         $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
         if(empty($aReposted) || !is_array($aReposted))
         if(empty($aReposted) || !is_array($aReposted))
             return '';
             return '';
 
 
-		$oModule = $this->getModule();
-		$bDisabled = $oModule->isAllowedRepost($aReposted) !== true || $this->_oDb->isReposted($aReposted['id'], $iOwnerId, $oModule->getUserId());
-		if($bDisabled && (int)$aReposted['reposts'] == 0)
+        $oModule = $this->getModule();
+        $bDisabled = $oModule->isAllowedRepost($aReposted) !== true || $this->_oDb->isReposted($aReposted['id'], $iOwnerId, $oModule->getUserId());
+        if($bDisabled && (int)$aReposted['reposts'] == 0)
             return '';
             return '';
 
 
-		$sStylePrefix = $this->_oConfig->getPrefix('style');
+        $sStylePrefix = $this->_oConfig->getPrefix('style');
         $sStylePrefixRepost = $sStylePrefix . '-repost-';
         $sStylePrefixRepost = $sStylePrefix . '-repost-';
 
 
         $bDynamicMode = isset($aParams['dynamic_mode']) && $aParams['dynamic_mode'] === true;
         $bDynamicMode = isset($aParams['dynamic_mode']) && $aParams['dynamic_mode'] === true;
@@ -1098,20 +1098,23 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
                         'condition' => (int)$aReposted['reposts'] == 0,
                         'condition' => (int)$aReposted['reposts'] == 0,
                         'content' => array()
                         'content' => array()
                     ),
                     ),
-                    'counter' => $this->getRepostCounter($aReposted, $aParams)
+                    'counter' => $this->getRepostCounter($aReposted, array_merge($aParams, ['show_script' => false]))
                 )
                 )
             ),
             ),
             'script' => $this->getRepostJsScript($bDynamicMode)
             'script' => $this->getRepostJsScript($bDynamicMode)
         ));
         ));
     }
     }
 
 
-    public function getRepostCounter($aEvent, $aParams = array())
+    public function getRepostCounter($aEvent, $aParams = [])
     {
     {
         $sStylePrefix = $this->_oConfig->getPrefix('style');
         $sStylePrefix = $this->_oConfig->getPrefix('style');
         $sJsObject = $this->_oConfig->getJsObject('repost');
         $sJsObject = $this->_oConfig->getJsObject('repost');
 
 
+        $bDynamicMode = isset($aParams['dynamic_mode']) && $aParams['dynamic_mode'] === true;
+
         $bShowDoRepostAsButtonSmall = isset($aParams['show_do_repost_as_button_small']) && $aParams['show_do_repost_as_button_small'] == true;
         $bShowDoRepostAsButtonSmall = isset($aParams['show_do_repost_as_button_small']) && $aParams['show_do_repost_as_button_small'] == true;
         $bShowDoRepostAsButton = !$bShowDoRepostAsButtonSmall && isset($aParams['show_do_repost_as_button']) && $aParams['show_do_repost_as_button'] == true;
         $bShowDoRepostAsButton = !$bShowDoRepostAsButtonSmall && isset($aParams['show_do_repost_as_button']) && $aParams['show_do_repost_as_button'] == true;
+        $bShowScript = !isset($aParams['show_script']) || (bool)$aParams['show_script'] === true;
 
 
         $sClass = $sStylePrefix . '-repost-counter';
         $sClass = $sStylePrefix . '-repost-counter';
         if($bShowDoRepostAsButtonSmall)
         if($bShowDoRepostAsButtonSmall)
@@ -1119,17 +1122,41 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
         if($bShowDoRepostAsButton)
         if($bShowDoRepostAsButton)
             $sClass .= ' bx-btn-height';
             $sClass .= ' bx-btn-height';
 
 
-        return $this->parseLink('javascript:void(0)', !empty($aEvent['reposts']) && (int)$aEvent['reposts'] > 0 ? $this->getRepostCounterLabel($aEvent['reposts']) : '', array(
-            'id' => $this->_oConfig->getHtmlIds('repost', 'counter') . $aEvent['id'],
+        return $this->parseHtmlByName('repost_counter.html', [
             'class' => $sClass,
             'class' => $sClass,
-            'title' => _t('_bx_timeline_txt_reposted_by'),
-            'onclick' => 'javascript:' . $sJsObject . '.toggleByPopup(this, ' . $aEvent['id'] . ')'
-        ));
+            'bx_repeat:attrs' => [
+                ['key' => 'id', 'value' => $this->_oConfig->getHtmlIds('repost', 'counter') . $aEvent['id']],
+                ['key' => 'title', 'value' => _t('_bx_timeline_txt_reposted_by')],
+                ['key' => 'href', 'value' => 'javascript:void(0)'],
+                ['key' => 'onclick', 'value' => 'javascript:' . $sJsObject . '.toggleByPopup(this, ' . $aEvent['id'] . ')']
+            ],
+            'content' => !empty($aEvent['reposts']) && (int)$aEvent['reposts'] > 0 ? $this->getRepostCounterLabel($aEvent['reposts'], $aParams) : '',
+            'script' => $bShowScript ? $this->getRepostJsScript($bDynamicMode) : ''
+        ]);
     }
     }
 
 
-    public function getRepostCounterLabel($iCount)
+    public function getRepostCounterLabel($iCount, $aParams = [])
     {
     {
-        return $iCount;
+        $sStylePrefix = $this->_oConfig->getPrefix('style');
+
+        return $this->parseHtmlByName('repost_counter_label.html', [
+            'style_prefix' => $sStylePrefix,
+            'bx_if:show_icon' => array(
+                'condition' => !isset($aParams['show_counter_label_icon']) || (bool)$aParams['show_counter_label_icon'] === true,
+                'content' => array(
+                    'style_prefix' => $sStylePrefix,
+                    'name' => $this->_getCounterIcon($aParams),
+                    'emoji' => ''
+                )
+            ),
+            'bx_if:show_text' => array(
+                'condition' => !isset($aParams['show_counter_label_text']) || (bool)$aParams['show_counter_label_text'] === true,
+                'content' => array(
+                    'style_prefix' => $sStylePrefix,
+                    'text' => $this->_getCounterLabel($iCount, $aParams)
+                )
+            )
+        ]);
     }
     }
 
 
     public function getRepostedBy($iId)
     public function getRepostedBy($iId)
@@ -3083,6 +3110,16 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
 
 
         return $iResult;
         return $iResult;
     }
     }
+
+    protected function _getCounterIcon($aParams = array())
+    {
+        return 'redo';
+    }
+
+    protected function _getCounterLabel($iCount, $aParams = array())
+    {
+        return _t(isset($aParams['caption']) ? $aParams['caption'] : '_bx_timeline_txt_repost_counter', $iCount);
+    }
 }
 }
 
 
 /** @} */
 /** @} */

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

@@ -386,6 +386,7 @@
     <string name="_bx_timeline_txt_filters"><![CDATA[Filters]]></string>
     <string name="_bx_timeline_txt_filters"><![CDATA[Filters]]></string>
 
 
     <string name="_bx_timeline_txt_do_repost"><![CDATA[Repost]]></string>
     <string name="_bx_timeline_txt_do_repost"><![CDATA[Repost]]></string>
+    <string name="_bx_timeline_txt_repost_counter"><![CDATA[{0}]]></string>
     <string name="_bx_timeline_txt_reposted"><![CDATA[Reposted {0}'s {1}.]]></string>
     <string name="_bx_timeline_txt_reposted"><![CDATA[Reposted {0}'s {1}.]]></string>
     <string name="_bx_timeline_txt_reposted_by"><![CDATA[Reposted by]]></string>
     <string name="_bx_timeline_txt_reposted_by"><![CDATA[Reposted by]]></string>
     <string name="_bx_timeline_txt_err_cannot_repost"><![CDATA[Cannot repost. Please report.]]></string>
     <string name="_bx_timeline_txt_err_cannot_repost"><![CDATA[Cannot repost. Please report.]]></string>

+ 2 - 1
modules/boonex/timeline/install/sql/enable.sql

@@ -219,7 +219,8 @@ INSERT INTO `sys_menu_items`(`set_name`, `module`, `name`, `title_system`, `titl
 ('bx_timeline_menu_item_counters', 'bx_timeline', 'item-vote', '_bx_timeline_menu_item_title_system_item_vote', '', 'javascript:void(0)', '', '', '', '', '', 0, 2147483647, 0, 0, 1, 10),
 ('bx_timeline_menu_item_counters', 'bx_timeline', 'item-vote', '_bx_timeline_menu_item_title_system_item_vote', '', 'javascript:void(0)', '', '', '', '', '', 0, 2147483647, 0, 0, 1, 10),
 ('bx_timeline_menu_item_counters', 'bx_timeline', 'item-reaction', '_bx_timeline_menu_item_title_system_item_reaction', '', 'javascript:void(0)', '', '', '', '', '', 0, 2147483647, 1, 0, 1, 20),
 ('bx_timeline_menu_item_counters', 'bx_timeline', 'item-reaction', '_bx_timeline_menu_item_title_system_item_reaction', '', 'javascript:void(0)', '', '', '', '', '', 0, 2147483647, 1, 0, 1, 20),
 ('bx_timeline_menu_item_counters', 'bx_timeline', 'item-score', '_bx_timeline_menu_item_title_system_item_score', '', 'javascript:void(0)', '', '', '', '', '', 0, 2147483647, 0, 0, 1, 30),
 ('bx_timeline_menu_item_counters', 'bx_timeline', 'item-score', '_bx_timeline_menu_item_title_system_item_score', '', 'javascript:void(0)', '', '', '', '', '', 0, 2147483647, 0, 0, 1, 30),
-('bx_timeline_menu_item_counters', 'bx_timeline', 'item-comment', '_bx_timeline_menu_item_title_system_item_comment', '', 'javascript:void(0)', '', '', '', '', '', 0, 2147483647, 1, 0, 1, 40);
+('bx_timeline_menu_item_counters', 'bx_timeline', 'item-comment', '_bx_timeline_menu_item_title_system_item_comment', '', 'javascript:void(0)', '', '', '', '', '', 0, 2147483647, 1, 0, 1, 40),
+('bx_timeline_menu_item_counters', 'bx_timeline', 'item-repost', '_bx_timeline_menu_item_title_system_item_repost', '', 'javascript:void(0)', '', '', '', '', '', 0, 2147483647, 1, 0, 1, 50);
 
 
 -- MENU: Item Meta Info
 -- MENU: Item Meta Info
 INSERT INTO `sys_objects_menu` (`object`, `title`, `set_name`, `module`, `template_id`, `deletable`, `active`, `override_class_name`, `override_class_file`) VALUES
 INSERT INTO `sys_objects_menu` (`object`, `title`, `set_name`, `module`, `template_id`, `deletable`, `active`, `override_class_name`, `override_class_file`) VALUES

+ 15 - 0
modules/boonex/timeline/template/css/repost.css

@@ -84,4 +84,19 @@ div.bx-tl-repost div.bx-tl-repost-counter-holder {
 /*--- Counter Styles ---*/
 /*--- Counter Styles ---*/
 .bx-tl-repost-counter-holder .bx-tl-repost-counter {
 .bx-tl-repost-counter-holder .bx-tl-repost-counter {
     line-height: normal;
     line-height: normal;
+}
+
+.bx-tl-repost-counter span.bx-tl-counter-icon {
+    position: relative;
+    box-sizing: border-box;
+
+    width: 2.0rem;
+    height: 2.0rem;
+
+    background-color: rgba(232, 232, 232, 1.0);
+    border: 1px solid #ffffff;
+    border-radius: 1rem;
+
+    line-height: normal;
+    font-size: 1.0rem;
 }
 }