BxBaseModProfileModule.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup BaseProfile Base classes for profile modules
  7. * @ingroup TridentModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Base class for profile modules.
  13. */
  14. class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolProfileService
  15. {
  16. protected $_iAccountId;
  17. function __construct(&$aModule)
  18. {
  19. parent::__construct($aModule);
  20. $this->_iAccountId = getLoggedId();
  21. }
  22. public function actionDeleteProfileImg($iFileId, $iContentId, $sFieldPicture)
  23. {
  24. $aResult = array();
  25. $CNF = &$this->_oConfig->CNF;
  26. $oSrorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  27. if (!($aFile = $oSrorage->getFile((int)$iFileId)) || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)) || $aContentInfo[$sFieldPicture] != (int)$iFileId)
  28. $aResult = array('error' => 1, 'msg' => _t('_sys_storage_err_file_not_found'));
  29. $oAccountProfile = BxDolProfile::getInstanceAccountProfile();
  30. if ($oAccountProfile)
  31. $iAccountProfileId = $oAccountProfile->id();
  32. if ((!$aResult && !isLogged()) || (!$aResult && $aFile['profile_id'] != $iAccountProfileId && !$this->_isModerator()))
  33. $aResult = array('error' => 2, 'msg' => _t('_Access denied'));
  34. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oTemplate);
  35. if (!$aResult && !$oForm->_deleteFile($iContentId, $sFieldPicture, (int)$iFileId, true))
  36. $aResult = array('error' => 3, 'msg' => _t('_Failed'));
  37. elseif (!$aResult)
  38. $aResult = array('error' => 0, 'msg' => '');
  39. header('Content-Type: application/json; charset=utf-8');
  40. echo json_encode($aResult);
  41. }
  42. // ====== SERVICE METHODS
  43. public function servicePrivateProfileMsg()
  44. {
  45. return MsgBox(_t('_sys_access_denied_to_private_content'));
  46. }
  47. public function serviceGetContentInfoById($iContentId)
  48. {
  49. return $this->_oDb->getContentInfoById((int)$iContentId);
  50. }
  51. public function serviceGetMenuAddonManageTools()
  52. {
  53. bx_import('SearchResult', $this->_aModule);
  54. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  55. $o = new $sClass();
  56. $o->fillFilters(array(
  57. 'perofileStatus' => BX_PROFILE_STATUS_PENDING
  58. ));
  59. $o->unsetPaginate();
  60. return $o->getNum();
  61. }
  62. public function serviceGetMenuAddonManageToolsProfileStats()
  63. {
  64. bx_import('SearchResult', $this->_aModule);
  65. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  66. $o = new $sClass();
  67. $o->fillFilters(array(
  68. 'account_id' => getLoggedId(),
  69. 'perofileStatus' => ''
  70. ));
  71. $o->unsetPaginate();
  72. return $o->getNum();
  73. }
  74. public function serviceGetSubmenuObject ()
  75. {
  76. return $this->_oConfig->CNF['OBJECT_MENU_SUBMENU_VIEW_ENTRY'];
  77. }
  78. public function serviceGetMenuSetNameForMenuTrigger ($sMenuTriggerName)
  79. {
  80. $CNF = &$this->_oConfig->CNF;
  81. if ($CNF['TRIGGER_MENU_PROFILE_VIEW_SUBMENU'] == $sMenuTriggerName)
  82. return $CNF['OBJECT_MENU_SUBMENU_VIEW_ENTRY'];
  83. elseif ($CNF['TRIGGER_MENU_PROFILE_VIEW_ACTIONS'] == $sMenuTriggerName)
  84. return $CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY'];
  85. return '';
  86. }
  87. public function serviceGetPageObjectForPageTrigger ($sPageTriggerName)
  88. {
  89. if (isset($this->_oConfig->CNF['TRIGGER_PAGE_VIEW_ENTRY']) && $this->_oConfig->CNF['TRIGGER_PAGE_VIEW_ENTRY'] == $sPageTriggerName)
  90. return $this->_oConfig->CNF['OBJECT_PAGE_VIEW_ENTRY'];
  91. return '';
  92. }
  93. public function serviceProfilesSearch ($sTerm, $iLimit)
  94. {
  95. $aRet = array();
  96. $a = $this->_oDb->searchByTerm($sTerm, $iLimit);
  97. foreach ($a as $r)
  98. $aRet[] = array ('label' => $this->serviceProfileName($r['content_id']), 'value' => $r['profile_id']);
  99. return $aRet;
  100. }
  101. public function serviceProfileUnit ($iContentId)
  102. {
  103. return $this->_serviceTemplateFunc('unit', $iContentId);
  104. }
  105. public function serviceProfilePicture ($iContentId)
  106. {
  107. return $this->_serviceTemplateFunc('urlPicture', $iContentId);
  108. }
  109. public function serviceProfileAvatar ($iContentId)
  110. {
  111. return $this->_serviceTemplateFunc('urlAvatar', $iContentId);
  112. }
  113. public function serviceProfileEditUrl ($iContentId)
  114. {
  115. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $this->_oConfig->CNF['URI_EDIT_ENTRY'] . '&id=' . $iContentId);
  116. }
  117. public function serviceProfileThumb ($iContentId)
  118. {
  119. return $this->_serviceTemplateFunc('thumb', $iContentId);
  120. }
  121. public function serviceProfileIcon ($iContentId)
  122. {
  123. return $this->_serviceTemplateFunc('icon', $iContentId);
  124. }
  125. public function serviceProfileName ($iContentId)
  126. {
  127. if (!$iContentId)
  128. return false;
  129. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  130. if (!$aContentInfo)
  131. return false;
  132. return bx_process_output($aContentInfo[$this->_oConfig->CNF['FIELD_NAME']]);
  133. }
  134. public function serviceProfileCreateUrl ($bAbsolute = true)
  135. {
  136. $CNF = $this->_oConfig->CNF;
  137. if(empty($CNF['URL_CREATE']))
  138. return false;
  139. return $bAbsolute ? BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_CREATE']) : $CNF['URL_CREATE'];
  140. }
  141. public function serviceProfileUrl ($iContentId)
  142. {
  143. if (!$iContentId)
  144. return false;
  145. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  146. if (!$aContentInfo)
  147. return false;
  148. $CNF = $this->_oConfig->CNF;
  149. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  150. }
  151. public function servicePrepareFields ($aFieldsProfile)
  152. {
  153. return $aFieldsProfile;
  154. }
  155. public function serviceFormsHelper ()
  156. {
  157. return parent::serviceFormsHelper ();
  158. }
  159. public function serviceEntityCreate ()
  160. {
  161. BxDolInformer::getInstance($this->_oTemplate)->setEnabled(false);
  162. return parent::serviceEntityCreate ();
  163. }
  164. public function serviceActAsProfile ()
  165. {
  166. return true;
  167. }
  168. public function serviceBrowseRecentProfiles ($bDisplayEmptyMsg = false)
  169. {
  170. return $this->_serviceBrowse ('recent', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  171. }
  172. public function serviceBrowseActiveProfiles ($bDisplayEmptyMsg = false)
  173. {
  174. return $this->_serviceBrowse ('active', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  175. }
  176. public function serviceBrowseTopProfiles ($bDisplayEmptyMsg = false)
  177. {
  178. return $this->_serviceBrowse ('top', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  179. }
  180. public function serviceBrowseOnlineProfiles ($bDisplayEmptyMsg = false)
  181. {
  182. return $this->_serviceBrowse ('online', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  183. }
  184. public function serviceBrowseConnections ($iProfileId, $sObjectConnections = 'sys_profiles_friends', $sConnectionsType = 'content', $iMutual = false, $iDesignBox = BX_DB_PADDING_DEF, $iProfileId2 = 0)
  185. {
  186. return $this->_serviceBrowse (
  187. 'connections',
  188. array(
  189. 'object' => $sObjectConnections,
  190. 'type' => $sConnectionsType,
  191. 'mutual' => $iMutual,
  192. 'profile' => (int)$iProfileId,
  193. 'profile2' => (int)$iProfileId2),
  194. $iDesignBox
  195. );
  196. }
  197. public function serviceBrowseConnectionsQuick ($iProfileId, $sObjectConnections = 'sys_profiles_friends', $sConnectionsType = 'content', $iMutual = false, $iProfileId2 = 0)
  198. {
  199. // get connections object
  200. $oConnection = BxDolConnection::getObjectInstance($sObjectConnections);
  201. if (!$oConnection)
  202. return '';
  203. // set some vars
  204. $iLimit = empty($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? 4 : getParam($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']);
  205. if (!$iLimit)
  206. $iLimit = 4;
  207. $iStart = (int)bx_get('start');
  208. // get connections array
  209. bx_import('BxDolConnection');
  210. $a = $oConnection->getConnectionsAsArray ($sConnectionsType, $iProfileId, $iProfileId2, $iMutual, (int)bx_get('start'), $iLimit + 1, BX_CONNECTIONS_ORDER_ADDED_DESC);
  211. if (!$a)
  212. return '';
  213. // get paginate object
  214. $oPaginate = new BxTemplPaginate(array(
  215. 'on_change_page' => "return !loadDynamicBlockAutoPaginate(this, '{start}', '{per_page}');",
  216. 'num' => count($a),
  217. 'per_page' => $iLimit,
  218. 'start' => $iStart,
  219. ));
  220. // remove last item from connection array, because we've got one more item for pagination calculations only
  221. if (count($a) > $iLimit)
  222. array_pop($a);
  223. // get profiles HTML
  224. $s = '';
  225. foreach ($a as $iProfileId) {
  226. if (!($o = BxDolProfile::getInstance($iProfileId))) {
  227. continue;
  228. }
  229. $s .= $o->getUnit();
  230. }
  231. // return profiles + paginate
  232. return $s . (!$iStart && $oPaginate->getNum() <= $iLimit ? '' : $oPaginate->getSimplePaginate());
  233. }
  234. public function serviceBrowseByAcl ($mixedLevelId, $iDesignBox = BX_DB_PADDING_DEF)
  235. {
  236. return $this->_serviceBrowse (
  237. 'acl',
  238. array(
  239. 'level' => $mixedLevelId,
  240. ),
  241. $iDesignBox,
  242. true
  243. );
  244. }
  245. public function serviceEntityEditCover ($iContentId = 0)
  246. {
  247. return $this->_serviceEntityForm ('editDataForm', $iContentId, $this->_oConfig->CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT_COVER']);
  248. }
  249. public function serviceProfileMembership ($iContentId = 0)
  250. {
  251. if (!$iContentId)
  252. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  253. if (!$iContentId)
  254. return false;
  255. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  256. if (!$aContentInfo)
  257. return false;
  258. return BxDolAcl::getInstance()->getProfileMembership($aContentInfo['profile_id']);
  259. }
  260. public function serviceProfileFriends ($iContentId = 0)
  261. {
  262. if (!$iContentId)
  263. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  264. if (!$iContentId)
  265. return false;
  266. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  267. if (!$aContentInfo)
  268. return false;
  269. bx_import('BxDolConnection');
  270. $s = $this->serviceBrowseConnectionsQuick ($aContentInfo['profile_id'], 'sys_profiles_friends', BX_CONNECTIONS_CONTENT_TYPE_CONTENT, true);
  271. if (!$s)
  272. return MsgBox(_t('_sys_txt_empty'));
  273. return $s;
  274. }
  275. /**
  276. * For internal usage only.
  277. */
  278. public function serviceDeleteEntityService ($iContentId, $bDeleteWithContent = false)
  279. {
  280. return parent::serviceDeleteEntity ($iContentId, 'deleteDataService');
  281. }
  282. /**
  283. * Data for Notifications module
  284. */
  285. public function serviceGetNotificationsData()
  286. {
  287. $a = parent::serviceGetNotificationsData();
  288. $sModule = $this->_aModule['name'];
  289. $a['handlers'][] = array('group' => $sModule . '_timeline_post_common', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'timeline_post_common', 'module_name' => $sModule, 'module_method' => 'get_notifications_timeline_post_common', 'module_class' => 'Module');
  290. $a['alerts'][] = array('unit' => $sModule, 'action' => 'timeline_post_common');
  291. return $a;
  292. }
  293. /**
  294. * Notification about new member requst in the group
  295. */
  296. public function serviceGetNotificationsTimelinePostCommon($aEvent)
  297. {
  298. return $this->_serviceGetNotification($aEvent, '_bx_' . $this->_oConfig->getUri() . '_txt_ntfs_timeline_post_common');
  299. }
  300. public function serviceGetConnectionButtonsTitles($iProfileId, $sConnectionsObject = 'sys_profiles_friends')
  301. {
  302. if (!isLogged())
  303. return array();
  304. if (!($oConn = BxDolConnection::getObjectInstance($sConnectionsObject)))
  305. return array();
  306. $CNF = $this->_oConfig->CNF;
  307. if ($oConn->isConnectedNotMutual(bx_get_logged_profile_id(), $iProfileId)) {
  308. return array(
  309. 'add' => _t($CNF['T']['menu_item_title_befriend_sent']),
  310. 'remove' => _t($CNF['T']['menu_item_title_unfriend_cancel_request']),
  311. );
  312. } elseif ($oConn->isConnectedNotMutual($iProfileId, bx_get_logged_profile_id())) {
  313. return array(
  314. 'add' => _t($CNF['T']['menu_item_title_befriend_confirm']),
  315. 'remove' => _t($CNF['T']['menu_item_title_unfriend_reject_request']),
  316. );
  317. } elseif ($oConn->isConnected($iProfileId, bx_get_logged_profile_id(), true)) {
  318. return array(
  319. 'add' => '',
  320. 'remove' => _t($CNF['T']['menu_item_title_unfriend']),
  321. );
  322. } else {
  323. return array(
  324. 'add' => _t($CNF['T']['menu_item_title_befriend']),
  325. 'remove' => '',
  326. );
  327. }
  328. }
  329. // ====== PERMISSION METHODS
  330. /**
  331. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  332. */
  333. public function checkAllowedAdd ($isPerformAction = false)
  334. {
  335. if ($this->serviceActAsProfile() && BxDolAccount::getInstance()->isProfilesLimitReached())
  336. return _t('_sys_txt_access_denied');
  337. return parent::checkAllowedAdd ($isPerformAction);
  338. }
  339. /**
  340. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  341. */
  342. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  343. {
  344. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  345. if ($oProfile && $oProfile->id() == $this->_iProfileId)
  346. return CHECK_ACTION_RESULT_ALLOWED;
  347. return parent::checkAllowedView ($aDataEntry, $isPerformAction);
  348. }
  349. /**
  350. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  351. */
  352. public function checkAllowedViewProfileImage ($aDataEntry, $isPerformAction = false)
  353. {
  354. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedView($aDataEntry)) && BX_DOL_PG_FRIENDS == $aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']])
  355. return CHECK_ACTION_RESULT_ALLOWED;
  356. return $sMsg;
  357. }
  358. /**
  359. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  360. */
  361. public function checkAllowedViewCoverImage ($aDataEntry, $isPerformAction = false)
  362. {
  363. return $this->checkAllowedView($aDataEntry);
  364. }
  365. /**
  366. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  367. */
  368. public function checkAllowedPost ($aDataEntry, $isPerformAction = false)
  369. {
  370. return $this->checkAllowedView ($aDataEntry, $isPerformAction);
  371. }
  372. /**
  373. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  374. */
  375. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  376. {
  377. // moderator always has access
  378. if ($this->_isModerator($isPerformAction))
  379. return CHECK_ACTION_RESULT_ALLOWED;
  380. // owner (checked by account! not as profile as ususal) always have access
  381. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name']);
  382. if (!$oProfile)
  383. return _t('_sys_txt_error_occured');
  384. if ($oProfile->getAccountId() == $this->_iAccountId)
  385. return CHECK_ACTION_RESULT_ALLOWED;
  386. return _t('_sys_txt_access_denied');
  387. }
  388. /**
  389. * Check if user can change cover image
  390. */
  391. public function checkAllowedChangeCover ($aDataEntry, $isPerformAction = false)
  392. {
  393. // moderator always has access
  394. if ($this->_isModerator($isPerformAction))
  395. return CHECK_ACTION_RESULT_ALLOWED;
  396. // owner (checked by account! not as profile as ususal) always have access
  397. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name']);
  398. if (!$oProfile)
  399. return _t('_sys_txt_error_occured');
  400. if ($oProfile->getAccountId() == $this->_iAccountId)
  401. return CHECK_ACTION_RESULT_ALLOWED;
  402. return _t('_sys_txt_access_denied');
  403. }
  404. /**
  405. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  406. */
  407. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  408. {
  409. // moderator always has access
  410. if ($this->_isModerator($isPerformAction))
  411. return CHECK_ACTION_RESULT_ALLOWED;
  412. // check ACL and owner (checked by account! not as profile as ususal)
  413. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  414. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name']);
  415. if (!$oProfile)
  416. return _t('_sys_txt_error_occured');
  417. if ($oProfile->getAccountId() == $this->_iAccountId && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  418. return CHECK_ACTION_RESULT_ALLOWED;
  419. return _t('_sys_txt_access_denied');
  420. }
  421. /**
  422. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  423. */
  424. public function checkAllowedViewMoreMenu (&$aDataEntry, $isPerformAction = false)
  425. {
  426. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']);
  427. if (!$oMenu || !$oMenu->getCode())
  428. return _t('_sys_txt_access_denied');
  429. return CHECK_ACTION_RESULT_ALLOWED;
  430. }
  431. /**
  432. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  433. */
  434. public function checkAllowedFriendAdd (&$aDataEntry, $isPerformAction = false)
  435. {
  436. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', true, false);
  437. }
  438. /**
  439. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  440. */
  441. public function checkAllowedFriendRemove (&$aDataEntry, $isPerformAction = false)
  442. {
  443. if (CHECK_ACTION_RESULT_ALLOWED === $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', false, true, true))
  444. return CHECK_ACTION_RESULT_ALLOWED;
  445. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', false, true, false);
  446. }
  447. /**
  448. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  449. */
  450. public function checkAllowedSubscribeAdd (&$aDataEntry, $isPerformAction = false)
  451. {
  452. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedView($aDataEntry)))
  453. return $sMsg;
  454. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_subscriptions', false, false);
  455. }
  456. /**
  457. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  458. */
  459. public function checkAllowedSubscribeRemove (&$aDataEntry, $isPerformAction = false)
  460. {
  461. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_subscriptions', false, true);
  462. }
  463. public function checkMyself($iContentId)
  464. {
  465. $iLogged = (int)bx_get_logged_profile_id();
  466. if(empty($iLogged))
  467. return false;
  468. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->_oConfig->getName());
  469. if(!$oProfile)
  470. return false;
  471. return $oProfile->id() == $iLogged;
  472. }
  473. // ====== PROTECTED METHODS
  474. protected function _checkAllowedConnect (&$aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap = false)
  475. {
  476. if (!$this->_iProfileId)
  477. return _t('_sys_txt_access_denied');
  478. $CNF = &$this->_oConfig->CNF;
  479. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->_aModule['name']);
  480. if (!$oProfile || $oProfile->id() == $this->_iProfileId)
  481. return _t('_sys_txt_access_denied');
  482. $oConn = BxDolConnection::getObjectInstance($sObjConnection);
  483. if ($isSwap)
  484. $isConnected = $oConn->isConnected($oProfile->id(), $this->_iProfileId, $isMutual);
  485. else
  486. $isConnected = $oConn->isConnected($this->_iProfileId, $oProfile->id(), $isMutual);
  487. if ($isInvertResult)
  488. $isConnected = !$isConnected;
  489. return $isConnected ? _t('_sys_txt_access_denied') : CHECK_ACTION_RESULT_ALLOWED;
  490. }
  491. protected function _buildRssParams($sMode, $aArgs)
  492. {
  493. $aParams = array ();
  494. $sMode = bx_process_input($sMode);
  495. switch ($sMode) {
  496. case 'connections':
  497. $aParams = array(
  498. 'object' => isset($aArgs[0]) ? $aArgs[0] : '',
  499. 'type' => isset($aArgs[1]) ? $aArgs[1] : '',
  500. 'profile' => isset($aArgs[2]) ? (int)$aArgs[2] : 0,
  501. 'mutual' => isset($aArgs[3]) ? (int)$aArgs[3] : 0,
  502. 'profile2' => isset($aArgs[4]) ? (int)$aArgs[4] : 0,
  503. );
  504. break;
  505. }
  506. return $aParams;
  507. }
  508. }
  509. /** @} */