BxBaseModProfileModule.php 97 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480
  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. public function actionEmbed($iContentId, $sUnitTemplate = '', $sAddCode = '')
  75. {
  76. return parent::actionEmbed($iContentId, 'unit_with_cover.html');
  77. }
  78. // ====== SERVICE METHODS
  79. public function serviceGetSafeServices()
  80. {
  81. $a = parent::serviceGetSafeServices();
  82. return array_merge($a, array (
  83. 'ProfileUnitSafe' => '',
  84. 'ProfileUrl' => '',
  85. 'EntityCreate' => '',
  86. 'BrowseRecommended' => '',
  87. 'BrowseRecentProfiles' => '',
  88. 'BrowseActiveProfiles' => '',
  89. 'BrowseTopProfiles' => '',
  90. 'BrowseOnlineProfiles' => '',
  91. 'BrowseConnections' => '',
  92. 'BrowseConnectionsEverywhere' => '',
  93. 'BrowseByAcl' => '',
  94. ));
  95. }
  96. public function serviceGetOptionsRedirectAfterAdd()
  97. {
  98. $CNF = &$this->_oConfig->CNF;
  99. $aResult = array();
  100. $aChoices = array(BX_DOL_PROFILE_REDIRECT_PROFILE, BX_DOL_PROFILE_REDIRECT_LAST, BX_DOL_PROFILE_REDIRECT_CUSTOM, BX_DOL_PROFILE_REDIRECT_HOMEPAGE);
  101. foreach($aChoices as $sChoice)
  102. $aResult[] = array('key' => $sChoice, 'value' => _t($CNF['T']['option_redirect_aadd_' . $sChoice]));
  103. return $aResult;
  104. }
  105. public function serviceGetOptionsActivation()
  106. {
  107. $CNF = &$this->_oConfig->CNF;
  108. $aResult = array();
  109. $aChoices = array(BX_DOL_PROFILE_ACTIVATE_ALWAYS, BX_DOL_PROFILE_ACTIVATE_NEVER, BX_DOL_PROFILE_ACTIVATE_ADD, BX_DOL_PROFILE_ACTIVATE_EDIT);
  110. foreach($aChoices as $sChoice)
  111. $aResult[] = array('key' => $sChoice, 'value' => _t($CNF['T']['option_activation_' . $sChoice]));
  112. return $aResult;
  113. }
  114. public function serviceGetThumb ($iContentId, $sTranscoder = '')
  115. {
  116. $CNF = &$this->_oConfig->CNF;
  117. if(bx_is_api()){
  118. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  119. return bx_api_get_image($CNF['OBJECT_STORAGE'], $aContentInfo[$CNF['FIELD_PICTURE']]);
  120. }
  121. if(empty($sTranscoder) && !empty($CNF['OBJECT_IMAGES_TRANSCODER_THUMB']))
  122. $sTranscoder = $CNF['OBJECT_IMAGES_TRANSCODER_THUMB'];
  123. $mixedResult = $this->_getFieldValueThumb('FIELD_PICTURE', $iContentId, $sTranscoder);
  124. return $mixedResult !== false ? $mixedResult : '';
  125. }
  126. public function serviceGetCover ($iContentId, $sTranscoder = '')
  127. {
  128. $CNF = &$this->_oConfig->CNF;
  129. if(bx_is_api()){
  130. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  131. $aTmp = bx_api_get_image($CNF['OBJECT_STORAGE'], $aContentInfo[$CNF['FIELD_COVER']]);
  132. if (!$aTmp){
  133. return ['storage' => $CNF['OBJECT_STORAGE']];
  134. }
  135. return $aTmp;
  136. }
  137. if(empty($sTranscoder) && !empty($CNF['OBJECT_IMAGES_TRANSCODER_COVER']))
  138. $sTranscoder = $CNF['OBJECT_IMAGES_TRANSCODER_COVER'];
  139. $mixedResult = $this->_getFieldValueThumb('FIELD_COVER', $iContentId, $sTranscoder);
  140. return $mixedResult !== false ? $mixedResult : '';
  141. }
  142. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  143. {
  144. if(empty($sUnitTemplate))
  145. $sUnitTemplate = 'unit_with_cover.html';
  146. return parent::serviceGetSearchResultUnit($iContentId, $sUnitTemplate);
  147. }
  148. public function serviceGetSearchableFieldsExtended($aInputsAdd = array())
  149. {
  150. $CNF = &$this->_oConfig->CNF;
  151. $aResult = parent::serviceGetSearchableFieldsExtended($aInputsAdd);
  152. if(!$this->serviceActAsProfile())
  153. return $aResult;
  154. if(!in_array('online', $this->_aSearchableNamesExcept))
  155. $aResult['online'] = array(
  156. 'type' => 'checkbox',
  157. 'caption' => $CNF['T']['form_field_online'],
  158. 'info' => '',
  159. 'value' => '1',
  160. 'values' => '',
  161. 'pass' => ''
  162. );
  163. if(!empty($CNF['FIELD_PICTURE']) && !in_array($CNF['FIELD_PICTURE'], $this->_aSearchableNamesExcept))
  164. $aResult[$CNF['FIELD_PICTURE']] = array(
  165. 'type' => 'checkbox',
  166. 'caption' => $CNF['T']['form_field_picture'],
  167. 'info' => '',
  168. 'value' => '1',
  169. 'values' => '',
  170. 'pass' => '',
  171. 'search_operator' => '>='
  172. );
  173. return $aResult;
  174. }
  175. /**
  176. * @page service Service Calls
  177. * @section bx_base_profile Base Profile
  178. * @subsection bx_base_profile-general General
  179. * @subsubsection bx_base_profile-entity_calendar entity_calendar
  180. *
  181. * @code bx_srv('bx_persons', 'entity_calendar', [...]); @endcode
  182. *
  183. * Get calendar block
  184. * @param $iContentId content ID
  185. *
  186. * @see BxBaseModProfileModule::serviceEntityCalendar
  187. */
  188. /**
  189. * @ref bx_base_profile-entity_calendar "entity_calendar"
  190. */
  191. public function serviceEntityCalendar($iContentId = 0, $sTemplate = 'calendar.html')
  192. {
  193. $iContentId = $this->_getContent($iContentId, false);
  194. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->_oConfig->getName());
  195. if($oProfile){
  196. $o = new BxTemplCalendar(array(
  197. 'eventSources' => array (
  198. bx_append_url_params(BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'profile_calendar_data', array('profile_id' => $oProfile->id())),
  199. ),
  200. ), $this->_oTemplate);
  201. return $o->display($sTemplate);
  202. }
  203. return '';
  204. }
  205. public function servicePrivateProfileMsg()
  206. {
  207. $sMessage = '';
  208. $mixedContent = $this->_getContent();
  209. if($mixedContent) {
  210. list($iContentId, $aContentInfo) = $mixedContent;
  211. $sMessage = $this->checkAllowedView($aContentInfo);
  212. }
  213. else
  214. $sMessage = MsgBox(_t('_sys_access_denied_to_private_content'));
  215. return !$this->_bIsApi ? $sMessage : [bx_api_get_msg($sMessage, ['ext' => ['msg_type' => 'result']])];
  216. }
  217. public function serviceGetContentInfoById($iContentId)
  218. {
  219. return $this->_oDb->getContentInfoById((int)$iContentId);
  220. }
  221. public function serviceGetContentInfoByProfileId($iProfileId)
  222. {
  223. return $this->_oDb->getContentInfoByProfileId((int)$iProfileId);
  224. }
  225. public function serviceGetMenuAddonManageTools()
  226. {
  227. $CNF = &$this->_oConfig->CNF;
  228. $iNumTotal = $this->_oDb->getEntriesNumByParams();
  229. $iNum1 = $this->_oDb->getEntriesNumByParams([
  230. [
  231. 'key' => 'status',
  232. 'table' => 'sys_profiles',
  233. 'value' => BX_PROFILE_STATUS_PENDING,
  234. 'operator' => '='
  235. ]
  236. ]);
  237. $iNum2 = 0;
  238. if (isset($CNF['OBJECT_REPORTS'])){
  239. $iNum2 = $this->_oDb->getEntriesNumByParams([
  240. [
  241. 'key' => 'reports',
  242. 'value' => '0',
  243. 'operator' => '>'
  244. ]
  245. ]);
  246. }
  247. return array('counter1_value' => $iNum1, 'counter2_value' => $iNum2, 'counter3_value' => $iNumTotal, 'counter1_caption' => _t('_sys_menu_dashboard_manage_tools_addon_counter1_caption_profile_default'));
  248. }
  249. public function serviceGetMenuAddonManageToolsProfileStats($iProfileId = 0)
  250. {
  251. if(!$iProfileId)
  252. $iProfileId = bx_get_logged_profile_id();
  253. $aAccountInfo = BxDolProfileQuery::getInstance()->getAccountInfoByProfileId($iProfileId);
  254. if(empty($aAccountInfo) || !is_array($aAccountInfo))
  255. return 0;
  256. bx_import('SearchResult', $this->_aModule);
  257. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  258. $o = new $sClass();
  259. $o->fillFilters([
  260. 'account_id' => $aAccountInfo['id'],
  261. 'perofileStatus' => ''
  262. ]);
  263. $o->unsetPaginate();
  264. return $o->getNum();
  265. }
  266. public function serviceGetMenuAddonFavoritesProfileStats()
  267. {
  268. bx_import('SearchResult', $this->_aModule);
  269. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  270. $o = new $sClass('favorite', array('user' => bx_get_logged_profile_id()));
  271. $o->unsetPaginate();
  272. return $o->getNum();
  273. }
  274. public function serviceGetSubmenuObject ()
  275. {
  276. return $this->_oConfig->CNF['OBJECT_MENU_SUBMENU_VIEW_ENTRY'];
  277. }
  278. public function serviceGetMenuSetNameForMenuTrigger ($sMenuTriggerName)
  279. {
  280. $CNF = &$this->_oConfig->CNF;
  281. if (isset($CNF['TRIGGER_MENU_PROFILE_VIEW_SUBMENU']) && $CNF['TRIGGER_MENU_PROFILE_VIEW_SUBMENU'] == $sMenuTriggerName)
  282. return $CNF['OBJECT_MENU_SUBMENU_VIEW_ENTRY'];
  283. elseif (isset($CNF['TRIGGER_MENU_PROFILE_SNIPPET_META']) && $CNF['TRIGGER_MENU_PROFILE_SNIPPET_META'] == $sMenuTriggerName)
  284. return $CNF['OBJECT_MENU_SNIPPET_META'];
  285. else if (isset($CNF['TRIGGER_MENU_PROFILE_VIEW_ACTIONS']) && $CNF['TRIGGER_MENU_PROFILE_VIEW_ACTIONS'] == $sMenuTriggerName) {
  286. if(empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL']))
  287. return $CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY'];
  288. else
  289. return array($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY'], $CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL']);
  290. }
  291. return '';
  292. }
  293. public function serviceGetSnippetMenuVars($iProfileId, $bPublic = null, $aParams = [])
  294. {
  295. return $this->_oTemplate->getSnippetMenuVars($iProfileId, $bPublic, $aParams);
  296. }
  297. public function serviceGetPageObjectForPageTrigger ($sPageTriggerName)
  298. {
  299. if (isset($this->_oConfig->CNF['TRIGGER_PAGE_VIEW_ENTRY']) && $this->_oConfig->CNF['TRIGGER_PAGE_VIEW_ENTRY'] == $sPageTriggerName)
  300. return $this->_oConfig->CNF['OBJECT_PAGE_VIEW_ENTRY'];
  301. return '';
  302. }
  303. public function serviceProfilesSearch ($sTerm, $iLimit)
  304. {
  305. $aRet = array();
  306. $a = $this->_oDb->searchByTerm($sTerm, $iLimit);
  307. foreach ($a as $r) {
  308. $oProfile = BxDolProfile::getInstance($r['profile_id']);
  309. if (bx_is_api()) {
  310. $aData = $oProfile->getUnitAPI(0, ['template' => 'unit_wo_info']);
  311. $aRet[] = $aData['author_data'];
  312. }
  313. else{
  314. $aRet[] = array (
  315. 'label' => $this->serviceProfileName($r['content_id']),
  316. 'value' => $r['profile_id'],
  317. 'url' => $oProfile->getUrl(),
  318. 'thumb' => $oProfile->getThumb(),
  319. 'unit' => $oProfile->getUnit(0, ['template' => ['name' => 'unit_wo_info', 'size' => 'icon']])
  320. );
  321. }
  322. }
  323. return $aRet;
  324. }
  325. /**
  326. * @page service Service Calls
  327. * @section bx_base_profile Base Profile
  328. * @subsection bx_base_profile-general General
  329. * @subsubsection bx_base_profile-profile_unit_safe profile_unit_safe
  330. *
  331. * @code bx_srv('bx_persons', 'profile_unit_safe', [...]); @endcode
  332. *
  333. * Get profile unit
  334. * @param $iContentId content ID
  335. *
  336. * @see BxBaseModProfileModule::serviceProfileUnitSafe
  337. */
  338. /**
  339. * @ref bx_base_profile-profile_unit_safe "profile_unit_safe"
  340. */
  341. public function serviceProfileUnitSafe ($iContentId, $aParams = array())
  342. {
  343. unset($aParams['check_private_content']);
  344. return $this->serviceProfileUnit ($iContentId, $aParams);
  345. }
  346. public function serviceProfileUnit ($iContentId, $aParams = [])
  347. {
  348. $mixedContent = $this->_getContent($iContentId);
  349. if($mixedContent === false)
  350. return false;
  351. list($iContentId, $aContentInfo) = $mixedContent;
  352. $bCheckPrivateContent = isset($aParams['check_private_content']) ? (bool)$aParams['check_private_content'] : true;
  353. $aUnitTemplate = ['name' => 'unit.html', 'size' => false, 'vars' => []];
  354. if(!empty($aParams['template'])) {
  355. $mixedTemplate = $aParams['template'];
  356. unset($aParams['template']);
  357. if(is_string($mixedTemplate))
  358. $aUnitTemplate['name'] = $mixedTemplate . '.html';
  359. else if(is_array($mixedTemplate)) {
  360. if(!empty($mixedTemplate['name']))
  361. $aUnitTemplate['name'] = $mixedTemplate['name'] . '.html';
  362. if(!empty($mixedTemplate['size']))
  363. $aUnitTemplate['size'] = $mixedTemplate['size'];
  364. if(!empty($mixedTemplate['vars']))
  365. $aUnitTemplate['vars'] = $mixedTemplate['vars'];
  366. }
  367. }
  368. $aUnitParams = [];
  369. if(!empty($aParams))
  370. $aUnitParams = $aParams;
  371. return $this->_oTemplate->unit($aContentInfo, $bCheckPrivateContent, array_values($aUnitTemplate), $aUnitParams);
  372. }
  373. public function serviceProfileUnitApi ($iContentId, $aParams = [])
  374. {
  375. $mixedContent = $this->_getContent($iContentId);
  376. if($mixedContent === false)
  377. return false;
  378. list($iContentId, $aContentInfo) = $mixedContent;
  379. return $this->_oTemplate->unitAPI($aContentInfo, $aParams);
  380. }
  381. public function serviceHasImage ($iContentId)
  382. {
  383. $CNF = &$this->_oConfig->CNF;
  384. $mixedContent = $this->_getContent($iContentId, 'getContentInfoById');
  385. if($mixedContent === false)
  386. return false;
  387. list($iContentId, $aContentInfo) = $mixedContent;
  388. return !empty($aContentInfo[$CNF['FIELD_PICTURE']]);
  389. }
  390. public function serviceProfilePicture ($iContentId)
  391. {
  392. return $this->_serviceTemplateFunc('urlPicture', $iContentId);
  393. }
  394. public function serviceProfileAvatar ($iContentId)
  395. {
  396. return $this->_serviceTemplateFunc('urlAvatar', $iContentId);
  397. }
  398. public function serviceProfileAvatarBig ($iContentId)
  399. {
  400. return $this->_serviceTemplateFunc('urlAvatarBig', $iContentId);
  401. }
  402. public function serviceProfileCover ($iContentId)
  403. {
  404. return $this->_serviceTemplateFunc('urlCover', $iContentId);
  405. }
  406. public function serviceProfileUnitCover ($iContentId)
  407. {
  408. return $this->_serviceTemplateFunc('urlCoverUnit', $iContentId);
  409. }
  410. public function serviceProfileEditUrl ($iContentId)
  411. {
  412. return bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $this->_oConfig->CNF['URI_EDIT_ENTRY'] . '&id=' . $iContentId));
  413. }
  414. public function serviceProfileThumb ($iContentId)
  415. {
  416. return $this->_serviceTemplateFunc('urlThumb', $iContentId);
  417. }
  418. public function serviceProfileIcon ($iContentId)
  419. {
  420. return $this->_serviceTemplateFunc('urlIcon', $iContentId);
  421. }
  422. public function serviceProfileName ($iContentId)
  423. {
  424. if (!$iContentId)
  425. return false;
  426. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  427. if (!$aContentInfo)
  428. return false;
  429. $sDisplayName = $this->getProfileName($aContentInfo);
  430. /**
  431. * @hooks
  432. * @hookdef hook-bx_base_profile-profile_name '{module_name}', 'profile_name' - hook to override profile display name
  433. * - $unit_name - module name
  434. * - $action - equals `profile_name`
  435. * - $object_id - profile id
  436. * - $sender_id - not used
  437. * - $extra_params - array of additional params with the following array keys:
  438. * - `info` - [array] profile info array as key&value pairs
  439. * - `display_name` - [string] by ref, profile display name, can be overridden in hook processing
  440. * @hook @ref hook-bx_base_profile-profile_name
  441. */
  442. bx_alert($this->getName(), 'profile_name', $aContentInfo['profile_id'], 0, [
  443. 'info' => $aContentInfo,
  444. 'display_name' => &$sDisplayName
  445. ]);
  446. return $sDisplayName;
  447. }
  448. public function serviceProfileSettings ($iContentId)
  449. {
  450. if (!$iContentId)
  451. return false;
  452. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  453. if (!$aContentInfo)
  454. return false;
  455. if (isset($aContentInfo['settings']))
  456. return json_decode($aContentInfo['settings']);
  457. }
  458. public function serviceProfileSettingsSet ($iContentId, $oValue)
  459. {
  460. $CNF = $this->_oConfig->CNF;
  461. $this->_oDb->updateEntriesBy(['settings' => json_encode($oValue)], [$CNF['FIELD_ID'] => $iContentId]);
  462. }
  463. public function serviceProfileCreateUrl ($bAbsolute = true)
  464. {
  465. $CNF = $this->_oConfig->CNF;
  466. if(empty($CNF['URL_CREATE']))
  467. return false;
  468. return $bAbsolute ? bx_absolute_url(BxDolPermalinks::getInstance()->permalink($CNF['URL_CREATE'])) : $CNF['URL_CREATE'];
  469. }
  470. /**
  471. * @page service Service Calls
  472. * @section bx_base_profile Base Profile
  473. * @subsection bx_base_profile-general General
  474. * @subsubsection bx_base_profile-profile_url profile_url
  475. *
  476. * @code bx_srv('bx_persons', 'profile_url', [...]); @endcode
  477. *
  478. * Get profile URL
  479. * @param $iContentId content ID
  480. *
  481. * @see BxBaseModProfileModule::serviceProfileUrl
  482. */
  483. /**
  484. * @ref bx_base_profile-profile_url "profile_url"
  485. */
  486. public function serviceProfileUrl ($iContentId)
  487. {
  488. if (!$iContentId)
  489. return false;
  490. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  491. if (!$aContentInfo)
  492. return false;
  493. $CNF = $this->_oConfig->CNF;
  494. return bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]));
  495. }
  496. /**
  497. * @see iBxDolProfileService::serviceGetSpaceTitle
  498. */
  499. public function serviceGetSpaceTitle()
  500. {
  501. return _t('_sys_ps_space_title_friend');
  502. }
  503. /**
  504. * @see iBxDolProfileService::serviceGetParticipatingProfiles
  505. */
  506. public function serviceGetParticipatingProfiles($iProfileId, $aConnectionObjects = false)
  507. {
  508. if (false === $aConnectionObjects)
  509. $aConnectionObjects = array('sys_profiles_friends');
  510. $a = array();
  511. foreach ($aConnectionObjects as $sConnectionObject) {
  512. if (!($o = BxDolConnection::getObjectInstance($sConnectionObject)))
  513. continue;
  514. if (BX_CONNECTIONS_TYPE_MUTUAL == $o->getType())
  515. $a = array_merge($a, $o->getConnectedContentByType($iProfileId, $this->getName(), true));
  516. else
  517. $a = array_merge($a, $o->getConnectedContentByType($iProfileId, $this->getName()));
  518. }
  519. $aRet = array_unique($a);
  520. // the check for an ability to post in profile has been moved to BxDolPrivacy because we need to have an extended check
  521. // with an ability to check for extended roles taking into account the type of content which is going be posted/edited
  522. // so now this service returns just a fans, not filtered by an ability to post into an entry's context
  523. /*foreach ($a as $iConnectedProfileId) {
  524. if (!($oConnectedProfile = BxDolProfile::getInstance($iConnectedProfileId)))
  525. continue;
  526. if (CHECK_ACTION_RESULT_ALLOWED === bx_srv($oConnectedProfile->getModule(), 'check_allowed_post_in_profile', array($oConnectedProfile->getContentId(), $iProfileId)))
  527. $aRet[] = $iConnectedProfileId;
  528. }*/
  529. /**
  530. * @hooks
  531. * @hookdef hook-system-get_participating_profiles 'system', 'get_participating_profiles' - hook to override context participants list
  532. * - $unit_name - equals `system`
  533. * - $action - equals `get_participating_profiles`
  534. * - $object_id - context profile id
  535. * - $sender_id - not used
  536. * - $extra_params - array of additional params with the following array keys:
  537. * - `module` - [string] module name
  538. * - `profiles` - [array] by ref, a list of participating profiles ids, can be overridden in hook processing
  539. * @hook @ref hook-system-get_participating_profiles
  540. */
  541. bx_alert('system', 'get_participating_profiles', $iProfileId, false, [
  542. 'module' => $this->_oConfig->getName(),
  543. 'profiles' => &$aRet
  544. ]);
  545. return $aRet;
  546. }
  547. /**
  548. * Prepare fields from some universal set of fields to fields in particular profile module.
  549. * By default only 'name' and 'description' fields are supported.
  550. * After fields convertion it can be used in @see BxBaseModGeneralModule::serviceEntityAdd
  551. * @param $aFieldsProfile fields in soem universal format.
  552. * @return array which is ready to use for particular module
  553. */
  554. public function servicePrepareFields ($aFieldsProfile)
  555. {
  556. /**
  557. * @hooks
  558. * @hookdef hook-bx_base_profile-prepare_fields '{module_name}', 'prepare_fields' - hook to override prepared profile fields
  559. * - $unit_name - module name
  560. * - $action - equals `prepare_fields`
  561. * - $object_id - not used
  562. * - $sender_id - not used
  563. * - $extra_params - array of additional params with the following array keys:
  564. * - `fields_orig` - [array] original fields array as key&value pairs
  565. * - `fields_result` - [array] by ref, resulting fields array as key&value pairs, can be overridden in hook processing
  566. * @hook @ref hook-bx_base_profile-prepare_fields
  567. */
  568. bx_alert($this->getName(), 'prepare_fields', 0, 0, [
  569. 'fields_orig' => $aFieldsProfile,
  570. 'fields_result' => &$aFieldsProfile
  571. ]);
  572. return $aFieldsProfile;
  573. }
  574. protected function _servicePrepareFields ($aFieldsProfile, $aFieldsDefault, $aMap)
  575. {
  576. $aFieldsOrig = $aFieldsProfile;
  577. bx_import('BxDolPrivacy');
  578. $aFieldsDefault2 = array(
  579. 'allow_view_to' => BX_DOL_PG_ALL,
  580. 'allow_contact_to' => BX_DOL_PG_ALL,
  581. 'allow_post_to' => BX_DOL_PG_FRIENDS,
  582. );
  583. $aFieldsProfile = array_merge($aFieldsDefault2, $aFieldsDefault, $aFieldsProfile);
  584. foreach ($aMap as $k => $v) {
  585. if (isset($aFieldsProfile[$v]))
  586. $aFieldsProfile[$k] = $aFieldsProfile[$v];
  587. if ($k != $v && !isset($aMap[$v]))
  588. unset($aFieldsProfile[$v]);
  589. }
  590. /**
  591. * @hooks
  592. * @hookdef hook-bx_base_profile-prepare_fields '{module_name}', 'prepare_fields' - hook to override prepared profile fields
  593. * - $unit_name - module name
  594. * - $action - equals `prepare_fields`
  595. * - $object_id - not used
  596. * - $sender_id - not used
  597. * - $extra_params - array of additional params with the following array keys:
  598. * - `fields_orig` - [array] original fields array as key&value pairs
  599. * - `fields_result` - [array] by ref, resulting fields array as key&value pairs, can be overridden in hook processing
  600. * @hook @ref hook-bx_base_profile-prepare_fields
  601. */
  602. bx_alert($this->getName(), 'prepare_fields', 0, 0, [
  603. 'fields_orig' => $aFieldsOrig,
  604. 'fields_result' => &$aFieldsProfile
  605. ]);
  606. return $aFieldsProfile;
  607. }
  608. public function serviceFormsHelper ()
  609. {
  610. return parent::serviceFormsHelper ();
  611. }
  612. /**
  613. * @page service Service Calls
  614. * @section bx_base_profile Base Profile
  615. * @subsection bx_base_profile-forms Forms
  616. * @subsubsection bx_base_profile-entity_create entity_create
  617. *
  618. * @code bx_srv('bx_persons', 'entity_create', [...]); @endcode
  619. *
  620. * Get profile creation form
  621. * @param $sDisplay optional form display name
  622. *
  623. * @see BxBaseModProfileModule::serviceEntityCreate
  624. */
  625. /**
  626. * @ref bx_base_profile-entity_create "entity_create"
  627. */
  628. public function serviceEntityCreate ($sDisplay = false)
  629. {
  630. BxDolInformer::getInstance($this->_oTemplate)->setEnabled(false);
  631. return parent::serviceEntityCreate ($sDisplay);
  632. }
  633. public function serviceActAsProfile ()
  634. {
  635. return true;
  636. }
  637. /**
  638. * @page service Service Calls
  639. * @section bx_base_profile Base Profile
  640. * @subsection bx_base_profile-browse Browse
  641. * @subsubsection bx_base_profile-browse_recommended browse_recommended
  642. *
  643. * @code bx_srv('bx_persons', 'browse_recommended', [...]); @endcode
  644. *
  645. * Browse recommended profiles
  646. * @param $sUnitView optional, unit view, for example - showcase
  647. * @param $bEmptyMessage optional, display or not "empty" message when there is no content
  648. * @param $bAjaxPaginate optional, use AJAX paginate or not
  649. *
  650. * @see BxBaseModProfileModule::serviceBrowseRecommended
  651. */
  652. /**
  653. * @ref bx_base_profile-browse_recommended "browse_recommended"
  654. */
  655. public function serviceBrowseRecommended ($sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = true)
  656. {
  657. if (!isLogged())
  658. return '';
  659. return $this->_serviceBrowse ('recommended', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  660. }
  661. /**
  662. * @page service Service Calls
  663. * @section bx_base_profile Base Profile
  664. * @subsection bx_base_profile-browse Browse
  665. * @subsubsection bx_base_profile-browse_recent_profiles browse_recent_profiles
  666. *
  667. * @code bx_srv('bx_persons', 'browse_recent_profiles', [...]); @endcode
  668. *
  669. * Browse recently joined profiles
  670. * @param $bEmptyMessage optional, display or not "empty" message when there is no content
  671. * @param $bAjaxPaginate optional, use AJAX paginate or not
  672. *
  673. * @see BxBaseModProfileModule::serviceBrowseRecentProfiles
  674. */
  675. /**
  676. * @ref bx_base_profile-browse_recent_profiles "browse_recent_profiles"
  677. */
  678. public function serviceBrowseRecentProfiles ($bDisplayEmptyMsg = false, $bAjaxPaginate = true)
  679. {
  680. return $this->_serviceBrowse ('recent', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate);
  681. }
  682. /**
  683. * @page service Service Calls
  684. * @section bx_base_profile Base Profile
  685. * @subsection bx_base_profile-browse Browse
  686. * @subsubsection bx_base_profile-browse_active_profiles browse_active_profiles
  687. *
  688. * @code bx_srv('bx_persons', 'browse_active_profiles', [...]); @endcode
  689. *
  690. * Browse recently active profiles
  691. * @param $bEmptyMessage optional, display or not "empty" message when there is no content
  692. * @param $bAjaxPaginate optional, use AJAX paginate or not
  693. *
  694. * @see BxBaseModProfileModule::serviceBrowseActiveProfiles
  695. */
  696. /**
  697. * @ref bx_base_profile-browse_active_profiles "browse_active_profiles"
  698. */
  699. public function serviceBrowseActiveProfiles ($sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = false)
  700. {
  701. return $this->_serviceBrowse ('active', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  702. }
  703. /**
  704. * @page service Service Calls
  705. * @section bx_base_profile Base Profile
  706. * @subsection bx_base_profile-browse Browse
  707. * @subsubsection bx_base_profile-browse_familiar_profiles browse_familiar_profiles
  708. *
  709. * @code bx_srv('bx_persons', 'browse_familiar_profiles', [...]); @endcode
  710. *
  711. * Browse profiles you might be familiar with. By default using 'Profile Friends' connection.
  712. * @param $bEmptyMessage optional, display or not "empty" message when there is no content
  713. * @param $bAjaxPaginate optional, use AJAX paginate or not
  714. *
  715. * @see BxBaseModProfileModule::serviceBrowseFamiliarProfiles
  716. */
  717. /**
  718. * @ref bx_base_profile-browse_familiar_profiles "browse_familiar_profiles"
  719. */
  720. public function serviceBrowseFamiliarProfiles ($sConnection = '', $sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = false)
  721. {
  722. $aParams = [
  723. 'object' => 'sys_profiles_friends',
  724. 'profile' => bx_get_logged_profile_id(),
  725. ];
  726. if(!empty($sConnection)) {
  727. if(is_string($sConnection))
  728. $aParams['object'] = $sConnection;
  729. else if(is_array($sConnection))
  730. $aParams = array_merge($aParams, $sConnection);
  731. }
  732. if($sUnitView)
  733. $aParams['unit_view'] = $sUnitView;
  734. return $this->_serviceBrowse ('familiar', $aParams, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  735. }
  736. /**
  737. * @page service Service Calls
  738. * @section bx_base_profile Base Profile
  739. * @subsection bx_base_profile-browse Browse
  740. * @subsubsection bx_base_profile-browse_top_profiles browse_top_profiles
  741. *
  742. * @code bx_srv('bx_persons', 'browse_top_profiles', [...]); @endcode
  743. *
  744. * Browse top profiles
  745. * @param $bEmptyMessage optional, display or not "empty" message when there is no content
  746. * @param $bAjaxPaginate optional, use AJAX paginate or not
  747. *
  748. * @see BxBaseModProfileModule::serviceBrowseTopProfiles
  749. */
  750. /**
  751. * @ref bx_base_profile-browse_top_profiles "browse_top_profiles"
  752. */
  753. public function serviceBrowseTopProfiles ($bDisplayEmptyMsg = false, $bAjaxPaginate = false)
  754. {
  755. return $this->_serviceBrowse ('top', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate);
  756. }
  757. /**
  758. * @page service Service Calls
  759. * @section bx_base_profile Base Profile
  760. * @subsection bx_base_profile-browse Browse
  761. * @subsubsection bx_base_profile-browse_online_profiles browse_online_profiles
  762. *
  763. * @code bx_srv('bx_persons', 'browse_online_profiles', [...]); @endcode
  764. *
  765. * Browse online profiles
  766. * @param $bEmptyMessage optional, display or not "empty" message when there is no content
  767. * @param $bAjaxPaginate optional, use AJAX paginate or not
  768. *
  769. * @see BxBaseModProfileModule::serviceBrowseOnlineProfiles
  770. */
  771. /**
  772. * @ref bx_base_profile-browse_online_profiles "browse_online_profiles"
  773. */
  774. public function serviceBrowseOnlineProfiles ($bDisplayEmptyMsg = false, $bAjaxPaginate = false)
  775. {
  776. return $this->_serviceBrowse ('online', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate);
  777. }
  778. public function serviceBrowseConnections ($iProfileId, $sObjectConnections = 'sys_profiles_friends', $sConnectionsType = 'content', $iMutual = false, $iDesignBox = BX_DB_PADDING_DEF, $iProfileId2 = 0)
  779. {
  780. return $this->_serviceBrowse (
  781. 'connections', [
  782. 'object' => $sObjectConnections,
  783. 'type' => $sConnectionsType,
  784. 'mutual' => $iMutual,
  785. 'profile' => (int)$iProfileId,
  786. 'profile2' => (int)$iProfileId2
  787. ], $iDesignBox
  788. );
  789. }
  790. public function serviceBrowseRelationsQuick ($iProfileId, $sObjectConnections = 'sys_profiles_friends', $sConnectionsType = 'content', $iMutual = false, $iProfileId2 = 0)
  791. {
  792. // get connections object
  793. $oConnection = BxDolConnection::getObjectInstance($sObjectConnections);
  794. if (!$oConnection)
  795. return '';
  796. // set some vars
  797. $iStart = (int)bx_get('start');
  798. $iLimit = empty($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? 4 : getParam($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']);
  799. if (!$iLimit)
  800. $iLimit = 4;
  801. // get connections array
  802. bx_import('BxDolConnection');
  803. $aConnections = $oConnection->getConnectionsAsArrayExt($sConnectionsType, $iProfileId, $iProfileId2, $iMutual, $iStart, $iLimit + 1, BX_CONNECTIONS_ORDER_ADDED_DESC);
  804. if(empty($aConnections) || !is_array($aConnections))
  805. return '';
  806. $aResult = array();
  807. foreach($aConnections as $iProfile => $aConnection)
  808. $aResult[] = array(
  809. 'id' => $iProfile,
  810. 'info' => array(
  811. 'addon' => $oConnection->getRelationTranslation($aConnection['relation'])
  812. )
  813. );
  814. return $this->_serviceBrowseQuick($aResult, $iStart, $iLimit);
  815. }
  816. public function serviceBrowseConnectionsQuick ($iProfileId, $sObjectConnections = 'sys_profiles_friends', $sConnectionsType = 'content', $iMutual = false, $iProfileId2 = 0)
  817. {
  818. // get connections object
  819. $oConnection = BxDolConnection::getObjectInstance($sObjectConnections);
  820. if (!$oConnection)
  821. return '';
  822. // set some vars
  823. $iLimit = empty($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? 4 : getParam($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']);
  824. if (!$iLimit)
  825. $iLimit = 4;
  826. $iStart = (int)bx_get('start');
  827. // get connections array
  828. bx_import('BxDolConnection');
  829. $a = $oConnection->getConnectionsAsArray ($sConnectionsType, $iProfileId, $iProfileId2, $iMutual, (int)bx_get('start'), $iLimit + 1, BX_CONNECTIONS_ORDER_ADDED_DESC);
  830. if (!$a)
  831. return '';
  832. return $this->_serviceBrowseQuick($a, $iStart, $iLimit);
  833. }
  834. public function serviceBrowseConnectionsByType ($aParamsCnn, $aParamsBrs = array())
  835. {
  836. $sAll = 'all';
  837. $aParamsCnn['object'] = !empty($aParamsCnn['object']) ? $aParamsCnn['object'] : 'sys_profiles_friends';
  838. $aParamsCnn['type'] = !empty($aParamsCnn['type']) ? $aParamsCnn['type'] : 'content';
  839. $aParamsCnn['profile_id2'] = !empty($aParamsCnn['profile_id2']) ? (int)$aParamsCnn['profile_id2'] : 0;
  840. $aParamsCnn['mutual'] = isset($aParamsCnn['mutual']) ? $aParamsCnn['mutual'] : false;
  841. $oConnection = BxDolConnection::getObjectInstance($aParamsCnn['object']);
  842. if(!$oConnection)
  843. return '';
  844. $aSQLParts = $oConnection->getConnectionsAsSQLParts ($aParamsCnn['type'], 'sys_profiles', 'id', $aParamsCnn['profile_id'], $aParamsCnn['profile_id2'], $aParamsCnn['mutual']);
  845. $sType = !empty($aParamsBrs['type']) ? $aParamsBrs['type'] : $sAll;
  846. if(bx_get('type') !== false)
  847. $sType = bx_process_input(bx_get('type'));
  848. $iStart = (int)bx_get('start');
  849. $iLimitDefault = 4;
  850. $iLimit = !empty($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? getParam($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) : $iLimitDefault;
  851. if(!empty($aParamsBrs['per_page']))
  852. $iLimit = (int)$aParamsBrs['per_page'];
  853. if(!$iLimit)
  854. $iLimit = $iLimitDefault;
  855. $aProfiles = BxDolProfileQuery::getInstance()->getConnectedProfilesByType($aSQLParts, ($sType != $sAll ? $sType : ''), $iStart, $iLimit + 1);
  856. $mixedMenu = '';
  857. if(!isset($aParamsBrs['filter_menu']) || $aParamsBrs['filter_menu'] === true) {
  858. $aModules = array(
  859. array('name' => $sAll)
  860. );
  861. $aModules = array_merge($aModules, BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1)));
  862. $aMenuItems = array();
  863. foreach($aModules as $aModule)
  864. if($aModule['name'] == $sAll || BxDolRequest::serviceExists($aModule['name'], 'act_as_profile'))
  865. $aMenuItems[] = array(
  866. 'id' => $aModule['name'],
  867. 'name' => $aModule['name'],
  868. 'class' => '',
  869. 'link' => 'javascript:void(0)',
  870. 'onclick' => "return !loadDynamicBlockAutoPaginate(this, " . $iStart . ", " . $iLimit . ", " . bx_js_string(json_encode(array('type' => $aModule['name']))) . ");",
  871. 'target' => '_self',
  872. 'title' => _t('_' . $aModule['name']),
  873. 'active' => 1
  874. );
  875. if(!empty($aMenuItems)) {
  876. $mixedMenu = new BxTemplMenu(array('template' => 'menu_vertical.html', 'menu_id'=> $this->_oConfig->getName() . '-connections-by-type', 'menu_items' => $aMenuItems));
  877. $mixedMenu->setSelected('', $sType);
  878. }
  879. }
  880. return array(
  881. 'menu' => $mixedMenu,
  882. 'content' => $this->_serviceBrowseQuick(array_keys($aProfiles), $iStart, $iLimit, array('type' => $sType))
  883. );
  884. }
  885. /**
  886. * @page service Service Calls
  887. * @section bx_base_profile Base Profile
  888. * @subsection bx_base_profile-browse Browse
  889. * @subsubsection bx_base_profile-browse_by_acl browse_by_acl
  890. *
  891. * @code bx_srv('bx_persons', 'browse_by_acl', [...]); @endcode
  892. *
  893. * Browse profiles by membership(ACL) level
  894. * @param $mixedLevelId membership level, or array of membership levels
  895. * @param $iDesignBox optional, design box identifier
  896. *
  897. * @see BxBaseModProfileModule::serviceBrowseByAcl
  898. */
  899. /**
  900. * @ref bx_base_profile-browse_by_acl "browse_by_acl"
  901. */
  902. public function serviceBrowseByAcl ($mixedLevelId, $iDesignBox = BX_DB_PADDING_DEF)
  903. {
  904. return $this->_serviceBrowse (
  905. 'acl',
  906. array(
  907. 'level' => $mixedLevelId,
  908. ),
  909. $iDesignBox,
  910. true
  911. );
  912. }
  913. public function serviceEntityEditCover ($iContentId = 0)
  914. {
  915. return $this->_serviceEntityForm ('editDataForm', $iContentId, $this->_oConfig->CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT_COVER']);
  916. }
  917. /**
  918. * @page service Service Calls
  919. * @section bx_base_profile Base Profile
  920. * @subsection bx_base_profile-page_blocks Page Blocks
  921. * @subsubsection bx_base_profile-entity_cover entity_cover
  922. *
  923. * @code bx_srv('bx_persons', 'entity_cover', [...]); @endcode
  924. *
  925. * Get cover
  926. * @param $iContentId content ID
  927. *
  928. * @see BxBaseModProfileModule::serviceEntityCover
  929. */
  930. /**
  931. * @ref bx_base_general-entity_cover "entity_cover"
  932. */
  933. public function serviceEntityCover ($iContentId = 0, $aParams = [])
  934. {
  935. $mixedContent = $this->_getContent($iContentId);
  936. if($mixedContent === false)
  937. return false;
  938. list($iContentId, $aContentInfo) = $mixedContent;
  939. if(bx_is_api()){
  940. $aContentInfo['cover'] = $this->serviceGetCover($iContentId);
  941. $aContentInfo['image'] = $this->serviceGetThumb($iContentId);
  942. $CNF = $this->_oConfig->CNF;
  943. if(!empty($CNF['OBJECT_MENU_VIEW_ENTRY_META'])){
  944. $oMetaMenu = BxTemplMenu::getObjectInstance($CNF['OBJECT_MENU_VIEW_ENTRY_META']);
  945. $aContentInfo['meta_menu'] = $oMetaMenu->getCodeAPI();
  946. }
  947. if(!empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY'])){
  948. $oActionMenu = BxTemplMenu::getObjectInstance($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL']);
  949. $aContentInfo['actions_menu'] = $oActionMenu->getCodeAPI();
  950. }
  951. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->MODULE);
  952. $aContentInfo['profile'] = BxDolProfile::getData($this->_aProfileInfo['id'], [
  953. 'get_avatar' => 'getAvatarBig',
  954. 'with_info' => false
  955. ]);
  956. return [bx_api_get_block('entity_cover', $aContentInfo)];
  957. }
  958. return $this->_oTemplate->getBlockCover($aContentInfo, $aParams);
  959. }
  960. /**
  961. * Entry comments
  962. */
  963. public function serviceEntityCommentsByProfile ($iProfileId)
  964. {
  965. $CNF = &$this->_oConfig->CNF;
  966. if(empty($CNF['OBJECT_COMMENTS']))
  967. return '';
  968. $oProfile = BxDolProfile::getInstance($iProfileId);
  969. if(!$oProfile)
  970. return '';
  971. return $this->_entityComments($CNF['OBJECT_COMMENTS'], $oProfile->getContentId());
  972. }
  973. /**
  974. * Entry social sharing block
  975. */
  976. public function serviceEntitySocialSharing ($mixedContent = false, $aParams = array())
  977. {
  978. if(!empty($mixedContent)) {
  979. if(!is_array($mixedContent))
  980. $mixedContent = array((int)$mixedContent, array());
  981. }
  982. else {
  983. $mixedContent = $this->_getContent();
  984. if($mixedContent === false)
  985. return false;
  986. }
  987. list($iContentId, $aContentInfo) = $mixedContent;
  988. return parent::serviceEntitySocialSharing(array($iContentId, $aContentInfo), array(
  989. 'id_thumb' => !empty($CNF['FIELD_PICTURE']) && !empty($aContentInfo[$CNF['FIELD_PICTURE']]) ? $aContentInfo[$CNF['FIELD_PICTURE']] : 0,
  990. ));
  991. }
  992. public function serviceProfileMembership ($iContentId = 0)
  993. {
  994. $mixedContent = $this->_getContent($iContentId);
  995. if($mixedContent === false)
  996. return false;
  997. list($iContentId, $aContentInfo) = $mixedContent;
  998. return BxDolAcl::getInstance()->getProfileMembership($aContentInfo['profile_id']);
  999. }
  1000. public function serviceProfileFriends ($iContentId = 0)
  1001. {
  1002. $mixedContent = $this->_getContent($iContentId);
  1003. if($mixedContent === false)
  1004. return false;
  1005. list($iContentId, $aContentInfo) = $mixedContent;
  1006. bx_import('BxDolConnection');
  1007. $s = $this->serviceBrowseConnectionsQuick ($aContentInfo['profile_id'], 'sys_profiles_friends', BX_CONNECTIONS_CONTENT_TYPE_CONTENT, true);
  1008. if (!$s)
  1009. return MsgBox(_t('_sys_txt_empty'));
  1010. return $s;
  1011. }
  1012. public function serviceProfileFriendsMutual ($iContentId = 0)
  1013. {
  1014. $mixedContent = $this->_getContent($iContentId);
  1015. if($mixedContent === false)
  1016. return false;
  1017. list($iContentId, $aContentInfo) = $mixedContent;
  1018. $iViewer = bx_get_logged_profile_id();
  1019. $iOwner = (int)$aContentInfo['profile_id'];
  1020. if($iViewer == $iOwner)
  1021. return false;
  1022. bx_import('BxDolConnection');
  1023. $s = $this->serviceBrowseConnectionsQuick ($iOwner, 'sys_profiles_friends', BX_CONNECTIONS_CONTENT_TYPE_COMMON, true, $iViewer);
  1024. if(!$s)
  1025. return MsgBox(_t('_sys_txt_empty'));
  1026. return $s;
  1027. }
  1028. public function serviceProfileSubscriptions ($iContentId = 0, $aParams = array())
  1029. {
  1030. $mixedContent = $this->_getContent($iContentId);
  1031. if($mixedContent === false)
  1032. return false;
  1033. list($iContentId, $aContentInfo) = $mixedContent;
  1034. bx_import('BxDolConnection');
  1035. $aResult = $this->serviceBrowseConnectionsByType(array(
  1036. 'profile_id' => $aContentInfo['profile_id'],
  1037. 'object' => 'sys_profiles_subscriptions',
  1038. 'type' => BX_CONNECTIONS_CONTENT_TYPE_CONTENT
  1039. ), array(
  1040. 'type' => isset($aParams['type']) ? $aParams['type'] : '',
  1041. 'filter_menu' => isset($aParams['filter_menu']) ? $aParams['filter_menu'] : true,
  1042. ));
  1043. if(empty($aResult['content']))
  1044. $aResult['content'] = MsgBox(_t('_sys_txt_empty'));
  1045. return $aResult;
  1046. }
  1047. public function serviceProfileSubscribedMe ($iContentId = 0)
  1048. {
  1049. $mixedContent = $this->_getContent($iContentId);
  1050. if($mixedContent === false)
  1051. return false;
  1052. list($iContentId, $aContentInfo) = $mixedContent;
  1053. bx_import('BxDolConnection');
  1054. $s = $this->serviceBrowseConnectionsQuick ($aContentInfo['profile_id'], 'sys_profiles_subscriptions', BX_CONNECTIONS_CONTENT_TYPE_INITIATORS);
  1055. if (!$s)
  1056. return MsgBox(_t('_sys_txt_empty'));
  1057. return $s;
  1058. }
  1059. public function serviceProfileRelations ($iContentId = 0, $aParams = array())
  1060. {
  1061. if(!BxDolRelation::isEnabled())
  1062. return false;
  1063. $mixedContent = $this->_getContent($iContentId);
  1064. if($mixedContent === false)
  1065. return false;
  1066. list($iContentId, $aContentInfo) = $mixedContent;
  1067. bx_import('BxDolConnection');
  1068. $s = $this->serviceBrowseRelationsQuick ($aContentInfo['profile_id'], 'sys_profiles_relations', BX_CONNECTIONS_CONTENT_TYPE_CONTENT, 1);
  1069. if (!$s)
  1070. return MsgBox(_t('_sys_txt_empty'));
  1071. return $s;
  1072. }
  1073. public function serviceProfileRelatedMe ($iContentId = 0)
  1074. {
  1075. if(!BxDolRelation::isEnabled())
  1076. return false;
  1077. $mixedContent = $this->_getContent($iContentId);
  1078. if($mixedContent === false)
  1079. return false;
  1080. list($iContentId, $aContentInfo) = $mixedContent;
  1081. bx_import('BxDolConnection');
  1082. $s = $this->serviceBrowseRelationsQuick ($aContentInfo['profile_id'], 'sys_profiles_relations', BX_CONNECTIONS_CONTENT_TYPE_INITIATORS, 1);
  1083. if (!$s)
  1084. return MsgBox(_t('_sys_txt_empty'));
  1085. return $s;
  1086. }
  1087. /**
  1088. * check enabled profile activation letter
  1089. */
  1090. public function serviceIsEnableProfileActivationLetter()
  1091. {
  1092. $CNF = &$this->_oConfig->CNF;
  1093. return isset($CNF['PARAM_ENABLE_ACTIVATION_LETTER']) ? (bool)getParam($CNF['PARAM_ENABLE_ACTIVATION_LETTER']) : true;
  1094. }
  1095. public function serviceIsEnableRelations()
  1096. {
  1097. if(!BxDolRelation::isEnabled())
  1098. return false;
  1099. $sModule = $this->_oConfig->getName();
  1100. $oRelations = BxDolConnection::getObjectInstance('sys_profiles_relations');
  1101. return $oRelations->isRelationAvailableWithProfile($sModule) || $oRelations->isRelationAvailableFromProfile($sModule);
  1102. }
  1103. /**
  1104. * For internal usage only.
  1105. */
  1106. public function serviceDeleteEntityService ($iContentId, $bDeleteWithContent = false)
  1107. {
  1108. return parent::serviceDeleteEntity ($iContentId, 'deleteDataService');
  1109. }
  1110. /**
  1111. * Data for Notifications module
  1112. */
  1113. public function serviceGetNotificationsData()
  1114. {
  1115. $a = parent::serviceGetNotificationsData();
  1116. $sModule = $this->_aModule['name'];
  1117. $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');
  1118. $a['settings'][] = array('group' => 'timeline_post', 'unit' => $sModule, 'action' => 'timeline_post_common', 'types' => array('follow_member'));
  1119. $a['alerts'][] = array('unit' => $sModule, 'action' => 'timeline_post_common');
  1120. return $a;
  1121. }
  1122. public function serviceGetNotificationsPost($aEvent)
  1123. {
  1124. $aResult = parent::serviceGetNotificationsVote($aEvent);
  1125. if(empty($aResult) || !is_array($aResult) || !$this->serviceActAsProfile())
  1126. return $aResult;
  1127. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$aEvent['object_id'], $this->_oConfig->getName());
  1128. if($oProfile !== false)
  1129. $aResult['entry_author'] = $oProfile->id();
  1130. return $aResult;
  1131. }
  1132. public function serviceGetNotificationsVote($aEvent)
  1133. {
  1134. $aResult = parent::serviceGetNotificationsVote($aEvent);
  1135. if(empty($aResult) || !is_array($aResult) || !$this->serviceActAsProfile())
  1136. return $aResult;
  1137. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$aEvent['object_id'], $this->_oConfig->getName());
  1138. if($oProfile !== false)
  1139. $aResult['entry_author'] = $oProfile->id();
  1140. return $aResult;
  1141. }
  1142. /**
  1143. * Notification about new member requst in the group
  1144. */
  1145. public function serviceGetNotificationsTimelinePostCommon($aEvent)
  1146. {
  1147. $CNF = &$this->_oConfig->CNF;
  1148. $iContentId = (int)$aEvent['object_id'];
  1149. $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  1150. if(!$oGroupProfile)
  1151. return [];
  1152. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1153. if(empty($aContentInfo) || !is_array($aContentInfo))
  1154. return [];
  1155. $aSubcontentInfo = BxDolService::call('bx_timeline', 'get_info', array((int)$aEvent['subobject_id'], false));
  1156. if(empty($aSubcontentInfo) || !is_array($aSubcontentInfo))
  1157. return [];
  1158. $sEntrySummary = isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '';
  1159. $sSubentryUrl = bx_absolute_url(str_replace(BX_DOL_URL_ROOT, '', BxDolService::call('bx_timeline', 'get_link', array((int)$aEvent['subobject_id']))), '{bx_url_root}');
  1160. $sSubentrySample = $aSubcontentInfo['title'];
  1161. if(empty($sSubentrySample))
  1162. $sSubentrySample = strmaxtextlen($aSubcontentInfo['description'], 20, '...');
  1163. $sSubentrySummary = $aSubcontentInfo['description'];
  1164. return [
  1165. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1166. 'entry_url' => bx_absolute_url(str_replace(BX_DOL_URL_ROOT, '', $oGroupProfile->getUrl()), '{bx_url_root}'),
  1167. 'entry_caption' => $oGroupProfile->getDisplayName(),
  1168. 'entry_summary' => $sEntrySummary,
  1169. 'entry_author' => $oGroupProfile->id(),
  1170. 'subentry_sample' => $sSubentrySample,
  1171. 'subentry_url' => $sSubentryUrl,
  1172. 'subentry_summary' => $sSubentrySummary,
  1173. 'lang_key' => $CNF['T']['txt_ntfs_timeline_post_common'],
  1174. ];
  1175. }
  1176. /**
  1177. * Data for Timeline module
  1178. */
  1179. public function serviceGetTimelineData()
  1180. {
  1181. $CNF = &$this->_oConfig->CNF;
  1182. $sModule = $this->_aModule['name'];
  1183. $aAlerts = array();
  1184. $aHandlers = array();
  1185. if(!empty($CNF['FIELD_PICTURE'])) {
  1186. $aAlerts = array_merge($aAlerts, array(
  1187. array('unit' => $sModule, 'action' => 'profile_picture_changed'),
  1188. array('unit' => $sModule, 'action' => 'profile_picture_deleted')
  1189. ));
  1190. $aHandlers = array_merge($aHandlers, array(
  1191. 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' => ''),
  1192. array('group' => $sModule . '_profile_picture', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'profile_picture_deleted')
  1193. ));
  1194. }
  1195. if(!empty($CNF['FIELD_COVER'])) {
  1196. $aAlerts = array_merge($aAlerts, array(
  1197. array('unit' => $sModule, 'action' => 'profile_cover_changed'),
  1198. array('unit' => $sModule, 'action' => 'profile_cover_deleted')
  1199. ));
  1200. $aHandlers = array_merge($aHandlers, array(
  1201. 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' => ''),
  1202. array('group' => $sModule . '_profile_cover', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'profile_cover_deleted')
  1203. ));
  1204. }
  1205. $aResult = array();
  1206. if(!empty($aAlerts) && !empty($aHandlers))
  1207. $aResult = array(
  1208. 'handlers' => $aHandlers,
  1209. 'alerts' => $aAlerts
  1210. );
  1211. return $aResult;
  1212. }
  1213. /**
  1214. * Entry post for Timeline module
  1215. */
  1216. public function serviceGetTimelineProfilePicture($aEvent, $aBrowseParams = [])
  1217. {
  1218. $aResult = $this->_serviceGetTimelineProfileImage($aEvent, $aBrowseParams, [
  1219. 'stg' => 'OBJECT_STORAGE',
  1220. 'trans' => ['OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_AVATAR'],
  1221. 'trans_orig' => ['OBJECT_IMAGES_TRANSCODER_PICTURE', 'OBJECT_IMAGES_TRANSCODER_GALLERY'],
  1222. 'txt_ss' => 'txt_sample_pp_single',
  1223. 'txt_sswa' => 'txt_sample_pp_single_with_article',
  1224. 'txt_sa' => 'txt_sample_pi_action',
  1225. 'txt_sau' => 'txt_sample_pi_action_user'
  1226. ]);
  1227. if($aResult !== false)
  1228. $aResult['allowed_view'] = ['module' => $this->_oConfig->getName(), 'method' => 'get_timeline_profile_picture_allowed_view'];
  1229. return $aResult;
  1230. }
  1231. public function serviceGetTimelineProfilePictureAllowedView($aEvent)
  1232. {
  1233. return $this->_serviceGetTimelineProfileImageAllowedView($aEvent);
  1234. }
  1235. public function serviceGetTimelineProfileCover($aEvent, $aBrowseParams = [])
  1236. {
  1237. $aResult = $this->_serviceGetTimelineProfileImage($aEvent, $aBrowseParams, [
  1238. 'stg' => 'OBJECT_STORAGE_COVER',
  1239. 'trans' => ['OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_COVER_THUMB'],
  1240. 'trans_orig' => ['OBJECT_IMAGES_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_GALLERY'],
  1241. 'txt_ss' => 'txt_sample_pc_single',
  1242. 'txt_sswa' => 'txt_sample_pc_single_with_article',
  1243. 'txt_sa' => 'txt_sample_pi_action',
  1244. 'txt_sau' => 'txt_sample_pi_action_user'
  1245. ]);
  1246. if($aResult !== false)
  1247. $aResult['allowed_view'] = ['module' => $this->_oConfig->getName(), 'method' => 'get_timeline_profile_cover_allowed_view'];
  1248. return $aResult;
  1249. }
  1250. public function serviceGetTimelineProfileCoverAllowedView($aEvent)
  1251. {
  1252. return $this->_serviceGetTimelineProfileImageAllowedView($aEvent);
  1253. }
  1254. public function serviceGetMenuItemTitleByConnection($sConnection, $sAction, $iContentProfileId, $iInitiatorProfileId = 0)
  1255. {
  1256. return $this->getMenuItemTitleByConnection($sConnection, $sAction, $iContentProfileId, $iInitiatorProfileId);
  1257. }
  1258. // ====== PERMISSION METHODS
  1259. /**
  1260. * @see iBxDolProfileService::serviceCheckAllowedProfileView
  1261. */
  1262. public function serviceCheckAllowedProfileView($iContentId)
  1263. {
  1264. return $this->serviceCheckAllowedWithContent('View', $iContentId);
  1265. }
  1266. /**
  1267. * @see iBxDolProfileService::serviceCheckAllowedProfileContact
  1268. */
  1269. public function serviceCheckAllowedProfileContact($iContentId)
  1270. {
  1271. return $this->serviceCheckAllowedWithContent('Contact', $iContentId);
  1272. }
  1273. /**
  1274. * @see iBxDolProfileService::serviceCheckAllowedPostInProfile
  1275. */
  1276. public function serviceCheckAllowedPostInProfile($iContentId, $sPostModule = '')
  1277. {
  1278. $CNF = &$this->_oConfig->CNF;
  1279. if(!empty($CNF['FIELD_ALLOW_VIEW_TO']) && getParam('sys_treat_cxt_in_cxt_as_cnt') == 'on') {
  1280. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1281. if($aContentInfo && isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) && (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] < 0)
  1282. return _t('_sys_txt_access_denied');
  1283. }
  1284. // for groups based profiles we do have a Role permissions which have a higher priority than the site-wide permissions.
  1285. if (method_exists($this, 'isAllowedModuleActionByProfile')) {
  1286. $bResult = $this->isAllowedModuleActionByProfile($iContentId, $sPostModule, 'post');
  1287. // if a profile is having a role and a role is having permissions set then it overrides the site-wide setting.
  1288. if ($bResult !== NULL) return $bResult;
  1289. }
  1290. return $this->serviceCheckAllowedWithContent('Post', $iContentId);
  1291. }
  1292. /**
  1293. * @see iBxDolProfileService::serviceCheckAllowedModuleActionInProfile
  1294. */
  1295. public function serviceCheckAllowedModuleActionInProfile($iContentId, $sPostModule, $sActionName)
  1296. {
  1297. if (method_exists($this, 'isAllowedModuleActionByProfile')) {
  1298. $bResult = $this->isAllowedModuleActionByProfile($iContentId, $sPostModule, $sActionName);
  1299. if ($bResult !== NULL) return $bResult;
  1300. }
  1301. return _t('_Access denied');
  1302. }
  1303. /**
  1304. * @see iBxDolProfileService::serviceCheckSpacePrivacy
  1305. */
  1306. public function serviceCheckSpacePrivacy($iContentId)
  1307. {
  1308. return $this->serviceCheckAllowedProfileView($iContentId);
  1309. }
  1310. /**
  1311. * Check if the profile can be viewed.
  1312. *
  1313. * NOTE. This service should be used if it's needed to pass some specific values in
  1314. * $isPerformAction and $iProfileId parameters, otherwise it's recommended to use
  1315. * BxBaseModProfileModule::serviceCheckAllowedProfileView service method or
  1316. * BxDolProfile::checkAllowedProfileView method.
  1317. *
  1318. * @param type $aDataEntry - entry which the action will be performed for
  1319. * @param type $isPerformAction - perform or just check the action
  1320. * @param type $iProfileId - performer's profile ID
  1321. * @return integer - one of CHECK_ACTION_RESULT_XXX constants.
  1322. */
  1323. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  1324. {
  1325. if (!$iProfileId)
  1326. $iProfileId = $this->_iProfileId;
  1327. if(empty($aDataEntry) || !is_array($aDataEntry))
  1328. return _t('_sys_txt_not_found');
  1329. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  1330. if ($oProfile && $oProfile->id() == $iProfileId)
  1331. return CHECK_ACTION_RESULT_ALLOWED;
  1332. return parent::serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  1333. }
  1334. /**
  1335. * Check if posting (comment, post in Timeline) is available.
  1336. *
  1337. * NOTE. This service should be used if it's needed to pass some specific values in
  1338. * $isPerformAction and $iProfileId parameters, otherwise it's recommended to use
  1339. * BxBaseModProfileModule::serviceCheckAllowedPostInProfile service method or
  1340. * BxDolProfile::checkAllowedPostInProfile method.
  1341. *
  1342. * @param type $aDataEntry - entry which the action will be performed for
  1343. * @param type $isPerformAction - perform or just check the action
  1344. * @param type $iProfileId - performer's profile ID
  1345. * @return integer - one of CHECK_ACTION_RESULT_XXX constants.
  1346. */
  1347. public function serviceCheckAllowedPostForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  1348. {
  1349. $CNF = &$this->_oConfig->CNF;
  1350. if(!$iProfileId)
  1351. $iProfileId = $this->_iProfileId;
  1352. // check is view allowed
  1353. if(($mixedResult = $this->serviceCheckAllowedViewForProfile($aDataEntry, $isPerformAction, $iProfileId)) !== CHECK_ACTION_RESULT_ALLOWED)
  1354. return $mixedResult;
  1355. // moderator and owner always have access
  1356. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->getName());
  1357. if(($oProfile && $oProfile->id() == $iProfileId) || $this->_isModerator($isPerformAction))
  1358. return CHECK_ACTION_RESULT_ALLOWED;
  1359. // check privacy
  1360. if(!empty($CNF['OBJECT_PRIVACY_POST'])) {
  1361. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_POST']);
  1362. if($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  1363. return _t('_sys_access_denied_to_private_content');
  1364. }
  1365. // check alert to allow custom checks
  1366. $mixedResult = null;
  1367. /**
  1368. * @hooks
  1369. * @hookdef hook-system-check_allowed_post 'system', 'check_allowed_post' - hook to override the result of checking whether 'post' action is allowed or not to specified profile
  1370. * It's equivalent to @ref hook-system-check_allowed_view
  1371. * @hook @ref hook-system-check_allowed_post
  1372. */
  1373. bx_alert('system', 'check_allowed_post', 0, 0, [
  1374. 'module' => $this->getName(),
  1375. 'content_info' => $aDataEntry,
  1376. 'profile_id' => $iProfileId,
  1377. 'override_result' => &$mixedResult
  1378. ]);
  1379. if($mixedResult !== null)
  1380. return $mixedResult;
  1381. return CHECK_ACTION_RESULT_ALLOWED;
  1382. }
  1383. /**
  1384. * Check if profile can be contacted.
  1385. *
  1386. * NOTE. This service should be used if it's needed to pass some specific values in
  1387. * $isPerformAction and $iProfileId parameters, otherwise it's recommended to use
  1388. * BxBaseModProfileModule::serviceCheckAllowedProfileContact service method or
  1389. * BxDolProfile::checkAllowedProfileContact method.
  1390. *
  1391. * @param type $aDataEntry - entry which the action will be performed for
  1392. * @param type $isPerformAction - perform or just check the action
  1393. * @param type $iProfileId - performer's profile ID
  1394. * @return integer - one of CHECK_ACTION_RESULT_XXX constants.
  1395. */
  1396. public function serviceCheckAllowedContactForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  1397. {
  1398. $mixedResult = $this->_serviceCheckAllowedContactForProfile($aDataEntry, $isPerformAction, $iProfileId);
  1399. /**
  1400. * @hooks
  1401. * @hookdef hook-system-check_allowed_contact 'system', 'check_allowed_contact' - hook to override the result of checking whether 'contact' action is allowed or not to specified profile
  1402. * It's equivalent to @ref hook-system-check_allowed_view
  1403. * @hook @ref hook-system-check_allowed_contact
  1404. */
  1405. bx_alert('system', 'check_allowed_contact', 0, 0, [
  1406. 'module' => $this->getName(),
  1407. 'content_info' => $aDataEntry,
  1408. 'profile_id' => $iProfileId,
  1409. 'override_result' => &$mixedResult
  1410. ]);
  1411. return $mixedResult;
  1412. }
  1413. public function serviceSetViewProfileCover($oPage, $aProfileInfo)
  1414. {
  1415. $this->_oTemplate->setCover($oPage,$aProfileInfo);
  1416. }
  1417. /**
  1418. * Returns list of members by mode with limited number of records for React Jot
  1419. * @param string $sMode
  1420. * @param int $iStart
  1421. * @param int $iPerPage
  1422. * @return mixed
  1423. */
  1424. public function serviceGetMembers($sMode = 'active', $iStart = 0, $iPerPage = 10){
  1425. bx_import('SearchResult', $this->_aModule);
  1426. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  1427. $o = new $sClass($sMode);
  1428. $o -> aCurrent['paginate'] = array('perPage' => $iPerPage, 'forceStart' => $iStart);
  1429. return $o -> getSearchData();
  1430. }
  1431. /**
  1432. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1433. */
  1434. public function checkAllowedAdd ($isPerformAction = false)
  1435. {
  1436. $oAccount = BxDolAccount::getInstance();
  1437. if (!$oAccount || ($this->serviceActAsProfile() && $oAccount->isProfilesLimitReached()))
  1438. return _t('_sys_txt_access_denied');
  1439. return parent::checkAllowedAdd ($isPerformAction);
  1440. }
  1441. /**
  1442. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1443. */
  1444. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  1445. {
  1446. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
  1447. }
  1448. /**
  1449. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1450. */
  1451. public function checkAllowedViewProfileImage ($aDataEntry, $isPerformAction = false)
  1452. {
  1453. $CNF = &$this->_oConfig->CNF;
  1454. // check privacy
  1455. if (empty($CNF['OBJECT_PRIVACY_VIEW']))
  1456. return CHECK_ACTION_RESULT_ALLOWED;
  1457. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  1458. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']]) && !$oPrivacy->isPartiallyVisible($aDataEntry[$CNF['FIELD_ALLOW_VIEW_TO']]))
  1459. return _t('_sys_access_denied_to_private_content');
  1460. return CHECK_ACTION_RESULT_ALLOWED;
  1461. }
  1462. /**
  1463. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1464. */
  1465. public function checkAllowedViewCoverImage ($aDataEntry, $isPerformAction = false)
  1466. {
  1467. return $this->checkAllowedViewProfileImage($aDataEntry);
  1468. }
  1469. /**
  1470. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1471. */
  1472. public function checkAllowedPost ($aDataEntry, $isPerformAction = false)
  1473. {
  1474. return $this->serviceCheckAllowedPostForProfile ($aDataEntry, $isPerformAction);
  1475. }
  1476. /**
  1477. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1478. */
  1479. public function checkAllowedContact ($aDataEntry, $isPerformAction = false)
  1480. {
  1481. return $this->serviceCheckAllowedContactForProfile ($aDataEntry, $isPerformAction);
  1482. }
  1483. /**
  1484. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1485. */
  1486. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  1487. {
  1488. if(empty($aDataEntry) || !is_array($aDataEntry))
  1489. return _t('_sys_txt_not_found');
  1490. // moderator always has access
  1491. if ($this->_isModerator($isPerformAction))
  1492. return CHECK_ACTION_RESULT_ALLOWED;
  1493. // owner (checked by account instead of author!) always have access
  1494. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name']);
  1495. if (!$oProfile)
  1496. return _t('_sys_txt_error_occured');
  1497. if ($oProfile->id() == $this->_iProfileId || $oProfile->getAccountId() == $this->_iAccountId)
  1498. return CHECK_ACTION_RESULT_ALLOWED;
  1499. return _t('_sys_txt_access_denied');
  1500. }
  1501. /**
  1502. * Check if user can change cover image
  1503. */
  1504. public function checkAllowedChangeCover ($aDataEntry, $isPerformAction = false)
  1505. {
  1506. // moderator always has access
  1507. if ($this->_isModerator($isPerformAction))
  1508. return CHECK_ACTION_RESULT_ALLOWED;
  1509. // owner (checked by account instead of author!) always have access
  1510. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name']);
  1511. if (!$oProfile)
  1512. return _t('_sys_txt_error_occured');
  1513. if ($oProfile->id() == $this->_iProfileId || $oProfile->getAccountId() == $this->_iAccountId)
  1514. return CHECK_ACTION_RESULT_ALLOWED;
  1515. return _t('_sys_txt_access_denied');
  1516. }
  1517. /**
  1518. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1519. */
  1520. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  1521. {
  1522. // moderator always has access
  1523. if ($this->_isModerator($isPerformAction))
  1524. return CHECK_ACTION_RESULT_ALLOWED;
  1525. // owner (checked by account instead of author!) always have access
  1526. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  1527. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name'], $isPerformAction);
  1528. if (!$oProfile)
  1529. return _t('_sys_txt_error_occured');
  1530. if (($oProfile->id() == $this->_iProfileId || $oProfile->getAccountId() == $this->_iAccountId) && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  1531. return CHECK_ACTION_RESULT_ALLOWED;
  1532. return _t('_sys_txt_access_denied');
  1533. }
  1534. /**
  1535. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1536. */
  1537. public function checkAllowedViewMoreMenu (&$aDataEntry, $isPerformAction = false)
  1538. {
  1539. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']);
  1540. if (!$oMenu || !$oMenu->getCode())
  1541. return _t('_sys_txt_access_denied');
  1542. return CHECK_ACTION_RESULT_ALLOWED;
  1543. }
  1544. /**
  1545. * Compose differs from Contact. For example, a user should NOT be able to start conversation (compose)
  1546. * with himself but he should be able to view conversation page where he is one of the participants.
  1547. *
  1548. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1549. */
  1550. public function checkAllowedCompose(&$aDataEntry, $isPerformAction = false)
  1551. {
  1552. $CNF = &$this->_oConfig->CNF;
  1553. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->getName());
  1554. if($oProfile && $oProfile->id() == $this->_iProfileId)
  1555. return _t('_sys_txt_access_denied');
  1556. return $this->checkAllowedContact($aDataEntry, $isPerformAction);
  1557. }
  1558. /**
  1559. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1560. */
  1561. public function checkAllowedFriendAdd (&$aDataEntry, $isPerformAction = false)
  1562. {
  1563. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, ['sys_profiles_friends', 'checkAllowedAddConnection'], false, false);
  1564. }
  1565. /**
  1566. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1567. */
  1568. public function checkAllowedFriendRemove (&$aDataEntry, $isPerformAction = false)
  1569. {
  1570. if (CHECK_ACTION_RESULT_ALLOWED === $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, ['sys_profiles_friends', 'checkAllowedRemoveConnection'], false, true, true))
  1571. return CHECK_ACTION_RESULT_ALLOWED;
  1572. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, ['sys_profiles_friends', 'checkAllowedRemoveConnection'], false, true, false);
  1573. }
  1574. /**
  1575. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1576. */
  1577. public function checkAllowedRelationAdd (&$aDataEntry, $isPerformAction = false)
  1578. {
  1579. $sResult = _t('_sys_txt_access_denied');
  1580. if(!BxDolRelation::isEnabled())
  1581. return $sResult;
  1582. if(($sMsg = $this->checkAllowedView($aDataEntry)) !== CHECK_ACTION_RESULT_ALLOWED)
  1583. return $sMsg;
  1584. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_relations', false, false);
  1585. }
  1586. /**
  1587. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1588. */
  1589. public function checkAllowedRelationRemove (&$aDataEntry, $isPerformAction = false)
  1590. {
  1591. $sResult = _t('_sys_txt_access_denied');
  1592. if(!BxDolRelation::isEnabled())
  1593. return $sResult;
  1594. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_relations', false, true);
  1595. }
  1596. public function checkAllowedRelationsView (&$aDataEntry, $isPerformAction = false)
  1597. {
  1598. $sResult = _t('_sys_txt_access_denied');
  1599. if(!BxDolRelation::isEnabled())
  1600. return $sResult;
  1601. $sModule = $this->_oConfig->getName();
  1602. $oRelations = BxDolConnection::getObjectInstance('sys_profiles_relations');
  1603. if(!$oRelations->isRelationAvailableWithProfile($sModule) && !$oRelations->isRelationAvailableFromProfile($sModule))
  1604. return $sResult;
  1605. if(empty($aDataEntry) || !is_array($aDataEntry))
  1606. return $sResult;
  1607. return CHECK_ACTION_RESULT_ALLOWED;
  1608. }
  1609. /**
  1610. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1611. */
  1612. public function checkAllowedSubscribeAdd(&$aDataEntry, $isPerformAction = false)
  1613. {
  1614. $mixedResult = $this->_modProfileCheckAllowedSubscribeAdd($aDataEntry, $isPerformAction);
  1615. /**
  1616. * @hooks
  1617. * @hookdef hook-system-check_allowed_subscribe_add 'system', 'check_allowed_subscribe_add' - hook to override the result of checking whether 'subscribe' action is allowed or not to currently logged in user
  1618. * It's equivalent to @ref hook-system-check_allowed_view
  1619. * @hook @ref hook-system-check_allowed_subscribe_add
  1620. */
  1621. bx_alert('system', 'check_allowed_subscribe_add', 0, 0, [
  1622. 'module' => $this->getName(),
  1623. 'content_info' => $aDataEntry,
  1624. 'profile_id' => bx_get_logged_profile_id(),
  1625. 'override_result' => &$mixedResult
  1626. ]);
  1627. return $mixedResult;
  1628. }
  1629. /**
  1630. * Note. Is mainly needed for internal usage. Access level is 'public' to allow outer calls from alerts.
  1631. */
  1632. public function _modProfileCheckAllowedSubscribeAdd(&$aDataEntry, $isPerformAction = false)
  1633. {
  1634. if(($sMsg = $this->checkAllowedView($aDataEntry)) !== CHECK_ACTION_RESULT_ALLOWED)
  1635. return $sMsg;
  1636. return $this->_checkAllowedConnect($aDataEntry, $isPerformAction, 'sys_profiles_subscriptions', false, false);
  1637. }
  1638. /**
  1639. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1640. */
  1641. public function checkAllowedSubscribeRemove (&$aDataEntry, $isPerformAction = false)
  1642. {
  1643. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_subscriptions', false, true);
  1644. }
  1645. public function checkAllowedSubscriptionsView (&$aDataEntry, $isPerformAction = false)
  1646. {
  1647. $CNF = &$this->_oConfig->CNF;
  1648. $sResult = _t('_sys_txt_access_denied');
  1649. if(empty($aDataEntry) || !is_array($aDataEntry))
  1650. return $sResult;
  1651. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->_aModule['name']);
  1652. if(!$oProfile || ($oProfile->id() != $this->_iProfileId && $this->_oDb->getParam($CNF['PARAM_PUBLIC_SBSN']) != 'on' && $this->_oDb->getParam($CNF['PARAM_PUBLIC_SBSD']) != 'on'))
  1653. return $sResult;
  1654. return CHECK_ACTION_RESULT_ALLOWED;
  1655. }
  1656. public function checkMyself($iContentId)
  1657. {
  1658. $iLogged = (int)bx_get_logged_profile_id();
  1659. if(empty($iLogged))
  1660. return false;
  1661. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->_oConfig->getName());
  1662. if(!$oProfile)
  1663. return false;
  1664. return $oProfile->id() == $iLogged;
  1665. }
  1666. public function isAllowDeleteOrDisable($iActorProfileId, $iTargetProfileId)
  1667. {
  1668. if (BxDolAcl::getInstance()->isMemberLevelInSet(array(MEMBERSHIP_ID_MODERATOR), $iActorProfileId) && BxDolAcl::getInstance()->isMemberLevelInSet(array(MEMBERSHIP_ID_MODERATOR, MEMBERSHIP_ID_ADMINISTRATOR), $iTargetProfileId))
  1669. return false;
  1670. return true;
  1671. }
  1672. public function getProfileObject($iContentId)
  1673. {
  1674. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->_oConfig->getName());
  1675. if (!$oProfile)
  1676. $oProfile = BxDolProfileUndefined::getInstance();
  1677. return $oProfile;
  1678. }
  1679. protected function _serviceCheckAllowedContactForProfile($aDataEntry, $isPerformAction = false, $iProfileId = false)
  1680. {
  1681. $CNF = &$this->_oConfig->CNF;
  1682. if(!$iProfileId)
  1683. $iProfileId = $this->_iProfileId;
  1684. /*
  1685. * allow to 'contact myself'. It's needed to allow a user to view conversation page
  1686. * where he is one of the participants.
  1687. */
  1688. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->getName());
  1689. if($oProfile && $oProfile->id() == $iProfileId)
  1690. return CHECK_ACTION_RESULT_ALLOWED;
  1691. // moderator always has access
  1692. if($this->_isModeratorForProfile($isPerformAction, $iProfileId))
  1693. return CHECK_ACTION_RESULT_ALLOWED;
  1694. // check privacy
  1695. if(!empty($CNF['OBJECT_PRIVACY_CONTACT'])) {
  1696. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_CONTACT']);
  1697. if($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  1698. return _t('_sys_access_denied_to_private_content');
  1699. }
  1700. return CHECK_ACTION_RESULT_ALLOWED;
  1701. }
  1702. // ====== COMMON METHODS
  1703. public function onUpdateImage($iContentId, $sFiledName, $sFiledValue, $iProfileId = 0)
  1704. {
  1705. $CNF = &$this->_oConfig->CNF;
  1706. $sModule = $this->getName();
  1707. if(!$iProfileId && ($oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $sModule)) !== false)
  1708. $iProfileId = $oProfile->id();
  1709. $aField2Method = [
  1710. $CNF['FIELD_PICTURE'] => 'picture',
  1711. $CNF['FIELD_COVER'] => 'cover',
  1712. ];
  1713. if(!empty($aField2Method[$sFiledName]))
  1714. /**
  1715. * @hooks
  1716. * @hookdef hook-bx_base_profile-profile_picture_changed '{module_name}', 'profile_picture_changed' - hook after profile picture was changed
  1717. * - $unit_name - module name
  1718. * - $action - equals `profile_picture_changed`
  1719. * - $object_id - image id
  1720. * - $sender_id - profile id who performed the action
  1721. * - $extra_params - array of additional params with the following array keys:
  1722. * - `object_author_id` - [int] profile id
  1723. * - `content` - [int] profile content id
  1724. * - `field` - [string] field name
  1725. * @hook @ref hook-bx_base_profile-profile_picture_changed
  1726. */
  1727. /**
  1728. * @hooks
  1729. * @hookdef hook-bx_base_profile-profile_cover_changed '{module_name}', 'profile_cover_changed' - hook after profile cover was changed
  1730. * It's equivalent to @ref hook-bx_base_profile-profile_picture_changed
  1731. * @hook @ref hook-bx_base_profile-profile_cover_changed
  1732. */
  1733. bx_alert($sModule, 'profile_' . $aField2Method[$sFiledName] . '_changed', $sFiledValue, $iProfileId, [
  1734. 'object_author_id' => $iProfileId,
  1735. 'content' => $iContentId,
  1736. 'field' => $sFiledName
  1737. ]);
  1738. }
  1739. protected function _alertParams($aContentInfo)
  1740. {
  1741. $aParams = parent::_alertParams($aContentInfo);
  1742. $CNF = &$this->_oConfig->CNF;
  1743. if(!empty($CNF['FIELD_STATUS']) && isset($aContentInfo[$CNF['FIELD_STATUS']]))
  1744. $aParams['status'] = $aContentInfo[$CNF['FIELD_STATUS']];
  1745. if(!empty($CNF['FIELD_STATUS_ADMIN']) && isset($aContentInfo[$CNF['FIELD_STATUS_ADMIN']]))
  1746. $aParams['status_admin'] = $aContentInfo[$CNF['FIELD_STATUS_ADMIN']];
  1747. if(!empty($CNF['FIELD_ALLOW_VIEW_TO']) && isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]))
  1748. $aParams['privacy_view'] = $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']];
  1749. return $aParams;
  1750. }
  1751. public function alertAfterAdd($aContentInfo)
  1752. {
  1753. $CNF = &$this->_oConfig->CNF;
  1754. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  1755. $aParams = $this->_alertParams($aContentInfo);
  1756. /**
  1757. * @hooks
  1758. * @hookdef hook-bx_base_profile-added '{module_name}', 'added' - hook after profile was added
  1759. * - $unit_name - module name
  1760. * - $action - equals `added`
  1761. * - $object_id - profile content id
  1762. * - $sender_id - not used
  1763. * - $extra_params - array of additional params with the following array keys:
  1764. * - `status` - [string] context status
  1765. * - `status_admin` - [string] context admin status
  1766. * - `privacy_view` - [int] or [string] privacy for view context action, @see BxDolPrivacy
  1767. * @hook @ref hook-bx_base_profile-added
  1768. */
  1769. bx_alert($this->getName(), 'added', $iContentId, false, $aParams);
  1770. }
  1771. public function alertAfterEdit($aContentInfo)
  1772. {
  1773. $CNF = &$this->_oConfig->CNF;
  1774. $sModule = $this->getName();
  1775. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  1776. $aParams = $this->_alertParams($aContentInfo);
  1777. /**
  1778. * @hooks
  1779. * @hookdef hook-bx_base_profile-edited '{module_name}', 'edited' - hook after profile was changed
  1780. * It's equivalent to @ref hook-bx_base_profile-added
  1781. * @hook @ref hook-bx_base_profile-edited
  1782. */
  1783. bx_alert($sModule, 'edited', $iContentId, false, $aParams);
  1784. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $sModule);
  1785. /**
  1786. * @hooks
  1787. * @hookdef hook-profile-edit 'profile', 'edit' - hook after profile was changed
  1788. * - $unit_name - equals `profile`
  1789. * - $action - equals `edit`
  1790. * - $object_id - profile id
  1791. * - $sender_id - not used
  1792. * - $extra_params - array of additional params with the following array keys:
  1793. * - `content` - [int] profile content id
  1794. * - `module` - [string] module name
  1795. * @hook @ref hook-profile-added
  1796. */
  1797. bx_alert('profile', 'edit', $oProfile->id(), 0, [
  1798. 'content' => $iContentId,
  1799. 'module' => $sModule
  1800. ]);
  1801. }
  1802. public function getProfileByCurrentUrl ()
  1803. {
  1804. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  1805. if ($iProfileId)
  1806. return BxDolProfile::getInstance($iProfileId);
  1807. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1808. if ($iContentId)
  1809. return BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  1810. return false;
  1811. }
  1812. public function getEntryImageData($aContentInfo, $sField = 'FIELD_PICTURE', $aTranscoders = array())
  1813. {
  1814. return parent::getEntryImageData($aContentInfo, $sField, $aTranscoders);
  1815. }
  1816. public function getProfileName ($aContentInfo)
  1817. {
  1818. return bx_process_output($aContentInfo[$this->_oConfig->CNF['FIELD_NAME']]);
  1819. }
  1820. public function getMenuItemTitleByConnection($sConnection, $sAction, $iContentProfileId, $iInitiatorProfileId = 0)
  1821. {
  1822. $oConnection = BxDolConnection::getObjectInstance($sConnection);
  1823. if(!$oConnection)
  1824. return false;
  1825. if(!$iInitiatorProfileId)
  1826. $iInitiatorProfileId = bx_get_logged_profile_id();
  1827. $aResult = [];
  1828. switch($sConnection) {
  1829. case 'sys_profiles_friends':
  1830. $aResult = $this->_getMenuItemTitleProfilesFriends($sAction, $iContentProfileId, $iInitiatorProfileId, $oConnection);
  1831. break;
  1832. case 'sys_profiles_subscriptions':
  1833. $aResult = $this->_getMenuItemTitleProfilesSubscriptions($sAction, $iContentProfileId, $iInitiatorProfileId, $oConnection);
  1834. break;
  1835. }
  1836. return $aResult;
  1837. }
  1838. protected function _getMenuItemTitleProfilesFriends($sAction, $iContentProfileId, $iInitiatorProfileId, &$oConnection)
  1839. {
  1840. $CNF = $this->_oConfig->getCNF();
  1841. $aResult = [];
  1842. if($oConnection->isConnectedNotMutual($iInitiatorProfileId, $iContentProfileId))
  1843. $aResult = [
  1844. 'add' => _t(!empty($CNF['T']['menu_item_title_befriend_sent']) ? $CNF['T']['menu_item_title_befriend_sent'] : '_sys_menu_item_title_sm_befriend_sent'),
  1845. 'remove' => _t(!empty($CNF['T']['menu_item_title_unfriend_cancel']) ? $CNF['T']['menu_item_title_unfriend_cancel'] : '_sys_menu_item_title_sm_unfriend_cancel'),
  1846. ];
  1847. else if($oConnection->isConnectedNotMutual($iContentProfileId, $iInitiatorProfileId))
  1848. $aResult = [
  1849. 'add' => _t(!empty($CNF['T']['menu_item_title_befriend_confirm']) ? $CNF['T']['menu_item_title_befriend_confirm'] : '_sys_menu_item_title_sm_befriend_confirm'),
  1850. 'remove' => _t(!empty($CNF['T']['menu_item_title_unfriend_reject']) ? $CNF['T']['menu_item_title_unfriend_reject'] : '_sys_menu_item_title_sm_unfriend_reject'),
  1851. ];
  1852. else if($oConnection->isConnected($iInitiatorProfileId, $iContentProfileId, true))
  1853. $aResult = [
  1854. 'add' => '',
  1855. 'remove' => _t(!empty($CNF['T']['menu_item_title_unfriend']) ? $CNF['T']['menu_item_title_unfriend'] : '_sys_menu_item_title_sm_unfriend'),
  1856. ];
  1857. else
  1858. $aResult = [
  1859. 'add' => _t(!empty($CNF['T']['menu_item_title_befriend']) ? $CNF['T']['menu_item_title_befriend'] : '_sys_menu_item_title_sm_befriend'),
  1860. 'remove' => '',
  1861. ];
  1862. return !empty($sAction) && isset($aResult[$sAction]) ? $aResult[$sAction] : $aResult;
  1863. }
  1864. protected function _getMenuItemTitleProfilesSubscriptions($sAction, $iContentProfileId, $iInitiatorProfileId, &$oConnection)
  1865. {
  1866. $CNF = $this->_oConfig->getCNF();
  1867. $aResult = [];
  1868. if($oConnection->isConnected($iInitiatorProfileId, $iContentProfileId))
  1869. $aResult = [
  1870. 'add' => '',
  1871. 'remove' => _t(!empty($CNF['T']['menu_item_title_unsubscribe']) ? $CNF['T']['menu_item_title_unsubscribe'] : '_sys_menu_item_title_sm_unsubscribe'),
  1872. ];
  1873. else
  1874. $aResult = [
  1875. 'add' => _t(!empty($CNF['T']['menu_item_title_subscribe']) ? $CNF['T']['menu_item_title_subscribe'] : '_sys_menu_item_title_sm_subscribe'),
  1876. 'remove' => '',
  1877. ];
  1878. return !empty($sAction) && !empty($aResult[$sAction]) ? $aResult[$sAction] : $aResult;
  1879. }
  1880. public function decodeDataAPI($aData, $aParams = [])
  1881. {
  1882. $CNF = $this->_oConfig->CNF;
  1883. $sModule = $this->getName();
  1884. $iId = (int)$aData[$CNF['FIELD_ID']];
  1885. $oProfile = BxDolProfile::getInstanceByContentAndType($iId, $sModule);
  1886. $aResult = [
  1887. 'id' => $iId,
  1888. 'module' => $sModule,
  1889. 'module_title' => _t($CNF['T']['txt_sample_single']),
  1890. 'added' => $aData[$CNF['FIELD_ADDED']],
  1891. 'author' => $aData[$CNF['FIELD_AUTHOR']],
  1892. 'author_data' => $oProfile !== false ? BxDolProfile::getData($oProfile->id()) : '',
  1893. 'title' => $aData[$CNF['FIELD_TITLE']],
  1894. $CNF['FIELD_TITLE'] => $aData[$CNF['FIELD_TITLE']],
  1895. 'url' => bx_api_get_relative_url($this->serviceGetLink($iId)),
  1896. 'image' => $this->serviceGetThumb($iId),
  1897. 'cover' => $this->serviceGetCover($iId),
  1898. ];
  1899. if(isset($aParams['template']) && $aParams['template'] == 'unit_wo_info')
  1900. return $aResult;
  1901. if(isset($aParams['extended']) && $aParams['extended'] === true)
  1902. $aResult['text'] = $aData[$CNF['FIELD_TEXT']];
  1903. if(getParam('sys_api_conn_in_prof_units') == 'on' && $oProfile !== false) {
  1904. $iProfileId = $oProfile->id();
  1905. $aResult['title'] = $oProfile->getDisplayName();
  1906. if(($oConnection = BxDolConnection::getObjectInstance('sys_profiles_friends')) !== false && isset($CNF['URI_VIEW_FRIENDS'])) {
  1907. $aResult['friends_count'] = $oConnection->getConnectedContentCount($iProfileId, true);
  1908. $aResult['friends_list'] = $oConnection->getConnectedListAPI($iProfileId, true, BX_CONNECTIONS_CONTENT_TYPE_CONTENT);
  1909. if(isLogged()) {
  1910. $iLoggedId = bx_get_logged_profile_id();
  1911. $aResult['mutual_friends_count'] = $oConnection->getCommonContentCount($iProfileId, $iLoggedId, true);
  1912. $aResult['mutual_friends_list'] = $oConnection->getCommonListAPI($iProfileId, $iLoggedId, true);
  1913. }
  1914. }
  1915. if(($oConnection = BxDolConnection::getObjectInstance('sys_profiles_subscriptions')) !== false){
  1916. $aResult['followers_count'] = $oConnection->getConnectedInitiatorsCount($iProfileId);
  1917. $aResult['followers_list'] = $oConnection->getConnectedListAPI($iProfileId, false, BX_CONNECTIONS_CONTENT_TYPE_INITIATORS);
  1918. }
  1919. }
  1920. $sKey = 'OBJECT_MENU_SNIPPET_META';
  1921. if(!empty($CNF[$sKey]) && ($oMetaMenu = BxDolMenu::getObjectInstance($CNF[$sKey], $this->_oTemplate)) !== false) {
  1922. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  1923. $bPublic = !$oPrivacy || $oPrivacy->check($iId) || $oPrivacy->isPartiallyVisible($aData[$CNF['FIELD_ALLOW_VIEW_TO']]);
  1924. $oMetaMenu->setContentId($iId);
  1925. $oMetaMenu->setContentPublic($bPublic);
  1926. if(isset($aParams['context']))
  1927. $oMetaMenu->setContext($aParams['context']);
  1928. $aResult['meta'] = $oMetaMenu->getCodeAPI();
  1929. }
  1930. return $aResult;
  1931. }
  1932. // ====== PROTECTED METHODS
  1933. protected function _checkAllowedConnect (&$aDataEntry, $isPerformAction, $mixedConnection, $isMutual, $isInvertResult, $isSwap = false)
  1934. {
  1935. if (!$this->_iProfileId)
  1936. return _t('_sys_txt_access_denied');
  1937. $CNF = &$this->_oConfig->CNF;
  1938. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->_aModule['name']);
  1939. if (!$oProfile || $oProfile->id() == $this->_iProfileId)
  1940. return _t('_sys_txt_access_denied');
  1941. $sConnObject = '';
  1942. $sConnMethod = 'checkAllowedConnect';
  1943. if(is_array($mixedConnection))
  1944. list($sConnObject, $sConnMethod) = $mixedConnection;
  1945. else
  1946. $sConnObject = $mixedConnection;
  1947. return BxDolConnection::getObjectInstance($sConnObject)->$sConnMethod($this->_iProfileId, $oProfile->id(), $isPerformAction, $isMutual, $isInvertResult, $isSwap);
  1948. }
  1949. protected function _buildRssParams($sMode, $aArgs)
  1950. {
  1951. $aParams = array ();
  1952. $sMode = bx_process_input($sMode);
  1953. switch ($sMode) {
  1954. case 'connections':
  1955. $aParams = array(
  1956. 'object' => isset($aArgs[0]) ? $aArgs[0] : '',
  1957. 'type' => isset($aArgs[1]) ? $aArgs[1] : '',
  1958. 'profile' => isset($aArgs[2]) ? (int)$aArgs[2] : 0,
  1959. 'mutual' => isset($aArgs[3]) ? (int)$aArgs[3] : 0,
  1960. 'profile2' => isset($aArgs[4]) ? (int)$aArgs[4] : 0,
  1961. );
  1962. break;
  1963. }
  1964. return $aParams;
  1965. }
  1966. protected function _serviceGetTimelineProfileImage($aEvent, $aBrowseParams, $aBuildParams)
  1967. {
  1968. $CNF = &$this->_oConfig->CNF;
  1969. $aFileInfo = BxDolStorage::getObjectInstance($CNF[$aBuildParams['stg']])->getFile((int)$aEvent['object_id']);
  1970. if(empty($aFileInfo) || !is_array($aFileInfo))
  1971. return false;
  1972. $aEventContent = unserialize($aEvent['content']);
  1973. if(!is_array($aEventContent) || empty($aEventContent['content']))
  1974. return false;
  1975. $aContentInfo = $this->_oDb->getContentInfoById($aEventContent['content']);
  1976. if(empty($aContentInfo) || !is_array($aContentInfo))
  1977. return false;
  1978. $oProfile = BxDolProfile::getInstanceMagic($aContentInfo['profile_id']);
  1979. if (!$oProfile->isActive())
  1980. return false;
  1981. $sUserName = $oProfile->getDisplayName();
  1982. $sSample = isset($CNF['T'][$aBuildParams['txt_sswa']]) ? $CNF['T'][$aBuildParams['txt_sswa']] : $CNF['T'][$aBuildParams['txt_ss']];
  1983. //--- Title & Description
  1984. $sTitle = !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '';
  1985. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TEXT']]))
  1986. $sTitle = $aContentInfo[$CNF['FIELD_TEXT']];
  1987. $sDescription = _t($CNF['T'][$aBuildParams['txt_sau']], $sUserName, _t($sSample));
  1988. return array(
  1989. 'owner_id' => $aEvent['owner_id'],
  1990. 'object_owner_id' => $aContentInfo['profile_id'],
  1991. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  1992. 'sample' => $sSample,
  1993. 'sample_wo_article' => $CNF['T'][$aBuildParams['txt_ss']],
  1994. 'sample_action' => isset($CNF['T'][$aBuildParams['txt_sa']]) ? $CNF['T'][$aBuildParams['txt_sa']] : '',
  1995. 'url' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']])),
  1996. 'content' => $this->_getContentForTimelineProfileImage($aEvent, $aBrowseParams, $aBuildParams, $aContentInfo, $aFileInfo), //a string to display or array to parse default template before displaying.
  1997. 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
  1998. 'views' => '',
  1999. 'votes' => '',
  2000. 'scores' => '',
  2001. 'reports' => '',
  2002. 'comments' => '',
  2003. 'title' => $sTitle, //may be empty.
  2004. 'description' => $sDescription //may be empty.
  2005. );
  2006. }
  2007. protected function _serviceGetTimelineProfileImageAllowedView($aEvent)
  2008. {
  2009. $sError = _t('_sys_access_denied_to_private_content');
  2010. if(empty($aEvent['content']) || !is_array($aEvent['content']) || empty($aEvent['content']['id']))
  2011. return $sError;
  2012. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['content']['id']);
  2013. if(empty($aContentInfo) || !is_array($aContentInfo))
  2014. return $sError;
  2015. return $this->serviceCheckAllowedViewForProfile($aContentInfo);
  2016. }
  2017. protected function _getContentForTimelineProfileImage($aEvent, $aBrowseParams, $aBuildParams, $aContentInfo, $aFileInfo)
  2018. {
  2019. $CNF = &$this->_oConfig->CNF;
  2020. $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]));
  2021. //--- Image(s)
  2022. $sImage = $this->_oConfig->getImageUrl($aFileInfo['id'], $aBuildParams['trans']);
  2023. $sImageOrig = $this->_oConfig->getImageUrl($aFileInfo['id'], $aBuildParams['trans_orig']);
  2024. if(!empty($sImage)) {
  2025. if(empty($sImageOrig))
  2026. $sImageOrig = $sImage;
  2027. $a = ['id' => $aFileInfo['id'], 'url' => $sUrl, 'src' => $sImage];
  2028. if(CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedView($aContentInfo)) {
  2029. $a['src_orig'] = $sImageOrig;
  2030. $sCnfKey = 'OBJECT_IMAGES_TRANSCODER_GALLERY';
  2031. if(!empty($CNF[$sCnfKey]) && ($sSrcMedium = $this->_oConfig->getImageUrl($aFileInfo['id'], [$sCnfKey])) != '')
  2032. $a['src_medium'] = $sSrcMedium;
  2033. }
  2034. $aImages = [$a];
  2035. }
  2036. return array(
  2037. 'sample' => isset($CNF['T'][$aBuildParams['txt_sswa']]) ? $CNF['T'][$aBuildParams['txt_sswa']] : $CNF['T'][$aBuildParams['txt_ss']],
  2038. 'sample_wo_article' => $CNF['T'][$aBuildParams['txt_ss']],
  2039. 'sample_action' => isset($CNF['T'][$aBuildParams['txt_sa']]) ? $CNF['T'][$aBuildParams['txt_sa']] : '',
  2040. 'id' => $aContentInfo[$CNF['FIELD_ID']],
  2041. 'url' => $sUrl,
  2042. 'title' => '',
  2043. 'text' => '',
  2044. 'images' => $aImages,
  2045. 'videos' => array()
  2046. );
  2047. }
  2048. protected function _entityComments($sObject, $iId = 0)
  2049. {
  2050. if(!$iId)
  2051. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  2052. if(!$iId)
  2053. $iId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  2054. if(!$iId)
  2055. return false;
  2056. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  2057. if(!$oCmts || !$oCmts->isEnabled())
  2058. return false;
  2059. return $oCmts->getCommentsBlock(array(), array('in_designbox' => false));
  2060. }
  2061. protected function _getContent($iContentId = 0, $sFuncGetContent = 'getContentInfoById')
  2062. {
  2063. if(!$iContentId && bx_get('id') === false && bx_get('profile_id') !== false) {
  2064. $oProfile = BxDolProfile::getInstance((int)bx_get('profile_id'));
  2065. if($oProfile)
  2066. $iContentId = $oProfile->getContentId();
  2067. }
  2068. return parent::_getContent($iContentId, $sFuncGetContent);
  2069. }
  2070. }
  2071. /** @} */