BxBaseModProfileModule.php 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup BaseProfile Base classes for profile modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. define('BX_DOL_PROFILE_REDIRECT_PROFILE', 'profile');
  12. define('BX_DOL_PROFILE_REDIRECT_LAST', 'last');
  13. define('BX_DOL_PROFILE_REDIRECT_CUSTOM', 'custom');
  14. /**
  15. * Base class for profile modules.
  16. */
  17. class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolContentInfoService, iBxDolProfileService
  18. {
  19. protected $_iAccountId;
  20. function __construct(&$aModule)
  21. {
  22. parent::__construct($aModule);
  23. $this->_iAccountId = getLoggedId();
  24. }
  25. public function actionDeleteProfileImg($iFileId, $iContentId, $sFieldPicture)
  26. {
  27. $aResult = array();
  28. $CNF = &$this->_oConfig->CNF;
  29. $oSrorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  30. if (!($aFile = $oSrorage->getFile((int)$iFileId)) || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)) || $aContentInfo[$sFieldPicture] != (int)$iFileId)
  31. $aResult = array('error' => 1, 'msg' => _t('_sys_storage_err_file_not_found'));
  32. $oAccountProfile = BxDolProfile::getInstanceAccountProfile();
  33. if ($oAccountProfile)
  34. $iAccountProfileId = $oAccountProfile->id();
  35. if ((!$aResult && !isLogged()) || (!$aResult && $aFile['profile_id'] != $iAccountProfileId && !$this->_isModerator()))
  36. $aResult = array('error' => 2, 'msg' => _t('_Access denied'));
  37. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oTemplate);
  38. if (!$aResult && !$oForm->_deleteFile($iContentId, $sFieldPicture, (int)$iFileId, true))
  39. $aResult = array('error' => 3, 'msg' => _t('_Failed'));
  40. elseif (!$aResult)
  41. $aResult = array('error' => 0, 'msg' => '');
  42. header('Content-Type: application/json; charset=utf-8');
  43. echo json_encode($aResult);
  44. }
  45. // ====== SERVICE METHODS
  46. public function serviceGetOptionsRedirectAfterAdd()
  47. {
  48. $CNF = &$this->_oConfig->CNF;
  49. $aResult = array();
  50. $aChoices = array(BX_DOL_PROFILE_REDIRECT_PROFILE, BX_DOL_PROFILE_REDIRECT_LAST, BX_DOL_PROFILE_REDIRECT_CUSTOM);
  51. foreach($aChoices as $sChoice)
  52. $aResult[] = array('key' => $sChoice, 'value' => _t($CNF['T']['option_redirect_aadd_' . $sChoice]));
  53. return $aResult;
  54. }
  55. public function serviceGetThumb ($iContentId, $sTranscoder = '')
  56. {
  57. $CNF = &$this->_oConfig->CNF;
  58. if(empty($sTranscoder) && !empty($CNF['OBJECT_IMAGES_TRANSCODER_THUMB']))
  59. $sTranscoder = $CNF['OBJECT_IMAGES_TRANSCODER_THUMB'];
  60. $mixedResult = $this->_getFieldValueThumb('FIELD_PICTURE', $iContentId, $sTranscoder);
  61. return $mixedResult !== false ? $mixedResult : '';
  62. }
  63. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  64. {
  65. if(empty($sUnitTemplate))
  66. $sUnitTemplate = 'unit_with_cover.html';
  67. return parent::serviceGetSearchResultUnit($iContentId, $sUnitTemplate);
  68. }
  69. public function serviceGetSearchableFieldsExtended()
  70. {
  71. $CNF = &$this->_oConfig->CNF;
  72. $aResult = parent::serviceGetSearchableFieldsExtended();
  73. if(!$this->serviceActAsProfile())
  74. return $aResult;
  75. if(!in_array('online', $this->_aSearchableNamesExcept))
  76. $aResult['online'] = array(
  77. 'type' => 'checkbox',
  78. 'caption' => $CNF['T']['form_field_online'],
  79. 'info' => '',
  80. 'value' => '1',
  81. 'values' => '',
  82. 'pass' => ''
  83. );
  84. if(!empty($CNF['FIELD_PICTURE']) && !in_array($CNF['FIELD_PICTURE'], $this->_aSearchableNamesExcept))
  85. $aResult[$CNF['FIELD_PICTURE']] = array(
  86. 'type' => 'checkbox',
  87. 'caption' => $CNF['T']['form_field_picture'],
  88. 'info' => '',
  89. 'value' => '1',
  90. 'values' => '',
  91. 'pass' => '',
  92. 'search_operator' => '>='
  93. );
  94. return $aResult;
  95. }
  96. public function servicePrivateProfileMsg()
  97. {
  98. return MsgBox(_t('_sys_access_denied_to_private_content'));
  99. }
  100. public function serviceGetContentInfoById($iContentId)
  101. {
  102. return $this->_oDb->getContentInfoById((int)$iContentId);
  103. }
  104. public function serviceGetMenuAddonManageTools()
  105. {
  106. bx_import('SearchResult', $this->_aModule);
  107. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  108. $o = new $sClass();
  109. $o->fillFilters(array(
  110. 'perofileStatus' => BX_PROFILE_STATUS_PENDING
  111. ));
  112. $o->unsetPaginate();
  113. return $o->getNum();
  114. }
  115. public function serviceGetMenuAddonManageToolsProfileStats()
  116. {
  117. bx_import('SearchResult', $this->_aModule);
  118. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  119. $o = new $sClass();
  120. $o->fillFilters(array(
  121. 'account_id' => getLoggedId(),
  122. 'perofileStatus' => ''
  123. ));
  124. $o->unsetPaginate();
  125. return $o->getNum();
  126. }
  127. public function serviceGetMenuAddonFavoritesProfileStats()
  128. {
  129. bx_import('SearchResult', $this->_aModule);
  130. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  131. $o = new $sClass('favorite', array('user' => bx_get_logged_profile_id()));
  132. $o->unsetPaginate();
  133. return $o->getNum();
  134. }
  135. public function serviceGetSubmenuObject ()
  136. {
  137. return $this->_oConfig->CNF['OBJECT_MENU_SUBMENU_VIEW_ENTRY'];
  138. }
  139. public function serviceGetMenuSetNameForMenuTrigger ($sMenuTriggerName)
  140. {
  141. $CNF = &$this->_oConfig->CNF;
  142. if ($CNF['TRIGGER_MENU_PROFILE_VIEW_SUBMENU'] == $sMenuTriggerName)
  143. return $CNF['OBJECT_MENU_SUBMENU_VIEW_ENTRY'];
  144. elseif ($CNF['TRIGGER_MENU_PROFILE_VIEW_ACTIONS'] == $sMenuTriggerName)
  145. return $CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY'];
  146. return '';
  147. }
  148. public function serviceGetSnippetMenuVars($iProfileId, $bPublic = null)
  149. {
  150. return $this->_oTemplate->getSnippetMenuVars($iProfileId, $bPublic);
  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 ($iContentId = 0)
  483. {
  484. $mixedContent = $this->_getContent($iContentId);
  485. if($mixedContent === false)
  486. return false;
  487. list($iContentId, $aContentInfo) = $mixedContent;
  488. $CNF = &$this->_oConfig->CNF;
  489. return $this->_entitySocialSharing ($iContentId, array(
  490. 'id_timeline' => 0,
  491. 'id_thumb' => !empty($CNF['FIELD_PICTURE']) && !empty($aContentInfo[$CNF['FIELD_PICTURE']]) ? $aContentInfo[$CNF['FIELD_PICTURE']] : '',
  492. 'title' => !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  493. 'object_storage' => !empty($CNF['OBJECT_STORAGE']) ? $CNF['OBJECT_STORAGE'] : '',
  494. 'object_transcoder' => false,
  495. 'object_vote' => '',
  496. 'object_score' => !empty($CNF['OBJECT_SCORES']) ? $CNF['OBJECT_SCORES'] : '',
  497. 'object_favorite' => !empty($CNF['OBJECT_FAVORITES']) ? $CNF['OBJECT_FAVORITES'] : '',
  498. 'object_feature' => !empty($CNF['OBJECT_FEATURED']) ? $CNF['OBJECT_FEATURED'] : '',
  499. 'object_report' => !empty($CNF['OBJECT_REPORTS']) ? $CNF['OBJECT_REPORTS'] : '',
  500. 'uri_view_entry' => !empty($CNF['URI_VIEW_ENTRY']) ? $CNF['URI_VIEW_ENTRY'] : '',
  501. 'social_sharing' => false
  502. ));
  503. }
  504. public function serviceProfileMembership ($iContentId = 0)
  505. {
  506. $mixedContent = $this->_getContent($iContentId);
  507. if($mixedContent === false)
  508. return false;
  509. list($iContentId, $aContentInfo) = $mixedContent;
  510. return BxDolAcl::getInstance()->getProfileMembership($aContentInfo['profile_id']);
  511. }
  512. public function serviceProfileFriends ($iContentId = 0)
  513. {
  514. $mixedContent = $this->_getContent($iContentId);
  515. if($mixedContent === false)
  516. return false;
  517. list($iContentId, $aContentInfo) = $mixedContent;
  518. bx_import('BxDolConnection');
  519. $s = $this->serviceBrowseConnectionsQuick ($aContentInfo['profile_id'], 'sys_profiles_friends', BX_CONNECTIONS_CONTENT_TYPE_CONTENT, true);
  520. if (!$s)
  521. return MsgBox(_t('_sys_txt_empty'));
  522. return $s;
  523. }
  524. public function serviceProfileSubscriptions ($iContentId = 0, $aParams = array())
  525. {
  526. $mixedContent = $this->_getContent($iContentId);
  527. if($mixedContent === false)
  528. return false;
  529. list($iContentId, $aContentInfo) = $mixedContent;
  530. bx_import('BxDolConnection');
  531. $aResult = $this->serviceBrowseConnectionsByType(array(
  532. 'profile_id' => $aContentInfo['profile_id'],
  533. 'object' => 'sys_profiles_subscriptions',
  534. 'type' => BX_CONNECTIONS_CONTENT_TYPE_CONTENT
  535. ), array(
  536. 'type' => isset($aParams['type']) ? $aParams['type'] : '',
  537. 'filter_menu' => isset($aParams['filter_menu']) ? $aParams['filter_menu'] : true,
  538. ));
  539. if(empty($aResult['content']))
  540. $aResult['content'] = MsgBox(_t('_sys_txt_empty'));
  541. return $aResult;
  542. }
  543. public function serviceProfileSubscribedMe ($iContentId = 0)
  544. {
  545. $mixedContent = $this->_getContent($iContentId);
  546. if($mixedContent === false)
  547. return false;
  548. list($iContentId, $aContentInfo) = $mixedContent;
  549. bx_import('BxDolConnection');
  550. $s = $this->serviceBrowseConnectionsQuick ($aContentInfo['profile_id'], 'sys_profiles_subscriptions', BX_CONNECTIONS_CONTENT_TYPE_INITIATORS);
  551. if (!$s)
  552. return MsgBox(_t('_sys_txt_empty'));
  553. return $s;
  554. }
  555. /**
  556. * check enabled profile activation letter
  557. */
  558. public function serviceIsEnableProfileActivationLetter()
  559. {
  560. $CNF = &$this->_oConfig->CNF;
  561. return isset($CNF['PARAM_ENABLE_ACTIVATION_LETTER']) ? (bool)getParam($CNF['PARAM_ENABLE_ACTIVATION_LETTER']) : true;
  562. }
  563. /**
  564. * For internal usage only.
  565. */
  566. public function serviceDeleteEntityService ($iContentId, $bDeleteWithContent = false)
  567. {
  568. return parent::serviceDeleteEntity ($iContentId, 'deleteDataService');
  569. }
  570. /**
  571. * Data for Notifications module
  572. */
  573. public function serviceGetNotificationsData()
  574. {
  575. $a = parent::serviceGetNotificationsData();
  576. $sModule = $this->_aModule['name'];
  577. $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');
  578. $a['alerts'][] = array('unit' => $sModule, 'action' => 'timeline_post_common');
  579. return $a;
  580. }
  581. /**
  582. * Notification about new member requst in the group
  583. */
  584. public function serviceGetNotificationsTimelinePostCommon($aEvent)
  585. {
  586. $CNF = &$this->_oConfig->CNF;
  587. $iContentId = (int)$aEvent['object_id'];
  588. $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  589. if(!$oGroupProfile)
  590. return array();
  591. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  592. if(empty($aContentInfo) || !is_array($aContentInfo))
  593. return array();
  594. $aSubcontentInfo = BxDolService::call('bx_timeline', 'get_info', array((int)$aEvent['subobject_id'], false));
  595. if(empty($aSubcontentInfo) || !is_array($aSubcontentInfo))
  596. return array();
  597. $sSubentryUrl = BxDolService::call('bx_timeline', 'get_link', array((int)$aEvent['subobject_id']));
  598. $sSubentrySample = $aSubcontentInfo['title'];
  599. if(empty($sSubentrySample))
  600. $sSubentrySample = strmaxtextlen($aSubcontentInfo['description'], 20, '...');
  601. return array(
  602. 'entry_sample' => $CNF['T']['txt_sample_single'],
  603. 'entry_url' => $oGroupProfile->getUrl(),
  604. 'entry_caption' => $oGroupProfile->getDisplayName(),
  605. 'entry_author' => $oGroupProfile->id(),
  606. 'subentry_sample' => $sSubentrySample,
  607. 'subentry_url' => $sSubentryUrl,
  608. 'lang_key' => $CNF['T']['txt_ntfs_timeline_post_common'],
  609. );
  610. }
  611. /**
  612. * Data for Timeline module
  613. */
  614. public function serviceGetTimelineData()
  615. {
  616. $CNF = &$this->_oConfig->CNF;
  617. $sModule = $this->_aModule['name'];
  618. $aAlerts = array();
  619. $aHandlers = array();
  620. if(!empty($CNF['FIELD_PICTURE'])) {
  621. $aAlerts = array_merge($aAlerts, array(
  622. array('unit' => $sModule, 'action' => 'profile_picture_changed'),
  623. array('unit' => $sModule, 'action' => 'profile_picture_deleted')
  624. ));
  625. $aHandlers = array_merge($aHandlers, array(
  626. 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' => ''),
  627. array('group' => $sModule . '_profile_picture', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'profile_picture_deleted')
  628. ));
  629. }
  630. if(!empty($CNF['FIELD_COVER'])) {
  631. $aAlerts = array_merge($aAlerts, array(
  632. array('unit' => $sModule, 'action' => 'profile_cover_changed'),
  633. array('unit' => $sModule, 'action' => 'profile_cover_deleted')
  634. ));
  635. $aHandlers = array_merge($aHandlers, array(
  636. 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' => ''),
  637. array('group' => $sModule . '_profile_cover', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'profile_cover_deleted')
  638. ));
  639. }
  640. $aResult = array();
  641. if(!empty($aAlerts) && !empty($aHandlers))
  642. $aResult = array(
  643. 'handlers' => $aHandlers,
  644. 'alerts' => $aAlerts
  645. );
  646. return $aResult;
  647. }
  648. /**
  649. * Entry post for Timeline module
  650. */
  651. public function serviceGetTimelineProfilePicture($aEvent, $aBrowseParams = array())
  652. {
  653. return $this->_serviceGetTimelineProfileImage($aEvent, $aBrowseParams, array(
  654. 'stg' => 'OBJECT_STORAGE',
  655. 'trans' => array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_AVATAR'),
  656. 'trans_orig' => array('OBJECT_IMAGES_TRANSCODER_PICTURE', 'OBJECT_IMAGES_TRANSCODER_GALLERY'),
  657. 'txt_ss' => 'txt_sample_pp_single',
  658. 'txt_sswa' => 'txt_sample_pp_single_with_article',
  659. 'txt_sa' => 'txt_sample_pi_action',
  660. 'txt_sau' => 'txt_sample_pi_action_user'
  661. ));
  662. }
  663. public function serviceGetTimelineProfileCover($aEvent, $aBrowseParams = array())
  664. {
  665. return $this->_serviceGetTimelineProfileImage($aEvent, $aBrowseParams, array(
  666. 'stg' => 'OBJECT_STORAGE_COVER',
  667. 'trans' => array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_COVER_THUMB'),
  668. 'trans_orig' => array('OBJECT_IMAGES_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_GALLERY'),
  669. 'txt_ss' => 'txt_sample_pc_single',
  670. 'txt_sswa' => 'txt_sample_pc_single_with_article',
  671. 'txt_sa' => 'txt_sample_pi_action',
  672. 'txt_sau' => 'txt_sample_pi_action_user'
  673. ));
  674. }
  675. public function serviceGetConnectionButtonsTitles($iProfileId, $sConnectionsObject = 'sys_profiles_friends')
  676. {
  677. if (!isLogged())
  678. return array();
  679. if (!($oConn = BxDolConnection::getObjectInstance($sConnectionsObject)))
  680. return array();
  681. $CNF = $this->_oConfig->CNF;
  682. if ($oConn->isConnectedNotMutual(bx_get_logged_profile_id(), $iProfileId)) {
  683. return array(
  684. 'add' => _t($CNF['T']['menu_item_title_befriend_sent']),
  685. 'remove' => _t($CNF['T']['menu_item_title_unfriend_cancel_request']),
  686. );
  687. } elseif ($oConn->isConnectedNotMutual($iProfileId, bx_get_logged_profile_id())) {
  688. return array(
  689. 'add' => _t($CNF['T']['menu_item_title_befriend_confirm']),
  690. 'remove' => _t($CNF['T']['menu_item_title_unfriend_reject_request']),
  691. );
  692. } elseif ($oConn->isConnected($iProfileId, bx_get_logged_profile_id(), true)) {
  693. return array(
  694. 'add' => '',
  695. 'remove' => _t($CNF['T']['menu_item_title_unfriend']),
  696. );
  697. } else {
  698. return array(
  699. 'add' => _t($CNF['T']['menu_item_title_befriend']),
  700. 'remove' => '',
  701. );
  702. }
  703. }
  704. // ====== PERMISSION METHODS
  705. /**
  706. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  707. */
  708. public function checkAllowedAdd ($isPerformAction = false)
  709. {
  710. $oAccount = BxDolAccount::getInstance();
  711. if (!$oAccount || ($this->serviceActAsProfile() && $oAccount->isProfilesLimitReached()))
  712. return _t('_sys_txt_access_denied');
  713. return parent::checkAllowedAdd ($isPerformAction);
  714. }
  715. /**
  716. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  717. */
  718. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  719. {
  720. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
  721. }
  722. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  723. {
  724. if (!$iProfileId)
  725. $iProfileId = $this->_iProfileId;
  726. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  727. if ($oProfile && $oProfile->id() == $iProfileId)
  728. return CHECK_ACTION_RESULT_ALLOWED;
  729. return parent::serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  730. }
  731. /**
  732. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  733. */
  734. public function checkAllowedViewProfileImage ($aDataEntry, $isPerformAction = false)
  735. {
  736. $CNF = &$this->_oConfig->CNF;
  737. // check privacy
  738. if (empty($CNF['OBJECT_PRIVACY_VIEW']))
  739. return CHECK_ACTION_RESULT_ALLOWED;
  740. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  741. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']]) && !$oPrivacy->isPartiallyVisible($aDataEntry[$CNF['FIELD_ALLOW_VIEW_TO']]))
  742. return _t('_sys_access_denied_to_private_content');
  743. return CHECK_ACTION_RESULT_ALLOWED;
  744. }
  745. /**
  746. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  747. */
  748. public function checkAllowedViewCoverImage ($aDataEntry, $isPerformAction = false)
  749. {
  750. return $this->checkAllowedViewProfileImage($aDataEntry);
  751. }
  752. /**
  753. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  754. */
  755. public function checkAllowedPost ($aDataEntry, $isPerformAction = false)
  756. {
  757. return $this->checkAllowedView ($aDataEntry, $isPerformAction);
  758. }
  759. /**
  760. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  761. */
  762. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  763. {
  764. // moderator always has access
  765. if ($this->_isModerator($isPerformAction))
  766. return CHECK_ACTION_RESULT_ALLOWED;
  767. // owner (checked by account! not as profile as ususal) always have access
  768. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name']);
  769. if (!$oProfile)
  770. return _t('_sys_txt_error_occured');
  771. if ($oProfile->getAccountId() == $this->_iAccountId)
  772. return CHECK_ACTION_RESULT_ALLOWED;
  773. return _t('_sys_txt_access_denied');
  774. }
  775. /**
  776. * Check if user can change cover image
  777. */
  778. public function checkAllowedChangeCover ($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. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  793. */
  794. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  795. {
  796. // moderator always has access
  797. if ($this->_isModerator($isPerformAction))
  798. return CHECK_ACTION_RESULT_ALLOWED;
  799. // check ACL and owner (checked by account! not as profile as ususal)
  800. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  801. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name'], $isPerformAction);
  802. if (!$oProfile)
  803. return _t('_sys_txt_error_occured');
  804. if ($oProfile->getAccountId() == $this->_iAccountId && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  805. return CHECK_ACTION_RESULT_ALLOWED;
  806. return _t('_sys_txt_access_denied');
  807. }
  808. /**
  809. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  810. */
  811. public function checkAllowedViewMoreMenu (&$aDataEntry, $isPerformAction = false)
  812. {
  813. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']);
  814. if (!$oMenu || !$oMenu->getCode())
  815. return _t('_sys_txt_access_denied');
  816. return CHECK_ACTION_RESULT_ALLOWED;
  817. }
  818. /**
  819. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  820. */
  821. public function checkAllowedCompose (&$aDataEntry, $isPerformAction = false)
  822. {
  823. $CNF = &$this->_oConfig->CNF;
  824. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->getName());
  825. if($oProfile && $oProfile->id() == $this->_iProfileId)
  826. return _t('_sys_txt_access_denied');
  827. return $this->checkAllowedView ($aDataEntry, $isPerformAction);
  828. }
  829. /**
  830. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  831. */
  832. public function checkAllowedFriendAdd (&$aDataEntry, $isPerformAction = false)
  833. {
  834. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', true, false);
  835. }
  836. /**
  837. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  838. */
  839. public function checkAllowedFriendRemove (&$aDataEntry, $isPerformAction = false)
  840. {
  841. if (CHECK_ACTION_RESULT_ALLOWED === $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', false, true, true))
  842. return CHECK_ACTION_RESULT_ALLOWED;
  843. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', false, true, false);
  844. }
  845. /**
  846. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  847. */
  848. public function checkAllowedSubscribeAdd (&$aDataEntry, $isPerformAction = false)
  849. {
  850. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedView($aDataEntry)))
  851. return $sMsg;
  852. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_subscriptions', false, false);
  853. }
  854. /**
  855. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  856. */
  857. public function checkAllowedSubscribeRemove (&$aDataEntry, $isPerformAction = false)
  858. {
  859. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_subscriptions', false, true);
  860. }
  861. public function checkAllowedSubscriptionsView (&$aDataEntry, $isPerformAction = false)
  862. {
  863. $CNF = &$this->_oConfig->CNF;
  864. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->_aModule['name']);
  865. if(!$oProfile || ($oProfile->id() != $this->_iProfileId && $this->_oDb->getParam($CNF['PARAM_PUBLIC_SBSN']) != 'on' && $this->_oDb->getParam($CNF['PARAM_PUBLIC_SBSD']) != 'on'))
  866. return _t('_sys_txt_access_denied');
  867. return CHECK_ACTION_RESULT_ALLOWED;
  868. }
  869. public function checkMyself($iContentId)
  870. {
  871. $iLogged = (int)bx_get_logged_profile_id();
  872. if(empty($iLogged))
  873. return false;
  874. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->_oConfig->getName());
  875. if(!$oProfile)
  876. return false;
  877. return $oProfile->id() == $iLogged;
  878. }
  879. // ====== PROTECTED METHODS
  880. protected function _checkAllowedConnect (&$aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap = false)
  881. {
  882. if (!$this->_iProfileId)
  883. return _t('_sys_txt_access_denied');
  884. $CNF = &$this->_oConfig->CNF;
  885. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->_aModule['name']);
  886. if (!$oProfile || $oProfile->id() == $this->_iProfileId)
  887. return _t('_sys_txt_access_denied');
  888. return BxDolConnection::getObjectInstance($sObjConnection)->checkAllowedConnect ($this->_iProfileId, $oProfile->id(), $isPerformAction, $isMutual, $isInvertResult, $isSwap);
  889. }
  890. protected function _buildRssParams($sMode, $aArgs)
  891. {
  892. $aParams = array ();
  893. $sMode = bx_process_input($sMode);
  894. switch ($sMode) {
  895. case 'connections':
  896. $aParams = array(
  897. 'object' => isset($aArgs[0]) ? $aArgs[0] : '',
  898. 'type' => isset($aArgs[1]) ? $aArgs[1] : '',
  899. 'profile' => isset($aArgs[2]) ? (int)$aArgs[2] : 0,
  900. 'mutual' => isset($aArgs[3]) ? (int)$aArgs[3] : 0,
  901. 'profile2' => isset($aArgs[4]) ? (int)$aArgs[4] : 0,
  902. );
  903. break;
  904. }
  905. return $aParams;
  906. }
  907. protected function _serviceBrowseQuick($aProfiles, $iStart = 0, $iLimit = 4, $aAdditionalParams = array())
  908. {
  909. // get paginate object
  910. $oPaginate = new BxTemplPaginate(array(
  911. 'on_change_page' => "return !loadDynamicBlockAutoPaginate(this, '{start}', '{per_page}', " . bx_js_string(json_encode($aAdditionalParams)) . ");",
  912. 'num' => count($aProfiles),
  913. 'per_page' => $iLimit,
  914. 'start' => $iStart,
  915. ));
  916. // remove last item from connection array, because we've got one more item for pagination calculations only
  917. if (count($aProfiles) > $iLimit)
  918. array_pop($aProfiles);
  919. // get profiles HTML
  920. $s = '';
  921. foreach ($aProfiles as $iProfileId) {
  922. $oProfile = BxDolProfile::getInstance($iProfileId);
  923. if(!$oProfile)
  924. continue;
  925. $s .= $oProfile->getUnit();
  926. }
  927. // return profiles + paginate
  928. return $s . (!$iStart && $oPaginate->getNum() <= $iLimit ? '' : $oPaginate->getSimplePaginate());
  929. }
  930. protected function _serviceGetTimelineProfileImage($aEvent, $aBrowseParams, $aBuildParams)
  931. {
  932. $CNF = &$this->_oConfig->CNF;
  933. $aFileInfo = BxDolStorage::getObjectInstance($CNF[$aBuildParams['stg']])->getFile((int)$aEvent['object_id']);
  934. if(empty($aFileInfo) || !is_array($aFileInfo))
  935. return '';
  936. $aEventContent = unserialize($aEvent['content']);
  937. if(!is_array($aEventContent) || empty($aEventContent['content']))
  938. return '';
  939. $aContentInfo = $this->_oDb->getContentInfoById($aEventContent['content']);
  940. if(empty($aContentInfo) || !is_array($aContentInfo))
  941. return '';
  942. list($sUserName) = $this->getUserInfo($aContentInfo['profile_id']);
  943. $sSample = isset($CNF['T'][$aBuildParams['txt_sswa']]) ? $CNF['T'][$aBuildParams['txt_sswa']] : $CNF['T'][$aBuildParams['txt_ss']];
  944. //--- Title & Description
  945. $sTitle = !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '';
  946. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TEXT']]))
  947. $sTitle = $aContentInfo[$CNF['FIELD_TEXT']];
  948. $sDescription = _t($CNF['T'][$aBuildParams['txt_sau']], $sUserName, _t($sSample));
  949. return array(
  950. 'owner_id' => $aContentInfo['profile_id'],
  951. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  952. 'sample' => $sSample,
  953. 'sample_wo_article' => $CNF['T'][$aBuildParams['txt_ss']],
  954. 'sample_action' => isset($CNF['T'][$aBuildParams['txt_sa']]) ? $CNF['T'][$aBuildParams['txt_sa']] : '',
  955. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]),
  956. 'content' => $this->_getContentForTimelineProfileImage($aEvent, $aBrowseParams, $aBuildParams, $aContentInfo, $aFileInfo), //a string to display or array to parse default template before displaying.
  957. 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
  958. 'views' => '',
  959. 'votes' => '',
  960. 'scores' => '',
  961. 'reports' => '',
  962. 'comments' => '',
  963. 'title' => $sTitle, //may be empty.
  964. 'description' => $sDescription //may be empty.
  965. );
  966. }
  967. protected function _getContentForTimelineProfileImage($aEvent, $aBrowseParams, $aBuildParams, $aContentInfo, $aFileInfo)
  968. {
  969. $CNF = &$this->_oConfig->CNF;
  970. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  971. //--- Image(s)
  972. $sImage = $this->_oConfig->getImageUrl($aFileInfo['id'], $aBuildParams['trans']);
  973. $sImageOrig = $this->_oConfig->getImageUrl($aFileInfo['id'], $aBuildParams['trans_orig']);
  974. if(!empty($sImage)) {
  975. if(empty($sImageOrig))
  976. $sImageOrig = $sImage;
  977. $aImages = array(
  978. array('url' => $sUrl, 'src' => $sImage, 'src_orig' => $sImageOrig),
  979. );
  980. }
  981. return array(
  982. 'sample' => isset($CNF['T'][$aBuildParams['txt_sswa']]) ? $CNF['T'][$aBuildParams['txt_sswa']] : $CNF['T'][$aBuildParams['txt_ss']],
  983. 'sample_wo_article' => $CNF['T'][$aBuildParams['txt_ss']],
  984. 'sample_action' => isset($CNF['T'][$aBuildParams['txt_sa']]) ? $CNF['T'][$aBuildParams['txt_sa']] : '',
  985. 'url' => $sUrl,
  986. 'title' => '',
  987. 'text' => '',
  988. 'images' => $aImages,
  989. 'videos' => array()
  990. );
  991. }
  992. protected function _entityComments($sObject, $iId = 0)
  993. {
  994. if(!$iId)
  995. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  996. if(!$iId)
  997. $iId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  998. if(!$iId)
  999. return false;
  1000. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  1001. if(!$oCmts || !$oCmts->isEnabled())
  1002. return false;
  1003. return $oCmts->getCommentsBlock(array(), array('in_designbox' => false));
  1004. }
  1005. protected function _getContent($iContentId = 0, $sFuncGetContent = 'getContentInfoById')
  1006. {
  1007. if(!$iContentId && bx_get('id') === false && bx_get('profile_id') !== false) {
  1008. $oProfile = BxDolProfile::getInstance((int)bx_get('profile_id'));
  1009. if($oProfile)
  1010. $iContentId = $oProfile->getContentId();
  1011. }
  1012. return parent::_getContent($iContentId, $sFuncGetContent);
  1013. }
  1014. }
  1015. /** @} */