ソースを参照

Ticket #2252 - Core changes.

AntonLV 7 年 前
親
コミット
c1fa7a06d5

+ 16 - 3
inc/classes/BxDol.php

@@ -171,7 +171,7 @@ interface iBxDolProfile
     public function hasImage();
     public function getPicture();
     public function getAvatar();
-	public function getCover();
+    public function getCover();
     public function getThumb();
     public function getIcon();
     public function getIconModule();
@@ -185,7 +185,13 @@ interface iBxDolProfile
      * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
      */    
     public function checkAllowedProfileView();
-    
+
+    /**
+     * Check if profile can be contacted.
+     * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
+     */    
+    public function checkAllowedProfileContact();
+
     /**
      * Check if posting in profile is allowed
      * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
@@ -201,7 +207,7 @@ interface iBxDolProfileService
     public function serviceProfileUnit ($iContentId);
     public function serviceProfilePicture ($iContentId);
     public function serviceProfileAvatar ($iContentId);
-	public function serviceProfileCover ($iContentId); 
+    public function serviceProfileCover ($iContentId); 
     public function serviceProfileThumb ($iContentId);
     public function serviceProfileIcon ($iContentId);
     public function serviceProfileName ($iContentId);
@@ -215,6 +221,13 @@ interface iBxDolProfileService
      */     
     public function serviceCheckAllowedProfileView($iContentId);
 
+    /**
+     * Check if profile can be contacted
+     * @param $iContentId content ID
+     * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
+     */     
+    public function serviceCheckAllowedProfileContact($iContentId);
+    
     /**
      * Check if posting in profile is allowed, for example posting in profile's timeline
      * @param $iContentId content ID

+ 10 - 0
inc/classes/BxDolProfile.php

@@ -352,6 +352,16 @@ class BxDolProfile extends BxDolFactory implements iBxDolProfile
         return BxDolService::call($aInfo['type'], 'check_allowed_profile_view', array($aInfo['content_id']));
     }
 
+    /**
+     * @see iBxDolProfile::checkAllowedProfileContact
+     */
+    public function checkAllowedProfileContact($iProfileId = 0)
+    {
+        $aInfo = $this->getInfo($iProfileId);
+        return BxDolService::call($aInfo['type'], 'check_allowed_profile_contact', array($aInfo['content_id']));
+    }
+    
+    
     /**
      * @see iBxDolProfile::checkAllowedPostInProfile
      */

+ 8 - 0
inc/classes/BxDolProfileUndefined.php

@@ -189,6 +189,14 @@ class BxDolProfileUndefined extends BxDolFactory implements iBxDolSingleton, iBx
         return CHECK_ACTION_RESULT_ALLOWED;
     }
 
+    /**
+     * @see iBxDolProfile::checkAllowedProfileContact
+     */
+    public function checkAllowedProfileContact($iProfileId = 0)
+    {
+        return _t('_sys_txt_access_denied');
+    }
+
     /**
      * @see iBxDolProfile::checkAllowedPostInProfile
      */

+ 22 - 0
inc/utils.inc.php

@@ -1074,6 +1074,28 @@ function bx_get ($sName, $sMethod = false)
         return false;
 }
 
+function bx_set ($sName, $sValue, $sMethod = false)
+{
+    if(!$sMethod)
+        $sMethod = 'get';
+
+    $bResult = true;
+    switch($sMethod) {
+        case 'get':
+            $_GET[$sName] = $sValue;
+            break;
+        
+        case 'post':
+            $_POST[$sName] = $sValue;
+            break;
+
+        default:
+            $bResult = false;
+    }
+
+    return $bResult;
+}
+
 function bx_get_with_prefix ($sPrefix, $sMethod = false)
 {
     $aSources = array('get' => &$_GET, 'post' => &$_POST);

+ 49 - 25
modules/base/general/classes/BxBaseModGeneralFormEntry.php

@@ -69,18 +69,7 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
             $this->aInputs[$CNF['FIELD_PHOTO']]['ghost_template'] = '';
         }
 
