1
0

BxBaseModProfileModule.php 75 KB

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