1
0

BxBaseModProfileModule.php 63 KB

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