1
0

BxBaseModProfileModule.php 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454
  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. /**
  855. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  856. */
  857. public function checkAllowedAdd ($isPerformAction = false)
  858. {
  859. $oAccount = BxDolAccount::getInstance();
  860. if (!$oAccount || ($this->serviceActAsProfile() && $oAccount->isProfilesLimitReached()))
  861. return _t('_sys_txt_access_denied');
  862. return parent::checkAllowedAdd ($isPerformAction);
  863. }
  864. /**
  865. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  866. */
  867. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  868. {
  869. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
  870. }
  871. /**
  872. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  873. */
  874. public function checkAllowedViewProfileImage ($aDataEntry, $isPerformAction = false)
  875. {
  876. $CNF = &$this->_oConfig->CNF;
  877. // check privacy
  878. if (empty($CNF['OBJECT_PRIVACY_VIEW']))
  879. return CHECK_ACTION_RESULT_ALLOWED;
  880. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  881. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']]) && !$oPrivacy->isPartiallyVisible($aDataEntry[$CNF['FIELD_ALLOW_VIEW_TO']]))
  882. return _t('_sys_access_denied_to_private_content');
  883. return CHECK_ACTION_RESULT_ALLOWED;
  884. }
  885. /**
  886. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  887. */
  888. public function checkAllowedViewCoverImage ($aDataEntry, $isPerformAction = false)
  889. {
  890. return $this->checkAllowedViewProfileImage($aDataEntry);
  891. }
  892. /**
  893. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  894. */
  895. public function checkAllowedPost ($aDataEntry, $isPerformAction = false)
  896. {
  897. return $this->serviceCheckAllowedPostForProfile ($aDataEntry, $isPerformAction);
  898. }
  899. /**
  900. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  901. */
  902. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  903. {
  904. // moderator always has access
  905. if ($this->_isModerator($isPerformAction))
  906. return CHECK_ACTION_RESULT_ALLOWED;
  907. // owner (checked by account! not as profile as ususal) always have access
  908. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name']);
  909. if (!$oProfile)
  910. return _t('_sys_txt_error_occured');
  911. if ($oProfile->getAccountId() == $this->_iAccountId)
  912. return CHECK_ACTION_RESULT_ALLOWED;
  913. return _t('_sys_txt_access_denied');
  914. }
  915. /**
  916. * Check if user can change cover image
  917. */
  918. public function checkAllowedChangeCover ($aDataEntry, $isPerformAction = false)
  919. {
  920. // moderator always has access
  921. if ($this->_isModerator($isPerformAction))
  922. return CHECK_ACTION_RESULT_ALLOWED;
  923. // owner (checked by account! not as profile as ususal) always have access
  924. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name']);
  925. if (!$oProfile)
  926. return _t('_sys_txt_error_occured');
  927. if ($oProfile->getAccountId() == $this->_iAccountId)
  928. return CHECK_ACTION_RESULT_ALLOWED;
  929. return _t('_sys_txt_access_denied');
  930. }
  931. /**
  932. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  933. */
  934. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  935. {
  936. // moderator always has access
  937. if ($this->_isModerator($isPerformAction))
  938. return CHECK_ACTION_RESULT_ALLOWED;
  939. // check ACL and owner (checked by account! not as profile as ususal)
  940. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  941. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name'], $isPerformAction);
  942. if (!$oProfile)
  943. return _t('_sys_txt_error_occured');
  944. if ($oProfile->getAccountId() == $this->_iAccountId && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  945. return CHECK_ACTION_RESULT_ALLOWED;
  946. return _t('_sys_txt_access_denied');
  947. }
  948. /**
  949. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  950. */
  951. public function checkAllowedViewMoreMenu (&$aDataEntry, $isPerformAction = false)
  952. {
  953. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']);
  954. if (!$oMenu || !$oMenu->getCode())
  955. return _t('_sys_txt_access_denied');
  956. return CHECK_ACTION_RESULT_ALLOWED;
  957. }
  958. /**
  959. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  960. */
  961. public function checkAllowedCompose (&$aDataEntry, $isPerformAction = false)
  962. {
  963. $CNF = &$this->_oConfig->CNF;
  964. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->getName());
  965. if($oProfile && $oProfile->id() == $this->_iProfileId)
  966. return _t('_sys_txt_access_denied');
  967. return $this->checkAllowedView ($aDataEntry, $isPerformAction);
  968. }
  969. /**
  970. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  971. */
  972. public function checkAllowedFriendAdd (&$aDataEntry, $isPerformAction = false)
  973. {
  974. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', true, false);
  975. }
  976. /**
  977. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  978. */
  979. public function checkAllowedFriendRemove (&$aDataEntry, $isPerformAction = false)
  980. {
  981. if (CHECK_ACTION_RESULT_ALLOWED === $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', false, true, true))
  982. return CHECK_ACTION_RESULT_ALLOWED;
  983. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', false, true, false);
  984. }
  985. /**
  986. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  987. */
  988. public function checkAllowedRelationAdd (&$aDataEntry, $isPerformAction = false)
  989. {
  990. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedView($aDataEntry)))
  991. return $sMsg;
  992. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_relations', false, false);
  993. }
  994. /**
  995. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  996. */
  997. public function checkAllowedRelationRemove (&$aDataEntry, $isPerformAction = false)
  998. {
  999. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_relations', false, true);
  1000. }
  1001. public function checkAllowedRelationsView (&$aDataEntry, $isPerformAction = false)
  1002. {
  1003. $CNF = &$this->_oConfig->CNF;
  1004. $sResult = _t('_sys_txt_access_denied');
  1005. if(empty($aDataEntry) || !is_array($aDataEntry))
  1006. return $sResult;
  1007. return CHECK_ACTION_RESULT_ALLOWED;
  1008. }
  1009. /**
  1010. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1011. */
  1012. public function checkAllowedSubscribeAdd (&$aDataEntry, $isPerformAction = false)
  1013. {
  1014. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedView($aDataEntry)))
  1015. return $sMsg;
  1016. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_subscriptions', false, false);
  1017. }
  1018. /**
  1019. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1020. */
  1021. public function checkAllowedSubscribeRemove (&$aDataEntry, $isPerformAction = false)
  1022. {
  1023. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_subscriptions', false, true);
  1024. }
  1025. public function checkAllowedSubscriptionsView (&$aDataEntry, $isPerformAction = false)
  1026. {
  1027. $CNF = &$this->_oConfig->CNF;
  1028. $sResult = _t('_sys_txt_access_denied');
  1029. if(empty($aDataEntry) || !is_array($aDataEntry))
  1030. return $sResult;
  1031. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->_aModule['name']);
  1032. if(!$oProfile || ($oProfile->id() != $this->_iProfileId && $this->_oDb->getParam($CNF['PARAM_PUBLIC_SBSN']) != 'on' && $this->_oDb->getParam($CNF['PARAM_PUBLIC_SBSD']) != 'on'))
  1033. return $sResult;
  1034. return CHECK_ACTION_RESULT_ALLOWED;
  1035. }
  1036. public function checkMyself($iContentId)
  1037. {
  1038. $iLogged = (int)bx_get_logged_profile_id();
  1039. if(empty($iLogged))
  1040. return false;
  1041. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->_oConfig->getName());
  1042. if(!$oProfile)
  1043. return false;
  1044. return $oProfile->id() == $iLogged;
  1045. }
  1046. // ====== PROTECTED METHODS
  1047. protected function _checkAllowedConnect (&$aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap = false)
  1048. {
  1049. if (!$this->_iProfileId)
  1050. return _t('_sys_txt_access_denied');
  1051. $CNF = &$this->_oConfig->CNF;
  1052. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->_aModule['name']);
  1053. if (!$oProfile || $oProfile->id() == $this->_iProfileId)
  1054. return _t('_sys_txt_access_denied');
  1055. return BxDolConnection::getObjectInstance($sObjConnection)->checkAllowedConnect ($this->_iProfileId, $oProfile->id(), $isPerformAction, $isMutual, $isInvertResult, $isSwap);
  1056. }
  1057. protected function _buildRssParams($sMode, $aArgs)
  1058. {
  1059. $aParams = array ();
  1060. $sMode = bx_process_input($sMode);
  1061. switch ($sMode) {
  1062. case 'connections':
  1063. $aParams = array(
  1064. 'object' => isset($aArgs[0]) ? $aArgs[0] : '',
  1065. 'type' => isset($aArgs[1]) ? $aArgs[1] : '',
  1066. 'profile' => isset($aArgs[2]) ? (int)$aArgs[2] : 0,
  1067. 'mutual' => isset($aArgs[3]) ? (int)$aArgs[3] : 0,
  1068. 'profile2' => isset($aArgs[4]) ? (int)$aArgs[4] : 0,
  1069. );
  1070. break;
  1071. }
  1072. return $aParams;
  1073. }
  1074. protected function _serviceBrowseQuick($aProfiles, $iStart = 0, $iLimit = 4, $aAdditionalParams = array())
  1075. {
  1076. // get paginate object
  1077. $oPaginate = new BxTemplPaginate(array(
  1078. 'on_change_page' => "return !loadDynamicBlockAutoPaginate(this, '{start}', '{per_page}', " . bx_js_string(json_encode($aAdditionalParams)) . ");",
  1079. 'num' => count($aProfiles),
  1080. 'per_page' => $iLimit,
  1081. 'start' => $iStart,
  1082. ));
  1083. // remove last item from connection array, because we've got one more item for pagination calculations only
  1084. if (count($aProfiles) > $iLimit)
  1085. array_pop($aProfiles);
  1086. // get profiles HTML
  1087. $s = '';
  1088. foreach ($aProfiles as $mixedProfile) {
  1089. $bProfile = is_array($mixedProfile);
  1090. $oProfile = BxDolProfile::getInstance($bProfile ? (int)$mixedProfile['id'] : (int)$mixedProfile);
  1091. if(!$oProfile)
  1092. continue;
  1093. $aUnitParams = array();
  1094. if($bProfile && is_array($mixedProfile['info']))
  1095. $aUnitParams = array('template' => array('vars' => $mixedProfile['info']));
  1096. $s .= $oProfile->getUnit(0, $aUnitParams);
  1097. }
  1098. // return profiles + paginate
  1099. return $s . (!$iStart && $oPaginate->getNum() <= $iLimit ? '' : $oPaginate->getSimplePaginate());
  1100. }
  1101. protected function _serviceGetTimelineProfileImage($aEvent, $aBrowseParams, $aBuildParams)
  1102. {
  1103. $CNF = &$this->_oConfig->CNF;
  1104. $aFileInfo = BxDolStorage::getObjectInstance($CNF[$aBuildParams['stg']])->getFile((int)$aEvent['object_id']);
  1105. if(empty($aFileInfo) || !is_array($aFileInfo))
  1106. return false;
  1107. $aEventContent = unserialize($aEvent['content']);
  1108. if(!is_array($aEventContent) || empty($aEventContent['content']))
  1109. return false;
  1110. $aContentInfo = $this->_oDb->getContentInfoById($aEventContent['content']);
  1111. if(empty($aContentInfo) || !is_array($aContentInfo))
  1112. return false;
  1113. $oProfile = BxDolProfile::getInstanceMagic($aContentInfo['profile_id']);
  1114. if (!$oProfile->isActive())
  1115. return false;
  1116. $sUserName = $oProfile->getDisplayName();
  1117. $sSample = isset($CNF['T'][$aBuildParams['txt_sswa']]) ? $CNF['T'][$aBuildParams['txt_sswa']] : $CNF['T'][$aBuildParams['txt_ss']];
  1118. //--- Title & Description
  1119. $sTitle = !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '';
  1120. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TEXT']]))
  1121. $sTitle = $aContentInfo[$CNF['FIELD_TEXT']];
  1122. $sDescription = _t($CNF['T'][$aBuildParams['txt_sau']], $sUserName, _t($sSample));
  1123. return array(
  1124. 'owner_id' => $aEvent['owner_id'],
  1125. 'object_owner_id' => $aContentInfo['profile_id'],
  1126. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  1127. 'sample' => $sSample,
  1128. 'sample_wo_article' => $CNF['T'][$aBuildParams['txt_ss']],
  1129. 'sample_action' => isset($CNF['T'][$aBuildParams['txt_sa']]) ? $CNF['T'][$aBuildParams['txt_sa']] : '',
  1130. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]),
  1131. 'content' => $this->_getContentForTimelineProfileImage($aEvent, $aBrowseParams, $aBuildParams, $aContentInfo, $aFileInfo), //a string to display or array to parse default template before displaying.
  1132. 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
  1133. 'views' => '',
  1134. 'votes' => '',
  1135. 'scores' => '',
  1136. 'reports' => '',
  1137. 'comments' => '',
  1138. 'title' => $sTitle, //may be empty.
  1139. 'description' => $sDescription //may be empty.
  1140. );
  1141. }
  1142. protected function _getContentForTimelineProfileImage($aEvent, $aBrowseParams, $aBuildParams, $aContentInfo, $aFileInfo)
  1143. {
  1144. $CNF = &$this->_oConfig->CNF;
  1145. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1146. //--- Image(s)
  1147. $sImage = $this->_oConfig->getImageUrl($aFileInfo['id'], $aBuildParams['trans']);
  1148. $sImageOrig = $this->_oConfig->getImageUrl($aFileInfo['id'], $aBuildParams['trans_orig']);
  1149. if(!empty($sImage)) {
  1150. if(empty($sImageOrig))
  1151. $sImageOrig = $sImage;
  1152. $a = array('url' => $sUrl, 'src' => $sImage);
  1153. if (CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedView($aContentInfo))
  1154. $a['src_orig'] = $sImageOrig;
  1155. $aImages = array($a);
  1156. }
  1157. return array(
  1158. 'sample' => isset($CNF['T'][$aBuildParams['txt_sswa']]) ? $CNF['T'][$aBuildParams['txt_sswa']] : $CNF['T'][$aBuildParams['txt_ss']],
  1159. 'sample_wo_article' => $CNF['T'][$aBuildParams['txt_ss']],
  1160. 'sample_action' => isset($CNF['T'][$aBuildParams['txt_sa']]) ? $CNF['T'][$aBuildParams['txt_sa']] : '',
  1161. 'url' => $sUrl,
  1162. 'title' => '',
  1163. 'text' => '',
  1164. 'images' => $aImages,
  1165. 'videos' => array()
  1166. );
  1167. }
  1168. protected function _entityComments($sObject, $iId = 0)
  1169. {
  1170. if(!$iId)
  1171. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1172. if(!$iId)
  1173. $iId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  1174. if(!$iId)
  1175. return false;
  1176. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  1177. if(!$oCmts || !$oCmts->isEnabled())
  1178. return false;
  1179. return $oCmts->getCommentsBlock(array(), array('in_designbox' => false));
  1180. }
  1181. protected function _getContent($iContentId = 0, $sFuncGetContent = 'getContentInfoById')
  1182. {
  1183. if(!$iContentId && bx_get('id') === false && bx_get('profile_id') !== false) {
  1184. $oProfile = BxDolProfile::getInstance((int)bx_get('profile_id'));
  1185. if($oProfile)
  1186. $iContentId = $oProfile->getContentId();
  1187. }
  1188. return parent::_getContent($iContentId, $sFuncGetContent);
  1189. }
  1190. }
  1191. /** @} */