Răsfoiți Sursa

#24 - Share feature update.

AntonLV 11 ani în urmă
părinte
comite
ca1f8fd936

+ 10 - 28
modules/boonex/timeline/classes/BxTimelineMenuItemActions.php

@@ -45,34 +45,12 @@ class BxTimelineMenuItemActions extends BxTemplMenuCustom
             $sCommentsOnclick = $this->_oModule->_oConfig->getJsObject('view') . ".commentItem(this, '" . $sCommentsSystem . "', " . $iCommentsObject . ")";
         }
 
-        $iOwnerId = $this->_oModule->getUserId(); //--- in whose timeline the content will be shared
-        $sShareType = $sReshareType = $aEvent['type'];
-        $sShareAction = $sReshareAction = $aEvent['action'];
-
-        if($this->_oModule->_oConfig->isSystem($sShareType, $sShareAction))
-            $iShareObject = $iReshareObject = $aEvent['object_id'];
-        else {
-            $iShareObject = $iReshareObject = $aEvent['id'];
-
-            $sCommonPrefix = $this->_oModule->_oConfig->getPrefix('common_post');
-            if(str_replace($sCommonPrefix, '', $sShareType) == BX_TIMELINE_PARSE_TYPE_SHARE) {
-                $sReshareType = $aEvent['content']['type'];
-                $sReshareAction = $aEvent['content']['action'];
-                $iReshareObject = $aEvent['content']['object_id'];
-            }
-        }
-
         $this->addMarkers(array(
             'content_id' => $aEvent['id'],
 
             'comment_system' => $sCommentsSystem,
             'comment_object' => $iCommentsObject,
             'comment_onclick' => $sCommentsOnclick,
-
-            'share_type' => $sShareType,
-            'share_action' => $sShareAction,
-            'share_object' => $iShareObject,
-            'share_onclick' => $this->_oModule->serviceGetShareJsClick($iOwnerId, $sReshareType, $sReshareAction, $iReshareObject),
         ));
     }
 
@@ -103,6 +81,16 @@ class BxTimelineMenuItemActions extends BxTemplMenuCustom
     	return $this->_oModule->getVoteObject($sVotesSystem, $iVotesObject)->getElementInline();
     }
 
