BxDolPrivacy.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaCore UNA Core
  7. * @{
  8. */
  9. define('BX_DOL_PG_HIDDEN', '1');
  10. define('BX_DOL_PG_MEONLY', '2');
  11. define('BX_DOL_PG_ALL', '3');
  12. define('BX_DOL_PG_MEMBERS', '4');
  13. define('BX_DOL_PG_FRIENDS', '5');
  14. define('BX_DOL_PG_FRIENDS_SELECTED', '6');
  15. define('BX_DOL_PG_RELATIONS', '7');
  16. define('BX_DOL_PG_RELATIONS_SELECTED', '8');
  17. define('BX_DOL_PG_CUSTOM', '9');
  18. define('BX_DOL_PG_DEFAULT', BX_DOL_PG_ALL);
  19. /**
  20. * Privacy settings for any content.
  21. *
  22. * Integration of the content with privacy engine allows site member
  23. * to organize the access to his content.
  24. *
  25. * In addition to regular privacy groups (Public, Friends), spaces are supported.
  26. * When some space (usually some another profile) is specified as privacy,
  27. * then another profile visibility is used to check the privacy.
  28. *
  29. * Related classes:
  30. * BxDolPrivacyQuery - database queries.
  31. *
  32. * Example of usage:
  33. * 1. Register your privacy actions in `sys_privacy_actions` database table.
  34. * 2. Add one privacy field(with INT type) in the table with your items for each action.
  35. * For example, for action 'comment', the field name should be 'allow_comment_to'.
  36. * 3. Add group choosers for necessary actions in the form, which is used to add new items.
  37. * @code
  38. * $oPrivacy = new BxDolPrivacy();
  39. * $oPrivacy->getGroupChooser($iItemOwnerId, $sModuleUri, $sModuleAction);
  40. * @endcode
  41. *
  42. * 4. Check privacy when any user tries to view an item.
  43. * @code
  44. * $oPrivacy = new BxDolPrivacy($sTable, $sFieldId, $sFieldOwnerId);
  45. * if($oPrivacy->check($sAction, $iObjectId, $iViewerId)) {
  46. * //show necessary content
  47. * }
  48. * @endcode
  49. *
  50. * @see an example of integration in BoonEx modules, for example: Posts
  51. *
  52. *
  53. * Memberships/ACL:
  54. * Doesn't depend on user's membership.
  55. *
  56. *
  57. * Alerts:
  58. * no alerts available
  59. *
  60. */
  61. class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
  62. {
  63. protected $_oDb;
  64. protected $_sObject;
  65. protected $_aObject;
  66. protected $_aGroupsSettings;
  67. protected $_aGroupsExclude;
  68. protected $_sFormUsers;
  69. protected $_sFormDisplayUsersSelect;
  70. /**
  71. * Constructor
  72. * @param $aObject array of grid options
  73. */
  74. protected function __construct($aObject)
  75. {
  76. parent::__construct();
  77. $this->_aObject = $aObject;
  78. $this->_sObject = $aObject['object'];
  79. $this->_oDb = new BxDolPrivacyQuery();
  80. $this->_oDb->init($this->_aObject);
  81. $this->_aGroupsSettings = array(
  82. BX_DOL_PG_FRIENDS_SELECTED => array('connection' => 'sys_profiles_friends'),
  83. BX_DOL_PG_RELATIONS_SELECTED => array('connection' => 'sys_profiles_relations')
  84. );
  85. $this->_aGroupsExclude = array();
  86. $this->_sFormUsers = 'sys_privacy_group_custom';
  87. $this->_sFormDisplayUsersSelect = 'sys_privacy_group_custom_manage';
  88. }
  89. /**
  90. * Get privacy object instance by object name
  91. * @param $sObject object name
  92. * @return object instance or false on error
  93. */
  94. public static function getObjectInstance($sObject)
  95. {
  96. if(isset($GLOBALS['bxDolClasses']['BxDolPrivacy!' . $sObject]))
  97. return $GLOBALS['bxDolClasses']['BxDolPrivacy!' . $sObject];
  98. $aObject = BxDolPrivacyQuery::getPrivacyObject($sObject);
  99. if(!$aObject || !is_array($aObject))
  100. return false;
  101. $sClass = 'BxTemplPrivacy';
  102. if(!empty($aObject['override_class_name'])) {
  103. $sClass = $aObject['override_class_name'];
  104. if(!empty($aObject['override_class_file']))
  105. require_once(BX_DIRECTORY_PATH_ROOT . $aObject['override_class_file']);
  106. }
  107. $o = new $sClass($aObject);
  108. return ($GLOBALS['bxDolClasses']['BxDolPrivacy!' . $sObject] = $o);
  109. }
  110. /**
  111. * Get Select element with available groups.
  112. *
  113. * @param string $sObject privacy object name.
  114. * @param integer $iOwnerId object's owner ID.
  115. * @param array $aParams an array of custom selector's params (dynamic_groups - an array of arrays('key' => group_id, 'value' => group_title), title - the title to be used for generated field).
  116. * @return an array with Select element description.
  117. */
  118. public static function getGroupChooser($sObject, $iOwnerId = 0, $aParams = array())
  119. {
  120. $oPrivacy = BxDolPrivacy::getObjectInstance($sObject);
  121. if(empty($oPrivacy))
  122. return array();
  123. $sModule = $oPrivacy->_aObject['module'];
  124. $sAction = $oPrivacy->_aObject['action'];
  125. if($iOwnerId == 0)
  126. $iOwnerId = bx_get_logged_profile_id();
  127. $sValue = $oPrivacy->_oDb->getDefaultGroupByUser($sModule, $sAction, $iOwnerId);
  128. if(empty($sValue))
  129. $sValue = $oPrivacy->_oDb->getDefaultGroup($sModule, $sAction);
  130. $aValues = $oPrivacy->getGroups();
  131. $aValues = $oPrivacy->addDynamicGroups($aValues, $iOwnerId, $aParams);
  132. $aValues = $oPrivacy->addAclGroups($aValues, $iOwnerId, $aParams);
  133. $aValues = $oPrivacy->addSpaces($aValues, $iOwnerId, $aParams);
  134. $sName = $oPrivacy->convertActionToField($sAction);
  135. $sTitle = isset($aParams['title']) && !empty($aParams['title']) ? $aParams['title'] : '';
  136. if(empty($sTitle)) {
  137. $sTitle = $oPrivacy->_oDb->getTitle($sModule, $sAction);
  138. $sTitle = _t(!empty($sTitle) ? $sTitle : '_' . $sName);
  139. }
  140. $bDynamicMode = isset($aParams['dynamic_mode']) ? (bool)$aParams['dynamic_mode'] : false;
  141. return array(
  142. 'type' => 'select',
  143. 'name' => $sName,
  144. 'caption' => $sTitle,
  145. 'value' => $sValue,
  146. 'values' => $aValues,
  147. 'attrs' => array(
  148. 'class' => 'sys-privacy-group',
  149. 'onchange' => 'javascript: ' . $oPrivacy->getJsObjectName() . '.selectGroup(this);'
  150. ),
  151. 'checker' => array(
  152. 'func' => 'avail',
  153. 'error' => _t('_sys_ps_ferr_incorrect_select')
  154. ),
  155. 'db' => array(
  156. 'pass' => 'Int'
  157. ),
  158. 'content' => $oPrivacy->getJsScript($bDynamicMode)
  159. );
  160. }
  161. public function actionLoadGroupCustom()
  162. {
  163. $iProfileId = (int)bx_get('profile_id');
  164. $iContentId = (int)bx_get('content_id');
  165. $iGroupId = (int)bx_get('group_id');
  166. $oForm = BxDolForm::getObjectInstance($this->_sFormUsers, $this->_sFormDisplayUsersSelect);
  167. return echoJson(array('eval' => $this->getJsObjectName() . '.onSelectGroup(oData);', 'content' => $oForm->getElementGroupCustom(array(
  168. 'profile_id' => $iProfileId,
  169. 'content_id' => $iContentId,
  170. 'object' => $this->_sObject,
  171. 'group_id' => $iGroupId
  172. ))));
  173. }
  174. public function actionSelectGroup()
  175. {
  176. $aValues = array(
  177. 'profile_id' => (int)bx_get('profile_id'),
  178. 'content_id' => (int)bx_get('content_id'),
  179. 'object' => $this->_sObject,
  180. 'group_id' => (int)bx_get('group_id')
  181. );
  182. $aParams = array(
  183. 'popup_only' => (bool)bx_get('popup_only')
  184. );
  185. if(!isset($this->_aGroupsSettings[$aValues['group_id']]))
  186. return echoJson(array());
  187. if($aValues['profile_id'] != bx_get_logged_profile_id())
  188. return echoJson(array('msg' => _t('_sys_ps_ferr_incorrect_gc_owner')));
  189. if(($mixedResult = $this->isSelectGroupCustom($aValues)) !== true)
  190. return echoJson(array('msg' => $mixedResult));
  191. return echoJson($this->getSelectGroup($aValues, $aParams));
  192. }
  193. public function actionUsersList()
  194. {
  195. $iGroup = (int)bx_get('group');
  196. if(!isset($this->_aGroupsSettings[$iGroup]))
  197. return echoJson(array());
  198. $oConnection = BxDolConnection::getObjectInstance($this->_aGroupsSettings[$iGroup]['connection']);
  199. if(!$oConnection)
  200. return echoJson(array());
  201. $iProfileId = bx_get_logged_profile_id();
  202. $aConnectedIds = $oConnection->getConnectedContent($iProfileId, true);
  203. if(empty($aConnectedIds) || !is_array($aConnectedIds))
  204. return echoJson(array());
  205. $sTerm = bx_get('term');
  206. $aProfiles = BxDolService::call('system', 'profiles_search', array($sTerm), 'TemplServiceProfiles');
  207. if(empty($aProfiles))
  208. return echoJson(array());
  209. $aResult = array();
  210. foreach($aProfiles as $aProfile)
  211. if(in_array($aProfile['value'], $aConnectedIds))
  212. $aResult[] = $aProfile;
  213. echoJson($aResult);
  214. }
  215. public function loadGroupCustom($iProfileId, $iContentId, $iGroupId, $aHtmlIds)
  216. {
  217. return $this->_oTemplate->_wrapInTagJsCode($this->getJsObjectName() . ".loadGroupCustom(" . json_encode(array(
  218. 'iProfileId' => $iProfileId,
  219. 'iContentId' => $iContentId,
  220. 'iGroupId' => $iGroupId,
  221. 'aHtmlIds' => $aHtmlIds
  222. )) . ");");
  223. }
  224. public function getGroupSettings($iGroup)
  225. {
  226. if(empty($this->_aGroupsSettings[$iGroup]) || !is_array($this->_aGroupsSettings[$iGroup]))
  227. return false;
  228. return $this->_aGroupsSettings[$iGroup];
  229. }
  230. public function getGroupCustom($aParams)
  231. {
  232. return $this->_oDb->getGroupCustom($aParams);
  233. }
  234. public function updateGroupCustom($aParamsSet, $aParamsWhere)
  235. {
  236. return $this->_oDb->updateGroupCustom($aParamsSet, $aParamsWhere);
  237. }
  238. public function deleteGroupCustom($aParamsWhere)
  239. {
  240. return $this->_oDb->deleteGroupCustom($aParamsWhere);
  241. }
  242. public function associateGroupCustomWithContent($iProfileId, $iContentId, $iGroupId)
  243. {
  244. return $this->updateGroupCustom(array('content_id' => $iContentId), array(
  245. 'profile_id' => $iProfileId,
  246. 'content_id' => 0,
  247. 'object' => $this->_sObject,
  248. 'group_id' => $iGroupId
  249. ));
  250. }
  251. public function reassociateGroupCustomWithContent($iProfileId, $iContentId, $iGroupId)
  252. {
  253. $aGroupCustom = $this->getGroupCustom(array(
  254. 'type' => 'pco',
  255. 'profile_id' => $iProfileId,
  256. 'content_id' => $iContentId,
  257. 'object' => $this->_sObject
  258. ));
  259. if(!empty($aGroupCustom) && is_array($aGroupCustom) && $aGroupCustom['group_id'] != $iGroupId)
  260. $this->deleteGroupCustom(array('id' => $aGroupCustom['id']));
  261. return $this->associateGroupCustomWithContent($iProfileId, $iContentId, $iGroupId);
  262. }
  263. public function deleteGroupCustomByContentId($iContentId)
  264. {
  265. return $this->_oDb->deleteGroupCustom(array('content_id' => $iContentId, 'object' => $this->_sObject));
  266. }
  267. public function deleteGroupCustomByProfileId($iProfileId)
  268. {
  269. $aGroups = $this->_oDb->getGroupCustom(array('type' => 'profile_id', 'profile_id' => $iProfileId));
  270. if(empty($aGroups) || !is_array($aGroups))
  271. return true;
  272. foreach($aGroups as $aGroup)
  273. $this->_oDb->deleteGroupCustom(array('id' => $aGroup['id']));
  274. return true;
  275. }
  276. public function addDynamicGroups($aValues, $iOwnerId, $aParams)
  277. {
  278. if (isset($aParams['dynamic_groups']) && is_array($aParams['dynamic_groups']))
  279. $aValues = array_merge($aValues, $aParams['dynamic_groups']);
  280. return $aValues;
  281. }
  282. public function addAclGroups($aValues, $iOwnerId, $aParams)
  283. {
  284. $aCheck = checkActionModule($iOwnerId, 'show membership levels in privacy groups', 'system', false);
  285. if($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  286. return $aValues;
  287. $aLevels = BxDolAcl::getInstance()->getMemberships(false, true, true, true);
  288. if(empty($aLevels) || !is_array($aLevels))
  289. return $aValues;
  290. $aValues[] = array('type' => 'group_header', 'value' => mb_strtoupper(_t('_sys_privacy_groups_acl')));
  291. foreach($aLevels as $iId => $sTitle)
  292. $aValues[] = array('key' => 'ml' . $iId, 'value' => $sTitle);
  293. $aValues[] = array('type' => 'group_end');
  294. return $aValues;
  295. }
  296. public function addSpaces($aValues, $iOwnerId, $aParams)
  297. {
  298. if (!$this->_aObject['spaces'])
  299. return $aValues;
  300. if (!($oProfile = BxDolProfile::getInstance($iOwnerId)))
  301. return $aValues;
  302. if (!($aModules = BxDolModuleQuery::getInstance()->getModules()))
  303. return $aValues;
  304. $bProfileProcessed = true; // don't allow to post to profiles for now
  305. $aExcludeModules = explode(',', getParam('sys_hide_post_to_context_for_privacy'));
  306. foreach ($aModules as $aModule) {
  307. if (!$aModule['enabled'])
  308. continue;
  309. if ('all' != $this->_aObject['spaces'] && false === stripos($this->_aObject['spaces'], $aModule['name']))
  310. continue;
  311. if (!BxDolRequest::serviceExists($aModule['name'], 'act_as_profile'))
  312. continue;
  313. if (in_array($aModule['name'], $aExcludeModules))
  314. continue;
  315. $bActAsProfile = BxDolService::call($aModule['name'], 'act_as_profile');
  316. if ($bActAsProfile && $bProfileProcessed)
  317. continue;
  318. if ($bActAsProfile)
  319. $bProfileProcessed = true;
  320. $a = BxDolService::call($aModule['name'], 'get_participating_profiles', array($oProfile->id()));
  321. $aSpaces = array();
  322. foreach ($a as $iProfileId) {
  323. if (!($o = BxDolProfile::getInstance($iProfileId)))
  324. continue;
  325. $aSpaces[-$iProfileId] = array('key' => -$iProfileId, 'value' => $o->getDisplayName());
  326. }
  327. if ($aSpaces) {
  328. $aItemStart = array(array('type' => 'group_header', 'value' => mb_strtoupper(BxDolService::call($aModule['name'], 'get_space_title'))));
  329. $aItemEnd = array(array('type' => 'group_end'));
  330. $aValues = array_merge($aValues, $aItemStart, array_values($aSpaces), $aItemEnd);
  331. }
  332. }
  333. return $aValues;
  334. }
  335. /**
  336. * Get database field name for action.
  337. *
  338. * @param string $sObject privacy object name.
  339. * @param string $sAction action name.
  340. * @return string with field name.
  341. */
  342. public static function getFieldName($sObject, $sAction = '')
  343. {
  344. $oPrivacy = BxDolPrivacy::getObjectInstance($sObject);
  345. if(empty($oPrivacy))
  346. return '';
  347. if(empty($sAction))
  348. $sAction = $oPrivacy->_aObject['action'];
  349. return $oPrivacy->convertActionToField($sAction);
  350. }
  351. /**
  352. * Get necessary condition array to use privacy in search classes
  353. * @param $mixedGroupId group ID or array of group IDs
  354. * @return array of conditions, for now with 'restriction' part only is returned
  355. */
  356. public function getContentByGroupAsCondition($mixedGroupId)
  357. {
  358. $aResult = array(
  359. 'restriction' => array (
  360. 'privacy_' . $this->_sObject => array(
  361. 'value' => $mixedGroupId,
  362. 'field' => $this->convertActionToField($this->_aObject['action']),
  363. 'operator' => is_array($mixedGroupId) ? 'in' : '=',
  364. 'table' => $this->_aObject['table'],
  365. ),
  366. ),
  367. );
  368. bx_alert('system', 'privacy_condition', 0, false, array(
  369. 'group_id' => $mixedGroupId,
  370. 'field' => $this->convertActionToField($this->_aObject['action']),
  371. 'object' => $this->_aObject,
  372. 'privacy_object' => $this,
  373. 'result' => &$aResult
  374. )
  375. );
  376. return $aResult;
  377. }
  378. /**
  379. * Get necessary condition array to use privacy in search classes
  380. * @param $iProfileIdOwner owner profile ID
  381. * @return array of conditions, for now with 'restriction' part only is returned
  382. */
  383. public function getContentPublicAsCondition($iProfileIdOwner = 0, $aCustomGroups = array())
  384. {
  385. $mixedPrivacyGroups = $this->getPrivacyGroupsForContentPublic($iProfileIdOwner, $aCustomGroups);
  386. if($mixedPrivacyGroups === true)
  387. return array();
  388. return $this->getContentByGroupAsCondition($mixedPrivacyGroups);
  389. }
  390. /**
  391. * Get necessary parts of SQL query to use privacy in other queries
  392. * @param $mixedGroupId group ID or array of group IDs
  393. * @return array of SQL string parts, for now 'where' part only is returned
  394. */
  395. public function getContentByGroupAsSQLPart($mixedGroupId)
  396. {
  397. $sField = $this->convertActionToField($this->_aObject['action']);
  398. return $this->_oDb->getContentByGroupAsSQLPart($sField, $mixedGroupId);
  399. }
  400. /**
  401. * Get necessary parts of SQL query to use privacy in other queries
  402. * @param $iProfileIdOwner owner profile ID
  403. * @return array of SQL string parts, for now 'where' part only is returned
  404. */
  405. public function getContentPublicAsSQLPart($iProfileIdOwner = 0, $aCustomGroups = array())
  406. {
  407. $mixedPrivacyGroups = $this->getPrivacyGroupsForContentPublic($iProfileIdOwner, $aCustomGroups);
  408. if($mixedPrivacyGroups === true)
  409. return array();
  410. return $this->getContentByGroupAsSQLPart($mixedPrivacyGroups);
  411. }
  412. /**
  413. * Check whether the viewer can make requested action.
  414. *
  415. * @param integer $iObjectId object ID the action to be performed with.
  416. * @param integer $iViewerId viewer ID.
  417. * @return boolean result of operation.
  418. */
  419. public function check($iObjectId, $iViewerId = 0)
  420. {
  421. if(empty($iViewerId))
  422. $iViewerId = (int)bx_get_logged_profile_id();
  423. $aObject = $this->getObjectInfo($this->convertActionToField($this->_aObject['action']), $iObjectId);
  424. if(empty($aObject) || !is_array($aObject))
  425. return false;
  426. if($aObject['group_id'] == BX_DOL_PG_HIDDEN)
  427. return false;
  428. if(isAdmin() || $iViewerId == $aObject['owner_id'])
  429. return true;
  430. if(strncmp($aObject['group_id'], 'ml', 2) === 0) {
  431. $iLevel = (int)substr($aObject['group_id'], 2);
  432. return (bool)BxDolAcl::getInstance()->isMemberLevelInSet(array($iLevel), $iViewerId);
  433. }
  434. if($aObject['group_id'] < 0)
  435. return $this->checkSpace($aObject, $iViewerId);
  436. $aGroup = $this->_oDb->getGroupsBy(array('type' => 'id', 'id' => $aObject['group_id']));
  437. if(!empty($aGroup) && is_array($aGroup) && (int)$aGroup['active'] == 1 && !empty($aGroup['check'])) {
  438. $sCheckMethod = $this->getCheckMethod($aGroup['check']);
  439. if(method_exists($this, $sCheckMethod) && $this->$sCheckMethod((substr($sCheckMethod, -8) == 'ByObject' ? $aObject : $aObject['owner_id']), $iViewerId))
  440. return true;
  441. }
  442. return $this->isDynamicGroupMember($aObject['group_id'], $aObject['owner_id'], $iViewerId, $iObjectId);
  443. }
  444. public function checkSpace($aObject, $iViewerId)
  445. {
  446. $oProfile = BxDolProfile::getInstance(-$aObject['group_id']);
  447. if (!$oProfile)
  448. return false;
  449. return CHECK_ACTION_RESULT_ALLOWED === BxDolService::call($oProfile->getModule(), 'check_space_privacy', array($oProfile->getContentId()));
  450. }
  451. public function checkMeOnly($iOwnerId, $iViewerId)
  452. {
  453. return false;
  454. }
  455. public function checkPublic($iOwnerId, $iViewerId)
  456. {
  457. return true;
  458. }
  459. public function checkMembers($iOwnerId, $iViewerId)
  460. {
  461. return isMember();
  462. }
  463. public function checkFriends($iOwnerId, $iViewerId)
  464. {
  465. return BxDolConnection::getObjectInstance('sys_profiles_friends')->isConnected($iOwnerId, $iViewerId, true);
  466. }
  467. public function checkFriendsSelectedByObject($aObject, $iViewerId)
  468. {
  469. if(!$this->checkFriends($aObject['owner_id'], $iViewerId))
  470. return false;
  471. $aGroupCustom = $this->getGroupCustom(array(
  472. 'type' => 'pcog_ext',
  473. 'profile_id' => $aObject['owner_id'],
  474. 'content_id' => $aObject['id'],
  475. 'object' => $this->_sObject,
  476. 'group_id' => $aObject['group_id']
  477. ));
  478. return !empty($aGroupCustom['members']) && is_array($aGroupCustom['members']) && in_array($iViewerId, $aGroupCustom['members']);
  479. }
  480. public function checkRelations($iOwnerId, $iViewerId)
  481. {
  482. return BxDolConnection::getObjectInstance('sys_profiles_relations')->isConnected($aObject['owner_id'], $iViewerId, true);
  483. }
  484. public function checkRelationsSelectedByObject($aObject, $iViewerId)
  485. {
  486. if(!$this->checkRelations($aObject['owner_id'], $iViewerId))
  487. return false;
  488. $aGroupCustom = $this->getGroupCustom(array(
  489. 'type' => 'pcog_ext',
  490. 'profile_id' => $aObject['owner_id'],
  491. 'content_id' => $aObject['id'],
  492. 'object' => $this->_sObject,
  493. 'group_id' => $aObject['group_id']
  494. ));
  495. return !empty($aGroupCustom['members']) && is_array($aGroupCustom['members']) && in_array($iViewerId, $aGroupCustom['members']);
  496. }
  497. public function checkCustomByObject($aObject, $iViewerId)
  498. {
  499. return '';
  500. }
  501. public function setTableFieldAuthor($sValue)
  502. {
  503. $this->_aObject['table_field_author'] = $sValue;
  504. $this->_oDb->init($this->_aObject);
  505. }
  506. protected function getObjectInfo($sAction, $iObjectId)
  507. {
  508. return $this->_oDb->getObjectInfo($sAction, $iObjectId);
  509. }
  510. protected function getPrivacyGroupsForContentPublic($iProfileIdOwner = 0, $aCustomGroups = array())
  511. {
  512. $aGroups = array(BX_DOL_PG_ALL);
  513. if(isLogged()) {
  514. $iProfileIdLogged = bx_get_logged_profile_id();
  515. if($iProfileIdLogged == $iProfileIdOwner)
  516. return true;
  517. $aGroups[] = BX_DOL_PG_MEMBERS;
  518. if($iProfileIdOwner && $this->checkFriends($iProfileIdOwner, $iProfileIdLogged))
  519. $aGroups[] = BX_DOL_PG_FRIENDS;
  520. }
  521. return array_merge($aGroups, $aCustomGroups);
  522. }
  523. protected function getCheckMethod($s)
  524. {
  525. if(substr($s, 0, 1) != '@')
  526. return false;
  527. return bx_gen_method_name(str_replace('@', 'check_', $s));
  528. }
  529. protected function convertActionToField($sAction)
  530. {
  531. return 'allow_' . strtolower(str_replace(' ', '-', $sAction)) . '_to';
  532. }
  533. /**
  534. * Check whethere viewer is a member of dynamic group.
  535. *
  536. * @param mixed $mixedGroupId dynamic group ID.
  537. * @param integer $iObjectOwnerId object owner ID.
  538. * @param integer $iViewerId viewer ID.
  539. * @return boolean result of operation.
  540. */
  541. protected function isDynamicGroupMember($mixedGroupId, $iObjectOwnerId, $iViewerId, $iObjectId)
  542. {
  543. return false;
  544. }
  545. /**
  546. * get privacy groups for getGroupChooser
  547. */
  548. protected function getGroups()
  549. {
  550. $aValues = array();
  551. $aGroups = $this->_oDb->getGroupsBy(array('type' => 'active'));
  552. foreach($aGroups as $aGroup) {
  553. if((int)$aGroup['active'] == 0 || in_array($aGroup['id'], $this->_aGroupsExclude))
  554. continue;
  555. $aValues[] = array('key' => $aGroup['id'], 'value' => _t($aGroup['title']));
  556. }
  557. return $aValues;
  558. }
  559. /**
  560. * Check whethere custom group is allowed in current circumstances.
  561. * NOTE. Can be overwritten if it's needed.
  562. *
  563. * @param type $aParams an array of parameters.
  564. * @return boolean result of operation.
  565. */
  566. protected function isSelectGroupCustom($aParams)
  567. {
  568. return true;
  569. }
  570. }
  571. /** @} */