BxBaseModProfileModule.php 46 KB

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