BxBaseModProfileModule.php 58 KB

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