BxBaseModProfileModule.php 48 KB

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