1
0

BxBaseModProfileModule.php 74 KB

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