BxBaseModProfileModule.php 81 KB

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