1
0

BxBaseModProfileModule.php 25 KB

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