Explorar el Código

Merge branch 'master' of https://github.com/unaio/una

AntonLV hace 8 años
padre
commit
fadb2ec5e9

+ 20 - 1
inc/classes/BxDol.php

@@ -218,7 +218,26 @@ interface iBxDolProfileService
      * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
      */    
     public function serviceCheckAllowedPostInProfile($iContentId);
-    
+
+    /**
+     * Get profiles, current profile have relation with, like friends, joined groups and events
+     * @return array
+     */
+    public function serviceGetParticipatingProfiles($iProfileId);
+
+    /**
+     * Get space title
+     * @return string
+     */ 
+    public function serviceGetSpaceTitle();
+
+    /**
+     * Check space privacy, when some profile is used for privacy checking of some content
+     * @param $iContentId content ID
+     * @return message on error, or CHECK_ACTION_RESULT_ALLOWED when allowed
+     */ 
+    public function serviceCheckSpacePrivacy($iContentId);
+        
     public function serviceProfilesSearch ($sTerm, $iLimit);
     public function serviceFormsHelper ();
     public function serviceActAsProfile ();

+ 73 - 2
inc/classes/BxDolPrivacy.php

@@ -21,6 +21,10 @@ define('BX_DOL_PG_DEFAULT', BX_DOL_PG_ALL);
  * Integration of the content with privacy engine allows site member
  * to organize the access to his content.
  *
+ * In addition to regular privacy groups (Public, Friends), spaces are supported. 
+ * When some space (usually some another profile) is specified as privacy, 
+ * then another profile visibility is used to check the privacy.
+ *
  * Related classes:
  *  BxDolPrivacyQuery - database queries.
  *
@@ -125,8 +129,9 @@ class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
 
         $aValues = $oPrivacy->getGroups();
 
-        if(isset($aParams['dynamic_groups']) && is_array($aParams['dynamic_groups']))
-            $aValues = array_merge($aValues, $aParams['dynamic_groups']);
+        $aValues = $oPrivacy->addDynamicGroups($aValues, $iOwnerId, $aParams);
+        
+        $aValues = $oPrivacy->addSpaces($aValues, $iOwnerId, $aParams);
 
         $sName = $oPrivacy->convertActionToField($sAction);
 
@@ -152,6 +157,60 @@ class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
         );
     }
 
