BxBaseModProfileModule.php 47 KB

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