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