1
0

BxBaseModProfileModule.php 85 KB

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