BxBaseModGroupsModule.php 80 KB

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