BxBaseModProfileModule.php 76 KB

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