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