BxBaseServices.php 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105
  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. * Checks whether a module is a 'Content' module or not.
  357. *
  358. * @param string $mixedModule - module name or an instance of Module class.
  359. * @return boolean result of operation.
  360. */
  361. public function serviceIsModuleContent($mixedModule)
  362. {
  363. if(is_string($mixedModule))
  364. $mixedModule = BxDolModule::getInstance($mixedModule);
  365. return $mixedModule instanceof BxDolModule && $mixedModule instanceof iBxDolContentInfoService && !($mixedModule instanceof iBxDolProfileService);
  366. }
  367. /**
  368. * Checks whether a module is a 'Context' module or not.
  369. *
  370. * @param string $mixedModule - module name or an instance of Module class.
  371. * @return boolean result of operation.
  372. */
  373. public function serviceIsModuleContext($mixedModule)
  374. {
  375. if(is_string($mixedModule))
  376. $mixedModule = BxDolModule::getInstance($mixedModule);
  377. return $mixedModule instanceof BxDolModule && $mixedModule instanceof iBxDolProfileService;
  378. }
  379. /**
  380. * Checks whether a module is a 'Profile' module or not.
  381. *
  382. * @param string $mixedModule - module name or an instance of Module class.
  383. * @return boolean result of operation.
  384. */
  385. public function serviceIsModuleProfile($mixedModule)
  386. {
  387. if(is_string($mixedModule))
  388. $mixedModule = BxDolModule::getInstance($mixedModule);
  389. return $mixedModule instanceof BxDolModule && $mixedModule instanceof iBxDolProfileService && $mixedModule->serviceActAsProfile();
  390. }
  391. /**
  392. * Get modules by type. Available types are 'content', 'context', 'profile'.
  393. *
  394. * @param type $sType - string with type.
  395. * @return array of modules.
  396. */
  397. public function serviceGetModulesByType($sType)
  398. {
  399. $aResults = array();
  400. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1));
  401. foreach($aModules as $aModule) {
  402. $oModule = BxDolModule::getInstance($aModule['name']);
  403. if(!$oModule)
  404. continue;
  405. if($sType == 'content' && !$this->serviceIsModuleContent($oModule))
  406. continue;
  407. if($sType == 'context' && !$this->serviceIsModuleContext($oModule))
  408. continue;
  409. if($sType == 'profile' && !$this->serviceIsModuleProfile($oModule))
  410. continue;
  411. $aResults[] = $aModule;
  412. }
  413. return $aResults;
  414. }
  415. public function serviceProfileUnit ($iContentId, $aParams = array())
  416. {
  417. return $this->_serviceProfileFunc('getUnit', $iContentId, $aParams);
  418. }
  419. public function serviceHasImage ($iContentId)
  420. {
  421. return false;
  422. }
  423. public function serviceProfilePicture ($iContentId)
  424. {
  425. return BxDolTemplate::getInstance()->getImageUrl('account-picture.png');
  426. }
  427. public function serviceProfileAvatar ($iContentId)
  428. {
  429. return BxDolTemplate::getInstance()->getImageUrl('account-avatar.png');
  430. }
  431. public function serviceProfileCover ($iContentId)
  432. {
  433. return '';
  434. }
  435. public function serviceProfileEditUrl ($iContentId)
  436. {
  437. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=account-settings-info');
  438. }
  439. public function serviceProfileThumb ($iContentId)
  440. {
  441. return $this->_serviceProfileFunc('getThumb', $iContentId);
  442. }
  443. public function serviceProfileIcon ($iContentId)
  444. {
  445. return $this->_serviceProfileFunc('getIcon', $iContentId);
  446. }
  447. public function serviceProfileName ($iContentId)
  448. {
  449. return $this->_serviceProfileFunc('getDisplayName', $iContentId);
  450. }
  451. public function serviceProfileUrl ($iContentId)
  452. {
  453. return $this->_serviceProfileFunc('getUrl', $iContentId);
  454. }
  455. /**
  456. * @see iBxDolProfileService::serviceCheckAllowedProfileView
  457. */
  458. public function serviceCheckAllowedProfileView($iContentId)
  459. {
  460. return _t('_Access denied');
  461. }
  462. /**
  463. * @see iBxDolProfileService::serviceCheckAllowedProfileContact
  464. */
  465. public function serviceCheckAllowedProfileContact($iContentId)
  466. {
  467. return _t('_Access denied');
  468. }
  469. /**
  470. * @see iBxDolProfileService::serviceCheckAllowedPostInProfile
  471. */
  472. public function serviceCheckAllowedPostInProfile($iContentId, $sPostModule = '')
  473. {
  474. return _t('_Access denied');
  475. }
  476. /**
  477. * @see iBxDolProfileService::serviceCheckAllowedModuleActionInProfile
  478. */
  479. public function serviceCheckAllowedModuleActionInProfile($iContentId, $sPostModule, $sActionName)
  480. {
  481. return _t('_Access denied');
  482. }
  483. /**
  484. * @see iBxDolProfileService::serviceGetSpaceTitle
  485. */
  486. public function serviceGetSpaceTitle()
  487. {
  488. return '';
  489. }
  490. /**
  491. * @see iBxDolProfileService::serviceGetParticipatingProfiles
  492. */
  493. public function serviceGetParticipatingProfiles($iProfileId, $aConnectionObject = false)
  494. {
  495. return array();
  496. }
  497. /**
  498. * @page service Service Calls
  499. * @section bx_system_general System Services
  500. * @subsection bx_system_general-general General
  501. * @subsubsection bx_system_general-get_create_post_form get_create_post_form
  502. *
  503. * @code bx_srv('system', 'get_create_post_form', [false, "bx_posts"], 'TemplServices'); @endcode
  504. * @code {{~system:get_create_post_form:TemplServices[false,"bx_posts"]~}} @endcode
  505. *
  506. * Get United Create Post form.
  507. * @param $mixedContextId - context which the post will be created in:
  508. * - false = 'Public' post form;
  509. * - 0 = 'Profile' post form, which allows to post in your own profile and connections;
  510. * - n = 'Context' post form, which allows to post in context (3d party profile, group, event, etc).
  511. * @param $sDefault - tab selected by default.
  512. * @param $aCustom - an array with custom paramaters.
  513. * @return string with form content
  514. *
  515. * @see BxBaseServices::serviceGetCreatePostForm
  516. */
  517. /**
  518. * @ref bx_system_general-get_create_post_form "get_create_post_form"
  519. */
  520. public function serviceGetCreatePostForm($mixedContextId = false, $sDefault = '', $aCustom = array())
  521. {
  522. if(!isLogged() || ($mixedContextId !== false && !is_numeric($mixedContextId)))
  523. return '';
  524. $oProfile = BxDolProfile::getInstance();
  525. if(!$oProfile)
  526. return '';
  527. if($mixedContextId !== false)
  528. $mixedContextId = (int)(!empty($mixedContextId) ? -$mixedContextId : $oProfile->id());
  529. $oMenu = BxDolMenu::getObjectInstance('sys_create_post');
  530. $oMenu->setContextId($mixedContextId);
  531. if(!$oMenu)
  532. return '';
  533. $aMenuItems = $oMenu->getMenuItems();
  534. if(empty($aMenuItems) || !is_array($aMenuItems))
  535. return '';
  536. if(empty($sDefault)) {
  537. $aDefault = array_shift($aMenuItems);
  538. $sDefault = !empty($aDefault['module']) ? $aDefault['module'] : $aDefault['name'];
  539. }
  540. $oMenu->setSelected($sDefault, $sDefault);
  541. $bContext = $mixedContextId !== false;
  542. if($bContext && ($aContextInfo = BxDolProfileQuery::getInstance()->getInfoById(abs($mixedContextId))))
  543. if(bx_srv($aContextInfo['type'], 'check_allowed_post_in_profile', [$aContextInfo['content_id'], $sDefault]) !== CHECK_ACTION_RESULT_ALLOWED)
  544. return '';
  545. $sTitle = _t('_sys_page_block_title_create_post' . (!$bContext ? '_public' : ($mixedContextId < 0 ? '_context' : '')));
  546. $sPlaceholder = _t('_sys_txt_create_post_placeholder', $oProfile->getDisplayName());
  547. $oTemplate = BxDolTemplate::getInstance();
  548. $oTemplate->addJs(array('BxDolCreatePost.js'));
  549. $sJsObject = 'oBxDolCreatePost';
  550. $sJsContent = $oTemplate->_wrapInTagJsCode("var " . $sJsObject . " = new BxDolCreatePost(" . json_encode(array(
  551. 'sObjName' => $sJsObject,
  552. 'sRootUrl' => BX_DOL_URL_ROOT,
  553. 'sDefault' => $sDefault,
  554. 'iContextId' => $bContext ? $mixedContextId : 0,
  555. 'oCustom' => $aCustom
  556. )) . ");");
  557. return array(
  558. 'title' => $sTitle,
  559. 'content' => BxDolTemplate::getInstance()->parseHtmlByName('create_post_form.html', array(
  560. 'default' => $sDefault,
  561. 'placeholder' => $sPlaceholder,
  562. 'user_thumb' => $oProfile->getUnit(0, array('template' => 'unit_wo_info_links')),
  563. 'form' => BxDolService::call($sDefault, 'get_create_post_form', array(array('context_id' => $mixedContextId, 'ajax_mode' => true, 'absolute_action_url' => true, 'custom' => $aCustom))),
  564. 'js_object' => $sJsObject,
  565. 'js_content' => $sJsContent
  566. )),
  567. 'menu' => $oMenu
  568. );
  569. }
  570. public function serviceGetBlockAuthor($sModule, $iContentId = 0)
  571. {
  572. if(!$iContentId && bx_get('id') !== false)
  573. $iContentId = (int)bx_get('id');
  574. $sMethodGetAuthor = 'get_author';
  575. if(!$sModule || !$iContentId || !BxDolRequest::serviceExists($sModule, $sMethodGetAuthor))
  576. return '';
  577. $iAuthor = bx_srv($sModule, $sMethodGetAuthor, [$iContentId]);
  578. if(!$iAuthor)
  579. return '';
  580. $oAuthor = BxDolProfile::getInstance($iAuthor);
  581. if(!$oAuthor)
  582. return '';
  583. $sModuleAuthor = $oAuthor->getModule();
  584. $sMethodGetCover = 'entity_cover';
  585. if(!BxDolRequest::serviceExists($sModuleAuthor, $sMethodGetCover))
  586. return '';
  587. return bx_srv($sModuleAuthor, $sMethodGetCover, [$oAuthor->getContentId(), [
  588. 'class' => 'bx-base-author',
  589. 'use_as_author' => true,
  590. 'show_cover' => false
  591. ]]);
  592. }
  593. /**
  594. * @page service Service Calls
  595. * @section bx_system_general System Services
  596. * @subsection bx_system_general-general General
  597. * @subsubsection bx_system_general-get_site_submenu get_site_submenu
  598. *
  599. * @code bx_srv('system', 'get_site_submenu', [], 'TemplServices'); @endcode
  600. * @code {{~system:get_site_submenu:TemplServices[]~}} @endcode
  601. *
  602. * Get Site Submenu code.
  603. * @see BxBaseServices::serviceGetSiteSubmenu
  604. */
  605. /**
  606. * @ref bx_system_general-get_site_submenu "get_site_submenu"
  607. */
  608. public function serviceGetSiteSubmenu()
  609. {
  610. $oMenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  611. return $oMenu ? $oMenu->getCode() : '';
  612. }
  613. /**
  614. * @page service Service Calls
  615. * @section bx_system_general System Services
  616. * @subsection bx_system_general-general General
  617. * @subsubsection bx_system_general-get_products_names get_products_names
  618. *
  619. * @code bx_srv('system', 'get_products_names', [], 'TemplServices');
  620. *
  621. * @code http://example.com/m/oauth2/com/get_products_names?module=system&class=BaseServices @endcode
  622. * @code http://hihi.una.io/modules/?r=oauth2/com/get_products_names&module=system&class=BaseServices @endcode
  623. *
  624. * Get an array of products names from all modules with payments functionality.
  625. * @param $iVendorId filter products by vendor ID.
  626. * @param $iLimit limit number of records from one module.
  627. * @return array of products where key id product name and value is module name
  628. *
  629. * @see BxBaseServices::serviceGetProductsNames
  630. */
  631. /**
  632. * @ref bx_system_general-get_products_names "get_products_names"
  633. */
  634. public function serviceGetProductsNames($iVendorId = 0, $iLimit = 1000)
  635. {
  636. $o = BxDolPayments::getInstance();
  637. if (!$o)
  638. return array();
  639. return $o->getProductsNames($iVendorId, $iLimit);
  640. }
  641. /**
  642. * @see iBxDolProfileService::serviceCheckSpacePrivacy
  643. */
  644. public function serviceCheckSpacePrivacy($iContentId)
  645. {
  646. return _t('_Access denied');
  647. }
  648. public function serviceFormsHelper ()
  649. {
  650. return new BxTemplAccountForms();
  651. }
  652. public function serviceActAsProfile ()
  653. {
  654. return false;
  655. }
  656. public function servicePrepareFields ($aFieldsProfile)
  657. {
  658. return $aFieldsProfile;
  659. }
  660. public function serviceProfilesSearch ($sTerm, $iLimit)
  661. {
  662. $oDb = BxDolAccountQuery::getInstance();
  663. $aRet = array();
  664. $a = $oDb->searchByTerm($sTerm, $iLimit);
  665. foreach ($a as $r)
  666. $aRet[] = array ('label' => $this->serviceProfileName($r['content_id']), 'value' => $r['profile_id']);
  667. return $aRet;
  668. }
  669. /**
  670. * @page service Service Calls
  671. * @section bx_system_general System Services
  672. * @subsection bx_system_general-general General
  673. * @subsubsection bx_system_general-keyword_search keyword_search
  674. *
  675. * @code bx_srv('system', 'keyword_search', ["bx_posts", ["keyword" => "test"}], 'TemplServices'); @endcode
  676. *
  677. * @code {{~system:keyword_search:TemplServices["bx_posts", {"keyword":"test"}]~}} @endcode
  678. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country", "keyword": "AU"}, "unit.html"]~}} @endcode
  679. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_state", "state":"NSW", "keyword": "AU"}, "unit.html"]~}} @endcode
  680. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"}, "unit.html"]~}} @endcode
  681. * @code {{~system:keyword_search:TemplServices["bx_posts", {"meta_type": "mention", "keyword": 2}, "unit_gallery.html"]~}} @endcode
  682. * @code {{~system:keyword_search:TemplServices["bx_posts", {"cat": "bx_posts_cats", "keyword": 3}, "unit_gallery.html"]~}} @endcode
  683. *
  684. * Search by keyword
  685. * @param $sSection - search object to search in, usually module name, for example: bx_posts
  686. * @param $aCondition - condition for search, supported conditions:
  687. * - search by keyword: ["keyword" => "test"]
  688. * - search by country: ["meta_type" => "location_country", "keyword" => "AU"]
  689. * - search by country and state: ["meta_type": "location_country_state", "state":"NSW", "keyword": "AU"]
  690. * - search by country, state and city: ["meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"]
  691. * - search for mentions: ["meta_type" => "mention", "keyword" => 2]
  692. * - search in category: ["cat": "bx_posts_cats", "keyword": 3]
  693. * @param $sTemplate - template for displaying search results, for example: unit.html
  694. * @param $iStart - paginate, display records starting from this number
  695. * @param $iPerPage - paginate, display this number of records per page
  696. * @param $bLiveSearch - search results like in live search
  697. *
  698. * @see BxBaseServices::serviceKeywordSearch
  699. */
  700. /**
  701. * @ref bx_system_general-keyword_search "keyword_search"
  702. */
  703. public function serviceKeywordSearch ($sSection, $aCondition, $sTemplate = '', $iStart = 0, $iPerPage = 0, $bLiveSearch = 0, $bPaginate = false)
  704. {
  705. if (!$sSection || !isset($aCondition['keyword']))
  706. return '';
  707. $sClass = 'BxTemplSearch';
  708. $sElsName = 'bx_elasticsearch';
  709. $sElsMethod = 'is_configured';
  710. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod)) {
  711. $oModule = BxDolModule::getInstance($sElsName);
  712. bx_import('Search', $oModule->_aModule);
  713. $sClass = 'BxElsSearch';
  714. }
  715. $oSearch = new $sClass(array($sSection));
  716. $oSearch->setLiveSearch($bLiveSearch);
  717. $oSearch->setMetaType(isset($aCondition['meta_type']) ? $aCondition['meta_type'] : '');
  718. $oSearch->setCategoryObject(isset($aCondition['cat']) ? $aCondition['cat'] : '');
  719. $oSearch->setCustomSearchCondition($aCondition);
  720. if (!$bPaginate)
  721. $oSearch->setRawProcessing(true);
  722. $oSearch->setCustomCurrentCondition(array(
  723. 'paginate' => array (
  724. 'start' => $iStart,
  725. 'perPage' => $iPerPage ? $iPerPage : BX_DOL_SEARCH_RESULTS_PER_PAGE_DEFAULT,
  726. )));
  727. if ($sTemplate)
  728. $oSearch->setUnitTemplate($sTemplate);
  729. return $oSearch->response();
  730. }
  731. /**
  732. * @page service Service Calls
  733. * @section bx_system_general System Services
  734. * @subsection bx_system_general-general General
  735. * @subsubsection bx_system_general-keyword_search keyword_search
  736. *
  737. * @code bx_srv('system', 'search_keyword_form', 'TemplServices'); @endcode
  738. *
  739. * Block with Search by Keywords Form
  740. *
  741. * @see BxBaseServices::serviceSearchKeywordForm
  742. */
  743. /**
  744. * @ref bx_system_general-keyword_search "keyword_search"
  745. */
  746. public function serviceSearchKeywordForm ()
  747. {
  748. return $this->_getSearchObject()->getForm(BX_DB_PADDING_DEF, false, true);
  749. }
  750. /**
  751. * @page service Service Calls
  752. * @section bx_system_general System Services
  753. * @subsection bx_system_general-general General
  754. * @subsubsection bx_system_general-keyword_search keyword_search
  755. *
  756. * @code bx_srv('system', 'search_keyword_result', 'TemplServices'); @endcode
  757. *
  758. * Block with Search by Keywords Results
  759. *
  760. * @see BxBaseServices::serviceSearchKeywordResult
  761. */
  762. /**
  763. * @ref bx_system_general-keyword_search "keyword_search"
  764. */
  765. public function serviceSearchKeywordResult ()
  766. {
  767. $oSearch = $this->_getSearchObject();
  768. $sCode = '';
  769. if (bx_get('keyword') !== false) {
  770. $sCode = $oSearch->response();
  771. if (!$sCode)
  772. $sCode = $oSearch->getEmptyResult();
  773. }
  774. return $sCode;
  775. }
  776. /**
  777. * @page service Service Calls
  778. * @section bx_system_general System Services
  779. * @subsection bx_system_general-general General
  780. * @subsubsection bx_system_general-cmts cmts
  781. *
  782. * @code bx_srv('system', 'cmts', ["sys_blocks", 1], 'TemplServices'); @endcode
  783. *
  784. * @code {{~system:cmts:TemplServices["sys_blocks", 1]~}} @endcode
  785. *
  786. * Comments block
  787. * @param $sObject - comments object name
  788. * @param $sId - content id assiciated tith the comments
  789. *
  790. * @see BxBaseServices::serviceCmts
  791. */
  792. /**
  793. * @ref bx_system_general-cmts "cmts"
  794. */
  795. public function serviceCmts ($sObject, $sId)
  796. {
  797. $o = BxDolCmts::getObjectInstance($sObject, $sId);
  798. if (!$o || !$o->isEnabled())
  799. return '';
  800. return $o->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => true));
  801. }
  802. public function _serviceProfileFunc ($sFunc, $iContentId, $aParams = array())
  803. {
  804. if (!$iContentId)
  805. return false;
  806. if (!($oAccount = BxDolAccount::getInstance($iContentId)))
  807. return false;
  808. return $oAccount->$sFunc(false, $aParams);
  809. }
  810. public function serviceAlertResponseProcessInstalled()
  811. {
  812. BxDolTranscoderImage::registerHandlersSystem();
  813. }
  814. public function serviceAlertResponseProcessStorageChange ($oAlert)
  815. {
  816. if ('sys_storage_default' != $oAlert->aExtras['option'])
  817. return;
  818. $aStorages = BxDolStorageQuery::getStorageObjects();
  819. foreach ($aStorages as $r) {
  820. if (0 == $r['current_size'] && 0 == $r['current_number'] && ($oStorage = BxDolStorage::getObjectInstance($r['object'])))
  821. $oStorage->changeStorageEngine($oAlert->aExtras['value']);
  822. }
  823. }
  824. public function serviceGetOptionsProfileBot()
  825. {
  826. $aResult = array(
  827. array('key' => '', 'value' => _t('_Select_one'))
  828. );
  829. $aAccountsIds = BxDolAccountQuery::getInstance()->getOperators();
  830. foreach($aAccountsIds as $iAccountId) {
  831. $aProfilesIds = BxDolAccount::getInstance($iAccountId)->getProfilesIds(true, false);
  832. foreach($aProfilesIds as $iProfileId) {
  833. $oProfile = BxDolProfile::getInstance($iProfileId);
  834. $aResult[] = array(
  835. 'key' => $iProfileId,
  836. 'value' => _t('_sys_profile_with_type', $oProfile->getDisplayName(), $oProfile->getModule()),
  837. );
  838. }
  839. }
  840. return $aResult;
  841. }
  842. public function serviceGetOptionsModuleListForPrivacySelector()
  843. {
  844. $aResult = array();
  845. $BxDolModuleQuery = BxDolModuleQuery::getInstance();
  846. $aModules = $BxDolModuleQuery->getModulesBy(array('type' => 'modules', 'active' => 1));
  847. foreach($aModules as $aModule){
  848. $oModule = BxDolModule::getInstance($aModule['name']);
  849. if($oModule instanceof iBxDolContentInfoService){
  850. if (!BxDolRequest::serviceExists($aModule['name'], 'act_as_profile'))
  851. continue;
  852. $aResult[$aModule['name']] = $aModule['title'];
  853. }
  854. }
  855. return $aResult;
  856. }
  857. public function serviceGetOptionsEmbedDefault()
  858. {
  859. $aResults = array(
  860. '' => _t('_None')
  861. );
  862. $aObjects = BxDolEmbedQuery::getObjects();
  863. foreach($aObjects as $aObject)
  864. $aResults[$aObject['object']] = $aObject['title'];
  865. return $aResults;
  866. }
  867. public function serviceGetOptionsLocationFieldDefault()
  868. {
  869. $aResults = array();
  870. $aObjects = BxDolLocationFieldQuery::getObjects();
  871. foreach($aObjects as $aObject)
  872. $aResults[$aObject['object']] = _t($aObject['title']);
  873. return $aResults;
  874. }
  875. public function serviceGetOptionsLocationMapDefault()
  876. {
  877. $aResults = array();
  878. $aObjects = BxDolLocationMapQuery::getObjects();
  879. foreach($aObjects as $aObject)
  880. $aResults[$aObject['object']] = _t($aObject['title']);
  881. return $aResults;
  882. }
  883. public function serviceGetOptionsLocationLeafletGetProviders()
  884. {
  885. return BxDolLocationMapLeaflet::getProviders();
  886. }
  887. public function serviceGetOptionsRelations()
  888. {
  889. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1));
  890. $aProfiles = array();
  891. foreach($aModules as $aModule) {
  892. $sMethod = 'act_as_profile';
  893. if(!BxDolRequest::serviceExists($aModule['name'], $sMethod) || !BxDolService::call($aModule['name'], $sMethod))
  894. continue;
  895. $aProfiles[$aModule['name']] = _t('_' . $aModule['name']);
  896. }
  897. $aResults = array();
  898. foreach($aProfiles as $sName1 => $sTitle1)
  899. foreach($aProfiles as $sName2 => $sTitle2)
  900. $aResults[$sName1 . '_' . $sName2] = $sTitle1 . ' - ' . $sTitle2;
  901. return $aResults;
  902. }
  903. public function serviceGetOptionsCfProhibited()
  904. {
  905. return BxDolFormQuery::getDataItems('sys_content_filter');
  906. }
  907. public function serviceGetBadge($aBadge, $bIsCompact = false)
  908. {
  909. $sClass = '';
  910. $sStyleFont = '';
  911. $sStyleBg = '';
  912. if ($aBadge['color'] == '')
  913. $aBadge['color'] = '#ff0000';
  914. if ($aBadge['fontcolor'] == '')
  915. $aBadge['fontcolor'] = '#ffffff';
  916. if ($bIsCompact && $aBadge['icon'] != ''){
  917. $aBadge['is_icon_only'] = 1;
  918. $sClass .= ' bx-badge-compact-to';
  919. $sStyleFont = 'color: ' . $aBadge['color'];
  920. }
  921. else{
  922. $sStyleBg = 'background-color: ' . $aBadge['color'] . '; color: ' . $aBadge['fontcolor'];
  923. }
  924. if ($aBadge['is_icon_only'] == 1){
  925. $sClass .= ' bx-badge-compact';
  926. }
  927. return BxDolTemplate::getInstance()->parseHtmlByName('badge.html', array(
  928. 'bx_if:content' => array(
  929. 'condition' => $aBadge['is_icon_only'] != '1',
  930. 'content' => array('content' => _t($aBadge['text'])),
  931. ),
  932. 'bx_if:icon' => array(
  933. 'condition' => $aBadge['icon'] != '',
  934. 'content' => array('content' => BxDolTemplate::getInstance()->getIcon($aBadge['icon'], array('class' => 'bx-badge-icon sys-colored', 'style' => $sStyleFont))),
  935. ),
  936. 'title' => $aBadge['text'],
  937. 'style_font' => $sStyleFont,
  938. 'style_bg' => $sStyleBg,
  939. 'class' => $sClass,
  940. )
  941. );
  942. }
  943. private function _getSearchObject()
  944. {
  945. $sClass = 'BxTemplSearch';
  946. $sElsName = 'bx_elasticsearch';
  947. $sElsMethod = 'is_configured';
  948. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod) && !bx_get('cat') && !bx_get('type')) {
  949. $oModule = BxDolModule::getInstance($sElsName);
  950. bx_import('Search', $oModule->_aModule);
  951. $sClass = 'BxElsSearch';
  952. }
  953. bx_alert('system', 'search_keyword', 0, 0, array('class' => &$sClass));
  954. $oSearch = new $sClass(bx_get('section'));
  955. $oSearch->setLiveSearch(bx_get('live_search') ? 1 : 0);
  956. $oSearch->setMetaType(bx_process_input(bx_get('type')));
  957. $oSearch->setCategoryObject(bx_process_input(bx_get('cat')));
  958. return $oSearch;
  959. }
  960. }
  961. /** @} */