BxBaseModProfileModule.php 70 KB

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