1
0

BxBaseModProfileModule.php 74 KB

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