BxBaseModProfileModule.php 98 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506
  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. define('BX_DOL_PROFILE_REDIRECT_HOMEPAGE', 'homepage');
  15. define('BX_DOL_PROFILE_ACTIVATE_ALWAYS', 'on');
  16. define('BX_DOL_PROFILE_ACTIVATE_NEVER', 'off');
  17. define('BX_DOL_PROFILE_ACTIVATE_ADD', 'add');
  18. define('BX_DOL_PROFILE_ACTIVATE_EDIT', 'edit');
  19. /**
  20. * Base class for profile modules.
  21. */
  22. class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolContentInfoService, iBxDolProfileService
  23. {
  24. protected $_iAccountId;
  25. function __construct(&$aModule)
  26. {
  27. parent::__construct($aModule);
  28. $CNF = &$this->_oConfig->CNF;
  29. if(!empty($CNF['FIELD_ALLOW_POST_TO']))
  30. $this->_aSearchableNamesExcept[] = $CNF['FIELD_ALLOW_POST_TO'];
  31. if(!empty($CNF['FIELD_ALLOW_CONTACT_TO']))
  32. $this->_aSearchableNamesExcept[] = $CNF['FIELD_ALLOW_CONTACT_TO'];
  33. $this->_iAccountId = getLoggedId();
  34. }
  35. public function actionDeleteProfileImg($iFileId, $iContentId, $sFieldPicture)
  36. {
  37. $aResult = array();
  38. $CNF = &$this->_oConfig->CNF;
  39. $oSrorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  40. if (!($aFile = $oSrorage->getFile((int)$iFileId)) || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)) || $aContentInfo[$sFieldPicture] != (int)$iFileId)
  41. $aResult = array('error' => 1, 'msg' => _t('_sys_storage_err_file_not_found'));
  42. $oAccountProfile = BxDolProfile::getInstanceAccountProfile();
  43. if ($oAccountProfile)
  44. $iAccountProfileId = $oAccountProfile->id();
  45. if ((!$aResult && !isLogged()) || (!$aResult && $aFile['profile_id'] != $iAccountProfileId && !$this->_isModerator()))
  46. $aResult = array('error' => 2, 'msg' => _t('_Access denied'));
  47. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oTemplate);
  48. if (!$aResult && !$oForm->_deleteFile($iContentId, $sFieldPicture, (int)$iFileId, true))
  49. $aResult = array('error' => 3, 'msg' => _t('_Failed'));
  50. elseif (!$aResult)
  51. $aResult = array('error' => 0, 'msg' => '');
  52. header('Content-Type: application/json; charset=utf-8');
  53. echo json_encode($aResult);
  54. }
  55. public function actionProfileCalendarData()
  56. {
  57. $iProfileId = (int)bx_get('profile_id');
  58. $aEntries = array();
  59. $BxDolModuleQuery = BxDolModuleQuery::getInstance();
  60. $aModules = $BxDolModuleQuery->getModulesBy(array('type' => 'modules', 'active' => 1));
  61. foreach($aModules as $aModule){
  62. $sModuleName = $aModule['name'];
  63. $oModule = BxDolModule::getInstance($sModuleName);
  64. if($oModule instanceof iBxDolCalendarService){
  65. if(BxDolRequest::serviceExists($sModuleName, 'get_calendar_entries')){
  66. $aEntries2 = BxDolService::call($sModuleName, 'get_calendar_entries', array($iProfileId));
  67. $aEntries = array_merge($aEntries, $aEntries2);
  68. }
  69. }
  70. }
  71. header('Content-Type: application/json; charset=utf-8');
  72. echo json_encode($aEntries);
  73. }
  74. public function actionEmbed($iContentId, $sUnitTemplate = '', $sAddCode = '')
  75. {
  76. return parent::actionEmbed($iContentId, 'unit_with_cover.html');
  77. }
  78. // ====== SERVICE METHODS
  79. public function serviceGetSafeServices()
  80. {
  81. $a = parent::serviceGetSafeServices();
  82. return array_merge($a, array (
  83. 'ProfileUnitSafe' => '',
  84. 'ProfileUrl' => '',
  85. 'EntityCreate' => '',
  86. 'BrowseRecommended' => '',
  87. 'BrowseRecentProfiles' => '',
  88. 'BrowseActiveProfiles' => '',
  89. 'BrowseTopProfiles' => '',
  90. 'BrowseOnlineProfiles' => '',
  91. 'BrowseConnections' => '',
  92. 'BrowseConnectionsEverywhere' => '',
  93. 'BrowseByAcl' => '',
  94. ));
  95. }
  96. public function serviceGetOptionsRedirectAfterAdd()
  97. {
  98. $CNF = &$this->_oConfig->CNF;
  99. $aResult = array();
  100. $aChoices = array(BX_DOL_PROFILE_REDIRECT_PROFILE, BX_DOL_PROFILE_REDIRECT_LAST, BX_DOL_PROFILE_REDIRECT_CUSTOM, BX_DOL_PROFILE_REDIRECT_HOMEPAGE);
  101. foreach($aChoices as $sChoice)
  102. $aResult[] = array('key' => $sChoice, 'value' => _t($CNF['T']['option_redirect_aadd_' . $sChoice]));
  103. return $aResult;
  104. }
  105. public function serviceGetOptionsActivation()
  106. {
  107. $CNF = &$this->_oConfig->CNF;
  108. $aResult = array();
  109. $aChoices = array(BX_DOL_PROFILE_ACTIVATE_ALWAYS, BX_DOL_PROFILE_ACTIVATE_NEVER, BX_DOL_PROFILE_ACTIVATE_ADD, BX_DOL_PROFILE_ACTIVATE_EDIT);
  110. foreach($aChoices as $sChoice)
  111. $aResult[] = array('key' => $sChoice, 'value' => _t($CNF['T']['option_activation_' . $sChoice]));
  112. return $aResult;
  113. }
  114. public function serviceGetThumb ($iContentId, $sTranscoder = '')
  115. {
  116. $CNF = &$this->_oConfig->CNF;
  117. if(bx_is_api()){
  118. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  119. return bx_api_get_image($CNF['OBJECT_STORAGE'], $aContentInfo[$CNF['FIELD_PICTURE']]);
  120. }
  121. if(empty($sTranscoder) && !empty($CNF['OBJECT_IMAGES_TRANSCODER_THUMB']))
  122. $sTranscoder = $CNF['OBJECT_IMAGES_TRANSCODER_THUMB'];
  123. $mixedResult = $this->_getFieldValueThumb('FIELD_PICTURE', $iContentId, $sTranscoder);
  124. return $mixedResult !== false ? $mixedResult : '';
  125. }
  126. public function serviceGetCover ($iContentId, $sTranscoder = '')
  127. {
  128. $CNF = &$this->_oConfig->CNF;
  129. if(bx_is_api()){
  130. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  131. $aTmp = bx_api_get_image($CNF['OBJECT_STORAGE'], $aContentInfo[$CNF['FIELD_COVER']]);
  132. if (!$aTmp){
  133. return ['storage' => $CNF['OBJECT_STORAGE']];
  134. }
  135. return $aTmp;
  136. }
  137. if(empty($sTranscoder) && !empty($CNF['OBJECT_IMAGES_TRANSCODER_COVER']))
  138. $sTranscoder = $CNF['OBJECT_IMAGES_TRANSCODER_COVER'];
  139. $mixedResult = $this->_getFieldValueThumb('FIELD_COVER', $iContentId, $sTranscoder);
  140. return $mixedResult !== false ? $mixedResult : '';
  141. }
  142. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  143. {
  144. if(empty($sUnitTemplate))
  145. $sUnitTemplate = 'unit_with_cover.html';
  146. return parent::serviceGetSearchResultUnit($iContentId, $sUnitTemplate);
  147. }
  148. public function serviceGetSearchableFieldsExtended($aInputsAdd = array())
  149. {
  150. $CNF = &$this->_oConfig->CNF;
  151. $aResult = parent::serviceGetSearchableFieldsExtended($aInputsAdd);
  152. if(!$this->serviceActAsProfile())
  153. return $aResult;
  154. if(!in_array('online', $this->_aSearchableNamesExcept))
  155. $aResult['online'] = array(
  156. 'type' => 'checkbox',
  157. 'caption' => $CNF['T']['form_field_online'],
  158. 'info' => '',
  159. 'value' => '1',
  160. 'values' => '',
  161. 'pass' => ''
  162. );
  163. if(!empty($CNF['FIELD_PICTURE']) && !in_array($CNF['FIELD_PICTURE'], $this->_aSearchableNamesExcept))
  164. $aResult[$CNF['FIELD_PICTURE']] = array(
  165. 'type' => 'checkbox',
  166. 'caption' => $CNF['T']['form_field_picture'],
  167. 'info' => '',
  168. 'value' => '1',
  169. 'values' => '',
  170. 'pass' => '',
  171. 'search_operator' => '>='
  172. );
  173. return $aResult;
  174. }
  175. /**
  176. * @page service Service Calls
  177. * @section bx_base_profile Base Profile
  178. * @subsection bx_base_profile-general General
  179. * @subsubsection bx_base_profile-entity_calendar entity_calendar
  180. *
  181. * @code bx_srv('bx_persons', 'entity_calendar', [...]); @endcode
  182. *
  183. * Get calendar block
  184. * @param $iContentId content ID
  185. *
  186. * @see BxBaseModProfileModule::serviceEntityCalendar
  187. */
  188. /**
  189. * @ref bx_base_profile-entity_calendar "entity_calendar"
  190. */
  191. public function serviceEntityCalendar($iContentId = 0, $sTemplate = 'calendar.html')
  192. {
  193. $iContentId = $this->_getContent($iContentId, false);
  194. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->_oConfig->getName());
  195. if($oProfile){
  196. $o = new BxTemplCalendar(array(
  197. 'eventSources' => array (
  198. bx_append_url_params(BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'profile_calendar_data', array('profile_id' => $oProfile->id())),
  199. ),
  200. ), $this->_oTemplate);
  201. return $o->display($sTemplate);
  202. }
  203. return '';
  204. }
  205. public function servicePrivateProfileMsg()
  206. {
  207. $sMessage = '';
  208. $mixedContent = $this->_getContent();
  209. if($mixedContent) {
  210. list($iContentId, $aContentInfo) = $mixedContent;
  211. $sMessage = $this->checkAllowedView($aContentInfo);
  212. }
  213. else
  214. $sMessage = MsgBox(_t('_sys_access_denied_to_private_content'));
  215. return !$this->_bIsApi ? $sMessage : [bx_api_get_msg($sMessage, ['ext' => ['msg_type' => 'result']])];
  216. }
  217. public function serviceGetContentInfoById($iContentId)
  218. {
  219. return $this->_oDb->getContentInfoById((int)$iContentId);
  220. }
  221. public function serviceGetContentInfoByProfileId($iProfileId)
  222. {
  223. return $this->_oDb->getContentInfoByProfileId((int)$iProfileId);
  224. }
  225. public function serviceGetMenuAddonManageTools()
  226. {
  227. $CNF = &$this->_oConfig->CNF;
  228. $iNumTotal = $this->_oDb->getEntriesNumByParams();
  229. $iNum1 = $this->_oDb->getEntriesNumByParams([
  230. [
  231. 'key' => 'status',
  232. 'table' => 'sys_profiles',
  233. 'value' => BX_PROFILE_STATUS_PENDING,
  234. 'operator' => '='
  235. ]
  236. ]);
  237. $iNum2 = 0;
  238. if (isset($CNF['OBJECT_REPORTS'])){
  239. $iNum2 = $this->_oDb->getEntriesNumByParams([
  240. [
  241. 'key' => 'reports',
  242. 'value' => '0',
  243. 'operator' => '>'
  244. ]
  245. ]);
  246. }
  247. return array('counter1_value' => $iNum1, 'counter2_value' => $iNum2, 'counter3_value' => $iNumTotal, 'counter1_caption' => _t('_sys_menu_dashboard_manage_tools_addon_counter1_caption_profile_default'));
  248. }
  249. public function serviceGetMenuAddonManageToolsProfileStats($iProfileId = 0)
  250. {
  251. if(!$iProfileId)
  252. $iProfileId = bx_get_logged_profile_id();
  253. $aAccountInfo = BxDolProfileQuery::getInstance()->getAccountInfoByProfileId($iProfileId);
  254. if(empty($aAccountInfo) || !is_array($aAccountInfo))
  255. return 0;
  256. bx_import('SearchResult', $this->_aModule);
  257. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  258. $o = new $sClass();
  259. $o->fillFilters([
  260. 'account_id' => $aAccountInfo['id'],
  261. 'perofileStatus' => ''
  262. ]);
  263. $o->unsetPaginate();
  264. return $o->getNum();
  265. }
  266. public function serviceGetMenuAddonFavoritesProfileStats()
  267. {
  268. bx_import('SearchResult', $this->_aModule);
  269. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  270. $o = new $sClass('favorite', array('user' => bx_get_logged_profile_id()));
  271. $o->unsetPaginate();
  272. return $o->getNum();
  273. }
  274. public function serviceGetSubmenuObject ()
  275. {
  276. return $this->_oConfig->CNF['OBJECT_MENU_SUBMENU_VIEW_ENTRY'];
  277. }
  278. public function serviceGetMenuSetNameForMenuTrigger ($sMenuTriggerName)
  279. {
  280. $CNF = &$this->_oConfig->CNF;
  281. if (isset($CNF['TRIGGER_MENU_PROFILE_VIEW_SUBMENU']) && $CNF['TRIGGER_MENU_PROFILE_VIEW_SUBMENU'] == $sMenuTriggerName)
  282. return $CNF['OBJECT_MENU_SUBMENU_VIEW_ENTRY'];
  283. elseif (isset($CNF['TRIGGER_MENU_PROFILE_SNIPPET_META']) && $CNF['TRIGGER_MENU_PROFILE_SNIPPET_META'] == $sMenuTriggerName)
  284. return $CNF['OBJECT_MENU_SNIPPET_META'];
  285. else if (isset($CNF['TRIGGER_MENU_PROFILE_VIEW_ACTIONS']) && $CNF['TRIGGER_MENU_PROFILE_VIEW_ACTIONS'] == $sMenuTriggerName) {
  286. if(empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL']))
  287. return $CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY'];
  288. else
  289. return array($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY'], $CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL']);
  290. }
  291. return '';
  292. }
  293. public function serviceGetSnippetMenuVars($iProfileId, $bPublic = null, $aParams = [])
  294. {
  295. return $this->_oTemplate->getSnippetMenuVars($iProfileId, $bPublic, $aParams);
  296. }
  297. public function serviceGetPageObjectForPageTrigger ($sPageTriggerName)
  298. {
  299. if (isset($this->_oConfig->CNF['TRIGGER_PAGE_VIEW_ENTRY']) && $this->_oConfig->CNF['TRIGGER_PAGE_VIEW_ENTRY'] == $sPageTriggerName)
  300. return $this->_oConfig->CNF['OBJECT_PAGE_VIEW_ENTRY'];
  301. return '';
  302. }
  303. public function serviceProfilesSearch ($sTerm, $iLimit)
  304. {
  305. $aRet = array();
  306. $a = $this->_oDb->searchByTerm($sTerm, $iLimit);
  307. foreach ($a as $r) {
  308. $oProfile = BxDolProfile::getInstance($r['profile_id']);
  309. if (bx_is_api()) {
  310. $aData = $oProfile->getUnitAPI(0, ['template' => 'unit_wo_info']);
  311. $aRet[] = $aData['author_data'];
  312. }
  313. else{
  314. $aRet[] = array (
  315. 'label' => $this->serviceProfileName($r['content_id']),
  316. 'value' => $r['profile_id'],
  317. 'url' => $oProfile->getUrl(),
  318. 'thumb' => $oProfile->getThumb(),
  319. 'unit' => $oProfile->getUnit(0, ['template' => ['name' => 'unit_wo_info', 'size' => 'icon']])
  320. );
  321. }
  322. }
  323. return $aRet;
  324. }
  325. /**
  326. * @page service Service Calls
  327. * @section bx_base_profile Base Profile
  328. * @subsection bx_base_profile-general General
  329. * @subsubsection bx_base_profile-profile_unit_safe profile_unit_safe
  330. *
  331. * @code bx_srv('bx_persons', 'profile_unit_safe', [...]); @endcode
  332. *
  333. * Get profile unit
  334. * @param $iContentId content ID
  335. *
  336. * @see BxBaseModProfileModule::serviceProfileUnitSafe
  337. */
  338. /**
  339. * @ref bx_base_profile-profile_unit_safe "profile_unit_safe"
  340. */
  341. public function serviceProfileUnitSafe ($iContentId, $aParams = array())
  342. {
  343. unset($aParams['check_private_content']);
  344. return $this->serviceProfileUnit ($iContentId, $aParams);
  345. }
  346. public function serviceProfileUnit ($iContentId, $aParams = [])
  347. {
  348. $mixedContent = $this->_getContent($iContentId);
  349. if($mixedContent === false)
  350. return false;
  351. list($iContentId, $aContentInfo) = $mixedContent;
  352. $bCheckPrivateContent = isset($aParams['check_private_content']) ? (bool)$aParams['check_private_content'] : true;
  353. $aUnitTemplate = ['name' => 'unit.html', 'size' => false, 'vars' => []];
  354. if(!empty($aParams['template'])) {
  355. $mixedTemplate = $aParams['template'];
  356. unset($aParams['template']);
  357. if(is_string($mixedTemplate))
  358. $aUnitTemplate['name'] = $mixedTemplate . '.html';
  359. else if(is_array($mixedTemplate)) {
  360. if(!empty($mixedTemplate['name']))
  361. $aUnitTemplate['name'] = $mixedTemplate['name'] . '.html';
  362. if(!empty($mixedTemplate['size']))
  363. $aUnitTemplate['size'] = $mixedTemplate['size'];
  364. if(!empty($mixedTemplate['vars']))
  365. $aUnitTemplate['vars'] = $mixedTemplate['vars'];
  366. }
  367. }
  368. $aUnitParams = [];
  369. if(!empty($aParams))
  370. $aUnitParams = $aParams;
  371. return $this->_oTemplate->unit($aContentInfo, $bCheckPrivateContent, array_values($aUnitTemplate), $aUnitParams);
  372. }
  373. public function serviceProfileUnitApi ($iContentId, $aParams = [])
  374. {
  375. $mixedContent = $this->_getContent($iContentId);
  376. if($mixedContent === false)
  377. return false;
  378. list($iContentId, $aContentInfo) = $mixedContent;
  379. return $this->_oTemplate->unitAPI($aContentInfo, $aParams);
  380. }
  381. public function serviceHasImage ($iContentId)
  382. {
  383. $CNF = &$this->_oConfig->CNF;
  384. $mixedContent = $this->_getContent($iContentId, 'getContentInfoById');
  385. if($mixedContent === false)
  386. return false;
  387. list($iContentId, $aContentInfo) = $mixedContent;
  388. return !empty($aContentInfo[$CNF['FIELD_PICTURE']]);
  389. }
  390. public function serviceProfilePicture ($iContentId)
  391. {
  392. return $this->_serviceTemplateFunc('urlPicture', $iContentId);
  393. }
  394. public function serviceProfileAvatar ($iContentId)
  395. {
  396. return $this->_serviceTemplateFunc('urlAvatar', $iContentId);
  397. }
  398. public function serviceProfileAvatarBig ($iContentId)
  399. {
  400. return $this->_serviceTemplateFunc('urlAvatarBig', $iContentId);
  401. }
  402. public function serviceProfileCover ($iContentId)
  403. {
  404. return $this->_serviceTemplateFunc('urlCover', $iContentId);
  405. }
  406. public function serviceProfileUnitCover ($iContentId)
  407. {
  408. return $this->_serviceTemplateFunc('urlCoverUnit', $iContentId);
  409. }
  410. public function serviceProfileEditUrl ($iContentId)
  411. {
  412. return bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $this->_oConfig->CNF['URI_EDIT_ENTRY'] . '&id=' . $iContentId));
  413. }
  414. public function serviceProfileThumb ($iContentId)
  415. {
  416. return $this->_serviceTemplateFunc('urlThumb', $iContentId);
  417. }
  418. public function serviceProfileIcon ($iContentId)
  419. {
  420. return $this->_serviceTemplateFunc('urlIcon', $iContentId);
  421. }
  422. public function serviceProfileName ($iContentId)
  423. {
  424. if (!$iContentId)
  425. return false;
  426. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  427. if (!$aContentInfo)
  428. return false;
  429. $sDisplayName = $this->getProfileName($aContentInfo);
  430. /**
  431. * @hooks
  432. * @hookdef hook-bx_base_profile-profile_name '{module_name}', 'profile_name' - hook to override profile display name
  433. * - $unit_name - module name
  434. * - $action - equals `profile_name`
  435. * - $object_id - profile id
  436. * - $sender_id - not used
  437. * - $extra_params - array of additional params with the following array keys:
  438. * - `info` - [array] profile info array as key&value pairs
  439. * - `display_name` - [string] by ref, profile display name, can be overridden in hook processing
  440. * @hook @ref hook-bx_base_profile-profile_name
  441. */
  442. bx_alert($this->getName(), 'profile_name', $aContentInfo['profile_id'], 0, [
  443. 'info' => $aContentInfo,
  444. 'display_name' => &$sDisplayName
  445. ]);
  446. return $sDisplayName;
  447. }
  448. public function serviceProfileSettings ($iContentId)
  449. {
  450. if (!$iContentId)
  451. return false;
  452. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  453. if (!$aContentInfo)
  454. return false;
  455. if (isset($aContentInfo['settings']))
  456. return json_decode($aContentInfo['settings']);
  457. }
  458. public function serviceProfileSettingsSet ($iContentId, $oValue)
  459. {
  460. $CNF = $this->_oConfig->CNF;
  461. $this->_oDb->updateEntriesBy(['settings' => json_encode($oValue)], [$CNF['FIELD_ID'] => $iContentId]);
  462. }
  463. public function serviceProfileCreateUrl ($bAbsolute = true)
  464. {
  465. $CNF = $this->_oConfig->CNF;
  466. if(empty($CNF['URL_CREATE']))
  467. return false;
  468. return $bAbsolute ? bx_absolute_url(BxDolPermalinks::getInstance()->permalink($CNF['URL_CREATE'])) : $CNF['URL_CREATE'];
  469. }
  470. /**
  471. * @page service Service Calls
  472. * @section bx_base_profile Base Profile
  473. * @subsection bx_base_profile-general General
  474. * @subsubsection bx_base_profile-profile_url profile_url
  475. *
  476. * @code bx_srv('bx_persons', 'profile_url', [...]); @endcode
  477. *
  478. * Get profile URL
  479. * @param $iContentId content ID
  480. *
  481. * @see BxBaseModProfileModule::serviceProfileUrl
  482. */
  483. /**
  484. * @ref bx_base_profile-profile_url "profile_url"
  485. */
  486. public function serviceProfileUrl ($iContentId)
  487. {
  488. if (!$iContentId)
  489. return false;
  490. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  491. if (!$aContentInfo)
  492. return false;
  493. $CNF = $this->_oConfig->CNF;
  494. return bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]));
  495. }
  496. /**
  497. * @see iBxDolProfileService::serviceGetSpaceTitle
  498. */
  499. public function serviceGetSpaceTitle()
  500. {
  501. return _t('_sys_ps_space_title_friend');
  502. }
  503. /**
  504. * @see iBxDolProfileService::serviceGetParticipatingProfiles
  505. */
  506. public function serviceGetParticipatingProfiles($iProfileId, $aConnectionObjects = false)
  507. {
  508. if (false === $aConnectionObjects)
  509. $aConnectionObjects = array('sys_profiles_friends');
  510. $a = array();
  511. foreach ($aConnectionObjects as $sConnectionObject) {
  512. if (!($o = BxDolConnection::getObjectInstance($sConnectionObject)))
  513. continue;
  514. if (BX_CONNECTIONS_TYPE_MUTUAL == $o->getType())
  515. $a = array_merge($a, $o->getConnectedContentByType($iProfileId, $this->getName(), true));
  516. else
  517. $a = array_merge($a, $o->getConnectedContentByType($iProfileId, $this->getName()));
  518. }
  519. $aRet = array_unique($a);
  520. // the check for an ability to post in profile has been moved to BxDolPrivacy because we need to have an extended check
  521. // with an ability to check for extended roles taking into account the type of content which is going be posted/edited
  522. // so now this service returns just a fans, not filtered by an ability to post into an entry's context
  523. /*foreach ($a as $iConnectedProfileId) {
  524. if (!($oConnectedProfile = BxDolProfile::getInstance($iConnectedProfileId)))
  525. continue;
  526. if (CHECK_ACTION_RESULT_ALLOWED === bx_srv($oConnectedProfile->getModule(), 'check_allowed_post_in_profile', array($oConnectedProfile->getContentId(), $iProfileId)))
  527. $aRet[] = $iConnectedProfileId;
  528. }*/
  529. /**
  530. * @hooks
  531. * @hookdef hook-system-get_participating_profiles 'system', 'get_participating_profiles' - hook to override context participants list
  532. * - $unit_name - equals `system`
  533. * - $action - equals `get_participating_profiles`
  534. * - $object_id - context profile id
  535. * - $sender_id - not used
  536. * - $extra_params - array of additional params with the following array keys:
  537. * - `module` - [string] module name
  538. * - `profiles` - [array] by ref, a list of participating profiles ids, can be overridden in hook processing
  539. * @hook @ref hook-system-get_participating_profiles
  540. */
  541. bx_alert('system', 'get_participating_profiles', $iProfileId, false, [
  542. 'module' => $this->_oConfig->getName(),
  543. 'profiles' => &$aRet
  544. ]);
  545. return $aRet;
  546. }
  547. /**
  548. * Prepare fields from some universal set of fields to fields in particular profile module.
  549. * By default only 'name' and 'description' fields are supported.
  550. * After fields convertion it can be used in @see BxBaseModGeneralModule::serviceEntityAdd
  551. * @param $aFieldsProfile fields in soem universal format.
  552. * @return array which is ready to use for particular module
  553. */
  554. public function servicePrepareFields ($aFieldsProfile)
  555. {
  556. /**
  557. * @hooks
  558. * @hookdef hook-bx_base_profile-prepare_fields '{module_name}', 'prepare_fields' - hook to override prepared profile fields
  559. * - $unit_name - module name
  560. * - $action - equals `prepare_fields`
  561. * - $object_id - not used
  562. * - $sender_id - not used
  563. * - $extra_params - array of additional params with the following array keys:
  564. * - `fields_orig` - [array] original fields array as key&value pairs
  565. * - `fields_result` - [array] by ref, resulting fields array as key&value pairs, can be overridden in hook processing
  566. * @hook @ref hook-bx_base_profile-prepare_fields
  567. */
  568. bx_alert($this->getName(), 'prepare_fields', 0, 0, [
  569. 'fields_orig' => $aFieldsProfile,
  570. 'fields_result' => &$aFieldsProfile
  571. ]);
  572. return $aFieldsProfile;
  573. }
  574. protected function _servicePrepareFields ($aFieldsProfile, $aFieldsDefault, $aMap)
  575. {
  576. $aFieldsOrig = $aFieldsProfile;
  577. bx_import('BxDolPrivacy');
  578. $aFieldsDefault2 = array(
  579. 'allow_view_to' => BX_DOL_PG_ALL,
  580. 'allow_contact_to' => BX_DOL_PG_ALL,
  581. 'allow_post_to' => BX_DOL_PG_FRIENDS,
  582. );
  583. $aFieldsProfile = array_merge($aFieldsDefault2, $aFieldsDefault, $aFieldsProfile);
  584. foreach ($aMap as $k => $v) {
  585. if (isset($aFieldsProfile[$v]))
  586. $aFieldsProfile[$k] = $aFieldsProfile[$v];
  587. if ($k != $v && !isset($aMap[$v]))
  588. unset($aFieldsProfile[$v]);
  589. }
  590. /**
  591. * @hooks
  592. * @hookdef hook-bx_base_profile-prepare_fields '{module_name}', 'prepare_fields' - hook to override prepared profile fields
  593. * - $unit_name - module name
  594. * - $action - equals `prepare_fields`
  595. * - $object_id - not used
  596. * - $sender_id - not used
  597. * - $extra_params - array of additional params with the following array keys:
  598. * - `fields_orig` - [array] original fields array as key&value pairs
  599. * - `fields_result` - [array] by ref, resulting fields array as key&value pairs, can be overridden in hook processing
  600. * @hook @ref hook-bx_base_profile-prepare_fields
  601. */
  602. bx_alert($this->getName(), 'prepare_fields', 0, 0, [
  603. 'fields_orig' => $aFieldsOrig,
  604. 'fields_result' => &$aFieldsProfile
  605. ]);
  606. return $aFieldsProfile;
  607. }
  608. public function serviceFormsHelper ()
  609. {
  610. return parent::serviceFormsHelper ();
  611. }
  612. /**
  613. * @page service Service Calls
  614. * @section bx_base_profile Base Profile
  615. * @subsection bx_base_profile-forms Forms
  616. * @subsubsection bx_base_profile-entity_create entity_create
  617. *
  618. * @code bx_srv('bx_persons', 'entity_create', [...]); @endcode
  619. *
  620. * Get profile creation form
  621. * @param $sDisplay optional form display name
  622. *
  623. * @see BxBaseModProfileModule::serviceEntityCreate
  624. */
  625. /**
  626. * @ref bx_base_profile-entity_create "entity_create"
  627. */
  628. public function serviceEntityCreate ($sDisplay = false)
  629. {
  630. BxDolInformer::getInstance($this->_oTemplate)->setEnabled(false);
  631. return parent::serviceEntityCreate ($sDisplay);
  632. }
  633. public function serviceActAsProfile ()
  634. {
  635. return true;
  636. }
  637. /**
  638. * @page service Service Calls
  639. * @section bx_base_profile Base Profile
  640. * @subsection bx_base_profile-browse Browse
  641. * @subsubsection bx_base_profile-browse_recommended browse_recommended
  642. *
  643. * @code bx_srv('bx_persons', 'browse_recommended', [...]); @endcode
  644. *
  645. * Browse recommended profiles
  646. * @param $sUnitView optional, unit view, for example - showcase
  647. * @param $bEmptyMessage optional, display or not "empty" message when there is no content
  648. * @param $bAjaxPaginate optional, use AJAX paginate or not
  649. *
  650. * @see BxBaseModProfileModule::serviceBrowseRecommended
  651. */
  652. /**
  653. * @ref bx_base_profile-browse_recommended "browse_recommended"
  654. */
  655. public function serviceBrowseRecommended ($sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = true)
  656. {
  657. if (!isLogged())
  658. return '';
  659. return $this->_serviceBrowse ('recommended', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  660. }
  661. /**
  662. * @page service Service Calls
  663. * @section bx_base_profile Base Profile
  664. * @subsection bx_base_profile-browse Browse
  665. * @subsubsection bx_base_profile-browse_recent_profiles browse_recent_profiles
  666. *
  667. * @code bx_srv('bx_persons', 'browse_recent_profiles', [...]); @endcode
  668. *
  669. * Browse recently joined profiles
  670. * @param $bEmptyMessage optional, display or not "empty" message when there is no content
  671. * @param $bAjaxPaginate optional, use AJAX paginate or not
  672. *
  673. * @see BxBaseModProfileModule::serviceBrowseRecentProfiles
  674. */
  675. /**
  676. * @ref bx_base_profile-browse_recent_profiles "browse_recent_profiles"
  677. */
  678. public function serviceBrowseRecentProfiles ($bDisplayEmptyMsg = false, $bAjaxPaginate = true, $sUnitView = false)
  679. {
  680. return $this->_serviceBrowse ('recent', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate);
  681. }
  682. /**
  683. * @page service Service Calls
  684. * @section bx_base_profile Base Profile
  685. * @subsection bx_base_profile-browse Browse
  686. * @subsubsection bx_base_profile-browse_active_profiles browse_active_profiles
  687. *
  688. * @code bx_srv('bx_persons', 'browse_active_profiles', [...]); @endcode
  689. *
  690. * Browse recently active profiles
  691. * @param $bEmptyMessage optional, display or not "empty" message when there is no content
  692. * @param $bAjaxPaginate optional, use AJAX paginate or not
  693. *
  694. * @see BxBaseModProfileModule::serviceBrowseActiveProfiles
  695. */
  696. /**
  697. * @ref bx_base_profile-browse_active_profiles "browse_active_profiles"
  698. */
  699. public function serviceBrowseActiveProfiles ($sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = false)
  700. {
  701. return $this->_serviceBrowse ('active', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  702. }
  703. /**
  704. * @page service Service Calls
  705. * @section bx_base_profile Base Profile
  706. * @subsection bx_base_profile-browse Browse
  707. * @subsubsection bx_base_profile-browse_familiar_profiles browse_familiar_profiles
  708. *
  709. * @code bx_srv('bx_persons', 'browse_familiar_profiles', [...]); @endcode
  710. *
  711. * Browse profiles you might be familiar with. By default using 'Profile Friends' connection.
  712. * @param $bEmptyMessage optional, display or not "empty" message when there is no content
  713. * @param $bAjaxPaginate optional, use AJAX paginate or not
  714. *
  715. * @see BxBaseModProfileModule::serviceBrowseFamiliarProfiles
  716. */
  717. /**
  718. * @ref bx_base_profile-browse_familiar_profiles "browse_familiar_profiles"
  719. */
  720. public function serviceBrowseFamiliarProfiles ($sConnection = '', $sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = false)
  721. {
  722. $aParams = [
  723. 'object' => 'sys_profiles_friends',
  724. 'profile' => bx_get_logged_profile_id(),
  725. ];
  726. if(!empty($sConnection)) {
  727. if(is_string($sConnection))
  728. $aParams['object'] = $sConnection;
  729. else if(is_array($sConnection))
  730. $aParams = array_merge($aParams, $sConnection);
  731. }
  732. if($sUnitView)
  733. $aParams['unit_view'] = $sUnitView;
  734. return $this->_serviceBrowse ('familiar', $aParams, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  735. }
  736. /**
  737. * @page service Service Calls
  738. * @section bx_base_profile Base Profile
  739. * @subsection bx_base_profile-browse Browse
  740. * @subsubsection bx_base_profile-browse_top_profiles browse_top_profiles
  741. *
  742. * @code bx_srv('bx_persons', 'browse_top_profiles', [...]); @endcode
  743. *
  744. * Browse top profiles
  745. * @param $bEmptyMessage optional, display or not "empty" message when there is no content
  746. * @param $bAjaxPaginate optional, use AJAX paginate or not
  747. *
  748. * @see BxBaseModProfileModule::serviceBrowseTopProfiles
  749. */
  750. /**
  751. * @ref bx_base_profile-browse_top_profiles "browse_top_profiles"
  752. */
  753. public function serviceBrowseTopProfiles ($bDisplayEmptyMsg = false, $bAjaxPaginate = false)
  754. {
  755. return $this->_serviceBrowse ('top', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate);
  756. }
  757. /**
  758. * @page service Service Calls
  759. * @section bx_base_profile Base Profile
  760. * @subsection bx_base_profile-browse Browse
  761. * @subsubsection bx_base_profile-browse_online_profiles browse_online_profiles
  762. *
  763. * @code bx_srv('bx_persons', 'browse_online_profiles', [...]); @endcode
  764. *
  765. * Browse online profiles
  766. * @param $bEmptyMessage optional, display or not "empty" message when there is no content
  767. * @param $bAjaxPaginate optional, use AJAX paginate or not
  768. *
  769. * @see BxBaseModProfileModule::serviceBrowseOnlineProfiles
  770. */
  771. /**
  772. * @ref bx_base_profile-browse_online_profiles "browse_online_profiles"
  773. */
  774. public function serviceBrowseOnlineProfiles ($bDisplayEmptyMsg = false, $bAjaxPaginate = false)
  775. {
  776. return $this->_serviceBrowse ('online', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate);
  777. }
  778. public function serviceBrowseConnections ($iProfileId, $sObjectConnections = 'sys_profiles_friends', $sConnectionsType = 'content', $iMutual = false, $iDesignBox = BX_DB_PADDING_DEF, $iProfileId2 = 0)
  779. {
  780. return $this->_serviceBrowse (
  781. 'connections', [
  782. 'object' => $sObjectConnections,
  783. 'type' => $sConnectionsType,
  784. 'mutual' => $iMutual,
  785. 'profile' => (int)$iProfileId,
  786. 'profile2' => (int)$iProfileId2
  787. ], $iDesignBox
  788. );
  789. }
  790. public function serviceBrowseRelationsQuick ($iProfileId, $sObjectConnections = 'sys_profiles_friends', $sConnectionsType = 'content', $iMutual = false, $iProfileId2 = 0)
  791. {
  792. // get connections object
  793. $oConnection = BxDolConnection::getObjectInstance($sObjectConnections);
  794. if (!$oConnection)
  795. return '';
  796. // set some vars
  797. $iStart = (int)bx_get('start');
  798. $iLimit = empty($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? 4 : getParam($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']);
  799. if (!$iLimit)
  800. $iLimit = 4;
  801. // get connections array
  802. bx_import('BxDolConnection');
  803. $aConnections = $oConnection->getConnectionsAsArrayExt($sConnectionsType, $iProfileId, $iProfileId2, $iMutual, $iStart, $iLimit + 1, BX_CONNECTIONS_ORDER_ADDED_DESC);
  804. if(empty($aConnections) || !is_array($aConnections))
  805. return '';
  806. $aResult = array();
  807. foreach($aConnections as $iProfile => $aConnection)
  808. $aResult[] = array(
  809. 'id' => $iProfile,
  810. 'info' => array(
  811. 'addon' => $oConnection->getRelationTranslation($aConnection['relation'])
  812. )
  813. );
  814. return $this->_serviceBrowseQuick($aResult, $iStart, $iLimit);
  815. }
  816. public function serviceBrowseConnectionsQuick ($iProfileId, $sObjectConnections = 'sys_profiles_friends', $sConnectionsType = 'content', $iMutual = false, $iProfileId2 = 0)
  817. {
  818. // get connections object
  819. $oConnection = BxDolConnection::getObjectInstance($sObjectConnections);
  820. if (!$oConnection)
  821. return '';
  822. // set some vars
  823. $iLimit = empty($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? 4 : getParam($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']);
  824. if (!$iLimit)
  825. $iLimit = 4;
  826. $iStart = (int)bx_get('start');
  827. // get connections array
  828. bx_import('BxDolConnection');
  829. $a = $oConnection->getConnectionsAsArray ($sConnectionsType, $iProfileId, $iProfileId2, $iMutual, (int)bx_get('start'), $iLimit + 1, BX_CONNECTIONS_ORDER_ADDED_DESC);
  830. if (!$a)
  831. return '';
  832. return $this->_serviceBrowseQuick($a, $iStart, $iLimit);
  833. }
  834. public function serviceBrowseConnectionsByType ($aParamsCnn, $aParamsBrs = array())
  835. {
  836. $sAll = 'all';
  837. $aParamsCnn['object'] = !empty($aParamsCnn['object']) ? $aParamsCnn['object'] : 'sys_profiles_friends';
  838. $aParamsCnn['type'] = !empty($aParamsCnn['type']) ? $aParamsCnn['type'] : 'content';
  839. $aParamsCnn['profile_id2'] = !empty($aParamsCnn['profile_id2']) ? (int)$aParamsCnn['profile_id2'] : 0;
  840. $aParamsCnn['mutual'] = isset($aParamsCnn['mutual']) ? $aParamsCnn['mutual'] : false;
  841. $oConnection = BxDolConnection::getObjectInstance($aParamsCnn['object']);
  842. if(!$oConnection)
  843. return '';
  844. $aSQLParts = $oConnection->getConnectionsAsSQLParts ($aParamsCnn['type'], 'sys_profiles', 'id', $aParamsCnn['profile_id'], $aParamsCnn['profile_id2'], $aParamsCnn['mutual']);
  845. $sType = !empty($aParamsBrs['type']) ? $aParamsBrs['type'] : $sAll;
  846. if(bx_get('type') !== false)
  847. $sType = bx_process_input(bx_get('type'));
  848. $iStart = (int)bx_get('start');
  849. $iLimitDefault = 4;
  850. $iLimit = !empty($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? getParam($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) : $iLimitDefault;
  851. if(!empty($aParamsBrs['per_page']))
  852. $iLimit = (int)$aParamsBrs['per_page'];
  853. if(!$iLimit)
  854. $iLimit = $iLimitDefault;
  855. $aProfiles = BxDolProfileQuery::getInstance()->getConnectedProfilesByType($aSQLParts, ($sType != $sAll ? $sType : ''), $iStart, $iLimit + 1);
  856. $mixedMenu = '';
  857. if(!isset($aParamsBrs['filter_menu']) || $aParamsBrs['filter_menu'] === true) {
  858. $aModules = array(
  859. array('name' => $sAll)
  860. );
  861. $aModules = array_merge($aModules, BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1)));
  862. $aMenuItems = array();
  863. foreach($aModules as $aModule)
  864. if($aModule['name'] == $sAll || BxDolRequest::serviceExists($aModule['name'], 'act_as_profile'))
  865. $aMenuItems[] = array(
  866. 'id' => $aModule['name'],
  867. 'name' => $aModule['name'],
  868. 'class' => '',
  869. 'link' => 'javascript:void(0)',
  870. 'onclick' => "return !loadDynamicBlockAutoPaginate(this, " . $iStart . ", " . $iLimit . ", " . bx_js_string(json_encode(array('type' => $aModule['name']))) . ");",
  871. 'target' => '_self',
  872. 'title' => _t('_' . $aModule['name']),
  873. 'active' => 1
  874. );
  875. if(!empty($aMenuItems)) {
  876. $mixedMenu = new BxTemplMenu(array('template' => 'menu_vertical.html', 'menu_id'=> $this->_oConfig->getName() . '-connections-by-type', 'menu_items' => $aMenuItems));
  877. $mixedMenu->setSelected('', $sType);
  878. }
  879. }
  880. return array(
  881. 'menu' => $mixedMenu,
  882. 'content' => $this->_serviceBrowseQuick(array_keys($aProfiles), $iStart, $iLimit, array('type' => $sType))
  883. );
  884. }
  885. /**
  886. * @page service Service Calls
  887. * @section bx_base_profile Base Profile
  888. * @subsection bx_base_profile-browse Browse
  889. * @subsubsection bx_base_profile-browse_by_acl browse_by_acl
  890. *
  891. * @code bx_srv('bx_persons', 'browse_by_acl', [...]); @endcode
  892. *
  893. * Browse profiles by membership(ACL) level
  894. * @param $mixedLevelId membership level, or array of membership levels
  895. * @param $iDesignBox optional, design box identifier
  896. *
  897. * @see BxBaseModProfileModule::serviceBrowseByAcl
  898. */
  899. /**
  900. * @ref bx_base_profile-browse_by_acl "browse_by_acl"
  901. */
  902. public function serviceBrowseByAcl ($mixedLevelId, $iDesignBox = BX_DB_PADDING_DEF)
  903. {
  904. return $this->_serviceBrowse (
  905. 'acl',
  906. array(
  907. 'level' => $mixedLevelId,
  908. ),
  909. $iDesignBox,
  910. true
  911. );
  912. }
  913. public function serviceEntityEditCover ($iContentId = 0)
  914. {
  915. return $this->_serviceEntityForm ('editDataForm', $iContentId, $this->_oConfig->CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT_COVER']);
  916. }
  917. /**
  918. * @page service Service Calls
  919. * @section bx_base_profile Base Profile
  920. * @subsection bx_base_profile-page_blocks Page Blocks
  921. * @subsubsection bx_base_profile-entity_cover entity_cover
  922. *
  923. * @code bx_srv('bx_persons', 'entity_cover', [...]); @endcode
  924. *
  925. * Get cover
  926. * @param $iContentId content ID
  927. *
  928. * @see BxBaseModProfileModule::serviceEntityCover
  929. */
  930. /**
  931. * @ref bx_base_general-entity_cover "entity_cover"
  932. */
  933. public function serviceEntityCover ($iContentId = 0, $aParams = [])
  934. {
  935. $mixedContent = $this->_getContent($iContentId);
  936. if($mixedContent === false)
  937. return false;
  938. list($iContentId, $aContentInfo) = $mixedContent;
  939. if($this->_bIsApi) {
  940. $CNF = &$this->_oConfig->CNF;
  941. $aContentInfo['cover'] = $this->serviceGetCover($iContentId);
  942. $aContentInfo['image'] = $this->serviceGetThumb($iContentId);
  943. $sKey = 'OBJECT_MENU_VIEW_ENTRY_META';
  944. if(!empty($CNF[$sKey]) && ($oMetaMenu = BxTemplMenu::getObjectInstance($CNF[$sKey])) !== false)
  945. $aContentInfo['meta_menu'] = $oMetaMenu->getCodeAPI();
  946. $sKey = 'OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL';
  947. if(!empty($CNF[$sKey]) && ($oActionMenu = BxTemplMenu::getObjectInstance($CNF[$sKey])) !== false)
  948. $aContentInfo['actions_menu'] = $oActionMenu->getCodeAPI();
  949. if(($oMenuManage = BxDolMenu::getObjectInstance('sys_site_manage')) !== false) {
  950. if(!empty($CNF['FIELD_ID']))
  951. $oMenuManage->setContentId($aContentInfo[$CNF['FIELD_ID']]);
  952. $aObjectManage = [];
  953. if(!empty($CNF['OBJECT_MENU_MANAGE_VIEW_ENTRY']))
  954. $aObjectManage = [$CNF['OBJECT_MENU_MANAGE_VIEW_ENTRY']];
  955. else if(!empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']))
  956. $aObjectManage = [$CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE'], true];
  957. call_user_func_array([$oMenuManage, 'setObjectManage'], $aObjectManage);
  958. $aMenuManage = $oMenuManage->getCodeAPI();
  959. if(!empty($aMenuManage) && is_array($aMenuManage)) {
  960. if(isset($aContentInfo['actions_menu']) && is_array($aContentInfo['actions_menu']))
  961. $aContentInfo['actions_menu']['items'] = array_merge($aContentInfo['actions_menu']['items'], $aMenuManage['items']);
  962. else
  963. $aContentInfo['actions_menu'] = $aMenuManage;
  964. }
  965. }
  966. if(($oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName())) !== false);
  967. $aContentInfo['profile'] = BxDolProfile::getData($oProfile, [
  968. 'get_avatar' => 'getAvatarBig',
  969. 'with_info' => false
  970. ]);
  971. return [bx_api_get_block('entity_cover', $aContentInfo)];
  972. }
  973. return $this->_oTemplate->getBlockCover($aContentInfo, $aParams);
  974. }
  975. /**
  976. * Entry comments
  977. */
  978. public function serviceEntityCommentsByProfile ($iProfileId)
  979. {
  980. $CNF = &$this->_oConfig->CNF;
  981. if(empty($CNF['OBJECT_COMMENTS']))
  982. return '';
  983. $oProfile = BxDolProfile::getInstance($iProfileId);
  984. if(!$oProfile)
  985. return '';
  986. return $this->_entityComments($CNF['OBJECT_COMMENTS'], $oProfile->getContentId());
  987. }
  988. /**
  989. * Entry social sharing block
  990. */
  991. public function serviceEntitySocialSharing ($mixedContent = false, $aParams = array())
  992. {
  993. if(!empty($mixedContent)) {
  994. if(!is_array($mixedContent))
  995. $mixedContent = array((int)$mixedContent, array());
  996. }
  997. else {
  998. $mixedContent = $this->_getContent();
  999. if($mixedContent === false)
  1000. return false;
  1001. }
  1002. list($iContentId, $aContentInfo) = $mixedContent;
  1003. return parent::serviceEntitySocialSharing(array($iContentId, $aContentInfo), array(
  1004. 'id_thumb' => !empty($CNF['FIELD_PICTURE']) && !empty($aContentInfo[$CNF['FIELD_PICTURE']]) ? $aContentInfo[$CNF['FIELD_PICTURE']] : 0,
  1005. ));
  1006. }
  1007. public function serviceProfileMembership ($iContentId = 0)
  1008. {
  1009. $mixedContent = $this->_getContent($iContentId);
  1010. if($mixedContent === false)
  1011. return false;
  1012. list($iContentId, $aContentInfo) = $mixedContent;
  1013. return BxDolAcl::getInstance()->getProfileMembership($aContentInfo['profile_id']);
  1014. }
  1015. public function serviceProfileFriends ($iContentId = 0)
  1016. {
  1017. $mixedContent = $this->_getContent($iContentId);
  1018. if($mixedContent === false)
  1019. return false;
  1020. list($iContentId, $aContentInfo) = $mixedContent;
  1021. bx_import('BxDolConnection');
  1022. $s = $this->serviceBrowseConnectionsQuick ($aContentInfo['profile_id'], 'sys_profiles_friends', BX_CONNECTIONS_CONTENT_TYPE_CONTENT, true);
  1023. if (!$s)
  1024. return MsgBox(_t('_sys_txt_empty'));
  1025. return $s;
  1026. }
  1027. public function serviceProfileFriendsMutual ($iContentId = 0)
  1028. {
  1029. $mixedContent = $this->_getContent($iContentId);
  1030. if($mixedContent === false)
  1031. return false;
  1032. list($iContentId, $aContentInfo) = $mixedContent;
  1033. $iViewer = bx_get_logged_profile_id();
  1034. $iOwner = (int)$aContentInfo['profile_id'];
  1035. if($iViewer == $iOwner)
  1036. return false;
  1037. bx_import('BxDolConnection');
  1038. $s = $this->serviceBrowseConnectionsQuick ($iOwner, 'sys_profiles_friends', BX_CONNECTIONS_CONTENT_TYPE_COMMON, true, $iViewer);
  1039. if(!$s)
  1040. return MsgBox(_t('_sys_txt_empty'));
  1041. return $s;
  1042. }
  1043. public function serviceProfileSubscriptions ($iContentId = 0, $aParams = array())
  1044. {
  1045. $mixedContent = $this->_getContent($iContentId);
  1046. if($mixedContent === false)
  1047. return false;
  1048. list($iContentId, $aContentInfo) = $mixedContent;
  1049. bx_import('BxDolConnection');
  1050. $aResult = $this->serviceBrowseConnectionsByType(array(
  1051. 'profile_id' => $aContentInfo['profile_id'],
  1052. 'object' => 'sys_profiles_subscriptions',
  1053. 'type' => BX_CONNECTIONS_CONTENT_TYPE_CONTENT
  1054. ), array(
  1055. 'type' => isset($aParams['type']) ? $aParams['type'] : '',
  1056. 'filter_menu' => isset($aParams['filter_menu']) ? $aParams['filter_menu'] : true,
  1057. ));
  1058. if(empty($aResult['content']))
  1059. $aResult['content'] = MsgBox(_t('_sys_txt_empty'));
  1060. return $aResult;
  1061. }
  1062. public function serviceProfileSubscribedMe ($iContentId = 0)
  1063. {
  1064. $mixedContent = $this->_getContent($iContentId);
  1065. if($mixedContent === false)
  1066. return false;
  1067. list($iContentId, $aContentInfo) = $mixedContent;
  1068. bx_import('BxDolConnection');
  1069. $s = $this->serviceBrowseConnectionsQuick ($aContentInfo['profile_id'], 'sys_profiles_subscriptions', BX_CONNECTIONS_CONTENT_TYPE_INITIATORS);
  1070. if (!$s)
  1071. return MsgBox(_t('_sys_txt_empty'));
  1072. return $s;
  1073. }
  1074. public function serviceProfileRelations ($iContentId = 0, $aParams = array())
  1075. {
  1076. if(!BxDolRelation::isEnabled())
  1077. return false;
  1078. $mixedContent = $this->_getContent($iContentId);
  1079. if($mixedContent === false)
  1080. return false;
  1081. list($iContentId, $aContentInfo) = $mixedContent;
  1082. bx_import('BxDolConnection');
  1083. $s = $this->serviceBrowseRelationsQuick ($aContentInfo['profile_id'], 'sys_profiles_relations', BX_CONNECTIONS_CONTENT_TYPE_CONTENT, 1);
  1084. if (!$s)
  1085. return MsgBox(_t('_sys_txt_empty'));
  1086. return $s;
  1087. }
  1088. public function serviceProfileRelatedMe ($iContentId = 0)
  1089. {
  1090. if(!BxDolRelation::isEnabled())
  1091. return false;
  1092. $mixedContent = $this->_getContent($iContentId);
  1093. if($mixedContent === false)
  1094. return false;
  1095. list($iContentId, $aContentInfo) = $mixedContent;
  1096. bx_import('BxDolConnection');
  1097. $s = $this->serviceBrowseRelationsQuick ($aContentInfo['profile_id'], 'sys_profiles_relations', BX_CONNECTIONS_CONTENT_TYPE_INITIATORS, 1);
  1098. if (!$s)
  1099. return MsgBox(_t('_sys_txt_empty'));
  1100. return $s;
  1101. }
  1102. /**
  1103. * check enabled profile activation letter
  1104. */
  1105. public function serviceIsEnableProfileActivationLetter()
  1106. {
  1107. $CNF = &$this->_oConfig->CNF;
  1108. return isset($CNF['PARAM_ENABLE_ACTIVATION_LETTER']) ? (bool)getParam($CNF['PARAM_ENABLE_ACTIVATION_LETTER']) : true;
  1109. }
  1110. public function serviceIsEnableRelations()
  1111. {
  1112. if(!BxDolRelation::isEnabled())
  1113. return false;
  1114. $sModule = $this->_oConfig->getName();
  1115. $oRelations = BxDolConnection::getObjectInstance('sys_profiles_relations');
  1116. return $oRelations->isRelationAvailableWithProfile($sModule) || $oRelations->isRelationAvailableFromProfile($sModule);
  1117. }
  1118. /**
  1119. * For internal usage only.
  1120. */
  1121. public function serviceDeleteEntityService ($iContentId, $bDeleteWithContent = false)
  1122. {
  1123. return parent::serviceDeleteEntity ($iContentId, 'deleteDataService');
  1124. }
  1125. /**
  1126. * Data for Notifications module
  1127. */
  1128. public function serviceGetNotificationsData()
  1129. {
  1130. $a = parent::serviceGetNotificationsData();
  1131. $sModule = $this->_aModule['name'];
  1132. $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');
  1133. $a['settings'][] = array('group' => 'timeline_post', 'unit' => $sModule, 'action' => 'timeline_post_common', 'types' => array('follow_member'));
  1134. $a['alerts'][] = array('unit' => $sModule, 'action' => 'timeline_post_common');
  1135. return $a;
  1136. }
  1137. public function serviceGetNotificationsPost($aEvent)
  1138. {
  1139. $aResult = parent::serviceGetNotificationsVote($aEvent);
  1140. if(empty($aResult) || !is_array($aResult) || !$this->serviceActAsProfile())
  1141. return $aResult;
  1142. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$aEvent['object_id'], $this->_oConfig->getName());
  1143. if($oProfile !== false)
  1144. $aResult['entry_author'] = $oProfile->id();
  1145. return $aResult;
  1146. }
  1147. public function serviceGetNotificationsVote($aEvent)
  1148. {
  1149. $aResult = parent::serviceGetNotificationsVote($aEvent);
  1150. if(empty($aResult) || !is_array($aResult) || !$this->serviceActAsProfile())
  1151. return $aResult;
  1152. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$aEvent['object_id'], $this->_oConfig->getName());
  1153. if($oProfile !== false)
  1154. $aResult['entry_author'] = $oProfile->id();
  1155. return $aResult;
  1156. }
  1157. /**
  1158. * Notification about new member requst in the group
  1159. */
  1160. public function serviceGetNotificationsTimelinePostCommon($aEvent)
  1161. {
  1162. $CNF = &$this->_oConfig->CNF;
  1163. $iContentId = (int)$aEvent['object_id'];
  1164. $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  1165. if(!$oGroupProfile)
  1166. return [];
  1167. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1168. if(empty($aContentInfo) || !is_array($aContentInfo))
  1169. return [];
  1170. $aSubcontentInfo = BxDolService::call('bx_timeline', 'get_info', array((int)$aEvent['subobject_id'], false));
  1171. if(empty($aSubcontentInfo) || !is_array($aSubcontentInfo))
  1172. return [];
  1173. $sEntrySummary = isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '';
  1174. $sSubentryUrl = bx_absolute_url(str_replace(BX_DOL_URL_ROOT, '', BxDolService::call('bx_timeline', 'get_link', array((int)$aEvent['subobject_id']))), '{bx_url_root}');
  1175. $sSubentrySample = $aSubcontentInfo['title'];
  1176. if(empty($sSubentrySample))
  1177. $sSubentrySample = strmaxtextlen($aSubcontentInfo['description'], 20, '...');
  1178. $sSubentrySummary = $aSubcontentInfo['description'];
  1179. return [
  1180. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1181. 'entry_url' => bx_absolute_url(str_replace(BX_DOL_URL_ROOT, '', $oGroupProfile->getUrl()), '{bx_url_root}'),
  1182. 'entry_caption' => $oGroupProfile->getDisplayName(),
  1183. 'entry_summary' => $sEntrySummary,
  1184. 'entry_author' => $oGroupProfile->id(),
  1185. 'subentry_sample' => $sSubentrySample,
  1186. 'subentry_url' => $sSubentryUrl,
  1187. 'subentry_summary' => $sSubentrySummary,
  1188. 'lang_key' => $CNF['T']['txt_ntfs_timeline_post_common'],
  1189. ];
  1190. }
  1191. /**
  1192. * Data for Timeline module
  1193. */
  1194. public function serviceGetTimelineData()
  1195. {
  1196. $CNF = &$this->_oConfig->CNF;
  1197. $sModule = $this->_aModule['name'];
  1198. $aAlerts = array();
  1199. $aHandlers = array();
  1200. if(!empty($CNF['FIELD_PICTURE'])) {
  1201. $aAlerts = array_merge($aAlerts, array(
  1202. array('unit' => $sModule, 'action' => 'profile_picture_changed'),
  1203. array('unit' => $sModule, 'action' => 'profile_picture_deleted')
  1204. ));
  1205. $aHandlers = array_merge($aHandlers, array(
  1206. 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' => ''),
  1207. array('group' => $sModule . '_profile_picture', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'profile_picture_deleted')
  1208. ));
  1209. }
  1210. if(!empty($CNF['FIELD_COVER'])) {
  1211. $aAlerts = array_merge($aAlerts, array(
  1212. array('unit' => $sModule, 'action' => 'profile_cover_changed'),
  1213. array('unit' => $sModule, 'action' => 'profile_cover_deleted')
  1214. ));
  1215. $aHandlers = array_merge($aHandlers, array(
  1216. 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' => ''),
  1217. array('group' => $sModule . '_profile_cover', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'profile_cover_deleted')
  1218. ));
  1219. }
  1220. $aResult = array();
  1221. if(!empty($aAlerts) && !empty($aHandlers))
  1222. $aResult = array(
  1223. 'handlers' => $aHandlers,
  1224. 'alerts' => $aAlerts
  1225. );
  1226. return $aResult;
  1227. }
  1228. /**
  1229. * Entry post for Timeline module
  1230. */
  1231. public function serviceGetTimelineProfilePicture($aEvent, $aBrowseParams = [])
  1232. {
  1233. $aResult = $this->_serviceGetTimelineProfileImage($aEvent, $aBrowseParams, [
  1234. 'stg' => 'OBJECT_STORAGE',
  1235. 'trans' => ['OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_AVATAR'],
  1236. 'trans_orig' => ['OBJECT_IMAGES_TRANSCODER_PICTURE', 'OBJECT_IMAGES_TRANSCODER_GALLERY'],
  1237. 'txt_ss' => 'txt_sample_pp_single',
  1238. 'txt_sswa' => 'txt_sample_pp_single_with_article',
  1239. 'txt_sa' => 'txt_sample_pi_action',
  1240. 'txt_sau' => 'txt_sample_pi_action_user'
  1241. ]);
  1242. if($aResult !== false)
  1243. $aResult['allowed_view'] = ['module' => $this->_oConfig->getName(), 'method' => 'get_timeline_profile_picture_allowed_view'];
  1244. return $aResult;
  1245. }
  1246. public function serviceGetTimelineProfilePictureAllowedView($aEvent)
  1247. {
  1248. return $this->_serviceGetTimelineProfileImageAllowedView($aEvent);
  1249. }
  1250. public function serviceGetTimelineProfileCover($aEvent, $aBrowseParams = [])
  1251. {
  1252. $aResult = $this->_serviceGetTimelineProfileImage($aEvent, $aBrowseParams, [
  1253. 'stg' => 'OBJECT_STORAGE_COVER',
  1254. 'trans' => ['OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_COVER_THUMB'],
  1255. 'trans_orig' => ['OBJECT_IMAGES_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_GALLERY'],
  1256. 'txt_ss' => 'txt_sample_pc_single',
  1257. 'txt_sswa' => 'txt_sample_pc_single_with_article',
  1258. 'txt_sa' => 'txt_sample_pi_action',
  1259. 'txt_sau' => 'txt_sample_pi_action_user'
  1260. ]);
  1261. if($aResult !== false)
  1262. $aResult['allowed_view'] = ['module' => $this->_oConfig->getName(), 'method' => 'get_timeline_profile_cover_allowed_view'];
  1263. return $aResult;
  1264. }
  1265. public function serviceGetTimelineProfileCoverAllowedView($aEvent)
  1266. {
  1267. return $this->_serviceGetTimelineProfileImageAllowedView($aEvent);
  1268. }
  1269. public function serviceGetMenuItemTitleByConnection($sConnection, $sAction, $iContentProfileId, $iInitiatorProfileId = 0)
  1270. {
  1271. return $this->getMenuItemTitleByConnection($sConnection, $sAction, $iContentProfileId, $iInitiatorProfileId);
  1272. }
  1273. // ====== PERMISSION METHODS
  1274. /**
  1275. * @see iBxDolProfileService::serviceCheckAllowedProfileView
  1276. */
  1277. public function serviceCheckAllowedProfileView($iContentId)
  1278. {
  1279. return $this->serviceCheckAllowedWithContent('View', $iContentId);
  1280. }
  1281. /**
  1282. * @see iBxDolProfileService::serviceCheckAllowedProfileContact
  1283. */
  1284. public function serviceCheckAllowedProfileContact($iContentId)
  1285. {
  1286. return $this->serviceCheckAllowedWithContent('Contact', $iContentId);
  1287. }
  1288. /**
  1289. * @see iBxDolProfileService::serviceCheckAllowedPostInProfile
  1290. */
  1291. public function serviceCheckAllowedPostInProfile($iContentId, $sPostModule = '')
  1292. {
  1293. $CNF = &$this->_oConfig->CNF;
  1294. if(!empty($CNF['FIELD_ALLOW_VIEW_TO']) && getParam('sys_treat_cxt_in_cxt_as_cnt') == 'on') {
  1295. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1296. if($aContentInfo && isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) && (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] < 0)
  1297. return _t('_sys_txt_access_denied');
  1298. }
  1299. // for groups based profiles we do have a Role permissions which have a higher priority than the site-wide permissions.
  1300. if (method_exists($this, 'isAllowedModuleActionByProfile')) {
  1301. $bResult = $this->isAllowedModuleActionByProfile($iContentId, $sPostModule, 'post');
  1302. // if a profile is having a role and a role is having permissions set then it overrides the site-wide setting.
  1303. if ($bResult !== NULL) return $bResult;
  1304. }
  1305. return $this->serviceCheckAllowedWithContent('Post', $iContentId);
  1306. }
  1307. /**
  1308. * @see iBxDolProfileService::serviceCheckAllowedModuleActionInProfile
  1309. */
  1310. public function serviceCheckAllowedModuleActionInProfile($iContentId, $sPostModule, $sActionName)
  1311. {
  1312. if (method_exists($this, 'isAllowedModuleActionByProfile')) {
  1313. $bResult = $this->isAllowedModuleActionByProfile($iContentId, $sPostModule, $sActionName);
  1314. if ($bResult !== NULL) return $bResult;
  1315. }
  1316. return _t('_Access denied');
  1317. }
  1318. /**
  1319. * @see iBxDolProfileService::serviceCheckSpacePrivacy
  1320. */
  1321. public function serviceCheckSpacePrivacy($iContentId)
  1322. {
  1323. return $this->serviceCheckAllowedProfileView($iContentId);
  1324. }
  1325. /**
  1326. * Check if the profile can be viewed.
  1327. *
  1328. * NOTE. This service should be used if it's needed to pass some specific values in
  1329. * $isPerformAction and $iProfileId parameters, otherwise it's recommended to use
  1330. * BxBaseModProfileModule::serviceCheckAllowedProfileView service method or
  1331. * BxDolProfile::checkAllowedProfileView method.
  1332. *
  1333. * @param type $aDataEntry - entry which the action will be performed for
  1334. * @param type $isPerformAction - perform or just check the action
  1335. * @param type $iProfileId - performer's profile ID
  1336. * @return integer - one of CHECK_ACTION_RESULT_XXX constants.
  1337. */
  1338. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  1339. {
  1340. if (!$iProfileId)
  1341. $iProfileId = $this->_iProfileId;
  1342. if(empty($aDataEntry) || !is_array($aDataEntry))
  1343. return _t('_sys_txt_not_found');
  1344. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  1345. if ($oProfile && $oProfile->id() == $iProfileId)
  1346. return CHECK_ACTION_RESULT_ALLOWED;
  1347. return parent::serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  1348. }
  1349. /**
  1350. * Check if posting (comment, post in Timeline) is available.
  1351. *
  1352. * NOTE. This service should be used if it's needed to pass some specific values in
  1353. * $isPerformAction and $iProfileId parameters, otherwise it's recommended to use
  1354. * BxBaseModProfileModule::serviceCheckAllowedPostInProfile service method or
  1355. * BxDolProfile::checkAllowedPostInProfile method.
  1356. *
  1357. * @param type $aDataEntry - entry which the action will be performed for
  1358. * @param type $isPerformAction - perform or just check the action
  1359. * @param type $iProfileId - performer's profile ID
  1360. * @return integer - one of CHECK_ACTION_RESULT_XXX constants.
  1361. */
  1362. public function serviceCheckAllowedPostForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  1363. {
  1364. $CNF = &$this->_oConfig->CNF;
  1365. if(!$iProfileId)
  1366. $iProfileId = $this->_iProfileId;
  1367. // check is view allowed
  1368. if(($mixedResult = $this->serviceCheckAllowedViewForProfile($aDataEntry, $isPerformAction, $iProfileId)) !== CHECK_ACTION_RESULT_ALLOWED)
  1369. return $mixedResult;
  1370. // moderator and owner always have access
  1371. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->getName());
  1372. if(($oProfile && $oProfile->id() == $iProfileId) || $this->_isModerator($isPerformAction))
  1373. return CHECK_ACTION_RESULT_ALLOWED;
  1374. // check privacy
  1375. if(!empty($CNF['OBJECT_PRIVACY_POST'])) {
  1376. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_POST']);
  1377. if($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  1378. return _t('_sys_access_denied_to_private_content');
  1379. }
  1380. // check alert to allow custom checks
  1381. $mixedResult = null;
  1382. /**
  1383. * @hooks
  1384. * @hookdef hook-system-check_allowed_post 'system', 'check_allowed_post' - hook to override the result of checking whether 'post' action is allowed or not to specified profile
  1385. * It's equivalent to @ref hook-system-check_allowed_view
  1386. * @hook @ref hook-system-check_allowed_post
  1387. */
  1388. bx_alert('system', 'check_allowed_post', 0, 0, [
  1389. 'module' => $this->getName(),
  1390. 'content_info' => $aDataEntry,
  1391. 'profile_id' => $iProfileId,
  1392. 'override_result' => &$mixedResult
  1393. ]);
  1394. if($mixedResult !== null)
  1395. return $mixedResult;
  1396. return CHECK_ACTION_RESULT_ALLOWED;
  1397. }
  1398. /**
  1399. * Check if profile can be contacted.
  1400. *
  1401. * NOTE. This service should be used if it's needed to pass some specific values in
  1402. * $isPerformAction and $iProfileId parameters, otherwise it's recommended to use
  1403. * BxBaseModProfileModule::serviceCheckAllowedProfileContact service method or
  1404. * BxDolProfile::checkAllowedProfileContact method.
  1405. *
  1406. * @param type $aDataEntry - entry which the action will be performed for
  1407. * @param type $isPerformAction - perform or just check the action
  1408. * @param type $iProfileId - performer's profile ID
  1409. * @return integer - one of CHECK_ACTION_RESULT_XXX constants.
  1410. */
  1411. public function serviceCheckAllowedContactForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  1412. {
  1413. $mixedResult = $this->_serviceCheckAllowedContactForProfile($aDataEntry, $isPerformAction, $iProfileId);
  1414. /**
  1415. * @hooks
  1416. * @hookdef hook-system-check_allowed_contact 'system', 'check_allowed_contact' - hook to override the result of checking whether 'contact' action is allowed or not to specified profile
  1417. * It's equivalent to @ref hook-system-check_allowed_view
  1418. * @hook @ref hook-system-check_allowed_contact
  1419. */
  1420. bx_alert('system', 'check_allowed_contact', 0, 0, [
  1421. 'module' => $this->getName(),
  1422. 'content_info' => $aDataEntry,
  1423. 'profile_id' => $iProfileId,
  1424. 'override_result' => &$mixedResult
  1425. ]);
  1426. return $mixedResult;
  1427. }
  1428. public function serviceSetViewProfileCover($oPage, $aProfileInfo)
  1429. {
  1430. $this->_oTemplate->setCover($oPage,$aProfileInfo);
  1431. }
  1432. /**
  1433. * Returns list of members by mode with limited number of records for React Jot
  1434. * @param string $sMode
  1435. * @param int $iStart
  1436. * @param int $iPerPage
  1437. * @return mixed
  1438. */
  1439. public function serviceGetMembers($sMode = 'active', $iStart = 0, $iPerPage = 10){
  1440. bx_import('SearchResult', $this->_aModule);
  1441. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  1442. $o = new $sClass($sMode);
  1443. $o -> aCurrent['paginate'] = array('perPage' => $iPerPage, 'forceStart' => $iStart);
  1444. return $o -> getSearchData();
  1445. }
  1446. /**
  1447. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1448. */
  1449. public function checkAllowedAdd ($isPerformAction = false)
  1450. {
  1451. $oAccount = BxDolAccount::getInstance();
  1452. if (!$oAccount || ($this->serviceActAsProfile() && $oAccount->isProfilesLimitReached()))
  1453. return _t('_sys_txt_access_denied');
  1454. return parent::checkAllowedAdd ($isPerformAction);
  1455. }
  1456. /**
  1457. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1458. */
  1459. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  1460. {
  1461. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
  1462. }
  1463. /**
  1464. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1465. */
  1466. public function checkAllowedViewProfileImage ($aDataEntry, $isPerformAction = false)
  1467. {
  1468. $CNF = &$this->_oConfig->CNF;
  1469. // check privacy
  1470. if (empty($CNF['OBJECT_PRIVACY_VIEW']))
  1471. return CHECK_ACTION_RESULT_ALLOWED;
  1472. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  1473. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']]) && !$oPrivacy->isPartiallyVisible($aDataEntry[$CNF['FIELD_ALLOW_VIEW_TO']]))
  1474. return _t('_sys_access_denied_to_private_content');
  1475. return CHECK_ACTION_RESULT_ALLOWED;
  1476. }
  1477. /**
  1478. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1479. */
  1480. public function checkAllowedViewCoverImage ($aDataEntry, $isPerformAction = false)
  1481. {
  1482. return $this->checkAllowedViewProfileImage($aDataEntry);
  1483. }
  1484. /**
  1485. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1486. */
  1487. public function checkAllowedPost ($aDataEntry, $isPerformAction = false)
  1488. {
  1489. return $this->serviceCheckAllowedPostForProfile ($aDataEntry, $isPerformAction);
  1490. }
  1491. /**
  1492. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1493. */
  1494. public function checkAllowedContact ($aDataEntry, $isPerformAction = false)
  1495. {
  1496. return $this->serviceCheckAllowedContactForProfile ($aDataEntry, $isPerformAction);
  1497. }
  1498. /**
  1499. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1500. */
  1501. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  1502. {
  1503. if(empty($aDataEntry) || !is_array($aDataEntry))
  1504. return _t('_sys_txt_not_found');
  1505. // moderator always has access
  1506. if ($this->_isModerator($isPerformAction))
  1507. return CHECK_ACTION_RESULT_ALLOWED;
  1508. // owner (checked by account instead of author!) always have access
  1509. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name']);
  1510. if (!$oProfile)
  1511. return _t('_sys_txt_error_occured');
  1512. if ($oProfile->id() == $this->_iProfileId || $oProfile->getAccountId() == $this->_iAccountId)
  1513. return CHECK_ACTION_RESULT_ALLOWED;
  1514. return _t('_sys_txt_access_denied');
  1515. }
  1516. /**
  1517. * Check if user can change cover image
  1518. */
  1519. public function checkAllowedChangeCover ($aDataEntry, $isPerformAction = false)
  1520. {
  1521. // moderator always has access
  1522. if ($this->_isModerator($isPerformAction))
  1523. return CHECK_ACTION_RESULT_ALLOWED;
  1524. // owner (checked by account instead of author!) always have access
  1525. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name']);
  1526. if (!$oProfile)
  1527. return _t('_sys_txt_error_occured');
  1528. if ($oProfile->id() == $this->_iProfileId || $oProfile->getAccountId() == $this->_iAccountId)
  1529. return CHECK_ACTION_RESULT_ALLOWED;
  1530. return _t('_sys_txt_access_denied');
  1531. }
  1532. /**
  1533. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1534. */
  1535. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  1536. {
  1537. // moderator always has access
  1538. if ($this->_isModerator($isPerformAction))
  1539. return CHECK_ACTION_RESULT_ALLOWED;
  1540. // owner (checked by account instead of author!) always have access
  1541. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  1542. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name'], $isPerformAction);
  1543. if (!$oProfile)
  1544. return _t('_sys_txt_error_occured');
  1545. if (($oProfile->id() == $this->_iProfileId || $oProfile->getAccountId() == $this->_iAccountId) && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  1546. return CHECK_ACTION_RESULT_ALLOWED;
  1547. return _t('_sys_txt_access_denied');
  1548. }
  1549. /**
  1550. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1551. */
  1552. public function checkAllowedViewMoreMenu (&$aDataEntry, $isPerformAction = false)
  1553. {
  1554. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']);
  1555. if (!$oMenu || !$oMenu->getCode())
  1556. return _t('_sys_txt_access_denied');
  1557. return CHECK_ACTION_RESULT_ALLOWED;
  1558. }
  1559. /**
  1560. * Compose differs from Contact. For example, a user should NOT be able to start conversation (compose)
  1561. * with himself but he should be able to view conversation page where he is one of the participants.
  1562. *
  1563. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1564. */
  1565. public function checkAllowedCompose(&$aDataEntry, $isPerformAction = false)
  1566. {
  1567. $CNF = &$this->_oConfig->CNF;
  1568. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->getName());
  1569. if($oProfile && $oProfile->id() == $this->_iProfileId)
  1570. return _t('_sys_txt_access_denied');
  1571. return $this->checkAllowedContact($aDataEntry, $isPerformAction);
  1572. }
  1573. /**
  1574. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1575. */
  1576. public function checkAllowedFriendAdd (&$aDataEntry, $isPerformAction = false)
  1577. {
  1578. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, ['sys_profiles_friends', 'checkAllowedAddConnection'], false, false);
  1579. }
  1580. /**
  1581. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1582. */
  1583. public function checkAllowedFriendRemove (&$aDataEntry, $isPerformAction = false)
  1584. {
  1585. if (CHECK_ACTION_RESULT_ALLOWED === $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, ['sys_profiles_friends', 'checkAllowedRemoveConnection'], false, true, true))
  1586. return CHECK_ACTION_RESULT_ALLOWED;
  1587. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, ['sys_profiles_friends', 'checkAllowedRemoveConnection'], false, true, false);
  1588. }
  1589. /**
  1590. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1591. */
  1592. public function checkAllowedRelationAdd (&$aDataEntry, $isPerformAction = false)
  1593. {
  1594. $sResult = _t('_sys_txt_access_denied');
  1595. if(!BxDolRelation::isEnabled())
  1596. return $sResult;
  1597. if(($sMsg = $this->checkAllowedView($aDataEntry)) !== CHECK_ACTION_RESULT_ALLOWED)
  1598. return $sMsg;
  1599. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_relations', false, false);
  1600. }
  1601. /**
  1602. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1603. */
  1604. public function checkAllowedRelationRemove (&$aDataEntry, $isPerformAction = false)
  1605. {
  1606. $sResult = _t('_sys_txt_access_denied');
  1607. if(!BxDolRelation::isEnabled())
  1608. return $sResult;
  1609. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_relations', false, true);
  1610. }
  1611. public function checkAllowedRelationsView (&$aDataEntry, $isPerformAction = false)
  1612. {
  1613. $sResult = _t('_sys_txt_access_denied');
  1614. if(!BxDolRelation::isEnabled())
  1615. return $sResult;
  1616. $sModule = $this->_oConfig->getName();
  1617. $oRelations = BxDolConnection::getObjectInstance('sys_profiles_relations');
  1618. if(!$oRelations->isRelationAvailableWithProfile($sModule) && !$oRelations->isRelationAvailableFromProfile($sModule))
  1619. return $sResult;
  1620. if(empty($aDataEntry) || !is_array($aDataEntry))
  1621. return $sResult;
  1622. return CHECK_ACTION_RESULT_ALLOWED;
  1623. }
  1624. /**
  1625. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1626. */
  1627. public function checkAllowedSubscribeAdd(&$aDataEntry, $isPerformAction = false)
  1628. {
  1629. $mixedResult = $this->_modProfileCheckAllowedSubscribeAdd($aDataEntry, $isPerformAction);
  1630. /**
  1631. * @hooks
  1632. * @hookdef hook-system-check_allowed_subscribe_add 'system', 'check_allowed_subscribe_add' - hook to override the result of checking whether 'subscribe' action is allowed or not to currently logged in user
  1633. * It's equivalent to @ref hook-system-check_allowed_view
  1634. * @hook @ref hook-system-check_allowed_subscribe_add
  1635. */
  1636. bx_alert('system', 'check_allowed_subscribe_add', 0, 0, [
  1637. 'module' => $this->getName(),
  1638. 'content_info' => $aDataEntry,
  1639. 'profile_id' => bx_get_logged_profile_id(),
  1640. 'override_result' => &$mixedResult
  1641. ]);
  1642. return $mixedResult;
  1643. }
  1644. /**
  1645. * Note. Is mainly needed for internal usage. Access level is 'public' to allow outer calls from alerts.
  1646. */
  1647. public function _modProfileCheckAllowedSubscribeAdd(&$aDataEntry, $isPerformAction = false)
  1648. {
  1649. if(($sMsg = $this->checkAllowedView($aDataEntry)) !== CHECK_ACTION_RESULT_ALLOWED)
  1650. return $sMsg;
  1651. return $this->_checkAllowedConnect($aDataEntry, $isPerformAction, 'sys_profiles_subscriptions', false, false);
  1652. }
  1653. /**
  1654. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1655. */
  1656. public function checkAllowedSubscribeRemove (&$aDataEntry, $isPerformAction = false)
  1657. {
  1658. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_subscriptions', false, true);
  1659. }
  1660. public function checkAllowedSubscriptionsView (&$aDataEntry, $isPerformAction = false)
  1661. {
  1662. $CNF = &$this->_oConfig->CNF;
  1663. $sResult = _t('_sys_txt_access_denied');
  1664. if(empty($aDataEntry) || !is_array($aDataEntry))
  1665. return $sResult;
  1666. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->_aModule['name']);
  1667. if(!$oProfile || ($oProfile->id() != $this->_iProfileId && $this->_oDb->getParam($CNF['PARAM_PUBLIC_SBSN']) != 'on' && $this->_oDb->getParam($CNF['PARAM_PUBLIC_SBSD']) != 'on'))
  1668. return $sResult;
  1669. return CHECK_ACTION_RESULT_ALLOWED;
  1670. }
  1671. public function checkMyself($iContentId)
  1672. {
  1673. $iLogged = (int)bx_get_logged_profile_id();
  1674. if(empty($iLogged))
  1675. return false;
  1676. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->_oConfig->getName());
  1677. if(!$oProfile)
  1678. return false;
  1679. return $oProfile->id() == $iLogged;
  1680. }
  1681. public function isAllowDeleteOrDisable($iActorProfileId, $iTargetProfileId)
  1682. {
  1683. if (BxDolAcl::getInstance()->isMemberLevelInSet(array(MEMBERSHIP_ID_MODERATOR), $iActorProfileId) && BxDolAcl::getInstance()->isMemberLevelInSet(array(MEMBERSHIP_ID_MODERATOR, MEMBERSHIP_ID_ADMINISTRATOR), $iTargetProfileId))
  1684. return false;
  1685. return true;
  1686. }
  1687. public function getProfileObject($iContentId)
  1688. {
  1689. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->_oConfig->getName());
  1690. if (!$oProfile)
  1691. $oProfile = BxDolProfileUndefined::getInstance();
  1692. return $oProfile;
  1693. }
  1694. protected function _serviceCheckAllowedContactForProfile($aDataEntry, $isPerformAction = false, $iProfileId = false)
  1695. {
  1696. $CNF = &$this->_oConfig->CNF;
  1697. if(!$iProfileId)
  1698. $iProfileId = $this->_iProfileId;
  1699. /*
  1700. * allow to 'contact myself'. It's needed to allow a user to view conversation page
  1701. * where he is one of the participants.
  1702. */
  1703. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->getName());
  1704. if($oProfile && $oProfile->id() == $iProfileId)
  1705. return CHECK_ACTION_RESULT_ALLOWED;
  1706. // moderator always has access
  1707. if($this->_isModeratorForProfile($isPerformAction, $iProfileId))
  1708. return CHECK_ACTION_RESULT_ALLOWED;
  1709. // check privacy
  1710. if(!empty($CNF['OBJECT_PRIVACY_CONTACT'])) {
  1711. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_CONTACT']);
  1712. if($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  1713. return _t('_sys_access_denied_to_private_content');
  1714. }
  1715. return CHECK_ACTION_RESULT_ALLOWED;
  1716. }
  1717. // ====== COMMON METHODS
  1718. public function onUpdateImage($iContentId, $sFiledName, $sFiledValue, $iProfileId = 0)
  1719. {
  1720. $CNF = &$this->_oConfig->CNF;
  1721. $sModule = $this->getName();
  1722. if(!$iProfileId && ($oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $sModule)) !== false)
  1723. $iProfileId = $oProfile->id();
  1724. $aField2Method = [
  1725. $CNF['FIELD_PICTURE'] => 'picture',
  1726. $CNF['FIELD_COVER'] => 'cover',
  1727. ];
  1728. if(!empty($aField2Method[$sFiledName]))
  1729. /**
  1730. * @hooks
  1731. * @hookdef hook-bx_base_profile-profile_picture_changed '{module_name}', 'profile_picture_changed' - hook after profile picture was changed
  1732. * - $unit_name - module name
  1733. * - $action - equals `profile_picture_changed`
  1734. * - $object_id - image id
  1735. * - $sender_id - profile id who performed the action
  1736. * - $extra_params - array of additional params with the following array keys:
  1737. * - `object_author_id` - [int] profile id
  1738. * - `content` - [int] profile content id
  1739. * - `field` - [string] field name
  1740. * @hook @ref hook-bx_base_profile-profile_picture_changed
  1741. */
  1742. /**
  1743. * @hooks
  1744. * @hookdef hook-bx_base_profile-profile_cover_changed '{module_name}', 'profile_cover_changed' - hook after profile cover was changed
  1745. * It's equivalent to @ref hook-bx_base_profile-profile_picture_changed
  1746. * @hook @ref hook-bx_base_profile-profile_cover_changed
  1747. */
  1748. bx_alert($sModule, 'profile_' . $aField2Method[$sFiledName] . '_changed', $sFiledValue, $iProfileId, [
  1749. 'object_author_id' => $iProfileId,
  1750. 'content' => $iContentId,
  1751. 'field' => $sFiledName
  1752. ]);
  1753. }
  1754. protected function _alertParams($aContentInfo)
  1755. {
  1756. $aParams = parent::_alertParams($aContentInfo);
  1757. $CNF = &$this->_oConfig->CNF;
  1758. if(!empty($CNF['FIELD_STATUS']) && isset($aContentInfo[$CNF['FIELD_STATUS']]))
  1759. $aParams['status'] = $aContentInfo[$CNF['FIELD_STATUS']];
  1760. if(!empty($CNF['FIELD_STATUS_ADMIN']) && isset($aContentInfo[$CNF['FIELD_STATUS_ADMIN']]))
  1761. $aParams['status_admin'] = $aContentInfo[$CNF['FIELD_STATUS_ADMIN']];
  1762. if(!empty($CNF['FIELD_ALLOW_VIEW_TO']) && isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]))
  1763. $aParams['privacy_view'] = $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']];
  1764. return $aParams;
  1765. }
  1766. public function alertAfterAdd($aContentInfo)
  1767. {
  1768. $CNF = &$this->_oConfig->CNF;
  1769. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  1770. $aParams = $this->_alertParams($aContentInfo);
  1771. /**
  1772. * @hooks
  1773. * @hookdef hook-bx_base_profile-added '{module_name}', 'added' - hook after profile was added
  1774. * - $unit_name - module name
  1775. * - $action - equals `added`
  1776. * - $object_id - profile content id
  1777. * - $sender_id - not used
  1778. * - $extra_params - array of additional params with the following array keys:
  1779. * - `status` - [string] context status
  1780. * - `status_admin` - [string] context admin status
  1781. * - `privacy_view` - [int] or [string] privacy for view context action, @see BxDolPrivacy
  1782. * @hook @ref hook-bx_base_profile-added
  1783. */
  1784. bx_alert($this->getName(), 'added', $iContentId, false, $aParams);
  1785. }
  1786. public function alertAfterEdit($aContentInfo)
  1787. {
  1788. $CNF = &$this->_oConfig->CNF;
  1789. $sModule = $this->getName();
  1790. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  1791. $aParams = $this->_alertParams($aContentInfo);
  1792. /**
  1793. * @hooks
  1794. * @hookdef hook-bx_base_profile-edited '{module_name}', 'edited' - hook after profile was changed
  1795. * It's equivalent to @ref hook-bx_base_profile-added
  1796. * @hook @ref hook-bx_base_profile-edited
  1797. */
  1798. bx_alert($sModule, 'edited', $iContentId, false, $aParams);
  1799. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $sModule);
  1800. /**
  1801. * @hooks
  1802. * @hookdef hook-profile-edit 'profile', 'edit' - hook after profile was changed
  1803. * - $unit_name - equals `profile`
  1804. * - $action - equals `edit`
  1805. * - $object_id - profile id
  1806. * - $sender_id - not used
  1807. * - $extra_params - array of additional params with the following array keys:
  1808. * - `content` - [int] profile content id
  1809. * - `module` - [string] module name
  1810. * @hook @ref hook-profile-added
  1811. */
  1812. bx_alert('profile', 'edit', $oProfile->id(), 0, [
  1813. 'content' => $iContentId,
  1814. 'module' => $sModule
  1815. ]);
  1816. }
  1817. public function getProfileByCurrentUrl ()
  1818. {
  1819. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  1820. if ($iProfileId)
  1821. return BxDolProfile::getInstance($iProfileId);
  1822. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1823. if ($iContentId)
  1824. return BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  1825. return false;
  1826. }
  1827. public function getEntryImageData($aContentInfo, $sField = 'FIELD_PICTURE', $aTranscoders = array())
  1828. {
  1829. return parent::getEntryImageData($aContentInfo, $sField, $aTranscoders);
  1830. }
  1831. public function getProfileName ($aContentInfo)
  1832. {
  1833. return bx_process_output($aContentInfo[$this->_oConfig->CNF['FIELD_NAME']]);
  1834. }
  1835. public function getMenuItemTitleByConnection($sConnection, $sAction, $iContentProfileId, $iInitiatorProfileId = 0)
  1836. {
  1837. $oConnection = BxDolConnection::getObjectInstance($sConnection);
  1838. if(!$oConnection)
  1839. return false;
  1840. if(!$iInitiatorProfileId)
  1841. $iInitiatorProfileId = bx_get_logged_profile_id();
  1842. $aResult = [];
  1843. switch($sConnection) {
  1844. case 'sys_profiles_friends':
  1845. $aResult = $this->_getMenuItemTitleProfilesFriends($sAction, $iContentProfileId, $iInitiatorProfileId, $oConnection);
  1846. break;
  1847. case 'sys_profiles_subscriptions':
  1848. $aResult = $this->_getMenuItemTitleProfilesSubscriptions($sAction, $iContentProfileId, $iInitiatorProfileId, $oConnection);
  1849. break;
  1850. }
  1851. return $aResult;
  1852. }
  1853. protected function _getMenuItemTitleProfilesFriends($sAction, $iContentProfileId, $iInitiatorProfileId, &$oConnection)
  1854. {
  1855. $CNF = $this->_oConfig->getCNF();
  1856. $aResult = [];
  1857. if($oConnection->isConnectedNotMutual($iInitiatorProfileId, $iContentProfileId))
  1858. $aResult = [
  1859. 'add' => _t(!empty($CNF['T']['menu_item_title_befriend_sent']) ? $CNF['T']['menu_item_title_befriend_sent'] : '_sys_menu_item_title_sm_befriend_sent'),
  1860. 'remove' => _t(!empty($CNF['T']['menu_item_title_unfriend_cancel']) ? $CNF['T']['menu_item_title_unfriend_cancel'] : '_sys_menu_item_title_sm_unfriend_cancel'),
  1861. ];
  1862. else if($oConnection->isConnectedNotMutual($iContentProfileId, $iInitiatorProfileId))
  1863. $aResult = [
  1864. 'add' => _t(!empty($CNF['T']['menu_item_title_befriend_confirm']) ? $CNF['T']['menu_item_title_befriend_confirm'] : '_sys_menu_item_title_sm_befriend_confirm'),
  1865. 'remove' => _t(!empty($CNF['T']['menu_item_title_unfriend_reject']) ? $CNF['T']['menu_item_title_unfriend_reject'] : '_sys_menu_item_title_sm_unfriend_reject'),
  1866. ];
  1867. else if($oConnection->isConnected($iInitiatorProfileId, $iContentProfileId, true))
  1868. $aResult = [
  1869. 'add' => '',
  1870. 'remove' => _t(!empty($CNF['T']['menu_item_title_unfriend']) ? $CNF['T']['menu_item_title_unfriend'] : '_sys_menu_item_title_sm_unfriend'),
  1871. ];
  1872. else
  1873. $aResult = [
  1874. 'add' => _t(!empty($CNF['T']['menu_item_title_befriend']) ? $CNF['T']['menu_item_title_befriend'] : '_sys_menu_item_title_sm_befriend'),
  1875. 'remove' => '',
  1876. ];
  1877. return !empty($sAction) && isset($aResult[$sAction]) ? $aResult[$sAction] : $aResult;
  1878. }
  1879. protected function _getMenuItemTitleProfilesSubscriptions($sAction, $iContentProfileId, $iInitiatorProfileId, &$oConnection)
  1880. {
  1881. $CNF = $this->_oConfig->getCNF();
  1882. $aResult = [];
  1883. if($oConnection->isConnected($iInitiatorProfileId, $iContentProfileId))
  1884. $aResult = [
  1885. 'add' => '',
  1886. 'remove' => _t(!empty($CNF['T']['menu_item_title_unsubscribe']) ? $CNF['T']['menu_item_title_unsubscribe'] : '_sys_menu_item_title_sm_unsubscribe'),
  1887. ];
  1888. else
  1889. $aResult = [
  1890. 'add' => _t(!empty($CNF['T']['menu_item_title_subscribe']) ? $CNF['T']['menu_item_title_subscribe'] : '_sys_menu_item_title_sm_subscribe'),
  1891. 'remove' => '',
  1892. ];
  1893. return !empty($sAction) && !empty($aResult[$sAction]) ? $aResult[$sAction] : $aResult;
  1894. }
  1895. public function decodeDataAPI($aData, $aParams = [])
  1896. {
  1897. $CNF = $this->_oConfig->CNF;
  1898. $sModule = $this->getName();
  1899. $iId = (int)$aData[$CNF['FIELD_ID']];
  1900. $oProfile = BxDolProfile::getInstanceByContentAndType($iId, $sModule);
  1901. $aResult = [
  1902. 'id' => $iId,
  1903. 'module' => $sModule,
  1904. 'module_title' => _t($CNF['T']['txt_sample_single']),
  1905. 'added' => $aData[$CNF['FIELD_ADDED']],
  1906. 'author' => $aData[$CNF['FIELD_AUTHOR']],
  1907. 'author_data' => $oProfile !== false ? BxDolProfile::getData($oProfile->id()) : '',
  1908. 'title' => $aData[$CNF['FIELD_TITLE']],
  1909. $CNF['FIELD_TITLE'] => $aData[$CNF['FIELD_TITLE']],
  1910. 'url' => bx_api_get_relative_url($this->serviceGetLink($iId)),
  1911. 'image' => $this->serviceGetThumb($iId),
  1912. 'cover' => $this->serviceGetCover($iId),
  1913. ];
  1914. if(isset($aParams['template']) && $aParams['template'] == 'unit_wo_info')
  1915. return $aResult;
  1916. if(isset($aParams['extended']) && $aParams['extended'] === true)
  1917. $aResult['text'] = $aData[$CNF['FIELD_TEXT']];
  1918. if(getParam('sys_api_conn_in_prof_units') == 'on' && $oProfile !== false) {
  1919. $iProfileId = $oProfile->id();
  1920. $aResult['title'] = $oProfile->getDisplayName();
  1921. if(($oConnection = BxDolConnection::getObjectInstance('sys_profiles_friends')) !== false && isset($CNF['URI_VIEW_FRIENDS'])) {
  1922. $aResult['friends_count'] = $oConnection->getConnectedContentCount($iProfileId, true);
  1923. $aResult['friends_list'] = $oConnection->getConnectedListAPI($iProfileId, true, BX_CONNECTIONS_CONTENT_TYPE_CONTENT);
  1924. if(isLogged()) {
  1925. $iLoggedId = bx_get_logged_profile_id();
  1926. $aResult['mutual_friends_count'] = $oConnection->getCommonContentCount($iProfileId, $iLoggedId, true);
  1927. $aResult['mutual_friends_list'] = $oConnection->getCommonListAPI($iProfileId, $iLoggedId, true);
  1928. }
  1929. }
  1930. if(($oConnection = BxDolConnection::getObjectInstance('sys_profiles_subscriptions')) !== false){
  1931. $aResult['followers_count'] = $oConnection->getConnectedInitiatorsCount($iProfileId);
  1932. $aResult['followers_list'] = $oConnection->getConnectedListAPI($iProfileId, false, BX_CONNECTIONS_CONTENT_TYPE_INITIATORS);
  1933. }
  1934. }
  1935. $sKey = 'OBJECT_MENU_SNIPPET_META';
  1936. if(!empty($CNF[$sKey]) && ($oMetaMenu = BxDolMenu::getObjectInstance($CNF[$sKey], $this->_oTemplate)) !== false) {
  1937. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  1938. $bPublic = !$oPrivacy || $oPrivacy->check($iId) || $oPrivacy->isPartiallyVisible($aData[$CNF['FIELD_ALLOW_VIEW_TO']]);
  1939. $oMetaMenu->setContentId($iId);
  1940. $oMetaMenu->setContentPublic($bPublic);
  1941. if(isset($aParams['context']))
  1942. $oMetaMenu->setContext($aParams['context']);
  1943. $aResult['meta'] = $oMetaMenu->getCodeAPI();
  1944. }
  1945. return $aResult;
  1946. }
  1947. // ====== PROTECTED METHODS
  1948. protected function _checkAllowedConnect (&$aDataEntry, $isPerformAction, $mixedConnection, $isMutual, $isInvertResult, $isSwap = false)
  1949. {
  1950. if (!$this->_iProfileId)
  1951. return _t('_sys_txt_access_denied');
  1952. $CNF = &$this->_oConfig->CNF;
  1953. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->_aModule['name']);
  1954. if (!$oProfile || $oProfile->id() == $this->_iProfileId)
  1955. return _t('_sys_txt_access_denied');
  1956. $sConnObject = '';
  1957. $sConnMethod = 'checkAllowedConnect';
  1958. if(is_array($mixedConnection))
  1959. list($sConnObject, $sConnMethod) = $mixedConnection;
  1960. else
  1961. $sConnObject = $mixedConnection;
  1962. return BxDolConnection::getObjectInstance($sConnObject)->$sConnMethod($this->_iProfileId, $oProfile->id(), $isPerformAction, $isMutual, $isInvertResult, $isSwap);
  1963. }
  1964. protected function _buildRssParams($sMode, $aArgs)
  1965. {
  1966. $aParams = array ();
  1967. $sMode = bx_process_input($sMode);
  1968. switch ($sMode) {
  1969. case 'connections':
  1970. $aParams = array(
  1971. 'object' => isset($aArgs[0]) ? $aArgs[0] : '',
  1972. 'type' => isset($aArgs[1]) ? $aArgs[1] : '',
  1973. 'profile' => isset($aArgs[2]) ? (int)$aArgs[2] : 0,
  1974. 'mutual' => isset($aArgs[3]) ? (int)$aArgs[3] : 0,
  1975. 'profile2' => isset($aArgs[4]) ? (int)$aArgs[4] : 0,
  1976. );
  1977. break;
  1978. }
  1979. return $aParams;
  1980. }
  1981. protected function _serviceGetTimelineProfileImage($aEvent, $aBrowseParams, $aBuildParams)
  1982. {
  1983. $CNF = &$this->_oConfig->CNF;
  1984. $aFileInfo = BxDolStorage::getObjectInstance($CNF[$aBuildParams['stg']])->getFile((int)$aEvent['object_id']);
  1985. if(empty($aFileInfo) || !is_array($aFileInfo))
  1986. return false;
  1987. $aEventContent = unserialize($aEvent['content']);
  1988. if(!is_array($aEventContent) || empty($aEventContent['content']))
  1989. return false;
  1990. $aContentInfo = $this->_oDb->getContentInfoById($aEventContent['content']);
  1991. if(empty($aContentInfo) || !is_array($aContentInfo))
  1992. return false;
  1993. $oProfile = BxDolProfile::getInstanceMagic($aContentInfo['profile_id']);
  1994. if (!$oProfile->isActive())
  1995. return false;
  1996. $sUserName = $oProfile->getDisplayName();
  1997. $sSample = isset($CNF['T'][$aBuildParams['txt_sswa']]) ? $CNF['T'][$aBuildParams['txt_sswa']] : $CNF['T'][$aBuildParams['txt_ss']];
  1998. //--- Title & Description
  1999. $sTitle = !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '';
  2000. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TEXT']]))
  2001. $sTitle = $aContentInfo[$CNF['FIELD_TEXT']];
  2002. $sDescription = _t($CNF['T'][$aBuildParams['txt_sau']], $sUserName, _t($sSample));
  2003. return array(
  2004. 'owner_id' => $aEvent['owner_id'],
  2005. 'object_owner_id' => $aContentInfo['profile_id'],
  2006. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  2007. 'sample' => $sSample,
  2008. 'sample_wo_article' => $CNF['T'][$aBuildParams['txt_ss']],
  2009. 'sample_action' => isset($CNF['T'][$aBuildParams['txt_sa']]) ? $CNF['T'][$aBuildParams['txt_sa']] : '',
  2010. 'url' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']])),
  2011. 'content' => $this->_getContentForTimelineProfileImage($aEvent, $aBrowseParams, $aBuildParams, $aContentInfo, $aFileInfo), //a string to display or array to parse default template before displaying.
  2012. 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
  2013. 'views' => '',
  2014. 'votes' => '',
  2015. 'scores' => '',
  2016. 'reports' => '',
  2017. 'comments' => '',
  2018. 'title' => $sTitle, //may be empty.
  2019. 'description' => $sDescription //may be empty.
  2020. );
  2021. }
  2022. protected function _serviceGetTimelineProfileImageAllowedView($aEvent)
  2023. {
  2024. $sError = _t('_sys_access_denied_to_private_content');
  2025. if(empty($aEvent['content']) || !is_array($aEvent['content']) || empty($aEvent['content']['id']))
  2026. return $sError;
  2027. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['content']['id']);
  2028. if(empty($aContentInfo) || !is_array($aContentInfo))
  2029. return $sError;
  2030. return $this->serviceCheckAllowedViewForProfile($aContentInfo);
  2031. }
  2032. protected function _getContentForTimelineProfileImage($aEvent, $aBrowseParams, $aBuildParams, $aContentInfo, $aFileInfo)
  2033. {
  2034. $CNF = &$this->_oConfig->CNF;
  2035. $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]));
  2036. //--- Image(s)
  2037. $sImage = $this->_oConfig->getImageUrl($aFileInfo['id'], $aBuildParams['trans']);
  2038. $sImageOrig = $this->_oConfig->getImageUrl($aFileInfo['id'], $aBuildParams['trans_orig']);
  2039. if(!empty($sImage)) {
  2040. if(empty($sImageOrig))
  2041. $sImageOrig = $sImage;
  2042. $a = ['id' => $aFileInfo['id'], 'url' => $sUrl, 'src' => $sImage];
  2043. if(CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedView($aContentInfo)) {
  2044. $a['src_orig'] = $sImageOrig;
  2045. $sCnfKey = 'OBJECT_IMAGES_TRANSCODER_GALLERY';
  2046. if(!empty($CNF[$sCnfKey]) && ($sSrcMedium = $this->_oConfig->getImageUrl($aFileInfo['id'], [$sCnfKey])) != '')
  2047. $a['src_medium'] = $sSrcMedium;
  2048. }
  2049. $aImages = [$a];
  2050. }
  2051. return array(
  2052. 'sample' => isset($CNF['T'][$aBuildParams['txt_sswa']]) ? $CNF['T'][$aBuildParams['txt_sswa']] : $CNF['T'][$aBuildParams['txt_ss']],
  2053. 'sample_wo_article' => $CNF['T'][$aBuildParams['txt_ss']],
  2054. 'sample_action' => isset($CNF['T'][$aBuildParams['txt_sa']]) ? $CNF['T'][$aBuildParams['txt_sa']] : '',
  2055. 'id' => $aContentInfo[$CNF['FIELD_ID']],
  2056. 'url' => $sUrl,
  2057. 'title' => '',
  2058. 'text' => '',
  2059. 'images' => $aImages,
  2060. 'videos' => array()
  2061. );
  2062. }
  2063. protected function _entityComments($sObject, $iId = 0)
  2064. {
  2065. if(!$iId)
  2066. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  2067. if(!$iId)
  2068. $iId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  2069. if(!$iId)
  2070. return false;
  2071. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  2072. if(!$oCmts || !$oCmts->isEnabled())
  2073. return false;
  2074. if (bx_is_api())
  2075. return [bx_srv('system', 'get_data_api', [['module' => $sObject, 'object_id' => $iId]], 'TemplCmtsServices')];
  2076. return $oCmts->getCommentsBlock(array(), array('in_designbox' => false));
  2077. }
  2078. protected function _getContent($iContentId = 0, $sFuncGetContent = 'getContentInfoById')
  2079. {
  2080. if(!$iContentId && bx_get('id') === false && bx_get('profile_id') !== false) {
  2081. $oProfile = BxDolProfile::getInstance((int)bx_get('profile_id'));
  2082. if($oProfile)
  2083. $iContentId = $oProfile->getContentId();
  2084. }
  2085. return parent::_getContent($iContentId, $sFuncGetContent);
  2086. }
  2087. }
  2088. /** @} */