1
0

BxBaseModProfileModule.php 72 KB

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