BxBaseModProfileModule.php 90 KB

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