+	protected function _getMenuItemItemShare($aItem)
+    {
+		$iOwnerId = $this->_oModule->getUserId(); //--- in whose timeline the content will be shared
+        $sType = $this->_aEvent['type'];
+        $sAction = $this->_aEvent['action'];
+        $iObjectId = $this->_oModule->_oConfig->isSystem($sType, $sAction) ? $this->_aEvent['object_id'] : $this->_aEvent['id'];
+
+        return $this->_oModule->serviceGetShareElementBlock($iOwnerId, $sType, $sAction, $iObjectId);
+    }
+
     /**
      * Check if menu items is visible.
      * @param $a menu item array
@@ -127,12 +115,6 @@ class BxTimelineMenuItemActions extends BxTemplMenuCustom
                 if(!empty($this->_aEvent))
                     $aCheckFuncParams = array($this->_aEvent);
                 break;
-
-            case 'item-share':
-                $sCheckFuncName = 'isAllowedShare';
-                if(!empty($this->_aEvent))
-                    $aCheckFuncParams = array($this->_aEvent);
-                break;
         }
 
         if(!$sCheckFuncName || !method_exists($this->_oModule, $sCheckFuncName))

+ 0 - 8
modules/boonex/timeline/classes/BxTimelineModule.php

@@ -423,14 +423,6 @@ class BxTimelineModule extends BxBaseModNotificationsModule
         ));
     }
 
-    public function serviceGetMenuItemAddonShare($sType, $sAction, $iObjectId)
-    {
-        if(empty($sType) || empty($iObjectId))
-            return '';
-
-        return $this->serviceGetShareCounter($sType, $sAction, $iObjectId);
-    }
-
     public function serviceGetSettingsCheckerHelper()
     {
         bx_import('FormCheckerHelper', $this->_aModule);

+ 39 - 15
modules/boonex/timeline/classes/BxTimelineTemplate.php

@@ -269,9 +269,13 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
         if(empty($aShared) || !is_array($aShared))
             return '';
 
-        if($this->getModule()->isAllowedShare($aShared) !== true)
+		$bDisabled = $this->getModule()->isAllowedShare($aShared) !== true;
+		if($bDisabled && (int)$aShared['shares'] == 0)
             return '';
 
+		$sStylePrefix = $this->_oConfig->getPrefix('style');
+        $sStylePrefixShare = $sStylePrefix . '-share-';
+
         $bShowDoShareAsButtonSmall = isset($aParams['show_do_share_as_button_small']) && $aParams['show_do_share_as_button_small'] == true;
         $bShowDoShareAsButton = !$bShowDoShareAsButtonSmall && isset($aParams['show_do_share_as_button']) && $aParams['show_do_share_as_button'] == true;
 
@@ -279,31 +283,51 @@ class BxTimelineTemplate extends BxBaseModNotificationsTemplate
         $bShowDoShareLabel = isset($aParams['show_do_share_label']) && $aParams['show_do_share_label'] == true;
         $bShowCounter = isset($aParams['show_counter']) && $aParams['show_counter'] === true;
 
-        $sDoShare = '';
+        //--- Do share link ---//
+		$sClass = $sStylePrefixShare . 'do-share';
+		if($bShowDoShareAsButton)
+			$sClass .= ' bx-btn';
+		else if($bShowDoShareAsButtonSmall)
+			$sClass .= ' bx-btn bx-btn-small';
+
+		$sOnClick = '';
+		if(!$bDisabled) {
+			$sCommonPrefix = $this->_oConfig->getPrefix('common_post');
+			if(str_replace($sCommonPrefix, '', $sType) == BX_TIMELINE_PARSE_TYPE_SHARE) {
+				$aSharedData = $this->_getCommonData($aShared);
+	
+	            $sOnClick = $this->getShareJsClick($iOwnerId, $aSharedData['content']['type'], $aSharedData['content']['action'], $aSharedData['content']['object_id']);
+			}
+			else
+				$sOnClick = $this->getShareJsClick($iOwnerId, $sType, $sAction, $iObjectId);
+		}
+		else
+			$sClass .= $bShowDoShareAsButton || $bShowDoShareAsButtonSmall ? ' bx-btn-disabled' : ' ' . $sStylePrefixShare . 'disabled';
+
+		$aOnClickAttrs = array();
+		if(!empty($sClass))
+			$aOnClickAttrs[] = array('key' => 'class', 'value' => $sClass);
+		if(!empty($sOnClick))
+			$aOnClickAttrs[] = array('key' => 'onclick', 'value' => $sOnClick);
+
+		$sDoShare = '';
         if($bShowDoShareIcon)
             $sDoShare .= $this->parseHtmlByName('bx_icon.html', array('name' => 'share'));
 
         if($bShowDoShareLabel)
             $sDoShare .= ($sDoShare != '' ? ' ' : '') . _t('_bx_timeline_txt_do_share');
 
-        $sDoShare = $this->parseHtmlByName('bx_a.html', array(
-            'href' => 'javascript:void(0)',
-            'title' => _t('_bx_timeline_txt_do_share'),
-            'bx_repeat:attrs' => array(
-                array('key' => 'class', 'value' => ($bShowDoShareAsButton ? 'bx-btn' : '') . ($bShowDoShareAsButtonSmall ? 'bx-btn bx-btn-small' : '')),
-                array('key' => 'onclick', 'value' => $this->getShareJsClick($iOwnerId, $sType, $sAction, $iObjectId))
-            ),
-            'content' => $sDoShare
-        ));
-
-        $sStylePrefix = $this->_oConfig->getPrefix('style');
-        $sStylePrefixShare = $sStylePrefix . '-share-';
         return $this->parseHtmlByName('share_element_block.html', array(
             'style_prefix' => $sStylePrefix,
             'html_id' => $this->_oConfig->getHtmlIds('share', 'main') . $aShared['id'],
             'class' => ($bShowDoShareAsButton ? $sStylePrefixShare . 'button' : '') . ($bShowDoShareAsButtonSmall ? $sStylePrefixShare . 'button-small' : ''),
             'count' => $aShared['shares'],
-            'do_share' => $sDoShare,
+            'do_share' => $this->parseHtmlByName('bx_a.html', array(
+	            'href' => 'javascript:void(0)',
+	            'title' => _t('_bx_timeline_txt_do_share'),
+	            'bx_repeat:attrs' => $aOnClickAttrs,
+	            'content' => $sDoShare
+	        )),
             'bx_if:show_counter' => array(
                 'condition' => $bShowCounter,
                 'content' => array(

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

@@ -81,7 +81,6 @@
     <string name="_bx_timeline_menu_item_title_item_comment"><![CDATA[Comment]]></string>
     <string name="_bx_timeline_menu_item_title_system_item_vote"><![CDATA[Vote]]></string>
     <string name="_bx_timeline_menu_item_title_system_item_share"><![CDATA[Share]]></string>
-    <string name="_bx_timeline_menu_item_title_item_share"><![CDATA[Share]]></string>
 
 	<string name="_bx_timeline_menu_title_post_attachments"><![CDATA[Form Attachments]]></string>
     <string name="_bx_timeline_menu_set_title_post_attachments"><![CDATA[Form Attachments]]></string>

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

@@ -51,7 +51,7 @@ INSERT INTO `sys_menu_sets`(`set_name`, `module`, `title`, `deletable`) VALUES
 INSERT INTO `sys_menu_items`(`set_name`, `module`, `name`, `title_system`, `title`, `link`, `onclick`, `target`, `icon`, `addon`, `submenu_object`, `visible_for_levels`, `active`, `copyable`, `editable`, `order`) VALUES 
 ('bx_timeline_menu_item_actions', 'bx_timeline', 'item-comment', '_bx_timeline_menu_item_title_system_item_comment', '_bx_timeline_menu_item_title_item_comment', 'javascript:void(0)', 'javascript:{comment_onclick}', '_self', 'comment', 'a:3:{s:6:"module";s:11:"bx_timeline";s:6:"method";s:27:"get_menu_item_addon_comment";s:6:"params";a:2:{i:0;s:16:"{comment_system}";i:1;s:16:"{comment_object}";}}', '', 2147483647, 1, 0, 1, 1),
 ('bx_timeline_menu_item_actions', 'bx_timeline', 'item-vote', '_bx_timeline_menu_item_title_system_item_vote', '', 'javascript:void(0)', '', '', '', '', '', 2147483647, 1, 0, 0, 2),
-('bx_timeline_menu_item_actions', 'bx_timeline', 'item-share', '_bx_timeline_menu_item_title_system_item_share', '_bx_timeline_menu_item_title_item_share', 'javascript:void(0)', 'javascript:{share_onclick}', '_self', 'share', 'a:3:{s:6:"module";s:11:"bx_timeline";s:6:"method";s:25:"get_menu_item_addon_share";s:6:"params";a:3:{i:0;s:12:"{share_type}";i:1;s:14:"{share_action}";i:2;s:14:"{share_object}";}}', '', 2147483647, 1, 0, 1, 3);
+('bx_timeline_menu_item_actions', 'bx_timeline', 'item-share', '_bx_timeline_menu_item_title_system_item_share', '', 'javascript:void(0)', '', '', '', '', '', 2147483647, 1, 0, 0, 3);
 
 -- MENU: Post form attachments (Link, Photo, Video)
 INSERT INTO `sys_objects_menu`(`object`, `title`, `set_name`, `module`, `template_id`, `deletable`, `active`, `override_class_name`, `override_class_file`) VALUES 

+ 4 - 0
modules/boonex/timeline/template/css/share.css

@@ -4,6 +4,10 @@
 	line-height: 1.25rem;
 }
 
+.bx-tl-share .bx-tl-share-element-holder .bx-tl-share-do-share.bx-tl-share-disabled {
+	color: #ddd;
+}
+
 .bx-tl-share-button .bx-tl-share-element-holder,
 .bx-tl-share-button .bx-tl-share-counter-holder {
 	line-height: 36px;