BxBaseServices.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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 UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * System services.
  11. */
  12. class BxBaseServices extends BxDol implements iBxDolProfileService
  13. {
  14. public function __construct()
  15. {
  16. parent::__construct();
  17. }
  18. public function serviceIsSafeService($s)
  19. {
  20. $sService = bx_gen_method_name($s);
  21. $aSafeServices = $this->serviceGetSafeServices();
  22. return isset($aSafeServices[$sService]);
  23. }
  24. public function serviceGetSafeServices()
  25. {
  26. return array(
  27. 'GetCreatePostForm' => 'BxBaseServices',
  28. 'KeywordSearch' => 'BxBaseServices',
  29. 'CreateAccountForm' => 'BxBaseServiceAccount',
  30. );
  31. }
  32. public function serviceProfileUnit ($iContentId, $aParams = array())
  33. {
  34. return $this->_serviceProfileFunc('getUnit', $iContentId, $aParams);
  35. }
  36. public function serviceHasImage ($iContentId)
  37. {
  38. return false;
  39. }
  40. public function serviceProfilePicture ($iContentId)
  41. {
  42. return $this->_serviceProfileFunc('getPicture', $iContentId);
  43. }
  44. public function serviceProfileAvatar ($iContentId)
  45. {
  46. return $this->_serviceProfileFunc('getAvatar', $iContentId);
  47. }
  48. public function serviceProfileCover ($iContentId)
  49. {
  50. return $this->_serviceTemplateFunc('urlCover', $iContentId);
  51. }
  52. public function serviceProfileEditUrl ($iContentId)
  53. {
  54. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=account-settings-info');
  55. }
  56. public function serviceProfileThumb ($iContentId)
  57. {
  58. return $this->_serviceProfileFunc('getThumb', $iContentId);
  59. }
  60. public function serviceProfileIcon ($iContentId)
  61. {
  62. return $this->_serviceProfileFunc('getIcon', $iContentId);
  63. }
  64. public function serviceProfileName ($iContentId)
  65. {
  66. return $this->_serviceProfileFunc('getDisplayName', $iContentId);
  67. }
  68. public function serviceProfileUrl ($iContentId)
  69. {
  70. return $this->_serviceProfileFunc('getUrl', $iContentId);
  71. }
  72. /**
  73. * @see iBxDolProfileService::serviceCheckAllowedProfileView
  74. */
  75. public function serviceCheckAllowedProfileView($iContentId)
  76. {
  77. return _t('_Access denied');
  78. }
  79. /**
  80. * @see iBxDolProfileService::serviceCheckAllowedProfileContact
  81. */
  82. public function serviceCheckAllowedProfileContact($iContentId)
  83. {
  84. return _t('_Access denied');
  85. }
  86. /**
  87. * @see iBxDolProfileService::serviceCheckAllowedPostInProfile
  88. */
  89. public function serviceCheckAllowedPostInProfile($iContentId)
  90. {
  91. return _t('_Access denied');
  92. }
  93. /**
  94. * @see iBxDolProfileService::serviceGetSpaceTitle
  95. */
  96. public function serviceGetSpaceTitle()
  97. {
  98. return '';
  99. }
  100. /**
  101. * @see iBxDolProfileService::serviceGetParticipatingProfiles
  102. */
  103. public function serviceGetParticipatingProfiles($iProfileId, $aConnectionObject = false)
  104. {
  105. return array();
  106. }
  107. /**
  108. * @page service Service Calls
  109. * @section bx_system_general System Services
  110. * @subsection bx_system_general-general General
  111. * @subsubsection bx_system_general-get_create_post_form get_create_post_form
  112. *
  113. * @code bx_srv('system', 'get_create_post_form', [false, "bx_posts"], 'TemplServices'); @endcode
  114. * @code {{~system:get_create_post_form:TemplServices[false,"bx_posts"]~}} @endcode
  115. *
  116. * Get United Create Post form.
  117. * @param $mixedContextId - context which the post will be created in:
  118. * - false = 'Public' post form;
  119. * - 0 = 'Profile' post form, which allows to post in your own profile and connections;
  120. * - n = 'Context' post form, which allows to post in context (3d party profile, group, event, etc).
  121. * @param $sDefault - tab selected by default.
  122. * @param $aCustom - an array with custom paramaters.
  123. * @return string with form content
  124. *
  125. * @see BxBaseServices::serviceGetCreatePostForm
  126. */
  127. /**
  128. * @ref bx_system_general-get_create_post_form "get_create_post_form"
  129. */
  130. public function serviceGetCreatePostForm($mixedContextId = false, $sDefault = '', $aCustom = array())
  131. {
  132. if(!isLogged() || ($mixedContextId !== false && !is_numeric($mixedContextId)))
  133. return '';
  134. if($mixedContextId !== false)
  135. $mixedContextId = (int)(!empty($mixedContextId) ? -$mixedContextId : bx_get_logged_profile_id());
  136. $bContext = $mixedContextId !== false;
  137. if($bContext && ($oContextProfile = BxDolProfile::getInstance(abs($mixedContextId))) !== false)
  138. if($oContextProfile->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  139. return '';
  140. $sTitle = _t('_sys_page_block_title_create_post' . (!$bContext ? '_public' : ($mixedContextId < 0 ? '_context' : '')));
  141. $sPlaceholder = _t('_sys_txt_create_post_placeholder', BxDolProfile::getInstance()->getDisplayName());
  142. $oMenu = BxDolMenu::getObjectInstance('sys_create_post');
  143. $aMenuItems = $oMenu->getMenuItems();
  144. if(empty($aMenuItems) || !is_array($aMenuItems))
  145. return '';
  146. if(empty($sDefault)) {
  147. $aDefault = array_shift($aMenuItems);
  148. $sDefault = $aDefault['module'];
  149. }
  150. $oMenu->setSelected($sDefault, $sDefault);
  151. $oTemplate = BxDolTemplate::getInstance();
  152. $oTemplate->addJs(array('BxDolCreatePost.js'));
  153. $sJsObject = 'oBxDolCreatePost';
  154. $sJsContent = $oTemplate->_wrapInTagJsCode("var " . $sJsObject . " = new BxDolCreatePost(" . json_encode(array(
  155. 'sObjName' => $sJsObject,
  156. 'sRootUrl' => BX_DOL_URL_ROOT,
  157. 'sDefault' => $sDefault,
  158. 'iContextId' => $bContext ? $mixedContextId : 0,
  159. 'oCustom' => $aCustom
  160. )) . ");");
  161. return array('content' => BxDolTemplate::getInstance()->parseHtmlByName('create_post_form.html', array(
  162. 'default' => $sDefault,
  163. 'title' => $sTitle,
  164. 'placeholder' => $sPlaceholder,
  165. 'user_thumb' => BxDolProfile::getInstance()->getUnit(0, array('template' => 'unit_wo_info')),
  166. 'menu' => $oMenu->getCode(),
  167. 'form' => BxDolService::call($sDefault, 'get_create_post_form', array(array('context_id' => $mixedContextId, 'ajax_mode' => true, 'absolute_action_url' => true, 'custom' => $aCustom))),
  168. 'js_object' => $sJsObject,
  169. 'js_content' => $sJsContent
  170. )));
  171. }
  172. /**
  173. * @see iBxDolProfileService::serviceCheckSpacePrivacy
  174. */
  175. public function serviceCheckSpacePrivacy($iContentId)
  176. {
  177. return _t('_Access denied');
  178. }
  179. public function serviceFormsHelper ()
  180. {
  181. return new BxTemplAccountForms();
  182. }
  183. public function serviceActAsProfile ()
  184. {
  185. return false;
  186. }
  187. public function servicePrepareFields ($aFieldsProfile)
  188. {
  189. return $aFieldsProfile;
  190. }
  191. public function serviceProfilesSearch ($sTerm, $iLimit)
  192. {
  193. $oDb = BxDolAccountQuery::getInstance();
  194. $aRet = array();
  195. $a = $oDb->searchByTerm($sTerm, $iLimit);
  196. foreach ($a as $r)
  197. $aRet[] = array ('label' => $this->serviceProfileName($r['content_id']), 'value' => $r['profile_id']);
  198. return $aRet;
  199. }
  200. /**
  201. * @page service Service Calls
  202. * @section bx_system_general System Services
  203. * @subsection bx_system_general-general General
  204. * @subsubsection bx_system_general-keyword_search keyword_search
  205. *
  206. * @code bx_srv('system', 'keyword_search', ["bx_posts", ["keyword" => "test"}], 'TemplServices'); @endcode
  207. *
  208. * @code {{~system:keyword_search:TemplServices["bx_posts", {"keyword":"test"}]~}} @endcode
  209. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country", "keyword": "AU"}, "unit.html"]~}} @endcode
  210. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_state", "state":"NSW", "keyword": "AU"}, "unit.html"]~}} @endcode
  211. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"}, "unit.html"]~}} @endcode
  212. * @code {{~system:keyword_search:TemplServices["bx_posts", {"meta_type": "mention", "keyword": 2}, "unit_gallery.html"]~}} @endcode
  213. * @code {{~system:keyword_search:TemplServices["bx_posts", {"cat": "bx_posts_cats", "keyword": 3}, "unit_gallery.html"]~}} @endcode
  214. *
  215. * Search by keyword
  216. * @param $sSection - search object to search in, usually module name, for example: bx_posts
  217. * @param $aCondition - condition for search, supported conditions:
  218. * - search by keyword: ["keyword" => "test"]
  219. * - search by country: ["meta_type" => "location_country", "keyword" => "AU"]
  220. * - search by country and state: ["meta_type": "location_country_state", "state":"NSW", "keyword": "AU"]
  221. * - search by country, state and city: ["meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"]
  222. * - search for mentions: ["meta_type" => "mention", "keyword" => 2]
  223. * - search in category: ["cat": "bx_posts_cats", "keyword": 3]
  224. * @param $sTemplate - template for displaying search results, for example: unit.html
  225. * @param $iStart - paginate, display records starting from this number
  226. * @param $iPerPage - paginate, display this number of records per page
  227. * @param $bLiveSearch - search results like in live search
  228. *
  229. * @see BxBaseServices::serviceKeywordSearch
  230. */
  231. /**
  232. * @ref bx_system_general-keyword_search "keyword_search"
  233. */
  234. public function serviceKeywordSearch ($sSection, $aCondition, $sTemplate = '', $iStart = 0, $iPerPage = 0, $bLiveSearch = 0)
  235. {
  236. if (!$sSection || !isset($aCondition['keyword']))
  237. return '';
  238. $sClass = 'BxTemplSearch';
  239. $sElsName = 'bx_elasticsearch';
  240. $sElsMethod = 'is_configured';
  241. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod)) {
  242. $oModule = BxDolModule::getInstance($sElsName);
  243. bx_import('Search', $oModule->_aModule);
  244. $sClass = 'BxElsSearch';
  245. }
  246. $oSearch = new $sClass(array($sSection));
  247. $oSearch->setLiveSearch($bLiveSearch);
  248. $oSearch->setMetaType(isset($aCondition['meta_type']) ? $aCondition['meta_type'] : '');
  249. $oSearch->setCategoryObject(isset($aCondition['cat']) ? $aCondition['cat'] : '');
  250. $oSearch->setCustomSearchCondition($aCondition);
  251. $oSearch->setRawProcessing(true);
  252. $oSearch->setCustomCurrentCondition(array(
  253. 'paginate' => array (
  254. 'start' => $iStart,
  255. 'perPage' => $iPerPage ? $iPerPage : BX_DOL_SEARCH_RESULTS_PER_PAGE_DEFAULT,
  256. )));
  257. if ($sTemplate)
  258. $oSearch->setUnitTemplate($sTemplate);
  259. return $oSearch->response();
  260. }
  261. public function _serviceProfileFunc ($sFunc, $iContentId, $aParams = array())
  262. {
  263. if (!$iContentId)
  264. return false;
  265. if (!($oAccount = BxDolAccount::getInstance($iContentId)))
  266. return false;
  267. return $oAccount->$sFunc(false, $aParams);
  268. }
  269. public function serviceAlertResponseProcessInstalled()
  270. {
  271. BxDolTranscoderImage::registerHandlersSystem();
  272. }
  273. public function serviceAlertResponseProcessStorageChange ($oAlert)
  274. {
  275. if ('sys_storage_default' != $oAlert->aExtras['option'])
  276. return;
  277. $aStorages = BxDolStorageQuery::getStorageObjects();
  278. foreach ($aStorages as $r) {
  279. if (0 == $r['current_size'] && 0 == $r['current_number'] && ($oStorage = BxDolStorage::getObjectInstance($r['object'])))
  280. $oStorage->changeStorageEngine($oAlert->aExtras['value']);
  281. }
  282. }
  283. /**
  284. * This service adds notification for users which open your site on mobile devices
  285. * and suggest to add your site to their mobile homepage.
  286. */
  287. public function serviceAddToMobileHomepage ()
  288. {
  289. BxDolTemplate::getInstance()->addJs('cubiq-add-to-homescreen/addtohomescreen.min.js');
  290. BxDolTemplate::getInstance()->addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'cubiq-add-to-homescreen/style/|addtohomescreen.css');
  291. return "<script>addToHomescreen();</script>";
  292. }
  293. public function serviceGetOptionsProfileBot()
  294. {
  295. $aResult = array(
  296. array('key' => '', 'value' => _t('_Select_one'))
  297. );
  298. $aAccountsIds = BxDolAccountQuery::getInstance()->getOperators();
  299. foreach($aAccountsIds as $iAccountId) {
  300. $aProfilesIds = BxDolAccount::getInstance($iAccountId)->getProfilesIds();
  301. foreach($aProfilesIds as $iProfileId)
  302. $aResult[] = array(
  303. 'key' => $iProfileId,
  304. 'value' => BxDolProfile::getInstance($iProfileId)->getDisplayName()
  305. );
  306. }
  307. return $aResult;
  308. }
  309. public function serviceGetOptionsEmbedDefault()
  310. {
  311. $aResults = array(
  312. '' => _t('_None')
  313. );
  314. $aObjects = BxDolEmbedQuery::getObjects();
  315. foreach($aObjects as $aObject)
  316. $aResults[$aObject['object']] = $aObject['title'];
  317. return $aResults;
  318. }
  319. public function serviceGetOptionsRelations()
  320. {
  321. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1));
  322. $aProfiles = array();
  323. foreach($aModules as $aModule) {
  324. $sMethod = 'act_as_profile';
  325. if(!BxDolRequest::serviceExists($aModule['name'], $sMethod) || !BxDolService::call($aModule['name'], $sMethod))
  326. continue;
  327. $aProfiles[$aModule['name']] = _t('_' . $aModule['name']);
  328. }
  329. $aResults = array();
  330. foreach($aProfiles as $sName1 => $sTitle1)
  331. foreach($aProfiles as $sName2 => $sTitle2)
  332. $aResults[$sName1 . '_' . $sName2] = $sTitle1 . ' - ' . $sTitle2;
  333. return $aResults;
  334. }
  335. }
  336. /** @} */