BxBaseModProfileModule.php 70 KB

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