BxBaseModProfileModule.php 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917
  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. echo $this->getName().'xxx';
  415. $a = array_unique($a);
  416. $aRet = array();
  417. foreach ($a as $iConnectedProfileId) {
  418. if (!($oConnectedProfile = BxDolProfile::getInstance($iConnectedProfileId)))
  419. continue;
  420. if (CHECK_ACTION_RESULT_ALLOWED === bx_srv($oConnectedProfile->getModule(), 'check_allowed_post_in_profile', array($oConnectedProfile->getContentId(), $iProfileId)))
  421. $aRet[] = $iConnectedProfileId;
  422. }
  423. bx_alert('system', 'get_participating_profiles', $iProfileId, false, array(
  424. 'module' => $this->_oConfig->getName(),
  425. 'profiles' => &$aRet
  426. ));
  427. return $aRet;
  428. }
  429. /**
  430. * Prepare fields from some universal set of fields to fields in particular profile module.
  431. * By default only 'name' and 'description' fields are supported.
  432. * After fields convertion it can be used in @see BxBaseModGeneralModule::serviceEntityAdd
  433. * @param $aFieldsProfile fields in soem universal format.
  434. * @return array which is ready to use for particular module
  435. */
  436. public function servicePrepareFields ($aFieldsProfile)
  437. {
  438. bx_alert($this->getName(), 'prepare_fields', 0, 0, array('fields_orig' => $aFieldsProfile, 'fields_result' => &$aFieldsProfile));
  439. return $aFieldsProfile;
  440. }
  441. protected function _servicePrepareFields ($aFieldsProfile, $aFieldsDefault, $aMap)
  442. {
  443. $aFieldsOrig = $aFieldsProfile;
  444. bx_import('BxDolPrivacy');
  445. $aFieldsDefault2 = array(
  446. 'allow_view_to' => BX_DOL_PG_ALL,
  447. 'allow_contact_to' => BX_DOL_PG_ALL,
  448. 'allow_post_to' => BX_DOL_PG_FRIENDS,
  449. );
  450. $aFieldsProfile = array_merge($aFieldsDefault2, $aFieldsDefault, $aFieldsProfile);
  451. foreach ($aMap as $k => $v) {
  452. if (isset($aFieldsProfile[$v]))
  453. $aFieldsProfile[$k] = $aFieldsProfile[$v];
  454. if ($k != $v && !isset($aMap[$v]))
  455. unset($aFieldsProfile[$v]);
  456. }
  457. bx_alert($this->getName(), 'prepare_fields', 0, 0, array('fields_orig' => $aFieldsOrig, 'fields_result' => &$aFieldsProfile));
  458. return $aFieldsProfile;
  459. }
  460. public function serviceFormsHelper ()
  461. {
  462. return parent::serviceFormsHelper ();
  463. }
  464. /**
  465. * @page service Service Calls
  466. * @section bx_base_profile Base Profile
  467. * @subsection bx_base_profile-forms Forms
  468. * @subsubsection bx_base_profile-entity_create entity_create
  469. *
  470. * @code bx_srv('bx_persons', 'entity_create', [...]); @endcode
  471. *
  472. * Get profile creation form
  473. * @param $sDisplay optional form display name
  474. *
  475. * @see BxBaseModProfileModule::serviceEntityCreate
  476. */
  477. /**
  478. * @ref bx_base_profile-entity_create "entity_create"
  479. */
  480. public function serviceEntityCreate ($sDisplay = false)
  481. {
  482. BxDolInformer::getInstance($this->_oTemplate)->setEnabled(false);
  483. return parent::serviceEntityCreate ($sDisplay);
  484. }
  485. public function serviceActAsProfile ()
  486. {
  487. return true;
  488. }
  489. /**
  490. * @page service Service Calls
  491. * @section bx_base_profile Base Profile
  492. * @subsection bx_base_profile-browse Browse
  493. * @subsubsection bx_base_profile-browse_recommended browse_recommended
  494. *
  495. * @code bx_srv('bx_persons', 'browse_recommended', [...]); @endcode
  496. *
  497. * Browse recommended profiles
  498. * @param $sUnitView optional, unit view, for example - showcase
  499. * @param $bEmptyMessage optional, display or not "empty" message when there is no content
  500. * @param $bAjaxPaginate optional, use AJAX paginate or not
  501. *
  502. * @see BxBaseModProfileModule::serviceBrowseRecommended
  503. */
  504. /**
  505. * @ref bx_base_profile-browse_recommended "browse_recommended"
  506. */
  507. public function serviceBrowseRecommended ($sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = true)
  508. {
  509. if (!isLogged())
  510. return '';
  511. return $this->_serviceBrowse ('recommended', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  512. }
  513. /**
  514. * @page service Service Calls
  515. * @section bx_base_profile Base Profile
  516. * @subsection bx_base_profile-browse Browse
  517. * @subsubsection bx_base_profile-browse_recent_profiles browse_recent_profiles
  518. *
  519. * @code bx_srv('bx_persons', 'browse_recent_profiles', [...]); @endcode
  520. *
  521. * Browse recently joined profiles
  522. * @param $bEmptyMessage optional, display or not "empty" message when there is no content
  523. * @param $bAjaxPaginate optional, use AJAX paginate or not
  524. *
  525. * @see BxBaseModProfileModule::serviceBrowseRecentProfiles
  526. */
  527. /**
  528. * @ref bx_base_profile-browse_recent_profiles "browse_recent_profiles"
  529. */
  530. public function serviceBrowseRecentProfiles ($bDisplayEmptyMsg = false, $bAjaxPaginate = true)
  531. {
  532. return $this->_serviceBrowse ('recent', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate);
  533. }
  534. /**
  535. * @page service Service Calls
  536. * @section bx_base_profile Base Profile
  537. * @subsection bx_base_profile-browse Browse
  538. * @subsubsection bx_base_profile-browse_active_profiles browse_active_profiles
  539. *
  540. * @code bx_srv('bx_persons', 'browse_active_profiles', [...]); @endcode
  541. *
  542. * Browse recently active profiles
  543. * @param $bEmptyMessage optional, display or not "empty" message when there is no content
  544. * @param $bAjaxPaginate optional, use AJAX paginate or not
  545. *
  546. * @see BxBaseModProfileModule::serviceBrowseActiveProfiles
  547. */
  548. /**
  549. * @ref bx_base_profile-browse_active_profiles "browse_active_profiles"
  550. */
  551. public function serviceBrowseActiveProfiles ($sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = false)
  552. {
  553. return $this->_serviceBrowse ('active', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  554. }
  555. /**
  556. * @page service Service Calls
  557. * @section bx_base_profile Base Profile
  558. * @subsection bx_base_profile-browse Browse
  559. * @subsubsection bx_base_profile-browse_top_profiles browse_top_profiles
  560. *
  561. * @code bx_srv('bx_persons', 'browse_top_profiles', [...]); @endcode
  562. *
  563. * Browse top profiles
  564. * @param $bEmptyMessage optional, display or not "empty" message when there is no content
  565. * @param $bAjaxPaginate optional, use AJAX paginate or not
  566. *
  567. * @see BxBaseModProfileModule::serviceBrowseTopProfiles
  568. */
  569. /**
  570. * @ref bx_base_profile-browse_top_profiles "browse_top_profiles"
  571. */
  572. public function serviceBrowseTopProfiles ($bDisplayEmptyMsg = false, $bAjaxPaginate = false)
  573. {
  574. return $this->_serviceBrowse ('top', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate);
  575. }
  576. /**
  577. * @page service Service Calls
  578. * @section bx_base_profile Base Profile
  579. * @subsection bx_base_profile-browse Browse
  580. * @subsubsection bx_base_profile-browse_online_profiles browse_online_profiles
  581. *
  582. * @code bx_srv('bx_persons', 'browse_online_profiles', [...]); @endcode
  583. *
  584. * Browse online profiles
  585. * @param $bEmptyMessage optional, display or not "empty" message when there is no content
  586. * @param $bAjaxPaginate optional, use AJAX paginate or not
  587. *
  588. * @see BxBaseModProfileModule::serviceBrowseOnlineProfiles
  589. */
  590. /**
  591. * @ref bx_base_profile-browse_online_profiles "browse_online_profiles"
  592. */
  593. public function serviceBrowseOnlineProfiles ($bDisplayEmptyMsg = false, $bAjaxPaginate = false)
  594. {
  595. return $this->_serviceBrowse ('online', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate);
  596. }
  597. public function serviceBrowseConnections ($iProfileId, $sObjectConnections = 'sys_profiles_friends', $sConnectionsType = 'content', $iMutual = false, $iDesignBox = BX_DB_PADDING_DEF, $iProfileId2 = 0)
  598. {
  599. return $this->_serviceBrowse (
  600. 'connections',
  601. array(
  602. 'object' => $sObjectConnections,
  603. 'type' => $sConnectionsType,
  604. 'mutual' => $iMutual,
  605. 'profile' => (int)$iProfileId,
  606. 'profile2' => (int)$iProfileId2),
  607. $iDesignBox
  608. );
  609. }
  610. public function serviceBrowseRelationsQuick ($iProfileId, $sObjectConnections = 'sys_profiles_friends', $sConnectionsType = 'content', $iMutual = false, $iProfileId2 = 0)
  611. {
  612. // get connections object
  613. $oConnection = BxDolConnection::getObjectInstance($sObjectConnections);
  614. if (!$oConnection)
  615. return '';
  616. // set some vars
  617. $iStart = (int)bx_get('start');
  618. $iLimit = empty($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? 4 : getParam($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']);
  619. if (!$iLimit)
  620. $iLimit = 4;
  621. // get connections array
  622. bx_import('BxDolConnection');
  623. $aConnections = $oConnection->getConnectionsAsArrayExt($sConnectionsType, $iProfileId, $iProfileId2, $iMutual, $iStart, $iLimit + 1, BX_CONNECTIONS_ORDER_ADDED_DESC);
  624. if(empty($aConnections) || !is_array($aConnections))
  625. return '';
  626. $aResult = array();
  627. foreach($aConnections as $iProfile => $aConnection)
  628. $aResult[] = array(
  629. 'id' => $iProfile,
  630. 'info' => array(
  631. 'addon' => $oConnection->getRelationTranslation($aConnection['relation'])
  632. )
  633. );
  634. return $this->_serviceBrowseQuick($aResult, $iStart, $iLimit);
  635. }
  636. public function serviceBrowseConnectionsQuick ($iProfileId, $sObjectConnections = 'sys_profiles_friends', $sConnectionsType = 'content', $iMutual = false, $iProfileId2 = 0)
  637. {
  638. // get connections object
  639. $oConnection = BxDolConnection::getObjectInstance($sObjectConnections);
  640. if (!$oConnection)
  641. return '';
  642. // set some vars
  643. $iLimit = empty($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? 4 : getParam($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']);
  644. if (!$iLimit)
  645. $iLimit = 4;
  646. $iStart = (int)bx_get('start');
  647. // get connections array
  648. bx_import('BxDolConnection');
  649. $a = $oConnection->getConnectionsAsArray ($sConnectionsType, $iProfileId, $iProfileId2, $iMutual, (int)bx_get('start'), $iLimit + 1, BX_CONNECTIONS_ORDER_ADDED_DESC);
  650. if (!$a)
  651. return '';
  652. return $this->_serviceBrowseQuick($a, $iStart, $iLimit);
  653. }
  654. public function serviceBrowseConnectionsByType ($aParamsCnn, $aParamsBrs = array())
  655. {
  656. $sAll = 'all';
  657. $aParamsCnn['object'] = !empty($aParamsCnn['object']) ? $aParamsCnn['object'] : 'sys_profiles_friends';
  658. $aParamsCnn['type'] = !empty($aParamsCnn['type']) ? $aParamsCnn['type'] : 'content';
  659. $aParamsCnn['profile_id2'] = !empty($aParamsCnn['profile_id2']) ? (int)$aParamsCnn['profile_id2'] : 0;
  660. $aParamsCnn['mutual'] = isset($aParamsCnn['mutual']) ? $aParamsCnn['mutual'] : false;
  661. $oConnection = BxDolConnection::getObjectInstance($aParamsCnn['object']);
  662. if(!$oConnection)
  663. return '';
  664. $aSQLParts = $oConnection->getConnectionsAsSQLParts ($aParamsCnn['type'], 'sys_profiles', 'id', $aParamsCnn['profile_id'], $aParamsCnn['profile_id2'], $aParamsCnn['mutual']);
  665. $sType = !empty($aParamsBrs['type']) ? $aParamsBrs['type'] : $sAll;
  666. if(bx_get('type') !== false)
  667. $sType = bx_process_input(bx_get('type'));
  668. $iStart = (int)bx_get('start');
  669. $iLimitDefault = 4;
  670. $iLimit = !empty($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? getParam($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) : $iLimitDefault;
  671. if(!empty($aParamsBrs['per_page']))
  672. $iLimit = (int)$aParamsBrs['per_page'];
  673. if(!$iLimit)
  674. $iLimit = $iLimitDefault;
  675. $aProfiles = BxDolProfileQuery::getInstance()->getConnectedProfilesByType($aSQLParts, ($sType != $sAll ? $sType : ''), $iStart, $iLimit + 1);
  676. $mixedMenu = '';
  677. if(!isset($aParamsBrs['filter_menu']) || $aParamsBrs['filter_menu'] === true) {
  678. $aModules = array(
  679. array('name' => $sAll)
  680. );
  681. $aModules = array_merge($aModules, BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1)));
  682. $aMenuItems = array();
  683. foreach($aModules as $aModule)
  684. if($aModule['name'] == $sAll || BxDolRequest::serviceExists($aModule['name'], 'act_as_profile'))
  685. $aMenuItems[] = array(
  686. 'id' => $aModule['name'],
  687. 'name' => $aModule['name'],
  688. 'class' => '',
  689. 'link' => 'javascript:void(0)',
  690. 'onclick' => "return !loadDynamicBlockAutoPaginate(this, " . $iStart . ", " . $iLimit . ", " . bx_js_string(json_encode(array('type' => $aModule['name']))) . ");",
  691. 'target' => '_self',
  692. 'title' => _t('_' . $aModule['name']),
  693. 'active' => 1
  694. );
  695. if(!empty($aMenuItems)) {
  696. $mixedMenu = new BxTemplMenu(array('template' => 'menu_vertical.html', 'menu_id'=> $this->_oConfig->getName() . '-connections-by-type', 'menu_items' => $aMenuItems));
  697. $mixedMenu->setSelected('', $sType);
  698. }
  699. }
  700. return array(
  701. 'menu' => $mixedMenu,
  702. 'content' => $this->_serviceBrowseQuick(array_keys($aProfiles), $iStart, $iLimit, array('type' => $sType))
  703. );
  704. }
  705. /**
  706. * @page service Service Calls
  707. * @section bx_base_profile Base Profile
  708. * @subsection bx_base_profile-browse Browse
  709. * @subsubsection bx_base_profile-browse_by_acl browse_by_acl
  710. *
  711. * @code bx_srv('bx_persons', 'browse_by_acl', [...]); @endcode
  712. *
  713. * Browse profiles by membership(ACL) level
  714. * @param $mixedLevelId membership level, or array of membership levels
  715. * @param $iDesignBox optional, design box identifier
  716. *
  717. * @see BxBaseModProfileModule::serviceBrowseByAcl
  718. */
  719. /**
  720. * @ref bx_base_profile-browse_by_acl "browse_by_acl"
  721. */
  722. public function serviceBrowseByAcl ($mixedLevelId, $iDesignBox = BX_DB_PADDING_DEF)
  723. {
  724. return $this->_serviceBrowse (
  725. 'acl',
  726. array(
  727. 'level' => $mixedLevelId,
  728. ),
  729. $iDesignBox,
  730. true
  731. );
  732. }
  733. public function serviceEntityEditCover ($iContentId = 0)
  734. {
  735. return $this->_serviceEntityForm ('editDataForm', $iContentId, $this->_oConfig->CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT_COVER']);
  736. }
  737. /**
  738. * Entry comments
  739. */
  740. public function serviceEntityCommentsByProfile ($iProfileId)
  741. {
  742. $CNF = &$this->_oConfig->CNF;
  743. if(empty($CNF['OBJECT_COMMENTS']))
  744. return '';
  745. $oProfile = BxDolProfile::getInstance($iProfileId);
  746. if(!$oProfile)
  747. return '';
  748. return $this->_entityComments($CNF['OBJECT_COMMENTS'], $oProfile->getContentId());
  749. }
  750. /**
  751. * Entry social sharing block
  752. */
  753. public function serviceEntitySocialSharing ($mixedContent = false, $aParams = array())
  754. {
  755. if(!empty($mixedContent)) {
  756. if(!is_array($mixedContent))
  757. $mixedContent = array((int)$mixedContent, array());
  758. }
  759. else {
  760. $mixedContent = $this->_getContent();
  761. if($mixedContent === false)
  762. return false;
  763. }
  764. list($iContentId, $aContentInfo) = $mixedContent;
  765. return parent::serviceEntitySocialSharing(array($iContentId, $aContentInfo), array(
  766. 'id_thumb' => !empty($CNF['FIELD_PICTURE']) && !empty($aContentInfo[$CNF['FIELD_PICTURE']]) ? $aContentInfo[$CNF['FIELD_PICTURE']] : 0,
  767. ));
  768. }
  769. public function serviceProfileMembership ($iContentId = 0)
  770. {
  771. $mixedContent = $this->_getContent($iContentId);
  772. if($mixedContent === false)
  773. return false;
  774. list($iContentId, $aContentInfo) = $mixedContent;
  775. return BxDolAcl::getInstance()->getProfileMembership($aContentInfo['profile_id']);
  776. }
  777. public function serviceProfileFriends ($iContentId = 0)
  778. {
  779. $mixedContent = $this->_getContent($iContentId);
  780. if($mixedContent === false)
  781. return false;
  782. list($iContentId, $aContentInfo) = $mixedContent;
  783. bx_import('BxDolConnection');
  784. $s = $this->serviceBrowseConnectionsQuick ($aContentInfo['profile_id'], 'sys_profiles_friends', BX_CONNECTIONS_CONTENT_TYPE_CONTENT, true);
  785. if (!$s)
  786. return MsgBox(_t('_sys_txt_empty'));
  787. return $s;
  788. }
  789. public function serviceProfileSubscriptions ($iContentId = 0, $aParams = array())
  790. {
  791. $mixedContent = $this->_getContent($iContentId);
  792. if($mixedContent === false)
  793. return false;
  794. list($iContentId, $aContentInfo) = $mixedContent;
  795. bx_import('BxDolConnection');
  796. $aResult = $this->serviceBrowseConnectionsByType(array(
  797. 'profile_id' => $aContentInfo['profile_id'],
  798. 'object' => 'sys_profiles_subscriptions',
  799. 'type' => BX_CONNECTIONS_CONTENT_TYPE_CONTENT
  800. ), array(
  801. 'type' => isset($aParams['type']) ? $aParams['type'] : '',
  802. 'filter_menu' => isset($aParams['filter_menu']) ? $aParams['filter_menu'] : true,
  803. ));
  804. if(empty($aResult['content']))
  805. $aResult['content'] = MsgBox(_t('_sys_txt_empty'));
  806. return $aResult;
  807. }
  808. public function serviceProfileSubscribedMe ($iContentId = 0)
  809. {
  810. $mixedContent = $this->_getContent($iContentId);
  811. if($mixedContent === false)
  812. return false;
  813. list($iContentId, $aContentInfo) = $mixedContent;
  814. bx_import('BxDolConnection');
  815. $s = $this->serviceBrowseConnectionsQuick ($aContentInfo['profile_id'], 'sys_profiles_subscriptions', BX_CONNECTIONS_CONTENT_TYPE_INITIATORS);
  816. if (!$s)
  817. return MsgBox(_t('_sys_txt_empty'));
  818. return $s;
  819. }
  820. public function serviceProfileRelations ($iContentId = 0, $aParams = array())
  821. {
  822. $mixedContent = $this->_getContent($iContentId);
  823. if($mixedContent === false)
  824. return false;
  825. list($iContentId, $aContentInfo) = $mixedContent;
  826. bx_import('BxDolConnection');
  827. $s = $this->serviceBrowseRelationsQuick ($aContentInfo['profile_id'], 'sys_profiles_relations', BX_CONNECTIONS_CONTENT_TYPE_CONTENT, 1);
  828. if (!$s)
  829. return MsgBox(_t('_sys_txt_empty'));
  830. return $s;
  831. }
  832. public function serviceProfileRelatedMe ($iContentId = 0)
  833. {
  834. $mixedContent = $this->_getContent($iContentId);
  835. if($mixedContent === false)
  836. return false;
  837. list($iContentId, $aContentInfo) = $mixedContent;
  838. bx_import('BxDolConnection');
  839. $s = $this->serviceBrowseRelationsQuick ($aContentInfo['profile_id'], 'sys_profiles_relations', BX_CONNECTIONS_CONTENT_TYPE_INITIATORS, 1);
  840. if (!$s)
  841. return MsgBox(_t('_sys_txt_empty'));
  842. return $s;
  843. }
  844. /**
  845. * check enabled profile activation letter
  846. */
  847. public function serviceIsEnableProfileActivationLetter()
  848. {
  849. $CNF = &$this->_oConfig->CNF;
  850. return isset($CNF['PARAM_ENABLE_ACTIVATION_LETTER']) ? (bool)getParam($CNF['PARAM_ENABLE_ACTIVATION_LETTER']) : true;
  851. }
  852. public function serviceIsEnableRelations()
  853. {
  854. $sModule = $this->_oConfig->getName();
  855. $oRelations = BxDolConnection::getObjectInstance('sys_profiles_relations');
  856. return $oRelations->isRelationAvailableWithProfile($sModule) || $oRelations->isRelationAvailableFromProfile($sModule);
  857. }
  858. /**
  859. * For internal usage only.
  860. */
  861. public function serviceDeleteEntityService ($iContentId, $bDeleteWithContent = false)
  862. {
  863. return parent::serviceDeleteEntity ($iContentId, 'deleteDataService');
  864. }
  865. /**
  866. * Data for Notifications module
  867. */
  868. public function serviceGetNotificationsData()
  869. {
  870. $a = parent::serviceGetNotificationsData();
  871. $sModule = $this->_aModule['name'];
  872. $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');
  873. $a['settings'][] = array('group' => 'timeline_post', 'unit' => $sModule, 'action' => 'timeline_post_common', 'types' => array('follow_member'));
  874. $a['alerts'][] = array('unit' => $sModule, 'action' => 'timeline_post_common');
  875. return $a;
  876. }
  877. public function serviceGetNotificationsPost($aEvent)
  878. {
  879. $aResult = parent::serviceGetNotificationsVote($aEvent);
  880. if(empty($aResult) || !is_array($aResult) || !$this->serviceActAsProfile())
  881. return $aResult;
  882. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$aEvent['object_id'], $this->_oConfig->getName());
  883. if($oProfile !== false)
  884. $aResult['entry_author'] = $oProfile->id();
  885. return $aResult;
  886. }
  887. public function serviceGetNotificationsVote($aEvent)
  888. {
  889. $aResult = parent::serviceGetNotificationsVote($aEvent);
  890. if(empty($aResult) || !is_array($aResult) || !$this->serviceActAsProfile())
  891. return $aResult;
  892. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$aEvent['object_id'], $this->_oConfig->getName());
  893. if($oProfile !== false)
  894. $aResult['entry_author'] = $oProfile->id();
  895. return $aResult;
  896. }
  897. /**
  898. * Notification about new member requst in the group
  899. */
  900. public function serviceGetNotificationsTimelinePostCommon($aEvent)
  901. {
  902. $CNF = &$this->_oConfig->CNF;
  903. $iContentId = (int)$aEvent['object_id'];
  904. $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  905. if(!$oGroupProfile)
  906. return array();
  907. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  908. if(empty($aContentInfo) || !is_array($aContentInfo))
  909. return array();
  910. $aSubcontentInfo = BxDolService::call('bx_timeline', 'get_info', array((int)$aEvent['subobject_id'], false));
  911. if(empty($aSubcontentInfo) || !is_array($aSubcontentInfo))
  912. return array();
  913. $sSubentryUrl = BxDolService::call('bx_timeline', 'get_link', array((int)$aEvent['subobject_id']));
  914. $sSubentrySample = $aSubcontentInfo['title'];
  915. if(empty($sSubentrySample))
  916. $sSubentrySample = strmaxtextlen($aSubcontentInfo['description'], 20, '...');
  917. return array(
  918. 'entry_sample' => $CNF['T']['txt_sample_single'],
  919. 'entry_url' => $oGroupProfile->getUrl(),
  920. 'entry_caption' => $oGroupProfile->getDisplayName(),
  921. 'entry_author' => $oGroupProfile->id(),
  922. 'subentry_sample' => $sSubentrySample,
  923. 'subentry_url' => $sSubentryUrl,
  924. 'lang_key' => $CNF['T']['txt_ntfs_timeline_post_common'],
  925. );
  926. }
  927. /**
  928. * Data for Timeline module
  929. */
  930. public function serviceGetTimelineData()
  931. {
  932. $CNF = &$this->_oConfig->CNF;
  933. $sModule = $this->_aModule['name'];
  934. $aAlerts = array();
  935. $aHandlers = array();
  936. if(!empty($CNF['FIELD_PICTURE'])) {
  937. $aAlerts = array_merge($aAlerts, array(
  938. array('unit' => $sModule, 'action' => 'profile_picture_changed'),
  939. array('unit' => $sModule, 'action' => 'profile_picture_deleted')
  940. ));
  941. $aHandlers = array_merge($aHandlers, array(
  942. 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' => ''),
  943. array('group' => $sModule . '_profile_picture', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'profile_picture_deleted')
  944. ));
  945. }
  946. if(!empty($CNF['FIELD_COVER'])) {
  947. $aAlerts = array_merge($aAlerts, array(
  948. array('unit' => $sModule, 'action' => 'profile_cover_changed'),
  949. array('unit' => $sModule, 'action' => 'profile_cover_deleted')
  950. ));
  951. $aHandlers = array_merge($aHandlers, array(
  952. 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' => ''),
  953. array('group' => $sModule . '_profile_cover', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'profile_cover_deleted')
  954. ));
  955. }
  956. $aResult = array();
  957. if(!empty($aAlerts) && !empty($aHandlers))
  958. $aResult = array(
  959. 'handlers' => $aHandlers,
  960. 'alerts' => $aAlerts
  961. );
  962. return $aResult;
  963. }
  964. /**
  965. * Entry post for Timeline module
  966. */
  967. public function serviceGetTimelineProfilePicture($aEvent, $aBrowseParams = array())
  968. {
  969. $aResult = $this->_serviceGetTimelineProfileImage($aEvent, $aBrowseParams, array(
  970. 'stg' => 'OBJECT_STORAGE',
  971. 'trans' => array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_AVATAR'),
  972. 'trans_orig' => array('OBJECT_IMAGES_TRANSCODER_PICTURE', 'OBJECT_IMAGES_TRANSCODER_GALLERY'),
  973. 'txt_ss' => 'txt_sample_pp_single',
  974. 'txt_sswa' => 'txt_sample_pp_single_with_article',
  975. 'txt_sa' => 'txt_sample_pi_action',
  976. 'txt_sau' => 'txt_sample_pi_action_user'
  977. ));
  978. $aResult['allowed_view'] = array('module' => $this->_oConfig->getName(), 'method' => 'get_timeline_profile_picture_allowed_view');
  979. return $aResult;
  980. }
  981. public function serviceGetTimelineProfilePictureAllowedView($aEvent)
  982. {
  983. return $this->_serviceGetTimelineProfileImageAllowedView($aEvent);
  984. }
  985. public function serviceGetTimelineProfileCover($aEvent, $aBrowseParams = array())
  986. {
  987. $aResult = $this->_serviceGetTimelineProfileImage($aEvent, $aBrowseParams, array(
  988. 'stg' => 'OBJECT_STORAGE_COVER',
  989. 'trans' => array('OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_COVER_THUMB'),
  990. 'trans_orig' => array('OBJECT_IMAGES_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_GALLERY'),
  991. 'txt_ss' => 'txt_sample_pc_single',
  992. 'txt_sswa' => 'txt_sample_pc_single_with_article',
  993. 'txt_sa' => 'txt_sample_pi_action',
  994. 'txt_sau' => 'txt_sample_pi_action_user'
  995. ));
  996. $aResult['allowed_view'] = array('module' => $this->_oConfig->getName(), 'method' => 'get_timeline_profile_cover_allowed_view');
  997. return $aResult;
  998. }
  999. public function serviceGetTimelineProfileCoverAllowedView($aEvent)
  1000. {
  1001. return $this->_serviceGetTimelineProfileImageAllowedView($aEvent);
  1002. }
  1003. public function serviceGetConnectionButtonsTitles($iProfileId, $sConnectionsObject = 'sys_profiles_friends')
  1004. {
  1005. if (!isLogged())
  1006. return array();
  1007. if (!($oConn = BxDolConnection::getObjectInstance($sConnectionsObject)))
  1008. return array();
  1009. $CNF = $this->_oConfig->CNF;
  1010. if ($oConn->isConnectedNotMutual(bx_get_logged_profile_id(), $iProfileId)) {
  1011. return array(
  1012. 'add' => _t($CNF['T']['menu_item_title_befriend_sent']),
  1013. 'remove' => _t($CNF['T']['menu_item_title_unfriend_cancel_request']),
  1014. );
  1015. } elseif ($oConn->isConnectedNotMutual($iProfileId, bx_get_logged_profile_id())) {
  1016. return array(
  1017. 'add' => _t($CNF['T']['menu_item_title_befriend_confirm']),
  1018. 'remove' => _t($CNF['T']['menu_item_title_unfriend_reject_request']),
  1019. );
  1020. } elseif ($oConn->isConnected($iProfileId, bx_get_logged_profile_id(), true)) {
  1021. return array(
  1022. 'add' => '',
  1023. 'remove' => _t($CNF['T']['menu_item_title_unfriend']),
  1024. );
  1025. } else {
  1026. return array(
  1027. 'add' => _t($CNF['T']['menu_item_title_befriend']),
  1028. 'remove' => '',
  1029. );
  1030. }
  1031. }
  1032. // ====== PERMISSION METHODS
  1033. /**
  1034. * @see iBxDolProfileService::serviceCheckAllowedProfileView
  1035. */
  1036. public function serviceCheckAllowedProfileView($iContentId)
  1037. {
  1038. return $this->serviceCheckAllowedWithContent('View', $iContentId);
  1039. }
  1040. /**
  1041. * @see iBxDolProfileService::serviceCheckAllowedProfileContact
  1042. */
  1043. public function serviceCheckAllowedProfileContact($iContentId)
  1044. {
  1045. return $this->serviceCheckAllowedWithContent('Contact', $iContentId);
  1046. }
  1047. /**
  1048. * @see iBxDolProfileService::serviceCheckAllowedPostInProfile
  1049. */
  1050. public function serviceCheckAllowedPostInProfile($iContentId)
  1051. {
  1052. return $this->serviceCheckAllowedWithContent('Post', $iContentId);
  1053. }
  1054. /**
  1055. * @see iBxDolProfileService::serviceCheckSpacePrivacy
  1056. */
  1057. public function serviceCheckSpacePrivacy($iContentId)
  1058. {
  1059. return $this->serviceCheckAllowedProfileView($iContentId);
  1060. }
  1061. /**
  1062. * Check if the profile can be viewed.
  1063. *
  1064. * NOTE. This service should be used if it's needed to pass some specific values in
  1065. * $isPerformAction and $iProfileId parameters, otherwise it's recommended to use
  1066. * BxBaseModProfileModule::serviceCheckAllowedProfileView service method or
  1067. * BxDolProfile::checkAllowedProfileView method.
  1068. *
  1069. * @param type $aDataEntry - entry which the action will be performed for
  1070. * @param type $isPerformAction - perform or just check the action
  1071. * @param type $iProfileId - performer's profile ID
  1072. * @return integer - one of CHECK_ACTION_RESULT_XXX constants.
  1073. */
  1074. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  1075. {
  1076. if (!$iProfileId)
  1077. $iProfileId = $this->_iProfileId;
  1078. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  1079. if ($oProfile && $oProfile->id() == $iProfileId)
  1080. return CHECK_ACTION_RESULT_ALLOWED;
  1081. return parent::serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  1082. }
  1083. /**
  1084. * Check if posting (comment, post in Timeline) is available.
  1085. *
  1086. * NOTE. This service should be used if it's needed to pass some specific values in
  1087. * $isPerformAction and $iProfileId parameters, otherwise it's recommended to use
  1088. * BxBaseModProfileModule::serviceCheckAllowedPostInProfile service method or
  1089. * BxDolProfile::checkAllowedPostInProfile method.
  1090. *
  1091. * @param type $aDataEntry - entry which the action will be performed for
  1092. * @param type $isPerformAction - perform or just check the action
  1093. * @param type $iProfileId - performer's profile ID
  1094. * @return integer - one of CHECK_ACTION_RESULT_XXX constants.
  1095. */
  1096. public function serviceCheckAllowedPostForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  1097. {
  1098. $CNF = &$this->_oConfig->CNF;
  1099. if(!$iProfileId)
  1100. $iProfileId = $this->_iProfileId;
  1101. // check is view allowed
  1102. if(($mixedResult = $this->serviceCheckAllowedViewForProfile($aDataEntry, $isPerformAction, $iProfileId)) !== CHECK_ACTION_RESULT_ALLOWED)
  1103. return $mixedResult;
  1104. // moderator and owner always have access
  1105. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->getName());
  1106. if(($oProfile && $oProfile->id() == $iProfileId) || $this->_isModerator($isPerformAction))
  1107. return CHECK_ACTION_RESULT_ALLOWED;
  1108. // check privacy
  1109. if(!empty($CNF['OBJECT_PRIVACY_POST'])) {
  1110. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_POST']);
  1111. if($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  1112. return _t('_sys_access_denied_to_private_content');
  1113. }
  1114. // check alert to allow custom checks
  1115. $mixedResult = null;
  1116. bx_alert('system', 'check_allowed_post', 0, 0, array('module' => $this->getName(), 'content_info' => $aDataEntry, 'profile_id' => $iProfileId, 'override_result' => &$mixedResult));
  1117. if($mixedResult !== null)
  1118. return $mixedResult;
  1119. return CHECK_ACTION_RESULT_ALLOWED;
  1120. }
  1121. /**
  1122. * Check if profile can be contacted.
  1123. *
  1124. * NOTE. This service should be used if it's needed to pass some specific values in
  1125. * $isPerformAction and $iProfileId parameters, otherwise it's recommended to use
  1126. * BxBaseModProfileModule::serviceCheckAllowedProfileContact service method or
  1127. * BxDolProfile::checkAllowedProfileContact method.
  1128. *
  1129. * @param type $aDataEntry - entry which the action will be performed for
  1130. * @param type $isPerformAction - perform or just check the action
  1131. * @param type $iProfileId - performer's profile ID
  1132. * @return integer - one of CHECK_ACTION_RESULT_XXX constants.
  1133. */
  1134. public function serviceCheckAllowedContactForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  1135. {
  1136. $mixedResult = $this->_serviceCheckAllowedContactForProfile($aDataEntry, $isPerformAction, $iProfileId);
  1137. // call alert to allow custom checks
  1138. bx_alert('system', 'check_allowed_contact', 0, 0, array(
  1139. 'module' => $this->getName(),
  1140. 'content_info' => $aDataEntry,
  1141. 'profile_id' => $iProfileId,
  1142. 'override_result' => &$mixedResult
  1143. ));
  1144. return $mixedResult;
  1145. }
  1146. public function serviceSetViewProfileCover($oPage, $aProfileInfo)
  1147. {
  1148. $this->_oTemplate->setCover($oPage,$aProfileInfo);
  1149. }
  1150. /**
  1151. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1152. */
  1153. public function checkAllowedAdd ($isPerformAction = false)
  1154. {
  1155. $oAccount = BxDolAccount::getInstance();
  1156. if (!$oAccount || ($this->serviceActAsProfile() && $oAccount->isProfilesLimitReached()))
  1157. return _t('_sys_txt_access_denied');
  1158. return parent::checkAllowedAdd ($isPerformAction);
  1159. }
  1160. /**
  1161. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1162. */
  1163. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  1164. {
  1165. return $this->serviceCheckAllowedViewForProfile ($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 checkAllowedViewProfileImage ($aDataEntry, $isPerformAction = false)
  1171. {
  1172. $CNF = &$this->_oConfig->CNF;
  1173. // check privacy
  1174. if (empty($CNF['OBJECT_PRIVACY_VIEW']))
  1175. return CHECK_ACTION_RESULT_ALLOWED;
  1176. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  1177. if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']]) && !$oPrivacy->isPartiallyVisible($aDataEntry[$CNF['FIELD_ALLOW_VIEW_TO']]))
  1178. return _t('_sys_access_denied_to_private_content');
  1179. return CHECK_ACTION_RESULT_ALLOWED;
  1180. }
  1181. /**
  1182. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1183. */
  1184. public function checkAllowedViewCoverImage ($aDataEntry, $isPerformAction = false)
  1185. {
  1186. return $this->checkAllowedViewProfileImage($aDataEntry);
  1187. }
  1188. /**
  1189. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1190. */
  1191. public function checkAllowedPost ($aDataEntry, $isPerformAction = false)
  1192. {
  1193. return $this->serviceCheckAllowedPostForProfile ($aDataEntry, $isPerformAction);
  1194. }
  1195. /**
  1196. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1197. */
  1198. public function checkAllowedContact ($aDataEntry, $isPerformAction = false)
  1199. {
  1200. return $this->serviceCheckAllowedContactForProfile ($aDataEntry, $isPerformAction);
  1201. }
  1202. /**
  1203. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1204. */
  1205. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  1206. {
  1207. // moderator always has access
  1208. if ($this->_isModerator($isPerformAction))
  1209. return CHECK_ACTION_RESULT_ALLOWED;
  1210. // owner (checked by account instead of author!) always have access
  1211. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name']);
  1212. if (!$oProfile)
  1213. return _t('_sys_txt_error_occured');
  1214. if ($oProfile->id() == $this->_iProfileId || $oProfile->getAccountId() == $this->_iAccountId)
  1215. return CHECK_ACTION_RESULT_ALLOWED;
  1216. return _t('_sys_txt_access_denied');
  1217. }
  1218. /**
  1219. * Check if user can change cover image
  1220. */
  1221. public function checkAllowedChangeCover ($aDataEntry, $isPerformAction = false)
  1222. {
  1223. // moderator always has access
  1224. if ($this->_isModerator($isPerformAction))
  1225. return CHECK_ACTION_RESULT_ALLOWED;
  1226. // owner (checked by account instead of author!) always have access
  1227. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name']);
  1228. if (!$oProfile)
  1229. return _t('_sys_txt_error_occured');
  1230. if ($oProfile->id() == $this->_iProfileId || $oProfile->getAccountId() == $this->_iAccountId)
  1231. return CHECK_ACTION_RESULT_ALLOWED;
  1232. return _t('_sys_txt_access_denied');
  1233. }
  1234. /**
  1235. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1236. */
  1237. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  1238. {
  1239. // moderator always has access
  1240. if ($this->_isModerator($isPerformAction))
  1241. return CHECK_ACTION_RESULT_ALLOWED;
  1242. // owner (checked by account instead of author!) always have access
  1243. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  1244. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name'], $isPerformAction);
  1245. if (!$oProfile)
  1246. return _t('_sys_txt_error_occured');
  1247. if (($oProfile->id() == $this->_iProfileId || $oProfile->getAccountId() == $this->_iAccountId) && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  1248. return CHECK_ACTION_RESULT_ALLOWED;
  1249. return _t('_sys_txt_access_denied');
  1250. }
  1251. /**
  1252. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1253. */
  1254. public function checkAllowedViewMoreMenu (&$aDataEntry, $isPerformAction = false)
  1255. {
  1256. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']);
  1257. if (!$oMenu || !$oMenu->getCode())
  1258. return _t('_sys_txt_access_denied');
  1259. return CHECK_ACTION_RESULT_ALLOWED;
  1260. }
  1261. /**
  1262. * Compose differs from Contact. For example, a user should NOT be able to start conversation (compose)
  1263. * with himself but he should be able to view conversation page where he is one of the participants.
  1264. *
  1265. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1266. */
  1267. public function checkAllowedCompose(&$aDataEntry, $isPerformAction = false)
  1268. {
  1269. $CNF = &$this->_oConfig->CNF;
  1270. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->getName());
  1271. if($oProfile && $oProfile->id() == $this->_iProfileId)
  1272. return _t('_sys_txt_access_denied');
  1273. return $this->checkAllowedContact($aDataEntry, $isPerformAction);
  1274. }
  1275. /**
  1276. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1277. */
  1278. public function checkAllowedFriendAdd (&$aDataEntry, $isPerformAction = false)
  1279. {
  1280. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', true, false);
  1281. }
  1282. /**
  1283. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1284. */
  1285. public function checkAllowedFriendRemove (&$aDataEntry, $isPerformAction = false)
  1286. {
  1287. if (CHECK_ACTION_RESULT_ALLOWED === $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', false, true, true))
  1288. return CHECK_ACTION_RESULT_ALLOWED;
  1289. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_friends', false, true, false);
  1290. }
  1291. /**
  1292. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1293. */
  1294. public function checkAllowedRelationAdd (&$aDataEntry, $isPerformAction = false)
  1295. {
  1296. if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedView($aDataEntry)))
  1297. return $sMsg;
  1298. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_relations', false, false);
  1299. }
  1300. /**
  1301. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1302. */
  1303. public function checkAllowedRelationRemove (&$aDataEntry, $isPerformAction = false)
  1304. {
  1305. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_relations', false, true);
  1306. }
  1307. public function checkAllowedRelationsView (&$aDataEntry, $isPerformAction = false)
  1308. {
  1309. $sResult = _t('_sys_txt_access_denied');
  1310. $sModule = $this->_oConfig->getName();
  1311. $oRelations = BxDolConnection::getObjectInstance('sys_profiles_relations');
  1312. if(!$oRelations->isRelationAvailableWithProfile($sModule) && !$oRelations->isRelationAvailableFromProfile($sModule))
  1313. return $sResult;
  1314. if(empty($aDataEntry) || !is_array($aDataEntry))
  1315. return $sResult;
  1316. return CHECK_ACTION_RESULT_ALLOWED;
  1317. }
  1318. /**
  1319. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1320. */
  1321. public function checkAllowedSubscribeAdd(&$aDataEntry, $isPerformAction = false)
  1322. {
  1323. $mixedResult = $this->_modProfileCheckAllowedSubscribeAdd($aDataEntry, $isPerformAction);
  1324. // call alert to allow custom checks
  1325. bx_alert('system', 'check_allowed_subscribe_add', 0, 0, array(
  1326. 'module' => $this->getName(),
  1327. 'content_info' => $aDataEntry,
  1328. 'profile_id' => bx_get_logged_profile_id(),
  1329. 'override_result' => &$mixedResult
  1330. ));
  1331. return $mixedResult;
  1332. }
  1333. /**
  1334. * Note. Is mainly needed for internal usage. Access level is 'public' to allow outer calls from alerts.
  1335. */
  1336. public function _modProfileCheckAllowedSubscribeAdd(&$aDataEntry, $isPerformAction = false)
  1337. {
  1338. if(($sMsg = $this->checkAllowedView($aDataEntry)) !== CHECK_ACTION_RESULT_ALLOWED)
  1339. return $sMsg;
  1340. return $this->_checkAllowedConnect($aDataEntry, $isPerformAction, 'sys_profiles_subscriptions', false, false);
  1341. }
  1342. /**
  1343. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1344. */
  1345. public function checkAllowedSubscribeRemove (&$aDataEntry, $isPerformAction = false)
  1346. {
  1347. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_subscriptions', false, true);
  1348. }
  1349. public function checkAllowedSubscriptionsView (&$aDataEntry, $isPerformAction = false)
  1350. {
  1351. $CNF = &$this->_oConfig->CNF;
  1352. $sResult = _t('_sys_txt_access_denied');
  1353. if(empty($aDataEntry) || !is_array($aDataEntry))
  1354. return $sResult;
  1355. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->_aModule['name']);
  1356. if(!$oProfile || ($oProfile->id() != $this->_iProfileId && $this->_oDb->getParam($CNF['PARAM_PUBLIC_SBSN']) != 'on' && $this->_oDb->getParam($CNF['PARAM_PUBLIC_SBSD']) != 'on'))
  1357. return $sResult;
  1358. return CHECK_ACTION_RESULT_ALLOWED;
  1359. }
  1360. public function checkMyself($iContentId)
  1361. {
  1362. $iLogged = (int)bx_get_logged_profile_id();
  1363. if(empty($iLogged))
  1364. return false;
  1365. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->_oConfig->getName());
  1366. if(!$oProfile)
  1367. return false;
  1368. return $oProfile->id() == $iLogged;
  1369. }
  1370. protected function _serviceCheckAllowedContactForProfile($aDataEntry, $isPerformAction = false, $iProfileId = false)
  1371. {
  1372. $CNF = &$this->_oConfig->CNF;
  1373. if(!$iProfileId)
  1374. $iProfileId = $this->_iProfileId;
  1375. /*
  1376. * allow to 'contact myself'. It's needed to allow a user to view conversation page
  1377. * where he is one of the participants.
  1378. */
  1379. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->getName());
  1380. if($oProfile && $oProfile->id() == $iProfileId)
  1381. return CHECK_ACTION_RESULT_ALLOWED;
  1382. // moderator always has access
  1383. if($this->_isModeratorForProfile($isPerformAction, $iProfileId))
  1384. return CHECK_ACTION_RESULT_ALLOWED;
  1385. // check privacy
  1386. if(!empty($CNF['OBJECT_PRIVACY_CONTACT'])) {
  1387. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_CONTACT']);
  1388. if($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  1389. return _t('_sys_access_denied_to_private_content');
  1390. }
  1391. return CHECK_ACTION_RESULT_ALLOWED;
  1392. }
  1393. // ====== COMMON METHODS
  1394. public function alertAfterAdd($aContentInfo)
  1395. {
  1396. $CNF = &$this->_oConfig->CNF;
  1397. $sModule = $this->getName();
  1398. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  1399. $aParams = array();
  1400. if(isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]))
  1401. $aParams['privacy_view'] = $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']];
  1402. bx_alert($sModule, 'added', $iContentId, false, $aParams);
  1403. }
  1404. public function alertAfterEdit($aContentInfo)
  1405. {
  1406. $CNF = &$this->_oConfig->CNF;
  1407. $sModule = $this->getName();
  1408. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  1409. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $sModule);
  1410. bx_alert($sModule, 'edited', $iContentId);
  1411. bx_alert('profile', 'edit', $oProfile->id(), 0, array('content' => $iContentId, 'module' => $sModule));
  1412. }
  1413. public function getProfileByCurrentUrl ()
  1414. {
  1415. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  1416. if ($iProfileId)
  1417. return BxDolProfile::getInstance($iProfileId);
  1418. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1419. if ($iContentId)
  1420. return BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  1421. return false;
  1422. }
  1423. public function getEntryImageData($aContentInfo, $sField = 'FIELD_PICTURE', $aTranscoders = array())
  1424. {
  1425. return parent::getEntryImageData($aContentInfo, $sField, $aTranscoders);
  1426. }
  1427. // ====== PROTECTED METHODS
  1428. protected function _checkAllowedConnect (&$aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap = false)
  1429. {
  1430. if (!$this->_iProfileId)
  1431. return _t('_sys_txt_access_denied');
  1432. $CNF = &$this->_oConfig->CNF;
  1433. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->_aModule['name']);
  1434. if (!$oProfile || $oProfile->id() == $this->_iProfileId)
  1435. return _t('_sys_txt_access_denied');
  1436. return BxDolConnection::getObjectInstance($sObjConnection)->checkAllowedConnect ($this->_iProfileId, $oProfile->id(), $isPerformAction, $isMutual, $isInvertResult, $isSwap);
  1437. }
  1438. protected function _buildRssParams($sMode, $aArgs)
  1439. {
  1440. $aParams = array ();
  1441. $sMode = bx_process_input($sMode);
  1442. switch ($sMode) {
  1443. case 'connections':
  1444. $aParams = array(
  1445. 'object' => isset($aArgs[0]) ? $aArgs[0] : '',
  1446. 'type' => isset($aArgs[1]) ? $aArgs[1] : '',
  1447. 'profile' => isset($aArgs[2]) ? (int)$aArgs[2] : 0,
  1448. 'mutual' => isset($aArgs[3]) ? (int)$aArgs[3] : 0,
  1449. 'profile2' => isset($aArgs[4]) ? (int)$aArgs[4] : 0,
  1450. );
  1451. break;
  1452. }
  1453. return $aParams;
  1454. }
  1455. protected function _serviceBrowseQuick($aProfiles, $iStart = 0, $iLimit = 4, $aAdditionalParams = array())
  1456. {
  1457. // get paginate object
  1458. $oPaginate = new BxTemplPaginate(array(
  1459. 'on_change_page' => "return !loadDynamicBlockAutoPaginate(this, '{start}', '{per_page}', " . bx_js_string(json_encode($aAdditionalParams)) . ");",
  1460. 'num' => count($aProfiles),
  1461. 'per_page' => $iLimit,
  1462. 'start' => $iStart,
  1463. ));
  1464. // remove last item from connection array, because we've got one more item for pagination calculations only
  1465. if (count($aProfiles) > $iLimit)
  1466. array_pop($aProfiles);
  1467. // get profiles HTML
  1468. $s = '';
  1469. foreach ($aProfiles as $mixedProfile) {
  1470. $bProfile = is_array($mixedProfile);
  1471. $oProfile = BxDolProfile::getInstance($bProfile ? (int)$mixedProfile['id'] : (int)$mixedProfile);
  1472. if(!$oProfile)
  1473. continue;
  1474. $aUnitParams = array('template' => array('name' => 'unit', 'size' => 'thumb'));
  1475. if(BxDolModule::getInstance($oProfile->getModule()) instanceof BxBaseModGroupsModule)
  1476. $aUnitParams['template']['name'] = 'unit_wo_cover';
  1477. if($bProfile && is_array($mixedProfile['info']))
  1478. $aUnitParams['template']['vars'] = $mixedProfile['info'];
  1479. $s .= $oProfile->getUnit(0, $aUnitParams);
  1480. }
  1481. // return profiles + paginate
  1482. return $s . (!$iStart && $oPaginate->getNum() <= $iLimit ? '' : $oPaginate->getSimplePaginate());
  1483. }
  1484. protected function _serviceGetTimelineProfileImage($aEvent, $aBrowseParams, $aBuildParams)
  1485. {
  1486. $CNF = &$this->_oConfig->CNF;
  1487. $aFileInfo = BxDolStorage::getObjectInstance($CNF[$aBuildParams['stg']])->getFile((int)$aEvent['object_id']);
  1488. if(empty($aFileInfo) || !is_array($aFileInfo))
  1489. return false;
  1490. $aEventContent = unserialize($aEvent['content']);
  1491. if(!is_array($aEventContent) || empty($aEventContent['content']))
  1492. return false;
  1493. $aContentInfo = $this->_oDb->getContentInfoById($aEventContent['content']);
  1494. if(empty($aContentInfo) || !is_array($aContentInfo))
  1495. return false;
  1496. $oProfile = BxDolProfile::getInstanceMagic($aContentInfo['profile_id']);
  1497. if (!$oProfile->isActive())
  1498. return false;
  1499. $sUserName = $oProfile->getDisplayName();
  1500. $sSample = isset($CNF['T'][$aBuildParams['txt_sswa']]) ? $CNF['T'][$aBuildParams['txt_sswa']] : $CNF['T'][$aBuildParams['txt_ss']];
  1501. //--- Title & Description
  1502. $sTitle = !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '';
  1503. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TEXT']]))
  1504. $sTitle = $aContentInfo[$CNF['FIELD_TEXT']];
  1505. $sDescription = _t($CNF['T'][$aBuildParams['txt_sau']], $sUserName, _t($sSample));
  1506. return array(
  1507. 'owner_id' => $aEvent['owner_id'],
  1508. 'object_owner_id' => $aContentInfo['profile_id'],
  1509. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  1510. 'sample' => $sSample,
  1511. 'sample_wo_article' => $CNF['T'][$aBuildParams['txt_ss']],
  1512. 'sample_action' => isset($CNF['T'][$aBuildParams['txt_sa']]) ? $CNF['T'][$aBuildParams['txt_sa']] : '',
  1513. 'url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]),
  1514. 'content' => $this->_getContentForTimelineProfileImage($aEvent, $aBrowseParams, $aBuildParams, $aContentInfo, $aFileInfo), //a string to display or array to parse default template before displaying.
  1515. 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
  1516. 'views' => '',
  1517. 'votes' => '',
  1518. 'scores' => '',
  1519. 'reports' => '',
  1520. 'comments' => '',
  1521. 'title' => $sTitle, //may be empty.
  1522. 'description' => $sDescription //may be empty.
  1523. );
  1524. }
  1525. protected function _serviceGetTimelineProfileImageAllowedView($aEvent)
  1526. {
  1527. $sError = _t('_sys_access_denied_to_private_content');
  1528. if(empty($aEvent['content']) || !is_array($aEvent['content']) || empty($aEvent['content']['id']))
  1529. return $sError;
  1530. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['content']['id']);
  1531. if(empty($aContentInfo) || !is_array($aContentInfo))
  1532. return $sError;
  1533. return $this->serviceCheckAllowedViewForProfile($aContentInfo);
  1534. }
  1535. protected function _getContentForTimelineProfileImage($aEvent, $aBrowseParams, $aBuildParams, $aContentInfo, $aFileInfo)
  1536. {
  1537. $CNF = &$this->_oConfig->CNF;
  1538. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]);
  1539. //--- Image(s)
  1540. $sImage = $this->_oConfig->getImageUrl($aFileInfo['id'], $aBuildParams['trans']);
  1541. $sImageOrig = $this->_oConfig->getImageUrl($aFileInfo['id'], $aBuildParams['trans_orig']);
  1542. if(!empty($sImage)) {
  1543. if(empty($sImageOrig))
  1544. $sImageOrig = $sImage;
  1545. $a = array('id' => $aFileInfo['id'], 'url' => $sUrl, 'src' => $sImage);
  1546. if (CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedView($aContentInfo))
  1547. $a['src_orig'] = $sImageOrig;
  1548. $aImages = array($a);
  1549. }
  1550. return array(
  1551. 'sample' => isset($CNF['T'][$aBuildParams['txt_sswa']]) ? $CNF['T'][$aBuildParams['txt_sswa']] : $CNF['T'][$aBuildParams['txt_ss']],
  1552. 'sample_wo_article' => $CNF['T'][$aBuildParams['txt_ss']],
  1553. 'sample_action' => isset($CNF['T'][$aBuildParams['txt_sa']]) ? $CNF['T'][$aBuildParams['txt_sa']] : '',
  1554. 'id' => $aContentInfo[$CNF['FIELD_ID']],
  1555. 'url' => $sUrl,
  1556. 'title' => '',
  1557. 'text' => '',
  1558. 'images' => $aImages,
  1559. 'videos' => array()
  1560. );
  1561. }
  1562. protected function _entityComments($sObject, $iId = 0)
  1563. {
  1564. if(!$iId)
  1565. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1566. if(!$iId)
  1567. $iId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  1568. if(!$iId)
  1569. return false;
  1570. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  1571. if(!$oCmts || !$oCmts->isEnabled())
  1572. return false;
  1573. return $oCmts->getCommentsBlock(array(), array('in_designbox' => false));
  1574. }
  1575. protected function _getContent($iContentId = 0, $sFuncGetContent = 'getContentInfoById')
  1576. {
  1577. if(!$iContentId && bx_get('id') === false && bx_get('profile_id') !== false) {
  1578. $oProfile = BxDolProfile::getInstance((int)bx_get('profile_id'));
  1579. if($oProfile)
  1580. $iContentId = $oProfile->getContentId();
  1581. }
  1582. return parent::_getContent($iContentId, $sFuncGetContent);
  1583. }
  1584. /**
  1585. * Returns list of members by mode with limited number of records for React Jot
  1586. * @param string $sMode
  1587. * @param int $iStart
  1588. * @param int $iPerPage
  1589. * @return mixed
  1590. */
  1591. public function serviceGetMembers($sMode = 'active', $iStart = 0, $iPerPage = 10){
  1592. bx_import('SearchResult', $this->_aModule);
  1593. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  1594. $o = new $sClass($sMode);
  1595. $o -> aCurrent['paginate'] = array('perPage' => $iPerPage, 'forceStart' => $iStart);
  1596. return $o -> getSearchData();
  1597. }
  1598. }
  1599. /** @} */