BxBaseModProfileModule.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  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. $oProfile = BxDolProfile::getInstance($r['profile_id']);
  133. $aRet[] = array (
  134. 'label' => $this->serviceProfileName($r['content_id']),
  135. 'value' => $r['profile_id'],
  136. 'thumb' => $oProfile->getThumb(),
  137. 'unit' => $oProfile->getUnit(0, array('template' => 'unit_wo_info'))
  138. );
  139. }
  140. return $aRet;
  141. }
  142. public function serviceProfileUnit ($iContentId, $aParams = array())
  143. {
  144. $mixedContent = $this->_getContent($iContentId);
  145. if($mixedContent === false)
  146. return false;
  147. list($iContentId, $aContentInfo) = $mixedContent;
  148. $bCheckPrivateContent = isset($aParams['check_private_content']) ? (bool)$aParams['check_private_content'] : true;
  149. $sTemplate = (!empty($aParams['template']) ? $aParams['template'] : 'unit') . '.html';
  150. return $this->_oTemplate->unit($aContentInfo, $bCheckPrivateContent, $sTemplate);
  151. }
  152. public function serviceHasImage ($iContentId)
  153. {
  154. $CNF = &$this->_oConfig->CNF;
  155. $mixedContent = $this->_getContent($iContentId, 'getContentInfoById');
  156. if($mixedContent === false)
  157. return false;
  158. list($iContentId, $aContentInfo) = $mixedContent;
  159. return !empty($aContentInfo[$CNF['FIELD_PICTURE']]);
  160. }
  161. public function serviceProfilePicture ($iContentId)
  162. {
  163. return $this->_serviceTemplateFunc('urlPicture', $iContentId);
  164. }
  165. public function serviceProfileAvatar ($iContentId)
  166. {
  167. return $this->_serviceTemplateFunc('urlAvatar', $iContentId);
  168. }
  169. public function serviceProfileEditUrl ($iContentId)
  170. {
  171. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $this->_oConfig->CNF['URI_EDIT_ENTRY'] . '&id=' . $iContentId);
  172. }
  173. public function serviceProfileThumb ($iContentId)
  174. {
  175. return $this->_serviceTemplateFunc('thumb', $iContentId);
  176. }
  177. public function serviceProfileIcon ($iContentId)
  178. {
  179. return $this->_serviceTemplateFunc('icon', $iContentId);
  180. }
  181. public function serviceProfileName ($iContentId)
  182. {
  183. if (!$iContentId)
  184. return false;
  185. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  186. if (!$aContentInfo)
  187. return false;
  188. return bx_process_output($aContentInfo[$this->_oConfig->CNF['FIELD_NAME']]);
  189. }
  190. public function serviceProfileCreateUrl ($bAbsolute = true)
  191. {
  192. $CNF = $this->_oConfig->CNF;
  193. if(empty($CNF['URL_CREATE']))
  194. return false;
  195. return $bAbsolute ? BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_CREATE']) : $CNF['URL_CREATE'];
  196. }
  197. public function serviceProfileUrl ($iContentId)
  198. {
  199. if (!$iContentId)
  200. return false;
  201. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  202. if (!$aContentInfo)
  203. return false;
  204. $CNF = $this->_oConfig->CNF;
  205. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  206. }
  207. /**
  208. * @see iBxDolProfileService::serviceCheckAllowedProfileView
  209. */
  210. public function serviceCheckAllowedProfileView($iContentId)
  211. {
  212. return $this->serviceCheckAllowedWithContent('View', $iContentId);
  213. }
  214. /**
  215. * @see iBxDolProfileService::serviceCheckAllowedPostInProfile
  216. */
  217. public function serviceCheckAllowedPostInProfile($iContentId)
  218. {
  219. return $this->serviceCheckAllowedProfileView($iContentId);
  220. }
  221. public function servicePrepareFields ($aFieldsProfile)
  222. {
  223. return $aFieldsProfile;
  224. }
  225. public function serviceFormsHelper ()
  226. {
  227. return parent::serviceFormsHelper ();
  228. }
  229. public function serviceEntityCreate ()
  230. {
  231. BxDolInformer::getInstance($this->_oTemplate)->setEnabled(false);
  232. return parent::serviceEntityCreate ();
  233. }
  234. public function serviceActAsProfile ()
  235. {
  236. return true;
  237. }
  238. public function serviceBrowseRecentProfiles ($bDisplayEmptyMsg = false)
  239. {
  240. return $this->_serviceBrowse ('recent', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  241. }
  242. public function serviceBrowseActiveProfiles ($bDisplayEmptyMsg = false)
  243. {
  244. return $this->_serviceBrowse ('active', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  245. }
  246. public function serviceBrowseTopProfiles ($bDisplayEmptyMsg = false)
  247. {
  248. return $this->_serviceBrowse ('top', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  249. }
  250. public function serviceBrowseOnlineProfiles ($bDisplayEmptyMsg = false)
  251. {
  252. return $this->_serviceBrowse ('online', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  253. }
  254. public function serviceBrowseConnections ($iProfileId, $sObjectConnections = 'sys_profiles_friends', $sConnectionsType = 'content', $iMutual = false, $iDesignBox = BX_DB_PADDING_DEF, $iProfileId2 = 0)
  255. {
  256. return $this->_serviceBrowse (
  257. 'connections',
  258. array(
  259. 'object' => $sObjectConnections,
  260. 'type' => $sConnectionsType,
  261. 'mutual' => $iMutual,
  262. 'profile' => (int)$iProfileId,
  263. 'profile2' => (int)$iProfileId2),
  264. $iDesignBox
  265. );
  266. }
  267. public function serviceBrowseConnectionsQuick ($iProfileId, $sObjectConnections = 'sys_profiles_friends', $sConnectionsType = 'content', $iMutual = false, $iProfileId2 = 0)
  268. {
  269. // get connections object
  270. $oConnection = BxDolConnection::getObjectInstance($sObjectConnections);
  271. if (!$oConnection)
  272. return '';
  273. // set some vars
  274. $iLimit = empty($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? 4 : getParam($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']);
  275. if (!$iLimit)
  276. $iLimit = 4;
  277. $iStart = (int)bx_get('start');
  278. // get connections array
  279. bx_import('BxDolConnection');
  280. $a = $oConnection->getConnectionsAsArray ($sConnectionsType, $iProfileId, $iProfileId2, $iMutual, (int)bx_get('start'), $iLimit + 1, BX_CONNECTIONS_ORDER_ADDED_DESC);
  281. if (!$a)
  282. return '';
  283. return $this->_serviceBrowseQuick($a, $iStart, $iLimit);
  284. }
  285. public function serviceBrowseByAcl ($mixedLevelId, $iDesignBox = BX_DB_PADDING_DEF)
  286. {
  287. return $this->_serviceBrowse (
  288. 'acl',
  289. array(
  290. 'level' => $mixedLevelId,
  291. ),
  292. $iDesignBox,
  293. true
  294. );
  295. }
  296. public function serviceEntityEditCover ($iContentId = 0)
  297. {
  298. return $this->_serviceEntityForm ('editDataForm', $iContentId, $this->_oConfig->CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT_COVER']);
  299. }
  300. /**
  301. * Entry comments
  302. */
  303. public function serviceEntityCommentsByProfile ($iProfileId)
  304. {
  305. $CNF = &$this->_oConfig->CNF;
  306. if(empty($CNF['OBJECT_COMMENTS']))
  307. return '';
  308. $oProfile = BxDolProfile::getInstance($iProfileId);
  309. if(!$oProfile)
  310. return '';
  311. return $this->_entityComments($CNF['OBJECT_COMMENTS'], $oProfile->getContentId());
  312. }
  313. /**
  314. * Entry social sharing block
  315. */
  316. public function serviceEntitySocialSharing ($iContentId = 0)
  317. {
  318. $mixedContent = $this->_getContent($iContentId);
  319. if($mixedContent === false)
  320. return false;
  321. list($iContentId, $aContentInfo) = $mixedContent;
  322. $CNF = &$this->_oConfig->CNF;
  323. return $this->_entitySocialSharing ($iContentId, array(
  324. 'id_timeline' => 0,
  325. 'id_thumb' => !empty($CNF['FIELD_PICTURE']) && !empty($aContentInfo[$CNF['FIELD_PICTURE']]) ? $aContentInfo[$CNF['FIELD_PICTURE']] : '',
  326. 'title' => !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  327. 'object_storage' => !empty($CNF['OBJECT_STORAGE']) ? $CNF['OBJECT_STORAGE'] : '',
  328. 'object_transcoder' => false,
  329. 'object_vote' => '',
  330. 'object_favorite' => !empty($CNF['OBJECT_FAVORITES']) ? $CNF['OBJECT_FAVORITES'] : '',
  331. 'object_feature' => !empty($CNF['OBJECT_FEATURED']) ? $CNF['OBJECT_FEATURED'] : '',
  332. 'object_report' => !empty($CNF['OBJECT_REPORTS']) ? $CNF['OBJECT_REPORTS'] : '',
  333. 'uri_view_entry' => !empty($CNF['URI_VIEW_ENTRY']) ? $CNF['URI_VIEW_ENTRY'] : '',
  334. 'social_sharing' => false
  335. ));
  336. }
  337. public function serviceProfileMembership ($iContentId = 0)
  338. {
  339. $mixedContent = $this->_getContent($iContentId);
  340. if($mixedContent === false)
  341. return false;
  342. list($iContentId, $aContentInfo) = $mixedContent;
  343. return BxDolAcl::getInstance()->getProfileMembership($aContentInfo['profile_id']);
  344. }
  345. public function serviceProfileFriends ($iContentId = 0)
  346. {
  347. $mixedContent = $this->_getContent($iContentId);
  348. if($mixedContent === false)
  349. return false;
  350. list($iContentId, $aContentInfo) = $mixedContent;
  351. bx_import('BxDolConnection');
  352. $s = $this->serviceBrowseConnectionsQuick ($aContentInfo['profile_id'], 'sys_profiles_friends', BX_CONNECTIONS_CONTENT_TYPE_CONTENT, true);
  353. if (!$s)
  354. return MsgBox(_t('_sys_txt_empty'));
  355. return $s;
  356. }
  357. public function serviceProfileSubscriptions ($iContentId = 0)
  358. {
  359. $mixedContent = $this->_getContent($iContentId);
  360. if($mixedContent === false)
  361. return false;
  362. list($iContentId, $aContentInfo) = $mixedContent;
  363. bx_import('BxDolConnection');
  364. $s = $this->serviceBrowseConnectionsQuick ($aContentInfo['profile_id'], 'sys_profiles_subscriptions', BX_CONNECTIONS_CONTENT_TYPE_CONTENT);
  365. if (!$s)
  366. return MsgBox(_t('_sys_txt_empty'));
  367. return $s;
  368. }
  369. public function serviceProfileSubscribedMe ($iContentId = 0)
  370. {
  371. $mixedContent = $this->_getContent($iContentId);
  372. if($mixedContent === false)
  373. return false;
  374. list($iContentId, $aContentInfo) = $mixedContent;
  375. bx_import('BxDolConnection');
  376. $s = $this->serviceBrowseConnectionsQuick ($aContentInfo['profile_id'], 'sys_profiles_subscriptions', BX_CONNECTIONS_CONTENT_TYPE_INITIATORS);
  377. if (!$s)
  378. return MsgBox(_t('_sys_txt_empty'));
  379. return $s;
  380. }
  381. /**
  382. * For internal usage only.
  383. */
  384. public function serviceDeleteEntityService ($iContentId, $bDeleteWithContent = false)
  385. {
  386. return parent::serviceDeleteEntity ($iContentId, 'deleteDataService');
  387. }
  388. /**
  389. * Data for Notifications module
  390. */
  391. public function serviceGetNotificationsData()
  392. {
  393. $a = parent::serviceGetNotificationsData();
  394. $sModule = $this->_aModule['name'];
  395. $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');
  396. $a['alerts'][] = array('unit' => $sModule, 'action' => 'timeline_post_common');
  397. return $a;
  398. }
  399. /**
  400. * Notification about new member requst in the group
  401. */
  402. public function serviceGetNotificationsTimelinePostCommon($aEvent)
  403. {
  404. $CNF = &$this->_oConfig->CNF;
  405. $iContentId = (int)$aEvent['object_id'];
  406. $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  407. if(!$oGroupProfile)
  408. return array();
  409. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  410. if(empty($aContentInfo) || !is_array($aContentInfo))
  411. return array();
  412. $aSubcontentInfo = BxDolService::call('bx_timeline', 'get_info', array((int)$aEvent['subobject_id'], false));
  413. if(empty($aSubcontentInfo) || !is_array($aSubcontentInfo))
  414. return array();
  415. $sSubentryUrl = BxDolService::call('bx_timeline', 'get_link', array((int)$aEvent['subobject_id']));
  416. $sSubentrySample = $aSubcontentInfo['title'];
  417. if(empty($sSubentrySample))
  418. $sSubentrySample = strmaxtextlen($aSubcontentInfo['description'], 20, '...');
  419. return array(
  420. 'entry_sample' => $CNF['T']['txt_sample_single'],
  421. 'entry_url' => $oGroupProfile->getUrl(),
  422. 'entry_caption' => $oGroupProfile->getDisplayName(),
  423. 'entry_author' => $oGroupProfile->id(),
  424. 'subentry_sample' => $sSubentrySample,
  425. 'subentry_url' => $sSubentryUrl,
  426. 'lang_key' => $CNF['T']['txt_ntfs_timeline_post_common'],
  427. );
  428. }
  429. public function serviceGetConnectionButtonsTitles($iProfileId, $sConnectionsObject = 'sys_profiles_friends')
  430. {
  431. if (!isLogged())
  432. return array();
  433. if (!($oConn = BxDolConnection::getObjectInstance($sConnectionsObject)))
  434. return array();
  435. $CNF = $this->_oConfig->CNF;
  436. if ($oConn->isConnectedNotMutual(bx_get_logged_profile_id(), $iProfileId)) {
  437. return array(
  438. 'add' => _t($CNF['T']['menu_item_title_befriend_sent']),
  439. 'remove' => _t($CNF['T']['menu_item_title_unfriend_cancel_request']),
  440. );
  441. } elseif ($oConn->isConnectedNotMutual($iProfileId, bx_get_logged_profile_id())) {
  442. return array(
  443. 'add' => _t($CNF['T']['menu_item_title_befriend_confirm']),
  444. 'remove' => _t($CNF['T']['menu_item_title_unfriend_reject_request']),
  445. );
  446. } elseif ($oConn->isConnected($iProfileId, bx_get_logged_profile_id(), true)) {
  447. return array(
  448. 'add' => '',
  449. 'remove' => _t($CNF['T']['menu_item_title_unfriend']),
  450. );
  451. } else {
  452. return array(
  453. 'add' => _t($CNF['T']['menu_item_title_befriend']),
  454. 'remove' => '',
  455. );
  456. }
  457. }
  458. // ====== PERMISSION METHODS
  459. /**
  460. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  461. */
  462. public function checkAllowedAdd ($isPerformAction = false)
  463. {
  464. $oAccount = BxDolAccount::getInstance();
  465. if (!$oAccount || ($this->serviceActAsProfile() && $oAccount->isProfilesLimitReached()))
  466. return _t('_sys_txt_access_denied');
  467. return parent::checkAllowedAdd ($isPerformAction);
  468. }
  469. /**
  470. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  471. */
  472. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  473. {
  474. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  475. if ($oProfile && $oProfile->id() == $this->_iProfileId)
  476. return CHECK_ACTION_RESULT_ALLOWED;
  477. return parent::checkAllowedView ($aDataEntry, $isPerformAction);
  478. }
  479. /**
  480. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  481. */
  482. public function checkAllowedViewProfileImage ($aDataEntry, $isPerformAction = false)
  483. {
  484. $CNF = &$this->_oConfig->CNF;
  485. // check privacy
  486. if (empty($CNF['OBJECT_PRIVACY_VIEW']))
  487. return CHECK_ACTION_RESULT_ALLOWED;
  488. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  489. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']]) && !$oPrivacy->isPartiallyVisible($aDataEntry[$CNF['FIELD_ALLOW_VIEW_TO']]))
  490. return _t('_sys_access_denied_to_private_content');
  491. return CHECK_ACTION_RESULT_ALLOWED;
  492. }
  493. /**
  494. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  495. */
  496. public function checkAllowedViewCoverImage ($aDataEntry, $isPerformAction = false)
  497. {
  498. return $this->checkAllowedViewProfileImage($aDataEntry);
  499. }
  500. /**
  501. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  502. */
  503. public function checkAllowedPost ($aDataEntry, $isPerformAction = false)
  504. {
  505. return $this->checkAllowedView ($aDataEntry, $isPerformAction);
  506. }
  507. /**
  508. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  509. */
  510. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  511. {
  512. // moderator always has access
  513. if ($this->_isModerator($isPerformAction))
  514. return CHECK_ACTION_RESULT_ALLOWED;
  515. // owner (checked by account! not as profile as ususal) always have access
  516. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name']);
  517. if (!$oProfile)
  518. return _t('_sys_txt_error_occured');
  519. if ($oProfile->getAccountId() == $this->_iAccountId)
  520. return CHECK_ACTION_RESULT_ALLOWED;
  521. return _t('_sys_txt_access_denied');
  522. }
  523. /**
  524. * Check if user can change cover image
  525. */
  526. public function checkAllowedChangeCover ($aDataEntry, $isPerformAction = false)
  527. {
  528. // moderator always has access
  529. if ($this->_isModerator($isPerformAction))
  530. return CHECK_ACTION_RESULT_ALLOWED;
  531. // owner (checked by account! not as profile as ususal) always have access
  532. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name']);
  533. if (!$oProfile)
  534. return _t('_sys_txt_error_occured');
  535. if ($oProfile->getAccountId() == $this->_iAccountId)
  536. return CHECK_ACTION_RESULT_ALLOWED;
  537. return _t('_sys_txt_access_denied');
  538. }
  539. /**
  540. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  541. */
  542. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  543. {
  544. // moderator always has access
  545. if ($this->_isModerator($isPerformAction))
  546. return CHECK_ACTION_RESULT_ALLOWED;
  547. // check ACL and owner (checked by account! not as profile as ususal)
  548. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  549. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name'], $isPerformAction);
  550. if (!$oProfile)
  551. return _t('_sys_txt_error_occured');
  552. if ($oProfile->getAccountId() == $this->_iAccountId && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  553. return CHECK_ACTION_RESULT_ALLOWED;
  554. return _t('_sys_txt_access_denied');
  555. }
  556. /**
  557. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  558. */
  559. public function checkAllowedViewMoreMenu (&$aDataEntry, $isPerformAction = false)
  560. {
  561. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']);
  562. if (!$oMenu || !$oMenu->getCode())
  563. return _t('_sys_txt_access_denied');
  564. return CHECK_ACTION_RESULT_ALLOWED;
  565. }
  566. /**
  567. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  568. */
  569. public function checkAllowedCompose (&$aDataEntry, $isPerformAction = false)
  570. {
  571. $CNF = &$this->_oConfig->CNF;
  572. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->getName());
  573. if($oProfile && $oProfile->id() == $this->_iProfileId)
  574. return _t('_sys_txt_access_denied');
  575. return $this->checkAllowedView ($aDataEntry, $isPerformAction);
  576. }
  577. /**
  578. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  579. */
  580. public function checkAllowedFriendAdd (&$aDataEntry, $isPerformAction = false)
  581. {
  582. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', true, false);
  583. }
  584. /**
  585. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  586. */
  587. public function checkAllowedFriendRemove (&$aDataEntry, $isPerformAction = false)
  588. {
  589. if (CHECK_ACTION_RESULT_ALLOWED === $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', false, true, true))
  590. return CHECK_ACTION_RESULT_ALLOWED;
  591. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', false, true, false);
  592. }
  593. /**
  594. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  595. */
  596. public function checkAllowedSubscribeAdd (&$aDataEntry, $isPerformAction = false)
  597. {
  598. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedView($aDataEntry)))
  599. return $sMsg;
  600. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_subscriptions', false, false);
  601. }
  602. /**
  603. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  604. */
  605. public function checkAllowedSubscribeRemove (&$aDataEntry, $isPerformAction = false)
  606. {
  607. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_subscriptions', false, true);
  608. }
  609. public function checkAllowedSubscriptionsView (&$aDataEntry, $isPerformAction = false)
  610. {
  611. $CNF = &$this->_oConfig->CNF;
  612. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->_aModule['name']);
  613. if(!$oProfile || ($oProfile->id() != $this->_iProfileId && $this->_oDb->getParam($CNF['PARAM_PUBLIC_SBSN']) != 'on' && $this->_oDb->getParam($CNF['PARAM_PUBLIC_SBSD']) != 'on'))
  614. return _t('_sys_txt_access_denied');
  615. return CHECK_ACTION_RESULT_ALLOWED;
  616. }
  617. public function checkMyself($iContentId)
  618. {
  619. $iLogged = (int)bx_get_logged_profile_id();
  620. if(empty($iLogged))
  621. return false;
  622. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->_oConfig->getName());
  623. if(!$oProfile)
  624. return false;
  625. return $oProfile->id() == $iLogged;
  626. }
  627. // ====== PROTECTED METHODS
  628. protected function _checkAllowedConnect (&$aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap = false)
  629. {
  630. if (!$this->_iProfileId)
  631. return _t('_sys_txt_access_denied');
  632. $CNF = &$this->_oConfig->CNF;
  633. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->_aModule['name']);
  634. if (!$oProfile || $oProfile->id() == $this->_iProfileId)
  635. return _t('_sys_txt_access_denied');
  636. // check ACL
  637. $aCheck = checkActionModule($this->_iProfileId, 'connect', 'system', $isPerformAction);
  638. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  639. return $aCheck[CHECK_ACTION_MESSAGE];
  640. $oConn = BxDolConnection::getObjectInstance($sObjConnection);
  641. if ($isSwap)
  642. $isConnected = $oConn->isConnected($oProfile->id(), $this->_iProfileId, $isMutual);
  643. else
  644. $isConnected = $oConn->isConnected($this->_iProfileId, $oProfile->id(), $isMutual);
  645. if ($isInvertResult)
  646. $isConnected = !$isConnected;
  647. return $isConnected ? _t('_sys_txt_access_denied') : CHECK_ACTION_RESULT_ALLOWED;
  648. }
  649. protected function _buildRssParams($sMode, $aArgs)
  650. {
  651. $aParams = array ();
  652. $sMode = bx_process_input($sMode);
  653. switch ($sMode) {
  654. case 'connections':
  655. $aParams = array(
  656. 'object' => isset($aArgs[0]) ? $aArgs[0] : '',
  657. 'type' => isset($aArgs[1]) ? $aArgs[1] : '',
  658. 'profile' => isset($aArgs[2]) ? (int)$aArgs[2] : 0,
  659. 'mutual' => isset($aArgs[3]) ? (int)$aArgs[3] : 0,
  660. 'profile2' => isset($aArgs[4]) ? (int)$aArgs[4] : 0,
  661. );
  662. break;
  663. }
  664. return $aParams;
  665. }
  666. protected function _serviceBrowseQuick($aProfiles, $iStart = 0, $iLimit = 4)
  667. {
  668. // get paginate object
  669. $oPaginate = new BxTemplPaginate(array(
  670. 'on_change_page' => "return !loadDynamicBlockAutoPaginate(this, '{start}', '{per_page}');",
  671. 'num' => count($aProfiles),
  672. 'per_page' => $iLimit,
  673. 'start' => $iStart,
  674. ));
  675. // remove last item from connection array, because we've got one more item for pagination calculations only
  676. if (count($aProfiles) > $iLimit)
  677. array_pop($aProfiles);
  678. // get profiles HTML
  679. $s = '';
  680. foreach ($aProfiles as $iProfileId) {
  681. $oProfile = BxDolProfile::getInstance($iProfileId);
  682. if(!$oProfile)
  683. continue;
  684. $s .= $oProfile->getUnit();
  685. }
  686. // return profiles + paginate
  687. return $s . (!$iStart && $oPaginate->getNum() <= $iLimit ? '' : $oPaginate->getSimplePaginate());
  688. }
  689. protected function _entityComments($sObject, $iId = 0)
  690. {
  691. if(!$iId)
  692. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  693. if(!$iId)
  694. $iId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  695. if(!$iId)
  696. return false;
  697. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  698. if(!$oCmts || !$oCmts->isEnabled())
  699. return false;
  700. return $oCmts->getCommentsBlock(array(), array('in_designbox' => false));
  701. }
  702. protected function _getContent($iContentId = 0, $sFuncGetContent = 'getContentInfoById')
  703. {
  704. if(!$iContentId && bx_get('id') === false && bx_get('profile_id') !== false) {
  705. $oProfile = BxDolProfile::getInstance((int)bx_get('profile_id'));
  706. if($oProfile)
  707. $iContentId = $oProfile->getContentId();
  708. }
  709. return parent::_getContent($iContentId, $sFuncGetContent);
  710. }
  711. }
  712. /** @} */