BxBaseModProfileModule.php 58 KB

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