-        if (isset($CNF['FIELD_ALLOW_VIEW_TO']) && isset($this->aInputs[$CNF['FIELD_ALLOW_VIEW_TO']]) && $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW'])) {
-
-            $aSave = array('db' => array('pass' => 'Xss'));
-            array_walk($this->aInputs[$CNF['FIELD_ALLOW_VIEW_TO']], function ($a, $k, $aSave) {
-                if (in_array($k, array('info', 'caption', 'value')))
-                    $aSave[0][$k] = $a;
-            }, array(&$aSave));
-            
-            $aGroupChooser = $oPrivacy->getGroupChooser($CNF['OBJECT_PRIVACY_VIEW']);
-            
-            $this->aInputs[$CNF['FIELD_ALLOW_VIEW_TO']] = array_merge($this->aInputs[$CNF['FIELD_ALLOW_VIEW_TO']], $aGroupChooser, $aSave);
-        }        
+        $this->_preparePrivacyField('VIEW');       
     }
 
     /**
@@ -149,19 +138,7 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
             $this->aInputs[$CNF['FIELD_ANONYMOUS']]['checked'] = $aValues[$CNF['FIELD_AUTHOR']] < 0;
         }
 
-        if (isset($CNF['FIELD_ALLOW_VIEW_TO']) && isset($this->aInputs[$CNF['FIELD_ALLOW_VIEW_TO']]) && $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW'])) {
-            $iContentId = !empty($aValues[$CNF['FIELD_ID']]) ? (int)$aValues[$CNF['FIELD_ID']] : 0;
-            $iProfileId = !empty($iContentId) ? (int)$this->getContentOwnerProfileId($iContentId) : bx_get_logged_profile_id();
-            $iGroupId = !empty($aValues[$CNF['FIELD_ALLOW_VIEW_TO']]) ? $aValues[$CNF['FIELD_ALLOW_VIEW_TO']] : 0;
-
-            $sKey = $CNF['FIELD_ALLOW_VIEW_TO'];
-            if(!isset($this->aInputs[$sKey]['content']))
-                $this->aInputs[$sKey]['content'] = '';
-
-            $this->aInputs[$sKey]['content'] .= $oPrivacy->loadGroupCustom($iProfileId, $iContentId, $iGroupId, array(
-                'form' => $this->getId()
-            ));
-        }
+        $this->_preloadPrivacyField('VIEW', $aValues);
 
         parent::initChecker ($aValues, $aSpecificValues);
     }
@@ -458,6 +435,53 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
                 $aValsToAdd[$CNF[$sKey1]] = serialize(BxDolMetatags::locationsParseComponents($aLocation));
         }
     }
+
+    protected function _preparePrivacyField($Type)
+    {
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        if(!isset($CNF['FIELD_ALLOW_' . $Type . '_TO']) || !isset($this->aInputs[$CNF['FIELD_ALLOW_' . $Type . '_TO']]) || !isset($CNF['OBJECT_PRIVACY_' . $Type]))
+            return;
+
+        $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_' . $Type]);
+        if(!$oPrivacy) 
+            return;
+
+
+        $aSave = array('db' => array('pass' => 'Xss'));
+        array_walk($this->aInputs[$CNF['FIELD_ALLOW_' . $Type . '_TO']], function ($a, $k, $aSave) {
+            if (in_array($k, array('info', 'caption', 'value')))
+                $aSave[0][$k] = $a;
+        }, array(&$aSave));
+
+        $aGroupChooser = $oPrivacy->getGroupChooser($CNF['OBJECT_PRIVACY_' . $Type]);
+
+        $this->aInputs[$CNF['FIELD_ALLOW_' . $Type . '_TO']] = array_merge($this->aInputs[$CNF['FIELD_ALLOW_' . $Type . '_TO']], $aGroupChooser, $aSave);
+    }
+
+    protected function _preloadPrivacyField($Type, $aValues)
+    {
+        $CNF = &$this->_oModule->_oConfig->CNF;
+
+        if(!isset($CNF['FIELD_ALLOW_' . $Type . '_TO']) || !isset($this->aInputs[$CNF['FIELD_ALLOW_' . $Type . '_TO']]) || !isset($CNF['OBJECT_PRIVACY_' . $Type]))
+            return;
+
+        $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_' . $Type]);
+        if(!$oPrivacy) 
+            return;
+
+        $iContentId = !empty($aValues[$CNF['FIELD_ID']]) ? (int)$aValues[$CNF['FIELD_ID']] : 0;
+        $iProfileId = !empty($iContentId) ? (int)$this->getContentOwnerProfileId($iContentId) : bx_get_logged_profile_id();
+        $iGroupId = !empty($aValues[$CNF['FIELD_ALLOW_' . $Type . '_TO']]) ? $aValues[$CNF['FIELD_ALLOW_' . $Type . '_TO']] : 0;
+
+        $sKey = $CNF['FIELD_ALLOW_' . $Type . '_TO'];
+        if(!isset($this->aInputs[$sKey]['content']))
+            $this->aInputs[$sKey]['content'] = '';
+
+        $this->aInputs[$sKey]['content'] .= $oPrivacy->loadGroupCustom($iProfileId, $iContentId, $iGroupId, array(
+            'form' => $this->getId()
+        ));
+    }
 }
 
 /** @} */

