1
0

BxBaseModProfileModule.php 26 KB

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