BxBaseModProfileModule.php 72 KB

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