BxBaseModProfileModule.php 56 KB

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