+    public function addDynamicGroups($aValues, $iOwnerId, $aParams)
+    {
+        if (isset($aParams['dynamic_groups']) && is_array($aParams['dynamic_groups']))
+            $aValues = array_merge($aValues, $aParams['dynamic_groups']);
+
+        return $aValues;
+    }
+
+    public function addSpaces($aValues, $iOwnerId, $aParams)
+    {
+        if (!$this->_aObject['spaces'])
+            return $aValues;
+
+        if (!($oProfile = BxDolProfile::getInstance($iOwnerId)))
+            return $aValues;
+
+        if (!($aModules = BxDolModuleQuery::getInstance()->getModules()))
+            return $aValues;
+
+        $bProfileProcessed = false;
+        foreach ($aModules as $aModule) {
+            if (!$aModule['enabled'])
+                continue;
+
+            if ('all' != $this->_aObject['spaces'] && false === stripos($this->_aObject['spaces'], $aModule['name']))
+                continue;
+
+            if (!BxDolRequest::serviceExists($aModule['name'], 'act_as_profile'))
+                continue;
+
+            $bActAsProfile = BxDolService::call($aModule['name'], 'act_as_profile');
+            if ($bActAsProfile && $bProfileProcessed)
+                continue;
+            if ($bActAsProfile)
+                $bProfileProcessed = true;
+
+            $a = BxDolService::call($aModule['name'], 'get_participating_profiles', array($oProfile->id()));
+            $aSpaces = array();
+            foreach ($a as $iProfileId) {
+                if (!($o = BxDolProfile::getInstance($iProfileId)))
+                    continue;
+                $sTitle = BxDolService::call($aModule['name'], 'get_space_title');
+                $aSpaces[-$iProfileId] = array('key' => -$iProfileId, 'value' => _t('_sys_ps_space_title_mask', $o->getDisplayName(), $sTitle));
+            }
+
+            if ($aSpaces) {
+                $aItem = array(array('key' => '', 'value' => '----'));
+                $aValues = array_merge($aValues, $aItem, array_values($aSpaces));
+            }
+        }
+        
+        return $aValues;
+    }
+    
     /**
      * Get database field name for action.
      *
@@ -251,6 +310,9 @@ class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
         if(isAdmin() || $iViewerId == $aObject['owner_id'])
             return true;
 
+        if ($aObject['group_id'] < 0)
+            return $this->checkSpace($aObject, $iViewerId);
+
         $aGroup = $this->_oDb->getGroupsBy(array('type' => 'id', 'id' => $aObject['group_id']));
         if(!empty($aGroup) && is_array($aGroup) && (int)$aGroup['active'] == 1 && !empty($aGroup['check'])) {
             $sCheckMethod = $this->getCheckMethod($aGroup['check']);
@@ -261,6 +323,15 @@ class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
         return $this->isDynamicGroupMember($aObject['group_id'], $aObject['owner_id'], $iViewerId, $iObjectId);
     }
 
+    public function checkSpace($aObject, $iViewerId)
+    {
+        $oProfile = BxDolProfile::getInstance(-$aObject['group_id']);
+        if (!$oProfile)
+            return false;
+
+        return CHECK_ACTION_RESULT_ALLOWED === BxDolService::call($oProfile->getModule(), 'check_space_privacy', array($oProfile->getContentId()));
+    }
+
     public function checkMeOnly($iOwnerId, $iViewerId)
     {
         return false;

+ 1 - 1
inc/classes/BxDolPrivacyQuery.php

@@ -69,7 +69,7 @@ class BxDolPrivacyQuery extends BxDolDb
         if(empty($this->_sTable) || empty($this->_sFieldId) || empty($this->_sFieldOwnerId))
             return array();
 
-        $sQuery = $this->prepare("SELECT `" . $this->_sFieldOwnerId . "` AS `owner_id`, `" . $sAction . "` AS `group_id` FROM `" . $this->_sTable . "` WHERE `" . $this->_sFieldId . "`=? LIMIT 1", $iObjectId);
+        $sQuery = $this->prepare("SELECT `" . $this->_sFieldId . "` AS `id`, `" . $this->_sFieldOwnerId . "` AS `owner_id`, `" . $sAction . "` AS `group_id` FROM `" . $this->_sTable . "` WHERE `" . $this->_sFieldId . "`=? LIMIT 1", $iObjectId);
 
         $sCacheKey = $this->_sCacheTestedObject . $this->_sTable . '_' . $this->_aObject['action'] . '_' . $iObjectId;
         return $this->fromMemory($sCacheKey, 'getRow', $sQuery);

+ 1 - 0
install/sql/system.sql

@@ -1521,6 +1521,7 @@ CREATE TABLE `sys_objects_privacy` (
   `action` varchar(255) NOT NULL default '',
   `title` varchar(255) NOT NULL default '',
   `default_group` varchar(255) NOT NULL default '1',
+  `spaces` varchar(255) NOT NULL DEFAULT 'all',
   `table` varchar(255) NOT NULL default '',
   `table_field_id` varchar(255) NOT NULL default '',
   `table_field_author` varchar(255) NOT NULL default '',

+ 17 - 0
modules/base/groups/classes/BxBaseModGroupsModule.php

@@ -40,6 +40,23 @@ class BxBaseModGroupsModule extends BxBaseModProfileModule
         return parent::serviceGetSearchResultUnit($iContentId, $sUnitTemplate);
     }
 
+    /**
+     * @see BxBaseModProfileModule::serviceGetSpaceTitle
+     */ 
+    public function serviceGetSpaceTitle()
+    {
+        return _t($this->_oConfig->CNF['T']['txt_sample_single']);
+    }
+    
+    /**
+     * @see iBxDolProfileService::serviceGetParticipatingProfiles
+     */ 
+    public function serviceGetParticipatingProfiles($iProfileId, $sConnectionObject = '')
+    {
+        $sConnectionObject = $this->_oConfig->CNF['OBJECT_CONNECTIONS'];
+        return parent::serviceGetParticipatingProfiles($iProfileId, $sConnectionObject);
+    }
+    
     /**
      * Check if this module entry can be used as profile
      */

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

