BxBaseModProfileModule.php 75 KB

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