1
0

BxBaseModProfileModule.php 75 KB

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