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