BxBaseModProfileModule.php 106 KB

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