BxBaseServices.php 36 KB

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