1
0

BxBaseModProfileModule.php 90 KB

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