BxBaseModProfileModule.php 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468
  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. * Prepare fields from some universal set of fields to fields in particular profile module.
  310. * By default only 'name' and 'description' fields are supported.
  311. * After fields convertion it can be used in @see BxBaseModGeneralModule::serviceEntityAdd
  312. * @param $aFieldsProfile fields in soem universal format.
  313. * @return array which is ready to use for particular module
  314. */
  315. public function servicePrepareFields ($aFieldsProfile)
  316. {
  317. bx_alert($this->getName(), 'prepare_fields', 0, 0, array('fields_orig' => $aFieldsProfile, 'fields_result' => &$aFieldsProfile));
  318. return $aFieldsProfile;
  319. }
  320. protected function _servicePrepareFields ($aFieldsProfile, $aFieldsDefault, $aMap)
  321. {
  322. $aFieldsOrig = $aFieldsProfile;
  323. bx_import('BxDolPrivacy');
  324. $aFieldsDefault2 = array(
  325. 'allow_view_to' => BX_DOL_PG_ALL,
  326. );
  327. $aFieldsProfile = array_merge($aFieldsDefault2, $aFieldsDefault, $aFieldsProfile);
  328. foreach ($aMap as $k => $v) {
  329. if (isset($aFieldsProfile[$v]))
  330. $aFieldsProfile[$k] = $aFieldsProfile[$v];
  331. if ($k != $v && !isset($aMap[$v]))
  332. unset($aFieldsProfile[$v]);
  333. }
  334. bx_alert($this->getName(), 'prepare_fields', 0, 0, array('fields_orig' => $aFieldsOrig, 'fields_result' => &$aFieldsProfile));
  335. return $aFieldsProfile;
  336. }
  337. public function serviceFormsHelper ()
  338. {
  339. return parent::serviceFormsHelper ();
  340. }
  341. public function serviceEntityCreate ($sDisplay = false)
  342. {
  343. BxDolInformer::getInstance($this->_oTemplate)->setEnabled(false);
  344. return parent::serviceEntityCreate ($sDisplay);
  345. }
  346. public function serviceActAsProfile ()
  347. {
  348. return true;
  349. }
  350. public function serviceBrowseRecommended ($sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = true)
  351. {
  352. if (!isLogged())
  353. return '';
  354. return $this->_serviceBrowse ('recommended', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  355. }
  356. public function serviceBrowseRecentProfiles ($bDisplayEmptyMsg = false, $bAjaxPaginate = true)
  357. {
  358. return $this->_serviceBrowse ('recent', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate);
  359. }
  360. public function serviceBrowseActiveProfiles ($sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = false)
  361. {
  362. return $this->_serviceBrowse ('active', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  363. }
  364. public function serviceBrowseTopProfiles ($bDisplayEmptyMsg = false, $bAjaxPaginate = false)
  365. {
  366. return $this->_serviceBrowse ('top', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate);
  367. }
  368. public function serviceBrowseOnlineProfiles ($bDisplayEmptyMsg = false, $bAjaxPaginate = false)
  369. {
  370. return $this->_serviceBrowse ('online', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate);
  371. }
  372. public function serviceBrowseConnections ($iProfileId, $sObjectConnections = 'sys_profiles_friends', $sConnectionsType = 'content', $iMutual = false, $iDesignBox = BX_DB_PADDING_DEF, $iProfileId2 = 0)
  373. {
  374. return $this->_serviceBrowse (
  375. 'connections',
  376. array(
  377. 'object' => $sObjectConnections,
  378. 'type' => $sConnectionsType,
  379. 'mutual' => $iMutual,
  380. 'profile' => (int)$iProfileId,
  381. 'profile2' => (int)$iProfileId2),
  382. $iDesignBox
  383. );
  384. }
  385. public function serviceBrowseRelationsQuick ($iProfileId, $sObjectConnections = 'sys_profiles_friends', $sConnectionsType = 'content', $iMutual = false, $iProfileId2 = 0)
  386. {
  387. // get connections object
  388. $oConnection = BxDolConnection::getObjectInstance($sObjectConnections);
  389. if (!$oConnection)
  390. return '';
  391. // set some vars
  392. $iStart = (int)bx_get('start');
  393. $iLimit = empty($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? 4 : getParam($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']);
  394. if (!$iLimit)
  395. $iLimit = 4;
  396. // get connections array
  397. bx_import('BxDolConnection');
  398. $aConnections = $oConnection->getConnectionsAsArrayExt($sConnectionsType, $iProfileId, $iProfileId2, $iMutual, $iStart, $iLimit + 1, BX_CONNECTIONS_ORDER_ADDED_DESC);
  399. if(empty($aConnections) || !is_array($aConnections))
  400. return '';
  401. $aResult = array();
  402. foreach($aConnections as $iProfile => $aConnection)
  403. $aResult[] = array(
  404. 'id' => $iProfile,
  405. 'info' => array(
  406. 'addon' => $oConnection->getRelationTranslation($aConnection['relation'])
  407. )
  408. );
  409. return $this->_serviceBrowseQuick($aResult, $iStart, $iLimit);
  410. }
  411. public function serviceBrowseConnectionsQuick ($iProfileId, $sObjectConnections = 'sys_profiles_friends', $sConnectionsType = 'content', $iMutual = false, $iProfileId2 = 0)
  412. {
  413. // get connections object
  414. $oConnection = BxDolConnection::getObjectInstance($sObjectConnections);
  415. if (!$oConnection)
  416. return '';
  417. // set some vars
  418. $iLimit = empty($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? 4 : getParam($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']);
  419. if (!$iLimit)
  420. $iLimit = 4;
  421. $iStart = (int)bx_get('start');
  422. // get connections array
  423. bx_import('BxDolConnection');
  424. $a = $oConnection->getConnectionsAsArray ($sConnectionsType, $iProfileId, $iProfileId2, $iMutual, (int)bx_get('start'), $iLimit + 1, BX_CONNECTIONS_ORDER_ADDED_DESC);
  425. if (!$a)
  426. return '';
  427. return $this->_serviceBrowseQuick($a, $iStart, $iLimit);
  428. }
  429. public function serviceBrowseConnectionsByType ($aParamsCnn, $aParamsBrs = array())
  430. {
  431. $sAll = 'all';
  432. $aParamsCnn['object'] = !empty($aParamsCnn['object']) ? $aParamsCnn['object'] : 'sys_profiles_friends';
  433. $aParamsCnn['type'] = !empty($aParamsCnn['type']) ? $aParamsCnn['type'] : 'content';
  434. $aParamsCnn['profile_id2'] = !empty($aParamsCnn['profile_id2']) ? (int)$aParamsCnn['profile_id2'] : 0;
  435. $aParamsCnn['mutual'] = isset($aParamsCnn['mutual']) ? $aParamsCnn['mutual'] : false;
  436. $oConnection = BxDolConnection::getObjectInstance($aParamsCnn['object']);
  437. if(!$oConnection)
  438. return '';
  439. $aSQLParts = $oConnection->getConnectionsAsSQLParts ($aParamsCnn['type'], 'sys_profiles', 'id', $aParamsCnn['profile_id'], $aParamsCnn['profile_id2'], $aParamsCnn['mutual']);
  440. $sType = !empty($aParamsBrs['type']) ? $aParamsBrs['type'] : $sAll;
  441. if(bx_get('type') !== false)
  442. $sType = bx_process_input(bx_get('type'));
  443. $iStart = (int)bx_get('start');
  444. $iLimitDefault = 4;
  445. $iLimit = !empty($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? getParam($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) : $iLimitDefault;
  446. if(!empty($aParamsBrs['per_page']))
  447. $iLimit = (int)$aParamsBrs['per_page'];
  448. if(!$iLimit)
  449. $iLimit = $iLimitDefault;
  450. $aProfiles = BxDolProfileQuery::getInstance()->getConnectedProfilesByType($aSQLParts, ($sType != $sAll ? $sType : ''), $iStart, $iLimit + 1);
  451. $mixedMenu = '';
  452. if(!isset($aParamsBrs['filter_menu']) || $aParamsBrs['filter_menu'] === true) {
  453. $aModules = array(
  454. array('name' => $sAll)
  455. );
  456. $aModules = array_merge($aModules, BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1)));
  457. $aMenuItems = array();
  458. foreach($aModules as $aModule)
  459. if($aModule['name'] == $sAll || BxDolRequest::serviceExists($aModule['name'], 'act_as_profile'))
  460. $aMenuItems[] = array(
  461. 'id' => $aModule['name'],
  462. 'name' => $aModule['name'],
  463. 'class' => '',
  464. 'link' => 'javascript:void(0)',
  465. 'onclick' => "return !loadDynamicBlockAutoPaginate(this, " . $iStart . ", " . $iLimit . ", " . bx_js_string(json_encode(array('type' => $aModule['name']))) . ");",
  466. 'target' => '_self',
  467. 'title' => _t('_' . $aModule['name']),
  468. 'active' => 1
  469. );
  470. if(!empty($aMenuItems)) {
  471. $mixedMenu = new BxTemplMenu(array('template' => 'menu_vertical.html', 'menu_id'=> $this->_oConfig->getName() . '-connections-by-type', 'menu_items' => $aMenuItems));
  472. $mixedMenu->setSelected('', $sType);
  473. }
  474. }
  475. return array(
  476. 'menu' => $mixedMenu,
  477. 'content' => $this->_serviceBrowseQuick(array_keys($aProfiles), $iStart, $iLimit, array('type' => $sType))
  478. );
  479. }
  480. public function serviceBrowseByAcl ($mixedLevelId, $iDesignBox = BX_DB_PADDING_DEF)
  481. {
  482. return $this->_serviceBrowse (
  483. 'acl',
  484. array(
  485. 'level' => $mixedLevelId,
  486. ),
  487. $iDesignBox,
  488. true
  489. );
  490. }
  491. public function serviceEntityEditCover ($iContentId = 0)
  492. {
  493. return $this->_serviceEntityForm ('editDataForm', $iContentId, $this->_oConfig->CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT_COVER']);
  494. }
  495. /**
  496. * Entry comments
  497. */
  498. public function serviceEntityCommentsByProfile ($iProfileId)
  499. {
  500. $CNF = &$this->_oConfig->CNF;
  501. if(empty($CNF['OBJECT_COMMENTS']))
  502. return '';
  503. $oProfile = BxDolProfile::getInstance($iProfileId);
  504. if(!$oProfile)
  505. return '';
  506. return $this->_entityComments($CNF['OBJECT_COMMENTS'], $oProfile->getContentId());
  507. }
  508. /**
  509. * Entry social sharing block
  510. */
  511. public function serviceEntitySocialSharing ($mixedContent = false, $aParams = array())
  512. {
  513. if(!empty($mixedContent)) {
  514. if(!is_array($mixedContent))
  515. $mixedContent = array((int)$mixedContent, array());
  516. }
  517. else {
  518. $mixedContent = $this->_getContent();
  519. if($mixedContent === false)
  520. return false;
  521. }
  522. list($iContentId, $aContentInfo) = $mixedContent;
  523. return parent::serviceEntitySocialSharing(array($iContentId, $aContentInfo), array(
  524. 'id_thumb' => !empty($CNF['FIELD_PICTURE']) && !empty($aContentInfo[$CNF['FIELD_PICTURE']]) ? $aContentInfo[$CNF['FIELD_PICTURE']] : 0,
  525. ));
  526. }
  527. public function serviceProfileMembership ($iContentId = 0)
  528. {
  529. $mixedContent = $this->_getContent($iContentId);
  530. if($mixedContent === false)
  531. return false;
  532. list($iContentId, $aContentInfo) = $mixedContent;
  533. return BxDolAcl::getInstance()->getProfileMembership($aContentInfo['profile_id']);
  534. }
  535. public function serviceProfileFriends ($iContentId = 0)
  536. {
  537. $mixedContent = $this->_getContent($iContentId);
  538. if($mixedContent === false)
  539. return false;
  540. list($iContentId, $aContentInfo) = $mixedContent;
  541. bx_import('BxDolConnection');
  542. $s = $this->serviceBrowseConnectionsQuick ($aContentInfo['profile_id'], 'sys_profiles_friends', BX_CONNECTIONS_CONTENT_TYPE_CONTENT, true);
  543. if (!$s)
  544. return MsgBox(_t('_sys_txt_empty'));
  545. return $s;
  546. }
  547. public function serviceProfileSubscriptions ($iContentId = 0, $aParams = array())
  548. {
  549. $mixedContent = $this->_getContent($iContentId);
  550. if($mixedContent === false)
  551. return false;
  552. list($iContentId, $aContentInfo) = $mixedContent;
  553. bx_import('BxDolConnection');
  554. $aResult = $this->serviceBrowseConnectionsByType(array(
  555. 'profile_id' => $aContentInfo['profile_id'],
  556. 'object' => 'sys_profiles_subscriptions',
  557. 'type' => BX_CONNECTIONS_CONTENT_TYPE_CONTENT
  558. ), array(
  559. 'type' => isset($aParams['type']) ? $aParams['type'] : '',
  560. 'filter_menu' => isset($aParams['filter_menu']) ? $aParams['filter_menu'] : true,
  561. ));
  562. if(empty($aResult['content']))
  563. $aResult['content'] = MsgBox(_t('_sys_txt_empty'));
  564. return $aResult;
  565. }
  566. public function serviceProfileSubscribedMe ($iContentId = 0)
  567. {
  568. $mixedContent = $this->_getContent($iContentId);
  569. if($mixedContent === false)
  570. return false;
  571. list($iContentId, $aContentInfo) = $mixedContent;
  572. bx_import('BxDolConnection');
  573. $s = $this->serviceBrowseConnectionsQuick ($aContentInfo['profile_id'], 'sys_profiles_subscriptions', BX_CONNECTIONS_CONTENT_TYPE_INITIATORS);
  574. if (!$s)
  575. return MsgBox(_t('_sys_txt_empty'));
  576. return $s;
  577. }
  578. public function serviceProfileRelations ($iContentId = 0, $aParams = array())
  579. {
  580. $mixedContent = $this->_getContent($iContentId);
  581. if($mixedContent === false)
  582. return false;
  583. list($iContentId, $aContentInfo) = $mixedContent;
  584. bx_import('BxDolConnection');
  585. $s = $this->serviceBrowseRelationsQuick ($aContentInfo['profile_id'], 'sys_profiles_relations', BX_CONNECTIONS_CONTENT_TYPE_CONTENT, 1);
  586. if (!$s)
  587. return MsgBox(_t('_sys_txt_empty'));
  588. return $s;
  589. }
  590. public function serviceProfileRelatedMe ($iContentId = 0)
  591. {
  592. $mixedContent = $this->_getContent($iContentId);
  593. if($mixedContent === false)
  594. return false;
  595. list($iContentId, $aContentInfo) = $mixedContent;
  596. bx_import('BxDolConnection');
  597. $s = $this->serviceBrowseRelationsQuick ($aContentInfo['profile_id'], 'sys_profiles_relations', BX_CONNECTIONS_CONTENT_TYPE_INITIATORS, 1);
  598. if (!$s)
  599. return MsgBox(_t('_sys_txt_empty'));
  600. return $s;
  601. }
  602. /**
  603. * check enabled profile activation letter
  604. */
  605. public function serviceIsEnableProfileActivationLetter()
  606. {
  607. $CNF = &$this->_oConfig->CNF;
  608. return isset($CNF['PARAM_ENABLE_ACTIVATION_LETTER']) ? (bool)getParam($CNF['PARAM_ENABLE_ACTIVATION_LETTER']) : true;
  609. }
  610. /**
  611. * For internal usage only.
  612. */
  613. public function serviceDeleteEntityService ($iContentId, $bDeleteWithContent = false)
  614. {
  615. return parent::serviceDeleteEntity ($iContentId, 'deleteDataService');
  616. }
  617. /**
  618. * Data for Notifications module
  619. */
  620. public function serviceGetNotificationsData()
  621. {
  622. $a = parent::serviceGetNotificationsData();
  623. $sModule = $this->_aModule['name'];
  624. $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');
  625. $a['settings'][] = array('group' => 'timeline_post', 'unit' => $sModule, 'action' => 'timeline_post_common', 'types' => array('follow_member'));
  626. $a['alerts'][] = array('unit' => $sModule, 'action' => 'timeline_post_common');
  627. return $a;
  628. }
  629. public function serviceGetNotificationsPost($aEvent)
  630. {
  631. $aResult = parent::serviceGetNotificationsVote($aEvent);
  632. if(empty($aResult) || !is_array($aResult) || !$this->serviceActAsProfile())
  633. return $aResult;
  634. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$aEvent['object_id'], $this->_oConfig->getName());
  635. if($oProfile !== false)
  636. $aResult['entry_author'] = $oProfile->id();
  637. return $aResult;
  638. }
  639. public function serviceGetNotificationsVote($aEvent)
  640. {
  641. $aResult = parent::serviceGetNotificationsVote($aEvent);
  642. if(empty($aResult) || !is_array($aResult) || !$this->serviceActAsProfile())
  643. return $aResult;
  644. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$aEvent['object_id'], $this->_oConfig->getName());
  645. if($oProfile !== false)
  646. $aResult['entry_author'] = $oProfile->id();
  647. return $aResult;
  648. }
  649. /**
  650. * Notification about new member requst in the group
  651. */
  652. public function serviceGetNotificationsTimelinePostCommon($aEvent)
  653. {
  654. $CNF = &$this->_oConfig->CNF;
  655. $iContentId = (int)$aEvent['object_id'];
  656. $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  657. if(!$oGroupProfile)
  658. return array();
  659. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  660. if(empty($aContentInfo) || !is_array($aContentInfo))
  661. return array();
  662. $aSubcontentInfo = BxDolService::call('bx_timeline', 'get_info', array((int)$aEvent['subobject_id'], false));
  663. if(empty($aSubcontentInfo) || !is_array($aSubcontentInfo))
  664. return array();
  665. $sSubentryUrl = BxDolService::call('bx_timeline', 'get_link', array((int)$aEvent['subobject_id']));
  666. $sSubentrySample = $aSubcontentInfo['title'];
  667. if(empty($sSubentrySample))
  668. $sSubentrySample = strmaxtextlen($aSubcontentInfo['description'], 20, '...');
  669. return array(
  670. 'entry_sample' => $CNF['T']['txt_sample_single'],
  671. 'entry_url' => $oGroupProfile->getUrl(),
  672. 'entry_caption' => $oGroupProfile->getDisplayName(),
  673. 'entry_author' => $oGroupProfile->id(),
  674. 'subentry_sample' => $sSubentrySample,
  675. 'subentry_url' => $sSubentryUrl,
  676. 'lang_key' => $CNF['T']['txt_ntfs_timeline_post_common'],
  677. );
  678. }
  679. /**
  680. * Data for Timeline module
  681. */
  682. public function serviceGetTimelineData()
  683. {
  684. $CNF = &$this->_oConfig->CNF;
  685. $sModule = $this->_aModule['name'];
  686. $aAlerts = array();
  687. $aHandlers = array();
  688. if(!empty($CNF['FIELD_PICTURE'])) {
  689. $aAlerts = array_merge($aAlerts, array(
  690. array('unit' => $sModule, 'action' => 'profile_picture_changed'),
  691. array('unit' => $sModule, 'action' => 'profile_picture_deleted')
  692. ));
  693. $aHandlers = array_merge($aHandlers, array(
  694. 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' => ''),
  695. array('group' => $sModule . '_profile_picture', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'profile_picture_deleted')
  696. ));
  697. }
  698. if(!empty($CNF['FIELD_COVER'])) {
  699. $aAlerts = array_merge($aAlerts, array(
  700. array('unit' => $sModule, 'action' => 'profile_cover_changed'),
  701. array('unit' => $sModule, 'action' => 'profile_cover_deleted')
  702. ));
  703. $aHandlers = array_merge($aHandlers, array(
  704. 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' => ''),
  705. array('group' => $sModule . '_profile_cover', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'profile_cover_deleted')
  706. ));
  707. }
  708. $aResult = array();
  709. if(!empty($aAlerts) && !empty($aHandlers))
  710. $aResult = array(
  711. 'handlers' => $aHandlers,
  712. 'alerts' => $aAlerts
  713. );
  714. return $aResult;
  715. }
  716. /**
  717. * Entry post for Timeline module
  718. */
  719. public function serviceGetTimelineProfilePicture($aEvent, $aBrowseParams = array())
  720. {
  721. return $this->_serviceGetTimelineProfileImage($aEvent, $aBrowseParams, array(
  722. 'stg' => 'OBJECT_STORAGE',
  723. 'trans' => array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_AVATAR'),
  724. 'trans_orig' => array('OBJECT_IMAGES_TRANSCODER_PICTURE', 'OBJECT_IMAGES_TRANSCODER_GALLERY'),
  725. 'txt_ss' => 'txt_sample_pp_single',
  726. 'txt_sswa' => 'txt_sample_pp_single_with_article',
  727. 'txt_sa' => 'txt_sample_pi_action',
  728. 'txt_sau' => 'txt_sample_pi_action_user'
  729. ));
  730. }
  731. public function serviceGetTimelineProfileCover($aEvent, $aBrowseParams = array())
  732. {
  733. return $this->_serviceGetTimelineProfileImage($aEvent, $aBrowseParams, array(
  734. 'stg' => 'OBJECT_STORAGE_COVER',
  735. 'trans' => array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_COVER_THUMB'),
  736. 'trans_orig' => array('OBJECT_IMAGES_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_GALLERY'),
  737. 'txt_ss' => 'txt_sample_pc_single',
  738. 'txt_sswa' => 'txt_sample_pc_single_with_article',
  739. 'txt_sa' => 'txt_sample_pi_action',
  740. 'txt_sau' => 'txt_sample_pi_action_user'
  741. ));
  742. }
  743. public function serviceGetConnectionButtonsTitles($iProfileId, $sConnectionsObject = 'sys_profiles_friends')
  744. {
  745. if (!isLogged())
  746. return array();
  747. if (!($oConn = BxDolConnection::getObjectInstance($sConnectionsObject)))
  748. return array();
  749. $CNF = $this->_oConfig->CNF;
  750. if ($oConn->isConnectedNotMutual(bx_get_logged_profile_id(), $iProfileId)) {
  751. return array(
  752. 'add' => _t($CNF['T']['menu_item_title_befriend_sent']),
  753. 'remove' => _t($CNF['T']['menu_item_title_unfriend_cancel_request']),
  754. );
  755. } elseif ($oConn->isConnectedNotMutual($iProfileId, bx_get_logged_profile_id())) {
  756. return array(
  757. 'add' => _t($CNF['T']['menu_item_title_befriend_confirm']),
  758. 'remove' => _t($CNF['T']['menu_item_title_unfriend_reject_request']),
  759. );
  760. } elseif ($oConn->isConnected($iProfileId, bx_get_logged_profile_id(), true)) {
  761. return array(
  762. 'add' => '',
  763. 'remove' => _t($CNF['T']['menu_item_title_unfriend']),
  764. );
  765. } else {
  766. return array(
  767. 'add' => _t($CNF['T']['menu_item_title_befriend']),
  768. 'remove' => '',
  769. );
  770. }
  771. }
  772. // ====== PERMISSION METHODS
  773. /**
  774. * @see iBxDolProfileService::serviceCheckAllowedProfileView
  775. */
  776. public function serviceCheckAllowedProfileView($iContentId)
  777. {
  778. return $this->serviceCheckAllowedWithContent('View', $iContentId);
  779. }
  780. /**
  781. * @see iBxDolProfileService::serviceCheckAllowedPostInProfile
  782. */
  783. public function serviceCheckAllowedPostInProfile($iContentId)
  784. {
  785. return $this->serviceCheckAllowedWithContent('Post', $iContentId);
  786. }
  787. /**
  788. * @see iBxDolProfileService::serviceCheckSpacePrivacy
  789. */
  790. public function serviceCheckSpacePrivacy($iContentId)
  791. {
  792. return $this->serviceCheckAllowedProfileView($iContentId);
  793. }
  794. /**
  795. * Check if the profile can be viewed.
  796. *
  797. * NOTE. This service should be used if it's needed to pass some specific values in
  798. * $isPerformAction and $iProfileId parameters, otherwise it's recommended to use
  799. * BxBaseModProfileModule::serviceCheckAllowedProfileView service method or
  800. * BxDolProfile::checkAllowedProfileView method.
  801. *
  802. * @param type $aDataEntry - entry which the action will be performed for
  803. * @param type $isPerformAction - perform or just check the action
  804. * @param type $iProfileId - performer's profile ID
  805. * @return integer - one of CHECK_ACTION_RESULT_XXX constants.
  806. */
  807. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  808. {
  809. if (!$iProfileId)
  810. $iProfileId = $this->_iProfileId;
  811. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  812. if ($oProfile && $oProfile->id() == $iProfileId)
  813. return CHECK_ACTION_RESULT_ALLOWED;
  814. return parent::serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  815. }
  816. /**
  817. * Check if posting (comment, post in Timeline) is available.
  818. *
  819. * NOTE. This service should be used if it's needed to pass some specific values in
  820. * $isPerformAction and $iProfileId parameters, otherwise it's recommended to use
  821. * BxBaseModProfileModule::serviceCheckAllowedPostInProfile service method or
  822. * BxDolProfile::checkAllowedPostInProfile method.
  823. *
  824. * @param type $aDataEntry - entry which the action will be performed for
  825. * @param type $isPerformAction - perform or just check the action
  826. * @param type $iProfileId - performer's profile ID
  827. * @return integer - one of CHECK_ACTION_RESULT_XXX constants.
  828. */
  829. public function serviceCheckAllowedPostForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  830. {
  831. $CNF = &$this->_oConfig->CNF;
  832. if(!$iProfileId)
  833. $iProfileId = $this->_iProfileId;
  834. // check is view allowed
  835. if(($mixedResult = $this->serviceCheckAllowedViewForProfile($aDataEntry, $isPerformAction, $iProfileId)) !== CHECK_ACTION_RESULT_ALLOWED)
  836. return $mixedResult;
  837. // moderator and owner always have access
  838. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->getName());
  839. if(($oProfile && $oProfile->id() == $iProfileId) || $this->_isModerator($isPerformAction))
  840. return CHECK_ACTION_RESULT_ALLOWED;
  841. // check privacy
  842. if(!empty($CNF['OBJECT_PRIVACY_POST'])) {
  843. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_POST']);
  844. if($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  845. return _t('_sys_access_denied_to_private_content');
  846. }
  847. // check alert to allow custom checks
  848. $mixedResult = null;
  849. bx_alert('system', 'check_allowed_post', 0, 0, array('module' => $this->getName(), 'content_info' => $aDataEntry, 'profile_id' => $iProfileId, 'override_result' => &$mixedResult));
  850. if($mixedResult !== null)
  851. return $mixedResult;
  852. return CHECK_ACTION_RESULT_ALLOWED;
  853. }
  854. /**
  855. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  856. */
  857. public function checkAllowedAdd ($isPerformAction = false)
  858. {
  859. $oAccount = BxDolAccount::getInstance();
  860. if (!$oAccount || ($this->serviceActAsProfile() && $oAccount->isProfilesLimitReached()))
  861. return _t('_sys_txt_access_denied');
  862. return parent::checkAllowedAdd ($isPerformAction);
  863. }
  864. /**
  865. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  866. */
  867. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  868. {
  869. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
  870. }
  871. /**
  872. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  873. */
  874. public function checkAllowedViewProfileImage ($aDataEntry, $isPerformAction = false)
  875. {
  876. $CNF = &$this->_oConfig->CNF;
  877. // check privacy
  878. if (empty($CNF['OBJECT_PRIVACY_VIEW']))
  879. return CHECK_ACTION_RESULT_ALLOWED;
  880. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  881. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']]) && !$oPrivacy->isPartiallyVisible($aDataEntry[$CNF['FIELD_ALLOW_VIEW_TO']]))
  882. return _t('_sys_access_denied_to_private_content');
  883. return CHECK_ACTION_RESULT_ALLOWED;
  884. }
  885. /**
  886. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  887. */
  888. public function checkAllowedViewCoverImage ($aDataEntry, $isPerformAction = false)
  889. {
  890. return $this->checkAllowedViewProfileImage($aDataEntry);
  891. }
  892. /**
  893. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  894. */
  895. public function checkAllowedPost ($aDataEntry, $isPerformAction = false)
  896. {
  897. return $this->serviceCheckAllowedPostForProfile ($aDataEntry, $isPerformAction);
  898. }
  899. /**
  900. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  901. */
  902. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  903. {
  904. // moderator always has access
  905. if ($this->_isModerator($isPerformAction))
  906. return CHECK_ACTION_RESULT_ALLOWED;
  907. // owner (checked by account! not as profile as ususal) always have access
  908. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name']);
  909. if (!$oProfile)
  910. return _t('_sys_txt_error_occured');
  911. if ($oProfile->getAccountId() == $this->_iAccountId)
  912. return CHECK_ACTION_RESULT_ALLOWED;
  913. return _t('_sys_txt_access_denied');
  914. }
  915. /**
  916. * Check if user can change cover image
  917. */
  918. public function checkAllowedChangeCover ($aDataEntry, $isPerformAction = false)
  919. {
  920. // moderator always has access
  921. if ($this->_isModerator($isPerformAction))
  922. return CHECK_ACTION_RESULT_ALLOWED;
  923. // owner (checked by account! not as profile as ususal) always have access
  924. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name']);
  925. if (!$oProfile)
  926. return _t('_sys_txt_error_occured');
  927. if ($oProfile->getAccountId() == $this->_iAccountId)
  928. return CHECK_ACTION_RESULT_ALLOWED;
  929. return _t('_sys_txt_access_denied');
  930. }
  931. /**
  932. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  933. */
  934. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  935. {
  936. // moderator always has access
  937. if ($this->_isModerator($isPerformAction))
  938. return CHECK_ACTION_RESULT_ALLOWED;
  939. // check ACL and owner (checked by account! not as profile as ususal)
  940. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  941. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name'], $isPerformAction);
  942. if (!$oProfile)
  943. return _t('_sys_txt_error_occured');
  944. if ($oProfile->getAccountId() == $this->_iAccountId && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  945. return CHECK_ACTION_RESULT_ALLOWED;
  946. return _t('_sys_txt_access_denied');
  947. }
  948. /**
  949. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  950. */
  951. public function checkAllowedViewMoreMenu (&$aDataEntry, $isPerformAction = false)
  952. {
  953. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']);
  954. if (!$oMenu || !$oMenu->getCode())
  955. return _t('_sys_txt_access_denied');
  956. return CHECK_ACTION_RESULT_ALLOWED;
  957. }
  958. /**
  959. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  960. */
  961. public function checkAllowedCompose (&$aDataEntry, $isPerformAction = false)
  962. {
  963. $CNF = &$this->_oConfig->CNF;
  964. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->getName());
  965. if($oProfile && $oProfile->id() == $this->_iProfileId)
  966. return _t('_sys_txt_access_denied');
  967. return $this->checkAllowedView ($aDataEntry, $isPerformAction);
  968. }
  969. /**
  970. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  971. */
  972. public function checkAllowedFriendAdd (&$aDataEntry, $isPerformAction = false)
  973. {
  974. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', true, false);
  975. }
  976. /**
  977. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  978. */
  979. public function checkAllowedFriendRemove (&$aDataEntry, $isPerformAction = false)
  980. {
  981. if (CHECK_ACTION_RESULT_ALLOWED === $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', false, true, true))
  982. return CHECK_ACTION_RESULT_ALLOWED;
  983. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', false, true, false);
  984. }
  985. /**
  986. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  987. */
  988. public function checkAllowedRelationAdd (&$aDataEntry, $isPerformAction = false)
  989. {
  990. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedView($aDataEntry)))
  991. return $sMsg;
  992. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_relations', false, false);
  993. }
  994. /**
  995. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  996. */
  997. public function checkAllowedRelationRemove (&$aDataEntry, $isPerformAction = false)
  998. {
  999. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_relations', false, true);
  1000. }
  1001. public function checkAllowedRelationsView (&$aDataEntry, $isPerformAction = false)
  1002. {
  1003. $CNF = &$this->_oConfig->CNF;
  1004. $sResult = _t('_sys_txt_access_denied');
  1005. if(empty($aDataEntry) || !is_array($aDataEntry))
  1006. return $sResult;
  1007. return CHECK_ACTION_RESULT_ALLOWED;
  1008. }
  1009. /**
  1010. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1011. */
  1012. public function checkAllowedSubscribeAdd (&$aDataEntry, $isPerformAction = false)
  1013. {
  1014. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedView($aDataEntry)))
  1015. return $sMsg;
  1016. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_subscriptions', false, false);
  1017. }
  1018. /**
  1019. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1020. */
  1021. public function checkAllowedSubscribeRemove (&$aDataEntry, $isPerformAction = false)
  1022. {
  1023. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_subscriptions', false, true);
  1024. }
  1025. public function checkAllowedSubscriptionsView (&$aDataEntry, $isPerformAction = false)
  1026. {
  1027. $CNF = &$this->_oConfig->CNF;
  1028. $sResult = _t('_sys_txt_access_denied');
  1029. if(empty($aDataEntry) || !is_array($aDataEntry))
  1030. return $sResult;
  1031. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->_aModule['name']);
  1032. if(!$oProfile || ($oProfile->id() != $this->_iProfileId && $this->_oDb->getParam($CNF['PARAM_PUBLIC_SBSN']) != 'on' && $this->_oDb->getParam($CNF['PARAM_PUBLIC_SBSD']) != 'on'))
  1033. return $sResult;
  1034. return CHECK_ACTION_RESULT_ALLOWED;
  1035. }
  1036. public function checkMyself($iContentId)
  1037. {
  1038. $iLogged = (int)bx_get_logged_profile_id();
  1039. if(empty($iLogged))
  1040. return false;
  1041. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->_oConfig->getName());
  1042. if(!$oProfile)
  1043. return false;
  1044. return $oProfile->id() == $iLogged;
  1045. }
  1046. public function getProfileByCurrentUrl ()
  1047. {
  1048. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  1049. if ($iProfileId)
  1050. return BxDolProfile::getInstance($iProfileId);
  1051. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1052. if ($iContentId)
  1053. return BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  1054. return false;
  1055. }
  1056. // ====== PROTECTED METHODS
  1057. protected function _checkAllowedConnect (&$aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap = false)
  1058. {
  1059. if (!$this->_iProfileId)
  1060. return _t('_sys_txt_access_denied');
  1061. $CNF = &$this->_oConfig->CNF;
  1062. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->_aModule['name']);
  1063. if (!$oProfile || $oProfile->id() == $this->_iProfileId)
  1064. return _t('_sys_txt_access_denied');
  1065. return BxDolConnection::getObjectInstance($sObjConnection)->checkAllowedConnect ($this->_iProfileId, $oProfile->id(), $isPerformAction, $isMutual, $isInvertResult, $isSwap);
  1066. }
  1067. protected function _buildRssParams($sMode, $aArgs)
  1068. {
  1069. $aParams = array ();
  1070. $sMode = bx_process_input($sMode);
  1071. switch ($sMode) {
  1072. case 'connections':
  1073. $aParams = array(
  1074. 'object' => isset($aArgs[0]) ? $aArgs[0] : '',
  1075. 'type' => isset($aArgs[1]) ? $aArgs[1] : '',
  1076. 'profile' => isset($aArgs[2]) ? (int)$aArgs[2] : 0,
  1077. 'mutual' => isset($aArgs[3]) ? (int)$aArgs[3] : 0,
  1078. 'profile2' => isset($aArgs[4]) ? (int)$aArgs[4] : 0,
  1079. );
  1080. break;
  1081. }
  1082. return $aParams;
  1083. }
  1084. protected function _serviceBrowseQuick($aProfiles, $iStart = 0, $iLimit = 4, $aAdditionalParams = array())
  1085. {
  1086. // get paginate object
  1087. $oPaginate = new BxTemplPaginate(array(
  1088. 'on_change_page' => "return !loadDynamicBlockAutoPaginate(this, '{start}', '{per_page}', " . bx_js_string(json_encode($aAdditionalParams)) . ");",
  1089. 'num' => count($aProfiles),
  1090. 'per_page' => $iLimit,
  1091. 'start' => $iStart,
  1092. ));
  1093. // remove last item from connection array, because we've got one more item for pagination calculations only
  1094. if (count($aProfiles) > $iLimit)
  1095. array_pop($aProfiles);
  1096. // get profiles HTML
  1097. $s = '';
  1098. foreach ($aProfiles as $mixedProfile) {
  1099. $bProfile = is_array($mixedProfile);
  1100. $oProfile = BxDolProfile::getInstance($bProfile ? (int)$mixedProfile['id'] : (int)$mixedProfile);
  1101. if(!$oProfile)
  1102. continue;
  1103. $aUnitParams = array();
  1104. if($bProfile && is_array($mixedProfile['info']))
  1105. $aUnitParams = array('template' => array('vars' => $mixedProfile['info']));
  1106. $s .= $oProfile->getUnit(0, $aUnitParams);
  1107. }
  1108. // return profiles + paginate
  1109. return $s . (!$iStart && $oPaginate->getNum() <= $iLimit ? '' : $oPaginate->getSimplePaginate());
  1110. }
  1111. protected function _serviceGetTimelineProfileImage($aEvent, $aBrowseParams, $aBuildParams)
  1112. {
  1113. $CNF = &$this->_oConfig->CNF;
  1114. $aFileInfo = BxDolStorage::getObjectInstance($CNF[$aBuildParams['stg']])->getFile((int)$aEvent['object_id']);
  1115. if(empty($aFileInfo) || !is_array($aFileInfo))
  1116. return false;
  1117. $aEventContent = unserialize($aEvent['content']);
  1118. if(!is_array($aEventContent) || empty($aEventContent['content']))
  1119. return false;
  1120. $aContentInfo = $this->_oDb->getContentInfoById($aEventContent['content']);
  1121. if(empty($aContentInfo) || !is_array($aContentInfo))
  1122. return false;
  1123. $oProfile = BxDolProfile::getInstanceMagic($aContentInfo['profile_id']);
  1124. if (!$oProfile->isActive())
  1125. return false;
  1126. $sUserName = $oProfile->getDisplayName();
  1127. $sSample = isset($CNF['T'][$aBuildParams['txt_sswa']]) ? $CNF['T'][$aBuildParams['txt_sswa']] : $CNF['T'][$aBuildParams['txt_ss']];
  1128. //--- Title & Description
  1129. $sTitle = !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '';
  1130. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TEXT']]))
  1131. $sTitle = $aContentInfo[$CNF['FIELD_TEXT']];
  1132. $sDescription = _t($CNF['T'][$aBuildParams['txt_sau']], $sUserName, _t($sSample));
  1133. return array(
  1134. 'owner_id' => $aEvent['owner_id'],
  1135. 'object_owner_id' => $aContentInfo['profile_id'],
  1136. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  1137. 'sample' => $sSample,
  1138. 'sample_wo_article' => $CNF['T'][$aBuildParams['txt_ss']],
  1139. 'sample_action' => isset($CNF['T'][$aBuildParams['txt_sa']]) ? $CNF['T'][$aBuildParams['txt_sa']] : '',
  1140. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]),
  1141. 'content' => $this->_getContentForTimelineProfileImage($aEvent, $aBrowseParams, $aBuildParams, $aContentInfo, $aFileInfo), //a string to display or array to parse default template before displaying.
  1142. 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
  1143. 'views' => '',
  1144. 'votes' => '',
  1145. 'scores' => '',
  1146. 'reports' => '',
  1147. 'comments' => '',
  1148. 'title' => $sTitle, //may be empty.
  1149. 'description' => $sDescription //may be empty.
  1150. );
  1151. }
  1152. protected function _getContentForTimelineProfileImage($aEvent, $aBrowseParams, $aBuildParams, $aContentInfo, $aFileInfo)
  1153. {
  1154. $CNF = &$this->_oConfig->CNF;
  1155. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1156. //--- Image(s)
  1157. $sImage = $this->_oConfig->getImageUrl($aFileInfo['id'], $aBuildParams['trans']);
  1158. $sImageOrig = $this->_oConfig->getImageUrl($aFileInfo['id'], $aBuildParams['trans_orig']);
  1159. if(!empty($sImage)) {
  1160. if(empty($sImageOrig))
  1161. $sImageOrig = $sImage;
  1162. $a = array('url' => $sUrl, 'src' => $sImage);
  1163. if (CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedView($aContentInfo))
  1164. $a['src_orig'] = $sImageOrig;
  1165. $aImages = array($a);
  1166. }
  1167. return array(
  1168. 'sample' => isset($CNF['T'][$aBuildParams['txt_sswa']]) ? $CNF['T'][$aBuildParams['txt_sswa']] : $CNF['T'][$aBuildParams['txt_ss']],
  1169. 'sample_wo_article' => $CNF['T'][$aBuildParams['txt_ss']],
  1170. 'sample_action' => isset($CNF['T'][$aBuildParams['txt_sa']]) ? $CNF['T'][$aBuildParams['txt_sa']] : '',
  1171. 'url' => $sUrl,
  1172. 'title' => '',
  1173. 'text' => '',
  1174. 'images' => $aImages,
  1175. 'videos' => array()
  1176. );
  1177. }
  1178. protected function _entityComments($sObject, $iId = 0)
  1179. {
  1180. if(!$iId)
  1181. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1182. if(!$iId)
  1183. $iId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  1184. if(!$iId)
  1185. return false;
  1186. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  1187. if(!$oCmts || !$oCmts->isEnabled())
  1188. return false;
  1189. return $oCmts->getCommentsBlock(array(), array('in_designbox' => false));
  1190. }
  1191. protected function _getContent($iContentId = 0, $sFuncGetContent = 'getContentInfoById')
  1192. {
  1193. if(!$iContentId && bx_get('id') === false && bx_get('profile_id') !== false) {
  1194. $oProfile = BxDolProfile::getInstance((int)bx_get('profile_id'));
  1195. if($oProfile)
  1196. $iContentId = $oProfile->getContentId();
  1197. }
  1198. return parent::_getContent($iContentId, $sFuncGetContent);
  1199. }
  1200. }
  1201. /** @} */