BxBaseModProfileModule.php 57 KB

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