BxBaseModProfileModule.php 101 KB

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