1
0

BxBaseModProfileModule.php 91 KB

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