BxBaseModProfileModule.php 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919
  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. define('BX_DOL_PROFILE_ACTIVATE_ALWAYS', 'on');
  15. define('BX_DOL_PROFILE_ACTIVATE_NEVER', 'off');
  16. define('BX_DOL_PROFILE_ACTIVATE_ADD', 'add');
  17. define('BX_DOL_PROFILE_ACTIVATE_EDIT', 'edit');
  18. /**
  19. * Base class for profile modules.
  20. */
  21. class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolContentInfoService, iBxDolProfileService
  22. {
  23. protected $_iAccountId;
  24. function __construct(&$aModule)
  25. {
  26. parent::__construct($aModule);
  27. $CNF = &$this->_oConfig->CNF;
  28. if(!empty($CNF['FIELD_ALLOW_POST_TO']))
  29. $this->_aSearchableNamesExcept[] = $CNF['FIELD_ALLOW_POST_TO'];
  30. if(!empty($CNF['FIELD_ALLOW_CONTACT_TO']))
  31. $this->_aSearchableNamesExcept[] = $CNF['FIELD_ALLOW_CONTACT_TO'];
  32. $this->_iAccountId = getLoggedId();
  33. }
  34. public function actionDeleteProfileImg($iFileId, $iContentId, $sFieldPicture)
  35. {
  36. $aResult = array();
  37. $CNF = &$this->_oConfig->CNF;
  38. $oSrorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  39. if (!($aFile = $oSrorage->getFile((int)$iFileId)) || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)) || $aContentInfo[$sFieldPicture] != (int)$iFileId)
  40. $aResult = array('error' => 1, 'msg' => _t('_sys_storage_err_file_not_found'));
  41. $oAccountProfile = BxDolProfile::getInstanceAccountProfile();
  42. if ($oAccountProfile)
  43. $iAccountProfileId = $oAccountProfile->id();
  44. if ((!$aResult && !isLogged()) || (!$aResult && $aFile['profile_id'] != $iAccountProfileId && !$this->_isModerator()))
  45. $aResult = array('error' => 2, 'msg' => _t('_Access denied'));
  46. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oTemplate);
  47. if (!$aResult && !$oForm->_deleteFile($iContentId, $sFieldPicture, (int)$iFileId, true))
  48. $aResult = array('error' => 3, 'msg' => _t('_Failed'));
  49. elseif (!$aResult)
  50. $aResult = array('error' => 0, 'msg' => '');
  51. header('Content-Type: application/json; charset=utf-8');
  52. echo json_encode($aResult);
  53. }
  54. public function actionProfileCalendarData()
  55. {
  56. $iProfileId = (int)bx_get('profile_id');
  57. $aEntries = array();
  58. $BxDolModuleQuery = BxDolModuleQuery::getInstance();
  59. $aModules = $BxDolModuleQuery->getModulesBy(array('type' => 'modules', 'active' => 1));
  60. foreach($aModules as $aModule){
  61. $sModuleName = $aModule['name'];
  62. $oModule = BxDolModule::getInstance($sModuleName);
  63. if($oModule instanceof iBxDolCalendarService){
  64. if(BxDolRequest::serviceExists($sModuleName, 'get_calendar_entries')){
  65. $aEntries2 = BxDolService::call($sModuleName, 'get_calendar_entries', array($iProfileId));
  66. $aEntries = array_merge($aEntries, $aEntries2);
  67. }
  68. }
  69. }
  70. header('Content-Type: application/json; charset=utf-8');
  71. echo json_encode($aEntries);
  72. }
  73. // ====== SERVICE METHODS
  74. public function serviceGetSafeServices()
  75. {
  76. $a = parent::serviceGetSafeServices();
  77. return array_merge($a, array (
  78. 'ProfileUnitSafe' => '',
  79. 'ProfileUrl' => '',
  80. 'EntityCreate' => '',
  81. 'BrowseRecommended' => '',
  82. 'BrowseRecentProfiles' => '',
  83. 'BrowseActiveProfiles' => '',
  84. 'BrowseTopProfiles' => '',
  85. 'BrowseOnlineProfiles' => '',
  86. 'BrowseByAcl' => '',
  87. ));
  88. }
  89. public function serviceGetOptionsRedirectAfterAdd()
  90. {
  91. $CNF = &$this->_oConfig->CNF;
  92. $aResult = array();
  93. $aChoices = array(BX_DOL_PROFILE_REDIRECT_PROFILE, BX_DOL_PROFILE_REDIRECT_LAST, BX_DOL_PROFILE_REDIRECT_CUSTOM);
  94. foreach($aChoices as $sChoice)
  95. $aResult[] = array('key' => $sChoice, 'value' => _t($CNF['T']['option_redirect_aadd_' . $sChoice]));
  96. return $aResult;
  97. }
  98. public function serviceGetOptionsActivation()
  99. {
  100. $CNF = &$this->_oConfig->CNF;
  101. $aResult = array();
  102. $aChoices = array(BX_DOL_PROFILE_ACTIVATE_ALWAYS, BX_DOL_PROFILE_ACTIVATE_NEVER, BX_DOL_PROFILE_ACTIVATE_ADD, BX_DOL_PROFILE_ACTIVATE_EDIT);
  103. foreach($aChoices as $sChoice)
  104. $aResult[] = array('key' => $sChoice, 'value' => _t($CNF['T']['option_activation_' . $sChoice]));
  105. return $aResult;
  106. }
  107. public function serviceGetThumb ($iContentId, $sTranscoder = '')
  108. {
  109. $CNF = &$this->_oConfig->CNF;
  110. if(empty($sTranscoder) && !empty($CNF['OBJECT_IMAGES_TRANSCODER_THUMB']))
  111. $sTranscoder = $CNF['OBJECT_IMAGES_TRANSCODER_THUMB'];
  112. $mixedResult = $this->_getFieldValueThumb('FIELD_PICTURE', $iContentId, $sTranscoder);
  113. return $mixedResult !== false ? $mixedResult : '';
  114. }
  115. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  116. {
  117. if(empty($sUnitTemplate))
  118. $sUnitTemplate = 'unit_with_cover.html';
  119. return parent::serviceGetSearchResultUnit($iContentId, $sUnitTemplate);
  120. }
  121. public function serviceGetSearchableFieldsExtended($aInputsAdd = array())
  122. {
  123. $CNF = &$this->_oConfig->CNF;
  124. $aResult = parent::serviceGetSearchableFieldsExtended($aInputsAdd);
  125. if(!$this->serviceActAsProfile())
  126. return $aResult;
  127. if(!in_array('online', $this->_aSearchableNamesExcept))
  128. $aResult['online'] = array(
  129. 'type' => 'checkbox',
  130. 'caption' => $CNF['T']['form_field_online'],
  131. 'info' => '',
  132. 'value' => '1',
  133. 'values' => '',
  134. 'pass' => ''
  135. );
  136. if(!empty($CNF['FIELD_PICTURE']) && !in_array($CNF['FIELD_PICTURE'], $this->_aSearchableNamesExcept))
  137. $aResult[$CNF['FIELD_PICTURE']] = array(
  138. 'type' => 'checkbox',
  139. 'caption' => $CNF['T']['form_field_picture'],
  140. 'info' => '',
  141. 'value' => '1',
  142. 'values' => '',
  143. 'pass' => '',
  144. 'search_operator' => '>='
  145. );
  146. return $aResult;
  147. }
  148. /**
  149. * @page service Service Calls
  150. * @section bx_base_profile Base Profile
  151. * @subsection bx_base_profile-general General
  152. * @subsubsection bx_base_profile-entity_calendar entity_calendar
  153. *
  154. * @code bx_srv('bx_persons', 'entity_calendar', [...]); @endcode
  155. *
  156. * Get calendar block
  157. * @param $iContentId content ID
  158. *
  159. * @see BxBaseModProfileModule::serviceEntityCalendar
  160. */
  161. /**
  162. * @ref bx_base_profile-entity_calendar "entity_calendar"
  163. */
  164. public function serviceEntityCalendar($iContentId = 0, $sTemplate = 'calendar.html')
  165. {
  166. $iContentId = $this->_getContent($iContentId, false);
  167. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->_oConfig->getName());
  168. if($oProfile){
  169. $o = new BxTemplCalendar(array(
  170. 'eventSources' => array (
  171. bx_append_url_params(BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'profile_calendar_data', array('profile_id' => $oProfile->id())),
  172. ),
  173. ), $this->_oTemplate);
  174. return $o->display($sTemplate);
  175. }
  176. return '';
  177. }
  178. public function servicePrivateProfileMsg()
  179. {
  180. $mixedContent = $this->_getContent();
  181. if ($mixedContent) {
  182. list($iContentId, $aContentInfo) = $mixedContent;
  183. return $this->checkAllowedView($aContentInfo);
  184. }
  185. return MsgBox(_t('_sys_access_denied_to_private_content'));
  186. }
  187. public function serviceGetContentInfoById($iContentId)
  188. {
  189. return $this->_oDb->getContentInfoById((int)$iContentId);
  190. }
  191. public function serviceGetMenuAddonManageTools()
  192. {
  193. bx_import('SearchResult', $this->_aModule);
  194. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  195. $o = new $sClass();
  196. $o->unsetPaginate();
  197. $iNumTotal = $o->getNum();
  198. $o->fillFilters(array(
  199. 'perofileStatus' => BX_PROFILE_STATUS_PENDING
  200. ));
  201. $iNum1 = $o->getNum();
  202. $iNum2 = 0;
  203. $CNF = &$this->_oConfig->CNF;
  204. if (isset($CNF['OBJECT_REPORTS'])){
  205. $o->fillFilters(array('perofileStatus' => ''));
  206. $o->fillFiltersByObjects(array('reported' => array('value' => '0', 'field' => 'reports', 'operator' => '>', 'table' => $CNF['TABLE_ENTRIES'])));
  207. $iNum2 = $o->getNum();
  208. }
  209. return array('counter1_value' => $iNum1, 'counter2_value' => $iNum2, 'counter3_value' => $iNumTotal, 'counter1_caption' => _t('_sys_menu_dashboard_manage_tools_addon_counter1_caption_profile_default'));
  210. }
  211. public function serviceGetMenuAddonManageToolsProfileStats()
  212. {
  213. bx_import('SearchResult', $this->_aModule);
  214. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  215. $o = new $sClass();
  216. $o->fillFilters(array(
  217. 'account_id' => getLoggedId(),
  218. 'perofileStatus' => ''
  219. ));
  220. $o->unsetPaginate();
  221. return $o->getNum();
  222. }
  223. public function serviceGetMenuAddonFavoritesProfileStats()
  224. {
  225. bx_import('SearchResult', $this->_aModule);
  226. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  227. $o = new $sClass('favorite', array('user' => bx_get_logged_profile_id()));
  228. $o->unsetPaginate();
  229. return $o->getNum();
  230. }
  231. public function serviceGetSubmenuObject ()
  232. {
  233. return $this->_oConfig->CNF['OBJECT_MENU_SUBMENU_VIEW_ENTRY'];
  234. }
  235. public function serviceGetMenuSetNameForMenuTrigger ($sMenuTriggerName)
  236. {
  237. $CNF = &$this->_oConfig->CNF;
  238. if (isset($CNF['TRIGGER_MENU_PROFILE_VIEW_SUBMENU']) && $CNF['TRIGGER_MENU_PROFILE_VIEW_SUBMENU'] == $sMenuTriggerName)
  239. return $CNF['OBJECT_MENU_SUBMENU_VIEW_ENTRY'];
  240. elseif (isset($CNF['TRIGGER_MENU_PROFILE_SNIPPET_META']) && $CNF['TRIGGER_MENU_PROFILE_SNIPPET_META'] == $sMenuTriggerName)
  241. return $CNF['OBJECT_MENU_SNIPPET_META'];
  242. else if (isset($CNF['TRIGGER_MENU_PROFILE_VIEW_ACTIONS']) && $CNF['TRIGGER_MENU_PROFILE_VIEW_ACTIONS'] == $sMenuTriggerName) {
  243. if(empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL']))
  244. return $CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY'];
  245. else
  246. return array($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY'], $CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL']);
  247. }
  248. return '';
  249. }
  250. public function serviceGetSnippetMenuVars($iProfileId, $bPublic = null)
  251. {
  252. return $this->_oTemplate->getSnippetMenuVars($iProfileId, $bPublic);
  253. }
  254. public function serviceGetPageObjectForPageTrigger ($sPageTriggerName)
  255. {
  256. if (isset($this->_oConfig->CNF['TRIGGER_PAGE_VIEW_ENTRY']) && $this->_oConfig->CNF['TRIGGER_PAGE_VIEW_ENTRY'] == $sPageTriggerName)
  257. return $this->_oConfig->CNF['OBJECT_PAGE_VIEW_ENTRY'];
  258. return '';
  259. }
  260. public function serviceProfilesSearch ($sTerm, $iLimit)
  261. {
  262. $aRet = array();
  263. $a = $this->_oDb->searchByTerm($sTerm, $iLimit);
  264. foreach ($a as $r) {
  265. $oProfile = BxDolProfile::getInstance($r['profile_id']);
  266. $aRet[] = array (
  267. 'label' => $this->serviceProfileName($r['content_id']),
  268. 'value' => $r['profile_id'],
  269. 'url' => $oProfile->getUrl(),
  270. 'thumb' => $oProfile->getThumb(),
  271. 'unit' => $oProfile->getUnit(0, array('template' => 'unit_wo_info'))
  272. );
  273. }
  274. return $aRet;
  275. }
  276. /**
  277. * @page service Service Calls
  278. * @section bx_base_profile Base Profile
  279. * @subsection bx_base_profile-general General
  280. * @subsubsection bx_base_profile-profile_unit_safe profile_unit_safe
  281. *
  282. * @code bx_srv('bx_persons', 'profile_unit_safe', [...]); @endcode
  283. *
  284. * Get profile unit
  285. * @param $iContentId content ID
  286. *
  287. * @see BxBaseModProfileModule::serviceProfileUnitSafe
  288. */
  289. /**
  290. * @ref bx_base_profile-profile_unit_safe "profile_unit_safe"
  291. */
  292. public function serviceProfileUnitSafe ($iContentId, $aParams = array())
  293. {
  294. unset($aParams['check_private_content']);
  295. return $this->serviceProfileUnit ($iContentId, $aParams);
  296. }
  297. public function serviceProfileUnit ($iContentId, $aParams = array())
  298. {
  299. $mixedContent = $this->_getContent($iContentId);
  300. if($mixedContent === false)
  301. return false;
  302. list($iContentId, $aContentInfo) = $mixedContent;
  303. $bCheckPrivateContent = isset($aParams['check_private_content']) ? (bool)$aParams['check_private_content'] : true;
  304. $sTemplate = 'unit.html';
  305. $sTemplateSize = false;
  306. $aTemplateVars = array();
  307. if(!empty($aParams['template'])) {
  308. if(is_string($aParams['template']))
  309. $sTemplate = $aParams['template'] . '.html';
  310. else if(is_array($aParams['template'])) {
  311. if(!empty($aParams['template']['name']))
  312. $sTemplate = $aParams['template']['name'] . '.html';
  313. if(!empty($aParams['template']['size']))
  314. $sTemplateSize = $aParams['template']['size'];
  315. if(!empty($aParams['template']['vars']))
  316. $aTemplateVars = $aParams['template']['vars'];
  317. }
  318. }
  319. return $this->_oTemplate->unit($aContentInfo, $bCheckPrivateContent, array($sTemplate, $sTemplateSize, $aTemplateVars));
  320. }
  321. public function serviceHasImage ($iContentId)
  322. {
  323. $CNF = &$this->_oConfig->CNF;
  324. $mixedContent = $this->_getContent($iContentId, 'getContentInfoById');
  325. if($mixedContent === false)
  326. return false;
  327. list($iContentId, $aContentInfo) = $mixedContent;
  328. return !empty($aContentInfo[$CNF['FIELD_PICTURE']]);
  329. }
  330. public function serviceProfilePicture ($iContentId)
  331. {
  332. return $this->_serviceTemplateFunc('urlPicture', $iContentId);
  333. }
  334. public function serviceProfileAvatar ($iContentId)
  335. {
  336. return $this->_serviceTemplateFunc('urlAvatar', $iContentId);
  337. }
  338. public function serviceProfileAvatarBig ($iContentId)
  339. {
  340. return $this->_serviceTemplateFunc('urlAvatarBig', $iContentId);
  341. }
  342. public function serviceProfileCover ($iContentId)
  343. {
  344. return $this->_serviceTemplateFunc('urlCover', $iContentId);
  345. }
  346. public function serviceProfileUnitCover ($iContentId)
  347. {
  348. return $this->_serviceTemplateFunc('urlCoverUnit', $iContentId);
  349. }
  350. public function serviceProfileEditUrl ($iContentId)
  351. {
  352. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $this->_oConfig->CNF['URI_EDIT_ENTRY'] . '&id=' . $iContentId);
  353. }
  354. public function serviceProfileThumb ($iContentId)
  355. {
  356. return $this->_serviceTemplateFunc('urlThumb', $iContentId);
  357. }
  358. public function serviceProfileIcon ($iContentId)
  359. {
  360. return $this->_serviceTemplateFunc('urlIcon', $iContentId);
  361. }
  362. public function serviceProfileName ($iContentId)
  363. {
  364. if (!$iContentId)
  365. return false;
  366. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  367. if (!$aContentInfo)
  368. return false;
  369. return bx_process_output($aContentInfo[$this->_oConfig->CNF['FIELD_NAME']]);
  370. }
  371. public function serviceProfileCreateUrl ($bAbsolute = true)
  372. {
  373. $CNF = $this->_oConfig->CNF;
  374. if(empty($CNF['URL_CREATE']))
  375. return false;
  376. return $bAbsolute ? BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_CREATE']) : $CNF['URL_CREATE'];
  377. }
  378. /**
  379. * @page service Service Calls
  380. * @section bx_base_profile Base Profile
  381. * @subsection bx_base_profile-general General
  382. * @subsubsection bx_base_profile-profile_url profile_url
  383. *
  384. * @code bx_srv('bx_persons', 'profile_url', [...]); @endcode
  385. *
  386. * Get profile URL
  387. * @param $iContentId content ID
  388. *
  389. * @see BxBaseModProfileModule::serviceProfileUrl
  390. */
  391. /**
  392. * @ref bx_base_profile-profile_url "profile_url"
  393. */
  394. public function serviceProfileUrl ($iContentId)
  395. {
  396. if (!$iContentId)
  397. return false;
  398. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  399. if (!$aContentInfo)
  400. return false;
  401. $CNF = $this->_oConfig->CNF;
  402. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  403. }
  404. /**
  405. * @see iBxDolProfileService::serviceGetSpaceTitle
  406. */
  407. public function serviceGetSpaceTitle()
  408. {
  409. return _t('_sys_ps_space_title_friend');
  410. }
  411. /**
  412. * @see iBxDolProfileService::serviceGetParticipatingProfiles
  413. */
  414. public function serviceGetParticipatingProfiles($iProfileId, $aConnectionObjects = false)
  415. {
  416. if (false === $aConnectionObjects)
  417. $aConnectionObjects = array('sys_profiles_friends');
  418. $a = array();
  419. foreach ($aConnectionObjects as $sConnectionObject) {
  420. if (!($o = BxDolConnection::getObjectInstance($sConnectionObject)))
  421. continue;
  422. if (BX_CONNECTIONS_TYPE_MUTUAL == $o->getType())
  423. $a = array_merge($a, $o->getConnectedContentByType($iProfileId, $this->getName(), true));
  424. else
  425. $a = array_merge($a, $o->getConnectedContentByType($iProfileId, $this->getName()));
  426. }
  427. $a = array_unique($a);
  428. $aRet = array();
  429. foreach ($a as $iConnectedProfileId) {
  430. if (!($oConnectedProfile = BxDolProfile::getInstance($iConnectedProfileId)))
  431. continue;
  432. if (CHECK_ACTION_RESULT_ALLOWED === bx_srv($oConnectedProfile->getModule(), 'check_allowed_post_in_profile', array($oConnectedProfile->getContentId(), $iProfileId)))
  433. $aRet[] = $iConnectedProfileId;
  434. }
  435. bx_alert('system', 'get_participating_profiles', $iProfileId, false, array(
  436. 'module' => $this->_oConfig->getName(),
  437. 'profiles' => &$aRet
  438. ));
  439. return $aRet;
  440. }
  441. /**
  442. * Prepare fields from some universal set of fields to fields in particular profile module.
  443. * By default only 'name' and 'description' fields are supported.
  444. * After fields convertion it can be used in @see BxBaseModGeneralModule::serviceEntityAdd
  445. * @param $aFieldsProfile fields in soem universal format.
  446. * @return array which is ready to use for particular module
  447. */
  448. public function servicePrepareFields ($aFieldsProfile)
  449. {
  450. bx_alert($this->getName(), 'prepare_fields', 0, 0, array('fields_orig' => $aFieldsProfile, 'fields_result' => &$aFieldsProfile));
  451. return $aFieldsProfile;
  452. }
  453. protected function _servicePrepareFields ($aFieldsProfile, $aFieldsDefault, $aMap)
  454. {
  455. $aFieldsOrig = $aFieldsProfile;
  456. bx_import('BxDolPrivacy');
  457. $aFieldsDefault2 = array(
  458. 'allow_view_to' => BX_DOL_PG_ALL,
  459. 'allow_contact_to' => BX_DOL_PG_ALL,
  460. 'allow_post_to' => BX_DOL_PG_FRIENDS,
  461. );
  462. $aFieldsProfile = array_merge($aFieldsDefault2, $aFieldsDefault, $aFieldsProfile);
  463. foreach ($aMap as $k => $v) {
  464. if (isset($aFieldsProfile[$v]))
  465. $aFieldsProfile[$k] = $aFieldsProfile[$v];
  466. if ($k != $v && !isset($aMap[$v]))
  467. unset($aFieldsProfile[$v]);
  468. }
  469. bx_alert($this->getName(), 'prepare_fields', 0, 0, array('fields_orig' => $aFieldsOrig, 'fields_result' => &$aFieldsProfile));
  470. return $aFieldsProfile;
  471. }
  472. public function serviceFormsHelper ()
  473. {
  474. return parent::serviceFormsHelper ();
  475. }
  476. /**
  477. * @page service Service Calls
  478. * @section bx_base_profile Base Profile
  479. * @subsection bx_base_profile-forms Forms
  480. * @subsubsection bx_base_profile-entity_create entity_create
  481. *
  482. * @code bx_srv('bx_persons', 'entity_create', [...]); @endcode
  483. *
  484. * Get profile creation form
  485. * @param $sDisplay optional form display name
  486. *
  487. * @see BxBaseModProfileModule::serviceEntityCreate
  488. */
  489. /**
  490. * @ref bx_base_profile-entity_create "entity_create"
  491. */
  492. public function serviceEntityCreate ($sDisplay = false)
  493. {
  494. BxDolInformer::getInstance($this->_oTemplate)->setEnabled(false);
  495. return parent::serviceEntityCreate ($sDisplay);
  496. }
  497. public function serviceActAsProfile ()
  498. {
  499. return true;
  500. }
  501. /**
  502. * @page service Service Calls
  503. * @section bx_base_profile Base Profile
  504. * @subsection bx_base_profile-browse Browse
  505. * @subsubsection bx_base_profile-browse_recommended browse_recommended
  506. *
  507. * @code bx_srv('bx_persons', 'browse_recommended', [...]); @endcode
  508. *
  509. * Browse recommended profiles
  510. * @param $sUnitView optional, unit view, for example - showcase
  511. * @param $bEmptyMessage optional, display or not "empty" message when there is no content
  512. * @param $bAjaxPaginate optional, use AJAX paginate or not
  513. *
  514. * @see BxBaseModProfileModule::serviceBrowseRecommended
  515. */
  516. /**
  517. * @ref bx_base_profile-browse_recommended "browse_recommended"
  518. */
  519. public function serviceBrowseRecommended ($sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = true)
  520. {
  521. if (!isLogged())
  522. return '';
  523. return $this->_serviceBrowse ('recommended', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  524. }
  525. /**
  526. * @page service Service Calls
  527. * @section bx_base_profile Base Profile
  528. * @subsection bx_base_profile-browse Browse
  529. * @subsubsection bx_base_profile-browse_recent_profiles browse_recent_profiles
  530. *
  531. * @code bx_srv('bx_persons', 'browse_recent_profiles', [...]); @endcode
  532. *
  533. * Browse recently joined profiles
  534. * @param $bEmptyMessage optional, display or not "empty" message when there is no content
  535. * @param $bAjaxPaginate optional, use AJAX paginate or not
  536. *
  537. * @see BxBaseModProfileModule::serviceBrowseRecentProfiles
  538. */
  539. /**
  540. * @ref bx_base_profile-browse_recent_profiles "browse_recent_profiles"
  541. */
  542. public function serviceBrowseRecentProfiles ($bDisplayEmptyMsg = false, $bAjaxPaginate = true)
  543. {
  544. return $this->_serviceBrowse ('recent', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate);
  545. }
  546. /**
  547. * @page service Service Calls
  548. * @section bx_base_profile Base Profile
  549. * @subsection bx_base_profile-browse Browse
  550. * @subsubsection bx_base_profile-browse_active_profiles browse_active_profiles
  551. *
  552. * @code bx_srv('bx_persons', 'browse_active_profiles', [...]); @endcode
  553. *
  554. * Browse recently active profiles
  555. * @param $bEmptyMessage optional, display or not "empty" message when there is no content
  556. * @param $bAjaxPaginate optional, use AJAX paginate or not
  557. *
  558. * @see BxBaseModProfileModule::serviceBrowseActiveProfiles
  559. */
  560. /**
  561. * @ref bx_base_profile-browse_active_profiles "browse_active_profiles"
  562. */
  563. public function serviceBrowseActiveProfiles ($sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = false)
  564. {
  565. return $this->_serviceBrowse ('active', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  566. }
  567. /**
  568. * @page service Service Calls
  569. * @section bx_base_profile Base Profile
  570. * @subsection bx_base_profile-browse Browse
  571. * @subsubsection bx_base_profile-browse_top_profiles browse_top_profiles
  572. *
  573. * @code bx_srv('bx_persons', 'browse_top_profiles', [...]); @endcode
  574. *
  575. * Browse top profiles
  576. * @param $bEmptyMessage optional, display or not "empty" message when there is no content
  577. * @param $bAjaxPaginate optional, use AJAX paginate or not
  578. *
  579. * @see BxBaseModProfileModule::serviceBrowseTopProfiles
  580. */
  581. /**
  582. * @ref bx_base_profile-browse_top_profiles "browse_top_profiles"
  583. */
  584. public function serviceBrowseTopProfiles ($bDisplayEmptyMsg = false, $bAjaxPaginate = false)
  585. {
  586. return $this->_serviceBrowse ('top', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate);
  587. }
  588. /**
  589. * @page service Service Calls
  590. * @section bx_base_profile Base Profile
  591. * @subsection bx_base_profile-browse Browse
  592. * @subsubsection bx_base_profile-browse_online_profiles browse_online_profiles
  593. *
  594. * @code bx_srv('bx_persons', 'browse_online_profiles', [...]); @endcode
  595. *
  596. * Browse online profiles
  597. * @param $bEmptyMessage optional, display or not "empty" message when there is no content
  598. * @param $bAjaxPaginate optional, use AJAX paginate or not
  599. *
  600. * @see BxBaseModProfileModule::serviceBrowseOnlineProfiles
  601. */
  602. /**
  603. * @ref bx_base_profile-browse_online_profiles "browse_online_profiles"
  604. */
  605. public function serviceBrowseOnlineProfiles ($bDisplayEmptyMsg = false, $bAjaxPaginate = false)
  606. {
  607. return $this->_serviceBrowse ('online', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate);
  608. }
  609. public function serviceBrowseConnections ($iProfileId, $sObjectConnections = 'sys_profiles_friends', $sConnectionsType = 'content', $iMutual = false, $iDesignBox = BX_DB_PADDING_DEF, $iProfileId2 = 0)
  610. {
  611. return $this->_serviceBrowse (
  612. 'connections',
  613. array(
  614. 'object' => $sObjectConnections,
  615. 'type' => $sConnectionsType,
  616. 'mutual' => $iMutual,
  617. 'profile' => (int)$iProfileId,
  618. 'profile2' => (int)$iProfileId2),
  619. $iDesignBox
  620. );
  621. }
  622. public function serviceBrowseRelationsQuick ($iProfileId, $sObjectConnections = 'sys_profiles_friends', $sConnectionsType = 'content', $iMutual = false, $iProfileId2 = 0)
  623. {
  624. // get connections object
  625. $oConnection = BxDolConnection::getObjectInstance($sObjectConnections);
  626. if (!$oConnection)
  627. return '';
  628. // set some vars
  629. $iStart = (int)bx_get('start');
  630. $iLimit = empty($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? 4 : getParam($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']);
  631. if (!$iLimit)
  632. $iLimit = 4;
  633. // get connections array
  634. bx_import('BxDolConnection');
  635. $aConnections = $oConnection->getConnectionsAsArrayExt($sConnectionsType, $iProfileId, $iProfileId2, $iMutual, $iStart, $iLimit + 1, BX_CONNECTIONS_ORDER_ADDED_DESC);
  636. if(empty($aConnections) || !is_array($aConnections))
  637. return '';
  638. $aResult = array();
  639. foreach($aConnections as $iProfile => $aConnection)
  640. $aResult[] = array(
  641. 'id' => $iProfile,
  642. 'info' => array(
  643. 'addon' => $oConnection->getRelationTranslation($aConnection['relation'])
  644. )
  645. );
  646. return $this->_serviceBrowseQuick($aResult, $iStart, $iLimit);
  647. }
  648. public function serviceBrowseConnectionsQuick ($iProfileId, $sObjectConnections = 'sys_profiles_friends', $sConnectionsType = 'content', $iMutual = false, $iProfileId2 = 0)
  649. {
  650. // get connections object
  651. $oConnection = BxDolConnection::getObjectInstance($sObjectConnections);
  652. if (!$oConnection)
  653. return '';
  654. // set some vars
  655. $iLimit = empty($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? 4 : getParam($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']);
  656. if (!$iLimit)
  657. $iLimit = 4;
  658. $iStart = (int)bx_get('start');
  659. // get connections array
  660. bx_import('BxDolConnection');
  661. $a = $oConnection->getConnectionsAsArray ($sConnectionsType, $iProfileId, $iProfileId2, $iMutual, (int)bx_get('start'), $iLimit + 1, BX_CONNECTIONS_ORDER_ADDED_DESC);
  662. if (!$a)
  663. return '';
  664. return $this->_serviceBrowseQuick($a, $iStart, $iLimit);
  665. }
  666. public function serviceBrowseConnectionsByType ($aParamsCnn, $aParamsBrs = array())
  667. {
  668. $sAll = 'all';
  669. $aParamsCnn['object'] = !empty($aParamsCnn['object']) ? $aParamsCnn['object'] : 'sys_profiles_friends';
  670. $aParamsCnn['type'] = !empty($aParamsCnn['type']) ? $aParamsCnn['type'] : 'content';
  671. $aParamsCnn['profile_id2'] = !empty($aParamsCnn['profile_id2']) ? (int)$aParamsCnn['profile_id2'] : 0;
  672. $aParamsCnn['mutual'] = isset($aParamsCnn['mutual']) ? $aParamsCnn['mutual'] : false;
  673. $oConnection = BxDolConnection::getObjectInstance($aParamsCnn['object']);
  674. if(!$oConnection)
  675. return '';
  676. $aSQLParts = $oConnection->getConnectionsAsSQLParts ($aParamsCnn['type'], 'sys_profiles', 'id', $aParamsCnn['profile_id'], $aParamsCnn['profile_id2'], $aParamsCnn['mutual']);
  677. $sType = !empty($aParamsBrs['type']) ? $aParamsBrs['type'] : $sAll;
  678. if(bx_get('type') !== false)
  679. $sType = bx_process_input(bx_get('type'));
  680. $iStart = (int)bx_get('start');
  681. $iLimitDefault = 4;
  682. $iLimit = !empty($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? getParam($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) : $iLimitDefault;
  683. if(!empty($aParamsBrs['per_page']))
  684. $iLimit = (int)$aParamsBrs['per_page'];
  685. if(!$iLimit)
  686. $iLimit = $iLimitDefault;
  687. $aProfiles = BxDolProfileQuery::getInstance()->getConnectedProfilesByType($aSQLParts, ($sType != $sAll ? $sType : ''), $iStart, $iLimit + 1);
  688. $mixedMenu = '';
  689. if(!isset($aParamsBrs['filter_menu']) || $aParamsBrs['filter_menu'] === true) {
  690. $aModules = array(
  691. array('name' => $sAll)
  692. );
  693. $aModules = array_merge($aModules, BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1)));
  694. $aMenuItems = array();
  695. foreach($aModules as $aModule)
  696. if($aModule['name'] == $sAll || BxDolRequest::serviceExists($aModule['name'], 'act_as_profile'))
  697. $aMenuItems[] = array(
  698. 'id' => $aModule['name'],
  699. 'name' => $aModule['name'],
  700. 'class' => '',
  701. 'link' => 'javascript:void(0)',
  702. 'onclick' => "return !loadDynamicBlockAutoPaginate(this, " . $iStart . ", " . $iLimit . ", " . bx_js_string(json_encode(array('type' => $aModule['name']))) . ");",
  703. 'target' => '_self',
  704. 'title' => _t('_' . $aModule['name']),
  705. 'active' => 1
  706. );
  707. if(!empty($aMenuItems)) {
  708. $mixedMenu = new BxTemplMenu(array('template' => 'menu_vertical.html', 'menu_id'=> $this->_oConfig->getName() . '-connections-by-type', 'menu_items' => $aMenuItems));
  709. $mixedMenu->setSelected('', $sType);
  710. }
  711. }
  712. return array(
  713. 'menu' => $mixedMenu,
  714. 'content' => $this->_serviceBrowseQuick(array_keys($aProfiles), $iStart, $iLimit, array('type' => $sType))
  715. );
  716. }
  717. /**
  718. * @page service Service Calls
  719. * @section bx_base_profile Base Profile
  720. * @subsection bx_base_profile-browse Browse
  721. * @subsubsection bx_base_profile-browse_by_acl browse_by_acl
  722. *
  723. * @code bx_srv('bx_persons', 'browse_by_acl', [...]); @endcode
  724. *
  725. * Browse profiles by membership(ACL) level
  726. * @param $mixedLevelId membership level, or array of membership levels
  727. * @param $iDesignBox optional, design box identifier
  728. *
  729. * @see BxBaseModProfileModule::serviceBrowseByAcl
  730. */
  731. /**
  732. * @ref bx_base_profile-browse_by_acl "browse_by_acl"
  733. */
  734. public function serviceBrowseByAcl ($mixedLevelId, $iDesignBox = BX_DB_PADDING_DEF)
  735. {
  736. return $this->_serviceBrowse (
  737. 'acl',
  738. array(
  739. 'level' => $mixedLevelId,
  740. ),
  741. $iDesignBox,
  742. true
  743. );
  744. }
  745. public function serviceEntityEditCover ($iContentId = 0)
  746. {
  747. return $this->_serviceEntityForm ('editDataForm', $iContentId, $this->_oConfig->CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT_COVER']);
  748. }
  749. /**
  750. * Entry comments
  751. */
  752. public function serviceEntityCommentsByProfile ($iProfileId)
  753. {
  754. $CNF = &$this->_oConfig->CNF;
  755. if(empty($CNF['OBJECT_COMMENTS']))
  756. return '';
  757. $oProfile = BxDolProfile::getInstance($iProfileId);
  758. if(!$oProfile)
  759. return '';
  760. return $this->_entityComments($CNF['OBJECT_COMMENTS'], $oProfile->getContentId());
  761. }
  762. /**
  763. * Entry social sharing block
  764. */
  765. public function serviceEntitySocialSharing ($mixedContent = false, $aParams = array())
  766. {
  767. if(!empty($mixedContent)) {
  768. if(!is_array($mixedContent))
  769. $mixedContent = array((int)$mixedContent, array());
  770. }
  771. else {
  772. $mixedContent = $this->_getContent();
  773. if($mixedContent === false)
  774. return false;
  775. }
  776. list($iContentId, $aContentInfo) = $mixedContent;
  777. return parent::serviceEntitySocialSharing(array($iContentId, $aContentInfo), array(
  778. 'id_thumb' => !empty($CNF['FIELD_PICTURE']) && !empty($aContentInfo[$CNF['FIELD_PICTURE']]) ? $aContentInfo[$CNF['FIELD_PICTURE']] : 0,
  779. ));
  780. }
  781. public function serviceProfileMembership ($iContentId = 0)
  782. {
  783. $mixedContent = $this->_getContent($iContentId);
  784. if($mixedContent === false)
  785. return false;
  786. list($iContentId, $aContentInfo) = $mixedContent;
  787. return BxDolAcl::getInstance()->getProfileMembership($aContentInfo['profile_id']);
  788. }
  789. public function serviceProfileFriends ($iContentId = 0)
  790. {
  791. $mixedContent = $this->_getContent($iContentId);
  792. if($mixedContent === false)
  793. return false;
  794. list($iContentId, $aContentInfo) = $mixedContent;
  795. bx_import('BxDolConnection');
  796. $s = $this->serviceBrowseConnectionsQuick ($aContentInfo['profile_id'], 'sys_profiles_friends', BX_CONNECTIONS_CONTENT_TYPE_CONTENT, true);
  797. if (!$s)
  798. return MsgBox(_t('_sys_txt_empty'));
  799. return $s;
  800. }
  801. public function serviceProfileSubscriptions ($iContentId = 0, $aParams = array())
  802. {
  803. $mixedContent = $this->_getContent($iContentId);
  804. if($mixedContent === false)
  805. return false;
  806. list($iContentId, $aContentInfo) = $mixedContent;
  807. bx_import('BxDolConnection');
  808. $aResult = $this->serviceBrowseConnectionsByType(array(
  809. 'profile_id' => $aContentInfo['profile_id'],
  810. 'object' => 'sys_profiles_subscriptions',
  811. 'type' => BX_CONNECTIONS_CONTENT_TYPE_CONTENT
  812. ), array(
  813. 'type' => isset($aParams['type']) ? $aParams['type'] : '',
  814. 'filter_menu' => isset($aParams['filter_menu']) ? $aParams['filter_menu'] : true,
  815. ));
  816. if(empty($aResult['content']))
  817. $aResult['content'] = MsgBox(_t('_sys_txt_empty'));
  818. return $aResult;
  819. }
  820. public function serviceProfileSubscribedMe ($iContentId = 0)
  821. {
  822. $mixedContent = $this->_getContent($iContentId);
  823. if($mixedContent === false)
  824. return false;
  825. list($iContentId, $aContentInfo) = $mixedContent;
  826. bx_import('BxDolConnection');
  827. $s = $this->serviceBrowseConnectionsQuick ($aContentInfo['profile_id'], 'sys_profiles_subscriptions', BX_CONNECTIONS_CONTENT_TYPE_INITIATORS);
  828. if (!$s)
  829. return MsgBox(_t('_sys_txt_empty'));
  830. return $s;
  831. }
  832. public function serviceProfileRelations ($iContentId = 0, $aParams = array())
  833. {
  834. $mixedContent = $this->_getContent($iContentId);
  835. if($mixedContent === false)
  836. return false;
  837. list($iContentId, $aContentInfo) = $mixedContent;
  838. bx_import('BxDolConnection');
  839. $s = $this->serviceBrowseRelationsQuick ($aContentInfo['profile_id'], 'sys_profiles_relations', BX_CONNECTIONS_CONTENT_TYPE_CONTENT, 1);
  840. if (!$s)
  841. return MsgBox(_t('_sys_txt_empty'));
  842. return $s;
  843. }
  844. public function serviceProfileRelatedMe ($iContentId = 0)
  845. {
  846. $mixedContent = $this->_getContent($iContentId);
  847. if($mixedContent === false)
  848. return false;
  849. list($iContentId, $aContentInfo) = $mixedContent;
  850. bx_import('BxDolConnection');
  851. $s = $this->serviceBrowseRelationsQuick ($aContentInfo['profile_id'], 'sys_profiles_relations', BX_CONNECTIONS_CONTENT_TYPE_INITIATORS, 1);
  852. if (!$s)
  853. return MsgBox(_t('_sys_txt_empty'));
  854. return $s;
  855. }
  856. /**
  857. * check enabled profile activation letter
  858. */
  859. public function serviceIsEnableProfileActivationLetter()
  860. {
  861. $CNF = &$this->_oConfig->CNF;
  862. return isset($CNF['PARAM_ENABLE_ACTIVATION_LETTER']) ? (bool)getParam($CNF['PARAM_ENABLE_ACTIVATION_LETTER']) : true;
  863. }
  864. public function serviceIsEnableRelations()
  865. {
  866. $sModule = $this->_oConfig->getName();
  867. $oRelations = BxDolConnection::getObjectInstance('sys_profiles_relations');
  868. return $oRelations->isRelationAvailableWithProfile($sModule) || $oRelations->isRelationAvailableFromProfile($sModule);
  869. }
  870. /**
  871. * For internal usage only.
  872. */
  873. public function serviceDeleteEntityService ($iContentId, $bDeleteWithContent = false)
  874. {
  875. return parent::serviceDeleteEntity ($iContentId, 'deleteDataService');
  876. }
  877. /**
  878. * Data for Notifications module
  879. */
  880. public function serviceGetNotificationsData()
  881. {
  882. $a = parent::serviceGetNotificationsData();
  883. $sModule = $this->_aModule['name'];
  884. $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');
  885. $a['settings'][] = array('group' => 'timeline_post', 'unit' => $sModule, 'action' => 'timeline_post_common', 'types' => array('follow_member'));
  886. $a['alerts'][] = array('unit' => $sModule, 'action' => 'timeline_post_common');
  887. return $a;
  888. }
  889. public function serviceGetNotificationsPost($aEvent)
  890. {
  891. $aResult = parent::serviceGetNotificationsVote($aEvent);
  892. if(empty($aResult) || !is_array($aResult) || !$this->serviceActAsProfile())
  893. return $aResult;
  894. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$aEvent['object_id'], $this->_oConfig->getName());
  895. if($oProfile !== false)
  896. $aResult['entry_author'] = $oProfile->id();
  897. return $aResult;
  898. }
  899. public function serviceGetNotificationsVote($aEvent)
  900. {
  901. $aResult = parent::serviceGetNotificationsVote($aEvent);
  902. if(empty($aResult) || !is_array($aResult) || !$this->serviceActAsProfile())
  903. return $aResult;
  904. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$aEvent['object_id'], $this->_oConfig->getName());
  905. if($oProfile !== false)
  906. $aResult['entry_author'] = $oProfile->id();
  907. return $aResult;
  908. }
  909. /**
  910. * Notification about new member requst in the group
  911. */
  912. public function serviceGetNotificationsTimelinePostCommon($aEvent)
  913. {
  914. $CNF = &$this->_oConfig->CNF;
  915. $iContentId = (int)$aEvent['object_id'];
  916. $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  917. if(!$oGroupProfile)
  918. return array();
  919. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  920. if(empty($aContentInfo) || !is_array($aContentInfo))
  921. return array();
  922. $aSubcontentInfo = BxDolService::call('bx_timeline', 'get_info', array((int)$aEvent['subobject_id'], false));
  923. if(empty($aSubcontentInfo) || !is_array($aSubcontentInfo))
  924. return array();
  925. $sSubentryUrl = BxDolService::call('bx_timeline', 'get_link', array((int)$aEvent['subobject_id']));
  926. $sSubentrySample = $aSubcontentInfo['title'];
  927. if(empty($sSubentrySample))
  928. $sSubentrySample = strmaxtextlen($aSubcontentInfo['description'], 20, '...');
  929. return array(
  930. 'entry_sample' => $CNF['T']['txt_sample_single'],
  931. 'entry_url' => $oGroupProfile->getUrl(),
  932. 'entry_caption' => $oGroupProfile->getDisplayName(),
  933. 'entry_author' => $oGroupProfile->id(),
  934. 'subentry_sample' => $sSubentrySample,
  935. 'subentry_url' => $sSubentryUrl,
  936. 'lang_key' => $CNF['T']['txt_ntfs_timeline_post_common'],
  937. );
  938. }
  939. /**
  940. * Data for Timeline module
  941. */
  942. public function serviceGetTimelineData()
  943. {
  944. $CNF = &$this->_oConfig->CNF;
  945. $sModule = $this->_aModule['name'];
  946. $aAlerts = array();
  947. $aHandlers = array();
  948. if(!empty($CNF['FIELD_PICTURE'])) {
  949. $aAlerts = array_merge($aAlerts, array(
  950. array('unit' => $sModule, 'action' => 'profile_picture_changed'),
  951. array('unit' => $sModule, 'action' => 'profile_picture_deleted')
  952. ));
  953. $aHandlers = array_merge($aHandlers, array(
  954. 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' => ''),
  955. array('group' => $sModule . '_profile_picture', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'profile_picture_deleted')
  956. ));
  957. }
  958. if(!empty($CNF['FIELD_COVER'])) {
  959. $aAlerts = array_merge($aAlerts, array(
  960. array('unit' => $sModule, 'action' => 'profile_cover_changed'),
  961. array('unit' => $sModule, 'action' => 'profile_cover_deleted')
  962. ));
  963. $aHandlers = array_merge($aHandlers, array(
  964. 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' => ''),
  965. array('group' => $sModule . '_profile_cover', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'profile_cover_deleted')
  966. ));
  967. }
  968. $aResult = array();
  969. if(!empty($aAlerts) && !empty($aHandlers))
  970. $aResult = array(
  971. 'handlers' => $aHandlers,
  972. 'alerts' => $aAlerts
  973. );
  974. return $aResult;
  975. }
  976. /**
  977. * Entry post for Timeline module
  978. */
  979. public function serviceGetTimelineProfilePicture($aEvent, $aBrowseParams = array())
  980. {
  981. $aResult = $this->_serviceGetTimelineProfileImage($aEvent, $aBrowseParams, array(
  982. 'stg' => 'OBJECT_STORAGE',
  983. 'trans' => array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_AVATAR'),
  984. 'trans_orig' => array('OBJECT_IMAGES_TRANSCODER_PICTURE', 'OBJECT_IMAGES_TRANSCODER_GALLERY'),
  985. 'txt_ss' => 'txt_sample_pp_single',
  986. 'txt_sswa' => 'txt_sample_pp_single_with_article',
  987. 'txt_sa' => 'txt_sample_pi_action',
  988. 'txt_sau' => 'txt_sample_pi_action_user'
  989. ));
  990. $aResult['allowed_view'] = array('module' => $this->_oConfig->getName(), 'method' => 'get_timeline_profile_picture_allowed_view');
  991. return $aResult;
  992. }
  993. public function serviceGetTimelineProfilePictureAllowedView($aEvent)
  994. {
  995. return $this->_serviceGetTimelineProfileImageAllowedView($aEvent);
  996. }
  997. public function serviceGetTimelineProfileCover($aEvent, $aBrowseParams = array())
  998. {
  999. $aResult = $this->_serviceGetTimelineProfileImage($aEvent, $aBrowseParams, array(
  1000. 'stg' => 'OBJECT_STORAGE_COVER',
  1001. 'trans' => array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_COVER_THUMB'),
  1002. 'trans_orig' => array('OBJECT_IMAGES_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_GALLERY'),
  1003. 'txt_ss' => 'txt_sample_pc_single',
  1004. 'txt_sswa' => 'txt_sample_pc_single_with_article',
  1005. 'txt_sa' => 'txt_sample_pi_action',
  1006. 'txt_sau' => 'txt_sample_pi_action_user'
  1007. ));
  1008. $aResult['allowed_view'] = array('module' => $this->_oConfig->getName(), 'method' => 'get_timeline_profile_cover_allowed_view');
  1009. return $aResult;
  1010. }
  1011. public function serviceGetTimelineProfileCoverAllowedView($aEvent)
  1012. {
  1013. return $this->_serviceGetTimelineProfileImageAllowedView($aEvent);
  1014. }
  1015. public function serviceGetConnectionButtonsTitles($iProfileId, $sConnectionsObject = 'sys_profiles_friends')
  1016. {
  1017. if (!isLogged())
  1018. return array();
  1019. if (!($oConn = BxDolConnection::getObjectInstance($sConnectionsObject)))
  1020. return array();
  1021. $CNF = $this->_oConfig->CNF;
  1022. if ($oConn->isConnectedNotMutual(bx_get_logged_profile_id(), $iProfileId)) {
  1023. return array(
  1024. 'add' => _t($CNF['T']['menu_item_title_befriend_sent']),
  1025. 'remove' => _t($CNF['T']['menu_item_title_unfriend_cancel_request']),
  1026. );
  1027. } elseif ($oConn->isConnectedNotMutual($iProfileId, bx_get_logged_profile_id())) {
  1028. return array(
  1029. 'add' => _t($CNF['T']['menu_item_title_befriend_confirm']),
  1030. 'remove' => _t($CNF['T']['menu_item_title_unfriend_reject_request']),
  1031. );
  1032. } elseif ($oConn->isConnected($iProfileId, bx_get_logged_profile_id(), true)) {
  1033. return array(
  1034. 'add' => '',
  1035. 'remove' => _t($CNF['T']['menu_item_title_unfriend']),
  1036. );
  1037. } else {
  1038. return array(
  1039. 'add' => _t($CNF['T']['menu_item_title_befriend']),
  1040. 'remove' => '',
  1041. );
  1042. }
  1043. }
  1044. // ====== PERMISSION METHODS
  1045. /**
  1046. * @see iBxDolProfileService::serviceCheckAllowedProfileView
  1047. */
  1048. public function serviceCheckAllowedProfileView($iContentId)
  1049. {
  1050. return $this->serviceCheckAllowedWithContent('View', $iContentId);
  1051. }
  1052. /**
  1053. * @see iBxDolProfileService::serviceCheckAllowedProfileContact
  1054. */
  1055. public function serviceCheckAllowedProfileContact($iContentId)
  1056. {
  1057. return $this->serviceCheckAllowedWithContent('Contact', $iContentId);
  1058. }
  1059. /**
  1060. * @see iBxDolProfileService::serviceCheckAllowedPostInProfile
  1061. */
  1062. public function serviceCheckAllowedPostInProfile($iContentId)
  1063. {
  1064. return $this->serviceCheckAllowedWithContent('Post', $iContentId);
  1065. }
  1066. /**
  1067. * @see iBxDolProfileService::serviceCheckSpacePrivacy
  1068. */
  1069. public function serviceCheckSpacePrivacy($iContentId)
  1070. {
  1071. return $this->serviceCheckAllowedProfileView($iContentId);
  1072. }
  1073. /**
  1074. * Check if the profile can be viewed.
  1075. *
  1076. * NOTE. This service should be used if it's needed to pass some specific values in
  1077. * $isPerformAction and $iProfileId parameters, otherwise it's recommended to use
  1078. * BxBaseModProfileModule::serviceCheckAllowedProfileView service method or
  1079. * BxDolProfile::checkAllowedProfileView method.
  1080. *
  1081. * @param type $aDataEntry - entry which the action will be performed for
  1082. * @param type $isPerformAction - perform or just check the action
  1083. * @param type $iProfileId - performer's profile ID
  1084. * @return integer - one of CHECK_ACTION_RESULT_XXX constants.
  1085. */
  1086. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  1087. {
  1088. if (!$iProfileId)
  1089. $iProfileId = $this->_iProfileId;
  1090. if(empty($aDataEntry) || !is_array($aDataEntry))
  1091. return _t('_sys_txt_not_found');
  1092. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  1093. if ($oProfile && $oProfile->id() == $iProfileId)
  1094. return CHECK_ACTION_RESULT_ALLOWED;
  1095. return parent::serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  1096. }
  1097. /**
  1098. * Check if posting (comment, post in Timeline) is available.
  1099. *
  1100. * NOTE. This service should be used if it's needed to pass some specific values in
  1101. * $isPerformAction and $iProfileId parameters, otherwise it's recommended to use
  1102. * BxBaseModProfileModule::serviceCheckAllowedPostInProfile service method or
  1103. * BxDolProfile::checkAllowedPostInProfile method.
  1104. *
  1105. * @param type $aDataEntry - entry which the action will be performed for
  1106. * @param type $isPerformAction - perform or just check the action
  1107. * @param type $iProfileId - performer's profile ID
  1108. * @return integer - one of CHECK_ACTION_RESULT_XXX constants.
  1109. */
  1110. public function serviceCheckAllowedPostForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  1111. {
  1112. $CNF = &$this->_oConfig->CNF;
  1113. if(!$iProfileId)
  1114. $iProfileId = $this->_iProfileId;
  1115. // check is view allowed
  1116. if(($mixedResult = $this->serviceCheckAllowedViewForProfile($aDataEntry, $isPerformAction, $iProfileId)) !== CHECK_ACTION_RESULT_ALLOWED)
  1117. return $mixedResult;
  1118. // moderator and owner always have access
  1119. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->getName());
  1120. if(($oProfile && $oProfile->id() == $iProfileId) || $this->_isModerator($isPerformAction))
  1121. return CHECK_ACTION_RESULT_ALLOWED;
  1122. // check privacy
  1123. if(!empty($CNF['OBJECT_PRIVACY_POST'])) {
  1124. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_POST']);
  1125. if($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  1126. return _t('_sys_access_denied_to_private_content');
  1127. }
  1128. // check alert to allow custom checks
  1129. $mixedResult = null;
  1130. bx_alert('system', 'check_allowed_post', 0, 0, array('module' => $this->getName(), 'content_info' => $aDataEntry, 'profile_id' => $iProfileId, 'override_result' => &$mixedResult));
  1131. if($mixedResult !== null)
  1132. return $mixedResult;
  1133. return CHECK_ACTION_RESULT_ALLOWED;
  1134. }
  1135. /**
  1136. * Check if profile can be contacted.
  1137. *
  1138. * NOTE. This service should be used if it's needed to pass some specific values in
  1139. * $isPerformAction and $iProfileId parameters, otherwise it's recommended to use
  1140. * BxBaseModProfileModule::serviceCheckAllowedProfileContact service method or
  1141. * BxDolProfile::checkAllowedProfileContact method.
  1142. *
  1143. * @param type $aDataEntry - entry which the action will be performed for
  1144. * @param type $isPerformAction - perform or just check the action
  1145. * @param type $iProfileId - performer's profile ID
  1146. * @return integer - one of CHECK_ACTION_RESULT_XXX constants.
  1147. */
  1148. public function serviceCheckAllowedContactForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  1149. {
  1150. $mixedResult = $this->_serviceCheckAllowedContactForProfile($aDataEntry, $isPerformAction, $iProfileId);
  1151. // call alert to allow custom checks
  1152. bx_alert('system', 'check_allowed_contact', 0, 0, array(
  1153. 'module' => $this->getName(),
  1154. 'content_info' => $aDataEntry,
  1155. 'profile_id' => $iProfileId,
  1156. 'override_result' => &$mixedResult
  1157. ));
  1158. return $mixedResult;
  1159. }
  1160. public function serviceSetViewProfileCover($oPage, $aProfileInfo)
  1161. {
  1162. $this->_oTemplate->setCover($oPage,$aProfileInfo);
  1163. }
  1164. /**
  1165. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1166. */
  1167. public function checkAllowedAdd ($isPerformAction = false)
  1168. {
  1169. $oAccount = BxDolAccount::getInstance();
  1170. if (!$oAccount || ($this->serviceActAsProfile() && $oAccount->isProfilesLimitReached()))
  1171. return _t('_sys_txt_access_denied');
  1172. return parent::checkAllowedAdd ($isPerformAction);
  1173. }
  1174. /**
  1175. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1176. */
  1177. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  1178. {
  1179. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
  1180. }
  1181. /**
  1182. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1183. */
  1184. public function checkAllowedViewProfileImage ($aDataEntry, $isPerformAction = false)
  1185. {
  1186. $CNF = &$this->_oConfig->CNF;
  1187. // check privacy
  1188. if (empty($CNF['OBJECT_PRIVACY_VIEW']))
  1189. return CHECK_ACTION_RESULT_ALLOWED;
  1190. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  1191. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']]) && !$oPrivacy->isPartiallyVisible($aDataEntry[$CNF['FIELD_ALLOW_VIEW_TO']]))
  1192. return _t('_sys_access_denied_to_private_content');
  1193. return CHECK_ACTION_RESULT_ALLOWED;
  1194. }
  1195. /**
  1196. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1197. */
  1198. public function checkAllowedViewCoverImage ($aDataEntry, $isPerformAction = false)
  1199. {
  1200. return $this->checkAllowedViewProfileImage($aDataEntry);
  1201. }
  1202. /**
  1203. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1204. */
  1205. public function checkAllowedPost ($aDataEntry, $isPerformAction = false)
  1206. {
  1207. return $this->serviceCheckAllowedPostForProfile ($aDataEntry, $isPerformAction);
  1208. }
  1209. /**
  1210. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1211. */
  1212. public function checkAllowedContact ($aDataEntry, $isPerformAction = false)
  1213. {
  1214. return $this->serviceCheckAllowedContactForProfile ($aDataEntry, $isPerformAction);
  1215. }
  1216. /**
  1217. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1218. */
  1219. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  1220. {
  1221. if(empty($aDataEntry) || !is_array($aDataEntry))
  1222. return _t('_sys_txt_not_found');
  1223. // moderator always has access
  1224. if ($this->_isModerator($isPerformAction))
  1225. return CHECK_ACTION_RESULT_ALLOWED;
  1226. // owner (checked by account instead of author!) always have access
  1227. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name']);
  1228. if (!$oProfile)
  1229. return _t('_sys_txt_error_occured');
  1230. if ($oProfile->id() == $this->_iProfileId || $oProfile->getAccountId() == $this->_iAccountId)
  1231. return CHECK_ACTION_RESULT_ALLOWED;
  1232. return _t('_sys_txt_access_denied');
  1233. }
  1234. /**
  1235. * Check if user can change cover image
  1236. */
  1237. public function checkAllowedChangeCover ($aDataEntry, $isPerformAction = false)
  1238. {
  1239. // moderator always has access
  1240. if ($this->_isModerator($isPerformAction))
  1241. return CHECK_ACTION_RESULT_ALLOWED;
  1242. // owner (checked by account instead of author!) always have access
  1243. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name']);
  1244. if (!$oProfile)
  1245. return _t('_sys_txt_error_occured');
  1246. if ($oProfile->id() == $this->_iProfileId || $oProfile->getAccountId() == $this->_iAccountId)
  1247. return CHECK_ACTION_RESULT_ALLOWED;
  1248. return _t('_sys_txt_access_denied');
  1249. }
  1250. /**
  1251. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1252. */
  1253. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  1254. {
  1255. // moderator always has access
  1256. if ($this->_isModerator($isPerformAction))
  1257. return CHECK_ACTION_RESULT_ALLOWED;
  1258. // owner (checked by account instead of author!) always have access
  1259. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  1260. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name'], $isPerformAction);
  1261. if (!$oProfile)
  1262. return _t('_sys_txt_error_occured');
  1263. if (($oProfile->id() == $this->_iProfileId || $oProfile->getAccountId() == $this->_iAccountId) && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  1264. return CHECK_ACTION_RESULT_ALLOWED;
  1265. return _t('_sys_txt_access_denied');
  1266. }
  1267. /**
  1268. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1269. */
  1270. public function checkAllowedViewMoreMenu (&$aDataEntry, $isPerformAction = false)
  1271. {
  1272. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']);
  1273. if (!$oMenu || !$oMenu->getCode())
  1274. return _t('_sys_txt_access_denied');
  1275. return CHECK_ACTION_RESULT_ALLOWED;
  1276. }
  1277. /**
  1278. * Compose differs from Contact. For example, a user should NOT be able to start conversation (compose)
  1279. * with himself but he should be able to view conversation page where he is one of the participants.
  1280. *
  1281. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1282. */
  1283. public function checkAllowedCompose(&$aDataEntry, $isPerformAction = false)
  1284. {
  1285. $CNF = &$this->_oConfig->CNF;
  1286. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->getName());
  1287. if($oProfile && $oProfile->id() == $this->_iProfileId)
  1288. return _t('_sys_txt_access_denied');
  1289. return $this->checkAllowedContact($aDataEntry, $isPerformAction);
  1290. }
  1291. /**
  1292. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1293. */
  1294. public function checkAllowedFriendAdd (&$aDataEntry, $isPerformAction = false)
  1295. {
  1296. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', true, false);
  1297. }
  1298. /**
  1299. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1300. */
  1301. public function checkAllowedFriendRemove (&$aDataEntry, $isPerformAction = false)
  1302. {
  1303. if (CHECK_ACTION_RESULT_ALLOWED === $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', false, true, true))
  1304. return CHECK_ACTION_RESULT_ALLOWED;
  1305. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', false, true, false);
  1306. }
  1307. /**
  1308. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1309. */
  1310. public function checkAllowedRelationAdd (&$aDataEntry, $isPerformAction = false)
  1311. {
  1312. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedView($aDataEntry)))
  1313. return $sMsg;
  1314. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_relations', false, false);
  1315. }
  1316. /**
  1317. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1318. */
  1319. public function checkAllowedRelationRemove (&$aDataEntry, $isPerformAction = false)
  1320. {
  1321. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_relations', false, true);
  1322. }
  1323. public function checkAllowedRelationsView (&$aDataEntry, $isPerformAction = false)
  1324. {
  1325. $sResult = _t('_sys_txt_access_denied');
  1326. $sModule = $this->_oConfig->getName();
  1327. $oRelations = BxDolConnection::getObjectInstance('sys_profiles_relations');
  1328. if(!$oRelations->isRelationAvailableWithProfile($sModule) && !$oRelations->isRelationAvailableFromProfile($sModule))
  1329. return $sResult;
  1330. if(empty($aDataEntry) || !is_array($aDataEntry))
  1331. return $sResult;
  1332. return CHECK_ACTION_RESULT_ALLOWED;
  1333. }
  1334. /**
  1335. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1336. */
  1337. public function checkAllowedSubscribeAdd(&$aDataEntry, $isPerformAction = false)
  1338. {
  1339. $mixedResult = $this->_modProfileCheckAllowedSubscribeAdd($aDataEntry, $isPerformAction);
  1340. // call alert to allow custom checks
  1341. bx_alert('system', 'check_allowed_subscribe_add', 0, 0, array(
  1342. 'module' => $this->getName(),
  1343. 'content_info' => $aDataEntry,
  1344. 'profile_id' => bx_get_logged_profile_id(),
  1345. 'override_result' => &$mixedResult
  1346. ));
  1347. return $mixedResult;
  1348. }
  1349. /**
  1350. * Note. Is mainly needed for internal usage. Access level is 'public' to allow outer calls from alerts.
  1351. */
  1352. public function _modProfileCheckAllowedSubscribeAdd(&$aDataEntry, $isPerformAction = false)
  1353. {
  1354. if(($sMsg = $this->checkAllowedView($aDataEntry)) !== CHECK_ACTION_RESULT_ALLOWED)
  1355. return $sMsg;
  1356. return $this->_checkAllowedConnect($aDataEntry, $isPerformAction, 'sys_profiles_subscriptions', false, false);
  1357. }
  1358. /**
  1359. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1360. */
  1361. public function checkAllowedSubscribeRemove (&$aDataEntry, $isPerformAction = false)
  1362. {
  1363. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_subscriptions', false, true);
  1364. }
  1365. public function checkAllowedSubscriptionsView (&$aDataEntry, $isPerformAction = false)
  1366. {
  1367. $CNF = &$this->_oConfig->CNF;
  1368. $sResult = _t('_sys_txt_access_denied');
  1369. if(empty($aDataEntry) || !is_array($aDataEntry))
  1370. return $sResult;
  1371. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->_aModule['name']);
  1372. if(!$oProfile || ($oProfile->id() != $this->_iProfileId && $this->_oDb->getParam($CNF['PARAM_PUBLIC_SBSN']) != 'on' && $this->_oDb->getParam($CNF['PARAM_PUBLIC_SBSD']) != 'on'))
  1373. return $sResult;
  1374. return CHECK_ACTION_RESULT_ALLOWED;
  1375. }
  1376. public function checkMyself($iContentId)
  1377. {
  1378. $iLogged = (int)bx_get_logged_profile_id();
  1379. if(empty($iLogged))
  1380. return false;
  1381. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->_oConfig->getName());
  1382. if(!$oProfile)
  1383. return false;
  1384. return $oProfile->id() == $iLogged;
  1385. }
  1386. public function isAllowDeleteOrDisable($iActorProfileId, $iTargetProfileId)
  1387. {
  1388. if (BxDolAcl::getInstance()->isMemberLevelInSet(array(MEMBERSHIP_ID_MODERATOR), $iActorProfileId) && BxDolAcl::getInstance()->isMemberLevelInSet(array(MEMBERSHIP_ID_MODERATOR, MEMBERSHIP_ID_ADMINISTRATOR), $iTargetProfileId))
  1389. return false;
  1390. return true;
  1391. }
  1392. public function getProfileObject($iContentId)
  1393. {
  1394. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->_oConfig->getName());
  1395. if (!$oProfile)
  1396. $oProfile = BxDolProfileUndefined::getInstance();
  1397. return $oProfile;
  1398. }
  1399. protected function _serviceCheckAllowedContactForProfile($aDataEntry, $isPerformAction = false, $iProfileId = false)
  1400. {
  1401. $CNF = &$this->_oConfig->CNF;
  1402. if(!$iProfileId)
  1403. $iProfileId = $this->_iProfileId;
  1404. /*
  1405. * allow to 'contact myself'. It's needed to allow a user to view conversation page
  1406. * where he is one of the participants.
  1407. */
  1408. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->getName());
  1409. if($oProfile && $oProfile->id() == $iProfileId)
  1410. return CHECK_ACTION_RESULT_ALLOWED;
  1411. // moderator always has access
  1412. if($this->_isModeratorForProfile($isPerformAction, $iProfileId))
  1413. return CHECK_ACTION_RESULT_ALLOWED;
  1414. // check privacy
  1415. if(!empty($CNF['OBJECT_PRIVACY_CONTACT'])) {
  1416. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_CONTACT']);
  1417. if($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  1418. return _t('_sys_access_denied_to_private_content');
  1419. }
  1420. return CHECK_ACTION_RESULT_ALLOWED;
  1421. }
  1422. // ====== COMMON METHODS
  1423. public function alertAfterAdd($aContentInfo)
  1424. {
  1425. $CNF = &$this->_oConfig->CNF;
  1426. $sModule = $this->getName();
  1427. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  1428. $aParams = array();
  1429. if(isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]))
  1430. $aParams['privacy_view'] = $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']];
  1431. bx_alert($sModule, 'added', $iContentId, false, $aParams);
  1432. }
  1433. public function alertAfterEdit($aContentInfo)
  1434. {
  1435. $CNF = &$this->_oConfig->CNF;
  1436. $sModule = $this->getName();
  1437. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  1438. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $sModule);
  1439. bx_alert($sModule, 'edited', $iContentId);
  1440. bx_alert('profile', 'edit', $oProfile->id(), 0, array('content' => $iContentId, 'module' => $sModule));
  1441. }
  1442. public function getProfileByCurrentUrl ()
  1443. {
  1444. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  1445. if ($iProfileId)
  1446. return BxDolProfile::getInstance($iProfileId);
  1447. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1448. if ($iContentId)
  1449. return BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  1450. return false;
  1451. }
  1452. public function getEntryImageData($aContentInfo, $sField = 'FIELD_PICTURE', $aTranscoders = array())
  1453. {
  1454. return parent::getEntryImageData($aContentInfo, $sField, $aTranscoders);
  1455. }
  1456. // ====== PROTECTED METHODS
  1457. protected function _checkAllowedConnect (&$aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap = false)
  1458. {
  1459. if (!$this->_iProfileId)
  1460. return _t('_sys_txt_access_denied');
  1461. $CNF = &$this->_oConfig->CNF;
  1462. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->_aModule['name']);
  1463. if (!$oProfile || $oProfile->id() == $this->_iProfileId)
  1464. return _t('_sys_txt_access_denied');
  1465. return BxDolConnection::getObjectInstance($sObjConnection)->checkAllowedConnect ($this->_iProfileId, $oProfile->id(), $isPerformAction, $isMutual, $isInvertResult, $isSwap);
  1466. }
  1467. protected function _buildRssParams($sMode, $aArgs)
  1468. {
  1469. $aParams = array ();
  1470. $sMode = bx_process_input($sMode);
  1471. switch ($sMode) {
  1472. case 'connections':
  1473. $aParams = array(
  1474. 'object' => isset($aArgs[0]) ? $aArgs[0] : '',
  1475. 'type' => isset($aArgs[1]) ? $aArgs[1] : '',
  1476. 'profile' => isset($aArgs[2]) ? (int)$aArgs[2] : 0,
  1477. 'mutual' => isset($aArgs[3]) ? (int)$aArgs[3] : 0,
  1478. 'profile2' => isset($aArgs[4]) ? (int)$aArgs[4] : 0,
  1479. );
  1480. break;
  1481. }
  1482. return $aParams;
  1483. }
  1484. protected function _serviceGetTimelineProfileImage($aEvent, $aBrowseParams, $aBuildParams)
  1485. {
  1486. $CNF = &$this->_oConfig->CNF;
  1487. $aFileInfo = BxDolStorage::getObjectInstance($CNF[$aBuildParams['stg']])->getFile((int)$aEvent['object_id']);
  1488. if(empty($aFileInfo) || !is_array($aFileInfo))
  1489. return false;
  1490. $aEventContent = unserialize($aEvent['content']);
  1491. if(!is_array($aEventContent) || empty($aEventContent['content']))
  1492. return false;
  1493. $aContentInfo = $this->_oDb->getContentInfoById($aEventContent['content']);
  1494. if(empty($aContentInfo) || !is_array($aContentInfo))
  1495. return false;
  1496. $oProfile = BxDolProfile::getInstanceMagic($aContentInfo['profile_id']);
  1497. if (!$oProfile->isActive())
  1498. return false;
  1499. $sUserName = $oProfile->getDisplayName();
  1500. $sSample = isset($CNF['T'][$aBuildParams['txt_sswa']]) ? $CNF['T'][$aBuildParams['txt_sswa']] : $CNF['T'][$aBuildParams['txt_ss']];
  1501. //--- Title & Description
  1502. $sTitle = !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '';
  1503. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TEXT']]))
  1504. $sTitle = $aContentInfo[$CNF['FIELD_TEXT']];
  1505. $sDescription = _t($CNF['T'][$aBuildParams['txt_sau']], $sUserName, _t($sSample));
  1506. return array(
  1507. 'owner_id' => $aEvent['owner_id'],
  1508. 'object_owner_id' => $aContentInfo['profile_id'],
  1509. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  1510. 'sample' => $sSample,
  1511. 'sample_wo_article' => $CNF['T'][$aBuildParams['txt_ss']],
  1512. 'sample_action' => isset($CNF['T'][$aBuildParams['txt_sa']]) ? $CNF['T'][$aBuildParams['txt_sa']] : '',
  1513. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]),
  1514. 'content' => $this->_getContentForTimelineProfileImage($aEvent, $aBrowseParams, $aBuildParams, $aContentInfo, $aFileInfo), //a string to display or array to parse default template before displaying.
  1515. 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
  1516. 'views' => '',
  1517. 'votes' => '',
  1518. 'scores' => '',
  1519. 'reports' => '',
  1520. 'comments' => '',
  1521. 'title' => $sTitle, //may be empty.
  1522. 'description' => $sDescription //may be empty.
  1523. );
  1524. }
  1525. protected function _serviceGetTimelineProfileImageAllowedView($aEvent)
  1526. {
  1527. $sError = _t('_sys_access_denied_to_private_content');
  1528. if(empty($aEvent['content']) || !is_array($aEvent['content']) || empty($aEvent['content']['id']))
  1529. return $sError;
  1530. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['content']['id']);
  1531. if(empty($aContentInfo) || !is_array($aContentInfo))
  1532. return $sError;
  1533. return $this->serviceCheckAllowedViewForProfile($aContentInfo);
  1534. }
  1535. protected function _getContentForTimelineProfileImage($aEvent, $aBrowseParams, $aBuildParams, $aContentInfo, $aFileInfo)
  1536. {
  1537. $CNF = &$this->_oConfig->CNF;
  1538. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1539. //--- Image(s)
  1540. $sImage = $this->_oConfig->getImageUrl($aFileInfo['id'], $aBuildParams['trans']);
  1541. $sImageOrig = $this->_oConfig->getImageUrl($aFileInfo['id'], $aBuildParams['trans_orig']);
  1542. if(!empty($sImage)) {
  1543. if(empty($sImageOrig))
  1544. $sImageOrig = $sImage;
  1545. $a = array('id' => $aFileInfo['id'], 'url' => $sUrl, 'src' => $sImage);
  1546. if (CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedView($aContentInfo))
  1547. $a['src_orig'] = $sImageOrig;
  1548. $aImages = array($a);
  1549. }
  1550. return array(
  1551. 'sample' => isset($CNF['T'][$aBuildParams['txt_sswa']]) ? $CNF['T'][$aBuildParams['txt_sswa']] : $CNF['T'][$aBuildParams['txt_ss']],
  1552. 'sample_wo_article' => $CNF['T'][$aBuildParams['txt_ss']],
  1553. 'sample_action' => isset($CNF['T'][$aBuildParams['txt_sa']]) ? $CNF['T'][$aBuildParams['txt_sa']] : '',
  1554. 'id' => $aContentInfo[$CNF['FIELD_ID']],
  1555. 'url' => $sUrl,
  1556. 'title' => '',
  1557. 'text' => '',
  1558. 'images' => $aImages,
  1559. 'videos' => array()
  1560. );
  1561. }
  1562. protected function _entityComments($sObject, $iId = 0)
  1563. {
  1564. if(!$iId)
  1565. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1566. if(!$iId)
  1567. $iId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  1568. if(!$iId)
  1569. return false;
  1570. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  1571. if(!$oCmts || !$oCmts->isEnabled())
  1572. return false;
  1573. return $oCmts->getCommentsBlock(array(), array('in_designbox' => false));
  1574. }
  1575. protected function _getContent($iContentId = 0, $sFuncGetContent = 'getContentInfoById')
  1576. {
  1577. if(!$iContentId && bx_get('id') === false && bx_get('profile_id') !== false) {
  1578. $oProfile = BxDolProfile::getInstance((int)bx_get('profile_id'));
  1579. if($oProfile)
  1580. $iContentId = $oProfile->getContentId();
  1581. }
  1582. return parent::_getContent($iContentId, $sFuncGetContent);
  1583. }
  1584. /**
  1585. * Returns list of members by mode with limited number of records for React Jot
  1586. * @param string $sMode
  1587. * @param int $iStart
  1588. * @param int $iPerPage
  1589. * @return mixed
  1590. */
  1591. public function serviceGetMembers($sMode = 'active', $iStart = 0, $iPerPage = 10){
  1592. bx_import('SearchResult', $this->_aModule);
  1593. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  1594. $o = new $sClass($sMode);
  1595. $o -> aCurrent['paginate'] = array('perPage' => $iPerPage, 'forceStart' => $iStart);
  1596. return $o -> getSearchData();
  1597. }
  1598. }
  1599. /** @} */