BxBaseModProfileModule.php 75 KB

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