BxBaseModProfileModule.php 105 KB

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