+ 4 - 25
modules/base/profile/classes/BxBaseModProfileFormEntry.php

@@ -23,18 +23,8 @@ class BxBaseModProfileFormEntry extends BxBaseModGeneralFormEntry
 
         $CNF = &$this->_oModule->_oConfig->CNF;
 
-        if (isset($CNF['FIELD_ALLOW_POST_TO']) && isset($this->aInputs[$CNF['FIELD_ALLOW_POST_TO']]) && isset($CNF['OBJECT_PRIVACY_POST']) && ($oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_POST'])) !== false) {
-
-            $aSave = array('db' => array('pass' => 'Xss'));
-            array_walk($this->aInputs[$CNF['FIELD_ALLOW_POST_TO']], function ($a, $k, $aSave) {
-                if (in_array($k, array('info', 'caption', 'value')))
-                    $aSave[0][$k] = $a;
-            }, array(&$aSave));
-
-            $aGroupChooser = $oPrivacy->getGroupChooser($CNF['OBJECT_PRIVACY_POST']);
-
-            $this->aInputs[$CNF['FIELD_ALLOW_POST_TO']] = array_merge($this->aInputs[$CNF['FIELD_ALLOW_POST_TO']], $aGroupChooser, $aSave);
-        }
+        $this->_preparePrivacyField('POST');
+        $this->_preparePrivacyField('CONTACT');
 
         if (!empty($CNF['FIELD_PICTURE']) && isset($this->aInputs[$CNF['FIELD_PICTURE']])) {
             $this->_aImageFields[$CNF['FIELD_PICTURE']] = array (
@@ -81,19 +71,8 @@ class BxBaseModProfileFormEntry extends BxBaseModGeneralFormEntry
             $this->aInputs[$sField]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName('form_ghost_template.html', $this->_getProfilePhotoGhostTmplVars($sField, $aContentInfo));
         }
 
-        if (isset($CNF['FIELD_ALLOW_POST_TO']) && isset($this->aInputs[$CNF['FIELD_ALLOW_POST_TO']]) && $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_POST'])) {
-            $iContentId = !empty($aValues[$CNF['FIELD_ID']]) ? (int)$aValues[$CNF['FIELD_ID']] : 0;
-            $iProfileId = !empty($iContentId) ? (int)$this->getContentOwnerProfileId($iContentId) : bx_get_logged_profile_id();
-            $iGroupId = !empty($aValues[$CNF['FIELD_ALLOW_POST_TO']]) ? $aValues[$CNF['FIELD_ALLOW_POST_TO']] : 0;
-
-            $sKey = $CNF['FIELD_ALLOW_POST_TO'];
-            if(!isset($this->aInputs[$sKey]['content']))
-                $this->aInputs[$sKey]['content'] = '';
-
-            $this->aInputs[$sKey]['content'] .= $oPrivacy->loadGroupCustom($iProfileId, $iContentId, $iGroupId, array(
-                'form' => $this->getId()
-            ));
-        }
+        $this->_preloadPrivacyField('POST', $aValues);
+        $this->_preloadPrivacyField('CONTACT', $aValues);
 
         parent::initChecker($aValues, $aSpecificValues);
     }

+ 61 - 0
modules/base/profile/classes/BxBaseModProfileModule.php

@@ -994,6 +994,14 @@ class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolCon
         return $this->serviceCheckAllowedWithContent('View', $iContentId);
     }
 
