1
0

BxBaseModProfileModule.php 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242
  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 serviceGetSearchableFieldsExtended()
  70. {
  71. $CNF = &$this->_oConfig->CNF;
  72. $aResult = parent::serviceGetSearchableFieldsExtended();
  73. if(!$this->serviceActAsProfile())
  74. return $aResult;
  75. if(!in_array('online', $this->_aSearchableNamesExcept))
  76. $aResult['online'] = array(
  77. 'type' => 'checkbox',
  78. 'caption' => $CNF['T']['form_field_online'],
  79. 'info' => '',
  80. 'value' => '1',
  81. 'values' => '',
  82. 'pass' => ''
  83. );
  84. if(!empty($CNF['FIELD_PICTURE']) && !in_array($CNF['FIELD_PICTURE'], $this->_aSearchableNamesExcept))
  85. $aResult[$CNF['FIELD_PICTURE']] = array(
  86. 'type' => 'checkbox',
  87. 'caption' => $CNF['T']['form_field_picture'],
  88. 'info' => '',
  89. 'value' => '1',
  90. 'values' => '',
  91. 'pass' => '',
  92. 'search_operator' => '>='
  93. );
  94. return $aResult;
  95. }
  96. public function servicePrivateProfileMsg()
  97. {
  98. $mixedContent = $this->_getContent();
  99. if ($mixedContent) {
  100. list($iContentId, $aContentInfo) = $mixedContent;
  101. return $this->checkAllowedView($aContentInfo);
  102. }
  103. return MsgBox(_t('_sys_access_denied_to_private_content'));
  104. }
  105. public function serviceGetContentInfoById($iContentId)
  106. {
  107. return $this->_oDb->getContentInfoById((int)$iContentId);
  108. }
  109. public function serviceGetMenuAddonManageTools()
  110. {
  111. bx_import('SearchResult', $this->_aModule);
  112. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  113. $o = new $sClass();
  114. $o->fillFilters(array(
  115. 'perofileStatus' => BX_PROFILE_STATUS_PENDING
  116. ));
  117. $o->unsetPaginate();
  118. return $o->getNum();
  119. }
  120. public function serviceGetMenuAddonManageToolsProfileStats()
  121. {
  122. bx_import('SearchResult', $this->_aModule);
  123. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  124. $o = new $sClass();
  125. $o->fillFilters(array(
  126. 'account_id' => getLoggedId(),
  127. 'perofileStatus' => ''
  128. ));
  129. $o->unsetPaginate();
  130. return $o->getNum();
  131. }
  132. public function serviceGetMenuAddonFavoritesProfileStats()
  133. {
  134. bx_import('SearchResult', $this->_aModule);
  135. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  136. $o = new $sClass('favorite', array('user' => bx_get_logged_profile_id()));
  137. $o->unsetPaginate();
  138. return $o->getNum();
  139. }
  140. public function serviceGetSubmenuObject ()
  141. {
  142. return $this->_oConfig->CNF['OBJECT_MENU_SUBMENU_VIEW_ENTRY'];
  143. }
  144. public function serviceGetMenuSetNameForMenuTrigger ($sMenuTriggerName)
  145. {
  146. $CNF = &$this->_oConfig->CNF;
  147. if ($CNF['TRIGGER_MENU_PROFILE_VIEW_SUBMENU'] == $sMenuTriggerName)
  148. return $CNF['OBJECT_MENU_SUBMENU_VIEW_ENTRY'];
  149. else if ($CNF['TRIGGER_MENU_PROFILE_VIEW_ACTIONS'] == $sMenuTriggerName) {
  150. if(empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL']))
  151. return $CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY'];
  152. else
  153. return array($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY'], $CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL']);
  154. }
  155. return '';
  156. }
  157. public function serviceGetSnippetMenuVars($iProfileId, $bPublic = null)
  158. {
  159. return $this->_oTemplate->getSnippetMenuVars($iProfileId, $bPublic);
  160. }
  161. public function serviceGetPageObjectForPageTrigger ($sPageTriggerName)
  162. {
  163. if (isset($this->_oConfig->CNF['TRIGGER_PAGE_VIEW_ENTRY']) && $this->_oConfig->CNF['TRIGGER_PAGE_VIEW_ENTRY'] == $sPageTriggerName)
  164. return $this->_oConfig->CNF['OBJECT_PAGE_VIEW_ENTRY'];
  165. return '';
  166. }
  167. public function serviceProfilesSearch ($sTerm, $iLimit)
  168. {
  169. $aRet = array();
  170. $a = $this->_oDb->searchByTerm($sTerm, $iLimit);
  171. foreach ($a as $r) {
  172. $oProfile = BxDolProfile::getInstance($r['profile_id']);
  173. $aRet[] = array (
  174. 'label' => $this->serviceProfileName($r['content_id']),
  175. 'value' => $r['profile_id'],
  176. 'url' => $oProfile->getUrl(),
  177. 'thumb' => $oProfile->getThumb(),
  178. 'unit' => $oProfile->getUnit(0, array('template' => 'unit_wo_info'))
  179. );
  180. }
  181. return $aRet;
  182. }
  183. public function serviceProfileUnit ($iContentId, $aParams = array())
  184. {
  185. $mixedContent = $this->_getContent($iContentId);
  186. if($mixedContent === false)
  187. return false;
  188. list($iContentId, $aContentInfo) = $mixedContent;
  189. $bCheckPrivateContent = isset($aParams['check_private_content']) ? (bool)$aParams['check_private_content'] : true;
  190. $sTemplate = (!empty($aParams['template']) ? $aParams['template'] : 'unit') . '.html';
  191. return $this->_oTemplate->unit($aContentInfo, $bCheckPrivateContent, $sTemplate);
  192. }
  193. public function serviceHasImage ($iContentId)
  194. {
  195. $CNF = &$this->_oConfig->CNF;
  196. $mixedContent = $this->_getContent($iContentId, 'getContentInfoById');
  197. if($mixedContent === false)
  198. return false;
  199. list($iContentId, $aContentInfo) = $mixedContent;
  200. return !empty($aContentInfo[$CNF['FIELD_PICTURE']]);
  201. }
  202. public function serviceProfilePicture ($iContentId)
  203. {
  204. return $this->_serviceTemplateFunc('urlPicture', $iContentId);
  205. }
  206. public function serviceProfileAvatar ($iContentId)
  207. {
  208. return $this->_serviceTemplateFunc('urlAvatar', $iContentId);
  209. }
  210. public function serviceProfileCover ($iContentId)
  211. {
  212. return $this->_serviceTemplateFunc('urlCover', $iContentId);
  213. }
  214. public function serviceProfileUnitCover ($iContentId)
  215. {
  216. return $this->_serviceTemplateFunc('urlCoverUnit', $iContentId);
  217. }
  218. public function serviceProfileEditUrl ($iContentId)
  219. {
  220. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $this->_oConfig->CNF['URI_EDIT_ENTRY'] . '&id=' . $iContentId);
  221. }
  222. public function serviceProfileThumb ($iContentId)
  223. {
  224. return $this->_serviceTemplateFunc('thumb', $iContentId);
  225. }
  226. public function serviceProfileIcon ($iContentId)
  227. {
  228. return $this->_serviceTemplateFunc('icon', $iContentId);
  229. }
  230. public function serviceProfileName ($iContentId)
  231. {
  232. if (!$iContentId)
  233. return false;
  234. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  235. if (!$aContentInfo)
  236. return false;
  237. return bx_process_output($aContentInfo[$this->_oConfig->CNF['FIELD_NAME']]);
  238. }
  239. public function serviceProfileCreateUrl ($bAbsolute = true)
  240. {
  241. $CNF = $this->_oConfig->CNF;
  242. if(empty($CNF['URL_CREATE']))
  243. return false;
  244. return $bAbsolute ? BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_CREATE']) : $CNF['URL_CREATE'];
  245. }
  246. public function serviceProfileUrl ($iContentId)
  247. {
  248. if (!$iContentId)
  249. return false;
  250. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  251. if (!$aContentInfo)
  252. return false;
  253. $CNF = $this->_oConfig->CNF;
  254. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  255. }
  256. /**
  257. * @see iBxDolProfileService::serviceGetSpaceTitle
  258. */
  259. public function serviceGetSpaceTitle()
  260. {
  261. return _t('_sys_ps_space_title_friend');
  262. }
  263. /**
  264. * @see iBxDolProfileService::serviceGetParticipatingProfiles
  265. */
  266. public function serviceGetParticipatingProfiles($iProfileId, $aConnectionObjects = false)
  267. {
  268. if (false === $aConnectionObjects)
  269. $aConnectionObjects = array('sys_profiles_friends');
  270. $a = array();
  271. foreach ($aConnectionObjects as $sConnectionObject) {
  272. if (!($o = BxDolConnection::getObjectInstance($sConnectionObject)))
  273. continue;
  274. if (BX_CONNECTIONS_TYPE_MUTUAL == $o->getType())
  275. $a = array_merge($a, $o->getConnectedContent($iProfileId, true));
  276. else
  277. $a = array_merge($a, $o->getConnectedContent($iProfileId));
  278. }
  279. $a = array_unique($a);
  280. $aRet = array();
  281. foreach ($a as $iConnectedProfileId) {
  282. if (!($oConnectedProfile = BxDolProfile::getInstance($iConnectedProfileId)))
  283. continue;
  284. if ($oConnectedProfile->getModule() != $this->getName())
  285. continue;
  286. if (CHECK_ACTION_RESULT_ALLOWED === bx_srv($oConnectedProfile->getModule(), 'check_allowed_post_in_profile', array($oConnectedProfile->getContentId(), $iProfileId)))
  287. $aRet[] = $iConnectedProfileId;
  288. }
  289. return $aRet;
  290. }
  291. /**
  292. * @see iBxDolProfileService::serviceCheckSpacePrivacy
  293. */
  294. public function serviceCheckSpacePrivacy($iContentId)
  295. {
  296. return $this->serviceCheckAllowedProfileView($iContentId);
  297. }
  298. /**
  299. * @see iBxDolProfileService::serviceCheckAllowedProfileView
  300. */
  301. public function serviceCheckAllowedProfileView($iContentId)
  302. {
  303. return $this->serviceCheckAllowedWithContent('View', $iContentId);
  304. }
  305. /**
  306. * @see iBxDolProfileService::serviceCheckAllowedPostInProfile
  307. */
  308. public function serviceCheckAllowedPostInProfile($iContentId, $iProfileIdPoster = false)
  309. {
  310. if (!$iContentId || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)))
  311. return _t('_sys_request_page_not_found_cpt');
  312. return $this->serviceCheckAllowedViewForProfile($aContentInfo, false, $iProfileIdPoster);
  313. }
  314. /**
  315. * Prepare fields from some universal set of fields to fields in particular profile module.
  316. * By default only 'name' and 'description' fields are supported.
  317. * After fields convertion it can be used in @see BxBaseModGeneralModule::serviceEntityAdd
  318. * @param $aFieldsProfile fields in soem universal format.
  319. * @return array which is ready to use for particular module
  320. */
  321. public function servicePrepareFields ($aFieldsProfile)
  322. {
  323. bx_alert($this->getName(), 'prepare_fields', 0, 0, array('fields_orig' => $aFieldsProfile, 'fields_result' => &$aFieldsProfile));
  324. return $aFieldsProfile;
  325. }
  326. protected function _servicePrepareFields ($aFieldsProfile, $aFieldsDefault, $aMap)
  327. {
  328. $aFieldsOrig = $aFieldsProfile;
  329. bx_import('BxDolPrivacy');
  330. $aFieldsDefault2 = array(
  331. 'allow_view_to' => BX_DOL_PG_ALL,
  332. );
  333. $aFieldsProfile = array_merge($aFieldsDefault2, $aFieldsDefault, $aFieldsProfile);
  334. foreach ($aMap as $k => $v) {
  335. if (isset($aFieldsProfile[$v]))
  336. $aFieldsProfile[$k] = $aFieldsProfile[$v];
  337. if ($k != $v && !isset($aMap[$v]))
  338. unset($aFieldsProfile[$v]);
  339. }
  340. bx_alert($this->getName(), 'prepare_fields', 0, 0, array('fields_orig' => $aFieldsOrig, 'fields_result' => &$aFieldsProfile));
  341. return $aFieldsProfile;
  342. }
  343. public function serviceFormsHelper ()
  344. {
  345. return parent::serviceFormsHelper ();
  346. }
  347. public function serviceEntityCreate ($sDisplay = false)
  348. {
  349. BxDolInformer::getInstance($this->_oTemplate)->setEnabled(false);
  350. return parent::serviceEntityCreate ($sDisplay);
  351. }
  352. public function serviceActAsProfile ()
  353. {
  354. return true;
  355. }
  356. public function serviceBrowseRecommended ($sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = true)
  357. {
  358. if (!isLogged())
  359. return '';
  360. return $this->_serviceBrowse ('recommended', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  361. }
  362. public function serviceBrowseRecentProfiles ($bDisplayEmptyMsg = false)
  363. {
  364. return $this->_serviceBrowse ('recent', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  365. }
  366. public function serviceBrowseActiveProfiles ($sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = true)
  367. {
  368. return $this->_serviceBrowse ('active', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  369. }
  370. public function serviceBrowseTopProfiles ($bDisplayEmptyMsg = false)
  371. {
  372. return $this->_serviceBrowse ('top', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  373. }
  374. public function serviceBrowseOnlineProfiles ($bDisplayEmptyMsg = false)
  375. {
  376. return $this->_serviceBrowse ('online', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  377. }
  378. public function serviceBrowseConnections ($iProfileId, $sObjectConnections = 'sys_profiles_friends', $sConnectionsType = 'content', $iMutual = false, $iDesignBox = BX_DB_PADDING_DEF, $iProfileId2 = 0)
  379. {
  380. return $this->_serviceBrowse (
  381. 'connections',
  382. array(
  383. 'object' => $sObjectConnections,
  384. 'type' => $sConnectionsType,
  385. 'mutual' => $iMutual,
  386. 'profile' => (int)$iProfileId,
  387. 'profile2' => (int)$iProfileId2),
  388. $iDesignBox
  389. );
  390. }
  391. public function serviceBrowseConnectionsQuick ($iProfileId, $sObjectConnections = 'sys_profiles_friends', $sConnectionsType = 'content', $iMutual = false, $iProfileId2 = 0)
  392. {
  393. // get connections object
  394. $oConnection = BxDolConnection::getObjectInstance($sObjectConnections);
  395. if (!$oConnection)
  396. return '';
  397. // set some vars
  398. $iLimit = empty($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? 4 : getParam($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']);
  399. if (!$iLimit)
  400. $iLimit = 4;
  401. $iStart = (int)bx_get('start');
  402. // get connections array
  403. bx_import('BxDolConnection');
  404. $a = $oConnection->getConnectionsAsArray ($sConnectionsType, $iProfileId, $iProfileId2, $iMutual, (int)bx_get('start'), $iLimit + 1, BX_CONNECTIONS_ORDER_ADDED_DESC);
  405. if (!$a)
  406. return '';
  407. return $this->_serviceBrowseQuick($a, $iStart, $iLimit);
  408. }
  409. public function serviceBrowseConnectionsByType ($aParamsCnn, $aParamsBrs = array())
  410. {
  411. $sAll = 'all';
  412. $aParamsCnn['object'] = !empty($aParamsCnn['object']) ? $aParamsCnn['object'] : 'sys_profiles_friends';
  413. $aParamsCnn['type'] = !empty($aParamsCnn['type']) ? $aParamsCnn['type'] : 'content';
  414. $aParamsCnn['profile_id2'] = !empty($aParamsCnn['profile_id2']) ? (int)$aParamsCnn['profile_id2'] : 0;
  415. $aParamsCnn['mutual'] = isset($aParamsCnn['mutual']) ? $aParamsCnn['mutual'] : false;
  416. $oConnection = BxDolConnection::getObjectInstance($aParamsCnn['object']);
  417. if(!$oConnection)
  418. return '';
  419. $aSQLParts = $oConnection->getConnectionsAsSQLParts ($aParamsCnn['type'], 'sys_profiles', 'id', $aParamsCnn['profile_id'], $aParamsCnn['profile_id2'], $aParamsCnn['mutual']);
  420. $sType = !empty($aParamsBrs['type']) ? $aParamsBrs['type'] : $sAll;
  421. if(bx_get('type') !== false)
  422. $sType = bx_process_input(bx_get('type'));
  423. $iStart = (int)bx_get('start');
  424. $iLimitDefault = 4;
  425. $iLimit = !empty($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? getParam($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) : $iLimitDefault;
  426. if(!empty($aParamsBrs['per_page']))
  427. $iLimit = (int)$aParamsBrs['per_page'];
  428. if(!$iLimit)
  429. $iLimit = $iLimitDefault;
  430. $aProfiles = BxDolProfileQuery::getInstance()->getConnectedProfilesByType($aSQLParts, ($sType != $sAll ? $sType : ''), $iStart, $iLimit + 1);
  431. $mixedMenu = '';
  432. if(!isset($aParamsBrs['filter_menu']) || $aParamsBrs['filter_menu'] === true) {
  433. $aModules = array(
  434. array('name' => $sAll)
  435. );
  436. $aModules = array_merge($aModules, BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1)));
  437. $aMenuItems = array();
  438. foreach($aModules as $aModule)
  439. if($aModule['name'] == $sAll || BxDolRequest::serviceExists($aModule['name'], 'act_as_profile'))
  440. $aMenuItems[] = array(
  441. 'id' => $aModule['name'],
  442. 'name' => $aModule['name'],
  443. 'class' => '',
  444. 'link' => 'javascript:void(0)',
  445. 'onclick' => "return !loadDynamicBlockAutoPaginate(this, " . $iStart . ", " . $iLimit . ", " . bx_js_string(json_encode(array('type' => $aModule['name']))) . ");",
  446. 'target' => '_self',
  447. 'title' => _t('_' . $aModule['name']),
  448. 'active' => 1
  449. );
  450. if(!empty($aMenuItems)) {
  451. $mixedMenu = new BxTemplMenu(array('template' => 'menu_vertical.html', 'menu_id'=> $this->_oConfig->getName() . '-connections-by-type', 'menu_items' => $aMenuItems));
  452. $mixedMenu->setSelected('', $sType);
  453. }
  454. }
  455. return array(
  456. 'menu' => $mixedMenu,
  457. 'content' => $this->_serviceBrowseQuick(array_keys($aProfiles), $iStart, $iLimit, array('type' => $sType))
  458. );
  459. }
  460. public function serviceBrowseByAcl ($mixedLevelId, $iDesignBox = BX_DB_PADDING_DEF)
  461. {
  462. return $this->_serviceBrowse (
  463. 'acl',
  464. array(
  465. 'level' => $mixedLevelId,
  466. ),
  467. $iDesignBox,
  468. true
  469. );
  470. }
  471. public function serviceEntityEditCover ($iContentId = 0)
  472. {
  473. return $this->_serviceEntityForm ('editDataForm', $iContentId, $this->_oConfig->CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT_COVER']);
  474. }
  475. /**
  476. * Entry comments
  477. */
  478. public function serviceEntityCommentsByProfile ($iProfileId)
  479. {
  480. $CNF = &$this->_oConfig->CNF;
  481. if(empty($CNF['OBJECT_COMMENTS']))
  482. return '';
  483. $oProfile = BxDolProfile::getInstance($iProfileId);
  484. if(!$oProfile)
  485. return '';
  486. return $this->_entityComments($CNF['OBJECT_COMMENTS'], $oProfile->getContentId());
  487. }
  488. /**
  489. * Entry social sharing block
  490. */
  491. public function serviceEntitySocialSharing ($mixedContent = false, $aParams = array())
  492. {
  493. if(!empty($mixedContent)) {
  494. if(!is_array($mixedContent))
  495. $mixedContent = array((int)$mixedContent, array());
  496. }
  497. else {
  498. $mixedContent = $this->_getContent();
  499. if($mixedContent === false)
  500. return false;
  501. }
  502. list($iContentId, $aContentInfo) = $mixedContent;
  503. return parent::serviceEntitySocialSharing(array($iContentId, $aContentInfo), array(
  504. 'id_thumb' => !empty($CNF['FIELD_PICTURE']) && !empty($aContentInfo[$CNF['FIELD_PICTURE']]) ? $aContentInfo[$CNF['FIELD_PICTURE']] : 0,
  505. ));
  506. }
  507. public function serviceProfileMembership ($iContentId = 0)
  508. {
  509. $mixedContent = $this->_getContent($iContentId);
  510. if($mixedContent === false)
  511. return false;
  512. list($iContentId, $aContentInfo) = $mixedContent;
  513. return BxDolAcl::getInstance()->getProfileMembership($aContentInfo['profile_id']);
  514. }
  515. public function serviceProfileFriends ($iContentId = 0)
  516. {
  517. $mixedContent = $this->_getContent($iContentId);
  518. if($mixedContent === false)
  519. return false;
  520. list($iContentId, $aContentInfo) = $mixedContent;
  521. bx_import('BxDolConnection');
  522. $s = $this->serviceBrowseConnectionsQuick ($aContentInfo['profile_id'], 'sys_profiles_friends', BX_CONNECTIONS_CONTENT_TYPE_CONTENT, true);
  523. if (!$s)
  524. return MsgBox(_t('_sys_txt_empty'));
  525. return $s;
  526. }
  527. public function serviceProfileSubscriptions ($iContentId = 0, $aParams = array())
  528. {
  529. $mixedContent = $this->_getContent($iContentId);
  530. if($mixedContent === false)
  531. return false;
  532. list($iContentId, $aContentInfo) = $mixedContent;
  533. bx_import('BxDolConnection');
  534. $aResult = $this->serviceBrowseConnectionsByType(array(
  535. 'profile_id' => $aContentInfo['profile_id'],
  536. 'object' => 'sys_profiles_subscriptions',
  537. 'type' => BX_CONNECTIONS_CONTENT_TYPE_CONTENT
  538. ), array(
  539. 'type' => isset($aParams['type']) ? $aParams['type'] : '',
  540. 'filter_menu' => isset($aParams['filter_menu']) ? $aParams['filter_menu'] : true,
  541. ));
  542. if(empty($aResult['content']))
  543. $aResult['content'] = MsgBox(_t('_sys_txt_empty'));
  544. return $aResult;
  545. }
  546. public function serviceProfileSubscribedMe ($iContentId = 0)
  547. {
  548. $mixedContent = $this->_getContent($iContentId);
  549. if($mixedContent === false)
  550. return false;
  551. list($iContentId, $aContentInfo) = $mixedContent;
  552. bx_import('BxDolConnection');
  553. $s = $this->serviceBrowseConnectionsQuick ($aContentInfo['profile_id'], 'sys_profiles_subscriptions', BX_CONNECTIONS_CONTENT_TYPE_INITIATORS);
  554. if (!$s)
  555. return MsgBox(_t('_sys_txt_empty'));
  556. return $s;
  557. }
  558. /**
  559. * check enabled profile activation letter
  560. */
  561. public function serviceIsEnableProfileActivationLetter()
  562. {
  563. $CNF = &$this->_oConfig->CNF;
  564. return isset($CNF['PARAM_ENABLE_ACTIVATION_LETTER']) ? (bool)getParam($CNF['PARAM_ENABLE_ACTIVATION_LETTER']) : true;
  565. }
  566. /**
  567. * For internal usage only.
  568. */
  569. public function serviceDeleteEntityService ($iContentId, $bDeleteWithContent = false)
  570. {
  571. return parent::serviceDeleteEntity ($iContentId, 'deleteDataService');
  572. }
  573. /**
  574. * Data for Notifications module
  575. */
  576. public function serviceGetNotificationsData()
  577. {
  578. $a = parent::serviceGetNotificationsData();
  579. $sModule = $this->_aModule['name'];
  580. $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');
  581. $a['settings'][] = array('group' => 'timeline_post', 'unit' => $sModule, 'action' => 'timeline_post_common', 'types' => array('follow_member'));
  582. $a['alerts'][] = array('unit' => $sModule, 'action' => 'timeline_post_common');
  583. return $a;
  584. }
  585. /**
  586. * Notification about new member requst in the group
  587. */
  588. public function serviceGetNotificationsTimelinePostCommon($aEvent)
  589. {
  590. $CNF = &$this->_oConfig->CNF;
  591. $iContentId = (int)$aEvent['object_id'];
  592. $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  593. if(!$oGroupProfile)
  594. return array();
  595. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  596. if(empty($aContentInfo) || !is_array($aContentInfo))
  597. return array();
  598. $aSubcontentInfo = BxDolService::call('bx_timeline', 'get_info', array((int)$aEvent['subobject_id'], false));
  599. if(empty($aSubcontentInfo) || !is_array($aSubcontentInfo))
  600. return array();
  601. $sSubentryUrl = BxDolService::call('bx_timeline', 'get_link', array((int)$aEvent['subobject_id']));
  602. $sSubentrySample = $aSubcontentInfo['title'];
  603. if(empty($sSubentrySample))
  604. $sSubentrySample = strmaxtextlen($aSubcontentInfo['description'], 20, '...');
  605. return array(
  606. 'entry_sample' => $CNF['T']['txt_sample_single'],
  607. 'entry_url' => $oGroupProfile->getUrl(),
  608. 'entry_caption' => $oGroupProfile->getDisplayName(),
  609. 'entry_author' => $oGroupProfile->id(),
  610. 'subentry_sample' => $sSubentrySample,
  611. 'subentry_url' => $sSubentryUrl,
  612. 'lang_key' => $CNF['T']['txt_ntfs_timeline_post_common'],
  613. );
  614. }
  615. /**
  616. * Data for Timeline module
  617. */
  618. public function serviceGetTimelineData()
  619. {
  620. $CNF = &$this->_oConfig->CNF;
  621. $sModule = $this->_aModule['name'];
  622. $aAlerts = array();
  623. $aHandlers = array();
  624. if(!empty($CNF['FIELD_PICTURE'])) {
  625. $aAlerts = array_merge($aAlerts, array(
  626. array('unit' => $sModule, 'action' => 'profile_picture_changed'),
  627. array('unit' => $sModule, 'action' => 'profile_picture_deleted')
  628. ));
  629. $aHandlers = array_merge($aHandlers, array(
  630. array('group' => $sModule . '_profile_picture', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'profile_picture_changed', 'module_name' => $sModule, 'module_method' => 'get_timeline_profile_picture', 'module_class' => 'Module', 'groupable' => 0, 'group_by' => ''),
  631. array('group' => $sModule . '_profile_picture', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'profile_picture_deleted')
  632. ));
  633. }
  634. if(!empty($CNF['FIELD_COVER'])) {
  635. $aAlerts = array_merge($aAlerts, array(
  636. array('unit' => $sModule, 'action' => 'profile_cover_changed'),
  637. array('unit' => $sModule, 'action' => 'profile_cover_deleted')
  638. ));
  639. $aHandlers = array_merge($aHandlers, array(
  640. array('group' => $sModule . '_profile_cover', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'profile_cover_changed', 'module_name' => $sModule, 'module_method' => 'get_timeline_profile_cover', 'module_class' => 'Module', 'groupable' => 0, 'group_by' => ''),
  641. array('group' => $sModule . '_profile_cover', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'profile_cover_deleted')
  642. ));
  643. }
  644. $aResult = array();
  645. if(!empty($aAlerts) && !empty($aHandlers))
  646. $aResult = array(
  647. 'handlers' => $aHandlers,
  648. 'alerts' => $aAlerts
  649. );
  650. return $aResult;
  651. }
  652. /**
  653. * Entry post for Timeline module
  654. */
  655. public function serviceGetTimelineProfilePicture($aEvent, $aBrowseParams = array())
  656. {
  657. return $this->_serviceGetTimelineProfileImage($aEvent, $aBrowseParams, array(
  658. 'stg' => 'OBJECT_STORAGE',
  659. 'trans' => array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_AVATAR'),
  660. 'trans_orig' => array('OBJECT_IMAGES_TRANSCODER_PICTURE', 'OBJECT_IMAGES_TRANSCODER_GALLERY'),
  661. 'txt_ss' => 'txt_sample_pp_single',
  662. 'txt_sswa' => 'txt_sample_pp_single_with_article',
  663. 'txt_sa' => 'txt_sample_pi_action',
  664. 'txt_sau' => 'txt_sample_pi_action_user'
  665. ));
  666. }
  667. public function serviceGetTimelineProfileCover($aEvent, $aBrowseParams = array())
  668. {
  669. return $this->_serviceGetTimelineProfileImage($aEvent, $aBrowseParams, array(
  670. 'stg' => 'OBJECT_STORAGE_COVER',
  671. 'trans' => array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_COVER_THUMB'),
  672. 'trans_orig' => array('OBJECT_IMAGES_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_GALLERY'),
  673. 'txt_ss' => 'txt_sample_pc_single',
  674. 'txt_sswa' => 'txt_sample_pc_single_with_article',
  675. 'txt_sa' => 'txt_sample_pi_action',
  676. 'txt_sau' => 'txt_sample_pi_action_user'
  677. ));
  678. }
  679. public function serviceGetConnectionButtonsTitles($iProfileId, $sConnectionsObject = 'sys_profiles_friends')
  680. {
  681. if (!isLogged())
  682. return array();
  683. if (!($oConn = BxDolConnection::getObjectInstance($sConnectionsObject)))
  684. return array();
  685. $CNF = $this->_oConfig->CNF;
  686. if ($oConn->isConnectedNotMutual(bx_get_logged_profile_id(), $iProfileId)) {
  687. return array(
  688. 'add' => _t($CNF['T']['menu_item_title_befriend_sent']),
  689. 'remove' => _t($CNF['T']['menu_item_title_unfriend_cancel_request']),
  690. );
  691. } elseif ($oConn->isConnectedNotMutual($iProfileId, bx_get_logged_profile_id())) {
  692. return array(
  693. 'add' => _t($CNF['T']['menu_item_title_befriend_confirm']),
  694. 'remove' => _t($CNF['T']['menu_item_title_unfriend_reject_request']),
  695. );
  696. } elseif ($oConn->isConnected($iProfileId, bx_get_logged_profile_id(), true)) {
  697. return array(
  698. 'add' => '',
  699. 'remove' => _t($CNF['T']['menu_item_title_unfriend']),
  700. );
  701. } else {
  702. return array(
  703. 'add' => _t($CNF['T']['menu_item_title_befriend']),
  704. 'remove' => '',
  705. );
  706. }
  707. }
  708. // ====== PERMISSION METHODS
  709. /**
  710. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  711. */
  712. public function checkAllowedAdd ($isPerformAction = false)
  713. {
  714. $oAccount = BxDolAccount::getInstance();
  715. if (!$oAccount || ($this->serviceActAsProfile() && $oAccount->isProfilesLimitReached()))
  716. return _t('_sys_txt_access_denied');
  717. return parent::checkAllowedAdd ($isPerformAction);
  718. }
  719. /**
  720. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  721. */
  722. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  723. {
  724. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
  725. }
  726. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  727. {
  728. if (!$iProfileId)
  729. $iProfileId = $this->_iProfileId;
  730. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  731. if ($oProfile && $oProfile->id() == $iProfileId)
  732. return CHECK_ACTION_RESULT_ALLOWED;
  733. return parent::serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  734. }
  735. /**
  736. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  737. */
  738. public function checkAllowedViewProfileImage ($aDataEntry, $isPerformAction = false)
  739. {
  740. $CNF = &$this->_oConfig->CNF;
  741. // check privacy
  742. if (empty($CNF['OBJECT_PRIVACY_VIEW']))
  743. return CHECK_ACTION_RESULT_ALLOWED;
  744. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  745. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']]) && !$oPrivacy->isPartiallyVisible($aDataEntry[$CNF['FIELD_ALLOW_VIEW_TO']]))
  746. return _t('_sys_access_denied_to_private_content');
  747. return CHECK_ACTION_RESULT_ALLOWED;
  748. }
  749. /**
  750. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  751. */
  752. public function checkAllowedViewCoverImage ($aDataEntry, $isPerformAction = false)
  753. {
  754. return $this->checkAllowedViewProfileImage($aDataEntry);
  755. }
  756. /**
  757. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  758. */
  759. public function checkAllowedPost ($aDataEntry, $isPerformAction = false)
  760. {
  761. return $this->checkAllowedView ($aDataEntry, $isPerformAction);
  762. }
  763. /**
  764. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  765. */
  766. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  767. {
  768. // moderator always has access
  769. if ($this->_isModerator($isPerformAction))
  770. return CHECK_ACTION_RESULT_ALLOWED;
  771. // owner (checked by account! not as profile as ususal) always have access
  772. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name']);
  773. if (!$oProfile)
  774. return _t('_sys_txt_error_occured');
  775. if ($oProfile->getAccountId() == $this->_iAccountId)
  776. return CHECK_ACTION_RESULT_ALLOWED;
  777. return _t('_sys_txt_access_denied');
  778. }
  779. /**
  780. * Check if user can change cover image
  781. */
  782. public function checkAllowedChangeCover ($aDataEntry, $isPerformAction = false)
  783. {
  784. // moderator always has access
  785. if ($this->_isModerator($isPerformAction))
  786. return CHECK_ACTION_RESULT_ALLOWED;
  787. // owner (checked by account! not as profile as ususal) always have access
  788. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name']);
  789. if (!$oProfile)
  790. return _t('_sys_txt_error_occured');
  791. if ($oProfile->getAccountId() == $this->_iAccountId)
  792. return CHECK_ACTION_RESULT_ALLOWED;
  793. return _t('_sys_txt_access_denied');
  794. }
  795. /**
  796. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  797. */
  798. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  799. {
  800. // moderator always has access
  801. if ($this->_isModerator($isPerformAction))
  802. return CHECK_ACTION_RESULT_ALLOWED;
  803. // check ACL and owner (checked by account! not as profile as ususal)
  804. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  805. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name'], $isPerformAction);
  806. if (!$oProfile)
  807. return _t('_sys_txt_error_occured');
  808. if ($oProfile->getAccountId() == $this->_iAccountId && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  809. return CHECK_ACTION_RESULT_ALLOWED;
  810. return _t('_sys_txt_access_denied');
  811. }
  812. /**
  813. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  814. */
  815. public function checkAllowedViewMoreMenu (&$aDataEntry, $isPerformAction = false)
  816. {
  817. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']);
  818. if (!$oMenu || !$oMenu->getCode())
  819. return _t('_sys_txt_access_denied');
  820. return CHECK_ACTION_RESULT_ALLOWED;
  821. }
  822. /**
  823. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  824. */
  825. public function checkAllowedCompose (&$aDataEntry, $isPerformAction = false)
  826. {
  827. $CNF = &$this->_oConfig->CNF;
  828. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->getName());
  829. if($oProfile && $oProfile->id() == $this->_iProfileId)
  830. return _t('_sys_txt_access_denied');
  831. return $this->checkAllowedView ($aDataEntry, $isPerformAction);
  832. }
  833. /**
  834. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  835. */
  836. public function checkAllowedFriendAdd (&$aDataEntry, $isPerformAction = false)
  837. {
  838. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', true, false);
  839. }
  840. /**
  841. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  842. */
  843. public function checkAllowedFriendRemove (&$aDataEntry, $isPerformAction = false)
  844. {
  845. if (CHECK_ACTION_RESULT_ALLOWED === $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', false, true, true))
  846. return CHECK_ACTION_RESULT_ALLOWED;
  847. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', false, true, false);
  848. }
  849. /**
  850. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  851. */
  852. public function checkAllowedSubscribeAdd (&$aDataEntry, $isPerformAction = false)
  853. {
  854. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedView($aDataEntry)))
  855. return $sMsg;
  856. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_subscriptions', false, false);
  857. }
  858. /**
  859. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  860. */
  861. public function checkAllowedSubscribeRemove (&$aDataEntry, $isPerformAction = false)
  862. {
  863. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_subscriptions', false, true);
  864. }
  865. public function checkAllowedSubscriptionsView (&$aDataEntry, $isPerformAction = false)
  866. {
  867. $CNF = &$this->_oConfig->CNF;
  868. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->_aModule['name']);
  869. if(!$oProfile || ($oProfile->id() != $this->_iProfileId && $this->_oDb->getParam($CNF['PARAM_PUBLIC_SBSN']) != 'on' && $this->_oDb->getParam($CNF['PARAM_PUBLIC_SBSD']) != 'on'))
  870. return _t('_sys_txt_access_denied');
  871. return CHECK_ACTION_RESULT_ALLOWED;
  872. }
  873. public function checkMyself($iContentId)
  874. {
  875. $iLogged = (int)bx_get_logged_profile_id();
  876. if(empty($iLogged))
  877. return false;
  878. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->_oConfig->getName());
  879. if(!$oProfile)
  880. return false;
  881. return $oProfile->id() == $iLogged;
  882. }
  883. // ====== PROTECTED METHODS
  884. protected function _checkAllowedConnect (&$aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap = false)
  885. {
  886. if (!$this->_iProfileId)
  887. return _t('_sys_txt_access_denied');
  888. $CNF = &$this->_oConfig->CNF;
  889. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->_aModule['name']);
  890. if (!$oProfile || $oProfile->id() == $this->_iProfileId)
  891. return _t('_sys_txt_access_denied');
  892. return BxDolConnection::getObjectInstance($sObjConnection)->checkAllowedConnect ($this->_iProfileId, $oProfile->id(), $isPerformAction, $isMutual, $isInvertResult, $isSwap);
  893. }
  894. protected function _buildRssParams($sMode, $aArgs)
  895. {
  896. $aParams = array ();
  897. $sMode = bx_process_input($sMode);
  898. switch ($sMode) {
  899. case 'connections':
  900. $aParams = array(
  901. 'object' => isset($aArgs[0]) ? $aArgs[0] : '',
  902. 'type' => isset($aArgs[1]) ? $aArgs[1] : '',
  903. 'profile' => isset($aArgs[2]) ? (int)$aArgs[2] : 0,
  904. 'mutual' => isset($aArgs[3]) ? (int)$aArgs[3] : 0,
  905. 'profile2' => isset($aArgs[4]) ? (int)$aArgs[4] : 0,
  906. );
  907. break;
  908. }
  909. return $aParams;
  910. }
  911. protected function _serviceBrowseQuick($aProfiles, $iStart = 0, $iLimit = 4, $aAdditionalParams = array())
  912. {
  913. // get paginate object
  914. $oPaginate = new BxTemplPaginate(array(
  915. 'on_change_page' => "return !loadDynamicBlockAutoPaginate(this, '{start}', '{per_page}', " . bx_js_string(json_encode($aAdditionalParams)) . ");",
  916. 'num' => count($aProfiles),
  917. 'per_page' => $iLimit,
  918. 'start' => $iStart,
  919. ));
  920. // remove last item from connection array, because we've got one more item for pagination calculations only
  921. if (count($aProfiles) > $iLimit)
  922. array_pop($aProfiles);
  923. // get profiles HTML
  924. $s = '';
  925. foreach ($aProfiles as $iProfileId) {
  926. $oProfile = BxDolProfile::getInstance($iProfileId);
  927. if(!$oProfile)
  928. continue;
  929. $s .= $oProfile->getUnit();
  930. }
  931. // return profiles + paginate
  932. return $s . (!$iStart && $oPaginate->getNum() <= $iLimit ? '' : $oPaginate->getSimplePaginate());
  933. }
  934. protected function _serviceGetTimelineProfileImage($aEvent, $aBrowseParams, $aBuildParams)
  935. {
  936. $CNF = &$this->_oConfig->CNF;
  937. $aFileInfo = BxDolStorage::getObjectInstance($CNF[$aBuildParams['stg']])->getFile((int)$aEvent['object_id']);
  938. if(empty($aFileInfo) || !is_array($aFileInfo))
  939. return '';
  940. $aEventContent = unserialize($aEvent['content']);
  941. if(!is_array($aEventContent) || empty($aEventContent['content']))
  942. return '';
  943. $aContentInfo = $this->_oDb->getContentInfoById($aEventContent['content']);
  944. if(empty($aContentInfo) || !is_array($aContentInfo))
  945. return '';
  946. list($sUserName) = $this->getUserInfo($aContentInfo['profile_id']);
  947. $sSample = isset($CNF['T'][$aBuildParams['txt_sswa']]) ? $CNF['T'][$aBuildParams['txt_sswa']] : $CNF['T'][$aBuildParams['txt_ss']];
  948. //--- Title & Description
  949. $sTitle = !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '';
  950. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TEXT']]))
  951. $sTitle = $aContentInfo[$CNF['FIELD_TEXT']];
  952. $sDescription = _t($CNF['T'][$aBuildParams['txt_sau']], $sUserName, _t($sSample));
  953. return array(
  954. 'owner_id' => $aContentInfo['profile_id'],
  955. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  956. 'sample' => $sSample,
  957. 'sample_wo_article' => $CNF['T'][$aBuildParams['txt_ss']],
  958. 'sample_action' => isset($CNF['T'][$aBuildParams['txt_sa']]) ? $CNF['T'][$aBuildParams['txt_sa']] : '',
  959. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]),
  960. 'content' => $this->_getContentForTimelineProfileImage($aEvent, $aBrowseParams, $aBuildParams, $aContentInfo, $aFileInfo), //a string to display or array to parse default template before displaying.
  961. 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
  962. 'views' => '',
  963. 'votes' => '',
  964. 'scores' => '',
  965. 'reports' => '',
  966. 'comments' => '',
  967. 'title' => $sTitle, //may be empty.
  968. 'description' => $sDescription //may be empty.
  969. );
  970. }
  971. protected function _getContentForTimelineProfileImage($aEvent, $aBrowseParams, $aBuildParams, $aContentInfo, $aFileInfo)
  972. {
  973. $CNF = &$this->_oConfig->CNF;
  974. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  975. //--- Image(s)
  976. $sImage = $this->_oConfig->getImageUrl($aFileInfo['id'], $aBuildParams['trans']);
  977. $sImageOrig = $this->_oConfig->getImageUrl($aFileInfo['id'], $aBuildParams['trans_orig']);
  978. if(!empty($sImage)) {
  979. if(empty($sImageOrig))
  980. $sImageOrig = $sImage;
  981. $aImages = array(
  982. array('url' => $sUrl, 'src' => $sImage, 'src_orig' => $sImageOrig),
  983. );
  984. }
  985. return array(
  986. 'sample' => isset($CNF['T'][$aBuildParams['txt_sswa']]) ? $CNF['T'][$aBuildParams['txt_sswa']] : $CNF['T'][$aBuildParams['txt_ss']],
  987. 'sample_wo_article' => $CNF['T'][$aBuildParams['txt_ss']],
  988. 'sample_action' => isset($CNF['T'][$aBuildParams['txt_sa']]) ? $CNF['T'][$aBuildParams['txt_sa']] : '',
  989. 'url' => $sUrl,
  990. 'title' => '',
  991. 'text' => '',
  992. 'images' => $aImages,
  993. 'videos' => array()
  994. );
  995. }
  996. protected function _entityComments($sObject, $iId = 0)
  997. {
  998. if(!$iId)
  999. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1000. if(!$iId)
  1001. $iId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  1002. if(!$iId)
  1003. return false;
  1004. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  1005. if(!$oCmts || !$oCmts->isEnabled())
  1006. return false;
  1007. return $oCmts->getCommentsBlock(array(), array('in_designbox' => false));
  1008. }
  1009. protected function _getContent($iContentId = 0, $sFuncGetContent = 'getContentInfoById')
  1010. {
  1011. if(!$iContentId && bx_get('id') === false && bx_get('profile_id') !== false) {
  1012. $oProfile = BxDolProfile::getInstance((int)bx_get('profile_id'));
  1013. if($oProfile)
  1014. $iContentId = $oProfile->getContentId();
  1015. }
  1016. return parent::_getContent($iContentId, $sFuncGetContent);
  1017. }
  1018. }
  1019. /** @} */