@@ -288,6 +288,33 @@ class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolCon
         $CNF = $this->_oConfig->CNF;
         return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
     }
+
+    /**
+     * @see iBxDolProfileService::serviceGetSpaceTitle
+     */ 
+    public function serviceGetSpaceTitle()
+    {
+        return _t('_sys_ps_space_title_friend');
+    }
+
+    /**
+     * @see iBxDolProfileService::serviceGetParticipatingProfiles
+     */ 
+    public function serviceGetParticipatingProfiles($iProfileId, $sConnectionObject = 'sys_profiles_friends')
+    {
+        if (!($o = BxDolConnection::getObjectInstance($sConnectionObject)))
+            return array();
+
+        return $o->getConnectedContent($iProfileId, true);
+    }
+    
+    /**
+     * @see iBxDolProfileService::serviceCheckSpacePrivacy
+     */ 
+    public function serviceCheckSpacePrivacy($iContentId)
+    {
+        return $this->serviceCheckAllowedProfileView($iContentId);
+    }
     
     /**
      * @see iBxDolProfileService::serviceCheckAllowedProfileView

+ 3 - 1
modules/boonex/english/data/langs/system/en.xml

@@ -2428,7 +2428,9 @@ If it is not enabled then please consider implement this optimization, since it
 	<string name="_sys_ps_group_title_public"><![CDATA[Public]]></string>
 	<string name="_sys_ps_group_title_closed"><![CDATA[Closed]]></string>
 	<string name="_sys_ps_group_title_secret"><![CDATA[Secret]]></string>
-	<string name="_sys_ps_ferr_incorrect_select"><![CDATA[You need to select some value]]></string>
+    <string name="_sys_ps_ferr_incorrect_select"><![CDATA[You need to select some value]]></string>
+    <string name="_sys_ps_space_title_friend"><![CDATA[friend]]></string>
+    <string name="_sys_ps_space_title_mask"><![CDATA[{0} ({1})]]></string>
 	<string name="_sys_push_notification_request"><![CDATA[Would you like to get notifications from {0}?]]></string>  
     <string name="_sys_push_notification_request_yes"><![CDATA[Yes]]></string>  
     <string name="_sys_push_notification_request_no"><![CDATA[No, thanks]]></string>

+ 3 - 3
modules/boonex/events/install/sql/enable.sql

@@ -499,9 +499,9 @@ INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
 ('bx_events', 'timeline_repost', @iHandler);
 
 -- PRIVACY 
-INSERT INTO `sys_objects_privacy` (`object`, `module`, `action`, `title`, `default_group`, `table`, `table_field_id`, `table_field_author`, `override_class_name`, `override_class_file`) VALUES
-('bx_events_allow_view_to', 'bx_events', 'view', '_bx_events_form_profile_input_allow_view_to', '3', 'bx_events_data', 'id', 'author', 'BxEventsPrivacy', 'modules/boonex/events/classes/BxEventsPrivacy.php'),
-('bx_events_allow_view_notification_to', 'bx_events', 'view_event', '_bx_events_form_profile_input_allow_view_notification_to', '3', 'bx_notifications_events', 'id', 'object_owner_id', 'BxEventsPrivacyNotifications', 'modules/boonex/events/classes/BxEventsPrivacyNotifications.php');
+INSERT INTO `sys_objects_privacy` (`object`, `module`, `action`, `title`, `default_group`, `spaces`, `table`, `table_field_id`, `table_field_author`, `override_class_name`, `override_class_file`) VALUES
+('bx_events_allow_view_to', 'bx_events', 'view', '_bx_events_form_profile_input_allow_view_to', '3', '', 'bx_events_data', 'id', 'author', 'BxEventsPrivacy', 'modules/boonex/events/classes/BxEventsPrivacy.php'),
+('bx_events_allow_view_notification_to', 'bx_events', 'view_event', '_bx_events_form_profile_input_allow_view_notification_to', '3', '', 'bx_notifications_events', 'id', 'object_owner_id', 'BxEventsPrivacyNotifications', 'modules/boonex/events/classes/BxEventsPrivacyNotifications.php');
 
 -- EMAIL TEMPLATES
 INSERT INTO `sys_email_templates` (`Module`, `NameSystem`, `Name`, `Subject`, `Body`) VALUES

+ 3 - 3
modules/boonex/groups/install/sql/enable.sql

@@ -486,9 +486,9 @@ INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
 
 -- PRIVACY 
 
-INSERT INTO `sys_objects_privacy` (`object`, `module`, `action`, `title`, `default_group`, `table`, `table_field_id`, `table_field_author`, `override_class_name`, `override_class_file`) VALUES
-('bx_groups_allow_view_to', 'bx_groups', 'view', '_bx_groups_form_profile_input_allow_view_to', '3', 'bx_groups_data', 'id', 'author', 'BxGroupsPrivacy', 'modules/boonex/groups/classes/BxGroupsPrivacy.php'),
-('bx_groups_allow_view_notification_to', 'bx_groups', 'view_event', '_bx_groups_form_profile_input_allow_view_notification_to', '3', 'bx_notifications_events', 'id', 'object_owner_id', 'BxGroupsPrivacyNotifications', 'modules/boonex/groups/classes/BxGroupsPrivacyNotifications.php');
+INSERT INTO `sys_objects_privacy` (`object`, `module`, `action`, `title`, `default_group`, `spaces`, `table`, `table_field_id`, `table_field_author`, `override_class_name`, `override_class_file`) VALUES
+('bx_groups_allow_view_to', 'bx_groups', 'view', '_bx_groups_form_profile_input_allow_view_to', '3', '', 'bx_groups_data', 'id', 'author', 'BxGroupsPrivacy', 'modules/boonex/groups/classes/BxGroupsPrivacy.php'),
+('bx_groups_allow_view_notification_to', 'bx_groups', 'view_event', '_bx_groups_form_profile_input_allow_view_notification_to', '3', '', 'bx_notifications_events', 'id', 'object_owner_id', 'BxGroupsPrivacyNotifications', 'modules/boonex/groups/classes/BxGroupsPrivacyNotifications.php');
 
 -- EMAIL TEMPLATES
 

+ 16 - 0
modules/boonex/organizations/classes/BxOrgsModule.php

@@ -40,6 +40,22 @@ class BxOrgsModule extends BxBaseModGroupsModule
         return parent::serviceGetSearchResultUnit($iContentId, $sUnitTemplate);
     }
 
+    /**
+     * @see BxBaseModProfileModule::serviceGetSpaceTitle
+     */ 
+    public function serviceGetSpaceTitle()
+    {
+        return BxBaseModProfileModule::serviceGetSpaceTitle();
+    }
+    
+    /**
+     * @see iBxDolProfileService::serviceGetParticipatingProfiles
+     */ 
+    public function serviceGetParticipatingProfiles($iProfileId, $sConnectionObject = 'sys_profiles_friends')
+    {
+        return BxBaseModProfileModule::serviceGetParticipatingProfiles($iProfileId, $sConnectionObject);
+    }
+    
     public function servicePrepareFields ($aFieldsProfile)
     {
         return parent::_servicePrepareFields($aFieldsProfile, array('org_cat' => 35), array(

+ 3 - 3
modules/boonex/organizations/install/sql/enable.sql

@@ -562,9 +562,9 @@ INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
 
 
 -- PRIVACY 
-INSERT INTO `sys_objects_privacy` (`object`, `module`, `action`, `title`, `default_group`, `table`, `table_field_id`, `table_field_author`, `override_class_name`, `override_class_file`) VALUES
-('bx_organizations_allow_view_to', 'bx_organizations', 'view', '_bx_orgs_form_profile_input_allow_view_to', '3', 'bx_organizations_data', 'id', 'author', 'BxOrgsPrivacy', 'modules/boonex/organizations/classes/BxOrgsPrivacy.php'),
-('bx_organizations_allow_view_notification_to', 'bx_organizations', 'view_event', '_bx_orgs_form_profile_input_allow_view_notification_to', '3', 'bx_notifications_events', 'id', 'object_owner_id', 'BxOrgsPrivacyNotifications', 'modules/boonex/organizations/classes/BxOrgsPrivacyNotifications.php');
+INSERT INTO `sys_objects_privacy` (`object`, `module`, `action`, `title`, `default_group`, `spaces`, `table`, `table_field_id`, `table_field_author`, `override_class_name`, `override_class_file`) VALUES
+('bx_organizations_allow_view_to', 'bx_organizations', 'view', '_bx_orgs_form_profile_input_allow_view_to', '3', '', 'bx_organizations_data', 'id', 'author', 'BxOrgsPrivacy', 'modules/boonex/organizations/classes/BxOrgsPrivacy.php'),
+('bx_organizations_allow_view_notification_to', 'bx_organizations', 'view_event', '_bx_orgs_form_profile_input_allow_view_notification_to', '3', '', 'bx_notifications_events', 'id', 'object_owner_id', 'BxOrgsPrivacyNotifications', 'modules/boonex/organizations/classes/BxOrgsPrivacyNotifications.php');
 
 
 -- EMAIL TEMPLATES

+ 2 - 2
modules/boonex/persons/install/sql/enable.sql

@@ -474,8 +474,8 @@ INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
 ('bx_persons', 'timeline_repost', @iHandler);
 
 -- PRIVACY 
-INSERT INTO `sys_objects_privacy` (`object`, `module`, `action`, `title`, `default_group`, `table`, `table_field_id`, `table_field_author`, `override_class_name`, `override_class_file`) VALUES
-('bx_persons_allow_view_to', 'bx_persons', 'view', '_bx_persons_form_profile_input_allow_view_to', '3', 'bx_persons_data', 'id', 'author', 'BxPersonsPrivacy', 'modules/boonex/persons/classes/BxPersonsPrivacy.php');
+INSERT INTO `sys_objects_privacy` (`object`, `module`, `action`, `title`, `default_group`, `spaces`, `table`, `table_field_id`, `table_field_author`, `override_class_name`, `override_class_file`) VALUES
+('bx_persons_allow_view_to', 'bx_persons', 'view', '_bx_persons_form_profile_input_allow_view_to', '3', '', 'bx_persons_data', 'id', 'author', 'BxPersonsPrivacy', 'modules/boonex/persons/classes/BxPersonsPrivacy.php');
 
 -- EMAIL TEMPLATES
 INSERT INTO `sys_email_templates` (`Module`, `NameSystem`, `Name`, `Subject`, `Body`) VALUES

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

@@ -2428,6 +2428,8 @@
 	<string name="_sys_ps_group_title_closed"><![CDATA[Закрытая]]></string>
     <string name="_sys_ps_group_title_secret"><![CDATA[Секретная]]></string>
     <string name="_sys_ps_ferr_incorrect_select"><![CDATA[Вам нужно выбрать значение]]></string>
+    <string name="_sys_ps_space_title_friend"><![CDATA[друг]]></string>
+    <string name="_sys_ps_space_title_mask"><![CDATA[{0} ({1})]]></string>
 	<string name="_sys_push_notification_request"><![CDATA[Хотите получать уведомления с сайта {0}?]]></string>   
     <string name="_sys_push_notification_request_yes"><![CDATA[Да]]></string>   
     <string name="_sys_push_notification_request_no"><![CDATA[Нет, спасибо]]></string>

+ 24 - 0
template/scripts/BxBaseServices.php

@@ -78,6 +78,30 @@ class BxBaseServices extends BxDol implements iBxDolProfileService
         return _t('_Access denied');
     }
 
+    /**
+     * @see iBxDolProfileService::serviceGetSpaceTitle
+     */ 
+    public function serviceGetSpaceTitle()
+    {
+        return '';
+    }
+
+    /**
+     * @see iBxDolProfileService::serviceGetParticipatingProfiles
+     */ 
+    public function serviceGetParticipatingProfiles($iProfileId)
+    {
+        return array();
+    }
+
+    /**
+     * @see iBxDolProfileService::serviceCheckSpacePrivacy
+     */ 
+    public function serviceCheckSpacePrivacy($iContentId)
+    {
+        return _t('_Access denied');
+    }
+    
     public function serviceFormsHelper ()
     {
         return new BxTemplAccountForms();