1
0

BxBaseModProfileModule.php 64 KB

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