1
0

BxBaseModProfileModule.php 70 KB

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