1
0

BxBaseModGroupsModule.php 102 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559
  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 BaseGroups Base classes for groups modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. define('BX_BASE_MOD_GROUPS_MMODE_MULTI_ROLES', 'multi_roles');
  12. define('BX_BASE_MOD_GROUPS_ROLE_COMMON', 0);
  13. define('BX_BASE_MOD_GROUPS_ROLE_ADMINISTRATOR', 1);
  14. define('BX_BASE_MOD_GROUPS_ROLE_MODERATOR', 2);
  15. define('BX_BASE_MOD_GROUPS_ACTION_EDIT', 'edit');
  16. define('BX_BASE_MOD_GROUPS_ACTION_CHANGE_SETTINGS', 'change_settings');
  17. define('BX_BASE_MOD_GROUPS_ACTION_CHANGE_COVER', 'change_cover');
  18. define('BX_BASE_MOD_GROUPS_ACTION_INVITE', 'invite');
  19. define('BX_BASE_MOD_GROUPS_ACTION_MANAGE_FANS', 'manage_fans');
  20. define('BX_BASE_MOD_GROUPS_ACTION_MANAGE_ROLES', 'manage_roles');
  21. define('BX_BASE_MOD_GROUPS_ACTION_DELETE', 'delete');
  22. define('BX_BASE_MOD_GROUPS_ACTION_EDIT_CONTENT', 'edit_any');
  23. define('BX_BASE_MOD_GROUPS_ACTION_DELETE_CONTENT', 'delete_any');
  24. define('BX_BASE_MOD_GROUPS_ACTION_TIMELINE_POST_PIN', 'pin'); //for timeline posts only
  25. define('BX_BASE_MOD_GROUPS_PERIOD_UNIT_DAY', 'day');
  26. define('BX_BASE_MOD_GROUPS_PERIOD_UNIT_WEEK', 'week');
  27. define('BX_BASE_MOD_GROUPS_PERIOD_UNIT_MONTH', 'month');
  28. define('BX_BASE_MOD_GROUPS_PERIOD_UNIT_YEAR', 'year');
  29. /**
  30. * Groups profiles module.
  31. */
  32. class BxBaseModGroupsModule extends BxBaseModProfileModule
  33. {
  34. function __construct(&$aModule)
  35. {
  36. parent::__construct($aModule);
  37. $CNF = &$this->_oConfig->CNF;
  38. if(isset($CNF['FIELD_PUBLISHED']))
  39. $this->_aSearchableNamesExcept = array_merge($this->_aSearchableNamesExcept, array(
  40. $CNF['FIELD_PUBLISHED'],
  41. ));
  42. }
  43. /**
  44. * Get possible recipients for start conversation form
  45. */
  46. public function actionAjaxGetInitialMembers ()
  47. {
  48. $sTerm = bx_get('term');
  49. $a = BxDolService::call('system', 'profiles_search', [$sTerm, ['module' => $this->_oConfig->getName()]], 'TemplServiceProfiles');
  50. header('Content-Type:text/javascript; charset=utf-8');
  51. echo(json_encode($a));
  52. }
  53. public function serviceGetInitialMembers ($sParams)
  54. {
  55. $aOptions = json_decode($sParams, true);
  56. if (!$sParams || !isset($aOptions['term']))
  57. return [];
  58. $a = BxDolService::call('system', 'profiles_search', [$aOptions['term'], ['module' => $this->_oConfig->getName()]], 'TemplServiceProfiles');
  59. return $a;
  60. }
  61. /**
  62. * Process Process Invitation
  63. */
  64. public function actionProcessInvite ($sKey, $iGroupProfileId, $bAccept)
  65. {
  66. $aData = $this->_oDb->getInviteByKey($sKey, $iGroupProfileId);
  67. if (isset($aData['invited_profile_id'])){
  68. $CNF = &$this->_oConfig->CNF;
  69. if (!isset($CNF['OBJECT_CONNECTIONS']) || !($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
  70. return '';
  71. $iInvitedProfileId = $aData['invited_profile_id'];
  72. if ($iInvitedProfileId != bx_get_logged_profile_id())
  73. return '';
  74. if ($bAccept){
  75. if($oConnection && !$oConnection->isConnected($iInvitedProfileId, $iGroupProfileId)){
  76. $oConnection->addConnection($iInvitedProfileId, $iGroupProfileId);
  77. $oConnection->addConnection($iGroupProfileId, $iInvitedProfileId);
  78. }
  79. }
  80. $this->_oDb->deleteInviteByKey($sKey, $iGroupProfileId);
  81. }
  82. }
  83. public function actionCheckName()
  84. {
  85. $CNF = &$this->_oConfig->CNF;
  86. $sName = bx_process_input(bx_get('name'));
  87. if(empty($sName))
  88. return echoJson(array());
  89. $sResult = '';
  90. $iId = (int)bx_get('id');
  91. if(!empty($iId)) {
  92. $aPrice = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iId));
  93. if(strcmp($sName, $aPrice[$CNF['FIELD_PRICE_NAME']]) == 0)
  94. $sResult = $sName;
  95. }
  96. echoJson(array(
  97. 'name' => !empty($sResult) ? $sResult : $this->_oConfig->getPriceName($sName)
  98. ));
  99. }
  100. public function actionGetQuestionnaire()
  101. {
  102. $sSource = '';
  103. if(($sSource = bx_get('s')) !== false)
  104. $sSource = bx_process_url_param($sSource);
  105. $sObject = '';
  106. if(($sObject = bx_get('o')) !== false)
  107. $sObject = bx_process_url_param($sObject);
  108. $sAction = '';
  109. if(($sAction = bx_get('a')) !== false)
  110. $sAction = bx_process_url_param($sAction);
  111. $iContentProfileId = 0;
  112. if(($iContentProfileId = bx_get('cpi')) !== false)
  113. $iContentProfileId = (int)$iContentProfileId;
  114. echoJson($this->serviceGetQuestionnaire($sSource, $sObject, $sAction, $iContentProfileId));
  115. }
  116. public function serviceManageTools($sType = 'common')
  117. {
  118. $this->_oTemplate->addJs(['modules/base/groups/js/|manage_tools.js']);
  119. return parent::serviceManageTools($sType);
  120. }
  121. public function decodeDataAPI($aData, $aParams = [])
  122. {
  123. $CNF = $this->_oConfig->CNF;
  124. $aResult = parent::decodeDataAPI($aData, $aParams);
  125. if(isset($aParams['template']) && $aParams['template'] == 'unit_wo_info')
  126. return $aResult;
  127. if(getParam('sys_api_conn_in_prof_units') == 'on' && ($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])) !== false) {
  128. $oProfile = BxDolProfile::getInstanceByContentAndType($aData[$CNF['FIELD_ID']], $this->_aModule['name']);
  129. $aResult['members_count'] = $oConnection->getConnectedInitiatorsCount($oProfile->id(), false);
  130. $aResult['members_list'] = $oConnection->getConnectedListAPI($oProfile->id(), false, BX_CONNECTIONS_CONTENT_TYPE_INITIATORS);
  131. }
  132. return array_merge($aResult, [
  133. 'author_data' => BxDolProfile::getData($aData[$CNF['FIELD_AUTHOR']]),
  134. 'visibility' => $aData[$CNF['FIELD_ALLOW_VIEW_TO']]
  135. ]);
  136. }
  137. public function serviceGetMenuAddonManageTools()
  138. {
  139. $CNF = &$this->_oConfig->CNF;
  140. $aResult = parent::serviceGetMenuAddonManageTools();
  141. if(!empty($CNF['FIELD_STATUS_ADMIN']))
  142. $aResult['counter1_value'] = $this->_oDb->getEntriesNumByParams([[
  143. 'key' => $CNF['FIELD_STATUS_ADMIN'],
  144. 'value' => BX_BASE_MOD_GENERAL_STATUS_PENDING,
  145. 'operator' => '='
  146. ]]);
  147. return $aResult;
  148. }
  149. public function serviceGetOptionsMembersMode()
  150. {
  151. $CNF = &$this->_oConfig->CNF;
  152. return array(
  153. array('key' => '', 'value' => _t('_None')),
  154. array('key' => BX_BASE_MOD_GROUPS_MMODE_MULTI_ROLES, 'value' => _t($CNF['T']['option_members_mode_' . BX_BASE_MOD_GROUPS_MMODE_MULTI_ROLES])),
  155. );
  156. }
  157. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  158. {
  159. if(empty($sUnitTemplate))
  160. $sUnitTemplate = 'unit.html';
  161. return parent::serviceGetSearchResultUnit($iContentId, $sUnitTemplate);
  162. }
  163. /**
  164. * @see BxBaseModProfileModule::serviceGetSpaceTitle
  165. */
  166. public function serviceGetSpaceTitle()
  167. {
  168. return _t($this->_oConfig->CNF['T']['txt_sample_single']);
  169. }
  170. /**
  171. * @see iBxDolProfileService::serviceGetParticipatingProfiles
  172. */
  173. public function serviceGetParticipatingProfiles($iProfileId, $aConnectionObjects = false)
  174. {
  175. if (isset($this->_oConfig->CNF['OBJECT_CONNECTIONS'])){
  176. $aConnectionObjects = array($this->_oConfig->CNF['OBJECT_CONNECTIONS'], 'sys_profiles_subscriptions');
  177. return parent::serviceGetParticipatingProfiles($iProfileId, $aConnectionObjects);
  178. }
  179. return parent::serviceGetParticipatingProfiles($iProfileId);
  180. }
  181. public function serviceGetSafeServices()
  182. {
  183. return array_merge(parent::serviceGetSafeServices(), [
  184. 'GetQuestionnaire' => '',
  185. 'GetInitialMembers' => '',
  186. 'EntityInvite' => '',
  187. ]);
  188. }
  189. /**
  190. * Check if this module entry can be used as profile
  191. */
  192. public function serviceActAsProfile ()
  193. {
  194. return false;
  195. }
  196. /**
  197. * Check if this module is group profile
  198. */
  199. public function serviceIsGroupProfile ()
  200. {
  201. return true;
  202. }
  203. public function serviceIsEnableForContext($iProfileId = 0)
  204. {
  205. $CNF = &$this->_oConfig->CNF;
  206. $bRet = true;
  207. $sCnfKey = 'ENABLE_FOR_CONTEXT_IN_MODULES';
  208. if(empty($iProfileId) || empty($CNF[$sCnfKey]) || !is_array($CNF[$sCnfKey]))
  209. $bRet = false;
  210. $oProfile = null;
  211. if($bRet && !($oProfile = BxDolProfile::getInstance($iProfileId)))
  212. $bRet = false;
  213. if($bRet && !in_array($oProfile->getModule(), $CNF[$sCnfKey]))
  214. $bRet = false;
  215. bx_alert($this->getName(), 'is_enabled_for_context', $iProfileId, false, [
  216. 'cnf' => $CNF,
  217. 'module' => $this,
  218. 'context_profile' => $oProfile,
  219. 'result' => &$bRet
  220. ]);
  221. return $bRet;
  222. }
  223. /**
  224. * check if provided profile is member of the group
  225. */
  226. public function serviceIsFan ($iGroupProfileId, $iProfileId = false)
  227. {
  228. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  229. return $oGroupProfile !== false && $this->isFan($oGroupProfile->getContentId(), $iProfileId);
  230. }
  231. /**
  232. * check if provided profile is admin of the group
  233. */
  234. public function serviceIsAdmin ($iGroupProfileId, $iProfileId = false)
  235. {
  236. if(!$iProfileId)
  237. $iProfileId = bx_get_logged_profile_id();
  238. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  239. if(!$oGroupProfile)
  240. return false;
  241. $iGroupContentId = $oGroupProfile->getContentId();
  242. if(!$this->isFan($iGroupContentId, $iProfileId))
  243. return false;
  244. $aGroupContentInfo = $this->_oDb->getContentInfoById($iGroupContentId);
  245. return $this->_oDb->isAdmin($iGroupProfileId, $iProfileId, $aGroupContentInfo);
  246. }
  247. public function serviceGetAdminRole($iGroupProfileId, $iProfileId = false)
  248. {
  249. if(!$iProfileId)
  250. $iProfileId = bx_get_logged_profile_id();
  251. if(!$this->serviceIsAdmin($iGroupProfileId, $iProfileId))
  252. return 0;
  253. return $this->_oDb->getRole($iGroupProfileId, $iProfileId);
  254. }
  255. /*
  256. * Get context (group) advanced members who can perform the specified action.
  257. * If 'Roles' are disabled for the context then all context admins are returned.
  258. */
  259. public function serviceGetAdminsByAction($iGroupProfileId, $mixedAction)
  260. {
  261. if(!$this->_oConfig->isAdmins())
  262. return [];
  263. $aGroupContentInfo = $this->_oDb->getContentInfoByProfileId($iGroupProfileId);
  264. if(empty($aGroupContentInfo) || !is_array($aGroupContentInfo))
  265. return [];
  266. $aAdmins = $this->_oDb->getAdmins($iGroupProfileId);
  267. if(!$this->_oConfig->isRoles())
  268. return $aAdmins;
  269. if(!is_array($mixedAction))
  270. $mixedAction = [$mixedAction];
  271. $aResult = [];
  272. foreach($mixedAction as $sAction)
  273. foreach($aAdmins as $iAdminProfileId)
  274. if(!in_array($iAdminProfileId, $aResult) && $this->isAllowedActionByRole($sAction, $aGroupContentInfo, $iGroupProfileId, $iAdminProfileId))
  275. $aResult[] = $iAdminProfileId;
  276. return $aResult;
  277. }
  278. public function serviceGetAdminsToManageContent($iGroupProfileId)
  279. {
  280. return $this->serviceGetAdminsByAction($iGroupProfileId, [
  281. BX_BASE_MOD_GROUPS_ACTION_EDIT_CONTENT,
  282. BX_BASE_MOD_GROUPS_ACTION_DELETE_CONTENT
  283. ]);
  284. }
  285. /**
  286. * Delete profile from fans and admins tables
  287. * @param $iProfileId profile id
  288. */
  289. public function serviceDeleteProfileFromFansAndAdmins ($iProfileId)
  290. {
  291. $CNF = &$this->_oConfig->CNF;
  292. $this->_oDb->deleteAdminsByProfileId($iProfileId);
  293. if (isset($CNF['OBJECT_CONNECTIONS']) && ($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
  294. $oConnection->onDeleteInitiatorAndContent($iProfileId);
  295. }
  296. /**
  297. * Reset group's author for particular group
  298. * @param $iContentId group id
  299. * @parem $iAuthorId new author profile ID
  300. * @return false of error, or number of updated records on success
  301. */
  302. public function serviceReassignEntityAuthor ($iContentId, $iAuthorId = 0)
  303. {
  304. $aContentInfo = $this->_oDb->getContentInfoById((int)$iContentId);
  305. if (!$aContentInfo)
  306. return false;
  307. if (empty($iAuthorId)) {
  308. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  309. if (!$oGroupProfile)
  310. return false;
  311. $aAdmins = $this->_oDb->getAdmins($oGroupProfile->id());
  312. if($aAdmins)
  313. $iAuthorId = array_pop($aAdmins);
  314. }
  315. return $this->_oDb->updateAuthorById($iContentId, $iAuthorId);
  316. }
  317. /**
  318. * Entry actions and social sharing block
  319. */
  320. public function serviceEntityAllActions ($mixedContent = false, $aParams = array())
  321. {
  322. $CNF = &$this->_oConfig->CNF;
  323. if(!empty($mixedContent)) {
  324. if(!is_array($mixedContent))
  325. $mixedContent = array((int)$mixedContent, (method_exists($this->_oDb, 'getContentInfoById')) ? $this->_oDb->getContentInfoById((int)$mixedContent) : array());
  326. }
  327. else {
  328. $mixedContent = $this->_getContent();
  329. if($mixedContent === false)
  330. return false;
  331. }
  332. list($iContentId, $aContentInfo) = $mixedContent;
  333. if(!empty($CNF['FIELD_PICTURE']) && !empty($aContentInfo[$CNF['FIELD_PICTURE']]))
  334. $aParams = array_merge(array(
  335. 'entry_thumb' => (int)$aContentInfo[$CNF['FIELD_PICTURE']]
  336. ), $aParams);
  337. return parent::serviceEntityAllActions ($mixedContent, $aParams);
  338. }
  339. /**
  340. * Reset group's author when author profile is deleted
  341. * @param $iProfileId author profile id
  342. * @param $iAuthorId new author profile id
  343. * @return number of changed items
  344. */
  345. public function serviceReassignEntitiesByAuthor ($iProfileId, $iAuthorId = 0)
  346. {
  347. $a = $this->_oDb->getEntriesByAuthor((int)$iProfileId);
  348. if (!$a)
  349. return 0;
  350. $iCount = 0;
  351. foreach ($a as $aContentInfo)
  352. $iCount += ('' == $this->serviceReassignEntityAuthor($aContentInfo[$this->_oConfig->CNF['FIELD_ID']], $iAuthorId) ? 1 : 0);
  353. return $iCount;
  354. }
  355. public function servicePrepareFields ($aFieldsProfile)
  356. {
  357. $CNF = &$this->_oConfig->CNF;
  358. $aFieldsProfile[$CNF['FIELD_NAME']] = $aFieldsProfile['name'];
  359. $aFieldsProfile[$CNF['FIELD_TEXT']] = isset($aFieldsProfile['description']) ? $aFieldsProfile['description'] : '';
  360. unset($aFieldsProfile['name']);
  361. unset($aFieldsProfile['description']);
  362. return $aFieldsProfile;
  363. }
  364. public function serviceOnRemoveConnection ($iGroupProfileId, $iInitiatorId)
  365. {
  366. $CNF = &$this->_oConfig->CNF;
  367. list ($iProfileId, $iGroupProfileId, $oGroupProfile) = $this->_prepareProfileAndGroupProfile($iGroupProfileId, $iInitiatorId);
  368. if (!$oGroupProfile)
  369. return false;
  370. $this->_oDb->fromAdmins($iGroupProfileId, $iProfileId);
  371. if ($oConn = BxDolConnection::getObjectInstance('sys_profiles_subscriptions'))
  372. return $oConn->removeConnection($iProfileId, $iGroupProfileId);
  373. return false;
  374. }
  375. public function serviceAddMutualConnection ($iGroupProfileId, $iInitiatorId, $bSendInviteOnly = false)
  376. {
  377. $CNF = &$this->_oConfig->CNF;
  378. list ($iProfileId, $iGroupProfileId, $oGroupProfile) = $this->_prepareProfileAndGroupProfile($iGroupProfileId, $iInitiatorId);
  379. if (!$oGroupProfile)
  380. return false;
  381. if (!($aContentInfo = $this->_oDb->getContentInfoById((int)BxDolProfile::getInstance($iGroupProfileId)->getContentId())))
  382. return false;
  383. if (!isset($CNF['OBJECT_CONNECTIONS']) || !($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])))
  384. return false;
  385. $sEntryTitle = $aContentInfo[$CNF['FIELD_NAME']];
  386. $sEntryUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]));
  387. // send invitation to the group
  388. $sModule = $this->getName();
  389. if ($bSendInviteOnly && !$oConnection->isConnected((int)$iInitiatorId, $oGroupProfile->id()) && !$oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId) && bx_get_logged_profile_id() != $iProfileId) {
  390. /**
  391. * @hooks
  392. * @hookdef hook-bx_base_groups-join_invitation '{module_name}', 'join_invitation' - hook before adding (sending) new join to context invitation
  393. * - $unit_name - module name
  394. * - $action - equals `join_invitation`
  395. * - $object_id - context id
  396. * - $sender_id - context profile id
  397. * - $extra_params - array of additional params with the following array keys:
  398. * - `content` - [array] context info array as key&value pairs
  399. * - `entry_title` - [string] context title
  400. * - `entry_url` - [string] context URL
  401. * - `group_profile` - [int] context profile id
  402. * - `profile` - [int] profile id who was invited
  403. * - `notification_subobject_id` - [int] profile id who was invited
  404. * - `object_author_id` - [int] context profile id
  405. * @hook @ref hook-bx_base_groups-join_invitation
  406. */
  407. bx_alert($sModule, 'join_invitation', $aContentInfo[$CNF['FIELD_ID']], $iGroupProfileId, [
  408. 'content' => $aContentInfo,
  409. 'entry_title' => $sEntryTitle,
  410. 'entry_url' => $sEntryUrl,
  411. 'group_profile' => $iGroupProfileId,
  412. 'profile' => $iProfileId,
  413. 'notification_subobject_id' => $iProfileId,
  414. 'object_author_id' => $iGroupProfileId
  415. ]);
  416. /**
  417. * 'Invitation Received' alert for Notifications module.
  418. * Note. It's essential to use Recipient ($iInitiatorId) in 'object_author_id' parameter.
  419. * In this case notification will be received by Recipient profile.
  420. */
  421. /**
  422. * @hooks
  423. * @hookdef hook-bx_base_groups-join_invitation_notif '{module_name}', 'join_invitation_notif' - hook before adding new join to context invitation. Is needed for Notifications module.
  424. * - $unit_name - module name
  425. * - $action - equals `join_invitation_notif`
  426. * - $object_id - context id
  427. * - $sender_id - context profile id
  428. * - $extra_params - array of additional params with the following array keys:
  429. * - `object_author_id` - [int] profile id who was invited
  430. * - `privacy_view` - [int] or [string] privacy for view context action, @see BxDolPrivacy
  431. * @hook @ref hook-bx_base_groups-join_invitation_notif
  432. */
  433. bx_alert($sModule, 'join_invitation_notif', $aContentInfo[$CNF['FIELD_ID']], $iGroupProfileId, [
  434. 'object_author_id' => $iInitiatorId,
  435. 'privacy_view' => isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) ? $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] : 3,
  436. ]);
  437. }
  438. // send notification to group's admins that new connection is pending confirmation
  439. elseif (!$bSendInviteOnly && $oConnection->isConnected((int)$iInitiatorId, $oGroupProfile->id()) && !$oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId) && $aContentInfo['join_confirmation']) {
  440. /**
  441. * @hooks
  442. * @hookdef hook-bx_base_groups-join_request '{module_name}', 'join_request' - hook before adding new join to context request
  443. * - $unit_name - module name
  444. * - $action - equals `join_request`
  445. * - $object_id - context id
  446. * - $sender_id - context profile id
  447. * - $extra_params - array of additional params with the following array keys:
  448. * - `object_author_id` - [int] context profile id
  449. * - `performer_id` - [int] profile id who wants to join
  450. * - `content` - [array] context info array as key&value pairs
  451. * - `entry_title` - [string] context title
  452. * - `entry_url` - [string] context URL
  453. * - `group_profile` - [int] context profile id
  454. * - `profile` - [int] profile id who wants to join
  455. * @hook @ref hook-bx_base_groups-join_request
  456. */
  457. bx_alert($this->getName(), 'join_request', $aContentInfo[$CNF['FIELD_ID']], $iGroupProfileId, [
  458. 'object_author_id' => $iGroupProfileId,
  459. 'performer_id' => $iProfileId,
  460. 'content' => $aContentInfo,
  461. 'entry_title' => $sEntryTitle,
  462. 'entry_url' => $sEntryUrl,
  463. 'group_profile' => $iGroupProfileId,
  464. 'profile' => $iProfileId
  465. ]);
  466. }
  467. // send notification that join request was accepted
  468. else if (!$bSendInviteOnly && $oConnection->isConnected((int)$iInitiatorId, $oGroupProfile->id(), true) && $oGroupProfile->getModule() != $this->getName() && bx_get_logged_profile_id() != $iProfileId) {
  469. /**
  470. * @hooks
  471. * @hookdef hook-bx_base_groups-join_request_accepted '{module_name}', 'join_request_accepted' - hook before accepting join to context request
  472. * It's equivalent to @ref hook-bx_base_groups-join_request
  473. * @hook @ref hook-bx_base_groups-join_request_accepted
  474. */
  475. bx_alert($this->getName(), 'join_request_accepted', $aContentInfo[$CNF['FIELD_ID']], $iGroupProfileId, [
  476. 'object_author_id' => $iGroupProfileId,
  477. 'performer_id' => $iProfileId,
  478. 'content' => $aContentInfo,
  479. 'entry_title' => $sEntryTitle,
  480. 'entry_url' => $sEntryUrl,
  481. 'group_profile' => $iGroupProfileId,
  482. 'profile' => $iProfileId
  483. ]);
  484. }
  485. // new fan was added
  486. if ($oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId, true)) {
  487. // follow group on join
  488. if (BxDolService::call($oGroupProfile->getModule(), 'act_as_profile')){
  489. $this->addFollower($oGroupProfile->id(), (int)$iInitiatorId);
  490. }
  491. else{
  492. $this->addFollower((int)$iInitiatorId, $oGroupProfile->id());
  493. }
  494. /**
  495. * @hooks
  496. * @hookdef hook-bx_base_groups-fan_added '{module_name}', 'fan_added' - hook before adding (registering) new context member
  497. * It's equivalent to @ref hook-bx_base_groups-join_request
  498. * @hook @ref hook-bx_base_groups-fan_added
  499. */
  500. bx_alert($this->getName(), 'fan_added', $aContentInfo[$CNF['FIELD_ID']], $iGroupProfileId, [
  501. 'object_author_id' => $iGroupProfileId,
  502. 'performer_id' => $iProfileId,
  503. 'content' => $aContentInfo,
  504. 'entry_title' => $sEntryTitle,
  505. 'entry_url' => $sEntryUrl,
  506. 'group_profile' => $iGroupProfileId,
  507. 'profile' => $iProfileId,
  508. ]);
  509. $this->doAudit($iGroupProfileId, $iInitiatorId, '_sys_audit_action_group_join_request_accepted');
  510. return false;
  511. }
  512. // don't automatically add connection (mutual) if group requires manual join confirmation
  513. if ($bSendInviteOnly || $aContentInfo['join_confirmation'])
  514. return false;
  515. // check if connection already exists
  516. if ($oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId, true) || $oConnection->isConnected($oGroupProfile->id(), (int)$iInitiatorId))
  517. return false;
  518. if (!$oConnection->addConnection($oGroupProfile->id(), (int)$iInitiatorId))
  519. return false;
  520. return true;
  521. }
  522. public function serviceFansTable ()
  523. {
  524. $CNF = &$this->_oConfig->CNF;
  525. $oGrid = BxDolGrid::getObjectInstance($CNF['OBJECT_GRID_CONNECTIONS']);
  526. if(!$oGrid)
  527. return false;
  528. if($this->_bIsApi){
  529. return [
  530. bx_api_get_block('grid', $oGrid->getCodeAPI())
  531. ];
  532. }
  533. return $oGrid->getCode();
  534. }
  535. public function serviceInvitesTable ()
  536. {
  537. $CNF = &$this->_oConfig->CNF;
  538. if(!isset($CNF['OBJECT_GRID_INVITES']))
  539. return false;
  540. $oGrid = BxDolGrid::getObjectInstance($CNF['OBJECT_GRID_INVITES']);
  541. if(!$oGrid)
  542. return false;
  543. if($this->_bIsApi)
  544. return [
  545. bx_api_get_block('grid', $oGrid->getCodeAPI())
  546. ];
  547. return $oGrid->getCode();
  548. }
  549. public function serviceBansTable ()
  550. {
  551. $CNF = &$this->_oConfig->CNF;
  552. if(!isset($CNF['OBJECT_GRID_BANS']))
  553. return false;
  554. $oGrid = BxDolGrid::getObjectInstance($CNF['OBJECT_GRID_BANS']);
  555. if(!$oGrid)
  556. return false;
  557. if($this->_bIsApi)
  558. return [
  559. bx_api_get_block('grid', $oGrid->getCodeAPI())
  560. ];
  561. return $oGrid->getCode();
  562. }
  563. public function serviceFans ($iContentId = 0, $bAsArray = false)
  564. {
  565. $CNF = &$this->_oConfig->CNF;
  566. if (!$iContentId)
  567. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  568. if (!$iContentId)
  569. return false;
  570. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  571. if (!$aContentInfo)
  572. return false;
  573. if (!($oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName())))
  574. return false;
  575. if(!$bAsArray) {
  576. bx_import('BxDolConnection');
  577. $mixedResult = $this->serviceBrowseConnectionsQuick ($oGroupProfile->id(), $CNF['OBJECT_CONNECTIONS'], BX_CONNECTIONS_CONTENT_TYPE_CONTENT, true);
  578. if (!$mixedResult)
  579. return MsgBox(_t('_sys_txt_empty'));
  580. }
  581. else
  582. $mixedResult = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])->getConnectedContent($oGroupProfile->id(), true);
  583. return $mixedResult;
  584. }
  585. public function serviceFansWithoutAdmins ($iContentId = 0, $bAsArray = false)
  586. {
  587. if (!$iContentId)
  588. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  589. if (!$iContentId)
  590. return false;
  591. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  592. if (!$aContentInfo)
  593. return false;
  594. if (!($oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName())))
  595. return false;
  596. $CNF = &$this->_oConfig->CNF;
  597. $aFans = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])->getConnectedContent($oGroupProfile->id(), true);
  598. if(empty($aFans) || !is_array($aFans))
  599. return false;
  600. $aAdmins = $this->_oDb->getAdmins($oGroupProfile->id());
  601. if(!empty($aAdmins) && is_array($aAdmins))
  602. $aFans = array_diff($aFans, $aAdmins);
  603. $iStart = (int)bx_get('start');
  604. $iLimit = !empty($CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? getParam($CNF['PARAM_NUM_CONNECTIONS_QUICK']) : 4;
  605. if(!$iLimit)
  606. $iLimit = 4;
  607. return $this->_serviceBrowseQuick($aFans, $iStart, $iLimit);
  608. }
  609. public function serviceAdmins ($iContentId = 0)
  610. {
  611. $CNF = &$this->_oConfig->CNF;
  612. if(!$iContentId)
  613. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  614. if(!$iContentId)
  615. return false;
  616. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  617. if(!$oGroupProfile)
  618. return false;
  619. $iStart = (int)bx_get('start');
  620. $iLimit = !empty($CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? getParam($CNF['PARAM_NUM_CONNECTIONS_QUICK']) : 4;
  621. if(!$iLimit)
  622. $iLimit = 4;
  623. $aProfiles = $this->_oDb->getAdmins($oGroupProfile->id(), $iStart, $iLimit+1);
  624. if(empty($aProfiles) || !is_array($aProfiles))
  625. return false;
  626. return $this->_serviceBrowseQuick($aProfiles, $iStart, $iLimit);
  627. }
  628. public function serviceMembersByRole ($iContentId = 0, $iRole = BX_BASE_MOD_GROUPS_ROLE_COMMON)
  629. {
  630. $CNF = &$this->_oConfig->CNF;
  631. if(!$iContentId)
  632. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  633. if(!$iContentId)
  634. return false;
  635. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  636. if(!$oGroupProfile)
  637. return false;
  638. $iStart = (int)bx_get('start');
  639. $iLimit = !empty($CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? getParam($CNF['PARAM_NUM_CONNECTIONS_QUICK']) : 4;
  640. if(!$iLimit)
  641. $iLimit = 4;
  642. $aProfiles = $this->_oDb->getRoles([
  643. 'type' => 'fan_pids_by_group_pid',
  644. 'group_profile_id' => $oGroupProfile->id(),
  645. 'role' => $iRole,
  646. 'start' => $iStart,
  647. 'limit' => $iLimit + 1
  648. ]);
  649. if(empty($aProfiles) || !is_array($aProfiles))
  650. return false;
  651. return $this->_serviceBrowseQuick($aProfiles, $iStart, $iLimit);
  652. }
  653. public function serviceBrowseJoinedEntries ($iProfileId = 0, $bDisplayEmptyMsg = false)
  654. {
  655. if (!$iProfileId)
  656. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  657. if (!$iProfileId)
  658. return '';
  659. return $this->_serviceBrowse ('joined_entries', array('joined_profile' => $iProfileId), BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  660. }
  661. public function serviceBrowseFollowedEntries ($iProfileId = 0, $bDisplayEmptyMsg = false)
  662. {
  663. if (!$iProfileId)
  664. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  665. if (!$iProfileId)
  666. return '';
  667. return $this->_serviceBrowse ('followed_entries', array('followed_profile' => $iProfileId), BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  668. }
  669. public function serviceBrowseCreatedEntries ($iProfileId = 0, $bDisplayEmptyMsg = false)
  670. {
  671. if (!$iProfileId)
  672. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  673. if (!$iProfileId)
  674. return '';
  675. return $this->_serviceBrowse ('created_entries', array('author' => $iProfileId), BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  676. }
  677. public function serviceBrowseRecommendationsFans ($iProfileId = 0, $aParams = [])
  678. {
  679. $CNF = &$this->_oConfig->CNF;
  680. if($this->_bIsApi)
  681. $aParams = bx_api_get_browse_params($aParams, true);
  682. if(!$iProfileId)
  683. $iProfileId = bx_get_logged_profile_id();
  684. if(!$iProfileId)
  685. return '';
  686. $aParams = array_merge([
  687. 'empty_message' => false,
  688. 'start' => 0,
  689. 'per_page' => 0
  690. ], $aParams);
  691. if(($iStartGet = bx_get('start')) !== false)
  692. $aParams['start'] = (int)$iStartGet;
  693. if(($iPerPageGet = bx_get('per_page')) !== false)
  694. $aParams['per_page'] = (int)$iPerPageGet;
  695. $oRecommendation = BxDolRecommendation::getObjectInstance($CNF['OBJECT_RECOMMENDATIONS_FANS']);
  696. if(!$oRecommendation)
  697. return false;
  698. if($this->_bIsApi) {
  699. $aData = $oRecommendation->getCodeAPI($iProfileId, $aParams);
  700. $aData = array_merge($aData, [
  701. 'module' => 'system',
  702. 'unit' => 'mixed',
  703. 'request_url' => '/api.php?r=bx_groups/browse_recommendations_fans&params[]=' . $iProfileId . '&params[]='
  704. ]);
  705. return [bx_api_get_block('browse', $aData)];
  706. }
  707. $sCode = $oRecommendation->getCode($iProfileId, $aParams);
  708. if(!$sCode && $aParams['empty_message'])
  709. $sCode = MsgBox(_t(!empty($aParams['empty_message_text']) ? $aParams['empty_message_text'] : '_Empty'));
  710. return $sCode;
  711. }
  712. public function serviceBrowseMembers ($iProfileId = 0, $aParams = [])
  713. {
  714. $CNF = &$this->_oConfig->CNF;
  715. if(!$iProfileId)
  716. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  717. if(!$iProfileId)
  718. return '';
  719. $oGroupProfile = BxDolProfile::getInstance($iProfileId);
  720. if(!($oGroupProfile))
  721. return '';
  722. return bx_srv('system', 'browse_members', [$oGroupProfile->id(), $CNF['OBJECT_CONNECTIONS'], $aParams], 'TemplServiceProfiles');
  723. }
  724. public function serviceEntityEditQuestionnaire($iProfileId = 0)
  725. {
  726. $CNF = &$this->_oConfig->CNF;
  727. if(!$iProfileId)
  728. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  729. if(!$iProfileId)
  730. return '';
  731. $aProfileInfo = BxDolProfileQuery::getInstance()->getInfoById($iProfileId);
  732. if(empty($aProfileInfo) || !is_array($aProfileInfo))
  733. return '';
  734. $aContentInfo = $this->_oDb->getContentInfoById($aProfileInfo['content_id']);
  735. if(empty($aContentInfo) || !is_array($aContentInfo))
  736. return '';
  737. if($this->checkAllowedEdit($aContentInfo) !== CHECK_ACTION_RESULT_ALLOWED)
  738. return MsgBox(_t('_Access denied'));
  739. $oGrid = BxDolGrid::getObjectInstance($CNF['OBJECT_GRID_QUESTIONS_MANAGE']);
  740. if(!$oGrid)
  741. return '';
  742. if($this->_bIsApi){
  743. return [
  744. bx_api_get_block('grid', $oGrid->getCodeAPI())
  745. ];
  746. }
  747. return $oGrid->getCode();
  748. }
  749. public function serviceEntityPricing($iProfileId = 0)
  750. {
  751. $CNF = &$this->_oConfig->CNF;
  752. if(!$iProfileId)
  753. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  754. if(!$iProfileId)
  755. return '';
  756. if(!$this->_oConfig->isPaidJoin())
  757. return '';
  758. $oPayments = BxDolPayments::getInstance();
  759. if(!$oPayments->isActive())
  760. return MsgBox(_t('_sys_payments_err_no_payments'));
  761. if($this->checkAllowedUsePaidJoin() !== CHECK_ACTION_RESULT_ALLOWED)
  762. return MsgBox(_t('_Access denied'));
  763. if($this->checkAllowedManageAdmins($iProfileId) !== CHECK_ACTION_RESULT_ALLOWED)
  764. return MsgBox(_t('_Access denied'));
  765. $oGrid = BxDolGrid::getObjectInstance($CNF['OBJECT_GRID_PRICES_MANAGE']);
  766. if(!$oGrid)
  767. return '';
  768. $sNote = '';
  769. if(!$oPayments->isAcceptingPayments($this->_iProfileId))
  770. $sNote = MsgBox(_t('_sys_payments_err_not_accept_payments', $oPayments->getDetailsUrl()));
  771. if($this->_bIsApi) {
  772. $aBlocks = [];
  773. if(!empty($sNote))
  774. $aBlocks[] = bx_api_get_msg($sNote);
  775. $aBlocks[] = bx_api_get_block('grid', $oGrid->getCodeAPI());
  776. return $aBlocks;
  777. }
  778. return $sNote . $oGrid->getCode();
  779. }
  780. public function serviceEntityJoin($iProfileId = 0)
  781. {
  782. $CNF = &$this->_oConfig->CNF;
  783. if(!$iProfileId)
  784. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  785. if(!$iProfileId)
  786. return '';
  787. if(!$this->_oConfig->isPaidJoin())
  788. return '';
  789. $oGrid = BxDolGrid::getObjectInstance($CNF['OBJECT_GRID_PRICES_VIEW']);
  790. if(!$oGrid)
  791. return '';
  792. return $oGrid->getCode();
  793. }
  794. public function serviceEntityInvite ($iContentId = 0, $bErrorMsg = true)
  795. {
  796. $CNF = &$this->_oConfig->CNF;
  797. if(!isset($CNF['OBJECT_FORM_ENTRY_DISPLAY_INVITE']))
  798. return false;
  799. return $this->_serviceEntityForm ('inviteForm', $iContentId, false, false, $bErrorMsg);
  800. }
  801. /**
  802. * Entry social sharing block
  803. */
  804. public function serviceEntitySocialSharing ($mixedContent = false, $aParams = array())
  805. {
  806. if(!empty($mixedContent)) {
  807. if(!is_array($mixedContent))
  808. $mixedContent = array((int)$mixedContent, array());
  809. }
  810. else {
  811. $mixedContent = $this->_getContent();
  812. if($mixedContent === false)
  813. return false;
  814. }
  815. list($iContentId, $aContentInfo) = $mixedContent;
  816. $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  817. if(!$oGroupProfile)
  818. return false;
  819. return parent::serviceEntitySocialSharing(array($iContentId, $aContentInfo), array(
  820. 'title' => $oGroupProfile->getDisplayName()
  821. ));
  822. }
  823. public function serviceIsPricingAvaliable($iProfileId)
  824. {
  825. if(!$this->_oConfig->isPaidJoin())
  826. return false;
  827. if($this->checkAllowedUsePaidJoin() !== CHECK_ACTION_RESULT_ALLOWED)
  828. return false;
  829. if($this->checkAllowedManageAdmins($iProfileId) !== CHECK_ACTION_RESULT_ALLOWED)
  830. return false;
  831. return true;
  832. }
  833. public function serviceIsPaidJoinAvaliable($iGroupProfileId, $iProfileId = 0)
  834. {
  835. return $this->isPaidJoinByProfileForProfile($iGroupProfileId, $iProfileId);
  836. }
  837. public function serviceIsPaidJoinAvaliableByContent($iGroupContentId, $iProfileId = 0)
  838. {
  839. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iGroupContentId, $this->getName());
  840. if(!$oGroupProfile)
  841. return false;
  842. return $this->isPaidJoinByProfileForProfile($oGroupProfile->id(), $iProfileId);
  843. }
  844. public function serviceIsFreeJoinAvaliable($iGroupProfileId, $iProfileId = 0)
  845. {
  846. return !$this->isPaidJoinByProfileForProfile($iGroupProfileId, $iProfileId);
  847. }
  848. public function serviceIsFreeJoinAvaliableByContent($iGroupContentId, $iProfileId = 0)
  849. {
  850. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iGroupContentId, $this->getName());
  851. if(!$oGroupProfile)
  852. return false;
  853. return !$this->isPaidJoinByProfileForProfile($oGroupProfile->id(), $iProfileId);
  854. }
  855. /**
  856. * Is Paid Join enabled in the group and whether a profile can use it.
  857. *
  858. * @param type $iGroupProfileId - Group profile ID.
  859. * @param type $iProfileId - Profile ID of the user who wants to join.
  860. * @return boolean
  861. */
  862. public function isPaidJoinByProfileForProfile($iGroupProfileId, $iProfileId = 0)
  863. {
  864. $CNF = &$this->_oConfig->CNF;
  865. if(empty($iProfileId))
  866. $iProfileId = $this->_iProfileId;
  867. if(BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])->isConnected($iProfileId, $iGroupProfileId))
  868. return false;
  869. return $this->isPaidJoinByProfile($iGroupProfileId);
  870. }
  871. /**
  872. * Is Paid Join enabled as is and whether a group has pricing plans added.
  873. *
  874. * @param type $iGroupProfileId - Group profile ID.
  875. * @return boolean
  876. */
  877. public function isPaidJoinByProfile($iGroupProfileId)
  878. {
  879. if(!$this->_oConfig->isPaidJoin())
  880. return false;
  881. $aPrices = $this->_oDb->getPrices(array('type' => 'by_profile_id', 'profile_id' => $iGroupProfileId));
  882. if(empty($aPrices) || !is_array($aPrices))
  883. return false;
  884. return true;
  885. }
  886. /**
  887. * Integration with Payments.
  888. */
  889. public function serviceGetPaymentData()
  890. {
  891. return $this->_aModule;
  892. }
  893. public function serviceGetCartItem($mixedItemId)
  894. {
  895. $CNF = &$this->_oConfig->CNF;
  896. if(!$mixedItemId)
  897. return array();
  898. if(is_numeric($mixedItemId))
  899. $aItem = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => (int)$mixedItemId));
  900. else
  901. $aItem = $this->_oDb->getPrices(array('type' => 'by_name', 'value' => $mixedItemId));
  902. if(empty($aItem) || !is_array($aItem))
  903. return array();
  904. if(!$this->isPaidJoinByProfile($aItem['profile_id']))
  905. return array();
  906. $oGroupProfile = BxDolProfile::getInstance($aItem['profile_id']);
  907. if(!$oGroupProfile)
  908. return array();
  909. $aGroupProfile = $this->_oDb->getContentInfoById($oGroupProfile->getContentId());
  910. $aRoles = BxDolFormQuery::getDataItems($CNF['OBJECT_PRE_LIST_ROLES']);
  911. $sTitle = '';
  912. if(!empty($aItem['period']) && !empty($aItem['period_unit']))
  913. $sTitle = _t($CNF['T']['txt_cart_item_title'], $oGroupProfile->getDisplayName(), $aRoles[$aItem['role_id']], $aItem['period'], $aItem['period_unit']);
  914. else
  915. $sTitle = _t($CNF['T']['txt_cart_item_title_lifetime'], $oGroupProfile->getDisplayName(), $aRoles[$aItem['role_id']]);
  916. return array (
  917. 'id' => $aItem['id'],
  918. 'author_id' => $aGroupProfile[$CNF['FIELD_AUTHOR']],
  919. 'name' => $aItem['name'],
  920. 'title' => $sTitle,
  921. 'description' => '',
  922. 'url' => $oGroupProfile->getUrl(),
  923. 'price_single' => $aItem['price'],
  924. 'price_recurring' => $aItem['price'],
  925. 'period_recurring' => $aItem['period'],
  926. 'period_unit_recurring' => $aItem['period_unit'],
  927. 'trial_recurring' => 0
  928. );
  929. }
  930. public function serviceGetCartItems($iSellerId)
  931. {
  932. $CNF = &$this->_oConfig->CNF;
  933. if(empty($iSellerId))
  934. return array();
  935. $sModule = $this->getName();
  936. $aRoles = BxDolFormQuery::getDataItems($CNF['OBJECT_PRE_LIST_ROLES']);
  937. $aGroups = $this->_oDb->getEntriesBy(array('type' => 'author', 'author' => $iSellerId));
  938. $aResult = array();
  939. foreach($aGroups as $aGroup) {
  940. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aGroup[$CNF['FIELD_ID']], $sModule);
  941. if(!$oGroupProfile)
  942. continue;
  943. $aPrices = $this->_oDb->getPrices(array('type' => 'by_profile_id', 'profile_id' => $oGroupProfile->id()));
  944. if(empty($aPrices) || !is_array($aPrices))
  945. continue;
  946. $sTitle = $oGroupProfile->getDisplayName();
  947. $sUrl = $oGroupProfile->getUrl();
  948. foreach($aPrices as $aPrice)
  949. $aResult[] = array(
  950. 'id' => $aPrice['id'],
  951. 'author_id' => $iSellerId,
  952. 'name' => $aPrice['name'],
  953. 'title' => _t($CNF['T']['txt_cart_item_title'], $sTitle, $aRoles[$aPrice['role_id']], $aPrice['period'], $aPrice['period_unit']),
  954. 'description' => '',
  955. 'url' => $sUrl,
  956. 'price_single' => $aPrice['price'],
  957. 'price_recurring' => $aPrice['price'],
  958. 'period_recurring' => $aPrice['period'],
  959. 'period_unit_recurring' => $aPrice['period_unit']
  960. );
  961. }
  962. return $aResult;
  963. }
  964. public function serviceRegisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  965. {
  966. return $this->_serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder);
  967. }
  968. public function serviceRegisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  969. {
  970. return $this->_serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder);
  971. }
  972. public function serviceReregisterCartItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  973. {
  974. return $this->_serviceReregisterItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder);
  975. }
  976. public function serviceReregisterSubscriptionItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  977. {
  978. return $this->_serviceReregisterItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder);
  979. }
  980. public function serviceUnregisterCartItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  981. {
  982. return $this->_serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder);
  983. }
  984. public function serviceUnregisterSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder, $sLicense)
  985. {
  986. return $this->_serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder);
  987. }
  988. public function serviceCancelSubscriptionItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder)
  989. {
  990. return true;
  991. }
  992. protected function _serviceRegisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder)
  993. {
  994. $CNF = &$this->_oConfig->CNF;
  995. $aItem = $this->serviceGetCartItem($iItemId);
  996. if(empty($aItem) || !is_array($aItem))
  997. return array();
  998. $aItemInfo = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iItemId));
  999. $mixedPeriod = false;
  1000. if((int)$aItemInfo['period'] != 0)
  1001. $mixedPeriod = array(
  1002. 'period' => (int)$aItemInfo['period'],
  1003. 'period_unit' => $aItemInfo['period_unit'],
  1004. 'period_reserve' => $CNF['PARAM_RECURRING_RESERVE']
  1005. );
  1006. if(!$this->setRole($aItemInfo['profile_id'], $iClientId, $aItemInfo['role_id'], $mixedPeriod, $sOrder))
  1007. return array();
  1008. return $aItem;
  1009. }
  1010. protected function _serviceReregisterItem($iClientId, $iSellerId, $iItemIdOld, $iItemIdNew, $sOrder)
  1011. {
  1012. $aItem = $this->serviceGetCartItem($iItemIdNew);
  1013. if(empty($aItem) || !is_array($aItem))
  1014. return array();
  1015. $aItemInfoOld = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iItemIdOld));
  1016. if(empty($aItemInfoOld) || !is_array($aItemInfoOld))
  1017. return array();
  1018. $aItemInfoNew = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iItemIdNew));
  1019. if(empty($aItemInfoNew) || !is_array($aItemInfoNew))
  1020. return array();
  1021. if(!$this->unsetRole($aItemInfoOld['profile_id'], $iClientId))
  1022. return array();
  1023. $aResult = $this->_serviceRegisterItem($iClientId, $iSellerId, $iItemIdNew, 1, $sOrder);
  1024. if(empty($aResult) || !is_array($aResult))
  1025. return array();
  1026. return $aItem;
  1027. }
  1028. protected function _serviceUnregisterItem($iClientId, $iSellerId, $iItemId, $iItemCount, $sOrder)
  1029. {
  1030. $aItemInfo = $this->_oDb->getPrices(array('type' => 'by_id', 'value' => $iItemId));
  1031. if(empty($aItemInfo) || !is_array($aItemInfo))
  1032. return false;
  1033. return $this->unsetRole($aItemInfo['profile_id'], $iClientId);
  1034. }
  1035. public function serviceGetQuestionnaire($sSource, $sObject, $sAction, $iContentProfileId)
  1036. {
  1037. $CNF = &$this->_oConfig->CNF;
  1038. $sMsg = _t('_sys_txt_not_found');
  1039. $aContentInfo = $this->_oDb->getContentInfoByProfileId($iContentProfileId);
  1040. if(empty($aContentInfo) || !is_array($aContentInfo))
  1041. return $this->_bIsApi ? [bx_api_get_msg($sMsg)] : ['code' => 1, 'msg' => $sMsg];
  1042. $oForm = null;
  1043. if(($oConnection = BxDolConnection::getObjectInstance($sObject)) !== false) {
  1044. $oForm = $oConnection->getQuestionnaireForm($sAction, $iContentProfileId, ['request' => [
  1045. 's' => $sSource,
  1046. ]]);
  1047. if($oForm === false)
  1048. return $this->_bIsApi ? [bx_api_get_msg($sMsg)] : ['code' => 3, 'msg' => $sMsg];
  1049. }
  1050. else
  1051. return $this->_bIsApi ? [bx_api_get_msg($sMsg)] : ['code' => 2, 'msg' => $sMsg];
  1052. $oForm->initChecker();
  1053. if($oForm->isSubmittedAndValid()) {
  1054. $iProfileId = bx_get_logged_profile_id();
  1055. $aQuestions = $this->_oDb->getQuestions(['sample' => 'content_pid', 'content_pid' => $iContentProfileId]);
  1056. foreach($aQuestions as $aQuestion)
  1057. $this->_oDb->insertAnswer((int)$aQuestion['id'], $iProfileId, $oForm->getCleanValue('question_' . $aQuestion['id']));
  1058. return $this->_bIsApi ? [] : ['code' => 0, 'o' => $sObject, 'a' => $sAction, 'cpi' => $iContentProfileId, 'ci' => $aContentInfo[$CNF['FIELD_ID']], 'eval' => $this->_oConfig->getJsObject($sSource) . '.connActionPerformed(oData)'];
  1059. }
  1060. if($this->_bIsApi)
  1061. return [bx_api_get_block('form', $oForm->getCodeAPI(), ['ext' => [
  1062. 'name' => $this->_oModule->getName(),
  1063. 'request' => ['url' => $oForm->aFormAttrs['action'], 'immutable' => true]]
  1064. ])];
  1065. bx_import('BxTemplFunctions');
  1066. $sContent = BxTemplFunctions::getInstance()->popupBox($this->_oConfig->getHtmlIds('popup_questionnaire'), _t($CNF['T']['popup_title_questionnaire']), $this->_oTemplate->parseHtmlByName('popup_qnr_questionnaire.html', [
  1067. 'form_id' => $oForm->getId(),
  1068. 'form' => $oForm->getCode(true),
  1069. ]));
  1070. return ['popup' => ['html' => $sContent, 'options' => ['closeOnOuterClick' => false]]];
  1071. }
  1072. /**
  1073. * Data for Notifications module
  1074. */
  1075. public function serviceGetNotificationsData()
  1076. {
  1077. $sModule = $this->_aModule['name'];
  1078. $aSettingsTypes = ['follow_member', 'follow_context'];
  1079. if($this->serviceActAsProfile())
  1080. $aSettingsTypes = ['personal', 'follow_member'];
  1081. return [
  1082. 'handlers' => [
  1083. ['group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_vote', 'module_class' => 'Module'],
  1084. ['group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'],
  1085. ['group' => $sModule . '_score_up', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteUp', 'module_name' => $sModule, 'module_method' => 'get_notifications_score_up', 'module_class' => 'Module'],
  1086. ['group' => $sModule . '_score_down', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVoteDown', 'module_name' => $sModule, 'module_method' => 'get_notifications_score_down', 'module_class' => 'Module'],
  1087. ['group' => $sModule . '_fan_added', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'fan_added', 'module_name' => $sModule, 'module_method' => 'get_notifications_fan_added', 'module_class' => 'Module'],
  1088. ['group' => $sModule . '_join_invitation', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'join_invitation_notif', 'module_name' => $sModule, 'module_method' => 'get_notifications_join_invitation', 'module_class' => 'Module'],
  1089. ['group' => $sModule . '_join_request', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'join_request', 'module_name' => $sModule, 'module_method' => 'get_notifications_join_request', 'module_class' => 'Module', 'module_event_privacy' => $this->_oConfig->CNF['OBJECT_PRIVACY_VIEW_NOTIFICATION_EVENT']],
  1090. ['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'],
  1091. //--- Moderation related: For 'admins'.
  1092. ['group' => $sModule . '_object_pending_approval', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'pending_approval', 'module_name' => $sModule, 'module_method' => 'get_notifications_post_pending_approval', 'module_class' => 'Module'],
  1093. ],
  1094. 'settings' => [
  1095. ['group' => 'vote', 'unit' => $sModule, 'action' => 'doVote', 'types' => $aSettingsTypes],
  1096. ['group' => 'score_up', 'unit' => $sModule, 'action' => 'doVoteUp', 'types' => $aSettingsTypes],
  1097. ['group' => 'score_down', 'unit' => $sModule, 'action' => 'doVoteDown', 'types' => $aSettingsTypes],
  1098. ['group' => 'fan', 'unit' => $sModule, 'action' => 'fan_added', 'types' => $aSettingsTypes],
  1099. ['group' => 'invite', 'unit' => $sModule, 'action' => 'join_invitation_notif', 'types' => ['personal']],
  1100. ['group' => 'join', 'unit' => $sModule, 'action' => 'join_request', 'types' => $aSettingsTypes],
  1101. ['group' => 'timeline_post', 'unit' => $sModule, 'action' => 'timeline_post_common', 'types' => $aSettingsTypes],
  1102. //--- Moderation related: For 'admins'.
  1103. ['group' => 'action_required', 'unit' => $sModule, 'action' => 'pending_approval', 'types' => ['personal']],
  1104. ],
  1105. 'alerts' => [
  1106. ['unit' => $sModule, 'action' => 'doVote'],
  1107. ['unit' => $sModule, 'action' => 'undoVote'],
  1108. ['unit' => $sModule, 'action' => 'doVoteUp'],
  1109. ['unit' => $sModule, 'action' => 'doVoteDown'],
  1110. ['unit' => $sModule, 'action' => 'fan_added'],
  1111. ['unit' => $sModule, 'action' => 'join_invitation_notif'],
  1112. ['unit' => $sModule, 'action' => 'join_request'],
  1113. ['unit' => $sModule, 'action' => 'timeline_post_common'],
  1114. //--- Moderation related: For 'admins'.
  1115. ['unit' => $sModule, 'action' => 'pending_approval'],
  1116. ]
  1117. ];
  1118. }
  1119. public function serviceGetNotificationsInsertData($oAlert, $aHandler, $aDataItems)
  1120. {
  1121. if($oAlert->sAction != 'join_invitation_notif' || empty($aDataItems) || !is_array($aDataItems))
  1122. return $aDataItems;
  1123. foreach($aDataItems as $iIndex => $aDataItem)
  1124. $aDataItems[$iIndex]['object_privacy_view'] = BX_DOL_PG_ALL;
  1125. return $aDataItems;
  1126. }
  1127. /**
  1128. * Notification about new invitation to join the group
  1129. */
  1130. public function serviceGetNotificationsJoinInvitation($aEvent)
  1131. {
  1132. $CNF = &$this->_oConfig->CNF;
  1133. $iContentId = (int)$aEvent['object_id'];
  1134. $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  1135. if(!$oGroupProfile)
  1136. return array();
  1137. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1138. if(empty($aContentInfo) || !is_array($aContentInfo))
  1139. return array();
  1140. /*
  1141. * It's essential that 'object_owner_id' contains invited member profile id.
  1142. */
  1143. $oProfile = BxDolProfile::getInstance((int)$aEvent['object_owner_id']);
  1144. if(!$oProfile)
  1145. return array();
  1146. /*
  1147. * Note. Group Profile URL is used for both Entry and Subentry URLs,
  1148. * because Subentry URL has higher display priority and notification
  1149. * should be linked to Group Profile (Group Profile -> Members tab)
  1150. * instead of Personal Profile of invited member.
  1151. */
  1152. $sEntryUrl = bx_absolute_url(str_replace(BX_DOL_URL_ROOT, '', $oGroupProfile->getUrl()), '{bx_url_root}');
  1153. return array(
  1154. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1155. 'entry_url' => $sEntryUrl,
  1156. 'entry_caption' => $oGroupProfile->getDisplayName(),
  1157. 'subentry_sample' => $oProfile->getDisplayName(),
  1158. 'subentry_url' => $sEntryUrl,
  1159. 'lang_key' => $this->_oConfig->CNF['T']['txt_ntfs_join_invitation']
  1160. );
  1161. }
  1162. /**
  1163. * Notification about new member requst in the group
  1164. */
  1165. public function serviceGetNotificationsJoinRequest($aEvent)
  1166. {
  1167. return $this->_serviceGetNotification($aEvent, 'join_request', $this->_oConfig->CNF['T']['txt_ntfs_join_request']);
  1168. }
  1169. /**
  1170. * Notification about new member in the group
  1171. */
  1172. public function serviceGetNotificationsFanAdded($aEvent)
  1173. {
  1174. return $this->_serviceGetNotification($aEvent, 'fan_added', $this->_oConfig->CNF['T']['txt_ntfs_fan_added']);
  1175. }
  1176. protected function _serviceGetNotification($aEvent, $sType, $sLangKey)
  1177. {
  1178. $CNF = &$this->_oConfig->CNF;
  1179. $iContentId = (int)$aEvent['object_id'];
  1180. $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  1181. if(!$oGroupProfile)
  1182. return array();
  1183. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1184. if(empty($aContentInfo) || !is_array($aContentInfo))
  1185. return array();
  1186. $oProfile = BxDolProfile::getInstance((int)$aEvent['subobject_id']);
  1187. if(!$oProfile)
  1188. return array();
  1189. $iGroupProfileId = $oGroupProfile->id();
  1190. /*
  1191. * Note. Group Profile URL is used for both Entry and Subentry URLs,
  1192. * because Subentry URL has higher display priority and notification
  1193. * should be linked to Group Profile (Group Profile -> Members tab or Manage page)
  1194. * instead of Personal Profile of a member, who performed an action.
  1195. */
  1196. if($sType == 'join_request' && !empty($CNF['URL_ENTRY_MANAGE']))
  1197. $sEntryUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink($CNF['URL_ENTRY_MANAGE'], [
  1198. 'profile_id' => $iGroupProfileId
  1199. ]), '{bx_url_root}');
  1200. else if(!empty($CNF['URL_ENTRY_FANS']))
  1201. $sEntryUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink($CNF['URL_ENTRY_FANS'], [
  1202. 'profile_id' => $iGroupProfileId
  1203. ]), '{bx_url_root}');
  1204. else
  1205. $sEntryUrl = bx_absolute_url(str_replace(BX_DOL_URL_ROOT, '', $oGroupProfile->getUrl()), '{bx_url_root}');
  1206. return [
  1207. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1208. 'entry_url' => $sEntryUrl,
  1209. 'entry_caption' => $oGroupProfile->getDisplayName(),
  1210. 'entry_author' => $iGroupProfileId,
  1211. 'subentry_sample' => $oProfile->getDisplayName(),
  1212. 'subentry_url' => $sEntryUrl,
  1213. 'lang_key' => $sLangKey
  1214. ];
  1215. }
  1216. /**
  1217. * Data for Reputation module
  1218. */
  1219. public function serviceGetReputationData()
  1220. {
  1221. $aResult = parent::serviceGetReputationData();
  1222. $sModule = $this->_aModule['name'];
  1223. if(!empty($aResult['handlers']) && is_array($aResult['handlers']))
  1224. foreach($aResult['handlers'] as $iKey => $aHandler)
  1225. if(in_array($aHandler['group'], [$sModule . '_comment', $sModule . '_reaction']))
  1226. unset($aResult['handlers'][$iKey]);
  1227. if(!empty($aResult['alerts']) && is_array($aResult['alerts']))
  1228. foreach($aResult['alerts'] as $iKey => $aAlert)
  1229. if($aAlert['unit'] == $sModule . '_reactions' || in_array($aAlert['action'], ['commentPost', 'commentRemoved']))
  1230. unset($aResult['alerts'][$iKey]);
  1231. return $aResult;
  1232. }
  1233. /**
  1234. * Data for Timeline module
  1235. */
  1236. public function serviceGetTimelineData()
  1237. {
  1238. $aResult = BxBaseModGeneralModule::serviceGetTimelineData();
  1239. $sModule = $this->_aModule['name'];
  1240. $aResult['handlers'] = array_merge($aResult['handlers'], [
  1241. ['group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'context_cover_changed'],
  1242. ['group' => $sModule . '_object', 'type' => 'update', 'alert_unit' => $sModule, 'alert_action' => 'context_cover_deleted']
  1243. ]);
  1244. $aResult['alerts'] = array_merge($aResult['alerts'], [
  1245. ['unit' => $sModule, 'action' => 'context_cover_changed'],
  1246. ['unit' => $sModule, 'action' => 'context_cover_deleted']
  1247. ]);
  1248. return $aResult;
  1249. }
  1250. /**
  1251. * Entry post for Timeline module
  1252. */
  1253. public function serviceGetTimelinePost($aEvent, $aBrowseParams = array())
  1254. {
  1255. $CNF = &$this->_oConfig->CNF;
  1256. $a = parent::serviceGetTimelinePost($aEvent, $aBrowseParams);
  1257. if($a === false)
  1258. return false;
  1259. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aEvent['object_id'], $this->getName());
  1260. $a['content']['url'] = $oGroupProfile->getUrl();
  1261. $a['content']['title'] = $oGroupProfile->getDisplayName();
  1262. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS']);
  1263. if($oConnection)
  1264. $a['content']['members'] = $oConnection->getConnectedInitiatorsCount($oGroupProfile->id(), true);
  1265. if(isset($aEvent['object_privacy_view']))
  1266. $a['content']['visibility'] = $aEvent['object_privacy_view'];
  1267. if(isset($CNF['FIELD_PUBLISHED'])) {
  1268. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
  1269. if($aContentInfo[$CNF['FIELD_PUBLISHED']] > $a['date'])
  1270. $a['date'] = $aContentInfo[$CNF['FIELD_PUBLISHED']];
  1271. }
  1272. return $a;
  1273. }
  1274. // ====== PERMISSION METHODS
  1275. /**
  1276. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1277. */
  1278. public function checkAllowedUsePaidJoin($isPerformAction = false)
  1279. {
  1280. // check ACL
  1281. $aCheck = checkActionModule($this->_iProfileId, 'use paid join', $this->getName(), $isPerformAction);
  1282. if($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1283. return $aCheck[CHECK_ACTION_MESSAGE];
  1284. return CHECK_ACTION_RESULT_ALLOWED;
  1285. }
  1286. /**
  1287. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1288. */
  1289. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  1290. {
  1291. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
  1292. }
  1293. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  1294. {
  1295. $CNF = &$this->_oConfig->CNF;
  1296. $iGroupContentId = (int)$aDataEntry[$CNF['FIELD_ID']];
  1297. $bInvited = false;
  1298. if(!empty($CNF['TABLE_INVITES'])) {
  1299. $iGroupProfileId = BxDolProfile::getInstanceByContentAndType($iGroupContentId, $this->getName())->id();
  1300. if(($sKey = bx_get('key')) !== false) {
  1301. $mixedInvited = $this->isInvited($sKey, $iGroupProfileId);
  1302. if($mixedInvited === true)
  1303. $bInvited = true;
  1304. }
  1305. else {
  1306. $mixedInvited = $this->isInvitedByProfileId($iProfileId ? $iProfileId : bx_get_logged_profile_id(), $iGroupProfileId);
  1307. if($mixedInvited === true)
  1308. $bInvited = true;
  1309. }
  1310. }
  1311. if ($this->isFan($iGroupContentId, $iProfileId) || $bInvited)
  1312. return CHECK_ACTION_RESULT_ALLOWED;
  1313. return parent::serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  1314. }
  1315. /**
  1316. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1317. */
  1318. public function checkAllowedCompose(&$aDataEntry, $isPerformAction = false)
  1319. {
  1320. if(!$this->isFan($aDataEntry[$this->_oConfig->CNF['FIELD_ID']]))
  1321. return _t('_sys_txt_access_denied');
  1322. return parent::checkAllowedCompose ($aDataEntry, $isPerformAction);
  1323. }
  1324. /**
  1325. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1326. */
  1327. public function checkAllowedFanAdd(&$aDataEntry, $isPerformAction = false)
  1328. {
  1329. $mixedResult = $this->_modGroupsCheckAllowedFanAdd($aDataEntry, $isPerformAction);
  1330. /**
  1331. * @hooks
  1332. * @hookdef hook-system-check_allowed_fan_add 'system', 'check_allowed_fan_add' - hook to override the result of checking whether 'fan add' to context action is allowed or not to currently logged in user
  1333. * - $unit_name - equals `system`
  1334. * - $action - equals `check_allowed_fan_add`
  1335. * - $object_id - not used
  1336. * - $sender_id - not used
  1337. * - $extra_params - array of additional params with the following array keys:
  1338. * - `module` - [string] module name
  1339. * - `content_info` - [array] context info array as key&value pairs
  1340. * - `profile_id` - [int] currently logged in profile id to be checked the availability of the action to
  1341. * - `override_result` - [string] or [int] by ref, check action result, can be overridden in hook processing. Return string with an error if action isn't allowed or CHECK_ACTION_RESULT_ALLOWED, @see BxDolAcl
  1342. * @hook @ref hook-system-check_allowed_fan_add
  1343. */
  1344. bx_alert('system', 'check_allowed_fan_add', 0, 0, [
  1345. 'module' => $this->getName(),
  1346. 'content_info' => $aDataEntry,
  1347. 'profile_id' => bx_get_logged_profile_id(),
  1348. 'override_result' => &$mixedResult
  1349. ]);
  1350. return $mixedResult;
  1351. }
  1352. public function _modGroupsCheckAllowedFanAdd (&$aDataEntry, $isPerformAction = false)
  1353. {
  1354. if ($this->isFan($aDataEntry[$this->_oConfig->CNF['FIELD_ID']]) || !isLogged())
  1355. return _t('_sys_txt_access_denied');
  1356. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], false, false);
  1357. }
  1358. /**
  1359. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1360. */
  1361. public function checkAllowedFanRemove (&$aDataEntry, $isPerformAction = false)
  1362. {
  1363. if (CHECK_ACTION_RESULT_ALLOWED === $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], false, true, true))
  1364. return CHECK_ACTION_RESULT_ALLOWED;
  1365. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], false, true, false);
  1366. }
  1367. protected function _checkAllowedActionByFan($sAction, $aDataEntry, $iProfileId = 0)
  1368. {
  1369. $CNF = &$this->_oConfig->CNF;
  1370. $bRoles = $this->_oConfig->isRoles();
  1371. if(empty($iProfileId))
  1372. $iProfileId = bx_get_logged_profile_id();
  1373. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->getName());
  1374. if(!$oGroupProfile)
  1375. return $sAction == BX_BASE_MOD_GROUPS_ACTION_DELETE ? CHECK_ACTION_RESULT_ALLOWED : _t('_sys_txt_not_found');
  1376. $iGroupProfileId = $oGroupProfile->id();
  1377. if(!$bRoles && $this->_oDb->isAdmin($iGroupProfileId, $iProfileId, $aDataEntry))
  1378. return CHECK_ACTION_RESULT_ALLOWED;
  1379. if($bRoles && $this->isAllowedActionByRole($sAction, $aDataEntry, $iGroupProfileId, $iProfileId))
  1380. return CHECK_ACTION_RESULT_ALLOWED;
  1381. return _t('_sys_txt_access_denied');
  1382. }
  1383. public function isAllowedActionByRole($mAction, $aDataEntry, $iGroupProfileId, $iProfileId)
  1384. {
  1385. $iProfileRole = $this->_oDb->getRole($iGroupProfileId, $iProfileId);
  1386. if (is_array($mAction)) {
  1387. $sAction = $mAction['action'];
  1388. $sActionModule = $mAction['module'];
  1389. } else {
  1390. $sAction = $mAction;
  1391. $sActionModule = $this->getName();
  1392. }
  1393. $bResult = false;
  1394. if($iProfileId)
  1395. $bResult = $this->isAllowedModuleActionByRole($sActionModule, $sAction, $iProfileRole);
  1396. // in case neither of the profile's roles are having permissions set explicitly then fallback to an old way
  1397. if ($bResult === NULL) {
  1398. $bResult = false;
  1399. if($this->isFanByGroupProfileId($iGroupProfileId)) {
  1400. switch ($sAction) {
  1401. case BX_BASE_MOD_GROUPS_ACTION_DELETE:
  1402. case BX_BASE_MOD_GROUPS_ACTION_EDIT:
  1403. case BX_BASE_MOD_GROUPS_ACTION_CHANGE_SETTINGS:
  1404. case BX_BASE_MOD_GROUPS_ACTION_CHANGE_COVER:
  1405. case BX_BASE_MOD_GROUPS_ACTION_MANAGE_ROLES:
  1406. if($this->isRole($iProfileRole, BX_BASE_MOD_GROUPS_ROLE_ADMINISTRATOR))
  1407. $bResult = true;
  1408. break;
  1409. case BX_BASE_MOD_GROUPS_ACTION_MANAGE_FANS:
  1410. case BX_BASE_MOD_GROUPS_ACTION_INVITE:
  1411. case BX_BASE_MOD_GROUPS_ACTION_EDIT_CONTENT:
  1412. case BX_BASE_MOD_GROUPS_ACTION_DELETE_CONTENT:
  1413. case BX_BASE_MOD_GROUPS_ACTION_TIMELINE_POST_PIN:
  1414. if($this->isRole($iProfileRole, BX_BASE_MOD_GROUPS_ROLE_ADMINISTRATOR) || $this->isRole($iProfileRole, BX_BASE_MOD_GROUPS_ROLE_MODERATOR))
  1415. $bResult = true;
  1416. break;
  1417. default:
  1418. $bResult = true;
  1419. }
  1420. }
  1421. }
  1422. // in case current user is not allowed to edit/delete this group then
  1423. // if it is a subgroup inside a context then give to the admin roles of a parent context the ability to edit/delete that subgroup.
  1424. if (
  1425. !$bResult &&
  1426. ($sAction == BX_BASE_MOD_GROUPS_ACTION_EDIT || $sAction == BX_BASE_MOD_GROUPS_ACTION_DELETE) &&
  1427. isset($this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']) &&
  1428. $this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO'] &&
  1429. isset($aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]) &&
  1430. $aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']] < 0)
  1431. {
  1432. $iParentContextProfileId = -$aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']];
  1433. $oParentContext = BxDolProfile::getInstance($iParentContextProfileId);
  1434. if ($oParentContext) {
  1435. $sCheckAction = $sAction == BX_BASE_MOD_GROUPS_ACTION_EDIT ? BX_BASE_MOD_GROUPS_ACTION_EDIT_CONTENT : BX_BASE_MOD_GROUPS_ACTION_DELETE_CONTENT;
  1436. $aParentDataEntry = bx_srv($oParentContext->getModule(), 'get_info', [$oParentContext->getContentId(), false]);
  1437. return $this->isAllowedActionByRole(['action' => $sCheckAction, 'module' => $oParentContext->getModule()], $aParentDataEntry, $iParentContextProfileId, $iProfileId);
  1438. }
  1439. }
  1440. /**
  1441. * @hooks
  1442. * @hookdef hook-system-check_allowed_action_by_role 'system', 'check_allowed_action_by_role' - hook to override the result of checking whether an action is allowed or not to context member by his role in the context
  1443. * - $unit_name - equals `system`
  1444. * - $action - equals `check_allowed_action_by_role`
  1445. * - $object_id - not used
  1446. * - $sender_id - not used
  1447. * - $extra_params - array of additional params with the following array keys:
  1448. * - `module` - [string] module name
  1449. * - `multi_roles` - [boolean] whether multi roles are enabled in context or not
  1450. * - `action` - [string] action to be checked
  1451. * - `action_module` - [string] module name which the action belongs to
  1452. * - `content_profile_id` - [int] context profile id
  1453. * - `content_info` - [array] context info array as key&value pairs
  1454. * - `profile_id` - [int] profile id to be checked the availability of the action to
  1455. * - `profile_role` - [int] profile role in the context
  1456. * - `override_result` - [boolean] by ref, check action result, can be overridden in hook processing.
  1457. * @hook @ref hook-system-check_allowed_action_by_role
  1458. */
  1459. bx_alert('system', 'check_allowed_action_by_role', 0, 0, [
  1460. 'module' => $this->getName(),
  1461. 'multi_roles' => $this->_oConfig->isMultiRoles(),
  1462. 'action' => $sAction,
  1463. 'action_module' => $sActionModule,
  1464. 'content_profile_id' => $iGroupProfileId,
  1465. 'content_info' => $aDataEntry,
  1466. 'profile_id' => $iProfileId,
  1467. 'profile_role' => $iProfileRole,
  1468. 'override_result' => &$bResult
  1469. ]);
  1470. return $bResult;
  1471. }
  1472. public function isAllowedModuleActionByRole($sModule, $sAction, $iProfileRole)
  1473. {
  1474. static $aRoles;
  1475. if (!$aRoles && isset($this->_oConfig->CNF['OBJECT_PRE_LIST_ROLES']) && !empty($this->_oConfig->CNF['OBJECT_PRE_LIST_ROLES']))
  1476. $aRoles = BxBaseFormView::getDataItems($this->_oConfig->CNF['OBJECT_PRE_LIST_ROLES'], true, BX_DATA_VALUES_ALL);
  1477. if ($aRoles) {
  1478. foreach ($aRoles as $iRole => $aRoleData) {
  1479. if ($iRole == 0 && $iProfileRole == 0 || $iRole > 0 && $this->isRole($iProfileRole, $iRole)) {
  1480. $mPermissions = isset($aRoles[$iRole]) && isset($aRoles[$iRole]['Data']) && !empty($aRoles[$iRole]['Data']) ? unserialize($aRoles[$iRole]['Data']) : false;
  1481. if ($mPermissions && isset($mPermissions[$sModule])) {
  1482. return isset($mPermissions[$sModule][$sAction]) && $mPermissions[$sModule][$sAction];
  1483. }
  1484. }
  1485. }
  1486. }
  1487. return NULL;
  1488. }
  1489. public function isAllowedModuleActionByProfile($iContentId, $sPostModule, $sAction, $iProfileId = 0) {
  1490. if (!$iProfileId) $iProfileId = bx_get_logged_profile_id();
  1491. if ($iProfileId && $this->isFan($iContentId, $iProfileId)) {
  1492. $sModuleName = $this->getName();
  1493. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $sModuleName);
  1494. $aDataEntry = $this->_oDb->getContentInfoById($iContentId);
  1495. $bResult = $this->isAllowedActionByRole(['action' => $sAction, 'module' => $sPostModule], $aDataEntry, $oGroupProfile->id(), $iProfileId);
  1496. if ($bResult === true) return CHECK_ACTION_RESULT_ALLOWED;
  1497. if ($bResult === false) return _t('_sys_txt_access_denied');
  1498. }
  1499. return NULL; //undefined, because the profile is either not a fan or his role is not having permissions defined. So process the default way then.
  1500. }
  1501. public function isRole($iProfileRole, $iRole)
  1502. {
  1503. if(!$this->_oConfig->isMultiRoles())
  1504. return $iProfileRole == $iRole;
  1505. else
  1506. return $iProfileRole & (1 << ($iRole - 1));
  1507. }
  1508. public function serviceIsRole($iProfileRole, $iRole)
  1509. {
  1510. return $this->isRole($iProfileRole, $iRole);
  1511. }
  1512. public function checkAllowedManageFans($mixedDataEntry, $isPerformAction = false)
  1513. {
  1514. $aDataEntry = array();
  1515. if(!is_array($mixedDataEntry)) {
  1516. $oGroupProfile = BxDolProfile::getInstance((int)$mixedDataEntry);
  1517. if($oGroupProfile && $this->getName() == $oGroupProfile->getModule())
  1518. $aDataEntry = $this->_oDb->getContentInfoById($oGroupProfile->getContentId());
  1519. }
  1520. else
  1521. $aDataEntry = $mixedDataEntry;
  1522. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_MANAGE_FANS, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  1523. return CHECK_ACTION_RESULT_ALLOWED;
  1524. return parent::checkAllowedEdit($aDataEntry, $isPerformAction);
  1525. }
  1526. public function checkAllowedManageAdmins($mixedDataEntry, $isPerformAction = false)
  1527. {
  1528. $aDataEntry = array();
  1529. if(!is_array($mixedDataEntry)) {
  1530. $oGroupProfile = BxDolProfile::getInstance((int)$mixedDataEntry);
  1531. if($oGroupProfile && $this->getName() == $oGroupProfile->getModule())
  1532. $aDataEntry = $this->_oDb->getContentInfoById($oGroupProfile->getContentId());
  1533. }
  1534. else
  1535. $aDataEntry = $mixedDataEntry;
  1536. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_MANAGE_ROLES, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  1537. return CHECK_ACTION_RESULT_ALLOWED;
  1538. return parent::checkAllowedEdit($aDataEntry, $isPerformAction);
  1539. }
  1540. public function checkAllowedEdit($aDataEntry, $isPerformAction = false)
  1541. {
  1542. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_EDIT, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  1543. return CHECK_ACTION_RESULT_ALLOWED;
  1544. return parent::checkAllowedEdit($aDataEntry, $isPerformAction);
  1545. }
  1546. public function checkAllowedInvite($aDataEntry, $isPerformAction = false)
  1547. {
  1548. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_INVITE, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  1549. return CHECK_ACTION_RESULT_ALLOWED;
  1550. return parent::checkAllowedEdit($aDataEntry, $isPerformAction);
  1551. }
  1552. public function checkAllowedChangeCover($aDataEntry, $isPerformAction = false)
  1553. {
  1554. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_CHANGE_COVER, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  1555. return CHECK_ACTION_RESULT_ALLOWED;
  1556. return parent::checkAllowedChangeCover($aDataEntry, $isPerformAction);
  1557. }
  1558. public function checkAllowedChangeSettings($aDataEntry, $isPerformAction = false)
  1559. {
  1560. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_CHANGE_SETTINGS, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  1561. return CHECK_ACTION_RESULT_ALLOWED;
  1562. return parent::checkAllowedChangeSettings($aDataEntry, $isPerformAction);
  1563. }
  1564. public function checkAllowedDelete(&$aDataEntry, $isPerformAction = false)
  1565. {
  1566. if($this->_checkAllowedActionByFan(BX_BASE_MOD_GROUPS_ACTION_DELETE, $aDataEntry) === CHECK_ACTION_RESULT_ALLOWED)
  1567. return CHECK_ACTION_RESULT_ALLOWED;
  1568. return parent::checkAllowedDelete($aDataEntry, $isPerformAction);
  1569. }
  1570. public function checkAllowedJoin(&$aDataEntry, $isPerformAction = false)
  1571. {
  1572. if (bx_get('key')){
  1573. $sKey = bx_get('key');
  1574. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  1575. $aData = $this->_oDb->getInviteByKey($sKey, $oGroupProfile->id());
  1576. if (isset($aData['invited_profile_id']) && $aData['invited_profile_id'] == bx_get_logged_profile_id()){
  1577. return CHECK_ACTION_RESULT_ALLOWED;
  1578. }
  1579. }
  1580. return _t('_sys_txt_access_denied');
  1581. }
  1582. public function checkAllowedSubscribeAdd(&$aDataEntry, $isPerformAction = false)
  1583. {
  1584. $mixedResult = $this->_modGroupsCheckAllowedSubscribeAdd($aDataEntry, $isPerformAction);
  1585. /**
  1586. * @hooks
  1587. * @hookdef hook-system-check_allowed_subscribe_add 'system', 'check_allowed_subscribe_add' - hook to override the result of checking whether currently logged in user can subscribe (follow) the context or not
  1588. * - $unit_name - equals `system`
  1589. * - $action - equals `check_allowed_subscribe_add`
  1590. * - $object_id - not used
  1591. * - $sender_id - not used
  1592. * - $extra_params - array of additional params with the following array keys:
  1593. * - `module` - [string] module name
  1594. * - `content_info` - [array] context info array as key&value pairs
  1595. * - `profile_id` - [int] currently logged in profile id to be checked the availability of the action to
  1596. * - `override_result` - [string] or [int] by ref, check action result, can be overridden in hook processing. Return string with an error if action isn't allowed or CHECK_ACTION_RESULT_ALLOWED, @see BxDolAcl
  1597. * @hook @ref hook-system-check_allowed_subscribe_add
  1598. */
  1599. bx_alert('system', 'check_allowed_subscribe_add', 0, 0, [
  1600. 'module' => $this->getName(),
  1601. 'content_info' => $aDataEntry,
  1602. 'profile_id' => bx_get_logged_profile_id(),
  1603. 'override_result' => &$mixedResult
  1604. ]);
  1605. return $mixedResult;
  1606. }
  1607. /**
  1608. * Note. Is mainly needed for internal usage. Access level is 'public' to allow outer calls from alerts.
  1609. */
  1610. public function _modGroupsCheckAllowedSubscribeAdd(&$aDataEntry, $isPerformAction = false)
  1611. {
  1612. $CNF = &$this->_oConfig->CNF;
  1613. if(!$this->isFan($aDataEntry[$CNF['FIELD_ID']]) && (!isset($CNF['PARAM_SBS_WO_JOIN']) || getParam($CNF['PARAM_SBS_WO_JOIN']) != 'on'))
  1614. return _t('_sys_txt_access_denied');
  1615. return parent::_modProfileCheckAllowedSubscribeAdd($aDataEntry, $isPerformAction);
  1616. }
  1617. /**
  1618. * @deprecated since version 11.0.3 and can be removed in the next version.
  1619. */
  1620. public function _checkAllowedSubscribeAdd (&$aDataEntry, $isPerformAction = false)
  1621. {
  1622. return parent::checkAllowedSubscribeAdd ($aDataEntry, $isPerformAction);
  1623. }
  1624. public function doAudit($iGroupProfileId, $iFanId, $sAction)
  1625. {
  1626. $oProfile = BxDolProfile::getInstance($iFanId);
  1627. $iContentId = $oProfile->getContentId();
  1628. $sModule = $oProfile->getModule();
  1629. $oModule = BxDolModule::getInstance($sModule);
  1630. if (BxDolRequest::serviceExists($sModule, 'act_as_profile') && BxDolService::call($sModule, 'act_as_profile') && $oModule->_oConfig){
  1631. $CNF = $oModule->_oConfig->CNF;
  1632. $aContentInfo = BxDolRequest::serviceExists($sModule, 'get_all') ? BxDolService::call($sModule, 'get_all', array(array('type' => 'id', 'id' => $iContentId))) : array();
  1633. $AuditParams = array(
  1634. 'content_title' => (isset($CNF['FIELD_TITLE']) && isset($aContentInfo[$CNF['FIELD_TITLE']])) ? $aContentInfo[$CNF['FIELD_TITLE']] : '',
  1635. 'context_profile_id' => $iGroupProfileId,
  1636. 'context_profile_title' => BxDolProfile::getInstance($iGroupProfileId)->getDisplayName()
  1637. );
  1638. bx_audit(
  1639. $iContentId,
  1640. $sModule,
  1641. $sAction,
  1642. $AuditParams
  1643. );
  1644. }
  1645. }
  1646. protected function _checkAllowedConnect (&$aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap = false)
  1647. {
  1648. $sResult = $this->checkAllowedView($aDataEntry);
  1649. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->CNF['OBJECT_PRIVACY_VIEW']);
  1650. // when context is in another context
  1651. if ($aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']] < 0 && getParam('sys_check_fan_in_parent_context')) {
  1652. $oParent = BxDolProfile::getInstance(abs($aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]));
  1653. $oModule = $oParent ? BxDolModule::getInstance($oParent->getModule()) : null;
  1654. if ($oModule && method_exists($oModule, 'isFan') && !$oModule->isFan($oParent->getContentId()))
  1655. return _t('_sys_txt_access_denied');
  1656. }
  1657. // if profile view isn't allowed but visibility is in partially visible groups
  1658. // then display buttons to connect (befriend, join) to profile,
  1659. // if other conditions (in parent::_checkAllowedConnect) are met as well
  1660. if (CHECK_ACTION_RESULT_ALLOWED !== $sResult && !in_array($aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']], array_merge($oPrivacy->getPartiallyVisiblePrivacyGroups(), array('s'))))
  1661. return $sResult;
  1662. return parent::_checkAllowedConnect ($aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap);
  1663. }
  1664. // ====== COMMON METHODS
  1665. public function onUpdateImage($iContentId, $sFiledName, $sFiledValue, $iProfileId = 0)
  1666. {
  1667. $CNF = &$this->_oConfig->CNF;
  1668. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1669. $aField2Method = [
  1670. $CNF['FIELD_PICTURE'] => 'picture',
  1671. $CNF['FIELD_COVER'] => 'cover',
  1672. ];
  1673. if(!empty($aField2Method[$sFiledName]))
  1674. /**
  1675. * @hooks
  1676. * @hookdef hook-bx_base_groups-context_picture_changed '{module_name}', 'context_picture_changed' - hook after context picture was changed
  1677. * - $unit_name - module name
  1678. * - $action - equals `context_picture_changed`
  1679. * - $object_id - context id
  1680. * - $sender_id - profile id who performed the action
  1681. * - $extra_params - array of additional params with the following array keys:
  1682. * - `status` - [string] context status
  1683. * - `status_admin` - [string] context admin status
  1684. * - `privacy_view` - [int] or [string] privacy for view context action, @see BxDolPrivacy
  1685. * - `cf` - [int] context's audience filter value
  1686. * @hook @ref hook-bx_base_groups-context_picture_changed
  1687. */
  1688. /**
  1689. * @hooks
  1690. * @hookdef hook-bx_base_groups-context_cover_changed '{module_name}', 'context_cover_changed' - hook after context cover was changed
  1691. * It's equivalent to @ref hook-bx_base_groups-context_picture_changed
  1692. * @hook @ref hook-bx_base_groups-context_cover_changed
  1693. */
  1694. bx_alert($this->getName(), 'context_' . $aField2Method[$sFiledName] . '_changed', $iContentId, $iProfileId, $this->_alertParams($aContentInfo));
  1695. }
  1696. protected function _alertParams($aContentInfo)
  1697. {
  1698. $aParams = parent::_alertParams($aContentInfo);
  1699. $CNF = &$this->_oConfig->CNF;
  1700. if(!empty($CNF['FIELD_CF']) && isset($aContentInfo[$CNF['FIELD_CF']]))
  1701. $aParams['cf'] = $aContentInfo[$CNF['FIELD_CF']];
  1702. return $aParams;
  1703. }
  1704. public function alertAfterAdd($aContentInfo)
  1705. {
  1706. $CNF = &$this->_oConfig->CNF;
  1707. $iId = (int)$aContentInfo[$CNF['FIELD_ID']];
  1708. $iAuthorId = (int)$aContentInfo[$CNF['FIELD_AUTHOR']];
  1709. $sAction = 'added';
  1710. if(isset($CNF['FIELD_STATUS_ADMIN']) && isset($aContentInfo[$CNF['FIELD_STATUS_ADMIN']]) && $aContentInfo[$CNF['FIELD_STATUS_ADMIN']] == BX_BASE_MOD_GENERAL_STATUS_PENDING)
  1711. $sAction = 'deferred';
  1712. $sModule = $this->getName();
  1713. $aParams = $this->_alertParams($aContentInfo);
  1714. /**
  1715. * @hooks
  1716. * @hookdef hook-system-prepare_alert_params 'system', 'prepare_alert_params' - hook to override alert (hook) params
  1717. * - $unit_name - equals `system`
  1718. * - $action - equals `prepare_alert_params`
  1719. * - $object_id - not used
  1720. * - $sender_id - not used
  1721. * - $extra_params - array of additional params with the following array keys:
  1722. * - `unit` - [string] unit name
  1723. * - `action` - [string] by ref, action, can be overridden in hook processing
  1724. * - `object_id` - [int] by ref, object id, can be overridden in hook processing
  1725. * - `sender_id` - [int] by ref, action performer profile id, can be overridden in hook processing
  1726. * - `extras` - [array] by ref, extra params array as key&value pairs, can be overridden in hook processing
  1727. * @hook @ref hook-system-prepare_alert_params
  1728. */
  1729. bx_alert('system', 'prepare_alert_params', 0, 0, [
  1730. 'unit'=> $sModule,
  1731. 'action' => &$sAction,
  1732. 'object_id' => &$iId,
  1733. 'sender_id' => &$iAuthorId,
  1734. 'extras' => &$aParams
  1735. ]);
  1736. /**
  1737. * @hooks
  1738. * @hookdef hook-bx_base_groups-added '{module_name}', 'added' - hook after context was added (published)
  1739. * - $unit_name - module name
  1740. * - $action - equals `added`
  1741. * - $object_id - context id
  1742. * - $sender_id - not used
  1743. * - $extra_params - array of additional params with the following array keys:
  1744. * - `status` - [string] context status
  1745. * - `status_admin` - [string] context admin status
  1746. * - `privacy_view` - [int] or [string] privacy for view context action, @see BxDolPrivacy
  1747. * - `cf` - [int] context's audience filter value
  1748. * @hook @ref hook-bx_base_groups-added
  1749. */
  1750. /**
  1751. * @hooks
  1752. * @hookdef hook-bx_base_groups-deferred '{module_name}', 'deferred' - hook after context was added with pending approval status
  1753. * It's equivalent to @ref hook-bx_base_groups-added
  1754. * @hook @ref hook-bx_base_groups-deferred
  1755. */
  1756. bx_alert($sModule, $sAction, $iId, false, $aParams);
  1757. $this->_processModerationNotifications($aContentInfo);
  1758. }
  1759. public function addFollower ($iProfileId1, $iProfileId2)
  1760. {
  1761. $oConnectionFollow = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
  1762. if($oConnectionFollow && !$oConnectionFollow->isConnected($iProfileId1, $iProfileId2)){
  1763. $oConnectionFollow->addConnection($iProfileId1, $iProfileId2);
  1764. return true;
  1765. }
  1766. return false;
  1767. }
  1768. public function isFan ($iContentId, $iProfileId = false)
  1769. {
  1770. $CNF = &$this->_oConfig->CNF;
  1771. $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  1772. if($oGroupProfile && isset($CNF['OBJECT_CONNECTIONS']))
  1773. return ($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])) && $oConnection->isConnected($iProfileId ? $iProfileId : bx_get_logged_profile_id(), $oGroupProfile->id(), true);
  1774. return false;
  1775. }
  1776. public function isFanByGroupProfileId ($iGroupProfileId, $iProfileId = false)
  1777. {
  1778. $CNF = &$this->_oConfig->CNF;
  1779. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  1780. if($oGroupProfile && isset($CNF['OBJECT_CONNECTIONS']))
  1781. return ($oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])) && $oConnection->isConnected($iProfileId ? $iProfileId : bx_get_logged_profile_id(), $oGroupProfile->id(), true);
  1782. return false;
  1783. }
  1784. public function isInvited ($sKey, $iGroupProfileId)
  1785. {
  1786. $CNF = &$this->_oConfig->CNF;
  1787. $aData = $this->_oDb->getInviteByKey($sKey, $iGroupProfileId);
  1788. if (!isset($aData['invited_profile_id']))
  1789. return _t($CNF['T']['txt_invitation_popup_error_invitation_absent']);
  1790. if ($aData['invited_profile_id'] != bx_get_logged_profile_id())
  1791. return _t($CNF['T']['txt_invitation_popup_error_wrong_user']);
  1792. return true;
  1793. }
  1794. public function isInvitedByProfileId ($iProfileId, $iGroupProfileId)
  1795. {
  1796. $CNF = &$this->_oConfig->CNF;
  1797. $aData = $this->_oDb->getInviteByInvited($iProfileId, $iGroupProfileId);
  1798. if (!isset($aData['invited_profile_id']))
  1799. return _t($CNF['T']['txt_invitation_popup_error_invitation_absent']);
  1800. if ($aData['invited_profile_id'] != bx_get_logged_profile_id())
  1801. return _t($CNF['T']['txt_invitation_popup_error_wrong_user']);
  1802. return true;
  1803. }
  1804. public function serviceIsInvited($iGroupProfileId, $iProfileId = false, $sKey = '')
  1805. {
  1806. if(!$iProfileId)
  1807. $iProfileId = bx_get_logged_profile_id();
  1808. if(empty($sKey) && ($sKey = bx_get('key')) !== false)
  1809. $sKey = bx_process_input($sKey);
  1810. $mixedInvited = false;
  1811. if(!empty($sKey))
  1812. $mixedInvited = $this->isInvited($sKey, $iGroupProfileId);
  1813. else if($iProfileId !== false)
  1814. $mixedInvited = $this->isInvitedByProfileId($iProfileId, $iGroupProfileId);
  1815. return $mixedInvited === true;
  1816. }
  1817. public function serviceIsNotInvited($iGroupProfileId, $iProfileId = false, $sKey = '')
  1818. {
  1819. return !$this->serviceIsInvited($iGroupProfileId, $iProfileId, $sKey);
  1820. }
  1821. public function serviceGetInvitedKey($iGroupProfileId, $iProfileId = false)
  1822. {
  1823. $sKey = '';
  1824. if(($sKey = bx_get('key')) !== false)
  1825. $sKey = bx_process_input($sKey);
  1826. if(!$sKey) {
  1827. if(!$iProfileId)
  1828. $iProfileId = bx_get_logged_profile_id();
  1829. if($iProfileId !== false) {
  1830. $aInvite = $this->_oDb->getInviteByInvited($iProfileId, $iGroupProfileId);
  1831. if(!empty($aInvite) && is_array($aInvite))
  1832. $sKey = $aInvite['key'];
  1833. }
  1834. }
  1835. return $sKey;
  1836. }
  1837. public function getRole($iGroupProfileId, $iFanProfileId)
  1838. {
  1839. if(!$this->isFanByGroupProfileId($iGroupProfileId, $iFanProfileId))
  1840. return false;
  1841. return $this->_oDb->getRole($iGroupProfileId, $iFanProfileId);
  1842. }
  1843. public function setRole($iGroupProfileId, $iFanProfileId, $mixedRole, $mixedPeriod = false, $sOrder = '')
  1844. {
  1845. $CNF = &$this->_oConfig->CNF;
  1846. if(!isset($CNF['OBJECT_CONNECTIONS']))
  1847. return false;
  1848. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS']);
  1849. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  1850. if(!$oConnection || !$oGroupProfile)
  1851. return false;
  1852. if(!$oConnection->isConnected($iFanProfileId, $iGroupProfileId, true) && !$oConnection->addConnection($iFanProfileId, $iGroupProfileId))
  1853. return false;
  1854. if(!$this->_oDb->setRole($iGroupProfileId, $iFanProfileId, $mixedRole, $mixedPeriod, $sOrder))
  1855. return false;
  1856. $this->onSetRole($iGroupProfileId, $iFanProfileId, $mixedRole);
  1857. return true;
  1858. }
  1859. public function onSetRole($iGroupProfileId, $iFanProfileId, $mixedRole)
  1860. {
  1861. $CNF = &$this->_oConfig->CNF;
  1862. $iProfileId = bx_get_logged_profile_id();
  1863. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  1864. $aGroupProfileInfo = $this->_oDb->getContentInfoById((int)$oGroupProfile->getContentId());
  1865. $aRoles = BxDolFormQuery::getDataItems($CNF['OBJECT_PRE_LIST_ROLES']);
  1866. // notify about admin status
  1867. if(!empty($CNF['EMAIL_FAN_SET_ROLE']) && $iFanProfileId != $iProfileId) {
  1868. $aSetRoles = is_array($mixedRole) ? $mixedRole : [$mixedRole];
  1869. $aRolesNames = [];
  1870. foreach ($aSetRoles as $iRole)
  1871. $aRolesNames[] = $aRoles[(int)$iRole];
  1872. sendMailTemplate($CNF['EMAIL_FAN_SET_ROLE'], 0, $iFanProfileId, array(
  1873. 'EntryUrl' => $oGroupProfile->getUrl(),
  1874. 'EntryTitle' => $oGroupProfile->getDisplayName(),
  1875. 'Role' => implode(', ', $aRolesNames),
  1876. ), BX_EMAIL_NOTIFY);
  1877. }
  1878. /**
  1879. * @hooks
  1880. * @hookdef hook-bx_base_groups-set_role '{module_name}', 'set_role' - hook after 'set role' action was applied to context member
  1881. * - $unit_name - module name
  1882. * - $action - equals `set_role`
  1883. * - $object_id - context id
  1884. * - $sender_id - context profile id
  1885. * - $extra_params - array of additional params with the following array keys:
  1886. * - `object_author_id` - [int] context profile id
  1887. * - `performer_id` - [int] performer profile id
  1888. * - `fan_id` - [int] context member profile id
  1889. * - `content` - [array] context info array as key&value pairs
  1890. * - `role` - [int] or [array] role or an array of roles to be set
  1891. * - `group_profile` - [int] context profile id
  1892. * - `profile` - [int] performer profile id
  1893. * @hook @ref hook-bx_base_groups-set_role
  1894. */
  1895. bx_alert($this->getName(), 'set_role', $aGroupProfileInfo[$CNF['FIELD_ID']], $iGroupProfileId, array(
  1896. 'object_author_id' => $iGroupProfileId,
  1897. 'performer_id' => $iProfileId,
  1898. 'fan_id' => $iFanProfileId,
  1899. 'content' => $aGroupProfileInfo,
  1900. 'role' => $mixedRole,
  1901. 'group_profile' => $iGroupProfileId,
  1902. 'profile' => $iProfileId
  1903. ));
  1904. $this->doAudit($iGroupProfileId, $iFanProfileId, '_sys_audit_action_group_role_changed');
  1905. }
  1906. public function unsetRole($iGroupProfileId, $iFanProfileId)
  1907. {
  1908. $CNF = &$this->_oConfig->CNF;
  1909. if(!isset($CNF['OBJECT_CONNECTIONS']))
  1910. return false;
  1911. $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS']);
  1912. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  1913. if(!$oConnection || !$oGroupProfile)
  1914. return false;
  1915. if($oConnection->isConnected($iFanProfileId, $iGroupProfileId, true) && !$oConnection->removeConnection($iFanProfileId, $iGroupProfileId))
  1916. return false;
  1917. $iRole = $this->_oDb->getRole($iGroupProfileId, $iFanProfileId);
  1918. if(!$this->_oDb->unsetRole($iGroupProfileId, $iFanProfileId))
  1919. return false;
  1920. $this->onUnsetRole($iGroupProfileId, $iFanProfileId, $iRole);
  1921. return true;
  1922. }
  1923. public function onUnsetRole($iGroupProfileId, $iFanProfileId, $iRole)
  1924. {
  1925. $CNF = &$this->_oConfig->CNF;
  1926. $iProfileId = bx_get_logged_profile_id();
  1927. $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
  1928. $aGroupProfileInfo = $this->_oDb->getContentInfoById((int)$oGroupProfile->getContentId());
  1929. /**
  1930. * @hooks
  1931. * @hookdef hook-bx_base_groups-set_role '{module_name}', 'set_role' - hook after 'set role' action was applied to context member
  1932. * - $unit_name - module name
  1933. * - $action - equals `set_role`
  1934. * - $object_id - context id
  1935. * - $sender_id - context profile id
  1936. * - $extra_params - array of additional params with the following array keys:
  1937. * - `object_author_id` - [int] context profile id
  1938. * - `performer_id` - [int] performer profile id
  1939. * - `fan_id` - [int] context member profile id
  1940. * - `content` - [array] context info array as key&value pairs
  1941. * - `role` - [int] or [array] role or an array of roles to be set
  1942. * - `group_profile` - [int] context profile id
  1943. * - `profile` - [int] performer profile id
  1944. * @hook @ref hook-bx_base_groups-set_role
  1945. */
  1946. bx_alert($this->getName(), 'set_role', $aGroupProfileInfo[$CNF['FIELD_ID']], $iGroupProfileId, array(
  1947. 'object_author_id' => $iGroupProfileId,
  1948. 'performer_id' => $iProfileId,
  1949. 'fan_id' => $iFanProfileId,
  1950. 'content' => $aGroupProfileInfo,
  1951. 'role' => $iRole,
  1952. 'group_profile' => $iGroupProfileId,
  1953. 'profile' => $iProfileId
  1954. ));
  1955. $this->doAudit($iGroupProfileId, $iFanProfileId, '_sys_audit_action_group_role_changed');
  1956. }
  1957. public function getGroupsByFan($iProfileId, $mixedRole = false)
  1958. {
  1959. $CNF = &$this->_oConfig->CNF;
  1960. if(!isset($CNF['OBJECT_CONNECTIONS']))
  1961. return false;
  1962. if($mixedRole === false)
  1963. $mixedRole = BX_BASE_MOD_GROUPS_ROLE_COMMON;
  1964. if(!is_array($mixedRole))
  1965. $mixedRole = [$mixedRole];
  1966. $aResult = [];
  1967. foreach($mixedRole as $iRole) {
  1968. switch($iRole) {
  1969. case BX_BASE_MOD_GROUPS_ROLE_COMMON:
  1970. $aIds = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS'])->getConnectedContent($iProfileId);
  1971. break;
  1972. default:
  1973. $aIds = $this->_oDb->getRoles([
  1974. 'type' => 'group_pids_by_fan_id',
  1975. 'fan_id' => $iProfileId,
  1976. 'role' => $iRole
  1977. ]);
  1978. }
  1979. $aResult = array_merge($aResult, $aIds);
  1980. }
  1981. return $aResult;
  1982. }
  1983. public function getMenuItemTitleByConnection($sConnection, $sAction, $iContentProfileId, $iInitiatorProfileId = 0)
  1984. {
  1985. $CNF = $this->_oConfig->getCNF();
  1986. $aResult = parent::getMenuItemTitleByConnection($sConnection, $sAction, $iContentProfileId, $iInitiatorProfileId);
  1987. if(!empty($aResult))
  1988. return $aResult;
  1989. $oConnection = BxDolConnection::getObjectInstance($sConnection);
  1990. if(!$oConnection)
  1991. return false;
  1992. if(!$iInitiatorProfileId)
  1993. $iInitiatorProfileId = bx_get_logged_profile_id();
  1994. $aResult = [];
  1995. if($oConnection->isConnectedNotMutual($iInitiatorProfileId, $iContentProfileId))
  1996. $aResult = [
  1997. 'add' => _t(!empty($CNF['T']['menu_item_title_sm_join_requested']) ? $CNF['T']['menu_item_title_sm_join_requested'] : '_sys_menu_item_title_sm_join_requested'),
  1998. 'remove' => _t(!empty($CNF['T']['menu_item_title_sm_leave_cancel']) ? $CNF['T']['menu_item_title_sm_leave_cancel'] : '_sys_menu_item_title_sm_leave_cancel'),
  1999. ];
  2000. else if($oConnection->isConnectedNotMutual($iContentProfileId, $iInitiatorProfileId))
  2001. $aResult = [
  2002. 'add' => _t(!empty($CNF['T']['menu_item_title_sm_join_confirm']) ? $CNF['T']['menu_item_title_sm_join_confirm'] : '_sys_menu_item_title_sm_join_confirm'),
  2003. 'remove' => _t(!empty($CNF['T']['menu_item_title_sm_leave_reject']) ? $CNF['T']['menu_item_title_sm_leave_reject'] : '_sys_menu_item_title_sm_leave_reject'),
  2004. ];
  2005. else if($oConnection->isConnected($iInitiatorProfileId, $iContentProfileId, true))
  2006. $aResult = [
  2007. 'add' => '',
  2008. 'remove' => _t(!empty($CNF['T']['menu_item_title_sm_leave']) ? $CNF['T']['menu_item_title_sm_leave'] : '_sys_menu_item_title_sm_leave'),
  2009. ];
  2010. else
  2011. $aResult = [
  2012. 'add' => _t(!empty($CNF['T']['menu_item_title_sm_join']) ? $CNF['T']['menu_item_title_sm_join'] : '_sys_menu_item_title_sm_join'),
  2013. 'remove' => '',
  2014. ];
  2015. return !empty($sAction) && isset($aResult[$sAction]) ? $aResult[$sAction] : $aResult;
  2016. }
  2017. protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl, $aBrowseParams = array())
  2018. {
  2019. $CNF = &$this->_oConfig->CNF;
  2020. $iImageId = 0;
  2021. $sImageMd = $sImageXl = '';
  2022. if(isset($CNF['FIELD_COVER']) && !empty($aContentInfo[$CNF['FIELD_COVER']])) {
  2023. $iImageId = (int)$aContentInfo[$CNF['FIELD_COVER']];
  2024. $sImageMd = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_GALLERY']);
  2025. $sImageXl = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_COVER']);
  2026. }
  2027. if($sImageXl == '' && isset($CNF['FIELD_PICTURE']) && !empty($aContentInfo[$CNF['FIELD_PICTURE']])) {
  2028. $iImageId = (int)$aContentInfo[$CNF['FIELD_PICTURE']];
  2029. $sImageMd = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_GALLERY']);
  2030. $sImageXl = $this->_oConfig->getImageUrl($iImageId, ['OBJECT_IMAGES_TRANSCODER_COVER']);
  2031. }
  2032. if(empty($sImageXl))
  2033. return [];
  2034. $aImage = [
  2035. 'id' => $iImageId,
  2036. 'url' => $sUrl,
  2037. 'src' => $sImageXl,
  2038. 'src_orig' => $sImageXl
  2039. ];
  2040. if(!empty($sImageMd))
  2041. $aImage['src_medium'] = $sImageMd;
  2042. return [
  2043. $aImage
  2044. ];
  2045. }
  2046. protected function _prepareProfileAndGroupProfile($iGroupProfileId, $iInitiatorId)
  2047. {
  2048. if (!($oGroupProfile = BxDolProfile::getInstance($iGroupProfileId)))
  2049. return array(0, 0, null);
  2050. if ($oGroupProfile->getModule() == $this->getName()) {
  2051. $iProfileId = $iInitiatorId;
  2052. $iGroupProfileId = $oGroupProfile->id();
  2053. } else {
  2054. $iProfileId = $oGroupProfile->id();
  2055. $iGroupProfileId = $iInitiatorId;
  2056. }
  2057. return array($iProfileId, $iGroupProfileId, $oGroupProfile);
  2058. }
  2059. }
  2060. /** @} */