1
0

BxBaseModProfileModule.php 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396
  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. $this->_iAccountId = getLoggedId();
  24. }
  25. public function actionDeleteProfileImg($iFileId, $iContentId, $sFieldPicture)
  26. {
  27. $aResult = array();
  28. $CNF = &$this->_oConfig->CNF;
  29. $oSrorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  30. if (!($aFile = $oSrorage->getFile((int)$iFileId)) || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)) || $aContentInfo[$sFieldPicture] != (int)$iFileId)
  31. $aResult = array('error' => 1, 'msg' => _t('_sys_storage_err_file_not_found'));
  32. $oAccountProfile = BxDolProfile::getInstanceAccountProfile();
  33. if ($oAccountProfile)
  34. $iAccountProfileId = $oAccountProfile->id();
  35. if ((!$aResult && !isLogged()) || (!$aResult && $aFile['profile_id'] != $iAccountProfileId && !$this->_isModerator()))
  36. $aResult = array('error' => 2, 'msg' => _t('_Access denied'));
  37. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oTemplate);
  38. if (!$aResult && !$oForm->_deleteFile($iContentId, $sFieldPicture, (int)$iFileId, true))
  39. $aResult = array('error' => 3, 'msg' => _t('_Failed'));
  40. elseif (!$aResult)
  41. $aResult = array('error' => 0, 'msg' => '');
  42. header('Content-Type: application/json; charset=utf-8');
  43. echo json_encode($aResult);
  44. }
  45. // ====== SERVICE METHODS
  46. public function serviceGetOptionsRedirectAfterAdd()
  47. {
  48. $CNF = &$this->_oConfig->CNF;
  49. $aResult = array();
  50. $aChoices = array(BX_DOL_PROFILE_REDIRECT_PROFILE, BX_DOL_PROFILE_REDIRECT_LAST, BX_DOL_PROFILE_REDIRECT_CUSTOM);
  51. foreach($aChoices as $sChoice)
  52. $aResult[] = array('key' => $sChoice, 'value' => _t($CNF['T']['option_redirect_aadd_' . $sChoice]));
  53. return $aResult;
  54. }
  55. public function serviceGetThumb ($iContentId, $sTranscoder = '')
  56. {
  57. $CNF = &$this->_oConfig->CNF;
  58. if(empty($sTranscoder) && !empty($CNF['OBJECT_IMAGES_TRANSCODER_THUMB']))
  59. $sTranscoder = $CNF['OBJECT_IMAGES_TRANSCODER_THUMB'];
  60. $mixedResult = $this->_getFieldValueThumb('FIELD_PICTURE', $iContentId, $sTranscoder);
  61. return $mixedResult !== false ? $mixedResult : '';
  62. }
  63. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  64. {
  65. if(empty($sUnitTemplate))
  66. $sUnitTemplate = 'unit_with_cover.html';
  67. return parent::serviceGetSearchResultUnit($iContentId, $sUnitTemplate);
  68. }
  69. public function serviceGetSearchableFieldsExtended()
  70. {
  71. $CNF = &$this->_oConfig->CNF;
  72. $aResult = parent::serviceGetSearchableFieldsExtended();
  73. if(!$this->serviceActAsProfile())
  74. return $aResult;
  75. if(!in_array('online', $this->_aSearchableNamesExcept))
  76. $aResult['online'] = array(
  77. 'type' => 'checkbox',
  78. 'caption' => $CNF['T']['form_field_online'],
  79. 'info' => '',
  80. 'value' => '1',
  81. 'values' => '',
  82. 'pass' => ''
  83. );
  84. if(!empty($CNF['FIELD_PICTURE']) && !in_array($CNF['FIELD_PICTURE'], $this->_aSearchableNamesExcept))
  85. $aResult[$CNF['FIELD_PICTURE']] = array(
  86. 'type' => 'checkbox',
  87. 'caption' => $CNF['T']['form_field_picture'],
  88. 'info' => '',
  89. 'value' => '1',
  90. 'values' => '',
  91. 'pass' => '',
  92. 'search_operator' => '>='
  93. );
  94. return $aResult;
  95. }
  96. public function servicePrivateProfileMsg()
  97. {
  98. $mixedContent = $this->_getContent();
  99. if ($mixedContent) {
  100. list($iContentId, $aContentInfo) = $mixedContent;
  101. return $this->checkAllowedView($aContentInfo);
  102. }
  103. return MsgBox(_t('_sys_access_denied_to_private_content'));
  104. }
  105. public function serviceGetContentInfoById($iContentId)
  106. {
  107. return $this->_oDb->getContentInfoById((int)$iContentId);
  108. }
  109. public function serviceGetMenuAddonManageTools()
  110. {
  111. bx_import('SearchResult', $this->_aModule);
  112. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  113. $o = new $sClass();
  114. $o->fillFilters(array(
  115. 'perofileStatus' => BX_PROFILE_STATUS_PENDING
  116. ));
  117. $o->unsetPaginate();
  118. return $o->getNum();
  119. }
  120. public function serviceGetMenuAddonManageToolsProfileStats()
  121. {
  122. bx_import('SearchResult', $this->_aModule);
  123. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  124. $o = new $sClass();
  125. $o->fillFilters(array(
  126. 'account_id' => getLoggedId(),
  127. 'perofileStatus' => ''
  128. ));
  129. $o->unsetPaginate();
  130. return $o->getNum();
  131. }
  132. public function serviceGetMenuAddonFavoritesProfileStats()
  133. {
  134. bx_import('SearchResult', $this->_aModule);
  135. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  136. $o = new $sClass('favorite', array('user' => bx_get_logged_profile_id()));
  137. $o->unsetPaginate();
  138. return $o->getNum();
  139. }
  140. public function serviceGetSubmenuObject ()
  141. {
  142. return $this->_oConfig->CNF['OBJECT_MENU_SUBMENU_VIEW_ENTRY'];
  143. }
  144. public function serviceGetMenuSetNameForMenuTrigger ($sMenuTriggerName)
  145. {
  146. $CNF = &$this->_oConfig->CNF;
  147. if (isset($CNF['TRIGGER_MENU_PROFILE_VIEW_SUBMENU']) && $CNF['TRIGGER_MENU_PROFILE_VIEW_SUBMENU'] == $sMenuTriggerName)
  148. return $CNF['OBJECT_MENU_SUBMENU_VIEW_ENTRY'];
  149. elseif (isset($CNF['TRIGGER_MENU_PROFILE_SNIPPET_META']) && $CNF['TRIGGER_MENU_PROFILE_SNIPPET_META'] == $sMenuTriggerName)
  150. return $CNF['OBJECT_MENU_SNIPPET_META'];
  151. else if (isset($CNF['TRIGGER_MENU_PROFILE_VIEW_ACTIONS']) && $CNF['TRIGGER_MENU_PROFILE_VIEW_ACTIONS'] == $sMenuTriggerName) {
  152. if(empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL']))
  153. return $CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY'];
  154. else
  155. return array($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY'], $CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL']);
  156. }
  157. return '';
  158. }
  159. public function serviceGetSnippetMenuVars($iProfileId, $bPublic = null)
  160. {
  161. return $this->_oTemplate->getSnippetMenuVars($iProfileId, $bPublic);
  162. }
  163. public function serviceGetPageObjectForPageTrigger ($sPageTriggerName)
  164. {
  165. if (isset($this->_oConfig->CNF['TRIGGER_PAGE_VIEW_ENTRY']) && $this->_oConfig->CNF['TRIGGER_PAGE_VIEW_ENTRY'] == $sPageTriggerName)
  166. return $this->_oConfig->CNF['OBJECT_PAGE_VIEW_ENTRY'];
  167. return '';
  168. }
  169. public function serviceProfilesSearch ($sTerm, $iLimit)
  170. {
  171. $aRet = array();
  172. $a = $this->_oDb->searchByTerm($sTerm, $iLimit);
  173. foreach ($a as $r) {
  174. $oProfile = BxDolProfile::getInstance($r['profile_id']);
  175. $aRet[] = array (
  176. 'label' => $this->serviceProfileName($r['content_id']),
  177. 'value' => $r['profile_id'],
  178. 'url' => $oProfile->getUrl(),
  179. 'thumb' => $oProfile->getThumb(),
  180. 'unit' => $oProfile->getUnit(0, array('template' => 'unit_wo_info'))
  181. );
  182. }
  183. return $aRet;
  184. }
  185. public function serviceProfileUnit ($iContentId, $aParams = array())
  186. {
  187. $mixedContent = $this->_getContent($iContentId);
  188. if($mixedContent === false)
  189. return false;
  190. list($iContentId, $aContentInfo) = $mixedContent;
  191. $bCheckPrivateContent = isset($aParams['check_private_content']) ? (bool)$aParams['check_private_content'] : true;
  192. $sTemplate = 'unit.html';
  193. $aTemplateVars = array();
  194. if(!empty($aParams['template'])) {
  195. if(is_string($aParams['template']))
  196. $sTemplate = $aParams['template'] . '.html';
  197. else if(is_array($aParams['template'])) {
  198. if(!empty($aParams['template']['name']))
  199. $sTemplate = $aParams['template']['name'] . '.html';
  200. if(!empty($aParams['template']['vars']))
  201. $aTemplateVars = $aParams['template']['vars'];
  202. }
  203. }
  204. return $this->_oTemplate->unit($aContentInfo, $bCheckPrivateContent, array($sTemplate, $aTemplateVars));
  205. }
  206. public function serviceHasImage ($iContentId)
  207. {
  208. $CNF = &$this->_oConfig->CNF;
  209. $mixedContent = $this->_getContent($iContentId, 'getContentInfoById');
  210. if($mixedContent === false)
  211. return false;
  212. list($iContentId, $aContentInfo) = $mixedContent;
  213. return !empty($aContentInfo[$CNF['FIELD_PICTURE']]);
  214. }
  215. public function serviceProfilePicture ($iContentId)
  216. {
  217. return $this->_serviceTemplateFunc('urlPicture', $iContentId);
  218. }
  219. public function serviceProfileAvatar ($iContentId)
  220. {
  221. return $this->_serviceTemplateFunc('urlAvatar', $iContentId);
  222. }
  223. public function serviceProfileCover ($iContentId)
  224. {
  225. return $this->_serviceTemplateFunc('urlCover', $iContentId);
  226. }
  227. public function serviceProfileUnitCover ($iContentId)
  228. {
  229. return $this->_serviceTemplateFunc('urlCoverUnit', $iContentId);
  230. }
  231. public function serviceProfileEditUrl ($iContentId)
  232. {
  233. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $this->_oConfig->CNF['URI_EDIT_ENTRY'] . '&id=' . $iContentId);
  234. }
  235. public function serviceProfileThumb ($iContentId)
  236. {
  237. return $this->_serviceTemplateFunc('thumb', $iContentId);
  238. }
  239. public function serviceProfileIcon ($iContentId)
  240. {
  241. return $this->_serviceTemplateFunc('icon', $iContentId);
  242. }
  243. public function serviceProfileName ($iContentId)
  244. {
  245. if (!$iContentId)
  246. return false;
  247. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  248. if (!$aContentInfo)
  249. return false;
  250. return bx_process_output($aContentInfo[$this->_oConfig->CNF['FIELD_NAME']]);
  251. }
  252. public function serviceProfileCreateUrl ($bAbsolute = true)
  253. {
  254. $CNF = $this->_oConfig->CNF;
  255. if(empty($CNF['URL_CREATE']))
  256. return false;
  257. return $bAbsolute ? BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_CREATE']) : $CNF['URL_CREATE'];
  258. }
  259. public function serviceProfileUrl ($iContentId)
  260. {
  261. if (!$iContentId)
  262. return false;
  263. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  264. if (!$aContentInfo)
  265. return false;
  266. $CNF = $this->_oConfig->CNF;
  267. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  268. }
  269. /**
  270. * @see iBxDolProfileService::serviceGetSpaceTitle
  271. */
  272. public function serviceGetSpaceTitle()
  273. {
  274. return _t('_sys_ps_space_title_friend');
  275. }
  276. /**
  277. * @see iBxDolProfileService::serviceGetParticipatingProfiles
  278. */
  279. public function serviceGetParticipatingProfiles($iProfileId, $aConnectionObjects = false)
  280. {
  281. if (false === $aConnectionObjects)
  282. $aConnectionObjects = array('sys_profiles_friends');
  283. $a = array();
  284. foreach ($aConnectionObjects as $sConnectionObject) {
  285. if (!($o = BxDolConnection::getObjectInstance($sConnectionObject)))
  286. continue;
  287. if (BX_CONNECTIONS_TYPE_MUTUAL == $o->getType())
  288. $a = array_merge($a, $o->getConnectedContent($iProfileId, true));
  289. else
  290. $a = array_merge($a, $o->getConnectedContent($iProfileId));
  291. }
  292. $a = array_unique($a);
  293. $aRet = array();
  294. foreach ($a as $iConnectedProfileId) {
  295. if (!($oConnectedProfile = BxDolProfile::getInstance($iConnectedProfileId)))
  296. continue;
  297. if ($oConnectedProfile->getModule() != $this->getName())
  298. continue;
  299. if (CHECK_ACTION_RESULT_ALLOWED === bx_srv($oConnectedProfile->getModule(), 'check_allowed_post_in_profile', array($oConnectedProfile->getContentId(), $iProfileId)))
  300. $aRet[] = $iConnectedProfileId;
  301. }
  302. bx_alert('system', 'get_participating_profiles', $iProfileId, false, array(
  303. 'module' => $this->_oConfig->getName(),
  304. 'profiles' => &$aRet
  305. ));
  306. return $aRet;
  307. }
  308. /**
  309. * @see iBxDolProfileService::serviceCheckSpacePrivacy
  310. */
  311. public function serviceCheckSpacePrivacy($iContentId)
  312. {
  313. return $this->serviceCheckAllowedProfileView($iContentId);
  314. }
  315. /**
  316. * @see iBxDolProfileService::serviceCheckAllowedProfileView
  317. */
  318. public function serviceCheckAllowedProfileView($iContentId)
  319. {
  320. return $this->serviceCheckAllowedWithContent('View', $iContentId);
  321. }
  322. /**
  323. * @see iBxDolProfileService::serviceCheckAllowedPostInProfile
  324. */
  325. public function serviceCheckAllowedPostInProfile($iContentId, $iProfileIdPoster = false)
  326. {
  327. if (!$iContentId || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)))
  328. return _t('_sys_request_page_not_found_cpt');
  329. return $this->serviceCheckAllowedViewForProfile($aContentInfo, false, $iProfileIdPoster);
  330. }
  331. /**
  332. * Prepare fields from some universal set of fields to fields in particular profile module.
  333. * By default only 'name' and 'description' fields are supported.
  334. * After fields convertion it can be used in @see BxBaseModGeneralModule::serviceEntityAdd
  335. * @param $aFieldsProfile fields in soem universal format.
  336. * @return array which is ready to use for particular module
  337. */
  338. public function servicePrepareFields ($aFieldsProfile)
  339. {
  340. bx_alert($this->getName(), 'prepare_fields', 0, 0, array('fields_orig' => $aFieldsProfile, 'fields_result' => &$aFieldsProfile));
  341. return $aFieldsProfile;
  342. }
  343. protected function _servicePrepareFields ($aFieldsProfile, $aFieldsDefault, $aMap)
  344. {
  345. $aFieldsOrig = $aFieldsProfile;
  346. bx_import('BxDolPrivacy');
  347. $aFieldsDefault2 = array(
  348. 'allow_view_to' => BX_DOL_PG_ALL,
  349. );
  350. $aFieldsProfile = array_merge($aFieldsDefault2, $aFieldsDefault, $aFieldsProfile);
  351. foreach ($aMap as $k => $v) {
  352. if (isset($aFieldsProfile[$v]))
  353. $aFieldsProfile[$k] = $aFieldsProfile[$v];
  354. if ($k != $v && !isset($aMap[$v]))
  355. unset($aFieldsProfile[$v]);
  356. }
  357. bx_alert($this->getName(), 'prepare_fields', 0, 0, array('fields_orig' => $aFieldsOrig, 'fields_result' => &$aFieldsProfile));
  358. return $aFieldsProfile;
  359. }
  360. public function serviceFormsHelper ()
  361. {
  362. return parent::serviceFormsHelper ();
  363. }
  364. public function serviceEntityCreate ($sDisplay = false)
  365. {
  366. BxDolInformer::getInstance($this->_oTemplate)->setEnabled(false);
  367. return parent::serviceEntityCreate ($sDisplay);
  368. }
  369. public function serviceActAsProfile ()
  370. {
  371. return true;
  372. }
  373. public function serviceBrowseRecommended ($sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = true)
  374. {
  375. if (!isLogged())
  376. return '';
  377. return $this->_serviceBrowse ('recommended', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  378. }
  379. public function serviceBrowseRecentProfiles ($bDisplayEmptyMsg = false, $bAjaxPaginate = true)
  380. {
  381. return $this->_serviceBrowse ('recent', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate);
  382. }
  383. public function serviceBrowseActiveProfiles ($sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = false)
  384. {
  385. return $this->_serviceBrowse ('active', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  386. }
  387. public function serviceBrowseTopProfiles ($bDisplayEmptyMsg = false, $bAjaxPaginate = false)
  388. {
  389. return $this->_serviceBrowse ('top', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate);
  390. }
  391. public function serviceBrowseOnlineProfiles ($bDisplayEmptyMsg = false, $bAjaxPaginate = false)
  392. {
  393. return $this->_serviceBrowse ('online', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate);
  394. }
  395. public function serviceBrowseConnections ($iProfileId, $sObjectConnections = 'sys_profiles_friends', $sConnectionsType = 'content', $iMutual = false, $iDesignBox = BX_DB_PADDING_DEF, $iProfileId2 = 0)
  396. {
  397. return $this->_serviceBrowse (
  398. 'connections',
  399. array(
  400. 'object' => $sObjectConnections,
  401. 'type' => $sConnectionsType,
  402. 'mutual' => $iMutual,
  403. 'profile' => (int)$iProfileId,
  404. 'profile2' => (int)$iProfileId2),
  405. $iDesignBox
  406. );
  407. }
  408. public function serviceBrowseRelationsQuick ($iProfileId, $sObjectConnections = 'sys_profiles_friends', $sConnectionsType = 'content', $iMutual = false, $iProfileId2 = 0)
  409. {
  410. // get connections object
  411. $oConnection = BxDolConnection::getObjectInstance($sObjectConnections);
  412. if (!$oConnection)
  413. return '';
  414. // set some vars
  415. $iStart = (int)bx_get('start');
  416. $iLimit = empty($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? 4 : getParam($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']);
  417. if (!$iLimit)
  418. $iLimit = 4;
  419. // get connections array
  420. bx_import('BxDolConnection');
  421. $aConnections = $oConnection->getConnectionsAsArrayExt($sConnectionsType, $iProfileId, $iProfileId2, $iMutual, $iStart, $iLimit + 1, BX_CONNECTIONS_ORDER_ADDED_DESC);
  422. if(empty($aConnections) || !is_array($aConnections))
  423. return '';
  424. $aResult = array();
  425. foreach($aConnections as $iProfile => $aConnection)
  426. $aResult[] = array(
  427. 'id' => $iProfile,
  428. 'info' => array(
  429. 'addon' => $oConnection->getRelationTranslation($aConnection['relation'])
  430. )
  431. );
  432. return $this->_serviceBrowseQuick($aResult, $iStart, $iLimit);
  433. }
  434. public function serviceBrowseConnectionsQuick ($iProfileId, $sObjectConnections = 'sys_profiles_friends', $sConnectionsType = 'content', $iMutual = false, $iProfileId2 = 0)
  435. {
  436. // get connections object
  437. $oConnection = BxDolConnection::getObjectInstance($sObjectConnections);
  438. if (!$oConnection)
  439. return '';
  440. // set some vars
  441. $iLimit = empty($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? 4 : getParam($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']);
  442. if (!$iLimit)
  443. $iLimit = 4;
  444. $iStart = (int)bx_get('start');
  445. // get connections array
  446. bx_import('BxDolConnection');
  447. $a = $oConnection->getConnectionsAsArray ($sConnectionsType, $iProfileId, $iProfileId2, $iMutual, (int)bx_get('start'), $iLimit + 1, BX_CONNECTIONS_ORDER_ADDED_DESC);
  448. if (!$a)
  449. return '';
  450. return $this->_serviceBrowseQuick($a, $iStart, $iLimit);
  451. }
  452. public function serviceBrowseConnectionsByType ($aParamsCnn, $aParamsBrs = array())
  453. {
  454. $sAll = 'all';
  455. $aParamsCnn['object'] = !empty($aParamsCnn['object']) ? $aParamsCnn['object'] : 'sys_profiles_friends';
  456. $aParamsCnn['type'] = !empty($aParamsCnn['type']) ? $aParamsCnn['type'] : 'content';
  457. $aParamsCnn['profile_id2'] = !empty($aParamsCnn['profile_id2']) ? (int)$aParamsCnn['profile_id2'] : 0;
  458. $aParamsCnn['mutual'] = isset($aParamsCnn['mutual']) ? $aParamsCnn['mutual'] : false;
  459. $oConnection = BxDolConnection::getObjectInstance($aParamsCnn['object']);
  460. if(!$oConnection)
  461. return '';
  462. $aSQLParts = $oConnection->getConnectionsAsSQLParts ($aParamsCnn['type'], 'sys_profiles', 'id', $aParamsCnn['profile_id'], $aParamsCnn['profile_id2'], $aParamsCnn['mutual']);
  463. $sType = !empty($aParamsBrs['type']) ? $aParamsBrs['type'] : $sAll;
  464. if(bx_get('type') !== false)
  465. $sType = bx_process_input(bx_get('type'));
  466. $iStart = (int)bx_get('start');
  467. $iLimitDefault = 4;
  468. $iLimit = !empty($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? getParam($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) : $iLimitDefault;
  469. if(!empty($aParamsBrs['per_page']))
  470. $iLimit = (int)$aParamsBrs['per_page'];
  471. if(!$iLimit)
  472. $iLimit = $iLimitDefault;
  473. $aProfiles = BxDolProfileQuery::getInstance()->getConnectedProfilesByType($aSQLParts, ($sType != $sAll ? $sType : ''), $iStart, $iLimit + 1);
  474. $mixedMenu = '';
  475. if(!isset($aParamsBrs['filter_menu']) || $aParamsBrs['filter_menu'] === true) {
  476. $aModules = array(
  477. array('name' => $sAll)
  478. );
  479. $aModules = array_merge($aModules, BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1)));
  480. $aMenuItems = array();
  481. foreach($aModules as $aModule)
  482. if($aModule['name'] == $sAll || BxDolRequest::serviceExists($aModule['name'], 'act_as_profile'))
  483. $aMenuItems[] = array(
  484. 'id' => $aModule['name'],
  485. 'name' => $aModule['name'],
  486. 'class' => '',
  487. 'link' => 'javascript:void(0)',
  488. 'onclick' => "return !loadDynamicBlockAutoPaginate(this, " . $iStart . ", " . $iLimit . ", " . bx_js_string(json_encode(array('type' => $aModule['name']))) . ");",
  489. 'target' => '_self',
  490. 'title' => _t('_' . $aModule['name']),
  491. 'active' => 1
  492. );
  493. if(!empty($aMenuItems)) {
  494. $mixedMenu = new BxTemplMenu(array('template' => 'menu_vertical.html', 'menu_id'=> $this->_oConfig->getName() . '-connections-by-type', 'menu_items' => $aMenuItems));
  495. $mixedMenu->setSelected('', $sType);
  496. }
  497. }
  498. return array(
  499. 'menu' => $mixedMenu,
  500. 'content' => $this->_serviceBrowseQuick(array_keys($aProfiles), $iStart, $iLimit, array('type' => $sType))
  501. );
  502. }
  503. public function serviceBrowseByAcl ($mixedLevelId, $iDesignBox = BX_DB_PADDING_DEF)
  504. {
  505. return $this->_serviceBrowse (
  506. 'acl',
  507. array(
  508. 'level' => $mixedLevelId,
  509. ),
  510. $iDesignBox,
  511. true
  512. );
  513. }
  514. public function serviceEntityEditCover ($iContentId = 0)
  515. {
  516. return $this->_serviceEntityForm ('editDataForm', $iContentId, $this->_oConfig->CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT_COVER']);
  517. }
  518. /**
  519. * Entry comments
  520. */
  521. public function serviceEntityCommentsByProfile ($iProfileId)
  522. {
  523. $CNF = &$this->_oConfig->CNF;
  524. if(empty($CNF['OBJECT_COMMENTS']))
  525. return '';
  526. $oProfile = BxDolProfile::getInstance($iProfileId);
  527. if(!$oProfile)
  528. return '';
  529. return $this->_entityComments($CNF['OBJECT_COMMENTS'], $oProfile->getContentId());
  530. }
  531. /**
  532. * Entry social sharing block
  533. */
  534. public function serviceEntitySocialSharing ($mixedContent = false, $aParams = array())
  535. {
  536. if(!empty($mixedContent)) {
  537. if(!is_array($mixedContent))
  538. $mixedContent = array((int)$mixedContent, array());
  539. }
  540. else {
  541. $mixedContent = $this->_getContent();
  542. if($mixedContent === false)
  543. return false;
  544. }
  545. list($iContentId, $aContentInfo) = $mixedContent;
  546. return parent::serviceEntitySocialSharing(array($iContentId, $aContentInfo), array(
  547. 'id_thumb' => !empty($CNF['FIELD_PICTURE']) && !empty($aContentInfo[$CNF['FIELD_PICTURE']]) ? $aContentInfo[$CNF['FIELD_PICTURE']] : 0,
  548. ));
  549. }
  550. public function serviceProfileMembership ($iContentId = 0)
  551. {
  552. $mixedContent = $this->_getContent($iContentId);
  553. if($mixedContent === false)
  554. return false;
  555. list($iContentId, $aContentInfo) = $mixedContent;
  556. return BxDolAcl::getInstance()->getProfileMembership($aContentInfo['profile_id']);
  557. }
  558. public function serviceProfileFriends ($iContentId = 0)
  559. {
  560. $mixedContent = $this->_getContent($iContentId);
  561. if($mixedContent === false)
  562. return false;
  563. list($iContentId, $aContentInfo) = $mixedContent;
  564. bx_import('BxDolConnection');
  565. $s = $this->serviceBrowseConnectionsQuick ($aContentInfo['profile_id'], 'sys_profiles_friends', BX_CONNECTIONS_CONTENT_TYPE_CONTENT, true);
  566. if (!$s)
  567. return MsgBox(_t('_sys_txt_empty'));
  568. return $s;
  569. }
  570. public function serviceProfileSubscriptions ($iContentId = 0, $aParams = array())
  571. {
  572. $mixedContent = $this->_getContent($iContentId);
  573. if($mixedContent === false)
  574. return false;
  575. list($iContentId, $aContentInfo) = $mixedContent;
  576. bx_import('BxDolConnection');
  577. $aResult = $this->serviceBrowseConnectionsByType(array(
  578. 'profile_id' => $aContentInfo['profile_id'],
  579. 'object' => 'sys_profiles_subscriptions',
  580. 'type' => BX_CONNECTIONS_CONTENT_TYPE_CONTENT
  581. ), array(
  582. 'type' => isset($aParams['type']) ? $aParams['type'] : '',
  583. 'filter_menu' => isset($aParams['filter_menu']) ? $aParams['filter_menu'] : true,
  584. ));
  585. if(empty($aResult['content']))
  586. $aResult['content'] = MsgBox(_t('_sys_txt_empty'));
  587. return $aResult;
  588. }
  589. public function serviceProfileSubscribedMe ($iContentId = 0)
  590. {
  591. $mixedContent = $this->_getContent($iContentId);
  592. if($mixedContent === false)
  593. return false;
  594. list($iContentId, $aContentInfo) = $mixedContent;
  595. bx_import('BxDolConnection');
  596. $s = $this->serviceBrowseConnectionsQuick ($aContentInfo['profile_id'], 'sys_profiles_subscriptions', BX_CONNECTIONS_CONTENT_TYPE_INITIATORS);
  597. if (!$s)
  598. return MsgBox(_t('_sys_txt_empty'));
  599. return $s;
  600. }
  601. public function serviceProfileRelations ($iContentId = 0, $aParams = array())
  602. {
  603. $mixedContent = $this->_getContent($iContentId);
  604. if($mixedContent === false)
  605. return false;
  606. list($iContentId, $aContentInfo) = $mixedContent;
  607. bx_import('BxDolConnection');
  608. $s = $this->serviceBrowseRelationsQuick ($aContentInfo['profile_id'], 'sys_profiles_relations', BX_CONNECTIONS_CONTENT_TYPE_CONTENT, 1);
  609. if (!$s)
  610. return MsgBox(_t('_sys_txt_empty'));
  611. return $s;
  612. }
  613. public function serviceProfileRelatedMe ($iContentId = 0)
  614. {
  615. $mixedContent = $this->_getContent($iContentId);
  616. if($mixedContent === false)
  617. return false;
  618. list($iContentId, $aContentInfo) = $mixedContent;
  619. bx_import('BxDolConnection');
  620. $s = $this->serviceBrowseRelationsQuick ($aContentInfo['profile_id'], 'sys_profiles_relations', BX_CONNECTIONS_CONTENT_TYPE_INITIATORS, 1);
  621. if (!$s)
  622. return MsgBox(_t('_sys_txt_empty'));
  623. return $s;
  624. }
  625. /**
  626. * check enabled profile activation letter
  627. */
  628. public function serviceIsEnableProfileActivationLetter()
  629. {
  630. $CNF = &$this->_oConfig->CNF;
  631. return isset($CNF['PARAM_ENABLE_ACTIVATION_LETTER']) ? (bool)getParam($CNF['PARAM_ENABLE_ACTIVATION_LETTER']) : true;
  632. }
  633. /**
  634. * For internal usage only.
  635. */
  636. public function serviceDeleteEntityService ($iContentId, $bDeleteWithContent = false)
  637. {
  638. return parent::serviceDeleteEntity ($iContentId, 'deleteDataService');
  639. }
  640. /**
  641. * Data for Notifications module
  642. */
  643. public function serviceGetNotificationsData()
  644. {
  645. $a = parent::serviceGetNotificationsData();
  646. $sModule = $this->_aModule['name'];
  647. $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');
  648. $a['settings'][] = array('group' => 'timeline_post', 'unit' => $sModule, 'action' => 'timeline_post_common', 'types' => array('follow_member'));
  649. $a['alerts'][] = array('unit' => $sModule, 'action' => 'timeline_post_common');
  650. return $a;
  651. }
  652. public function serviceGetNotificationsPost($aEvent)
  653. {
  654. $aResult = parent::serviceGetNotificationsVote($aEvent);
  655. if(empty($aResult) || !is_array($aResult) || !$this->serviceActAsProfile())
  656. return $aResult;
  657. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$aEvent['object_id'], $this->_oConfig->getName());
  658. if($oProfile !== false)
  659. $aResult['entry_author'] = $oProfile->id();
  660. return $aResult;
  661. }
  662. public function serviceGetNotificationsVote($aEvent)
  663. {
  664. $aResult = parent::serviceGetNotificationsVote($aEvent);
  665. if(empty($aResult) || !is_array($aResult) || !$this->serviceActAsProfile())
  666. return $aResult;
  667. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$aEvent['object_id'], $this->_oConfig->getName());
  668. if($oProfile !== false)
  669. $aResult['entry_author'] = $oProfile->id();
  670. return $aResult;
  671. }
  672. /**
  673. * Notification about new member requst in the group
  674. */
  675. public function serviceGetNotificationsTimelinePostCommon($aEvent)
  676. {
  677. $CNF = &$this->_oConfig->CNF;
  678. $iContentId = (int)$aEvent['object_id'];
  679. $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  680. if(!$oGroupProfile)
  681. return array();
  682. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  683. if(empty($aContentInfo) || !is_array($aContentInfo))
  684. return array();
  685. $aSubcontentInfo = BxDolService::call('bx_timeline', 'get_info', array((int)$aEvent['subobject_id'], false));
  686. if(empty($aSubcontentInfo) || !is_array($aSubcontentInfo))
  687. return array();
  688. $sSubentryUrl = BxDolService::call('bx_timeline', 'get_link', array((int)$aEvent['subobject_id']));
  689. $sSubentrySample = $aSubcontentInfo['title'];
  690. if(empty($sSubentrySample))
  691. $sSubentrySample = strmaxtextlen($aSubcontentInfo['description'], 20, '...');
  692. return array(
  693. 'entry_sample' => $CNF['T']['txt_sample_single'],
  694. 'entry_url' => $oGroupProfile->getUrl(),
  695. 'entry_caption' => $oGroupProfile->getDisplayName(),
  696. 'entry_author' => $oGroupProfile->id(),
  697. 'subentry_sample' => $sSubentrySample,
  698. 'subentry_url' => $sSubentryUrl,
  699. 'lang_key' => $CNF['T']['txt_ntfs_timeline_post_common'],
  700. );
  701. }
  702. /**
  703. * Data for Timeline module
  704. */
  705. public function serviceGetTimelineData()
  706. {
  707. $CNF = &$this->_oConfig->CNF;
  708. $sModule = $this->_aModule['name'];
  709. $aAlerts = array();
  710. $aHandlers = array();
  711. if(!empty($CNF['FIELD_PICTURE'])) {
  712. $aAlerts = array_merge($aAlerts, array(
  713. array('unit' => $sModule, 'action' => 'profile_picture_changed'),
  714. array('unit' => $sModule, 'action' => 'profile_picture_deleted')
  715. ));
  716. $aHandlers = array_merge($aHandlers, array(
  717. 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' => ''),
  718. array('group' => $sModule . '_profile_picture', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'profile_picture_deleted')
  719. ));
  720. }
  721. if(!empty($CNF['FIELD_COVER'])) {
  722. $aAlerts = array_merge($aAlerts, array(
  723. array('unit' => $sModule, 'action' => 'profile_cover_changed'),
  724. array('unit' => $sModule, 'action' => 'profile_cover_deleted')
  725. ));
  726. $aHandlers = array_merge($aHandlers, array(
  727. 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' => ''),
  728. array('group' => $sModule . '_profile_cover', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'profile_cover_deleted')
  729. ));
  730. }
  731. $aResult = array();
  732. if(!empty($aAlerts) && !empty($aHandlers))
  733. $aResult = array(
  734. 'handlers' => $aHandlers,
  735. 'alerts' => $aAlerts
  736. );
  737. return $aResult;
  738. }
  739. /**
  740. * Entry post for Timeline module
  741. */
  742. public function serviceGetTimelineProfilePicture($aEvent, $aBrowseParams = array())
  743. {
  744. return $this->_serviceGetTimelineProfileImage($aEvent, $aBrowseParams, array(
  745. 'stg' => 'OBJECT_STORAGE',
  746. 'trans' => array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_AVATAR'),
  747. 'trans_orig' => array('OBJECT_IMAGES_TRANSCODER_PICTURE', 'OBJECT_IMAGES_TRANSCODER_GALLERY'),
  748. 'txt_ss' => 'txt_sample_pp_single',
  749. 'txt_sswa' => 'txt_sample_pp_single_with_article',
  750. 'txt_sa' => 'txt_sample_pi_action',
  751. 'txt_sau' => 'txt_sample_pi_action_user'
  752. ));
  753. }
  754. public function serviceGetTimelineProfileCover($aEvent, $aBrowseParams = array())
  755. {
  756. return $this->_serviceGetTimelineProfileImage($aEvent, $aBrowseParams, array(
  757. 'stg' => 'OBJECT_STORAGE_COVER',
  758. 'trans' => array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_COVER_THUMB'),
  759. 'trans_orig' => array('OBJECT_IMAGES_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_GALLERY'),
  760. 'txt_ss' => 'txt_sample_pc_single',
  761. 'txt_sswa' => 'txt_sample_pc_single_with_article',
  762. 'txt_sa' => 'txt_sample_pi_action',
  763. 'txt_sau' => 'txt_sample_pi_action_user'
  764. ));
  765. }
  766. public function serviceGetConnectionButtonsTitles($iProfileId, $sConnectionsObject = 'sys_profiles_friends')
  767. {
  768. if (!isLogged())
  769. return array();
  770. if (!($oConn = BxDolConnection::getObjectInstance($sConnectionsObject)))
  771. return array();
  772. $CNF = $this->_oConfig->CNF;
  773. if ($oConn->isConnectedNotMutual(bx_get_logged_profile_id(), $iProfileId)) {
  774. return array(
  775. 'add' => _t($CNF['T']['menu_item_title_befriend_sent']),
  776. 'remove' => _t($CNF['T']['menu_item_title_unfriend_cancel_request']),
  777. );
  778. } elseif ($oConn->isConnectedNotMutual($iProfileId, bx_get_logged_profile_id())) {
  779. return array(
  780. 'add' => _t($CNF['T']['menu_item_title_befriend_confirm']),
  781. 'remove' => _t($CNF['T']['menu_item_title_unfriend_reject_request']),
  782. );
  783. } elseif ($oConn->isConnected($iProfileId, bx_get_logged_profile_id(), true)) {
  784. return array(
  785. 'add' => '',
  786. 'remove' => _t($CNF['T']['menu_item_title_unfriend']),
  787. );
  788. } else {
  789. return array(
  790. 'add' => _t($CNF['T']['menu_item_title_befriend']),
  791. 'remove' => '',
  792. );
  793. }
  794. }
  795. // ====== PERMISSION METHODS
  796. /**
  797. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  798. */
  799. public function checkAllowedAdd ($isPerformAction = false)
  800. {
  801. $oAccount = BxDolAccount::getInstance();
  802. if (!$oAccount || ($this->serviceActAsProfile() && $oAccount->isProfilesLimitReached()))
  803. return _t('_sys_txt_access_denied');
  804. return parent::checkAllowedAdd ($isPerformAction);
  805. }
  806. /**
  807. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  808. */
  809. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  810. {
  811. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
  812. }
  813. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  814. {
  815. if (!$iProfileId)
  816. $iProfileId = $this->_iProfileId;
  817. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  818. if ($oProfile && $oProfile->id() == $iProfileId)
  819. return CHECK_ACTION_RESULT_ALLOWED;
  820. return parent::serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  821. }
  822. /**
  823. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  824. */
  825. public function checkAllowedViewProfileImage ($aDataEntry, $isPerformAction = false)
  826. {
  827. $CNF = &$this->_oConfig->CNF;
  828. // check privacy
  829. if (empty($CNF['OBJECT_PRIVACY_VIEW']))
  830. return CHECK_ACTION_RESULT_ALLOWED;
  831. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  832. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']]) && !$oPrivacy->isPartiallyVisible($aDataEntry[$CNF['FIELD_ALLOW_VIEW_TO']]))
  833. return _t('_sys_access_denied_to_private_content');
  834. return CHECK_ACTION_RESULT_ALLOWED;
  835. }
  836. /**
  837. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  838. */
  839. public function checkAllowedViewCoverImage ($aDataEntry, $isPerformAction = false)
  840. {
  841. return $this->checkAllowedViewProfileImage($aDataEntry);
  842. }
  843. /**
  844. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  845. */
  846. public function checkAllowedPost ($aDataEntry, $isPerformAction = false)
  847. {
  848. return $this->checkAllowedView ($aDataEntry, $isPerformAction);
  849. }
  850. /**
  851. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  852. */
  853. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  854. {
  855. // moderator always has access
  856. if ($this->_isModerator($isPerformAction))
  857. return CHECK_ACTION_RESULT_ALLOWED;
  858. // owner (checked by account! not as profile as ususal) always have access
  859. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name']);
  860. if (!$oProfile)
  861. return _t('_sys_txt_error_occured');
  862. if ($oProfile->getAccountId() == $this->_iAccountId)
  863. return CHECK_ACTION_RESULT_ALLOWED;
  864. return _t('_sys_txt_access_denied');
  865. }
  866. /**
  867. * Check if user can change cover image
  868. */
  869. public function checkAllowedChangeCover ($aDataEntry, $isPerformAction = false)
  870. {
  871. // moderator always has access
  872. if ($this->_isModerator($isPerformAction))
  873. return CHECK_ACTION_RESULT_ALLOWED;
  874. // owner (checked by account! not as profile as ususal) always have access
  875. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name']);
  876. if (!$oProfile)
  877. return _t('_sys_txt_error_occured');
  878. if ($oProfile->getAccountId() == $this->_iAccountId)
  879. return CHECK_ACTION_RESULT_ALLOWED;
  880. return _t('_sys_txt_access_denied');
  881. }
  882. /**
  883. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  884. */
  885. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  886. {
  887. // moderator always has access
  888. if ($this->_isModerator($isPerformAction))
  889. return CHECK_ACTION_RESULT_ALLOWED;
  890. // check ACL and owner (checked by account! not as profile as ususal)
  891. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  892. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name'], $isPerformAction);
  893. if (!$oProfile)
  894. return _t('_sys_txt_error_occured');
  895. if ($oProfile->getAccountId() == $this->_iAccountId && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  896. return CHECK_ACTION_RESULT_ALLOWED;
  897. return _t('_sys_txt_access_denied');
  898. }
  899. /**
  900. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  901. */
  902. public function checkAllowedViewMoreMenu (&$aDataEntry, $isPerformAction = false)
  903. {
  904. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']);
  905. if (!$oMenu || !$oMenu->getCode())
  906. return _t('_sys_txt_access_denied');
  907. return CHECK_ACTION_RESULT_ALLOWED;
  908. }
  909. /**
  910. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  911. */
  912. public function checkAllowedCompose (&$aDataEntry, $isPerformAction = false)
  913. {
  914. $CNF = &$this->_oConfig->CNF;
  915. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->getName());
  916. if($oProfile && $oProfile->id() == $this->_iProfileId)
  917. return _t('_sys_txt_access_denied');
  918. return $this->checkAllowedView ($aDataEntry, $isPerformAction);
  919. }
  920. /**
  921. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  922. */
  923. public function checkAllowedFriendAdd (&$aDataEntry, $isPerformAction = false)
  924. {
  925. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', true, false);
  926. }
  927. /**
  928. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  929. */
  930. public function checkAllowedFriendRemove (&$aDataEntry, $isPerformAction = false)
  931. {
  932. if (CHECK_ACTION_RESULT_ALLOWED === $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', false, true, true))
  933. return CHECK_ACTION_RESULT_ALLOWED;
  934. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', false, true, false);
  935. }
  936. /**
  937. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  938. */
  939. public function checkAllowedRelationAdd (&$aDataEntry, $isPerformAction = false)
  940. {
  941. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedView($aDataEntry)))
  942. return $sMsg;
  943. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_relations', false, false);
  944. }
  945. /**
  946. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  947. */
  948. public function checkAllowedRelationRemove (&$aDataEntry, $isPerformAction = false)
  949. {
  950. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_relations', false, true);
  951. }
  952. public function checkAllowedRelationsView (&$aDataEntry, $isPerformAction = false)
  953. {
  954. $CNF = &$this->_oConfig->CNF;
  955. $sResult = _t('_sys_txt_access_denied');
  956. if(empty($aDataEntry) || !is_array($aDataEntry))
  957. return $sResult;
  958. return CHECK_ACTION_RESULT_ALLOWED;
  959. }
  960. /**
  961. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  962. */
  963. public function checkAllowedSubscribeAdd (&$aDataEntry, $isPerformAction = false)
  964. {
  965. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedView($aDataEntry)))
  966. return $sMsg;
  967. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_subscriptions', false, false);
  968. }
  969. /**
  970. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  971. */
  972. public function checkAllowedSubscribeRemove (&$aDataEntry, $isPerformAction = false)
  973. {
  974. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_subscriptions', false, true);
  975. }
  976. public function checkAllowedSubscriptionsView (&$aDataEntry, $isPerformAction = false)
  977. {
  978. $CNF = &$this->_oConfig->CNF;
  979. $sResult = _t('_sys_txt_access_denied');
  980. if(empty($aDataEntry) || !is_array($aDataEntry))
  981. return $sResult;
  982. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->_aModule['name']);
  983. if(!$oProfile || ($oProfile->id() != $this->_iProfileId && $this->_oDb->getParam($CNF['PARAM_PUBLIC_SBSN']) != 'on' && $this->_oDb->getParam($CNF['PARAM_PUBLIC_SBSD']) != 'on'))
  984. return $sResult;
  985. return CHECK_ACTION_RESULT_ALLOWED;
  986. }
  987. public function checkMyself($iContentId)
  988. {
  989. $iLogged = (int)bx_get_logged_profile_id();
  990. if(empty($iLogged))
  991. return false;
  992. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->_oConfig->getName());
  993. if(!$oProfile)
  994. return false;
  995. return $oProfile->id() == $iLogged;
  996. }
  997. // ====== PROTECTED METHODS
  998. protected function _checkAllowedConnect (&$aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap = false)
  999. {
  1000. if (!$this->_iProfileId)
  1001. return _t('_sys_txt_access_denied');
  1002. $CNF = &$this->_oConfig->CNF;
  1003. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->_aModule['name']);
  1004. if (!$oProfile || $oProfile->id() == $this->_iProfileId)
  1005. return _t('_sys_txt_access_denied');
  1006. return BxDolConnection::getObjectInstance($sObjConnection)->checkAllowedConnect ($this->_iProfileId, $oProfile->id(), $isPerformAction, $isMutual, $isInvertResult, $isSwap);
  1007. }
  1008. protected function _buildRssParams($sMode, $aArgs)
  1009. {
  1010. $aParams = array ();
  1011. $sMode = bx_process_input($sMode);
  1012. switch ($sMode) {
  1013. case 'connections':
  1014. $aParams = array(
  1015. 'object' => isset($aArgs[0]) ? $aArgs[0] : '',
  1016. 'type' => isset($aArgs[1]) ? $aArgs[1] : '',
  1017. 'profile' => isset($aArgs[2]) ? (int)$aArgs[2] : 0,
  1018. 'mutual' => isset($aArgs[3]) ? (int)$aArgs[3] : 0,
  1019. 'profile2' => isset($aArgs[4]) ? (int)$aArgs[4] : 0,
  1020. );
  1021. break;
  1022. }
  1023. return $aParams;
  1024. }
  1025. protected function _serviceBrowseQuick($aProfiles, $iStart = 0, $iLimit = 4, $aAdditionalParams = array())
  1026. {
  1027. // get paginate object
  1028. $oPaginate = new BxTemplPaginate(array(
  1029. 'on_change_page' => "return !loadDynamicBlockAutoPaginate(this, '{start}', '{per_page}', " . bx_js_string(json_encode($aAdditionalParams)) . ");",
  1030. 'num' => count($aProfiles),
  1031. 'per_page' => $iLimit,
  1032. 'start' => $iStart,
  1033. ));
  1034. // remove last item from connection array, because we've got one more item for pagination calculations only
  1035. if (count($aProfiles) > $iLimit)
  1036. array_pop($aProfiles);
  1037. // get profiles HTML
  1038. $s = '';
  1039. foreach ($aProfiles as $mixedProfile) {
  1040. $bProfile = is_array($mixedProfile);
  1041. $oProfile = BxDolProfile::getInstance($bProfile ? (int)$mixedProfile['id'] : (int)$mixedProfile);
  1042. if(!$oProfile)
  1043. continue;
  1044. $aUnitParams = array();
  1045. if($bProfile && is_array($mixedProfile['info']))
  1046. $aUnitParams = array('template' => array('vars' => $mixedProfile['info']));
  1047. $s .= $oProfile->getUnit(0, $aUnitParams);
  1048. }
  1049. // return profiles + paginate
  1050. return $s . (!$iStart && $oPaginate->getNum() <= $iLimit ? '' : $oPaginate->getSimplePaginate());
  1051. }
  1052. protected function _serviceGetTimelineProfileImage($aEvent, $aBrowseParams, $aBuildParams)
  1053. {
  1054. $CNF = &$this->_oConfig->CNF;
  1055. $aFileInfo = BxDolStorage::getObjectInstance($CNF[$aBuildParams['stg']])->getFile((int)$aEvent['object_id']);
  1056. if(empty($aFileInfo) || !is_array($aFileInfo))
  1057. return false;
  1058. $aEventContent = unserialize($aEvent['content']);
  1059. if(!is_array($aEventContent) || empty($aEventContent['content']))
  1060. return false;
  1061. $aContentInfo = $this->_oDb->getContentInfoById($aEventContent['content']);
  1062. if(empty($aContentInfo) || !is_array($aContentInfo))
  1063. return false;
  1064. $oProfile = BxDolProfile::getInstanceMagic($aContentInfo['profile_id']);
  1065. if (!$oProfile->isActive())
  1066. return false;
  1067. $sUserName = $oProfile->getDisplayName();
  1068. $sSample = isset($CNF['T'][$aBuildParams['txt_sswa']]) ? $CNF['T'][$aBuildParams['txt_sswa']] : $CNF['T'][$aBuildParams['txt_ss']];
  1069. //--- Title & Description
  1070. $sTitle = !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '';
  1071. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TEXT']]))
  1072. $sTitle = $aContentInfo[$CNF['FIELD_TEXT']];
  1073. $sDescription = _t($CNF['T'][$aBuildParams['txt_sau']], $sUserName, _t($sSample));
  1074. return array(
  1075. 'owner_id' => $aContentInfo['profile_id'],
  1076. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  1077. 'sample' => $sSample,
  1078. 'sample_wo_article' => $CNF['T'][$aBuildParams['txt_ss']],
  1079. 'sample_action' => isset($CNF['T'][$aBuildParams['txt_sa']]) ? $CNF['T'][$aBuildParams['txt_sa']] : '',
  1080. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]),
  1081. 'content' => $this->_getContentForTimelineProfileImage($aEvent, $aBrowseParams, $aBuildParams, $aContentInfo, $aFileInfo), //a string to display or array to parse default template before displaying.
  1082. 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
  1083. 'views' => '',
  1084. 'votes' => '',
  1085. 'scores' => '',
  1086. 'reports' => '',
  1087. 'comments' => '',
  1088. 'title' => $sTitle, //may be empty.
  1089. 'description' => $sDescription //may be empty.
  1090. );
  1091. }
  1092. protected function _getContentForTimelineProfileImage($aEvent, $aBrowseParams, $aBuildParams, $aContentInfo, $aFileInfo)
  1093. {
  1094. $CNF = &$this->_oConfig->CNF;
  1095. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1096. //--- Image(s)
  1097. $sImage = $this->_oConfig->getImageUrl($aFileInfo['id'], $aBuildParams['trans']);
  1098. $sImageOrig = $this->_oConfig->getImageUrl($aFileInfo['id'], $aBuildParams['trans_orig']);
  1099. if(!empty($sImage)) {
  1100. if(empty($sImageOrig))
  1101. $sImageOrig = $sImage;
  1102. $a = array('url' => $sUrl, 'src' => $sImage);
  1103. if (CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedView($aContentInfo))
  1104. $a['src_orig'] = $sImageOrig;
  1105. $aImages = array($a);
  1106. }
  1107. return array(
  1108. 'sample' => isset($CNF['T'][$aBuildParams['txt_sswa']]) ? $CNF['T'][$aBuildParams['txt_sswa']] : $CNF['T'][$aBuildParams['txt_ss']],
  1109. 'sample_wo_article' => $CNF['T'][$aBuildParams['txt_ss']],
  1110. 'sample_action' => isset($CNF['T'][$aBuildParams['txt_sa']]) ? $CNF['T'][$aBuildParams['txt_sa']] : '',
  1111. 'url' => $sUrl,
  1112. 'title' => '',
  1113. 'text' => '',
  1114. 'images' => $aImages,
  1115. 'videos' => array()
  1116. );
  1117. }
  1118. protected function _entityComments($sObject, $iId = 0)
  1119. {
  1120. if(!$iId)
  1121. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1122. if(!$iId)
  1123. $iId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  1124. if(!$iId)
  1125. return false;
  1126. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  1127. if(!$oCmts || !$oCmts->isEnabled())
  1128. return false;
  1129. return $oCmts->getCommentsBlock(array(), array('in_designbox' => false));
  1130. }
  1131. protected function _getContent($iContentId = 0, $sFuncGetContent = 'getContentInfoById')
  1132. {
  1133. if(!$iContentId && bx_get('id') === false && bx_get('profile_id') !== false) {
  1134. $oProfile = BxDolProfile::getInstance((int)bx_get('profile_id'));
  1135. if($oProfile)
  1136. $iContentId = $oProfile->getContentId();
  1137. }
  1138. return parent::_getContent($iContentId, $sFuncGetContent);
  1139. }
  1140. }
  1141. /** @} */