AntonLV 7 anni fa
parent
commit
4eeb86582a

+ 11 - 2
inc/classes/BxDolProfile.php

@@ -173,15 +173,24 @@ class BxDolProfile extends BxDolFactory implements iBxDolProfile
         return BX_PROFILE_STATUS_ACTIVE == $this->getStatus($iProfileId);
     }
 
-	/**
+    /**
      * Is profile online
      */
-	public function isOnline($iProfileId = false)
+    public function isOnline($iProfileId = false)
     {
         $iProfileId = (int)$iProfileId ? $iProfileId : $this->_iProfileID;
         return $this->_oQuery->isOnline($iProfileId);
     }
 
+    /**
+     * Is profile can 'Act as Profile'
+     */
+    public function isActAsProfile($iProfileId = false)
+    {
+        $aInfo = $this->_oQuery->getInfoById((int)$iProfileId ? $iProfileId : $this->_iProfileID);
+        return BxDolService::call($aInfo['type'], 'act_as_profile');
+    }
+
     /**
      * Get profile status
      */

+ 3 - 2
install/sql/system.sql

@@ -4515,8 +4515,9 @@ INSERT INTO `sys_pages_blocks` (`object`, `cell_id`, `module`, `title`, `designb
 -- service blocks
 SET @iBlockOrder = IFNULL((SELECT `order` FROM `sys_pages_blocks` WHERE `object` = '' AND `cell_id` = 0 ORDER BY `order` DESC LIMIT 1), 0);
 INSERT INTO `sys_pages_blocks` (`object`, `cell_id`, `module`, `title_system`, `title`, `designbox_id`, `visible_for_levels`, `type`, `content`, `deletable`, `copyable`, `active`, `order`) VALUES
-('', 0, 'system', '_sys_page_block_title_sys_create_post_public', '_sys_page_block_title_create_post_public', 3, 2147483647, 'service', 'a:4:{s:6:"module";s:6:"system";s:6:"method";s:20:"get_create_post_form";s:6:"params";a:0:{}s:5:"class";s:13:"TemplServices";}', 0, 1, 1, @iBlockOrder + 1),
-('', 0, 'system', '_sys_page_block_title_sys_create_post_context', '_sys_page_block_title_create_post_context', 3, 2147483647, 'service', 'a:4:{s:6:"module";s:6:"system";s:6:"method";s:20:"get_create_post_form";s:6:"params";a:1:{i:0;s:12:"{profile_id}";}s:5:"class";s:13:"TemplServices";}', 0, 1, 1, @iBlockOrder + 2);
+('', 0, 'system', '_sys_page_block_title_sys_create_post', '_sys_page_block_title_create_post', 3, 2147483647, 'service', 'a:4:{s:6:"module";s:6:"system";s:6:"method";s:20:"get_create_post_form";s:6:"params";a:1:{i:0;i:0;}s:5:"class";s:13:"TemplServices";}', 0, 1, 1, @iBlockOrder + 1),
+('', 0, 'system', '_sys_page_block_title_sys_create_post_context', '_sys_page_block_title_create_post_context', 3, 2147483647, 'service', 'a:4:{s:6:"module";s:6:"system";s:6:"method";s:20:"get_create_post_form";s:6:"params";a:1:{i:0;s:12:"{profile_id}";}s:5:"class";s:13:"TemplServices";}', 0, 1, 1, @iBlockOrder + 2),
+('', 0, 'system', '_sys_page_block_title_sys_create_post_public', '_sys_page_block_title_create_post_public', 3, 2147483647, 'service', 'a:4:{s:6:"module";s:6:"system";s:6:"method";s:20:"get_create_post_form";s:6:"params";a:0:{}s:5:"class";s:13:"TemplServices";}', 0, 1, 1, @iBlockOrder + 3);
 
 -- content blocks
 INSERT INTO `sys_pages_blocks` (`object`, `cell_id`, `module`, `title_system`, `title`, `designbox_id`, `visible_for_levels`, `type`, `content`, `deletable`, `copyable`, `active`, `order`) VALUES

+ 51 - 7
modules/base/general/classes/BxBaseModGeneralModule.php

@@ -54,6 +54,7 @@ class BxBaseModGeneralModule extends BxDolModule
 
     	$aParams = bx_process_input(array_intersect_key($_GET, $this->_aFormParams));
     	$aParams = array_merge($this->_aFormParams, $aParams);
+        $aParams['context_id'] = (bool)$aParams['context_id'] ? (int)$aParams['context_id'] : false;
 
     	$mixedResponse = $this->serviceGetCreatePostForm($aParams);
     	if(empty($mixedResponse))
@@ -442,9 +443,16 @@ class BxBaseModGeneralModule extends BxDolModule
      */
     public function serviceGetObjectForm ($sType, $aParams = array())
     {
-        if (!in_array($sType, array('add', 'edit', 'view', 'delete')))
+        if(!in_array($sType, array('add', 'edit', 'view', 'delete')))
             return false;
 
+        $mixedContextId = isset($aParams['context_id']) ? $aParams['context_id'] : false;
+
+        $bContext = $mixedContextId !== false;
+        if($bContext && ($oContextProfile = BxDolProfile::getInstance(abs($mixedContextId))) !== false)
+            if($oContextProfile->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
+                return false;
+
         $CNF = &$this->_oConfig->CNF;
 
         bx_import('FormsEntryHelper', $this->_aModule);
@@ -465,13 +473,49 @@ class BxBaseModGeneralModule extends BxDolModule
         $oForm = $oFormsHelper->$sFunc($sDisplay);
 
         $sKey = 'FIELD_ALLOW_VIEW_TO';
-        if(!empty($aParams['context_id']) && !empty($CNF[$sKey]) && !empty($oForm->aInputs[$CNF[$sKey]])) {
-            foreach($oForm->aInputs[$CNF[$sKey]]['values'] as $aValue)
-                if(isset($aValue['key']) && (int)$aValue['key'] == -(int)$aParams['context_id']) {
-                    $oForm->aInputs[$CNF[$sKey]]['value'] = -(int)$aParams['context_id'];
-                    $oForm->aInputs[$CNF[$sKey]]['type'] = 'hidden';
-                    break;
+        if(!empty($CNF[$sKey]) && !empty($oForm->aInputs[$CNF[$sKey]]) && (!$bContext || $mixedContextId < 0)) {
+            $bContextOwner = $bContext && abs($mixedContextId) == (int)bx_get_logged_profile_id();
+
+            if(!$bContext || $bContextOwner) {
+                $iGc = 0;
+                $iKeyGh = false;
+                foreach($oForm->aInputs[$CNF[$sKey]]['values'] as $iKey => $aValue) {
+                    if(isset($aValue['type']) && in_array($aValue['type'], array('group_header', 'group_end'))) {
+                        if($iKeyGh !== false && $iGc == 0) {
+                            unset($oForm->aInputs[$CNF[$sKey]]['values'][$iKeyGh]);
+                            $iKeyGh = false;
+
+                            if($aValue['type'] == 'group_end')
+                                unset($oForm->aInputs[$CNF[$sKey]]['values'][$iKey]);
+                        }
+
+                        if($aValue['type'] == 'group_header') {
+                            $iGc = 0;
+                            $iKeyGh = $iKey;
+                        }
+
+                        continue;
+                    }
+
+                    //--- Show 'Public' privacy group only in Public post form. 
+                    if(!$bContext && $aValue['key'] == BX_DOL_PG_ALL) {
+                        $iGc += 1;
+                        continue;
+                    }
+
+                    //--- Show a default privacy groups in Profile (for Owner) post form.
+                    if($bContextOwner && (int)$aValue['key'] >= 0) {
+                        $iGc += 1;
+                        continue;
+                    }
+
+                    unset($oForm->aInputs[$CNF[$sKey]]['values'][$iKey]);
                 }
+            }
+            else {
+                $oForm->aInputs[$CNF[$sKey]]['value'] = $mixedContextId;
+                $oForm->aInputs[$CNF[$sKey]]['type'] = 'hidden';
+            }
         }
 
         bx_alert('system', 'get_object_form', 0, 0, array(

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

@@ -2514,6 +2514,8 @@ If it is not enabled then please consider implement this optimization, since it
 	<string name="_sys_page_block_title_confirm_email"><![CDATA[Email Confirmation]]></string>
 	<string name="_sys_page_block_title_confirm_phone"><![CDATA[Phone Confirmation]]></string>
 	<string name="_sys_page_block_title_create_account"><![CDATA[Sign up]]></string>
+        <string name="_sys_page_block_title_sys_create_post"><![CDATA[Create Post]]></string>
+	<string name="_sys_page_block_title_create_post"><![CDATA[Add new...]]></string>
 	<string name="_sys_page_block_title_sys_create_post_context"><![CDATA[Create Post (Context)]]></string>
 	<string name="_sys_page_block_title_create_post_context"><![CDATA[Add new...]]></string>
 	<string name="_sys_page_block_title_sys_create_post_public"><![CDATA[Create Post (Public)]]></string>

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

@@ -98,7 +98,7 @@
   <string name="_bx_timeline_page_title_sys_manage_administration"><![CDATA[Управление всеми событями ленты]]></string>
   <string name="_bx_timeline_page_title_manage"><![CDATA[Управление]]></string>
 	<string name="_bx_timeline_page_title_account"><![CDATA[Хроника новостей]]></string>
-	<string name="_bx_timeline_page_block_title_system_post_profile"><![CDATA[Создать публикацию]]></string>
+	<string name="_bx_timeline_page_block_title_system_post_profile"><![CDATA[Создать публикацию (в контекст)]]></string>
 	<string name="_bx_timeline_page_block_title_post_profile"><![CDATA[Создать публикацию]]></string>
 	<string name="_bx_timeline_page_block_title_system_view_profile"><![CDATA[Хроника новостей профайла (лента)]]></string>
 	<string name="_bx_timeline_page_block_title_view_profile"><![CDATA[Хроника новостей профайла]]></string>

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

@@ -2513,6 +2513,8 @@
 	<string name="_sys_page_block_title_confirm_email"><![CDATA[Email - Подтверждение]]></string>
 	<string name="_sys_page_block_title_confirm_phone"><![CDATA[Телефон - Подтверждение]]></string>
 	<string name="_sys_page_block_title_create_account"><![CDATA[Присоединиться]]></string>
+        <string name="_sys_page_block_title_sys_create_post"><![CDATA[Создать публикацию]]></string>
+	<string name="_sys_page_block_title_create_post"><![CDATA[Добавить...]]></string>
 	<string name="_sys_page_block_title_sys_create_post_context"><![CDATA[Создать публикацию (в контекст)]]></string>
 	<string name="_sys_page_block_title_create_post_context"><![CDATA[Добавить...]]></string>
 	<string name="_sys_page_block_title_sys_create_post_public"><![CDATA[Создать публикацию (публично)]]></string>

+ 28 - 3
modules/boonex/timeline/classes/BxTimelineFormPost.php

@@ -227,18 +227,43 @@ class BxTimelineFormPost extends BxBaseModGeneralFormEntry
             return $aInput;
         }
 
-        if($this->_bPublicMode || $this->_bProfileMode)
+        $bProfileModeOwner = $this->_bProfileMode && $iOwnerId == $iUserId;
+        if($this->_bPublicMode || $bProfileModeOwner) {
+            $iGc = 0;
+            $iKeyGh = false;
             foreach($aInput['values'] as $iKey => $aValue) {
+                if(isset($aValue['type']) && in_array($aValue['type'], array('group_header', 'group_end'))) {
+                    if($iKeyGh !== false && $iGc == 0) {
+                        unset($aInput['values'][$iKeyGh]);
+                        $iKeyGh = false;
+
+                        if($aValue['type'] == 'group_end')
+                            unset($aInput['values'][$iKey]);
+                    }
+
+                    if($aValue['type'] == 'group_header') {
+                        $iGc = 0;
+                        $iKeyGh = $iKey;
+                    }
+
+                    continue;
+                }
+
                 //--- Show 'Public' privacy group only in Public post form. 
-                if($this->_bPublicMode && isset($aValue['key']) && $aValue['key'] == BX_DOL_PG_ALL)
+                if($this->_bPublicMode && $aValue['key'] == BX_DOL_PG_ALL) {
+                    $iGc += 1;
                     continue;
+                }
 
                 //--- Show a default privacy groups in Profile (for Owner) post form.
-                if($this->_bProfileMode && $iOwnerId == $iUserId && isset($aValue['key']) && (int)$aValue['key'] >= 0)
+                if($bProfileModeOwner && (int)$aValue['key'] >= 0) {
+                    $iGc += 1;
                     continue;
+                }
 
                 unset($aInput['values'][$iKey]);
             }
+        }
 
         return $aInput;
     }

+ 32 - 18
modules/boonex/timeline/classes/BxTimelineModule.php

@@ -505,23 +505,28 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
     {
     	$aParams = array_merge($this->_aFormParams, $aParams);
 
-        $bContextId = !empty($aParams['context_id']);
-        $bFormDisplay = !empty($aParams['display']);
-
-        $this->_iOwnerId = $bContextId ? (int)$aParams['context_id'] : 0;
+        $bContext = $aParams['context_id'] !== false;
+        $this->_iOwnerId = $bContext ? abs($aParams['context_id']) : 0;
 
     	$oForm = $this->serviceGetObjectForm('add', $aParams);
     	if(!$oForm)
             return '';
 
-        $aParams['type'] = $bContextId ? BX_BASE_MOD_NTFS_TYPE_OWNER : BX_BASE_MOD_NTFS_TYPE_PUBLIC;
+        $aParams['type'] = BX_BASE_MOD_NTFS_TYPE_PUBLIC;
+        $aParams['form_display'] = 'form_display_post_add_public';
+        if($bContext) {
+            if($aParams['context_id'] < 0) {
+                $aParams['type'] = BX_BASE_MOD_NTFS_TYPE_OWNER;
+                $aParams['form_display'] = 'form_display_post_add_profile';
+            }
+            else {
+                $aParams['type'] = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
+                $aParams['form_display'] = 'form_display_post_add';
+            }
+        }
 
-        if($bFormDisplay)
+        if(!empty($aParams['display']))
             $aParams['form_display'] = $aParams['display'];
-        else if($bContextId) 
-            $aParams['form_display'] = 'form_display_post_add_profile';
-        else
-            $aParams['form_display'] = 'form_display_post_add_public';
 
     	$aResult = $this->getFormPost($aParams);
     	if(!empty($aResult['form'])) {
@@ -564,17 +569,26 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
     	if(!in_array($sType, array('add')))
             return false;
 
-        $bContextId = !empty($aParams['context_id']);
-        $bFormDisplay = !empty($aParams['display']);
+        $bContext = $aParams['context_id'] !== false;
+        if($bContext && ($oContextProfile = BxDolProfile::getInstance(abs($aParams['context_id']))) !== false)
+            if($oContextProfile->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
+                return false;
 
-        $aParams['type'] = $bContextId ? BX_BASE_MOD_NTFS_TYPE_OWNER : BX_BASE_MOD_NTFS_TYPE_PUBLIC;
+        $aParams['type'] = BX_BASE_MOD_NTFS_TYPE_PUBLIC;
+        $aParams['form_display'] = 'form_display_post_add_public';
+        if($bContext) {
+            if($aParams['context_id'] < 0) {
+                $aParams['type'] = BX_BASE_MOD_NTFS_TYPE_OWNER;
+                $aParams['form_display'] = 'form_display_post_add_profile';
+            }
+            else {
+                $aParams['type'] = BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS;
+                $aParams['form_display'] = 'form_display_post_add';
+            }
+        }
 
-        if($bFormDisplay)
+        if(!empty($aParams['display']))
             $aParams['form_display'] = $aParams['display'];
-        else if($bContextId)
-            $aParams['form_display'] = 'form_display_post_add_profile';
-        else
-            $aParams['form_display'] = 'form_display_post_add_public';
 
         $oForm = $this->getFormPostObject($aParams);
 

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

@@ -98,7 +98,7 @@
 	<string name="_bx_timeline_page_title_account"><![CDATA[Feed]]></string>
   <string name="_bx_timeline_page_title_sys_manage_administration"><![CDATA[Manage All]]></string>
   <string name="_bx_timeline_page_title_manage"><![CDATA[Manage]]></string>
-	<string name="_bx_timeline_page_block_title_system_post_profile"><![CDATA[Post to Feed]]></string>
+	<string name="_bx_timeline_page_block_title_system_post_profile"><![CDATA[Post to Сontext Feed]]></string>
 	<string name="_bx_timeline_page_block_title_post_profile"><![CDATA[Post to Feed]]></string>
 	<string name="_bx_timeline_page_block_title_system_view_profile"><![CDATA[Profile Feed (Timeline)]]></string>
 	<string name="_bx_timeline_page_block_title_view_profile"><![CDATA[Profile Feed]]></string>

+ 23 - 6
template/scripts/BxBaseServices.php

@@ -99,15 +99,32 @@ class BxBaseServices extends BxDol implements iBxDolProfileService
         return array();
     }
     
-    public function serviceGetCreatePostForm($iContextId = 0, $sDefault = '', $aCustom = array())
+    /**
+     * Get United Create Post form.
+     * 
+     * @param type $mixedContextId - context which the post will be created in:
+     *      false = 'Public' post form;
+     *      0 = 'Account' post form, which allows to post in your own profile and connections;
+     *      n = 'Context' post form, which allows to post in context (3d party profile, group, event, etc).
+     * @param type $sDefault - tab selected by default.
+     * @param type $aCustom - an array with custom paramaters.
+     * @return string
+     */
+    public function serviceGetCreatePostForm($mixedContextId = false, $sDefault = '', $aCustom = array())
     {
     	if(!isLogged())
             return '';
 
-    	$oProfile = BxDolProfile::getInstance();
+        if($mixedContextId !== false)
+            $mixedContextId = (int)(!empty($mixedContextId) ? -$mixedContextId : bx_get_logged_profile_id());
+
+        $bContext = $mixedContextId !== false;
+        if($bContext && ($oContextProfile = BxDolProfile::getInstance(abs($mixedContextId))) !== false)
+            if($oContextProfile->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
+                return '';
 
-        $sTitle = _t('_sys_page_block_title_create_post_' . (empty($iContextId) ? 'public' : 'context'));
-        $sPlaceholder = _t('_sys_txt_create_post_placeholder', $oProfile->getDisplayName());
+        $sTitle = _t('_sys_page_block_title_create_post' . (!$bContext ? '_public' : ($mixedContextId < 0 ? '_context' : '')));
+        $sPlaceholder = _t('_sys_txt_create_post_placeholder', BxDolProfile::getInstance()->getDisplayName());
 
     	$oMenu = BxDolMenu::getObjectInstance('sys_create_post');
 
@@ -129,7 +146,7 @@ class BxBaseServices extends BxDol implements iBxDolProfileService
             'sObjName' => $sJsObject,
             'sRootUrl' => BX_DOL_URL_ROOT,
             'sDefault' => $sDefault,
-            'iContextId' => $iContextId,
+            'iContextId' => $bContext ? $mixedContextId : 0,
             'oCustom' => $aCustom
         )) . ");");
 
@@ -139,7 +156,7 @@ class BxBaseServices extends BxDol implements iBxDolProfileService
             'placeholder' => $sPlaceholder,
             'user_thumb' => BxDolProfile::getInstance()->getUnit(0, array('template' => 'unit_wo_info')),
             'menu' => $oMenu->getCode(),
-            'form' => BxDolService::call($sDefault, 'get_create_post_form', array(array('context_id' => $iContextId, 'ajax_mode' => true, 'absolute_action_url' => true, 'custom' => $aCustom))),
+            'form' => BxDolService::call($sDefault, 'get_create_post_form', array(array('context_id' => $mixedContextId, 'ajax_mode' => true, 'absolute_action_url' => true, 'custom' => $aCustom))),
             'js_object' => $sJsObject,
             'js_content' => $sJsContent
     	)));