AntonLV il y a 6 ans
Parent
commit
d54494c0f4

+ 38 - 19
inc/classes/BxDolPrivacy.php

@@ -163,7 +163,7 @@ class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
             $sTitle = _t(!empty($sTitle) ? $sTitle : '_' . $sName);
         }
 
-        $bDynamicMode = isset($aParams['dynamic_mode']) ? (bool)$aParams['dynamic_mode'] : false;
+        $bDynamicMode = (isset($aParams['dynamic_mode']) && (bool)$aParams['dynamic_mode'] === true) || bx_is_dynamic_request();
         return array(
             'type' => 'select',
             'name' => $sName,
@@ -181,10 +181,31 @@ class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
             'db' => array(
                 'pass' => 'Int'
             ),
-            'content' => $oPrivacy->getJsScript($bDynamicMode)
+            'content' => $oPrivacy->addCssJs($bDynamicMode)
         );
     }
 
+    public static function initGroupChooser($sObject, $iOwnerId = 0, $aParams = array())
+    {
+        $sResult = '';
+
+        $oPrivacy = BxDolPrivacy::getObjectInstance($sObject);
+        if(empty($oPrivacy))
+            return $sResult;
+
+        $iOwnerId = !empty($iOwnerId) ? (int)$iOwnerId : bx_get_logged_profile_id();
+        $iContentId = !empty($aParams['content_id']) ? (int)$aParams['content_id'] : 0;
+        $iGroupId = !empty($aParams['group_id']) ? (int)$aParams['group_id'] : 0;
+        $bDynamicMode = (isset($aParams['dynamic_mode']) && (bool)$aParams['dynamic_mode'] === true) || bx_is_dynamic_request();
+
+        $sJsCodeAdd = '';
+        if($oPrivacy->isGroupsCustom())
+            $sJsCodeAdd = $oPrivacy->getLoadGroupCustom($iOwnerId, $iContentId, $iGroupId, isset($aParams['html_ids']) ? $aParams['html_ids'] : array());
+
+        return $oPrivacy->getJsScript($sJsCodeAdd, $bDynamicMode);
+    }
+    
+            
     public function actionLoadGroupCustom()
     {
         $iProfileId = (int)bx_get('profile_id');
@@ -253,16 +274,6 @@ class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
         echoJson($aResult);
     }
 
-    public function loadGroupCustom($iProfileId, $iContentId, $iGroupId, $aHtmlIds)
-    {
-        return $this->_oTemplate->_wrapInTagJsCode($this->getJsObjectName() . ".loadGroupCustom(" . json_encode(array(
-            'iProfileId' => $iProfileId,
-            'iContentId' => $iContentId,
-            'iGroupId' => $iGroupId,
-            'aHtmlIds' => $aHtmlIds
-        )) . ");");
-    }
-
     public function getGroupSettings($iGroup)
     {
         if(empty($this->_aGroupsSettings[$iGroup]) || !is_array($this->_aGroupsSettings[$iGroup]))
@@ -271,6 +282,13 @@ class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
         return $this->_aGroupsSettings[$iGroup];
     }
 
+    public function isGroupsCustom()
+    {
+        $aGroups = $this->_oDb->getGroupsBy(array('type' => 'active_list'));
+
+        return in_array(BX_DOL_PG_FRIENDS_SELECTED, $aGroups) || in_array(BX_DOL_PG_RELATIONS_SELECTED, $aGroups);                
+    }
+
     public function getGroupCustom($aParams)
     {
         return $this->_oDb->getGroupCustom($aParams);
@@ -305,10 +323,11 @@ class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
             'object' => $this->_sObject
         ));
 
-        if(!empty($aGroupCustom) && is_array($aGroupCustom) && $aGroupCustom['group_id'] != $iGroupId)
+        if(!empty($aGroupCustom) && is_array($aGroupCustom) && $aGroupCustom['group_id'] != $iGroupId) {
             $this->deleteGroupCustom(array('id' => $aGroupCustom['id']));
 
-        return $this->associateGroupCustomWithContent($iProfileId, $iContentId, $iGroupId);
+            $this->associateGroupCustomWithContent($iProfileId, $iContentId, $iGroupId);
+        }
     }
 
     public function deleteGroupCustomByContentId($iContentId)
