BxBaseModProfileModule.php 90 KB

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