+    /**
+     * @see iBxDolProfileService::serviceCheckAllowedProfileContact
+     */ 
+    public function serviceCheckAllowedProfileContact($iContentId)
+    {        
+        return $this->serviceCheckAllowedWithContent('Contact', $iContentId);
+    }
+
     /**
      * @see iBxDolProfileService::serviceCheckAllowedPostInProfile
      */
@@ -1080,6 +1088,51 @@ class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolCon
         return CHECK_ACTION_RESULT_ALLOWED;
     }
 
+    /**
+     * Check if profile can be contacted.
+     * 
+     * NOTE. This service should be used if it's needed to pass some specific values in 
+     * $isPerformAction and $iProfileId parameters, otherwise it's recommended to use 
+     * BxBaseModProfileModule::serviceCheckAllowedProfileContact service method or 
+     * BxDolProfile::checkAllowedProfileContact method.
+     * 
+     * @param type $aDataEntry - entry which the action will be performed for
+     * @param type $isPerformAction - perform or just check the action
+     * @param type $iProfileId - performer's profile ID
+     * @return integer - one of CHECK_ACTION_RESULT_XXX constants.
+     */
+    public function serviceCheckAllowedContactForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        if(!$iProfileId)
+            $iProfileId = $this->_iProfileId;
+
+        // check is view allowed
+        if(($mixedResult = $this->serviceCheckAllowedViewForProfile($aDataEntry, $isPerformAction, $iProfileId)) !== CHECK_ACTION_RESULT_ALLOWED)
+            return $mixedResult;
+
+        // moderator and owner always have access
+        $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->getName());
+        if(($oProfile && $oProfile->id() == $iProfileId) || $this->_isModerator($isPerformAction))
+            return CHECK_ACTION_RESULT_ALLOWED;
+
+        // check privacy
+        if(!empty($CNF['OBJECT_PRIVACY_CONTACT'])) {
+            $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_CONTACT']);
+            if($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
+                return _t('_sys_access_denied_to_private_content');
+        }
+
+        // call alert to allow custom checks
+        $mixedResult = null;
+        bx_alert('system', 'check_allowed_contact', 0, 0, array('module' => $this->getName(), 'content_info' => $aDataEntry, 'profile_id' => $iProfileId, 'override_result' => &$mixedResult));
+        if($mixedResult !== null)
+            return $mixedResult;
+
+        return CHECK_ACTION_RESULT_ALLOWED;
+    }
+
     public function serviceSetViewProfileCover($oPage, $aProfileInfo)
     {
         $this->_oTemplate->setCover($oPage,$aProfileInfo);
@@ -1138,6 +1191,14 @@ class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolCon
         return $this->serviceCheckAllowedPostForProfile ($aDataEntry, $isPerformAction);
     }
 
+    /**
+     * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
+     */
+    public function checkAllowedContact ($aDataEntry, $isPerformAction = false)
+    {
+        return $this->serviceCheckAllowedContactForProfile ($aDataEntry, $isPerformAction);
+    }
+
     /**
      * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
      */

+ 3 - 2
template/scripts/BxBasePrivacy.php

@@ -96,11 +96,12 @@ class BxBasePrivacy extends BxDolPrivacy
                 $aMembers = array_merge($aMembers, $aMembersList);
 
             $aMembers = array_unique($aMembers);
-            if(empty($aMembers) || !is_array($aMembers))
-                return array();
 
             $iGroupCustomId = $oForm->getGroupCustomId();
             if(!$iGroupCustomId) {
+                if(empty($aMembers) || !is_array($aMembers))
+                    return array();
+
                 $this->deleteGroupCustom(array(
                     'profile_id' => $oForm->getCleanValue('profile_id'),
                     'content_id' => $oForm->getCleanValue('content_id'),

+ 8 - 0
template/scripts/BxBaseServices.php

@@ -75,6 +75,14 @@ class BxBaseServices extends BxDol implements iBxDolProfileService
         return _t('_Access denied');
     }
 
+    /**
+     * @see iBxDolProfileService::serviceCheckAllowedProfileContact
+     */ 
+    public function serviceCheckAllowedProfileContact($iContentId)
+    {
+        return _t('_Access denied');
+    }
+
     /**
      * @see iBxDolProfileService::serviceCheckAllowedPostInProfile
      */