1
0

BxBaseModProfileModule.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  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 BaseProfile Base classes for profile modules
  7. * @ingroup UnaModules
  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 serviceGetMenuAddonFavoritesProfileStats()
  75. {
  76. bx_import('SearchResult', $this->_aModule);
  77. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  78. $o = new $sClass('favorite', array('user' => bx_get_logged_profile_id()));
  79. $o->unsetPaginate();
  80. return $o->getNum();
  81. }
  82. public function serviceGetSubmenuObject ()
  83. {
  84. return $this->_oConfig->CNF['OBJECT_MENU_SUBMENU_VIEW_ENTRY'];
  85. }
  86. public function serviceGetMenuSetNameForMenuTrigger ($sMenuTriggerName)
  87. {
  88. $CNF = &$this->_oConfig->CNF;
  89. if ($CNF['TRIGGER_MENU_PROFILE_VIEW_SUBMENU'] == $sMenuTriggerName)
  90. return $CNF['OBJECT_MENU_SUBMENU_VIEW_ENTRY'];
  91. elseif ($CNF['TRIGGER_MENU_PROFILE_VIEW_ACTIONS'] == $sMenuTriggerName)
  92. return $CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY'];
  93. return '';
  94. }
  95. public function serviceGetPageObjectForPageTrigger ($sPageTriggerName)
  96. {
  97. if (isset($this->_oConfig->CNF['TRIGGER_PAGE_VIEW_ENTRY']) && $this->_oConfig->CNF['TRIGGER_PAGE_VIEW_ENTRY'] == $sPageTriggerName)
  98. return $this->_oConfig->CNF['OBJECT_PAGE_VIEW_ENTRY'];
  99. return '';
  100. }
  101. public function serviceProfilesSearch ($sTerm, $iLimit)
  102. {
  103. $aRet = array();
  104. $a = $this->_oDb->searchByTerm($sTerm, $iLimit);
  105. foreach ($a as $r)
  106. $aRet[] = array ('label' => $this->serviceProfileName($r['content_id']), 'value' => $r['profile_id']);
  107. return $aRet;
  108. }
  109. public function serviceProfileUnit ($iContentId)
  110. {
  111. return $this->_serviceTemplateFunc('unit', $iContentId);
  112. }
  113. public function serviceProfilePicture ($iContentId)
  114. {
  115. return $this->_serviceTemplateFunc('urlPicture', $iContentId);
  116. }
  117. public function serviceProfileAvatar ($iContentId)
  118. {
  119. return $this->_serviceTemplateFunc('urlAvatar', $iContentId);
  120. }
  121. public function serviceProfileEditUrl ($iContentId)
  122. {
  123. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $this->_oConfig->CNF['URI_EDIT_ENTRY'] . '&id=' . $iContentId);
  124. }
  125. public function serviceProfileThumb ($iContentId)
  126. {
  127. return $this->_serviceTemplateFunc('thumb', $iContentId);
  128. }
  129. public function serviceProfileIcon ($iContentId)
  130. {
  131. return $this->_serviceTemplateFunc('icon', $iContentId);
  132. }
  133. public function serviceProfileName ($iContentId)
  134. {
  135. if (!$iContentId)
  136. return false;
  137. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  138. if (!$aContentInfo)
  139. return false;
  140. return bx_process_output($aContentInfo[$this->_oConfig->CNF['FIELD_NAME']]);
  141. }
  142. public function serviceProfileCreateUrl ($bAbsolute = true)
  143. {
  144. $CNF = $this->_oConfig->CNF;
  145. if(empty($CNF['URL_CREATE']))
  146. return false;
  147. return $bAbsolute ? BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_CREATE']) : $CNF['URL_CREATE'];
  148. }
  149. public function serviceProfileUrl ($iContentId)
  150. {
  151. if (!$iContentId)
  152. return false;
  153. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  154. if (!$aContentInfo)
  155. return false;
  156. $CNF = $this->_oConfig->CNF;
  157. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  158. }
  159. public function servicePrepareFields ($aFieldsProfile)
  160. {
  161. return $aFieldsProfile;
  162. }
  163. public function serviceFormsHelper ()
  164. {
  165. return parent::serviceFormsHelper ();
  166. }
  167. public function serviceEntityCreate ()
  168. {
  169. BxDolInformer::getInstance($this->_oTemplate)->setEnabled(false);
  170. return parent::serviceEntityCreate ();
  171. }
  172. public function serviceActAsProfile ()
  173. {
  174. return true;
  175. }
  176. public function serviceBrowseRecentProfiles ($bDisplayEmptyMsg = false)
  177. {
  178. return $this->_serviceBrowse ('recent', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  179. }
  180. public function serviceBrowseActiveProfiles ($bDisplayEmptyMsg = false)
  181. {
  182. return $this->_serviceBrowse ('active', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  183. }
  184. public function serviceBrowseTopProfiles ($bDisplayEmptyMsg = false)
  185. {
  186. return $this->_serviceBrowse ('top', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  187. }
  188. public function serviceBrowseOnlineProfiles ($bDisplayEmptyMsg = false)
  189. {
  190. return $this->_serviceBrowse ('online', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  191. }
  192. public function serviceBrowseConnections ($iProfileId, $sObjectConnections = 'sys_profiles_friends', $sConnectionsType = 'content', $iMutual = false, $iDesignBox = BX_DB_PADDING_DEF, $iProfileId2 = 0)
  193. {
  194. return $this->_serviceBrowse (
  195. 'connections',
  196. array(
  197. 'object' => $sObjectConnections,
  198. 'type' => $sConnectionsType,
  199. 'mutual' => $iMutual,
  200. 'profile' => (int)$iProfileId,
  201. 'profile2' => (int)$iProfileId2),
  202. $iDesignBox
  203. );
  204. }
  205. public function serviceBrowseConnectionsQuick ($iProfileId, $sObjectConnections = 'sys_profiles_friends', $sConnectionsType = 'content', $iMutual = false, $iProfileId2 = 0)
  206. {
  207. // get connections object
  208. $oConnection = BxDolConnection::getObjectInstance($sObjectConnections);
  209. if (!$oConnection)
  210. return '';
  211. // set some vars
  212. $iLimit = empty($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? 4 : getParam($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']);
  213. if (!$iLimit)
  214. $iLimit = 4;
  215. $iStart = (int)bx_get('start');
  216. // get connections array
  217. bx_import('BxDolConnection');
  218. $a = $oConnection->getConnectionsAsArray ($sConnectionsType, $iProfileId, $iProfileId2, $iMutual, (int)bx_get('start'), $iLimit + 1, BX_CONNECTIONS_ORDER_ADDED_DESC);
  219. if (!$a)
  220. return '';
  221. return $this->_serviceBrowseQuick($a, $iStart, $iLimit);
  222. }
  223. public function serviceBrowseByAcl ($mixedLevelId, $iDesignBox = BX_DB_PADDING_DEF)
  224. {
  225. return $this->_serviceBrowse (
  226. 'acl',
  227. array(
  228. 'level' => $mixedLevelId,
  229. ),
  230. $iDesignBox,
  231. true
  232. );
  233. }
  234. public function serviceEntityEditCover ($iContentId = 0)
  235. {
  236. return $this->_serviceEntityForm ('editDataForm', $iContentId, $this->_oConfig->CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT_COVER']);
  237. }
  238. /**
  239. * Entry social sharing block
  240. */
  241. public function serviceEntitySocialSharing ($iContentId = 0)
  242. {
  243. if (!$iContentId)
  244. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  245. if (!$iContentId)
  246. return false;
  247. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  248. if (!$aContentInfo)
  249. return false;
  250. $CNF = &$this->_oConfig->CNF;
  251. return $this->_entitySocialSharing ($iContentId, array(
  252. 'id_timeline' => 0,
  253. 'id_thumb' => !empty($CNF['FIELD_PICTURE']) && !empty($aContentInfo[$CNF['FIELD_PICTURE']]) ? $aContentInfo[$CNF['FIELD_PICTURE']] : '',
  254. 'title' => !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  255. 'object_storage' => !empty($CNF['OBJECT_STORAGE']) ? $CNF['OBJECT_STORAGE'] : '',
  256. 'object_transcoder' => false,
  257. 'object_vote' => '',
  258. 'object_favorite' => !empty($CNF['OBJECT_FAVORITES']) ? $CNF['OBJECT_FAVORITES'] : '',
  259. 'object_feature' => !empty($CNF['OBJECT_FEATURED']) ? $CNF['OBJECT_FEATURED'] : '',
  260. 'object_report' => !empty($CNF['OBJECT_REPORTS']) ? $CNF['OBJECT_REPORTS'] : '',
  261. 'uri_view_entry' => !empty($CNF['URI_VIEW_ENTRY']) ? $CNF['URI_VIEW_ENTRY'] : '',
  262. 'social_sharing' => false
  263. ));
  264. }
  265. public function serviceProfileMembership ($iContentId = 0)
  266. {
  267. if (!$iContentId)
  268. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  269. if (!$iContentId)
  270. return false;
  271. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  272. if (!$aContentInfo)
  273. return false;
  274. return BxDolAcl::getInstance()->getProfileMembership($aContentInfo['profile_id']);
  275. }
  276. public function serviceProfileFriends ($iContentId = 0)
  277. {
  278. if (!$iContentId)
  279. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  280. if (!$iContentId)
  281. return false;
  282. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  283. if (!$aContentInfo)
  284. return false;
  285. bx_import('BxDolConnection');
  286. $s = $this->serviceBrowseConnectionsQuick ($aContentInfo['profile_id'], 'sys_profiles_friends', BX_CONNECTIONS_CONTENT_TYPE_CONTENT, true);
  287. if (!$s)
  288. return MsgBox(_t('_sys_txt_empty'));
  289. return $s;
  290. }
  291. /**
  292. * For internal usage only.
  293. */
  294. public function serviceDeleteEntityService ($iContentId, $bDeleteWithContent = false)
  295. {
  296. return parent::serviceDeleteEntity ($iContentId, 'deleteDataService');
  297. }
  298. /**
  299. * Data for Notifications module
  300. */
  301. public function serviceGetNotificationsData()
  302. {
  303. $a = parent::serviceGetNotificationsData();
  304. $sModule = $this->_aModule['name'];
  305. $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');
  306. $a['alerts'][] = array('unit' => $sModule, 'action' => 'timeline_post_common');
  307. return $a;
  308. }
  309. /**
  310. * Notification about new member requst in the group
  311. */
  312. public function serviceGetNotificationsTimelinePostCommon($aEvent)
  313. {
  314. return $this->_serviceGetNotification($aEvent, '_bx_' . $this->_oConfig->getUri() . '_txt_ntfs_timeline_post_common');
  315. }
  316. public function serviceGetConnectionButtonsTitles($iProfileId, $sConnectionsObject = 'sys_profiles_friends')
  317. {
  318. if (!isLogged())
  319. return array();
  320. if (!($oConn = BxDolConnection::getObjectInstance($sConnectionsObject)))
  321. return array();
  322. $CNF = $this->_oConfig->CNF;
  323. if ($oConn->isConnectedNotMutual(bx_get_logged_profile_id(), $iProfileId)) {
  324. return array(
  325. 'add' => _t($CNF['T']['menu_item_title_befriend_sent']),
  326. 'remove' => _t($CNF['T']['menu_item_title_unfriend_cancel_request']),
  327. );
  328. } elseif ($oConn->isConnectedNotMutual($iProfileId, bx_get_logged_profile_id())) {
  329. return array(
  330. 'add' => _t($CNF['T']['menu_item_title_befriend_confirm']),
  331. 'remove' => _t($CNF['T']['menu_item_title_unfriend_reject_request']),
  332. );
  333. } elseif ($oConn->isConnected($iProfileId, bx_get_logged_profile_id(), true)) {
  334. return array(
  335. 'add' => '',
  336. 'remove' => _t($CNF['T']['menu_item_title_unfriend']),
  337. );
  338. } else {
  339. return array(
  340. 'add' => _t($CNF['T']['menu_item_title_befriend']),
  341. 'remove' => '',
  342. );
  343. }
  344. }
  345. // ====== PERMISSION METHODS
  346. /**
  347. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  348. */
  349. public function checkAllowedAdd ($isPerformAction = false)
  350. {
  351. $oAccount = BxDolAccount::getInstance();
  352. if (!$oAccount || ($this->serviceActAsProfile() && $oAccount->isProfilesLimitReached()))
  353. return _t('_sys_txt_access_denied');
  354. return parent::checkAllowedAdd ($isPerformAction);
  355. }
  356. /**
  357. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  358. */
  359. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  360. {
  361. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  362. if ($oProfile && $oProfile->id() == $this->_iProfileId)
  363. return CHECK_ACTION_RESULT_ALLOWED;
  364. return parent::checkAllowedView ($aDataEntry, $isPerformAction);
  365. }
  366. /**
  367. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  368. */
  369. public function checkAllowedViewProfileImage ($aDataEntry, $isPerformAction = false)
  370. {
  371. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedView($aDataEntry)) && BX_DOL_PG_FRIENDS == $aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']])
  372. return CHECK_ACTION_RESULT_ALLOWED;
  373. return $sMsg;
  374. }
  375. /**
  376. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  377. */
  378. public function checkAllowedViewCoverImage ($aDataEntry, $isPerformAction = false)
  379. {
  380. return $this->checkAllowedView($aDataEntry);
  381. }
  382. /**
  383. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  384. */
  385. public function checkAllowedPost ($aDataEntry, $isPerformAction = false)
  386. {
  387. return $this->checkAllowedView ($aDataEntry, $isPerformAction);
  388. }
  389. /**
  390. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  391. */
  392. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  393. {
  394. // moderator always has access
  395. if ($this->_isModerator($isPerformAction))
  396. return CHECK_ACTION_RESULT_ALLOWED;
  397. // owner (checked by account! not as profile as ususal) always have access
  398. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name']);
  399. if (!$oProfile)
  400. return _t('_sys_txt_error_occured');
  401. if ($oProfile->getAccountId() == $this->_iAccountId)
  402. return CHECK_ACTION_RESULT_ALLOWED;
  403. return _t('_sys_txt_access_denied');
  404. }
  405. /**
  406. * Check if user can change cover image
  407. */
  408. public function checkAllowedChangeCover ($aDataEntry, $isPerformAction = false)
  409. {
  410. // moderator always has access
  411. if ($this->_isModerator($isPerformAction))
  412. return CHECK_ACTION_RESULT_ALLOWED;
  413. // owner (checked by account! not as profile as ususal) always have access
  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)
  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 checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  425. {
  426. // moderator always has access
  427. if ($this->_isModerator($isPerformAction))
  428. return CHECK_ACTION_RESULT_ALLOWED;
  429. // check ACL and owner (checked by account! not as profile as ususal)
  430. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  431. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name']);
  432. if (!$oProfile)
  433. return _t('_sys_txt_error_occured');
  434. if ($oProfile->getAccountId() == $this->_iAccountId && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  435. return CHECK_ACTION_RESULT_ALLOWED;
  436. return _t('_sys_txt_access_denied');
  437. }
  438. /**
  439. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  440. */
  441. public function checkAllowedViewMoreMenu (&$aDataEntry, $isPerformAction = false)
  442. {
  443. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']);
  444. if (!$oMenu || !$oMenu->getCode())
  445. return _t('_sys_txt_access_denied');
  446. return CHECK_ACTION_RESULT_ALLOWED;
  447. }
  448. /**
  449. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  450. */
  451. public function checkAllowedCompose (&$aDataEntry, $isPerformAction = false)
  452. {
  453. $CNF = &$this->_oConfig->CNF;
  454. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->getName());
  455. if($oProfile && $oProfile->id() == $this->_iProfileId)
  456. return _t('_sys_txt_access_denied');
  457. return $this->checkAllowedView ($aDataEntry, $isPerformAction);
  458. }
  459. /**
  460. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  461. */
  462. public function checkAllowedFriendAdd (&$aDataEntry, $isPerformAction = false)
  463. {
  464. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', true, false);
  465. }
  466. /**
  467. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  468. */
  469. public function checkAllowedFriendRemove (&$aDataEntry, $isPerformAction = false)
  470. {
  471. if (CHECK_ACTION_RESULT_ALLOWED === $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', false, true, true))
  472. return CHECK_ACTION_RESULT_ALLOWED;
  473. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', false, true, false);
  474. }
  475. /**
  476. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  477. */
  478. public function checkAllowedSubscribeAdd (&$aDataEntry, $isPerformAction = false)
  479. {
  480. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedView($aDataEntry)))
  481. return $sMsg;
  482. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_subscriptions', false, false);
  483. }
  484. /**
  485. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  486. */
  487. public function checkAllowedSubscribeRemove (&$aDataEntry, $isPerformAction = false)
  488. {
  489. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_subscriptions', false, true);
  490. }
  491. public function checkAllowedSubscriptionsView (&$aDataEntry, $isPerformAction = false)
  492. {
  493. $CNF = &$this->_oConfig->CNF;
  494. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->_aModule['name']);
  495. if(!$oProfile || ($oProfile->id() != $this->_iProfileId && $this->_oDb->getParam($CNF['PARAM_PUBLIC_SBSN']) != 'on' && $this->_oDb->getParam($CNF['PARAM_PUBLIC_SBSD']) != 'on'))
  496. return _t('_sys_txt_access_denied');
  497. return CHECK_ACTION_RESULT_ALLOWED;
  498. }
  499. public function checkMyself($iContentId)
  500. {
  501. $iLogged = (int)bx_get_logged_profile_id();
  502. if(empty($iLogged))
  503. return false;
  504. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->_oConfig->getName());
  505. if(!$oProfile)
  506. return false;
  507. return $oProfile->id() == $iLogged;
  508. }
  509. // ====== PROTECTED METHODS
  510. protected function _checkAllowedConnect (&$aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap = false)
  511. {
  512. if (!$this->_iProfileId)
  513. return _t('_sys_txt_access_denied');
  514. $CNF = &$this->_oConfig->CNF;
  515. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->_aModule['name']);
  516. if (!$oProfile || $oProfile->id() == $this->_iProfileId)
  517. return _t('_sys_txt_access_denied');
  518. $oConn = BxDolConnection::getObjectInstance($sObjConnection);
  519. if ($isSwap)
  520. $isConnected = $oConn->isConnected($oProfile->id(), $this->_iProfileId, $isMutual);
  521. else
  522. $isConnected = $oConn->isConnected($this->_iProfileId, $oProfile->id(), $isMutual);
  523. if ($isInvertResult)
  524. $isConnected = !$isConnected;
  525. return $isConnected ? _t('_sys_txt_access_denied') : CHECK_ACTION_RESULT_ALLOWED;
  526. }
  527. protected function _buildRssParams($sMode, $aArgs)
  528. {
  529. $aParams = array ();
  530. $sMode = bx_process_input($sMode);
  531. switch ($sMode) {
  532. case 'connections':
  533. $aParams = array(
  534. 'object' => isset($aArgs[0]) ? $aArgs[0] : '',
  535. 'type' => isset($aArgs[1]) ? $aArgs[1] : '',
  536. 'profile' => isset($aArgs[2]) ? (int)$aArgs[2] : 0,
  537. 'mutual' => isset($aArgs[3]) ? (int)$aArgs[3] : 0,
  538. 'profile2' => isset($aArgs[4]) ? (int)$aArgs[4] : 0,
  539. );
  540. break;
  541. }
  542. return $aParams;
  543. }
  544. protected function _serviceBrowseQuick($aProfiles, $iStart = 0, $iLimit = 4)
  545. {
  546. // get paginate object
  547. $oPaginate = new BxTemplPaginate(array(
  548. 'on_change_page' => "return !loadDynamicBlockAutoPaginate(this, '{start}', '{per_page}');",
  549. 'num' => count($aProfiles),
  550. 'per_page' => $iLimit,
  551. 'start' => $iStart,
  552. ));
  553. // remove last item from connection array, because we've got one more item for pagination calculations only
  554. if (count($aProfiles) > $iLimit)
  555. array_pop($aProfiles);
  556. // get profiles HTML
  557. $s = '';
  558. foreach ($aProfiles as $iProfileId) {
  559. $oProfile = BxDolProfile::getInstance($iProfileId);
  560. if(!$oProfile)
  561. continue;
  562. $s .= $oProfile->getUnit();
  563. }
  564. // return profiles + paginate
  565. return $s . (!$iStart && $oPaginate->getNum() <= $iLimit ? '' : $oPaginate->getSimplePaginate());
  566. }
  567. }
  568. /** @} */