BxBaseServices.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029
  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 serviceIsPublicService($s)
  19. {
  20. $sService = bx_gen_method_name($s);
  21. $aServices = $this->serviceGetPublicServices();
  22. return isset($aServices[$sService]);
  23. }
  24. public function serviceGetPublicServices()
  25. {
  26. return array (
  27. 'GetProductsNames' => 'BxBaseServices',
  28. );
  29. }
  30. public function serviceIsSafeService($s)
  31. {
  32. $sService = bx_gen_method_name($s);
  33. $aSafeServices = $this->serviceGetSafeServices();
  34. return isset($aSafeServices[$sService]);
  35. }
  36. public function serviceGetSafeServices()
  37. {
  38. return array(
  39. 'GetCreatePostForm' => 'BxBaseServices',
  40. 'GetProductsNames' => 'BxBaseServices',
  41. 'KeywordSearch' => 'BxBaseServices',
  42. 'Cmts' => 'BxBaseServices',
  43. 'CreateAccountForm' => 'BxBaseServiceAccount',
  44. 'ForgotPassword' => 'BxBaseServiceAccount',
  45. 'SwitchProfile' => 'BxBaseServiceAccount',
  46. 'CategoriesList' => 'BxBaseServiceCategory',
  47. 'Test' => 'BxBaseServiceLogin',
  48. 'MemberAuthCode' => 'BxBaseServiceLogin',
  49. 'LoginForm' => 'BxBaseServiceLogin',
  50. 'KeywordsCloud' => 'BxBaseServiceMetatags',
  51. 'ProfileMembership' => 'BxBaseServiceProfiles',
  52. 'ProfileNotifications' => 'BxBaseServiceProfiles',
  53. 'GetCountOnlineProfiles' => 'BxBaseServiceProfiles',
  54. 'GetChartGrowth' => 'BxBaseChartServices',
  55. 'GetChartStats' => 'BxBaseChartServices',
  56. 'GetCartItemsCount' => 'BxBasePaymentsServices',
  57. 'GetOrdersCount' => 'BxBasePaymentsServices',
  58. );
  59. }
  60. public function serviceGetPreloaderContent($sName) {
  61. $sResult = '';
  62. switch($sName) {
  63. case 'tailwind':
  64. /**
  65. * Note. For now Tailwind isn't needed in Studio.
  66. */
  67. list($sPageUrl, $sPageParams) = bx_get_base_url_inline();
  68. if(!empty($sPageUrl) && strncmp($sPageUrl, BX_DOL_URL_STUDIO, strlen(BX_DOL_URL_STUDIO)) == 0)
  69. break;
  70. $sResult = '{dir_plugins_public}tailwind/css/|tailwind.min.css';
  71. break;
  72. }
  73. return $sResult;
  74. }
  75. /**
  76. * @page service Service Calls
  77. * @section bx_system_general System Services
  78. * @subsection bx_system_general-general General
  79. * @subsubsection bx_system_general-module_check_for_update module_check_for_update
  80. *
  81. * @code bx_srv('system', 'module_check_for_update', ["bx_posts"]); @endcode
  82. * @code bx_srv('system', 'module_check_for_update', ["bx_posts"], 'TemplServices'); @endcode
  83. * @code {{~system:module_check_for_update:TemplServices["bx_posts"]~}} @endcode
  84. *
  85. * Checks whether an update is available for requested module or not.
  86. * @param $mixedModule - module ID/name to check the updates for.
  87. * @return array with information about the update, false if nothing was found
  88. *
  89. * @see BxBaseServices::serviceModuleCheckForUpdate
  90. */
  91. /**
  92. * @ref bx_system_general-module_check_for_update "module_check_for_update"
  93. */
  94. public function serviceModuleCheckForUpdate($mixedModule)
  95. {
  96. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  97. if(empty($aModule) || !is_array($aModule))
  98. return false;
  99. $aUpdates = BxDolStudioInstallerUtils::getInstance()->checkUpdatesByModule($aModule['name']);
  100. if(empty($aUpdates) || !is_array($aUpdates))
  101. return false;
  102. $aUpdate = array_shift($aUpdates);
  103. return array(
  104. 'version_from' => $aUpdate['file_version'],
  105. 'version_to' => $aUpdate['file_version_to'],
  106. 'file_id' => $aUpdate['file_id']
  107. );
  108. }
  109. /**
  110. * @page service Service Calls
  111. * @section bx_system_general System Services
  112. * @subsection bx_system_general-general General
  113. * @subsubsection bx_system_general-module_update module_update
  114. *
  115. * @code bx_srv('system', 'module_update', ["bx_posts"]); @endcode
  116. * @code bx_srv('system', 'module_update', ["bx_posts"], 'TemplServices'); @endcode
  117. * @code {{~system:module_update:TemplServices["bx_posts"]~}} @endcode
  118. *
  119. * Download and install an update for requested module. The operation may be performed
  120. * immediately or by Transient Cron task. The second way is more common.
  121. * @param $mixedModule - module ID/name to check the updates for.
  122. * @return integer value determining the result of the operation. It can be one of the following values:
  123. * BX_DOL_STUDIO_IU_RC_SUCCESS, BX_DOL_STUDIO_IU_RC_FAILED or BX_DOL_STUDIO_IU_RC_SCHEDULED.
  124. *
  125. * @see BxBaseServices::serviceModuleUpdate
  126. */
  127. /**
  128. * @ref bx_system_general-module_update "module_update"
  129. */
  130. public function serviceModuleUpdate($mixedModule)
  131. {
  132. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  133. if(empty($aModule) || !is_array($aModule))
  134. return BX_DOL_STUDIO_IU_RC_FAILED;
  135. $aResult = BxDolStudioInstallerUtils::getInstance()->downloadUpdatePublic($aModule['name'], true);
  136. return $aResult['code'];
  137. }
  138. /**
  139. * @page service Service Calls
  140. * @section bx_system_general System Services
  141. * @subsection bx_system_general-general General
  142. * @subsubsection bx_system_general-module_delete module_delete
  143. *
  144. * @code bx_srv('system', 'module_delete', ["bx_posts"]); @endcode
  145. * @code bx_srv('system', 'module_delete', ["bx_posts", true], 'TemplServices'); @endcode
  146. * @code {{~system:module_delete:TemplServices["bx_posts"]~}} @endcode
  147. *
  148. * Delete the requested module. By default only uninstalled module can be deleted.
  149. * The operation may be performed immediately or by Transient Cron task. The second way is more common.
  150. * @param $sModule - module name to delete.
  151. * @param $bForceUninstall - if 'true' is passed the module will be uninstalled before deletion.
  152. * @return integer value determining the result of the operation. It can be one of the following values:
  153. * BX_DOL_STUDIO_IU_RC_SUCCESS, BX_DOL_STUDIO_IU_RC_FAILED or BX_DOL_STUDIO_IU_RC_SCHEDULED.
  154. *
  155. * @see BxBaseServices::serviceModuleDelete
  156. */
  157. /**
  158. * @ref bx_system_general-module_delete "module_delete"
  159. */
  160. public function serviceModuleDelete($sModule, $bForceUninstall = false)
  161. {
  162. $sModulePath = '';
  163. $oInstallerUtils = BxDolStudioInstallerUtils::getInstance();
  164. $aModule = BxDolModuleQuery::getInstance()->getModuleByName($sModule, false);
  165. if(!empty($aModule) && is_array($aModule)) {
  166. if(!$bForceUninstall)
  167. return BX_DOL_STUDIO_IU_RC_FAILED;
  168. $sModulePath = $aModule['path'];
  169. $aResult = $oInstallerUtils->perform($sModulePath, 'uninstall', array('auto_disable' => $bForceUninstall));
  170. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  171. return BX_DOL_STUDIO_IU_RC_FAILED;
  172. }
  173. else {
  174. $aModules = $oInstallerUtils->getModules(false);
  175. if(!isset($aModules[$sModule]))
  176. return BX_DOL_STUDIO_IU_RC_FAILED;
  177. $sModulePath = $aModules[$sModule]['dir'];
  178. }
  179. $aResult = $oInstallerUtils->perform($sModulePath, 'delete');
  180. return $aResult['code'];
  181. }
  182. /**
  183. * @page service Service Calls
  184. * @section bx_system_general System Services
  185. * @subsection bx_system_general-general General
  186. * @subsubsection bx_system_general-module_install module_install
  187. *
  188. * @code bx_srv('system', 'module_install', ["bx_posts"]); @endcode
  189. * @code bx_srv('system', 'module_install', ["bx_posts", true], 'TemplServices'); @endcode
  190. * @code {{~system:module_install:TemplServices["bx_posts"]~}} @endcode
  191. *
  192. * Install the requested module. By default the module will be installed only.
  193. * @param $sModule - module name to install.
  194. * @param $bForceEnable - if 'true' is passed the module will be automatically enabled after installation.
  195. * @return boolean value determining the result of the operation.
  196. *
  197. * @see BxBaseServices::serviceModuleInstall
  198. */
  199. /**
  200. * @ref bx_system_general-module_install "module_install"
  201. */
  202. public function serviceModuleInstall($sModule, $bForceEnable = false)
  203. {
  204. $oInstallerUtils = BxDolStudioInstallerUtils::getInstance();
  205. $aModules = $oInstallerUtils->getModules(false);
  206. if(!isset($aModules[$sModule]))
  207. return false;
  208. $aResult = $oInstallerUtils->perform($aModules[$sModule]['dir'], 'install', array('auto_enable' => $bForceEnable));
  209. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  210. return false;
  211. return true;
  212. }
  213. /**
  214. * @page service Service Calls
  215. * @section bx_system_general System Services
  216. * @subsection bx_system_general-general General
  217. * @subsubsection bx_system_general-module_uninstall module_uninstall
  218. *
  219. * @code bx_srv('system', 'module_uninstall', ["bx_posts"]); @endcode
  220. * @code bx_srv('system', 'module_uninstall', ["bx_posts", true], 'TemplServices'); @endcode
  221. * @code {{~system:module_uninstall:TemplServices["bx_posts"]~}} @endcode
  222. *
  223. * Uninstall the requested module. By default only disabled module can be uninstalled.
  224. * @param $mixedModule - module ID/name to uninstall.
  225. * @param $bForceDisable - if 'true' is passed the module will be automatically disabled before uninstallation.
  226. * @return boolean value determining the result of the operation.
  227. *
  228. * @see BxBaseServices::serviceModuleUninstall
  229. */
  230. /**
  231. * @ref bx_system_general-module_uninstall "module_uninstall"
  232. */
  233. public function serviceModuleUninstall($mixedModule, $bForceDisable = false)
  234. {
  235. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  236. if(empty($aModule) || !is_array($aModule))
  237. return false;
  238. if((int)$aModule['enabled'] != 0 && !$bForceDisable)
  239. return false;
  240. $aResult = BxDolStudioInstallerUtils::getInstance()->perform($aModule['path'], 'uninstall', array('auto_disable' => $bForceDisable));
  241. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  242. return false;
  243. return true;
  244. }
  245. /**
  246. * @page service Service Calls
  247. * @section bx_system_general System Services
  248. * @subsection bx_system_general-general General
  249. * @subsubsection bx_system_general-module_enable module_enable
  250. *
  251. * @code bx_srv('system', 'module_enable', ["bx_posts"]); @endcode
  252. * @code bx_srv('system', 'module_enable', ["bx_posts"], 'TemplServices'); @endcode
  253. * @code {{~system:module_enable:TemplServices["bx_posts"]~}} @endcode
  254. *
  255. * Enable the requested module.
  256. * @param $mixedModule - module ID/name to enable.
  257. * @return boolean value determining the result of the operation.
  258. *
  259. * @see BxBaseServices::serviceModuleEnable
  260. */
  261. /**
  262. * @ref bx_system_general-module_enable "module_enable"
  263. */
  264. public function serviceModuleEnable($mixedModule)
  265. {
  266. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  267. if(empty($aModule) || !is_array($aModule))
  268. return false;
  269. if((int)$aModule['enabled'] != 0)
  270. return false;
  271. $aResult = BxDolStudioInstallerUtils::getInstance()->perform($aModule['path'], 'enable');
  272. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  273. return false;
  274. return true;
  275. }
  276. /**
  277. * @page service Service Calls
  278. * @section bx_system_general System Services
  279. * @subsection bx_system_general-general General
  280. * @subsubsection bx_system_general-module_disable module_disable
  281. *
  282. * @code bx_srv('system', 'module_disable', ["bx_posts"]); @endcode
  283. * @code bx_srv('system', 'module_disable', ["bx_posts"], 'TemplServices'); @endcode
  284. * @code {{~system:module_disable:TemplServices["bx_posts"]~}} @endcode
  285. *
  286. * Disable the requested module.
  287. * @param $mixedModule - module ID/name to disable.
  288. * @return boolean value determining the result of the operation.
  289. *
  290. * @see BxBaseServices::serviceModuleDisable
  291. */
  292. /**
  293. * @ref bx_system_general-module_disable "module_disable"
  294. */
  295. public function serviceModuleDisable($mixedModule)
  296. {
  297. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  298. if(empty($aModule) || !is_array($aModule))
  299. return false;
  300. if((int)$aModule['enabled'] == 0)
  301. return false;
  302. $aResult = BxDolStudioInstallerUtils::getInstance()->perform($aModule['path'], 'disable');
  303. if($aResult['code'] != BX_DOL_STUDIO_IU_RC_SUCCESS)
  304. return false;
  305. return true;
  306. }
  307. /**
  308. * @page service Service Calls
  309. * @section bx_system_general System Services
  310. * @subsection bx_system_general-general General
  311. * @subsubsection bx_system_general-is_module_installed is_module_installed
  312. *
  313. * @code bx_srv('system', 'is_module_installed', ["bx_posts"]); @endcode
  314. * @code bx_srv('system', 'is_module_installed', ["bx_posts"], 'TemplServices'); @endcode
  315. * @code {{~system:is_module_installed:TemplServices["bx_posts"]~}} @endcode
  316. *
  317. * Checks whether the requested module is installed or not.
  318. * @param $mixedModule - module ID/name to check.
  319. * @return boolean value determining the result of the operation.
  320. *
  321. * @see BxBaseServices::serviceIsModuleInstalled
  322. */
  323. /**
  324. * @ref bx_system_general-is_module_installed "is_module_installed"
  325. */
  326. public function serviceIsModuleInstalled($mixedModule)
  327. {
  328. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  329. return !empty($aModule) && is_array($aModule);
  330. }
  331. /**
  332. * @page service Service Calls
  333. * @section bx_system_general System Services
  334. * @subsection bx_system_general-general General
  335. * @subsubsection bx_system_general-is_module_enabled is_module_enabled
  336. *
  337. * @code bx_srv('system', 'is_module_enabled', ["bx_posts"]); @endcode
  338. * @code bx_srv('system', 'is_module_enabled', ["bx_posts"], 'TemplServices'); @endcode
  339. * @code {{~system:is_module_enabled:TemplServices["bx_posts"]~}} @endcode
  340. *
  341. * Checks whether the requested module is enabled or not.
  342. * @param $mixedModule - module ID/name to check.
  343. * @return boolean value determining the result of the operation.
  344. *
  345. * @see BxBaseServices::serviceIsModuleEnabled
  346. */
  347. /**
  348. * @ref bx_system_general-is_module_enabled "is_module_enabled"
  349. */
  350. public function serviceIsModuleEnabled($mixedModule)
  351. {
  352. $aModule = BxDolModuleQuery::getInstance()->{'getModuleBy' . (is_numeric($mixedModule) ? 'Id' : 'Name')}($mixedModule, false);
  353. return !empty($aModule) && is_array($aModule) && (int)$aModule['enabled'] != 0;
  354. }
  355. /**
  356. * Get modules by type. Available types are 'content', 'context', 'profile'.
  357. *
  358. * @param type $sType - string with type.
  359. * @return array of modules.
  360. */
  361. public function serviceGetModulesByType($sType)
  362. {
  363. $aResults = array();
  364. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1));
  365. foreach($aModules as $aModule) {
  366. $oModule = BxDolModule::getInstance($aModule['name']);
  367. if(!$oModule)
  368. continue;
  369. if($sType == 'content' && (!($oModule instanceof iBxDolContentInfoService) || $oModule instanceof iBxDolProfileService))
  370. continue;
  371. if($sType == 'context' && !($oModule instanceof iBxDolProfileService))
  372. continue;
  373. if($sType == 'profile' && (!($oModule instanceof iBxDolProfileService) || !$oModule->serviceActAsProfile()))
  374. continue;
  375. $aResults[] = $aModule;
  376. }
  377. return $aResults;
  378. }
  379. public function serviceProfileUnit ($iContentId, $aParams = array())
  380. {
  381. return $this->_serviceProfileFunc('getUnit', $iContentId, $aParams);
  382. }
  383. public function serviceHasImage ($iContentId)
  384. {
  385. return false;
  386. }
  387. public function serviceProfilePicture ($iContentId)
  388. {
  389. return BxDolTemplate::getInstance()->getImageUrl('account-picture.png');
  390. }
  391. public function serviceProfileAvatar ($iContentId)
  392. {
  393. return BxDolTemplate::getInstance()->getImageUrl('account-avatar.png');
  394. }
  395. public function serviceProfileCover ($iContentId)
  396. {
  397. return '';
  398. }
  399. public function serviceProfileEditUrl ($iContentId)
  400. {
  401. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=account-settings-info');
  402. }
  403. public function serviceProfileThumb ($iContentId)
  404. {
  405. return $this->_serviceProfileFunc('getThumb', $iContentId);
  406. }
  407. public function serviceProfileIcon ($iContentId)
  408. {
  409. return $this->_serviceProfileFunc('getIcon', $iContentId);
  410. }
  411. public function serviceProfileName ($iContentId)
  412. {
  413. return $this->_serviceProfileFunc('getDisplayName', $iContentId);
  414. }
  415. public function serviceProfileUrl ($iContentId)
  416. {
  417. return $this->_serviceProfileFunc('getUrl', $iContentId);
  418. }
  419. /**
  420. * @see iBxDolProfileService::serviceCheckAllowedProfileView
  421. */
  422. public function serviceCheckAllowedProfileView($iContentId)
  423. {
  424. return _t('_Access denied');
  425. }
  426. /**
  427. * @see iBxDolProfileService::serviceCheckAllowedProfileContact
  428. */
  429. public function serviceCheckAllowedProfileContact($iContentId)
  430. {
  431. return _t('_Access denied');
  432. }
  433. /**
  434. * @see iBxDolProfileService::serviceCheckAllowedPostInProfile
  435. */
  436. public function serviceCheckAllowedPostInProfile($iContentId, $sPostModule = '')
  437. {
  438. return _t('_Access denied');
  439. }
  440. /**
  441. * @see iBxDolProfileService::serviceCheckAllowedModuleActionInProfile
  442. */
  443. public function serviceCheckAllowedModuleActionInProfile($iContentId, $sPostModule, $sActionName)
  444. {
  445. return _t('_Access denied');
  446. }
  447. /**
  448. * @see iBxDolProfileService::serviceGetSpaceTitle
  449. */
  450. public function serviceGetSpaceTitle()
  451. {
  452. return '';
  453. }
  454. /**
  455. * @see iBxDolProfileService::serviceGetParticipatingProfiles
  456. */
  457. public function serviceGetParticipatingProfiles($iProfileId, $aConnectionObject = false)
  458. {
  459. return array();
  460. }
  461. /**
  462. * @page service Service Calls
  463. * @section bx_system_general System Services
  464. * @subsection bx_system_general-general General
  465. * @subsubsection bx_system_general-get_create_post_form get_create_post_form
  466. *
  467. * @code bx_srv('system', 'get_create_post_form', [false, "bx_posts"], 'TemplServices'); @endcode
  468. * @code {{~system:get_create_post_form:TemplServices[false,"bx_posts"]~}} @endcode
  469. *
  470. * Get United Create Post form.
  471. * @param $mixedContextId - context which the post will be created in:
  472. * - false = 'Public' post form;
  473. * - 0 = 'Profile' post form, which allows to post in your own profile and connections;
  474. * - n = 'Context' post form, which allows to post in context (3d party profile, group, event, etc).
  475. * @param $sDefault - tab selected by default.
  476. * @param $aCustom - an array with custom paramaters.
  477. * @return string with form content
  478. *
  479. * @see BxBaseServices::serviceGetCreatePostForm
  480. */
  481. /**
  482. * @ref bx_system_general-get_create_post_form "get_create_post_form"
  483. */
  484. public function serviceGetCreatePostForm($mixedContextId = false, $sDefault = '', $aCustom = array())
  485. {
  486. if(!isLogged() || ($mixedContextId !== false && !is_numeric($mixedContextId)))
  487. return '';
  488. $oProfile = BxDolProfile::getInstance();
  489. if(!$oProfile)
  490. return '';
  491. if($mixedContextId !== false)
  492. $mixedContextId = (int)(!empty($mixedContextId) ? -$mixedContextId : $oProfile->id());
  493. $bContext = $mixedContextId !== false;
  494. if($bContext && ($oContextProfile = BxDolProfile::getInstance(abs($mixedContextId))) !== false)
  495. if($oContextProfile->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  496. return '';
  497. $sTitle = _t('_sys_page_block_title_create_post' . (!$bContext ? '_public' : ($mixedContextId < 0 ? '_context' : '')));
  498. $sPlaceholder = _t('_sys_txt_create_post_placeholder', $oProfile->getDisplayName());
  499. $oMenu = BxDolMenu::getObjectInstance('sys_create_post');
  500. if(!$oMenu)
  501. return '';
  502. $aMenuItems = $oMenu->getMenuItems();
  503. if(empty($aMenuItems) || !is_array($aMenuItems))
  504. return '';
  505. if(empty($sDefault)) {
  506. $aDefault = array_shift($aMenuItems);
  507. $sDefault = !empty($aDefault['module']) ? $aDefault['module'] : $aDefault['name'];
  508. }
  509. $oMenu->setSelected($sDefault, $sDefault);
  510. $oTemplate = BxDolTemplate::getInstance();
  511. $oTemplate->addJs(array('BxDolCreatePost.js'));
  512. $sJsObject = 'oBxDolCreatePost';
  513. $sJsContent = $oTemplate->_wrapInTagJsCode("var " . $sJsObject . " = new BxDolCreatePost(" . json_encode(array(
  514. 'sObjName' => $sJsObject,
  515. 'sRootUrl' => BX_DOL_URL_ROOT,
  516. 'sDefault' => $sDefault,
  517. 'iContextId' => $bContext ? $mixedContextId : 0,
  518. 'oCustom' => $aCustom
  519. )) . ");");
  520. return array(
  521. 'title' => $sTitle,
  522. 'content' => BxDolTemplate::getInstance()->parseHtmlByName('create_post_form.html', array(
  523. 'default' => $sDefault,
  524. 'placeholder' => $sPlaceholder,
  525. 'user_thumb' => $oProfile->getUnit(0, array('template' => 'unit_wo_info')),
  526. 'form' => BxDolService::call($sDefault, 'get_create_post_form', array(array('context_id' => $mixedContextId, 'ajax_mode' => true, 'absolute_action_url' => true, 'custom' => $aCustom))),
  527. 'js_object' => $sJsObject,
  528. 'js_content' => $sJsContent
  529. )),
  530. 'menu' => $oMenu
  531. );
  532. }
  533. /**
  534. * @page service Service Calls
  535. * @section bx_system_general System Services
  536. * @subsection bx_system_general-general General
  537. * @subsubsection bx_system_general-get_site_submenu get_site_submenu
  538. *
  539. * @code bx_srv('system', 'get_site_submenu', [], 'TemplServices'); @endcode
  540. * @code {{~system:get_site_submenu:TemplServices[]~}} @endcode
  541. *
  542. * Get Site Submenu code.
  543. * @see BxBaseServices::serviceGetSiteSubmenu
  544. */
  545. /**
  546. * @ref bx_system_general-get_site_submenu "get_site_submenu"
  547. */
  548. public function serviceGetSiteSubmenu()
  549. {
  550. $oMenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  551. $oMenu->setTemplateWrapper('menu_main_submenu_empty.html');
  552. return $oMenu ? $oMenu->getCode () : '';
  553. }
  554. /**
  555. * @page service Service Calls
  556. * @section bx_system_general System Services
  557. * @subsection bx_system_general-general General
  558. * @subsubsection bx_system_general-get_products_names get_products_names
  559. *
  560. * @code bx_srv('system', 'get_products_names', [], 'TemplServices');
  561. *
  562. * @code http://example.com/m/oauth2/com/get_products_names?module=system&class=BaseServices @endcode
  563. * @code http://hihi.una.io/modules/?r=oauth2/com/get_products_names&module=system&class=BaseServices @endcode
  564. *
  565. * Get an array of products names from all modules with payments functionality.
  566. * @param $iVendorId filter products by vendor ID.
  567. * @param $iLimit limit number of records from one module.
  568. * @return array of products where key id product name and value is module name
  569. *
  570. * @see BxBaseServices::serviceGetProductsNames
  571. */
  572. /**
  573. * @ref bx_system_general-get_products_names "get_products_names"
  574. */
  575. public function serviceGetProductsNames($iVendorId = 0, $iLimit = 1000)
  576. {
  577. $o = BxDolPayments::getInstance();
  578. if (!$o)
  579. return array();
  580. return $o->getProductsNames($iVendorId, $iLimit);
  581. }
  582. /**
  583. * @see iBxDolProfileService::serviceCheckSpacePrivacy
  584. */
  585. public function serviceCheckSpacePrivacy($iContentId)
  586. {
  587. return _t('_Access denied');
  588. }
  589. public function serviceFormsHelper ()
  590. {
  591. return new BxTemplAccountForms();
  592. }
  593. public function serviceActAsProfile ()
  594. {
  595. return false;
  596. }
  597. public function servicePrepareFields ($aFieldsProfile)
  598. {
  599. return $aFieldsProfile;
  600. }
  601. public function serviceProfilesSearch ($sTerm, $iLimit)
  602. {
  603. $oDb = BxDolAccountQuery::getInstance();
  604. $aRet = array();
  605. $a = $oDb->searchByTerm($sTerm, $iLimit);
  606. foreach ($a as $r)
  607. $aRet[] = array ('label' => $this->serviceProfileName($r['content_id']), 'value' => $r['profile_id']);
  608. return $aRet;
  609. }
  610. /**
  611. * @page service Service Calls
  612. * @section bx_system_general System Services
  613. * @subsection bx_system_general-general General
  614. * @subsubsection bx_system_general-keyword_search keyword_search
  615. *
  616. * @code bx_srv('system', 'keyword_search', ["bx_posts", ["keyword" => "test"}], 'TemplServices'); @endcode
  617. *
  618. * @code {{~system:keyword_search:TemplServices["bx_posts", {"keyword":"test"}]~}} @endcode
  619. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country", "keyword": "AU"}, "unit.html"]~}} @endcode
  620. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_state", "state":"NSW", "keyword": "AU"}, "unit.html"]~}} @endcode
  621. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"}, "unit.html"]~}} @endcode
  622. * @code {{~system:keyword_search:TemplServices["bx_posts", {"meta_type": "mention", "keyword": 2}, "unit_gallery.html"]~}} @endcode
  623. * @code {{~system:keyword_search:TemplServices["bx_posts", {"cat": "bx_posts_cats", "keyword": 3}, "unit_gallery.html"]~}} @endcode
  624. *
  625. * Search by keyword
  626. * @param $sSection - search object to search in, usually module name, for example: bx_posts
  627. * @param $aCondition - condition for search, supported conditions:
  628. * - search by keyword: ["keyword" => "test"]
  629. * - search by country: ["meta_type" => "location_country", "keyword" => "AU"]
  630. * - search by country and state: ["meta_type": "location_country_state", "state":"NSW", "keyword": "AU"]
  631. * - search by country, state and city: ["meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"]
  632. * - search for mentions: ["meta_type" => "mention", "keyword" => 2]
  633. * - search in category: ["cat": "bx_posts_cats", "keyword": 3]
  634. * @param $sTemplate - template for displaying search results, for example: unit.html
  635. * @param $iStart - paginate, display records starting from this number
  636. * @param $iPerPage - paginate, display this number of records per page
  637. * @param $bLiveSearch - search results like in live search
  638. *
  639. * @see BxBaseServices::serviceKeywordSearch
  640. */
  641. /**
  642. * @ref bx_system_general-keyword_search "keyword_search"
  643. */
  644. public function serviceKeywordSearch ($sSection, $aCondition, $sTemplate = '', $iStart = 0, $iPerPage = 0, $bLiveSearch = 0, $bPaginate = false)
  645. {
  646. if (!$sSection || !isset($aCondition['keyword']))
  647. return '';
  648. $sClass = 'BxTemplSearch';
  649. $sElsName = 'bx_elasticsearch';
  650. $sElsMethod = 'is_configured';
  651. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod)) {
  652. $oModule = BxDolModule::getInstance($sElsName);
  653. bx_import('Search', $oModule->_aModule);
  654. $sClass = 'BxElsSearch';
  655. }
  656. $oSearch = new $sClass(array($sSection));
  657. $oSearch->setLiveSearch($bLiveSearch);
  658. $oSearch->setMetaType(isset($aCondition['meta_type']) ? $aCondition['meta_type'] : '');
  659. $oSearch->setCategoryObject(isset($aCondition['cat']) ? $aCondition['cat'] : '');
  660. $oSearch->setCustomSearchCondition($aCondition);
  661. if (!$bPaginate)
  662. $oSearch->setRawProcessing(true);
  663. $oSearch->setCustomCurrentCondition(array(
  664. 'paginate' => array (
  665. 'start' => $iStart,
  666. 'perPage' => $iPerPage ? $iPerPage : BX_DOL_SEARCH_RESULTS_PER_PAGE_DEFAULT,
  667. )));
  668. if ($sTemplate)
  669. $oSearch->setUnitTemplate($sTemplate);
  670. return $oSearch->response();
  671. }
  672. /**
  673. * @page service Service Calls
  674. * @section bx_system_general System Services
  675. * @subsection bx_system_general-general General
  676. * @subsubsection bx_system_general-keyword_search keyword_search
  677. *
  678. * @code bx_srv('system', 'search_keyword_form', 'TemplServices'); @endcode
  679. *
  680. * Block with Search by Keywords Form
  681. *
  682. * @see BxBaseServices::serviceSearchKeywordForm
  683. */
  684. /**
  685. * @ref bx_system_general-keyword_search "keyword_search"
  686. */
  687. public function serviceSearchKeywordForm ()
  688. {
  689. return $this->_getSearchObject()->getForm(BX_DB_PADDING_DEF, false, true);
  690. }
  691. /**
  692. * @page service Service Calls
  693. * @section bx_system_general System Services
  694. * @subsection bx_system_general-general General
  695. * @subsubsection bx_system_general-keyword_search keyword_search
  696. *
  697. * @code bx_srv('system', 'search_keyword_result', 'TemplServices'); @endcode
  698. *
  699. * Block with Search by Keywords Results
  700. *
  701. * @see BxBaseServices::serviceSearchKeywordResult
  702. */
  703. /**
  704. * @ref bx_system_general-keyword_search "keyword_search"
  705. */
  706. public function serviceSearchKeywordResult ()
  707. {
  708. $oSearch = $this->_getSearchObject();
  709. $sCode = '';
  710. if (bx_get('keyword') !== false) {
  711. $sCode = $oSearch->response();
  712. if (!$sCode)
  713. $sCode = $oSearch->getEmptyResult();
  714. }
  715. return $sCode;
  716. }
  717. /**
  718. * @page service Service Calls
  719. * @section bx_system_general System Services
  720. * @subsection bx_system_general-general General
  721. * @subsubsection bx_system_general-cmts cmts
  722. *
  723. * @code bx_srv('system', 'cmts', ["sys_blocks", 1], 'TemplServices'); @endcode
  724. *
  725. * @code {{~system:cmts:TemplServices["sys_blocks", 1]~}} @endcode
  726. *
  727. * Comments block
  728. * @param $sObject - comments object name
  729. * @param $sId - content id assiciated tith the comments
  730. *
  731. * @see BxBaseServices::serviceCmts
  732. */
  733. /**
  734. * @ref bx_system_general-cmts "cmts"
  735. */
  736. public function serviceCmts ($sObject, $sId)
  737. {
  738. $o = BxDolCmts::getObjectInstance($sObject, $sId);
  739. if (!$o || !$o->isEnabled())
  740. return '';
  741. return $o->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => true));
  742. }
  743. public function _serviceProfileFunc ($sFunc, $iContentId, $aParams = array())
  744. {
  745. if (!$iContentId)
  746. return false;
  747. if (!($oAccount = BxDolAccount::getInstance($iContentId)))
  748. return false;
  749. return $oAccount->$sFunc(false, $aParams);
  750. }
  751. public function serviceAlertResponseProcessInstalled()
  752. {
  753. BxDolTranscoderImage::registerHandlersSystem();
  754. }
  755. public function serviceAlertResponseProcessStorageChange ($oAlert)
  756. {
  757. if ('sys_storage_default' != $oAlert->aExtras['option'])
  758. return;
  759. $aStorages = BxDolStorageQuery::getStorageObjects();
  760. foreach ($aStorages as $r) {
  761. if (0 == $r['current_size'] && 0 == $r['current_number'] && ($oStorage = BxDolStorage::getObjectInstance($r['object'])))
  762. $oStorage->changeStorageEngine($oAlert->aExtras['value']);
  763. }
  764. }
  765. public function serviceGetOptionsProfileBot()
  766. {
  767. $aResult = array(
  768. array('key' => '', 'value' => _t('_Select_one'))
  769. );
  770. $aAccountsIds = BxDolAccountQuery::getInstance()->getOperators();
  771. foreach($aAccountsIds as $iAccountId) {
  772. $aProfilesIds = BxDolAccount::getInstance($iAccountId)->getProfilesIds(true, false);
  773. foreach($aProfilesIds as $iProfileId) {
  774. $oProfile = BxDolProfile::getInstance($iProfileId);
  775. $aResult[] = array(
  776. 'key' => $iProfileId,
  777. 'value' => _t('_sys_profile_with_type', $oProfile->getDisplayName(), $oProfile->getModule()),
  778. );
  779. }
  780. }
  781. return $aResult;
  782. }
  783. public function serviceGetOptionsModuleListForPrivacySelector()
  784. {
  785. $aResult = array();
  786. $BxDolModuleQuery = BxDolModuleQuery::getInstance();
  787. $aModules = $BxDolModuleQuery->getModulesBy(array('type' => 'modules', 'active' => 1));
  788. foreach($aModules as $aModule){
  789. $oModule = BxDolModule::getInstance($aModule['name']);
  790. if($oModule instanceof iBxDolContentInfoService){
  791. if (!BxDolRequest::serviceExists($aModule['name'], 'act_as_profile'))
  792. continue;
  793. $aResult[$aModule['name']] = $aModule['title'];
  794. }
  795. }
  796. return $aResult;
  797. }
  798. public function serviceGetOptionsEmbedDefault()
  799. {
  800. $aResults = array(
  801. '' => _t('_None')
  802. );
  803. $aObjects = BxDolEmbedQuery::getObjects();
  804. foreach($aObjects as $aObject)
  805. $aResults[$aObject['object']] = $aObject['title'];
  806. return $aResults;
  807. }
  808. public function serviceGetOptionsLocationFieldDefault()
  809. {
  810. $aResults = array();
  811. $aObjects = BxDolLocationFieldQuery::getObjects();
  812. foreach($aObjects as $aObject)
  813. $aResults[$aObject['object']] = _t($aObject['title']);
  814. return $aResults;
  815. }
  816. public function serviceGetOptionsLocationMapDefault()
  817. {
  818. $aResults = array();
  819. $aObjects = BxDolLocationMapQuery::getObjects();
  820. foreach($aObjects as $aObject)
  821. $aResults[$aObject['object']] = _t($aObject['title']);
  822. return $aResults;
  823. }
  824. public function serviceGetOptionsLocationLeafletGetProviders()
  825. {
  826. return BxDolLocationMapLeaflet::getProviders();
  827. }
  828. public function serviceGetOptionsRelations()
  829. {
  830. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1));
  831. $aProfiles = array();
  832. foreach($aModules as $aModule) {
  833. $sMethod = 'act_as_profile';
  834. if(!BxDolRequest::serviceExists($aModule['name'], $sMethod) || !BxDolService::call($aModule['name'], $sMethod))
  835. continue;
  836. $aProfiles[$aModule['name']] = _t('_' . $aModule['name']);
  837. }
  838. $aResults = array();
  839. foreach($aProfiles as $sName1 => $sTitle1)
  840. foreach($aProfiles as $sName2 => $sTitle2)
  841. $aResults[$sName1 . '_' . $sName2] = $sTitle1 . ' - ' . $sTitle2;
  842. return $aResults;
  843. }
  844. public function serviceGetBadge($aBadge, $bIsCompact = false)
  845. {
  846. $sClass = '';
  847. $sStyleFont = '';
  848. $sStyleBg = '';
  849. if ($aBadge['color'] == '')
  850. $aBadge['color'] = '#ff0000';
  851. if ($aBadge['fontcolor'] == '')
  852. $aBadge['fontcolor'] = '#ffffff';
  853. if ($bIsCompact){
  854. $aBadge['is_icon_only'] = 1;
  855. $sClass .= ' bx-badge-compact-to';
  856. $sStyleFont = 'color: ' . $aBadge['color'];
  857. }
  858. else{
  859. $sStyleBg = 'background-color: ' . $aBadge['color'] . '; color: ' . $aBadge['fontcolor'];
  860. }
  861. if ($aBadge['is_icon_only'] == 1){
  862. $sClass .= ' bx-badge-compact';
  863. }
  864. return BxDolTemplate::getInstance()->parseHtmlByName('badge.html', array(
  865. 'bx_if:content' => array(
  866. 'condition' => $aBadge['is_icon_only'] != '1',
  867. 'content' => array('content' => _t($aBadge['text'])),
  868. ),
  869. 'bx_if:icon' => array(
  870. 'condition' => $aBadge['icon'] != '',
  871. 'content' => array('content' => BxDolTemplate::getInstance()->getIcon($aBadge['icon'], array('class' => 'bx-badge-icon sys-colored', 'style' => $sStyleFont))),
  872. ),
  873. 'title' => $aBadge['text'],
  874. 'style_font' => $sStyleFont,
  875. 'style_bg' => $sStyleBg,
  876. 'class' => $sClass,
  877. )
  878. );
  879. }
  880. private function _getSearchObject()
  881. {
  882. $sClass = 'BxTemplSearch';
  883. $sElsName = 'bx_elasticsearch';
  884. $sElsMethod = 'is_configured';
  885. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod) && !bx_get('cat') && !bx_get('type')) {
  886. $oModule = BxDolModule::getInstance($sElsName);
  887. bx_import('Search', $oModule->_aModule);
  888. $sClass = 'BxElsSearch';
  889. }
  890. bx_alert('system', 'search_keyword', 0, 0, array('class' => &$sClass));
  891. $oSearch = new $sClass(bx_get('section'));
  892. $oSearch->setLiveSearch(bx_get('live_search') ? 1 : 0);
  893. $oSearch->setMetaType(bx_process_input(bx_get('type')));
  894. $oSearch->setCategoryObject(bx_process_input(bx_get('cat')));
  895. return $oSearch;
  896. }
  897. }
  898. /** @} */