1
0

BxBaseModProfileModule.php 108 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup BaseProfile Base classes for profile modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. define('BX_DOL_PROFILE_REDIRECT_PROFILE', 'profile');
  12. define('BX_DOL_PROFILE_REDIRECT_LAST', 'last');
  13. define('BX_DOL_PROFILE_REDIRECT_CUSTOM', 'custom');
  14. define('BX_DOL_PROFILE_REDIRECT_HOMEPAGE', 'homepage');
  15. define('BX_DOL_PROFILE_ACTIVATE_ALWAYS', 'on');
  16. define('BX_DOL_PROFILE_ACTIVATE_NEVER', 'off');
  17. define('BX_DOL_PROFILE_ACTIVATE_ADD', 'add');
  18. define('BX_DOL_PROFILE_ACTIVATE_EDIT', 'edit');
  19. /**
  20. * Base class for profile modules.
  21. */
  22. class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolContentInfoService, iBxDolProfileService
  23. {
  24. protected $_iAccountId;
  25. function __construct(&$aModule)
  26. {
  27. parent::__construct($aModule);
  28. $CNF = &$this->_oConfig->CNF;
  29. if(!empty($CNF['FIELD_ALLOW_POST_TO']))
  30. $this->_aSearchableNamesExcept[] = $CNF['FIELD_ALLOW_POST_TO'];
  31. if(!empty($CNF['FIELD_ALLOW_CONTACT_TO']))
  32. $this->_aSearchableNamesExcept[] = $CNF['FIELD_ALLOW_CONTACT_TO'];
  33. $this->_iAccountId = getLoggedId();
  34. }
  35. public function actionDeleteProfileImg($iFileId, $iContentId, $sFieldPicture)
  36. {
  37. $aResult = array();
  38. $CNF = &$this->_oConfig->CNF;
  39. $oSrorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  40. if (!($aFile = $oSrorage->getFile((int)$iFileId)) || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)) || $aContentInfo[$sFieldPicture] != (int)$iFileId)
  41. $aResult = array('error' => 1, 'msg' => _t('_sys_storage_err_file_not_found'));
  42. $oAccountProfile = BxDolProfile::getInstanceAccountProfile();
  43. if ($oAccountProfile)
  44. $iAccountProfileId = $oAccountProfile->id();
  45. if ((!$aResult && !isLogged()) || (!$aResult && $aFile['profile_id'] != $iAccountProfileId && !$this->_isModerator()))
  46. $aResult = array('error' => 2, 'msg' => _t('_Access denied'));
  47. $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $CNF['OBJECT_FORM_ENTRY_DISPLAY_ADD'], $this->_oTemplate);
  48. if (!$aResult && !$oForm->_deleteFile($iContentId, $sFieldPicture, (int)$iFileId, true))
  49. $aResult = array('error' => 3, 'msg' => _t('_Failed'));
  50. elseif (!$aResult)
  51. $aResult = array('error' => 0, 'msg' => '');
  52. header('Content-Type: application/json; charset=utf-8');
  53. echo json_encode($aResult);
  54. }
  55. public function actionProfileCalendarData()
  56. {
  57. $iProfileId = (int)bx_get('profile_id');
  58. $aEntries = array();
  59. $BxDolModuleQuery = BxDolModuleQuery::getInstance();
  60. $aModules = $BxDolModuleQuery->getModulesBy(array('type' => 'modules', 'active' => 1));
  61. foreach($aModules as $aModule){
  62. $sModuleName = $aModule['name'];
  63. $oModule = BxDolModule::getInstance($sModuleName);
  64. if($oModule instanceof iBxDolCalendarService){
  65. if(BxDolRequest::serviceExists($sModuleName, 'get_calendar_entries')){
  66. $aEntries2 = BxDolService::call($sModuleName, 'get_calendar_entries', array($iProfileId));
  67. $aEntries = array_merge($aEntries, $aEntries2);
  68. }
  69. }
  70. }
  71. header('Content-Type: application/json; charset=utf-8');
  72. echo json_encode($aEntries);
  73. }
  74. public function actionEmbed($iContentId, $sUnitTemplate = '', $sAddCode = '')
  75. {
  76. return parent::actionEmbed($iContentId, 'unit_with_cover.html');
  77. }
  78. // ====== SERVICE METHODS
  79. public function serviceGetSafeServices()
  80. {
  81. $a = parent::serviceGetSafeServices();
  82. return array_merge($a, array (
  83. 'ProfileUnitSafe' => '',
  84. 'ProfileUrl' => '',
  85. 'EntityCreate' => '',
  86. 'BrowseRecommended' => '',
  87. 'BrowseRecentProfiles' => '',
  88. 'BrowseActiveProfiles' => '',
  89. 'BrowseTopProfiles' => '',
  90. 'BrowseOnlineProfiles' => '',
  91. 'BrowseConnections' => '',
  92. 'BrowseConnectionsEverywhere' => '',
  93. 'BrowseByAcl' => '',
  94. ));
  95. }
  96. public function serviceModuleSample ()
  97. {
  98. return parent::serviceModuleSample() ?: '_sys_sample_profile';
  99. }
  100. public function serviceGetOptionsRedirectAfterAdd()
  101. {
  102. $CNF = &$this->_oConfig->CNF;
  103. $aResult = array();
  104. $aChoices = array(BX_DOL_PROFILE_REDIRECT_PROFILE, BX_DOL_PROFILE_REDIRECT_LAST, BX_DOL_PROFILE_REDIRECT_CUSTOM, BX_DOL_PROFILE_REDIRECT_HOMEPAGE);
  105. foreach($aChoices as $sChoice)
  106. $aResult[] = array('key' => $sChoice, 'value' => _t($CNF['T']['option_redirect_aadd_' . $sChoice]));
  107. return $aResult;
  108. }
  109. public function serviceGetOptionsActivation()
  110. {
  111. $CNF = &$this->_oConfig->CNF;
  112. $aResult = array();
  113. $aChoices = array(BX_DOL_PROFILE_ACTIVATE_ALWAYS, BX_DOL_PROFILE_ACTIVATE_NEVER, BX_DOL_PROFILE_ACTIVATE_ADD, BX_DOL_PROFILE_ACTIVATE_EDIT);
  114. foreach($aChoices as $sChoice)
  115. $aResult[] = array('key' => $sChoice, 'value' => _t($CNF['T']['option_activation_' . $sChoice]));
  116. return $aResult;
  117. }
  118. public function serviceGetThumb ($iContentId, $sTranscoder = '')
  119. {
  120. $CNF = &$this->_oConfig->CNF;
  121. if(bx_is_api()){
  122. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  123. return bx_api_get_image($CNF['OBJECT_STORAGE'], $aContentInfo[$CNF['FIELD_PICTURE']]);
  124. }
  125. if(empty($sTranscoder) && !empty($CNF['OBJECT_IMAGES_TRANSCODER_THUMB']))
  126. $sTranscoder = $CNF['OBJECT_IMAGES_TRANSCODER_THUMB'];
  127. $mixedResult = $this->_getFieldValueThumb('FIELD_PICTURE', $iContentId, $sTranscoder);
  128. return $mixedResult !== false ? $mixedResult : '';
  129. }
  130. public function serviceGetCover ($iContentId, $sTranscoder = '')
  131. {
  132. $CNF = &$this->_oConfig->CNF;
  133. if(bx_is_api()){
  134. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  135. $aTmp = bx_api_get_image($CNF['OBJECT_STORAGE'], $aContentInfo[$CNF['FIELD_COVER']]);
  136. if (!$aTmp){
  137. return ['storage' => $CNF['OBJECT_STORAGE']];
  138. }
  139. return $aTmp;
  140. }
  141. if(empty($sTranscoder) && !empty($CNF['OBJECT_IMAGES_TRANSCODER_COVER']))
  142. $sTranscoder = $CNF['OBJECT_IMAGES_TRANSCODER_COVER'];
  143. $mixedResult = $this->_getFieldValueThumb('FIELD_COVER', $iContentId, $sTranscoder);
  144. return $mixedResult !== false ? $mixedResult : '';
  145. }
  146. public function serviceGetBadges($iContentId, $bIsSingle = false, $bIsCompact = false)
  147. {
  148. $mixedBadges = parent::serviceGetBadges($iContentId, $bIsSingle, $bIsCompact);
  149. if(($mixedBadge = $this->_oTemplate->getBadge($iContentId))) {
  150. if($this->_bIsApi)
  151. $mixedBadges[] = $mixedBadge;
  152. else
  153. $mixedBadges = $mixedBadge . $mixedBadges;
  154. }
  155. return $mixedBadges;
  156. }
  157. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  158. {
  159. if(empty($sUnitTemplate))
  160. $sUnitTemplate = 'unit_with_cover.html';
  161. return parent::serviceGetSearchResultUnit($iContentId, $sUnitTemplate);
  162. }
  163. public function serviceGetSearchableFieldsExtended($aInputsAdd = array())
  164. {
  165. $CNF = &$this->_oConfig->CNF;
  166. $aResult = parent::serviceGetSearchableFieldsExtended($aInputsAdd);
  167. if(!$this->serviceActAsProfile())
  168. return $aResult;
  169. if(!in_array('online', $this->_aSearchableNamesExcept))
  170. $aResult['online'] = array(
  171. 'type' => 'checkbox',
  172. 'caption' => $CNF['T']['form_field_online'],
  173. 'info' => '',
  174. 'value' => '1',
  175. 'values' => '',
  176. 'pass' => ''
  177. );
  178. if(!empty($CNF['FIELD_PICTURE']) && !in_array($CNF['FIELD_PICTURE'], $this->_aSearchableNamesExcept))
  179. $aResult[$CNF['FIELD_PICTURE']] = array(
  180. 'type' => 'checkbox',
  181. 'caption' => $CNF['T']['form_field_picture'],
  182. 'info' => '',
  183. 'value' => '1',
  184. 'values' => '',
  185. 'pass' => '',
  186. 'search_operator' => '>='
  187. );
  188. return $aResult;
  189. }
  190. /**
  191. * @page service Service Calls
  192. * @section bx_base_profile Base Profile
  193. * @subsection bx_base_profile-general General
  194. * @subsubsection bx_base_profile-entity_calendar entity_calendar
  195. *
  196. * @code bx_srv('bx_persons', 'entity_calendar', [...]); @endcode
  197. *
  198. * Get calendar block
  199. * @param $iContentId content ID
  200. *
  201. * @see BxBaseModProfileModule::serviceEntityCalendar
  202. */
  203. /**
  204. * @ref bx_base_profile-entity_calendar "entity_calendar"
  205. */
  206. public function serviceEntityCalendar($iContentId = 0, $sTemplate = 'calendar.html')
  207. {
  208. $iContentId = $this->_getContent($iContentId, false);
  209. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->_oConfig->getName());
  210. if($oProfile){
  211. $o = new BxTemplCalendar(array(
  212. 'eventSources' => array (
  213. bx_append_url_params(BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'profile_calendar_data', array('profile_id' => $oProfile->id())),
  214. ),
  215. ), $this->_oTemplate);
  216. return $o->display($sTemplate);
  217. }
  218. return '';
  219. }
  220. public function servicePrivateProfileMsg()
  221. {
  222. $sMessage = '';
  223. $mixedContent = $this->_getContent();
  224. if($mixedContent) {
  225. list($iContentId, $aContentInfo) = $mixedContent;
  226. $sMessage = $this->checkAllowedView($aContentInfo);
  227. }
  228. else
  229. $sMessage = MsgBox(_t('_sys_access_denied_to_private_content'));
  230. return !$this->_bIsApi ? $sMessage : [bx_api_get_msg($sMessage, ['ext' => ['msg_type' => 'result']])];
  231. }
  232. public function serviceGetContentInfoById($iContentId)
  233. {
  234. return $this->_oDb->getContentInfoById((int)$iContentId);
  235. }
  236. public function serviceGetContentInfoByProfileId($iProfileId)
  237. {
  238. return $this->_oDb->getContentInfoByProfileId((int)$iProfileId);
  239. }
  240. public function serviceGetMenuAddonManageTools()
  241. {
  242. $CNF = &$this->_oConfig->CNF;
  243. $iNumTotal = $this->_oDb->getEntriesNumByParams();
  244. $iNum1 = $this->_oDb->getEntriesNumByParams([
  245. [
  246. 'key' => 'status',
  247. 'table' => 'sys_profiles',
  248. 'value' => BX_PROFILE_STATUS_PENDING,
  249. 'operator' => '='
  250. ]
  251. ]);
  252. $iNum2 = 0;
  253. if (isset($CNF['OBJECT_REPORTS'])){
  254. $iNum2 = $this->_oDb->getEntriesNumByParams([
  255. [
  256. 'key' => 'reports',
  257. 'value' => '0',
  258. 'operator' => '>'
  259. ]
  260. ]);
  261. }
  262. return array('counter1_value' => $iNum1, 'counter2_value' => $iNum2, 'counter3_value' => $iNumTotal, 'counter1_caption' => _t('_sys_menu_dashboard_manage_tools_addon_counter1_caption_profile_default'));
  263. }
  264. public function serviceGetMenuAddonManageToolsProfileStats($iProfileId = 0)
  265. {
  266. if(!$iProfileId)
  267. $iProfileId = bx_get_logged_profile_id();
  268. $aAccountInfo = BxDolProfileQuery::getInstance()->getAccountInfoByProfileId($iProfileId);
  269. if(empty($aAccountInfo) || !is_array($aAccountInfo))
  270. return 0;
  271. bx_import('SearchResult', $this->_aModule);
  272. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  273. $o = new $sClass();
  274. $o->fillFilters([
  275. 'account_id' => $aAccountInfo['id'],
  276. 'perofileStatus' => ''
  277. ]);
  278. $o->unsetPaginate();
  279. return $o->getNum();
  280. }
  281. public function serviceGetMenuAddonFavoritesProfileStats()
  282. {
  283. bx_import('SearchResult', $this->_aModule);
  284. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  285. $o = new $sClass('favorite', array('user' => bx_get_logged_profile_id()));
  286. $o->unsetPaginate();
  287. return $o->getNum();
  288. }
  289. public function serviceGetSubmenuObject ()
  290. {
  291. return $this->_oConfig->CNF['OBJECT_MENU_SUBMENU_VIEW_ENTRY'];
  292. }
  293. public function serviceGetMenuSetNameForMenuTrigger ($sMenuTriggerName)
  294. {
  295. $CNF = &$this->_oConfig->CNF;
  296. if (isset($CNF['TRIGGER_MENU_PROFILE_VIEW_SUBMENU']) && $CNF['TRIGGER_MENU_PROFILE_VIEW_SUBMENU'] == $sMenuTriggerName)
  297. return $CNF['OBJECT_MENU_SUBMENU_VIEW_ENTRY'];
  298. elseif (isset($CNF['TRIGGER_MENU_PROFILE_SNIPPET_META']) && $CNF['TRIGGER_MENU_PROFILE_SNIPPET_META'] == $sMenuTriggerName)
  299. return $CNF['OBJECT_MENU_SNIPPET_META'];
  300. else if (isset($CNF['TRIGGER_MENU_PROFILE_VIEW_ACTIONS']) && $CNF['TRIGGER_MENU_PROFILE_VIEW_ACTIONS'] == $sMenuTriggerName) {
  301. if(empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL']))
  302. return $CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY'];
  303. else
  304. return array($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY'], $CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL']);
  305. }
  306. return '';
  307. }
  308. public function serviceGetSnippetMenuVars($iProfileId, $bPublic = null, $aParams = [])
  309. {
  310. return $this->_oTemplate->getSnippetMenuVars($iProfileId, $bPublic, $aParams);
  311. }
  312. public function serviceGetPageObjectForPageTrigger ($sPageTriggerName)
  313. {
  314. if (isset($this->_oConfig->CNF['TRIGGER_PAGE_VIEW_ENTRY']) && $this->_oConfig->CNF['TRIGGER_PAGE_VIEW_ENTRY'] == $sPageTriggerName)
  315. return $this->_oConfig->CNF['OBJECT_PAGE_VIEW_ENTRY'];
  316. return '';
  317. }
  318. public function serviceProfilesSearch ($sTerm, $mixedParams)
  319. {
  320. $aRet = [];
  321. $a = $this->_oDb->searchByTerm($sTerm, $mixedParams);
  322. foreach ($a as $r) {
  323. $oProfile = BxDolProfile::getInstance($r['profile_id']);
  324. $aItem = [];
  325. if ($this->_bIsApi) {
  326. $aData = $oProfile->getUnitAPI(0, ['template' => 'unit_wo_info']);
  327. $aData['author_data']['label'] = $this->serviceProfileName($r['content_id']);
  328. $aItem = $aData['author_data'];
  329. }
  330. else{
  331. $aItem = [
  332. 'label' => $this->serviceProfileName($r['content_id']),
  333. 'value' => $r['profile_id'],
  334. 'url' => $oProfile->getUrl(),
  335. 'thumb' => $oProfile->getThumb(),
  336. 'unit' => $oProfile->getUnit(0, ['template' => ['name' => 'unit_wo_info', 'size' => 'icon']])
  337. ];
  338. }
  339. $aRet[] = array_merge($aItem, [
  340. 'weight' => $r['profile_weight'] ?? 0
  341. ]);
  342. }
  343. return $aRet;
  344. }
  345. /**
  346. * @page service Service Calls
  347. * @section bx_base_profile Base Profile
  348. * @subsection bx_base_profile-general General
  349. * @subsubsection bx_base_profile-profile_unit_safe profile_unit_safe
  350. *
  351. * @code bx_srv('bx_persons', 'profile_unit_safe', [...]); @endcode
  352. *
  353. * Get profile unit
  354. * @param $iContentId content ID
  355. *
  356. * @see BxBaseModProfileModule::serviceProfileUnitSafe
  357. */
  358. /**
  359. * @ref bx_base_profile-profile_unit_safe "profile_unit_safe"
  360. */
  361. public function serviceProfileUnitSafe ($iContentId, $aParams = array())
  362. {
  363. unset($aParams['check_private_content']);
  364. return $this->serviceProfileUnit ($iContentId, $aParams);
  365. }
  366. public function serviceProfileUnit ($iContentId, $aParams = [])
  367. {
  368. $mixedContent = $this->_getContent($iContentId);
  369. if($mixedContent === false)
  370. return false;
  371. list($iContentId, $aContentInfo) = $mixedContent;
  372. $bCheckPrivateContent = isset($aParams['check_private_content']) ? (bool)$aParams['check_private_content'] : true;
  373. $aUnitTemplate = ['name' => 'unit.html', 'size' => false, 'vars' => []];
  374. if(!empty($aParams['template'])) {
  375. $mixedTemplate = $aParams['template'];
  376. unset($aParams['template']);
  377. if(is_string($mixedTemplate))
  378. $aUnitTemplate['name'] = $mixedTemplate . '.html';
  379. else if(is_array($mixedTemplate)) {
  380. if(!empty($mixedTemplate['name']))
  381. $aUnitTemplate['name'] = $mixedTemplate['name'] . '.html';
  382. if(!empty($mixedTemplate['size']))
  383. $aUnitTemplate['size'] = $mixedTemplate['size'];
  384. if(!empty($mixedTemplate['vars']))
  385. $aUnitTemplate['vars'] = $mixedTemplate['vars'];
  386. }
  387. }
  388. $aUnitParams = [];
  389. if(!empty($aParams))
  390. $aUnitParams = $aParams;
  391. return $this->_oTemplate->unit($aContentInfo, $bCheckPrivateContent, array_values($aUnitTemplate), $aUnitParams);
  392. }
  393. public function serviceProfileUnitApi ($iContentId, $aParams = [])
  394. {
  395. $mixedContent = $this->_getContent($iContentId);
  396. if($mixedContent === false)
  397. return false;
  398. list($iContentId, $aContentInfo) = $mixedContent;
  399. return $this->_oTemplate->unitAPI($aContentInfo, $aParams);
  400. }
  401. public function serviceHasImage ($iContentId)
  402. {
  403. $CNF = &$this->_oConfig->CNF;
  404. $mixedContent = $this->_getContent($iContentId, 'getContentInfoById');
  405. if($mixedContent === false)
  406. return false;
  407. list($iContentId, $aContentInfo) = $mixedContent;
  408. return !empty($aContentInfo[$CNF['FIELD_PICTURE']]);
  409. }
  410. public function serviceProfilePicture ($iContentId)
  411. {
  412. return $this->_serviceTemplateFunc('urlPicture', $iContentId);
  413. }
  414. public function serviceProfileAvatar ($iContentId)
  415. {
  416. return $this->_serviceTemplateFunc('urlAvatar', $iContentId);
  417. }
  418. public function serviceProfileAvatarBig ($iContentId)
  419. {
  420. return $this->_serviceTemplateFunc('urlAvatarBig', $iContentId);
  421. }
  422. public function serviceProfileCover ($iContentId)
  423. {
  424. return $this->_serviceTemplateFunc('urlCover', $iContentId);
  425. }
  426. public function serviceProfileUnitCover ($iContentId)
  427. {
  428. return $this->_serviceTemplateFunc('urlCoverUnit', $iContentId);
  429. }
  430. public function serviceProfileEditUrl ($iContentId)
  431. {
  432. return bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $this->_oConfig->CNF['URI_EDIT_ENTRY'] . '&id=' . $iContentId));
  433. }
  434. public function serviceProfileThumb ($iContentId)
  435. {
  436. return $this->_serviceTemplateFunc('urlThumb', $iContentId);
  437. }
  438. public function serviceProfileIcon ($iContentId)
  439. {
  440. return $this->_serviceTemplateFunc('urlIcon', $iContentId);
  441. }
  442. public function serviceProfileName ($iContentId)
  443. {
  444. if (!$iContentId)
  445. return false;
  446. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  447. if (!$aContentInfo)
  448. return false;
  449. $sDisplayName = $this->getProfileName($aContentInfo);
  450. /**
  451. * @hooks
  452. * @hookdef hook-bx_base_profile-profile_name '{module_name}', 'profile_name' - hook to override profile display name
  453. * - $unit_name - module name
  454. * - $action - equals `profile_name`
  455. * - $object_id - profile id
  456. * - $sender_id - not used
  457. * - $extra_params - array of additional params with the following array keys:
  458. * - `info` - [array] profile info array as key&value pairs
  459. * - `display_name` - [string] by ref, profile display name, can be overridden in hook processing
  460. * @hook @ref hook-bx_base_profile-profile_name
  461. */
  462. bx_alert($this->getName(), 'profile_name', $aContentInfo['profile_id'], 0, [
  463. 'info' => $aContentInfo,
  464. 'display_name' => &$sDisplayName,
  465. 'display_name_ref' => &$sDisplayName
  466. ]);
  467. return $sDisplayName;
  468. }
  469. public function serviceProfileSettings ($iContentId)
  470. {
  471. if (!$iContentId)
  472. return false;
  473. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  474. if (!$aContentInfo)
  475. return false;
  476. if (isset($aContentInfo['settings']))
  477. return json_decode($aContentInfo['settings']);
  478. }
  479. public function serviceProfileSettingsSet ($iContentId, $oValue)
  480. {
  481. $CNF = $this->_oConfig->CNF;
  482. $this->_oDb->updateEntriesBy(['settings' => json_encode($oValue)], [$CNF['FIELD_ID'] => $iContentId]);
  483. }
  484. public function serviceProfileCreateUrl ($bAbsolute = true)
  485. {
  486. $CNF = $this->_oConfig->CNF;
  487. if(empty($CNF['URL_CREATE']))
  488. return false;
  489. return $bAbsolute ? bx_absolute_url(BxDolPermalinks::getInstance()->permalink($CNF['URL_CREATE'])) : $CNF['URL_CREATE'];
  490. }
  491. /**
  492. * @page service Service Calls
  493. * @section bx_base_profile Base Profile
  494. * @subsection bx_base_profile-general General
  495. * @subsubsection bx_base_profile-profile_url profile_url
  496. *
  497. * @code bx_srv('bx_persons', 'profile_url', [...]); @endcode
  498. *
  499. * Get profile URL
  500. * @param $iContentId content ID
  501. *
  502. * @see BxBaseModProfileModule::serviceProfileUrl
  503. */
  504. /**
  505. * @ref bx_base_profile-profile_url "profile_url"
  506. */
  507. public function serviceProfileUrl ($iContentId)
  508. {
  509. if (!$iContentId)
  510. return false;
  511. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  512. if (!$aContentInfo)
  513. return false;
  514. $CNF = $this->_oConfig->CNF;
  515. return bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]));
  516. }
  517. /**
  518. * @see iBxDolProfileService::serviceGetSpaceTitle
  519. */
  520. public function serviceGetSpaceTitle()
  521. {
  522. return _t('_sys_ps_space_title_friend');
  523. }
  524. /**
  525. * @see iBxDolProfileService::serviceGetParticipatingProfiles
  526. */
  527. public function serviceGetParticipatingProfiles($iProfileId, $aConnectionObjects = false)
  528. {
  529. if (false === $aConnectionObjects)
  530. $aConnectionObjects = array('sys_profiles_friends');
  531. $a = array();
  532. foreach ($aConnectionObjects as $sConnectionObject) {
  533. if (!($o = BxDolConnection::getObjectInstance($sConnectionObject)))
  534. continue;
  535. if (BX_CONNECTIONS_TYPE_MUTUAL == $o->getType())
  536. $a = array_merge($a, $o->getConnectedContentByType($iProfileId, $this->getName(), true));
  537. else
  538. $a = array_merge($a, $o->getConnectedContentByType($iProfileId, $this->getName()));
  539. }
  540. $aRet = array_unique($a);
  541. // the check for an ability to post in profile has been moved to BxDolPrivacy because we need to have an extended check
  542. // with an ability to check for extended roles taking into account the type of content which is going be posted/edited
  543. // so now this service returns just a fans, not filtered by an ability to post into an entry's context
  544. /*foreach ($a as $iConnectedProfileId) {
  545. if (!($oConnectedProfile = BxDolProfile::getInstance($iConnectedProfileId)))
  546. continue;
  547. if (CHECK_ACTION_RESULT_ALLOWED === bx_srv($oConnectedProfile->getModule(), 'check_allowed_post_in_profile', array($oConnectedProfile->getContentId(), $iProfileId)))
  548. $aRet[] = $iConnectedProfileId;
  549. }*/
  550. /**
  551. * @hooks
  552. * @hookdef hook-system-get_participating_profiles 'system', 'get_participating_profiles' - hook to override context participants list
  553. * - $unit_name - equals `system`
  554. * - $action - equals `get_participating_profiles`
  555. * - $object_id - context profile id
  556. * - $sender_id - not used
  557. * - $extra_params - array of additional params with the following array keys:
  558. * - `module` - [string] module name
  559. * - `profiles` - [array] by ref, a list of participating profiles ids, can be overridden in hook processing
  560. * @hook @ref hook-system-get_participating_profiles
  561. */
  562. bx_alert('system', 'get_participating_profiles', $iProfileId, false, [
  563. 'module' => $this->_oConfig->getName(),
  564. 'profiles' => &$aRet,
  565. 'profiles_ref' => &$aRet
  566. ]);
  567. return $aRet;
  568. }
  569. /**
  570. * Prepare fields from some universal set of fields to fields in particular profile module.
  571. * By default only 'name' and 'description' fields are supported.
  572. * After fields convertion it can be used in @see BxBaseModGeneralModule::serviceEntityAdd
  573. * @param $aFieldsProfile fields in soem universal format.
  574. * @return array which is ready to use for particular module
  575. */
  576. public function servicePrepareFields ($aFieldsProfile)
  577. {
  578. /**
  579. * @hooks
  580. * @hookdef hook-bx_base_profile-prepare_fields '{module_name}', 'prepare_fields' - hook to override prepared profile fields
  581. * - $unit_name - module name
  582. * - $action - equals `prepare_fields`
  583. * - $object_id - not used
  584. * - $sender_id - not used
  585. * - $extra_params - array of additional params with the following array keys:
  586. * - `fields_orig` - [array] original fields array as key&value pairs
  587. * - `fields_result` - [array] by ref, resulting fields array as key&value pairs, can be overridden in hook processing
  588. * @hook @ref hook-bx_base_profile-prepare_fields
  589. */
  590. bx_alert($this->getName(), 'prepare_fields', 0, 0, [
  591. 'fields_orig' => $aFieldsProfile,
  592. 'fields_result' => &$aFieldsProfile
  593. ]);
  594. return $aFieldsProfile;
  595. }
  596. protected function _servicePrepareFields ($aFieldsProfile, $aFieldsDefault, $aMap)
  597. {
  598. $aFieldsOrig = $aFieldsProfile;
  599. bx_import('BxDolPrivacy');
  600. $aFieldsDefault2 = array(
  601. 'allow_view_to' => BX_DOL_PG_ALL,
  602. 'allow_contact_to' => BX_DOL_PG_ALL,
  603. 'allow_post_to' => BX_DOL_PG_FRIENDS,
  604. );
  605. $aFieldsProfile = array_merge($aFieldsDefault2, $aFieldsDefault, $aFieldsProfile);
  606. foreach ($aMap as $k => $v) {
  607. if (isset($aFieldsProfile[$v]))
  608. $aFieldsProfile[$k] = $aFieldsProfile[$v];
  609. if ($k != $v && !isset($aMap[$v]))
  610. unset($aFieldsProfile[$v]);
  611. }
  612. /**
  613. * @hooks
  614. * @hookdef hook-bx_base_profile-prepare_fields '{module_name}', 'prepare_fields' - hook to override prepared profile fields
  615. * - $unit_name - module name
  616. * - $action - equals `prepare_fields`
  617. * - $object_id - not used
  618. * - $sender_id - not used
  619. * - $extra_params - array of additional params with the following array keys:
  620. * - `fields_orig` - [array] original fields array as key&value pairs
  621. * - `fields_result` - [array] by ref, resulting fields array as key&value pairs, can be overridden in hook processing
  622. * @hook @ref hook-bx_base_profile-prepare_fields
  623. */
  624. bx_alert($this->getName(), 'prepare_fields', 0, 0, [
  625. 'fields_orig' => $aFieldsOrig,
  626. 'fields_result' => &$aFieldsProfile
  627. ]);
  628. return $aFieldsProfile;
  629. }
  630. public function serviceFormsHelper ()
  631. {
  632. return parent::serviceFormsHelper ();
  633. }
  634. /**
  635. * @page service Service Calls
  636. * @section bx_base_profile Base Profile
  637. * @subsection bx_base_profile-forms Forms
  638. * @subsubsection bx_base_profile-entity_create entity_create
  639. *
  640. * @code bx_srv('bx_persons', 'entity_create', [...]); @endcode
  641. *
  642. * Get profile creation form
  643. * @param $sDisplay optional form display name
  644. *
  645. * @see BxBaseModProfileModule::serviceEntityCreate
  646. */
  647. /**
  648. * @ref bx_base_profile-entity_create "entity_create"
  649. */
  650. public function serviceEntityCreate ($sDisplay = false)
  651. {
  652. BxDolInformer::getInstance($this->_oTemplate)->setEnabled(false);
  653. return parent::serviceEntityCreate ($sDisplay);
  654. }
  655. public function serviceActAsProfile ()
  656. {
  657. return true;
  658. }
  659. /**
  660. * @page service Service Calls
  661. * @section bx_base_profile Base Profile
  662. * @subsection bx_base_profile-browse Browse
  663. * @subsubsection bx_base_profile-browse_recommended browse_recommended
  664. *
  665. * @code bx_srv('bx_persons', 'browse_recommended', [...]); @endcode
  666. *
  667. * Browse recommended profiles
  668. * @param $sUnitView optional, unit view, for example - showcase
  669. * @param $bEmptyMessage optional, display or not "empty" message when there is no content
  670. * @param $bAjaxPaginate optional, use AJAX paginate or not
  671. *
  672. * @see BxBaseModProfileModule::serviceBrowseRecommended
  673. */
  674. /**
  675. * @ref bx_base_profile-browse_recommended "browse_recommended"
  676. */
  677. public function serviceBrowseRecommended ($sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = true)
  678. {
  679. if (!isLogged())
  680. return '';
  681. return $this->_serviceBrowse ('recommended', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  682. }
  683. /**
  684. * @page service Service Calls
  685. * @section bx_base_profile Base Profile
  686. * @subsection bx_base_profile-browse Browse
  687. * @subsubsection bx_base_profile-browse_recent_profiles browse_recent_profiles
  688. *
  689. * @code bx_srv('bx_persons', 'browse_recent_profiles', [...]); @endcode
  690. *
  691. * Browse recently joined profiles
  692. * @param $bEmptyMessage optional, display or not "empty" message when there is no content
  693. * @param $bAjaxPaginate optional, use AJAX paginate or not
  694. *
  695. * @see BxBaseModProfileModule::serviceBrowseRecentProfiles
  696. */
  697. /**
  698. * @ref bx_base_profile-browse_recent_profiles "browse_recent_profiles"
  699. */
  700. public function serviceBrowseRecentProfiles ($bDisplayEmptyMsg = false, $bAjaxPaginate = true, $sUnitView = false)
  701. {
  702. return $this->_serviceBrowse ('recent', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate);
  703. }
  704. /**
  705. * @page service Service Calls
  706. * @section bx_base_profile Base Profile
  707. * @subsection bx_base_profile-browse Browse
  708. * @subsubsection bx_base_profile-browse_active_profiles browse_active_profiles
  709. *
  710. * @code bx_srv('bx_persons', 'browse_active_profiles', [...]); @endcode
  711. *
  712. * Browse recently active profiles
  713. * @param $bEmptyMessage optional, display or not "empty" message when there is no content
  714. * @param $bAjaxPaginate optional, use AJAX paginate or not
  715. *
  716. * @see BxBaseModProfileModule::serviceBrowseActiveProfiles
  717. */
  718. /**
  719. * @ref bx_base_profile-browse_active_profiles "browse_active_profiles"
  720. */
  721. public function serviceBrowseActiveProfiles ($sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = false)
  722. {
  723. return $this->_serviceBrowse ('active', $sUnitView ? array('unit_view' => $sUnitView) : false, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  724. }
  725. /**
  726. * @page service Service Calls
  727. * @section bx_base_profile Base Profile
  728. * @subsection bx_base_profile-browse Browse
  729. * @subsubsection bx_base_profile-browse_familiar_profiles browse_familiar_profiles
  730. *
  731. * @code bx_srv('bx_persons', 'browse_familiar_profiles', [...]); @endcode
  732. *
  733. * Browse profiles you might be familiar with. By default using 'Profile Friends' connection.
  734. * @param $bEmptyMessage optional, display or not "empty" message when there is no content
  735. * @param $bAjaxPaginate optional, use AJAX paginate or not
  736. *
  737. * @see BxBaseModProfileModule::serviceBrowseFamiliarProfiles
  738. */
  739. /**
  740. * @ref bx_base_profile-browse_familiar_profiles "browse_familiar_profiles"
  741. */
  742. public function serviceBrowseFamiliarProfiles ($sConnection = '', $sUnitView = false, $bEmptyMessage = false, $bAjaxPaginate = false)
  743. {
  744. $aParams = [
  745. 'object' => 'sys_profiles_friends',
  746. 'profile' => bx_get_logged_profile_id(),
  747. ];
  748. if(!empty($sConnection)) {
  749. if(is_string($sConnection))
  750. $aParams['object'] = $sConnection;
  751. else if(is_array($sConnection))
  752. $aParams = array_merge($aParams, $sConnection);
  753. }
  754. if($sUnitView)
  755. $aParams['unit_view'] = $sUnitView;
  756. return $this->_serviceBrowse ('familiar', $aParams, BX_DB_PADDING_DEF, $bEmptyMessage, $bAjaxPaginate);
  757. }
  758. /**
  759. * @page service Service Calls
  760. * @section bx_base_profile Base Profile
  761. * @subsection bx_base_profile-browse Browse
  762. * @subsubsection bx_base_profile-browse_top_profiles browse_top_profiles
  763. *
  764. * @code bx_srv('bx_persons', 'browse_top_profiles', [...]); @endcode
  765. *
  766. * Browse top profiles
  767. * @param $bEmptyMessage optional, display or not "empty" message when there is no content
  768. * @param $bAjaxPaginate optional, use AJAX paginate or not
  769. *
  770. * @see BxBaseModProfileModule::serviceBrowseTopProfiles
  771. */
  772. /**
  773. * @ref bx_base_profile-browse_top_profiles "browse_top_profiles"
  774. */
  775. public function serviceBrowseTopProfiles ($bDisplayEmptyMsg = false, $bAjaxPaginate = false)
  776. {
  777. return $this->_serviceBrowse ('top', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate);
  778. }
  779. /**
  780. * @page service Service Calls
  781. * @section bx_base_profile Base Profile
  782. * @subsection bx_base_profile-browse Browse
  783. * @subsubsection bx_base_profile-browse_online_profiles browse_online_profiles
  784. *
  785. * @code bx_srv('bx_persons', 'browse_online_profiles', [...]); @endcode
  786. *
  787. * Browse online profiles
  788. * @param $bEmptyMessage optional, display or not "empty" message when there is no content
  789. * @param $bAjaxPaginate optional, use AJAX paginate or not
  790. *
  791. * @see BxBaseModProfileModule::serviceBrowseOnlineProfiles
  792. */
  793. /**
  794. * @ref bx_base_profile-browse_online_profiles "browse_online_profiles"
  795. */
  796. public function serviceBrowseOnlineProfiles ($bDisplayEmptyMsg = false, $bAjaxPaginate = false)
  797. {
  798. return $this->_serviceBrowse ('online', false, BX_DB_PADDING_DEF, $bDisplayEmptyMsg, $bAjaxPaginate);
  799. }
  800. public function serviceBrowseConnections ($iProfileId, $sObjectConnections = 'sys_profiles_friends', $sConnectionsType = 'content', $iMutual = false, $iDesignBox = BX_DB_PADDING_DEF, $iProfileId2 = 0)
  801. {
  802. return $this->_serviceBrowse (
  803. 'connections', [
  804. 'object' => $sObjectConnections,
  805. 'type' => $sConnectionsType,
  806. 'mutual' => $iMutual,
  807. 'profile' => (int)$iProfileId,
  808. 'profile2' => (int)$iProfileId2
  809. ], $iDesignBox
  810. );
  811. }
  812. public function serviceBrowseRelationsQuick ($iProfileId, $sObjectConnections = 'sys_profiles_friends', $sConnectionsType = 'content', $iMutual = false, $iProfileId2 = 0)
  813. {
  814. // get connections object
  815. $oConnection = BxDolConnection::getObjectInstance($sObjectConnections);
  816. if (!$oConnection)
  817. return '';
  818. // set some vars
  819. $iStart = (int)bx_get('start');
  820. $iLimit = empty($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? 4 : getParam($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']);
  821. if (!$iLimit)
  822. $iLimit = 4;
  823. // get connections array
  824. bx_import('BxDolConnection');
  825. $aConnections = $oConnection->getConnectionsAsArrayExt($sConnectionsType, $iProfileId, $iProfileId2, $iMutual, $iStart, $iLimit + 1, BX_CONNECTIONS_ORDER_ADDED_DESC);
  826. if(empty($aConnections) || !is_array($aConnections))
  827. return '';
  828. $aResult = array();
  829. foreach($aConnections as $iProfile => $aConnection)
  830. $aResult[] = array(
  831. 'id' => $iProfile,
  832. 'info' => array(
  833. 'addon' => $oConnection->getRelationTranslation($aConnection['relation'])
  834. )
  835. );
  836. return $this->_serviceBrowseQuick($aResult, $iStart, $iLimit);
  837. }
  838. public function serviceBrowseConnectionsQuick ($iProfileId, $sObjectConnections = 'sys_profiles_friends', $sConnectionsType = 'content', $iMutual = false, $iProfileId2 = 0)
  839. {
  840. // get connections object
  841. $oConnection = BxDolConnection::getObjectInstance($sObjectConnections);
  842. if (!$oConnection)
  843. return '';
  844. // set some vars
  845. $iLimit = empty($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? 4 : getParam($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']);
  846. if (!$iLimit)
  847. $iLimit = 4;
  848. $iStart = (int)bx_get('start');
  849. // get connections array
  850. bx_import('BxDolConnection');
  851. $a = $oConnection->getConnectionsAsArray ($sConnectionsType, $iProfileId, $iProfileId2, $iMutual, (int)bx_get('start'), $iLimit + 1, BX_CONNECTIONS_ORDER_ADDED_DESC);
  852. if (!$a)
  853. return '';
  854. return $this->_serviceBrowseQuick($a, $iStart, $iLimit);
  855. }
  856. public function serviceBrowseConnectionsByType ($aParamsCnn, $aParamsBrs = array())
  857. {
  858. $sAll = 'all';
  859. $aParamsCnn['object'] = !empty($aParamsCnn['object']) ? $aParamsCnn['object'] : 'sys_profiles_friends';
  860. $aParamsCnn['type'] = !empty($aParamsCnn['type']) ? $aParamsCnn['type'] : 'content';
  861. $aParamsCnn['profile_id2'] = !empty($aParamsCnn['profile_id2']) ? (int)$aParamsCnn['profile_id2'] : 0;
  862. $aParamsCnn['mutual'] = isset($aParamsCnn['mutual']) ? $aParamsCnn['mutual'] : false;
  863. $oConnection = BxDolConnection::getObjectInstance($aParamsCnn['object']);
  864. if(!$oConnection)
  865. return '';
  866. $aSQLParts = $oConnection->getConnectionsAsSQLParts ($aParamsCnn['type'], 'sys_profiles', 'id', $aParamsCnn['profile_id'], $aParamsCnn['profile_id2'], $aParamsCnn['mutual']);
  867. $sType = !empty($aParamsBrs['type']) ? $aParamsBrs['type'] : $sAll;
  868. if(bx_get('type') !== false)
  869. $sType = bx_process_input(bx_get('type'));
  870. $iStart = (int)bx_get('start');
  871. $iLimitDefault = 4;
  872. $iLimit = !empty($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) ? getParam($this->_oConfig->CNF['PARAM_NUM_CONNECTIONS_QUICK']) : $iLimitDefault;
  873. if(!empty($aParamsBrs['per_page']))
  874. $iLimit = (int)$aParamsBrs['per_page'];
  875. if(!$iLimit)
  876. $iLimit = $iLimitDefault;
  877. $aProfiles = BxDolProfileQuery::getInstance()->getConnectedProfilesByType($aSQLParts, ($sType != $sAll ? $sType : ''), $iStart, $iLimit + 1);
  878. $mixedMenu = '';
  879. if(!isset($aParamsBrs['filter_menu']) || $aParamsBrs['filter_menu'] === true) {
  880. $aModules = array(
  881. array('name' => $sAll)
  882. );
  883. $aModules = array_merge($aModules, BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1)));
  884. $aMenuItems = array();
  885. foreach($aModules as $aModule)
  886. if($aModule['name'] == $sAll || BxDolRequest::serviceExists($aModule['name'], 'act_as_profile'))
  887. $aMenuItems[] = array(
  888. 'id' => $aModule['name'],
  889. 'name' => $aModule['name'],
  890. 'class' => '',
  891. 'link' => 'javascript:void(0)',
  892. 'onclick' => "return !loadDynamicBlockAutoPaginate(this, " . $iStart . ", " . $iLimit . ", " . bx_js_string(json_encode(array('type' => $aModule['name']))) . ");",
  893. 'target' => '_self',
  894. 'title' => _t('_' . $aModule['name']),
  895. 'active' => 1
  896. );
  897. if(!empty($aMenuItems)) {
  898. $mixedMenu = new BxTemplMenu(array('template' => 'menu_vertical.html', 'menu_id'=> $this->_oConfig->getName() . '-connections-by-type', 'menu_items' => $aMenuItems));
  899. $mixedMenu->setSelected('', $sType);
  900. }
  901. }
  902. return array(
  903. 'menu' => $mixedMenu,
  904. 'content' => $this->_serviceBrowseQuick(array_keys($aProfiles), $iStart, $iLimit, array('type' => $sType))
  905. );
  906. }
  907. /**
  908. * @page service Service Calls
  909. * @section bx_base_profile Base Profile
  910. * @subsection bx_base_profile-browse Browse
  911. * @subsubsection bx_base_profile-browse_by_acl browse_by_acl
  912. *
  913. * @code bx_srv('bx_persons', 'browse_by_acl', [...]); @endcode
  914. *
  915. * Browse profiles by membership(ACL) level
  916. * @param $mixedLevelId membership level, or array of membership levels
  917. * @param $iDesignBox optional, design box identifier
  918. *
  919. * @see BxBaseModProfileModule::serviceBrowseByAcl
  920. */
  921. /**
  922. * @ref bx_base_profile-browse_by_acl "browse_by_acl"
  923. */
  924. public function serviceBrowseByAcl ($mixedLevelId, $iDesignBox = BX_DB_PADDING_DEF)
  925. {
  926. return $this->_serviceBrowse (
  927. 'acl',
  928. array(
  929. 'level' => $mixedLevelId,
  930. ),
  931. $iDesignBox,
  932. true
  933. );
  934. }
  935. public function serviceEntityEditCover($iContentId = 0)
  936. {
  937. return $this->_serviceEntityForm('editDataForm', $iContentId, $this->_oConfig->CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT_COVER']);
  938. }
  939. public function serviceEntityEditBadge($iContentId = 0)
  940. {
  941. return $this->_serviceEntityForm('editDataForm', $iContentId, $this->_oConfig->CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT_BADGE'], 'checkAllowedChangeBadge');
  942. }
  943. public function serviceEntityEditSettings($iContentId = 0)
  944. {
  945. $CNF = &$this->_oConfig->CNF;
  946. if(empty($CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT_SETTINGS']))
  947. return false;
  948. return $this->_serviceEntityForm('editDataForm', $iContentId, $CNF['OBJECT_FORM_ENTRY_DISPLAY_EDIT_SETTINGS']);
  949. }
  950. /**
  951. * @page service Service Calls
  952. * @section bx_base_profile Base Profile
  953. * @subsection bx_base_profile-page_blocks Page Blocks
  954. * @subsubsection bx_base_profile-entity_cover entity_cover
  955. *
  956. * @code bx_srv('bx_persons', 'entity_cover', [...]); @endcode
  957. *
  958. * Get cover
  959. * @param $iContentId content ID
  960. *
  961. * @see BxBaseModProfileModule::serviceEntityCover
  962. */
  963. /**
  964. * @ref bx_base_general-entity_cover "entity_cover"
  965. */
  966. public function serviceEntityCover ($iContentId = 0, $aParams = [])
  967. {
  968. $mixedContent = $this->_getContent($iContentId);
  969. if($mixedContent === false)
  970. return false;
  971. list($iContentId, $aContentInfo) = $mixedContent;
  972. if($this->_bIsApi) {
  973. $CNF = &$this->_oConfig->CNF;
  974. $aContentInfo['cover'] = $this->serviceGetCover($iContentId);
  975. $aContentInfo['image'] = $this->serviceGetThumb($iContentId);
  976. $sKey = 'OBJECT_MENU_VIEW_ENTRY_META';
  977. if(!empty($CNF[$sKey]) && ($oMetaMenu = BxTemplMenu::getObjectInstance($CNF[$sKey])) !== false)
  978. $aContentInfo['meta_menu'] = $oMetaMenu->getCodeAPI();
  979. $sKey = 'OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL';
  980. if(!empty($CNF[$sKey]) && ($oActionMenu = BxTemplMenu::getObjectInstance($CNF[$sKey])) !== false)
  981. $aContentInfo['actions_menu'] = $oActionMenu->getCodeAPI();
  982. if(($oMenuManage = BxDolMenu::getObjectInstance('sys_site_manage')) !== false) {
  983. if(!empty($CNF['FIELD_ID']))
  984. $oMenuManage->setContentId($aContentInfo[$CNF['FIELD_ID']]);
  985. $aObjectManage = [];
  986. if(!empty($CNF['OBJECT_MENU_MANAGE_VIEW_ENTRY']))
  987. $aObjectManage = [$CNF['OBJECT_MENU_MANAGE_VIEW_ENTRY']];
  988. else if(!empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']))
  989. $aObjectManage = [$CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE'], true];
  990. call_user_func_array([$oMenuManage, 'setObjectManage'], $aObjectManage);
  991. $aMenuManage = $oMenuManage->getCodeAPI();
  992. if(!empty($aMenuManage) && is_array($aMenuManage)) {
  993. if(isset($aContentInfo['actions_menu']) && is_array($aContentInfo['actions_menu']))
  994. $aContentInfo['actions_menu']['items'] = array_merge($aContentInfo['actions_menu']['items'], $aMenuManage['items']);
  995. else
  996. $aContentInfo['actions_menu'] = $aMenuManage;
  997. }
  998. }
  999. if(($oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName())) !== false);
  1000. $aContentInfo['profile'] = BxDolProfile::getData($oProfile, [
  1001. 'get_avatar' => 'getAvatarBig',
  1002. 'with_info' => false
  1003. ]);
  1004. return [bx_api_get_block('entity_cover', $aContentInfo)];
  1005. }
  1006. return $this->_oTemplate->getBlockCover($aContentInfo, $aParams);
  1007. }
  1008. /**
  1009. * Entry comments
  1010. */
  1011. public function serviceEntityCommentsByProfile ($iProfileId)
  1012. {
  1013. $CNF = &$this->_oConfig->CNF;
  1014. if(empty($CNF['OBJECT_COMMENTS']))
  1015. return '';
  1016. $oProfile = BxDolProfile::getInstance($iProfileId);
  1017. if(!$oProfile)
  1018. return '';
  1019. return $this->_entityComments($CNF['OBJECT_COMMENTS'], $oProfile->getContentId());
  1020. }
  1021. /**
  1022. * Entry social sharing block
  1023. */
  1024. public function serviceEntitySocialSharing ($mixedContent = false, $aParams = array())
  1025. {
  1026. $CNF = &$this->_oConfig->CNF;
  1027. if(!empty($mixedContent)) {
  1028. if(!is_array($mixedContent))
  1029. $mixedContent = array((int)$mixedContent, array());
  1030. }
  1031. else {
  1032. $mixedContent = $this->_getContent();
  1033. if($mixedContent === false)
  1034. return false;
  1035. }
  1036. list($iContentId, $aContentInfo) = $mixedContent;
  1037. return parent::serviceEntitySocialSharing(array($iContentId, $aContentInfo), array(
  1038. 'id_thumb' => !empty($CNF['FIELD_PICTURE']) && !empty($aContentInfo[$CNF['FIELD_PICTURE']]) ? $aContentInfo[$CNF['FIELD_PICTURE']] : 0,
  1039. ));
  1040. }
  1041. public function serviceProfileMembership ($iContentId = 0)
  1042. {
  1043. $mixedContent = $this->_getContent($iContentId);
  1044. if($mixedContent === false)
  1045. return false;
  1046. list($iContentId, $aContentInfo) = $mixedContent;
  1047. $mixedResult = BxDolAcl::getInstance()->getProfileMembership($aContentInfo['profile_id']);
  1048. return $this->_bIsApi ? [bx_api_get_block('entity_membership', $mixedResult)] : $mixedResult;
  1049. }
  1050. public function serviceProfileFriends ($iContentId = 0)
  1051. {
  1052. if(!$this->_oConfig->isFriends())
  1053. return false;
  1054. $mixedContent = $this->_getContent($iContentId);
  1055. if($mixedContent === false)
  1056. return false;
  1057. list($iContentId, $aContentInfo) = $mixedContent;
  1058. bx_import('BxDolConnection');
  1059. $s = $this->serviceBrowseConnectionsQuick ($aContentInfo['profile_id'], 'sys_profiles_friends', BX_CONNECTIONS_CONTENT_TYPE_CONTENT, true);
  1060. if (!$s)
  1061. return MsgBox(_t('_sys_txt_empty'));
  1062. return $s;
  1063. }
  1064. public function serviceProfileFriendsMutual ($iContentId = 0)
  1065. {
  1066. if(!$this->_oConfig->isFriends())
  1067. return false;
  1068. $mixedContent = $this->_getContent($iContentId);
  1069. if($mixedContent === false)
  1070. return false;
  1071. list($iContentId, $aContentInfo) = $mixedContent;
  1072. $iViewer = bx_get_logged_profile_id();
  1073. $iOwner = (int)$aContentInfo['profile_id'];
  1074. if($iViewer == $iOwner)
  1075. return false;
  1076. bx_import('BxDolConnection');
  1077. $s = $this->serviceBrowseConnectionsQuick ($iOwner, 'sys_profiles_friends', BX_CONNECTIONS_CONTENT_TYPE_COMMON, true, $iViewer);
  1078. if(!$s)
  1079. return MsgBox(_t('_sys_txt_empty'));
  1080. return $s;
  1081. }
  1082. public function serviceProfileSubscriptions ($iContentId = 0, $aParams = array())
  1083. {
  1084. $mixedContent = $this->_getContent($iContentId);
  1085. if($mixedContent === false)
  1086. return false;
  1087. list($iContentId, $aContentInfo) = $mixedContent;
  1088. bx_import('BxDolConnection');
  1089. $aResult = $this->serviceBrowseConnectionsByType(array(
  1090. 'profile_id' => $aContentInfo['profile_id'],
  1091. 'object' => 'sys_profiles_subscriptions',
  1092. 'type' => BX_CONNECTIONS_CONTENT_TYPE_CONTENT
  1093. ), array(
  1094. 'type' => isset($aParams['type']) ? $aParams['type'] : '',
  1095. 'filter_menu' => isset($aParams['filter_menu']) ? $aParams['filter_menu'] : true,
  1096. ));
  1097. if(empty($aResult['content']))
  1098. $aResult['content'] = MsgBox(_t('_sys_txt_empty'));
  1099. return $aResult;
  1100. }
  1101. public function serviceProfileSubscribedMe ($iContentId = 0)
  1102. {
  1103. $mixedContent = $this->_getContent($iContentId);
  1104. if($mixedContent === false)
  1105. return false;
  1106. list($iContentId, $aContentInfo) = $mixedContent;
  1107. bx_import('BxDolConnection');
  1108. $s = $this->serviceBrowseConnectionsQuick ($aContentInfo['profile_id'], 'sys_profiles_subscriptions', BX_CONNECTIONS_CONTENT_TYPE_INITIATORS);
  1109. if (!$s)
  1110. return MsgBox(_t('_sys_txt_empty'));
  1111. return $s;
  1112. }
  1113. public function serviceProfileRelations ($iContentId = 0, $aParams = array())
  1114. {
  1115. if(!BxDolConnectionRelation::isEnabled())
  1116. return false;
  1117. $mixedContent = $this->_getContent($iContentId);
  1118. if($mixedContent === false)
  1119. return false;
  1120. list($iContentId, $aContentInfo) = $mixedContent;
  1121. bx_import('BxDolConnection');
  1122. $s = $this->serviceBrowseRelationsQuick ($aContentInfo['profile_id'], 'sys_profiles_relations', BX_CONNECTIONS_CONTENT_TYPE_CONTENT, 1);
  1123. if (!$s)
  1124. return MsgBox(_t('_sys_txt_empty'));
  1125. return $s;
  1126. }
  1127. public function serviceProfileRelatedMe ($iContentId = 0)
  1128. {
  1129. if(!BxDolConnectionRelation::isEnabled())
  1130. return false;
  1131. $mixedContent = $this->_getContent($iContentId);
  1132. if($mixedContent === false)
  1133. return false;
  1134. list($iContentId, $aContentInfo) = $mixedContent;
  1135. bx_import('BxDolConnection');
  1136. $s = $this->serviceBrowseRelationsQuick ($aContentInfo['profile_id'], 'sys_profiles_relations', BX_CONNECTIONS_CONTENT_TYPE_INITIATORS, 1);
  1137. if (!$s)
  1138. return MsgBox(_t('_sys_txt_empty'));
  1139. return $s;
  1140. }
  1141. /**
  1142. * check enabled profile activation letter
  1143. */
  1144. public function serviceIsEnableProfileActivationLetter()
  1145. {
  1146. $CNF = &$this->_oConfig->CNF;
  1147. return isset($CNF['PARAM_ENABLE_ACTIVATION_LETTER']) ? (bool)getParam($CNF['PARAM_ENABLE_ACTIVATION_LETTER']) : true;
  1148. }
  1149. public function serviceIsEnableFriends()
  1150. {
  1151. return $this->_oConfig->isFriends();
  1152. }
  1153. public function serviceIsEnableRelations()
  1154. {
  1155. if(!BxDolConnectionRelation::isEnabled())
  1156. return false;
  1157. $sModule = $this->_oConfig->getName();
  1158. $oRelations = BxDolConnection::getObjectInstance('sys_profiles_relations');
  1159. return $oRelations->isRelationAvailableWithProfile($sModule) || $oRelations->isRelationAvailableFromProfile($sModule);
  1160. }
  1161. /**
  1162. * For internal usage only.
  1163. */
  1164. public function serviceDeleteEntityService ($iContentId, $bDeleteWithContent = false)
  1165. {
  1166. return parent::serviceDeleteEntity ($iContentId, 'deleteDataService');
  1167. }
  1168. /**
  1169. * Data for Notifications module
  1170. */
  1171. public function serviceGetNotificationsData()
  1172. {
  1173. $a = parent::serviceGetNotificationsData();
  1174. $sModule = $this->_aModule['name'];
  1175. $a['handlers'][] = array('group' => $sModule . '_timeline_post_common', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'timeline_post_common', 'module_name' => $sModule, 'module_method' => 'get_notifications_timeline_post_common', 'module_class' => 'Module');
  1176. $a['settings'][] = array('group' => 'timeline_post', 'unit' => $sModule, 'action' => 'timeline_post_common', 'types' => array('follow_member'));
  1177. $a['alerts'][] = array('unit' => $sModule, 'action' => 'timeline_post_common');
  1178. return $a;
  1179. }
  1180. public function serviceGetNotificationsPost($aEvent)
  1181. {
  1182. $aResult = parent::serviceGetNotificationsVote($aEvent);
  1183. if(empty($aResult) || !is_array($aResult) || !$this->serviceActAsProfile())
  1184. return $aResult;
  1185. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$aEvent['object_id'], $this->_oConfig->getName());
  1186. if($oProfile !== false)
  1187. $aResult['entry_author'] = $oProfile->id();
  1188. return $aResult;
  1189. }
  1190. public function serviceGetNotificationsVote($aEvent)
  1191. {
  1192. $aResult = parent::serviceGetNotificationsVote($aEvent);
  1193. if(empty($aResult) || !is_array($aResult) || !$this->serviceActAsProfile())
  1194. return $aResult;
  1195. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$aEvent['object_id'], $this->_oConfig->getName());
  1196. if($oProfile !== false)
  1197. $aResult['entry_author'] = $oProfile->id();
  1198. return $aResult;
  1199. }
  1200. /**
  1201. * Notification about new member requst in the group
  1202. */
  1203. public function serviceGetNotificationsTimelinePostCommon($aEvent)
  1204. {
  1205. $CNF = &$this->_oConfig->CNF;
  1206. $iContentId = (int)$aEvent['object_id'];
  1207. $oGroupProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->getName());
  1208. if(!$oGroupProfile)
  1209. return [];
  1210. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1211. if(empty($aContentInfo) || !is_array($aContentInfo))
  1212. return [];
  1213. $aSubcontentInfo = BxDolService::call('bx_timeline', 'get_info', array((int)$aEvent['subobject_id'], false));
  1214. if(empty($aSubcontentInfo) || !is_array($aSubcontentInfo))
  1215. return [];
  1216. $sEntrySummary = isset($aContentInfo[$CNF['FIELD_TEXT']]) ? $aContentInfo[$CNF['FIELD_TEXT']] : '';
  1217. $sSubentryUrl = bx_absolute_url(str_replace(BX_DOL_URL_ROOT, '', BxDolService::call('bx_timeline', 'get_link', array((int)$aEvent['subobject_id']))), '{bx_url_root}');
  1218. $sSubentrySample = $aSubcontentInfo['title'];
  1219. if(empty($sSubentrySample))
  1220. $sSubentrySample = strmaxtextlen($aSubcontentInfo['description'], 20, '...');
  1221. $sSubentrySummary = $aSubcontentInfo['description'];
  1222. return [
  1223. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1224. 'entry_url' => bx_absolute_url(str_replace(BX_DOL_URL_ROOT, '', $oGroupProfile->getUrl()), '{bx_url_root}'),
  1225. 'entry_caption' => $oGroupProfile->getDisplayName(),
  1226. 'entry_summary' => $sEntrySummary,
  1227. 'entry_author' => $oGroupProfile->id(),
  1228. 'subentry_sample' => $sSubentrySample,
  1229. 'subentry_url' => $sSubentryUrl,
  1230. 'subentry_summary' => $sSubentrySummary,
  1231. 'lang_key' => $CNF['T']['txt_ntfs_timeline_post_common'],
  1232. ];
  1233. }
  1234. /**
  1235. * Data for Timeline module
  1236. */
  1237. public function serviceGetTimelineData()
  1238. {
  1239. $CNF = &$this->_oConfig->CNF;
  1240. $sModule = $this->_aModule['name'];
  1241. $aResult = parent::serviceGetTimelineData();
  1242. if(!empty($CNF['FIELD_PICTURE'])) {
  1243. $aResult['handlers'] = array_merge($aResult['handlers'], [
  1244. ['group' => $sModule . '_profile_picture', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'profile_picture_changed', 'module_name' => $sModule, 'module_method' => 'get_timeline_profile_picture', 'module_class' => 'Module', 'groupable' => 0, 'group_by' => ''],
  1245. ['group' => $sModule . '_profile_picture', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'profile_picture_deleted']
  1246. ]);
  1247. $aResult['alerts'] = array_merge($aResult['alerts'], [
  1248. ['unit' => $sModule, 'action' => 'profile_picture_changed'],
  1249. ['unit' => $sModule, 'action' => 'profile_picture_deleted']
  1250. ]);
  1251. }
  1252. if(!empty($CNF['FIELD_COVER'])) {
  1253. $aResult['handlers'] = array_merge($aResult['handlers'], [
  1254. ['group' => $sModule . '_profile_cover', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'profile_cover_changed', 'module_name' => $sModule, 'module_method' => 'get_timeline_profile_cover', 'module_class' => 'Module', 'groupable' => 0, 'group_by' => ''],
  1255. ['group' => $sModule . '_profile_cover', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'profile_cover_deleted']
  1256. ]);
  1257. $aResult['alerts'] = array_merge($aResult['alerts'], [
  1258. ['unit' => $sModule, 'action' => 'profile_cover_changed'],
  1259. ['unit' => $sModule, 'action' => 'profile_cover_deleted']
  1260. ]);
  1261. }
  1262. return $aResult;
  1263. }
  1264. /**
  1265. * Entry post for Timeline module
  1266. */
  1267. public function serviceGetTimelinePost($aEvent, $aBrowseParams = [])
  1268. {
  1269. $mixedResult = parent::serviceGetTimelinePost($aEvent, $aBrowseParams);
  1270. if($mixedResult !== false && ($oAuthor = BxDolProfile::getInstanceByContentAndType($aEvent['object_id'], $this->_aModule['name'])) !== false)
  1271. $mixedResult['object_owner_id'] = $oAuthor->id();
  1272. /*
  1273. * Item should be shown to the author only as a 'welcome' item just after join.
  1274. */
  1275. $mixedResult['object_privacy_view'] = 2;
  1276. return $mixedResult;
  1277. }
  1278. /**
  1279. * Entry post for Timeline module
  1280. */
  1281. public function serviceGetTimelineProfilePicture($aEvent, $aBrowseParams = [])
  1282. {
  1283. $aResult = $this->_serviceGetTimelineProfileImage($aEvent, $aBrowseParams, [
  1284. 'stg' => 'OBJECT_STORAGE',
  1285. 'trans' => ['OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_AVATAR'],
  1286. 'trans_orig' => ['OBJECT_IMAGES_TRANSCODER_PICTURE', 'OBJECT_IMAGES_TRANSCODER_GALLERY'],
  1287. 'txt_ss' => 'txt_sample_pp_single',
  1288. 'txt_sswa' => 'txt_sample_pp_single_with_article',
  1289. 'txt_sa' => 'txt_sample_pi_action',
  1290. 'txt_sau' => 'txt_sample_pi_action_user'
  1291. ]);
  1292. if($aResult !== false)
  1293. $aResult['allowed_view'] = ['module' => $this->_oConfig->getName(), 'method' => 'get_timeline_profile_picture_allowed_view'];
  1294. return $aResult;
  1295. }
  1296. public function serviceGetTimelineProfilePictureAllowedView($aEvent)
  1297. {
  1298. return $this->_serviceGetTimelineProfileImageAllowedView($aEvent);
  1299. }
  1300. public function serviceGetTimelineProfileCover($aEvent, $aBrowseParams = [])
  1301. {
  1302. $aResult = $this->_serviceGetTimelineProfileImage($aEvent, $aBrowseParams, [
  1303. 'stg' => 'OBJECT_STORAGE_COVER',
  1304. 'trans' => ['OBJECT_IMAGES_TRANSCODER_GALLERY', 'OBJECT_IMAGES_TRANSCODER_COVER_THUMB'],
  1305. 'trans_orig' => ['OBJECT_IMAGES_TRANSCODER_COVER', 'OBJECT_IMAGES_TRANSCODER_GALLERY'],
  1306. 'txt_ss' => 'txt_sample_pc_single',
  1307. 'txt_sswa' => 'txt_sample_pc_single_with_article',
  1308. 'txt_sa' => 'txt_sample_pi_action',
  1309. 'txt_sau' => 'txt_sample_pi_action_user'
  1310. ]);
  1311. if($aResult !== false)
  1312. $aResult['allowed_view'] = ['module' => $this->_oConfig->getName(), 'method' => 'get_timeline_profile_cover_allowed_view'];
  1313. return $aResult;
  1314. }
  1315. public function serviceGetTimelineProfileCoverAllowedView($aEvent)
  1316. {
  1317. return $this->_serviceGetTimelineProfileImageAllowedView($aEvent);
  1318. }
  1319. public function serviceGetMenuItemTitleByConnection($sConnection, $sAction, $iContentProfileId, $iInitiatorProfileId = 0)
  1320. {
  1321. return $this->getMenuItemTitleByConnection($sConnection, $sAction, $iContentProfileId, $iInitiatorProfileId);
  1322. }
  1323. // ====== PERMISSION METHODS
  1324. /**
  1325. * @see iBxDolProfileService::serviceCheckAllowedProfileView
  1326. */
  1327. public function serviceCheckAllowedProfileView($iContentId)
  1328. {
  1329. return $this->serviceCheckAllowedWithContent('View', $iContentId);
  1330. }
  1331. /**
  1332. * @see iBxDolProfileService::serviceCheckAllowedProfileContact
  1333. */
  1334. public function serviceCheckAllowedProfileContact($iContentId)
  1335. {
  1336. return $this->serviceCheckAllowedWithContent('Contact', $iContentId);
  1337. }
  1338. /**
  1339. * @see iBxDolProfileService::serviceCheckAllowedPostInProfile
  1340. */
  1341. public function serviceCheckAllowedPostInProfile($iContentId, $sPostModule = '')
  1342. {
  1343. $CNF = &$this->_oConfig->CNF;
  1344. if(!empty($CNF['FIELD_ALLOW_VIEW_TO']) && getParam('sys_treat_cxt_in_cxt_as_cnt') == 'on') {
  1345. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  1346. if($aContentInfo && isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]) && (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] < 0)
  1347. return _t('_sys_txt_access_denied');
  1348. }
  1349. // for groups based profiles we do have a Role permissions which have a higher priority than the site-wide permissions.
  1350. if (method_exists($this, 'isAllowedModuleActionByProfile')) {
  1351. $iProfileId = $this->_iProfileId;
  1352. if(($sPrivacy = $CNF['OBJECT_PRIVACY_POST'] ?? false)) {
  1353. $oPrivacy = BxDolPrivacy::getObjectInstance($sPrivacy);
  1354. if($oPrivacy && !$oPrivacy->check($iContentId, $iProfileId))
  1355. return _t('_sys_access_denied_to_private_content');
  1356. }
  1357. // if a profile is having a role and a role is having permissions set then it overrides the site-wide setting.
  1358. if (($bResult = $this->isAllowedModuleActionByProfile($iContentId, $sPostModule, 'post', $iProfileId)) !== NULL)
  1359. return $bResult;
  1360. }
  1361. return $this->serviceCheckAllowedWithContent('Post', $iContentId);
  1362. }
  1363. /**
  1364. * @see iBxDolProfileService::serviceCheckAllowedModuleActionInProfile
  1365. */
  1366. public function serviceCheckAllowedModuleActionInProfile($iContentId, $sPostModule, $sActionName)
  1367. {
  1368. if (method_exists($this, 'isAllowedModuleActionByProfile')) {
  1369. $bResult = $this->isAllowedModuleActionByProfile($iContentId, $sPostModule, $sActionName);
  1370. if ($bResult !== NULL) return $bResult;
  1371. }
  1372. return _t('_Access denied');
  1373. }
  1374. /**
  1375. * @see iBxDolProfileService::serviceCheckSpacePrivacy
  1376. */
  1377. public function serviceCheckSpacePrivacy($iContentId)
  1378. {
  1379. return $this->serviceCheckAllowedProfileView($iContentId);
  1380. }
  1381. public function serviceCheckSpacePrivacyForProfile($iContentId, $iProfileId = false)
  1382. {
  1383. return $this->serviceCheckAllowedWithContentForProfile('View', $iContentId, $iProfileId);
  1384. }
  1385. /**
  1386. * Check if the profile can be viewed.
  1387. *
  1388. * NOTE. This service should be used if it's needed to pass some specific values in
  1389. * $isPerformAction and $iProfileId parameters, otherwise it's recommended to use
  1390. * BxBaseModProfileModule::serviceCheckAllowedProfileView service method or
  1391. * BxDolProfile::checkAllowedProfileView method.
  1392. *
  1393. * @param type $aDataEntry - entry which the action will be performed for
  1394. * @param type $isPerformAction - perform or just check the action
  1395. * @param type $iProfileId - performer's profile ID
  1396. * @return integer - one of CHECK_ACTION_RESULT_XXX constants.
  1397. */
  1398. public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  1399. {
  1400. if (!$iProfileId)
  1401. $iProfileId = $this->_iProfileId;
  1402. if(empty($aDataEntry) || !is_array($aDataEntry))
  1403. return _t('_sys_txt_not_found');
  1404. $sCacheKey = $this->getName() . ':' . __CLASS__ . ':serviceCheckAllowedViewForProfile:' . $aDataEntry['id'] . ':' . $iProfileId;
  1405. $mixedRet = bx_mem_cache_get($sCacheKey);
  1406. if (null !== $mixedRet)
  1407. return $mixedRet;
  1408. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
  1409. if ($oProfile && $oProfile->id() == $iProfileId)
  1410. $mixedRet = CHECK_ACTION_RESULT_ALLOWED;
  1411. else
  1412. $mixedRet = parent::serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
  1413. bx_mem_cache_set($sCacheKey, $mixedRet);
  1414. return $mixedRet;
  1415. }
  1416. /**
  1417. * Check if posting (comment, post in Timeline) is available.
  1418. *
  1419. * NOTE. This service should be used if it's needed to pass some specific values in
  1420. * $isPerformAction and $iProfileId parameters, otherwise it's recommended to use
  1421. * BxBaseModProfileModule::serviceCheckAllowedPostInProfile service method or
  1422. * BxDolProfile::checkAllowedPostInProfile method.
  1423. *
  1424. * @param type $aDataEntry - entry which the action will be performed for
  1425. * @param type $isPerformAction - perform or just check the action
  1426. * @param type $iProfileId - performer's profile ID
  1427. * @return integer - one of CHECK_ACTION_RESULT_XXX constants.
  1428. */
  1429. public function serviceCheckAllowedPostForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  1430. {
  1431. $CNF = &$this->_oConfig->CNF;
  1432. if(!$iProfileId)
  1433. $iProfileId = $this->_iProfileId;
  1434. // check is view allowed
  1435. if(($mixedResult = $this->serviceCheckAllowedViewForProfile($aDataEntry, $isPerformAction, $iProfileId)) !== CHECK_ACTION_RESULT_ALLOWED)
  1436. return $mixedResult;
  1437. // moderator and owner always have access
  1438. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->getName());
  1439. if(($oProfile && $oProfile->id() == $iProfileId) || $this->_isModerator($isPerformAction))
  1440. return CHECK_ACTION_RESULT_ALLOWED;
  1441. // check privacy
  1442. if(!empty($CNF['OBJECT_PRIVACY_POST'])) {
  1443. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_POST']);
  1444. if($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  1445. return _t('_sys_access_denied_to_private_content');
  1446. }
  1447. // check alert to allow custom checks
  1448. $mixedResult = null;
  1449. /**
  1450. * @hooks
  1451. * @hookdef hook-system-check_allowed_post 'system', 'check_allowed_post' - hook to override the result of checking whether 'post' action is allowed or not to specified profile
  1452. * It's equivalent to @ref hook-system-check_allowed_view
  1453. * @hook @ref hook-system-check_allowed_post
  1454. */
  1455. bx_alert('system', 'check_allowed_post', 0, 0, [
  1456. 'module' => $this->getName(),
  1457. 'content_info' => $aDataEntry,
  1458. 'profile_id' => $iProfileId,
  1459. 'override_result' => &$mixedResult
  1460. ]);
  1461. if($mixedResult !== null)
  1462. return $mixedResult;
  1463. return CHECK_ACTION_RESULT_ALLOWED;
  1464. }
  1465. /**
  1466. * Check if profile can be contacted.
  1467. *
  1468. * NOTE. This service should be used if it's needed to pass some specific values in
  1469. * $isPerformAction and $iProfileId parameters, otherwise it's recommended to use
  1470. * BxBaseModProfileModule::serviceCheckAllowedProfileContact service method or
  1471. * BxDolProfile::checkAllowedProfileContact method.
  1472. *
  1473. * @param type $aDataEntry - entry which the action will be performed for
  1474. * @param type $isPerformAction - perform or just check the action
  1475. * @param type $iProfileId - performer's profile ID
  1476. * @return integer - one of CHECK_ACTION_RESULT_XXX constants.
  1477. */
  1478. public function serviceCheckAllowedContactForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
  1479. {
  1480. $mixedResult = $this->_serviceCheckAllowedContactForProfile($aDataEntry, $isPerformAction, $iProfileId);
  1481. /**
  1482. * @hooks
  1483. * @hookdef hook-system-check_allowed_contact 'system', 'check_allowed_contact' - hook to override the result of checking whether 'contact' action is allowed or not to specified profile
  1484. * It's equivalent to @ref hook-system-check_allowed_view
  1485. * @hook @ref hook-system-check_allowed_contact
  1486. */
  1487. bx_alert('system', 'check_allowed_contact', 0, 0, [
  1488. 'module' => $this->getName(),
  1489. 'content_info' => $aDataEntry,
  1490. 'profile_id' => $iProfileId,
  1491. 'override_result' => &$mixedResult
  1492. ]);
  1493. return $mixedResult;
  1494. }
  1495. public function serviceSetViewProfileCover($oPage, $aProfileInfo)
  1496. {
  1497. $this->_oTemplate->setCover($oPage,$aProfileInfo);
  1498. }
  1499. /**
  1500. * Returns list of members by mode with limited number of records for React Jot
  1501. * @param string $sMode
  1502. * @param int $iStart
  1503. * @param int $iPerPage
  1504. * @return mixed
  1505. */
  1506. public function serviceGetMembers($sMode = 'active', $iStart = 0, $iPerPage = 10){
  1507. bx_import('SearchResult', $this->_aModule);
  1508. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  1509. $o = new $sClass($sMode);
  1510. $o -> aCurrent['paginate'] = array('perPage' => $iPerPage, 'forceStart' => $iStart);
  1511. return $o -> getSearchData();
  1512. }
  1513. /**
  1514. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1515. */
  1516. public function checkAllowedAdd ($isPerformAction = false)
  1517. {
  1518. if($this->serviceActAsProfile() && ($oAccount = BxDolAccount::getInstance()) !== false && $oAccount->isProfilesLimitReached())
  1519. return _t('_sys_txt_access_denied');
  1520. return parent::checkAllowedAdd ($isPerformAction);
  1521. }
  1522. /**
  1523. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
  1524. */
  1525. public function checkAllowedView ($aDataEntry, $isPerformAction = false)
  1526. {
  1527. return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
  1528. }
  1529. /**
  1530. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1531. */
  1532. public function checkAllowedViewProfileImage ($aDataEntry, $isPerformAction = false)
  1533. {
  1534. $CNF = &$this->_oConfig->CNF;
  1535. $sCacheKey = $this->getName() . ':' . __CLASS__ . ':checkAllowedViewProfileImage:' . $aDataEntry[$CNF['FIELD_ID']];
  1536. $mixedRet = bx_mem_cache_get($sCacheKey);
  1537. if (null !== $mixedRet)
  1538. return $mixedRet;
  1539. // check privacy
  1540. if (empty($CNF['OBJECT_PRIVACY_VIEW']) || isAdmin() || CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedEditAnyEntry()) {
  1541. $mixedRet = CHECK_ACTION_RESULT_ALLOWED;
  1542. }
  1543. elseif (($oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW'])) && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']]) && !$oPrivacy->isPartiallyVisible($aDataEntry[$CNF['FIELD_ALLOW_VIEW_TO']])) {
  1544. $mixedRet = _t('_sys_access_denied_to_private_content');
  1545. }
  1546. else {
  1547. $mixedRet = CHECK_ACTION_RESULT_ALLOWED;
  1548. }
  1549. bx_mem_cache_set($sCacheKey, $mixedRet);
  1550. return $mixedRet;
  1551. }
  1552. /**
  1553. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1554. */
  1555. public function checkAllowedViewCoverImage ($aDataEntry, $isPerformAction = false)
  1556. {
  1557. return $this->checkAllowedViewProfileImage($aDataEntry);
  1558. }
  1559. /**
  1560. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1561. */
  1562. public function checkAllowedViewBadgeImage ($aDataEntry, $isPerformAction = false)
  1563. {
  1564. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name']);
  1565. if(!$oProfile)
  1566. return _t('_sys_txt_error_occured');
  1567. $aCheck = checkActionModule($oProfile->id(), 'change badge', $this->_aModule['name'], false);
  1568. if($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1569. return $aCheck[CHECK_ACTION_MESSAGE];
  1570. return $this->checkAllowedViewProfileImage($aDataEntry, $isPerformAction);
  1571. }
  1572. /**
  1573. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1574. */
  1575. public function checkAllowedPost ($aDataEntry, $isPerformAction = false)
  1576. {
  1577. return $this->serviceCheckAllowedPostForProfile ($aDataEntry, $isPerformAction);
  1578. }
  1579. /**
  1580. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1581. */
  1582. public function checkAllowedContact ($aDataEntry, $isPerformAction = false)
  1583. {
  1584. return $this->serviceCheckAllowedContactForProfile ($aDataEntry, $isPerformAction);
  1585. }
  1586. /**
  1587. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1588. */
  1589. public function checkAllowedEdit ($aDataEntry, $isPerformAction = false)
  1590. {
  1591. if(empty($aDataEntry) || !is_array($aDataEntry))
  1592. return _t('_sys_txt_not_found');
  1593. // moderator always has access
  1594. if ($this->_isModerator($isPerformAction))
  1595. return CHECK_ACTION_RESULT_ALLOWED;
  1596. // owner (checked by account instead of author!) always have access
  1597. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name']);
  1598. if (!$oProfile)
  1599. return _t('_sys_txt_error_occured');
  1600. if ($oProfile->id() == $this->_iProfileId || $oProfile->getAccountId() == $this->_iAccountId)
  1601. return CHECK_ACTION_RESULT_ALLOWED;
  1602. return _t('_sys_txt_access_denied');
  1603. }
  1604. public function checkAllowedChangeBadge ($aDataEntry, $isPerformAction = false)
  1605. {
  1606. if(empty($aDataEntry) || !is_array($aDataEntry))
  1607. return _t('_sys_txt_not_found');
  1608. // moderator always has access
  1609. if($this->_isModerator($isPerformAction))
  1610. return CHECK_ACTION_RESULT_ALLOWED;
  1611. // owner (checked by account instead of author!) always have access
  1612. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name']);
  1613. if(!$oProfile)
  1614. return _t('_sys_txt_error_occured');
  1615. if($oProfile->getAccountId() != $this->_iAccountId)
  1616. return _t('_sys_txt_access_denied');
  1617. $aCheck = checkActionModule($this->_iProfileId, 'change badge', $this->getName(), false);
  1618. if($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  1619. return $aCheck[CHECK_ACTION_MESSAGE];
  1620. return CHECK_ACTION_RESULT_ALLOWED;
  1621. }
  1622. /**
  1623. * Check if user can change cover image
  1624. */
  1625. public function checkAllowedChangeCover ($aDataEntry, $isPerformAction = false)
  1626. {
  1627. // moderator always has access
  1628. if ($this->_isModerator($isPerformAction))
  1629. return CHECK_ACTION_RESULT_ALLOWED;
  1630. // owner (checked by account instead of author!) always have access
  1631. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name']);
  1632. if (!$oProfile)
  1633. return _t('_sys_txt_error_occured');
  1634. if ($oProfile->id() == $this->_iProfileId || $oProfile->getAccountId() == $this->_iAccountId)
  1635. return CHECK_ACTION_RESULT_ALLOWED;
  1636. return _t('_sys_txt_access_denied');
  1637. }
  1638. /**
  1639. * Check if user can change settings
  1640. */
  1641. public function checkAllowedChangeSettings ($aDataEntry, $isPerformAction = false)
  1642. {
  1643. // moderator always has access
  1644. if ($this->_isModerator($isPerformAction))
  1645. return CHECK_ACTION_RESULT_ALLOWED;
  1646. // owner (checked by account instead of author!) always have access
  1647. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name']);
  1648. if (!$oProfile)
  1649. return _t('_sys_txt_error_occured');
  1650. if ($oProfile->id() == $this->_iProfileId || $oProfile->getAccountId() == $this->_iAccountId)
  1651. return CHECK_ACTION_RESULT_ALLOWED;
  1652. return _t('_sys_txt_access_denied');
  1653. }
  1654. /**
  1655. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1656. */
  1657. public function checkAllowedDelete (&$aDataEntry, $isPerformAction = false)
  1658. {
  1659. // moderator always has access
  1660. if ($this->_isModerator($isPerformAction))
  1661. return CHECK_ACTION_RESULT_ALLOWED;
  1662. // owner (checked by account instead of author!) always have access
  1663. $aCheck = checkActionModule($this->_iProfileId, 'delete entry', $this->getName(), $isPerformAction);
  1664. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->_aModule['name'], $isPerformAction);
  1665. if (!$oProfile)
  1666. return _t('_sys_txt_error_occured');
  1667. if (($oProfile->id() == $this->_iProfileId || $oProfile->getAccountId() == $this->_iAccountId) && $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED)
  1668. return CHECK_ACTION_RESULT_ALLOWED;
  1669. return _t('_sys_txt_access_denied');
  1670. }
  1671. /**
  1672. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1673. */
  1674. public function checkAllowedViewMoreMenu (&$aDataEntry, $isPerformAction = false)
  1675. {
  1676. $oMenu = BxTemplMenu::getObjectInstance($this->_oConfig->CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_MORE']);
  1677. if (!$oMenu || !$oMenu->getCode())
  1678. return _t('_sys_txt_access_denied');
  1679. return CHECK_ACTION_RESULT_ALLOWED;
  1680. }
  1681. /**
  1682. * Compose differs from Contact. For example, a user should NOT be able to start conversation (compose)
  1683. * with himself but he should be able to view conversation page where he is one of the participants.
  1684. *
  1685. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1686. */
  1687. public function checkAllowedCompose(&$aDataEntry, $isPerformAction = false)
  1688. {
  1689. $CNF = &$this->_oConfig->CNF;
  1690. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->getName());
  1691. if($oProfile && $oProfile->id() == $this->_iProfileId)
  1692. return _t('_sys_txt_access_denied');
  1693. return $this->checkAllowedContact($aDataEntry, $isPerformAction);
  1694. }
  1695. public function checkAllowedFriendsView (&$aDataEntry, $isPerformAction = false)
  1696. {
  1697. $sResult = _t('_sys_txt_access_denied');
  1698. if(!$this->_oConfig->isFriends())
  1699. return $sResult;
  1700. if(empty($aDataEntry) || !is_array($aDataEntry))
  1701. return $sResult;
  1702. return CHECK_ACTION_RESULT_ALLOWED;
  1703. }
  1704. public function checkAllowedFriends (&$aDataEntry, $isPerformAction = false)
  1705. {
  1706. if(!$this->_oConfig->isFriends() || ($oProfile = BxDolProfile::getInstance($this->_iProfileId)) === false || !bx_srv($oProfile->getModule(), 'is_enable_friends'))
  1707. return _t('_sys_txt_access_denied');
  1708. return CHECK_ACTION_RESULT_ALLOWED;
  1709. }
  1710. /**
  1711. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1712. */
  1713. public function checkAllowedFriendAdd (&$aDataEntry, $isPerformAction = false)
  1714. {
  1715. if(!$this->_oConfig->isFriends() || ($oProfile = BxDolProfile::getInstance($this->_iProfileId)) === false || !bx_srv($oProfile->getModule(), 'is_enable_friends'))
  1716. return _t('_sys_txt_access_denied');
  1717. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, ['sys_profiles_friends', 'checkAllowedAddConnection'], false, false);
  1718. }
  1719. /**
  1720. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1721. */
  1722. public function checkAllowedFriendRemove (&$aDataEntry, $isPerformAction = false)
  1723. {
  1724. if(!$this->_oConfig->isFriends() || ($oProfile = BxDolProfile::getInstance($this->_iProfileId)) === false || !bx_srv($oProfile->getModule(), 'is_enable_friends'))
  1725. return _t('_sys_txt_access_denied');
  1726. if (CHECK_ACTION_RESULT_ALLOWED === $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, ['sys_profiles_friends', 'checkAllowedRemoveConnection'], false, true, true))
  1727. return CHECK_ACTION_RESULT_ALLOWED;
  1728. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, ['sys_profiles_friends', 'checkAllowedRemoveConnection'], false, true, false);
  1729. }
  1730. public function checkAllowedRelations (&$aDataEntry, $isPerformAction = false)
  1731. {
  1732. $CNF = &$this->_oConfig->CNF;
  1733. $sResult = _t('_sys_txt_access_denied');
  1734. if(!BxDolConnectionRelation::isEnabled())
  1735. return $sResult;
  1736. if(($sMsg = $this->checkAllowedView($aDataEntry)) !== CHECK_ACTION_RESULT_ALLOWED)
  1737. return $sMsg;
  1738. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->_aModule['name']);
  1739. if(!$oProfile || $oProfile->id() == $this->_iProfileId)
  1740. return $sResult;
  1741. if(!BxDolConnection::getObjectInstance('sys_profiles_relations')->isRelationAvailable($this->_iProfileId, $oProfile->id()))
  1742. return $sResult;
  1743. return CHECK_ACTION_RESULT_ALLOWED;
  1744. }
  1745. /**
  1746. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1747. */
  1748. public function checkAllowedRelationAdd (&$aDataEntry, $isPerformAction = false)
  1749. {
  1750. $sResult = _t('_sys_txt_access_denied');
  1751. if(!BxDolConnectionRelation::isEnabled())
  1752. return $sResult;
  1753. if(($sMsg = $this->checkAllowedView($aDataEntry)) !== CHECK_ACTION_RESULT_ALLOWED)
  1754. return $sMsg;
  1755. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_relations', false, false);
  1756. }
  1757. /**
  1758. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1759. */
  1760. public function checkAllowedRelationRemove (&$aDataEntry, $isPerformAction = false)
  1761. {
  1762. $sResult = _t('_sys_txt_access_denied');
  1763. if(!BxDolConnectionRelation::isEnabled())
  1764. return $sResult;
  1765. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_relations', false, true);
  1766. }
  1767. public function checkAllowedRelationsView (&$aDataEntry, $isPerformAction = false)
  1768. {
  1769. $sResult = _t('_sys_txt_access_denied');
  1770. if(!BxDolConnectionRelation::isEnabled())
  1771. return $sResult;
  1772. $sModule = $this->_oConfig->getName();
  1773. $oRelations = BxDolConnection::getObjectInstance('sys_profiles_relations');
  1774. if(!$oRelations->isRelationAvailableWithProfile($sModule) && !$oRelations->isRelationAvailableFromProfile($sModule))
  1775. return $sResult;
  1776. if(empty($aDataEntry) || !is_array($aDataEntry))
  1777. return $sResult;
  1778. return CHECK_ACTION_RESULT_ALLOWED;
  1779. }
  1780. public function checkAllowedSubscriptions(&$aDataEntry, $isPerformAction = false)
  1781. {
  1782. if(($sMsg = $this->checkAllowedView($aDataEntry)) !== CHECK_ACTION_RESULT_ALLOWED)
  1783. return $sMsg;
  1784. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, ['sys_profiles_subscriptions', 'checkAllowedConnectByAcl'], false, false);
  1785. }
  1786. /**
  1787. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1788. */
  1789. public function checkAllowedSubscribeAdd(&$aDataEntry, $isPerformAction = false)
  1790. {
  1791. $mixedResult = $this->_modProfileCheckAllowedSubscribeAdd($aDataEntry, $isPerformAction);
  1792. /**
  1793. * @hooks
  1794. * @hookdef hook-system-check_allowed_subscribe_add 'system', 'check_allowed_subscribe_add' - hook to override the result of checking whether 'subscribe' action is allowed or not to currently logged in user
  1795. * It's equivalent to @ref hook-system-check_allowed_view
  1796. * @hook @ref hook-system-check_allowed_subscribe_add
  1797. */
  1798. bx_alert('system', 'check_allowed_subscribe_add', 0, 0, [
  1799. 'module' => $this->getName(),
  1800. 'content_info' => $aDataEntry,
  1801. 'profile_id' => bx_get_logged_profile_id(),
  1802. 'override_result' => &$mixedResult
  1803. ]);
  1804. return $mixedResult;
  1805. }
  1806. /**
  1807. * Note. Is mainly needed for internal usage. Access level is 'public' to allow outer calls from alerts.
  1808. */
  1809. public function _modProfileCheckAllowedSubscribeAdd(&$aDataEntry, $isPerformAction = false)
  1810. {
  1811. if(($sMsg = $this->checkAllowedView($aDataEntry)) !== CHECK_ACTION_RESULT_ALLOWED)
  1812. return $sMsg;
  1813. return $this->_checkAllowedConnect($aDataEntry, $isPerformAction, 'sys_profiles_subscriptions', false, false);
  1814. }
  1815. /**
  1816. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  1817. */
  1818. public function checkAllowedSubscribeRemove (&$aDataEntry, $isPerformAction = false)
  1819. {
  1820. return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_subscriptions', false, true);
  1821. }
  1822. public function checkAllowedSubscriptionsView (&$aDataEntry, $isPerformAction = false)
  1823. {
  1824. $CNF = &$this->_oConfig->CNF;
  1825. $sResult = _t('_sys_txt_access_denied');
  1826. if(empty($aDataEntry) || !is_array($aDataEntry))
  1827. return $sResult;
  1828. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->_aModule['name']);
  1829. if(!$oProfile || ($oProfile->id() != $this->_iProfileId && $this->_oDb->getParam($CNF['PARAM_PUBLIC_SBSN']) != 'on' && $this->_oDb->getParam($CNF['PARAM_PUBLIC_SBSD']) != 'on'))
  1830. return $sResult;
  1831. return CHECK_ACTION_RESULT_ALLOWED;
  1832. }
  1833. public function checkMyself($iContentId)
  1834. {
  1835. $iLogged = (int)bx_get_logged_profile_id();
  1836. if(empty($iLogged))
  1837. return false;
  1838. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->_oConfig->getName());
  1839. if(!$oProfile)
  1840. return false;
  1841. return $oProfile->id() == $iLogged;
  1842. }
  1843. public function isAllowDeleteOrDisable($iActorProfileId, $iTargetProfileId)
  1844. {
  1845. if (BxDolAcl::getInstance()->isMemberLevelInSet(array(MEMBERSHIP_ID_MODERATOR), $iActorProfileId) && BxDolAcl::getInstance()->isMemberLevelInSet(array(MEMBERSHIP_ID_MODERATOR, MEMBERSHIP_ID_ADMINISTRATOR), $iTargetProfileId))
  1846. return false;
  1847. return true;
  1848. }
  1849. public function getProfileObject($iContentId)
  1850. {
  1851. $oProfile = BxDolProfile::getInstanceByContentAndType((int)$iContentId, $this->_oConfig->getName());
  1852. if (!$oProfile)
  1853. $oProfile = BxDolProfileUndefined::getInstance();
  1854. return $oProfile;
  1855. }
  1856. protected function _serviceCheckAllowedContactForProfile($aDataEntry, $isPerformAction = false, $iProfileId = false)
  1857. {
  1858. $CNF = &$this->_oConfig->CNF;
  1859. if(!$iProfileId)
  1860. $iProfileId = $this->_iProfileId;
  1861. /*
  1862. * allow to 'contact myself'. It's needed to allow a user to view conversation page
  1863. * where he is one of the participants.
  1864. */
  1865. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->getName());
  1866. if($oProfile && $oProfile->id() == $iProfileId)
  1867. return CHECK_ACTION_RESULT_ALLOWED;
  1868. // moderator always has access
  1869. if($this->_isModeratorForProfile($isPerformAction, $iProfileId))
  1870. return CHECK_ACTION_RESULT_ALLOWED;
  1871. // check privacy
  1872. if(!empty($CNF['OBJECT_PRIVACY_CONTACT'])) {
  1873. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_CONTACT']);
  1874. if($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
  1875. return _t('_sys_access_denied_to_private_content');
  1876. }
  1877. return CHECK_ACTION_RESULT_ALLOWED;
  1878. }
  1879. // ====== COMMON METHODS
  1880. public function isBadge($aData)
  1881. {
  1882. $CNF = &$this->_oConfig->CNF;
  1883. return !empty($CNF['FIELD_BADGE']) && $this->checkAllowedViewBadgeImage($aData) === CHECK_ACTION_RESULT_ALLOWED;
  1884. }
  1885. public function isMenuItemVisible($sObject, &$aItem, &$aContentInfo)
  1886. {
  1887. $CNF = &$this->_oConfig->CNF;
  1888. $bResult = parent::isMenuItemVisible($sObject, $aItem, $aContentInfo);
  1889. if(!$bResult)
  1890. return $bResult;
  1891. if(($sField = 'FIELD_STG_TABS') && !empty($CNF[$sField]) && isset($aContentInfo[$CNF[$sField]]) && ($sTabs = $aContentInfo[$CNF[$sField]])) {
  1892. $aTabs = explode(',', $sTabs);
  1893. if(in_array($aItem['name'], $aTabs))
  1894. return false;
  1895. }
  1896. return $bResult;
  1897. }
  1898. public function onUpdateImage($iContentId, $sFiledName, $sFiledValue, $iProfileId = 0)
  1899. {
  1900. $CNF = &$this->_oConfig->CNF;
  1901. $sModule = $this->getName();
  1902. if(!$iProfileId && ($oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $sModule)) !== false)
  1903. $iProfileId = $oProfile->id();
  1904. bx_content_cache_del_by_prefix('sprofile_unit_vars:' . $iProfileId . ':');
  1905. bx_content_cache_del_by_prefix('menu_sys_toolbar_member_p' . $iProfileId);
  1906. $aField2Method = [
  1907. $CNF['FIELD_PICTURE'] => 'picture',
  1908. $CNF['FIELD_COVER'] => 'cover',
  1909. ];
  1910. if(!empty($aField2Method[$sFiledName]))
  1911. /**
  1912. * @hooks
  1913. * @hookdef hook-bx_base_profile-profile_picture_changed '{module_name}', 'profile_picture_changed' - hook after profile picture was changed
  1914. * - $unit_name - module name
  1915. * - $action - equals `profile_picture_changed`
  1916. * - $object_id - image id
  1917. * - $sender_id - profile id who performed the action
  1918. * - $extra_params - array of additional params with the following array keys:
  1919. * - `object_author_id` - [int] profile id
  1920. * - `content` - [int] profile content id
  1921. * - `field` - [string] field name
  1922. * @hook @ref hook-bx_base_profile-profile_picture_changed
  1923. */
  1924. /**
  1925. * @hooks
  1926. * @hookdef hook-bx_base_profile-profile_cover_changed '{module_name}', 'profile_cover_changed' - hook after profile cover was changed
  1927. * It's equivalent to @ref hook-bx_base_profile-profile_picture_changed
  1928. * @hook @ref hook-bx_base_profile-profile_cover_changed
  1929. */
  1930. bx_alert($sModule, 'profile_' . $aField2Method[$sFiledName] . '_changed', $sFiledValue, $iProfileId, [
  1931. 'object_author_id' => $iProfileId,
  1932. 'content' => $iContentId,
  1933. 'field' => $sFiledName
  1934. ]);
  1935. }
  1936. protected function _alertParams($aContentInfo)
  1937. {
  1938. $aParams = parent::_alertParams($aContentInfo);
  1939. $CNF = &$this->_oConfig->CNF;
  1940. if(!empty($CNF['FIELD_STATUS']) && isset($aContentInfo[$CNF['FIELD_STATUS']]))
  1941. $aParams['status'] = $aContentInfo[$CNF['FIELD_STATUS']];
  1942. if(!empty($CNF['FIELD_STATUS_ADMIN']) && isset($aContentInfo[$CNF['FIELD_STATUS_ADMIN']]))
  1943. $aParams['status_admin'] = $aContentInfo[$CNF['FIELD_STATUS_ADMIN']];
  1944. if(!empty($CNF['FIELD_ALLOW_VIEW_TO']) && isset($aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]))
  1945. $aParams['privacy_view'] = $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']];
  1946. return $aParams;
  1947. }
  1948. public function alertAfterAdd($aContentInfo)
  1949. {
  1950. $CNF = &$this->_oConfig->CNF;
  1951. $sModule = $this->getName();
  1952. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  1953. $iAuthorId = false;
  1954. if(($oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $sModule)) !== false)
  1955. $iAuthorId = $oProfile->id();
  1956. $aParams = $this->_alertParams($aContentInfo);
  1957. /**
  1958. * @hooks
  1959. * @hookdef hook-bx_base_profile-added '{module_name}', 'added' - hook after profile was added
  1960. * - $unit_name - module name
  1961. * - $action - equals `added`
  1962. * - $object_id - profile content id
  1963. * - $sender_id - not used
  1964. * - $extra_params - array of additional params with the following array keys:
  1965. * - `status` - [string] context status
  1966. * - `status_admin` - [string] context admin status
  1967. * - `privacy_view` - [int] or [string] privacy for view context action, @see BxDolPrivacy
  1968. * @hook @ref hook-bx_base_profile-added
  1969. */
  1970. bx_alert($this->getName(), 'added', $iContentId, $iAuthorId, $aParams);
  1971. }
  1972. public function alertAfterEdit($aContentInfo)
  1973. {
  1974. $CNF = &$this->_oConfig->CNF;
  1975. $sModule = $this->getName();
  1976. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  1977. $aParams = $this->_alertParams($aContentInfo);
  1978. /**
  1979. * @hooks
  1980. * @hookdef hook-bx_base_profile-edited '{module_name}', 'edited' - hook after profile was changed
  1981. * It's equivalent to @ref hook-bx_base_profile-added
  1982. * @hook @ref hook-bx_base_profile-edited
  1983. */
  1984. bx_alert($sModule, 'edited', $iContentId, false, $aParams);
  1985. $oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $sModule);
  1986. /**
  1987. * @hooks
  1988. * @hookdef hook-profile-edit 'profile', 'edit' - hook after profile was changed
  1989. * - $unit_name - equals `profile`
  1990. * - $action - equals `edit`
  1991. * - $object_id - profile id
  1992. * - $sender_id - not used
  1993. * - $extra_params - array of additional params with the following array keys:
  1994. * - `content` - [int] profile content id
  1995. * - `module` - [string] module name
  1996. * @hook @ref hook-profile-added
  1997. */
  1998. bx_alert('profile', 'edit', $oProfile->id(), 0, [
  1999. 'content' => $iContentId,
  2000. 'module' => $sModule
  2001. ]);
  2002. }
  2003. public function getProfileByCurrentUrl ()
  2004. {
  2005. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  2006. if ($iProfileId)
  2007. return BxDolProfile::getInstance($iProfileId);
  2008. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  2009. if ($iContentId)
  2010. return BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
  2011. return false;
  2012. }
  2013. public function getEntryImageData($aContentInfo, $sField = 'FIELD_PICTURE', $aTranscoders = array())
  2014. {
  2015. return parent::getEntryImageData($aContentInfo, $sField, $aTranscoders);
  2016. }
  2017. public function getProfileName ($aContentInfo)
  2018. {
  2019. return bx_process_output($aContentInfo[$this->_oConfig->CNF['FIELD_NAME']]);
  2020. }
  2021. public function getMenuItemTitleByConnection($sConnection, $sAction, $iContentProfileId, $iInitiatorProfileId = 0)
  2022. {
  2023. $oConnection = BxDolConnection::getObjectInstance($sConnection);
  2024. if(!$oConnection)
  2025. return false;
  2026. if(!$iInitiatorProfileId)
  2027. $iInitiatorProfileId = bx_get_logged_profile_id();
  2028. $aResult = [];
  2029. switch($sConnection) {
  2030. case 'sys_profiles_friends':
  2031. $aResult = $this->_getMenuItemTitleProfilesFriends($sAction, $iContentProfileId, $iInitiatorProfileId, $oConnection);
  2032. break;
  2033. case 'sys_profiles_subscriptions':
  2034. $aResult = $this->_getMenuItemTitleProfilesSubscriptions($sAction, $iContentProfileId, $iInitiatorProfileId, $oConnection);
  2035. break;
  2036. }
  2037. return $aResult;
  2038. }
  2039. protected function _getMenuItemTitleProfilesFriends($sAction, $iContentProfileId, $iInitiatorProfileId, &$oConnection)
  2040. {
  2041. $CNF = $this->_oConfig->getCNF();
  2042. $aResult = [];
  2043. if($oConnection->isConnectedNotMutual($iInitiatorProfileId, $iContentProfileId))
  2044. $aResult = [
  2045. 'add' => _t(!empty($CNF['T']['menu_item_title_befriend_sent']) ? $CNF['T']['menu_item_title_befriend_sent'] : '_sys_menu_item_title_sm_befriend_sent'),
  2046. 'remove' => _t(!empty($CNF['T']['menu_item_title_unfriend_cancel']) ? $CNF['T']['menu_item_title_unfriend_cancel'] : '_sys_menu_item_title_sm_unfriend_cancel'),
  2047. ];
  2048. else if($oConnection->isConnectedNotMutual($iContentProfileId, $iInitiatorProfileId))
  2049. $aResult = [
  2050. 'add' => _t(!empty($CNF['T']['menu_item_title_befriend_confirm']) ? $CNF['T']['menu_item_title_befriend_confirm'] : '_sys_menu_item_title_sm_befriend_confirm'),
  2051. 'remove' => _t(!empty($CNF['T']['menu_item_title_unfriend_reject']) ? $CNF['T']['menu_item_title_unfriend_reject'] : '_sys_menu_item_title_sm_unfriend_reject'),
  2052. ];
  2053. else if($oConnection->isConnected($iInitiatorProfileId, $iContentProfileId, true))
  2054. $aResult = [
  2055. 'add' => '',
  2056. 'remove' => _t(!empty($CNF['T']['menu_item_title_unfriend']) ? $CNF['T']['menu_item_title_unfriend'] : '_sys_menu_item_title_sm_unfriend'),
  2057. ];
  2058. else
  2059. $aResult = [
  2060. 'add' => _t(!empty($CNF['T']['menu_item_title_befriend']) ? $CNF['T']['menu_item_title_befriend'] : '_sys_menu_item_title_sm_befriend'),
  2061. 'remove' => '',
  2062. ];
  2063. return !empty($sAction) && isset($aResult[$sAction]) ? $aResult[$sAction] : $aResult;
  2064. }
  2065. protected function _getMenuItemTitleProfilesSubscriptions($sAction, $iContentProfileId, $iInitiatorProfileId, &$oConnection)
  2066. {
  2067. $CNF = $this->_oConfig->getCNF();
  2068. $aResult = [];
  2069. if($oConnection->isConnected($iInitiatorProfileId, $iContentProfileId))
  2070. $aResult = [
  2071. 'add' => '',
  2072. 'remove' => _t(!empty($CNF['T']['menu_item_title_unsubscribe']) ? $CNF['T']['menu_item_title_unsubscribe'] : '_sys_menu_item_title_sm_unsubscribe'),
  2073. ];
  2074. else
  2075. $aResult = [
  2076. 'add' => _t(!empty($CNF['T']['menu_item_title_subscribe']) ? $CNF['T']['menu_item_title_subscribe'] : '_sys_menu_item_title_sm_subscribe'),
  2077. 'remove' => '',
  2078. ];
  2079. return !empty($sAction) && !empty($aResult[$sAction]) ? $aResult[$sAction] : $aResult;
  2080. }
  2081. public function decodeDataAPI($aData, $aParams = [])
  2082. {
  2083. $CNF = $this->_oConfig->CNF;
  2084. $sModule = $this->getName();
  2085. $iId = (int)$aData[$CNF['FIELD_ID']];
  2086. if(($mixedCheckResult = $this->serviceCheckAllowedViewForProfile($aData)) !== CHECK_ACTION_RESULT_ALLOWED)
  2087. return [
  2088. 'id' => $iId,
  2089. 'module' => 'sys_private',
  2090. 'module_src' => $sModule,
  2091. 'title' => _t('_sys_private_content'),
  2092. ];
  2093. $oProfile = BxDolProfile::getInstanceByContentAndType($iId, $sModule);
  2094. $aResult = [
  2095. 'id' => $iId,
  2096. 'module' => $sModule,
  2097. 'module_title' => _t($CNF['T']['txt_sample_single']),
  2098. 'added' => $aData[$CNF['FIELD_ADDED']],
  2099. 'author' => $aData[$CNF['FIELD_AUTHOR']],
  2100. 'author_data' => $oProfile !== false ? BxDolProfile::getData($oProfile->id()) : '',
  2101. 'title' => $aData[$CNF['FIELD_TITLE']],
  2102. $CNF['FIELD_TITLE'] => $aData[$CNF['FIELD_TITLE']],
  2103. 'url' => bx_api_get_relative_url($this->serviceGetLink($iId)),
  2104. 'image' => $this->serviceGetThumb($iId),
  2105. 'cover' => $this->serviceGetCover($iId),
  2106. 'badges' => $this->serviceGetBadges($iId, false, true)
  2107. ];
  2108. if(isset($aParams['template']) && $aParams['template'] == 'unit_wo_info')
  2109. return $aResult;
  2110. if(isset($aParams['extended']) && $aParams['extended'] === true)
  2111. $aResult['text'] = $aData[$CNF['FIELD_TEXT']];
  2112. if(getParam('sys_api_conn_in_prof_units') == 'on' && $oProfile !== false) {
  2113. $iProfileId = $oProfile->id();
  2114. $aResult['title'] = $oProfile->getDisplayName();
  2115. $aResult['online'] = $oProfile->isOnline();
  2116. if(($oConnection = BxDolConnection::getObjectInstance('sys_profiles_friends')) !== false && isset($CNF['URI_VIEW_FRIENDS'])) {
  2117. $aResult['friends_count'] = $oConnection->getConnectedContentCount($iProfileId, true);
  2118. $aResult['friends_list'] = $oConnection->getConnectedListAPI($iProfileId, true, BX_CONNECTIONS_CONTENT_TYPE_CONTENT);
  2119. if(isLogged()) {
  2120. $iLoggedId = bx_get_logged_profile_id();
  2121. $aResult['mutual_friends_count'] = $oConnection->getCommonContentCount($iProfileId, $iLoggedId, true);
  2122. $aResult['mutual_friends_list'] = $oConnection->getCommonListAPI($iProfileId, $iLoggedId, true);
  2123. }
  2124. }
  2125. if(($oConnection = BxDolConnection::getObjectInstance('sys_profiles_subscriptions')) !== false){
  2126. $aResult['followers_count'] = $oConnection->getConnectedInitiatorsCount($iProfileId);
  2127. $aResult['followers_list'] = $oConnection->getConnectedListAPI($iProfileId, false, BX_CONNECTIONS_CONTENT_TYPE_INITIATORS);
  2128. }
  2129. }
  2130. $sKey = 'OBJECT_MENU_SNIPPET_META';
  2131. if(!empty($CNF[$sKey]) && ($oMetaMenu = BxDolMenu::getObjectInstance($CNF[$sKey], $this->_oTemplate)) !== false) {
  2132. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  2133. $bPublic = !$oPrivacy || $oPrivacy->check($iId) || $oPrivacy->isPartiallyVisible($aData[$CNF['FIELD_ALLOW_VIEW_TO']]);
  2134. $oMetaMenu->setContentId($iId);
  2135. $oMetaMenu->setContentPublic($bPublic);
  2136. if(isset($aParams['context']))
  2137. $oMetaMenu->setContext($aParams['context']);
  2138. $aResult['meta'] = $oMetaMenu->getCodeAPI();
  2139. }
  2140. $this->decodeDataAPICommonFields($aResult, $aData, $aParams);
  2141. return $aResult;
  2142. }
  2143. // ====== PROTECTED METHODS
  2144. protected function _checkAllowedConnect (&$aDataEntry, $isPerformAction, $mixedConnection, $isMutual, $isInvertResult, $isSwap = false)
  2145. {
  2146. if (!$this->_iProfileId)
  2147. return _t('_sys_txt_access_denied');
  2148. $CNF = &$this->_oConfig->CNF;
  2149. $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$CNF['FIELD_ID']], $this->_aModule['name']);
  2150. if (!$oProfile || $oProfile->id() == $this->_iProfileId)
  2151. return _t('_sys_txt_access_denied');
  2152. $sConnObject = '';
  2153. $sConnMethod = 'checkAllowedConnect';
  2154. if(is_array($mixedConnection))
  2155. list($sConnObject, $sConnMethod) = $mixedConnection;
  2156. else
  2157. $sConnObject = $mixedConnection;
  2158. return BxDolConnection::getObjectInstance($sConnObject)->$sConnMethod($this->_iProfileId, $oProfile->id(), $isPerformAction, $isMutual, $isInvertResult, $isSwap);
  2159. }
  2160. protected function _buildRssParams($sMode, $aArgs)
  2161. {
  2162. $aParams = array ();
  2163. $sMode = bx_process_input($sMode);
  2164. switch ($sMode) {
  2165. case 'connections':
  2166. $aParams = array(
  2167. 'object' => isset($aArgs[0]) ? $aArgs[0] : '',
  2168. 'type' => isset($aArgs[1]) ? $aArgs[1] : '',
  2169. 'profile' => isset($aArgs[2]) ? (int)$aArgs[2] : 0,
  2170. 'mutual' => isset($aArgs[3]) ? (int)$aArgs[3] : 0,
  2171. 'profile2' => isset($aArgs[4]) ? (int)$aArgs[4] : 0,
  2172. );
  2173. break;
  2174. }
  2175. return $aParams;
  2176. }
  2177. protected function _serviceGetTimelineProfileImage($aEvent, $aBrowseParams, $aBuildParams)
  2178. {
  2179. $CNF = &$this->_oConfig->CNF;
  2180. $aFileInfo = BxDolStorage::getObjectInstance($CNF[$aBuildParams['stg']])->getFile((int)$aEvent['object_id']);
  2181. if(empty($aFileInfo) || !is_array($aFileInfo))
  2182. return false;
  2183. $aEventContent = unserialize($aEvent['content']);
  2184. if(!is_array($aEventContent) || empty($aEventContent['content']))
  2185. return false;
  2186. $aContentInfo = $this->_oDb->getContentInfoById($aEventContent['content']);
  2187. if(empty($aContentInfo) || !is_array($aContentInfo))
  2188. return false;
  2189. $oProfile = BxDolProfile::getInstanceMagic($aContentInfo['profile_id']);
  2190. if (!$oProfile->isActive())
  2191. return false;
  2192. $sUserName = $oProfile->getDisplayName();
  2193. $sSample = isset($CNF['T'][$aBuildParams['txt_sswa']]) ? $CNF['T'][$aBuildParams['txt_sswa']] : $CNF['T'][$aBuildParams['txt_ss']];
  2194. //--- Title & Description
  2195. $sTitle = !empty($aContentInfo[$CNF['FIELD_TITLE']]) ? $aContentInfo[$CNF['FIELD_TITLE']] : '';
  2196. if(empty($sTitle) && !empty($aContentInfo[$CNF['FIELD_TEXT']]))
  2197. $sTitle = $aContentInfo[$CNF['FIELD_TEXT']];
  2198. $sDescription = _t($CNF['T'][$aBuildParams['txt_sau']], $sUserName, _t($sSample));
  2199. return array(
  2200. 'owner_id' => $aEvent['owner_id'],
  2201. 'object_owner_id' => $aContentInfo['profile_id'],
  2202. 'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '',
  2203. 'sample' => $sSample,
  2204. 'sample_wo_article' => $CNF['T'][$aBuildParams['txt_ss']],
  2205. 'sample_action' => isset($CNF['T'][$aBuildParams['txt_sa']]) ? $CNF['T'][$aBuildParams['txt_sa']] : '',
  2206. 'url' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']])),
  2207. 'content' => $this->_getContentForTimelineProfileImage($aEvent, $aBrowseParams, $aBuildParams, $aContentInfo, $aFileInfo), //a string to display or array to parse default template before displaying.
  2208. 'date' => $aContentInfo[$CNF['FIELD_ADDED']],
  2209. 'views' => '',
  2210. 'votes' => '',
  2211. 'scores' => '',
  2212. 'reports' => '',
  2213. 'comments' => '',
  2214. 'title' => $sTitle, //may be empty.
  2215. 'description' => $sDescription //may be empty.
  2216. );
  2217. }
  2218. protected function _serviceGetTimelineProfileImageAllowedView($aEvent)
  2219. {
  2220. $sError = _t('_sys_access_denied_to_private_content');
  2221. if(empty($aEvent['content']) || !is_array($aEvent['content']) || empty($aEvent['content']['id']))
  2222. return $sError;
  2223. $aContentInfo = $this->_oDb->getContentInfoById($aEvent['content']['id']);
  2224. if(empty($aContentInfo) || !is_array($aContentInfo))
  2225. return $sError;
  2226. return $this->serviceCheckAllowedViewForProfile($aContentInfo);
  2227. }
  2228. protected function _getContentForTimelineProfileImage($aEvent, $aBrowseParams, $aBuildParams, $aContentInfo, $aFileInfo)
  2229. {
  2230. $CNF = &$this->_oConfig->CNF;
  2231. $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]));
  2232. //--- Image(s)
  2233. $sImage = $this->_oConfig->getImageUrl($aFileInfo['id'], $aBuildParams['trans']);
  2234. $sImageOrig = $this->_oConfig->getImageUrl($aFileInfo['id'], $aBuildParams['trans_orig']);
  2235. if(!empty($sImage)) {
  2236. if(empty($sImageOrig))
  2237. $sImageOrig = $sImage;
  2238. $a = ['id' => $aFileInfo['id'], 'url' => $sUrl, 'src' => $sImage];
  2239. if(CHECK_ACTION_RESULT_ALLOWED === $this->checkAllowedView($aContentInfo)) {
  2240. $a['src_orig'] = $sImageOrig;
  2241. $sCnfKey = 'OBJECT_IMAGES_TRANSCODER_GALLERY';
  2242. if(!empty($CNF[$sCnfKey]) && ($sSrcMedium = $this->_oConfig->getImageUrl($aFileInfo['id'], [$sCnfKey])) != '')
  2243. $a['src_medium'] = $sSrcMedium;
  2244. }
  2245. $aImages = [$a];
  2246. }
  2247. return array(
  2248. 'sample' => isset($CNF['T'][$aBuildParams['txt_sswa']]) ? $CNF['T'][$aBuildParams['txt_sswa']] : $CNF['T'][$aBuildParams['txt_ss']],
  2249. 'sample_wo_article' => $CNF['T'][$aBuildParams['txt_ss']],
  2250. 'sample_action' => isset($CNF['T'][$aBuildParams['txt_sa']]) ? $CNF['T'][$aBuildParams['txt_sa']] : '',
  2251. 'id' => $aContentInfo[$CNF['FIELD_ID']],
  2252. 'url' => $sUrl,
  2253. 'title' => '',
  2254. 'text' => '',
  2255. 'images' => $aImages,
  2256. 'videos' => array()
  2257. );
  2258. }
  2259. protected function _entityComments($sObject, $iId = 0)
  2260. {
  2261. if(!$iId)
  2262. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  2263. if(!$iId)
  2264. $iId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  2265. if(!$iId)
  2266. return false;
  2267. $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
  2268. if(!$oCmts || !$oCmts->isEnabled())
  2269. return false;
  2270. if (bx_is_api())
  2271. return [bx_srv('system', 'get_data_api', [['module' => $sObject, 'object_id' => $iId]], 'TemplCmtsServices')];
  2272. return $oCmts->getCommentsBlock(array(), array('in_designbox' => false));
  2273. }
  2274. protected function _getContent($iContentId = 0, $sFuncGetContent = 'getContentInfoById')
  2275. {
  2276. if(!$iContentId && bx_get('id') === false && bx_get('profile_id') !== false) {
  2277. $oProfile = BxDolProfile::getInstance((int)bx_get('profile_id'));
  2278. if($oProfile)
  2279. $iContentId = $oProfile->getContentId();
  2280. }
  2281. return parent::_getContent($iContentId, $sFuncGetContent);
  2282. }
  2283. }
  2284. /** @} */