BxBaseModProfileModule.php 58 KB

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