BxBaseModProfileModule.php 75 KB

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