1
0

BxBaseModProfileModule.php 108 KB

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