1
0

BxBaseModGroupsModule.php 80 KB

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