BxBaseModProfileModule.php 89 KB

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