BxBaseModProfileModule.php 100 KB

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