@@ -338,11 +357,11 @@ class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
 
     public function addAclGroups($aValues, $iOwnerId, $aParams)
     {
-		$aCheck = checkActionModule($iOwnerId, 'show membership levels in privacy groups', 'system', false);
-		if($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
-			return $aValues;
-        
-		$aLevels = BxDolAcl::getInstance()->getMemberships(false, true, true, true);
+        $aCheck = checkActionModule($iOwnerId, 'show membership levels in privacy groups', 'system', false);
+        if($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
+            return $aValues;
+
+        $aLevels = BxDolAcl::getInstance()->getMemberships(false, true, true, true);
         if(empty($aLevels) || !is_array($aLevels))
             return $aValues;
 

+ 15 - 5
inc/classes/BxDolPrivacyQuery.php

@@ -20,7 +20,8 @@ class BxDolPrivacyQuery extends BxDolDb
 
     protected $_sCacheGroup;
     protected $_sCacheGroupFriends;
-    protected $_sCacheGroupsActive;
+    protected $_sCacheGroupsActVis;
+    protected $_sCacheGroupsActVisList;
 
     protected $_sCacheTestedObject;
 
@@ -35,6 +36,7 @@ class BxDolPrivacyQuery extends BxDolDb
         $this->_sCacheGroup = 'sys_privacy_group_';
         $this->_sCacheGroupFriends = 'sys_privacy_group_friends_';
         $this->_sCacheGroupsActVis = 'sys_privacy_group_act_vis';
+        $this->_sCacheGroupsActVisList = 'sys_privacy_group_act_vis_list';
 
         $this->_sCacheTestedObject = 'sys_privacy_tested_object_';
     }
@@ -77,6 +79,9 @@ class BxDolPrivacyQuery extends BxDolDb
 
     function getGroupsBy($aParams)
     {
+        $sSelectClause = "`id`, `title`, `check`, `active`";
+        $sWhereClause = "";
+
         switch($aParams['type']) {
             case 'id':
                 $sCacheFunction = 'fromCache';
@@ -91,13 +96,18 @@ class BxDolPrivacyQuery extends BxDolDb
                 $sMethod = 'getAll';
                 $sWhereClause = "`active`='1' AND `visible`='1'";
                 break;
+
+            case 'active_list':
+                $sCacheFunction = 'fromMemory';
+                $sCacheName = $this->_sCacheGroupsActVisList;
+                $sMethod = 'getColumn';
+                $sSelectClause = "`id`";
+                $sWhereClause = "`active`='1' AND `visible`='1'";
+                break;
         }
 
         $sSql = "SELECT
-                   `id`,
-                   `title`,
-                   `check`,
-                   `active`
+                    " . $sSelectClause . "
                 FROM `sys_privacy_groups`
                 WHERE " . $sWhereClause;
 

+ 11 - 7
modules/base/general/classes/BxBaseModGeneralFormEntry.php

@@ -484,7 +484,8 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
         if(!isset($CNF[$sField]) || !isset($this->aInputs[$CNF[$sField]]) || !isset($CNF[$sObject]))
             return;
 
-        $oPrivacy = BxDolPrivacy::getObjectInstance($CNF[$sObject]);
+        $sPrivacy = $CNF[$sObject];
+        $oPrivacy = BxDolPrivacy::getObjectInstance($sPrivacy);
         if(!$oPrivacy) 
             return;
 
@@ -494,9 +495,7 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
                 $aSave[0][$k] = $a;
         }, array(&$aSave));
 
-        $aGroupChooser = $oPrivacy->getGroupChooser($CNF[$sObject], 0, array(
-            'dynamic_mode' => $this->_bDynamicMode
-        ));
+        $aGroupChooser = $oPrivacy->getGroupChooser($sPrivacy);
 
         $this->aInputs[$CNF[$sField]] = array_merge($this->aInputs[$CNF[$sField]], $aGroupChooser, $aSave);
     }
@@ -508,7 +507,8 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
         if(!isset($CNF[$sField]) || !isset($this->aInputs[$CNF[$sField]]) || !isset($CNF[$sObject]))
             return;
 
-        $oPrivacy = BxDolPrivacy::getObjectInstance($CNF[$sObject]);
+        $sPrivacy = $CNF[$sObject];
+        $oPrivacy = BxDolPrivacy::getObjectInstance($sPrivacy);
         if(!$oPrivacy) 
             return;
 
@@ -520,8 +520,12 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
         if(!isset($this->aInputs[$sKey]['content']))
             $this->aInputs[$sKey]['content'] = '';
 
-        $this->aInputs[$sKey]['content'] .= $oPrivacy->loadGroupCustom($iProfileId, $iContentId, $iGroupId, array(
-            'form' => $this->getId()
+        $this->aInputs[$sKey]['content'] .= $oPrivacy->initGroupChooser($sPrivacy, $iProfileId, array(
+            'content_id' => $iContentId,
+            'group_id' => $iGroupId,
+            'html_ids' => array(
+                'form' => $this->getId()
+            )
         ));
     }
 }

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

@@ -307,7 +307,8 @@ class BxTimelineFormPost extends BxBaseModGeneralFormEntry
         if(!isset($CNF[$sFieldKey]) || !isset($this->aInputs[$CNF[$sFieldKey]]) || !isset($CNF[$sObject]))
             return;
 
-        $oPrivacy = BxDolPrivacy::getObjectInstance($CNF[$sObject]);
+        $sPrivacy = $CNF[$sObject];
+        $oPrivacy = BxDolPrivacy::getObjectInstance($sPrivacy);
         if(!$oPrivacy) 
             return;
 
@@ -320,8 +321,12 @@ class BxTimelineFormPost extends BxBaseModGeneralFormEntry
         if(!isset($this->aInputs[$sField]['content']))
             $this->aInputs[$sField]['content'] = '';
 
-        $this->aInputs[$sField]['content'] .= $oPrivacy->loadGroupCustom($iProfileId, $iContentId, $iGroupId, array(
-            'form' => $this->getId()
+        $this->aInputs[$sField]['content'] .= $oPrivacy->initGroupChooser($sPrivacy, $iProfileId, array(
+            'content_id' => $iContentId,
+            'group_id' => $iGroupId,
+            'html_ids' => array(
+                'form' => $this->getId()
+            )
         ));
     }
 }

+ 40 - 10
template/scripts/BxBasePrivacy.php

@@ -48,29 +48,49 @@ class BxBasePrivacy extends BxDolPrivacy
      *
      * @return string
      */
-    public function getJsScript($bDynamicMode = false)
+    public function getJsScript($sCodeAdd = '', $bDynamicMode = false)
     {
-        $aParams = array(
+        $sCode = $this->_sJsObjName . " = new " . $this->_sJsObjClass . "(" . json_encode(array(
             'sObject' => $this->_sObject,
             'sObjName' => $this->_sJsObjName,
             'sRootUrl' => BX_DOL_URL_ROOT,
             'aGroupSettings' => $this->_aGroupsSettings,
             'aHtmlIds' => $this->_aHtmlIds
-        );
+        )) . ");" . $sCodeAdd;
+
+        if($bDynamicMode) {
+            $sCode = "var " . $this->_sJsObjName . " = null;
+            if(typeof(jQuery.ui.core) == 'undefined')
+                $.getScript('" . bx_js_string($this->_oTemplate->getJsUrl('jquery-ui/jquery.ui.core.min.js'), BX_ESCAPE_STR_APOS) . "');
+            if(typeof(jQuery.ui.widget) == 'undefined')
+                $.getScript('" . bx_js_string($this->_oTemplate->getJsUrl('jquery-ui/jquery.ui.widget.min.js'), BX_ESCAPE_STR_APOS) . "');
+            if(typeof(jQuery.ui.menu) == 'undefined')
+                $.getScript('" . bx_js_string($this->_oTemplate->getJsUrl('jquery-ui/jquery.ui.menu.min.js'), BX_ESCAPE_STR_APOS) . "');
+            if(typeof(jQuery.ui.autocomplete) == 'undefined')
+                $.getScript('" . bx_js_string($this->_oTemplate->getJsUrl('jquery-ui/jquery.ui.autocomplete.min.js'), BX_ESCAPE_STR_APOS) . "');
+            if(window['" . $this->_sJsObjName . "'] === null)
+                $.getScript('" . bx_js_string($this->_oTemplate->getJsUrl('BxDolPrivacy.js'), BX_ESCAPE_STR_APOS) . "', function(data, textStatus, jqxhr) {
+                    " . $sCode . "
+                });";
+        }
+        else
+            $sCode = "if(window['" . $this->_sJsObjName . "'] == undefined) var " . $sCode;
 
-        return $this->addCssJs($bDynamicMode) . $this->_oTemplate->_wrapInTagJsCode("if(window['" . $this->_sJsObjName . "'] == undefined) var " . $this->_sJsObjName . " = new " . $this->_sJsObjClass . "(" . json_encode($aParams) . ");");
+        return $this->addCssJs($bDynamicMode) . $this->_oTemplate->_wrapInTagJsCode($sCode);
     }
 
     public function addCssJs($bDynamicMode = false)
     {
         $sInclude = '';
 
-        $sInclude .= $this->_oTemplate->addJs(array(
-            'jquery-ui/jquery-ui.custom.min.js',
-            'jquery-ui/jquery.ui.widget.min.js', 
-            'jquery-ui/jquery.ui.autocomplete.min.js', 
-            'BxDolPrivacy.js'
-        ), $bDynamicMode);
+        if(!$bDynamicMode)
+            $this->_oTemplate->addJs(array(
+                'jquery-ui/jquery.ui.core.min.js',
+                'jquery-ui/jquery.ui.widget.min.js',
+                'jquery-ui/jquery.ui.menu.min.js',
+                'jquery-ui/jquery.ui.autocomplete.min.js', 
+                'BxDolPrivacy.js'
+            ));
 
         $sInclude .= $this->_oTemplate->addCss(array(
             'forms.css', 
@@ -142,6 +162,16 @@ class BxBasePrivacy extends BxDolPrivacy
             'content' => $oForm->getElementGroupCustom()
         ));
     }
+
+    protected function getLoadGroupCustom($iProfileId, $iContentId, $iGroupId, $aHtmlIds)
+    {
+        return $this->_sJsObjName . ".loadGroupCustom(" . json_encode(array(
+            'iProfileId' => $iProfileId,
+            'iContentId' => $iContentId,
+            'iGroupId' => $iGroupId,
+            'aHtmlIds' => $aHtmlIds
+        )) . ");";
+    }
 }
 
 /** @} */