BxBaseServices.php 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010
  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_site_submenu get_site_submenu
  523. *
  524. * @code bx_srv('system', 'get_site_submenu', [], 'TemplServices'); @endcode
  525. * @code {{~system:get_site_submenu:TemplServices[]~}} @endcode
  526. *
  527. * Get Site Submenu code.
  528. * @see BxBaseServices::serviceGetSiteSubmenu
  529. */
  530. /**
  531. * @ref bx_system_general-get_site_submenu "get_site_submenu"
  532. */
  533. public function serviceGetSiteSubmenu()
  534. {
  535. $oMenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  536. $oMenu->setTemplateWrapper('menu_main_submenu_empty.html');
  537. return $oMenu ? $oMenu->getCode () : '';
  538. }
  539. /**
  540. * @page service Service Calls
  541. * @section bx_system_general System Services
  542. * @subsection bx_system_general-general General
  543. * @subsubsection bx_system_general-get_products_names get_products_names
  544. *
  545. * @code bx_srv('system', 'get_products_names', [], 'TemplServices');
  546. *
  547. * @code http://example.com/m/oauth2/com/get_products_names?module=system&class=BaseServices @endcode
  548. * @code http://hihi.una.io/modules/?r=oauth2/com/get_products_names&module=system&class=BaseServices @endcode
  549. *
  550. * Get an array of products names from all modules with payments functionality.
  551. * @param $iVendorId filter products by vendor ID.
  552. * @param $iLimit limit number of records from one module.
  553. * @return array of products where key id product name and value is module name
  554. *
  555. * @see BxBaseServices::serviceGetProductsNames
  556. */
  557. /**
  558. * @ref bx_system_general-get_products_names "get_products_names"
  559. */
  560. public function serviceGetProductsNames($iVendorId = 0, $iLimit = 1000)
  561. {
  562. $o = BxDolPayments::getInstance();
  563. if (!$o)
  564. return array();
  565. return $o->getProductsNames($iVendorId, $iLimit);
  566. }
  567. /**
  568. * @see iBxDolProfileService::serviceCheckSpacePrivacy
  569. */
  570. public function serviceCheckSpacePrivacy($iContentId)
  571. {
  572. return _t('_Access denied');
  573. }
  574. public function serviceFormsHelper ()
  575. {
  576. return new BxTemplAccountForms();
  577. }
  578. public function serviceActAsProfile ()
  579. {
  580. return false;
  581. }
  582. public function servicePrepareFields ($aFieldsProfile)
  583. {
  584. return $aFieldsProfile;
  585. }
  586. public function serviceProfilesSearch ($sTerm, $iLimit)
  587. {
  588. $oDb = BxDolAccountQuery::getInstance();
  589. $aRet = array();
  590. $a = $oDb->searchByTerm($sTerm, $iLimit);
  591. foreach ($a as $r)
  592. $aRet[] = array ('label' => $this->serviceProfileName($r['content_id']), 'value' => $r['profile_id']);
  593. return $aRet;
  594. }
  595. /**
  596. * @page service Service Calls
  597. * @section bx_system_general System Services
  598. * @subsection bx_system_general-general General
  599. * @subsubsection bx_system_general-keyword_search keyword_search
  600. *
  601. * @code bx_srv('system', 'keyword_search', ["bx_posts", ["keyword" => "test"}], 'TemplServices'); @endcode
  602. *
  603. * @code {{~system:keyword_search:TemplServices["bx_posts", {"keyword":"test"}]~}} @endcode
  604. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country", "keyword": "AU"}, "unit.html"]~}} @endcode
  605. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_state", "state":"NSW", "keyword": "AU"}, "unit.html"]~}} @endcode
  606. * @code {{~system:keyword_search:TemplServices["bx_albums", {"meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"}, "unit.html"]~}} @endcode
  607. * @code {{~system:keyword_search:TemplServices["bx_posts", {"meta_type": "mention", "keyword": 2}, "unit_gallery.html"]~}} @endcode
  608. * @code {{~system:keyword_search:TemplServices["bx_posts", {"cat": "bx_posts_cats", "keyword": 3}, "unit_gallery.html"]~}} @endcode
  609. *
  610. * Search by keyword
  611. * @param $sSection - search object to search in, usually module name, for example: bx_posts
  612. * @param $aCondition - condition for search, supported conditions:
  613. * - search by keyword: ["keyword" => "test"]
  614. * - search by country: ["meta_type" => "location_country", "keyword" => "AU"]
  615. * - search by country and state: ["meta_type": "location_country_state", "state":"NSW", "keyword": "AU"]
  616. * - search by country, state and city: ["meta_type": "location_country_city", "state":"NSW", "city":"Manly", "keyword": "AU"]
  617. * - search for mentions: ["meta_type" => "mention", "keyword" => 2]
  618. * - search in category: ["cat": "bx_posts_cats", "keyword": 3]
  619. * @param $sTemplate - template for displaying search results, for example: unit.html
  620. * @param $iStart - paginate, display records starting from this number
  621. * @param $iPerPage - paginate, display this number of records per page
  622. * @param $bLiveSearch - search results like in live search
  623. *
  624. * @see BxBaseServices::serviceKeywordSearch
  625. */
  626. /**
  627. * @ref bx_system_general-keyword_search "keyword_search"
  628. */
  629. public function serviceKeywordSearch ($sSection, $aCondition, $sTemplate = '', $iStart = 0, $iPerPage = 0, $bLiveSearch = 0, $bPaginate = false)
  630. {
  631. if (!$sSection || !isset($aCondition['keyword']))
  632. return '';
  633. $sClass = 'BxTemplSearch';
  634. $sElsName = 'bx_elasticsearch';
  635. $sElsMethod = 'is_configured';
  636. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod)) {
  637. $oModule = BxDolModule::getInstance($sElsName);
  638. bx_import('Search', $oModule->_aModule);
  639. $sClass = 'BxElsSearch';
  640. }
  641. $oSearch = new $sClass(array($sSection));
  642. $oSearch->setLiveSearch($bLiveSearch);
  643. $oSearch->setMetaType(isset($aCondition['meta_type']) ? $aCondition['meta_type'] : '');
  644. $oSearch->setCategoryObject(isset($aCondition['cat']) ? $aCondition['cat'] : '');
  645. $oSearch->setCustomSearchCondition($aCondition);
  646. if (!$bPaginate)
  647. $oSearch->setRawProcessing(true);
  648. $oSearch->setCustomCurrentCondition(array(
  649. 'paginate' => array (
  650. 'start' => $iStart,
  651. 'perPage' => $iPerPage ? $iPerPage : BX_DOL_SEARCH_RESULTS_PER_PAGE_DEFAULT,
  652. )));
  653. if ($sTemplate)
  654. $oSearch->setUnitTemplate($sTemplate);
  655. return $oSearch->response();
  656. }
  657. /**
  658. * @page service Service Calls
  659. * @section bx_system_general System Services
  660. * @subsection bx_system_general-general General
  661. * @subsubsection bx_system_general-keyword_search keyword_search
  662. *
  663. * @code bx_srv('system', 'search_keyword_form', 'TemplServices'); @endcode
  664. *
  665. * Block with Search by Keywords Form
  666. *
  667. * @see BxBaseServices::serviceSearchKeywordForm
  668. */
  669. /**
  670. * @ref bx_system_general-keyword_search "keyword_search"
  671. */
  672. public function serviceSearchKeywordForm ()
  673. {
  674. return $this->_getSearchObject()->getForm(BX_DB_PADDING_DEF, false, true);
  675. }
  676. /**
  677. * @page service Service Calls
  678. * @section bx_system_general System Services
  679. * @subsection bx_system_general-general General
  680. * @subsubsection bx_system_general-keyword_search keyword_search
  681. *
  682. * @code bx_srv('system', 'search_keyword_result', 'TemplServices'); @endcode
  683. *
  684. * Block with Search by Keywords Results
  685. *
  686. * @see BxBaseServices::serviceSearchKeywordResult
  687. */
  688. /**
  689. * @ref bx_system_general-keyword_search "keyword_search"
  690. */
  691. public function serviceSearchKeywordResult ()
  692. {
  693. $oSearch = $this->_getSearchObject();
  694. $sCode = '';
  695. if (bx_get('keyword') !== false) {
  696. $sCode = $oSearch->response();
  697. if (!$sCode)
  698. $sCode = $oSearch->getEmptyResult();
  699. }
  700. return $sCode;
  701. }
  702. /**
  703. * @page service Service Calls
  704. * @section bx_system_general System Services
  705. * @subsection bx_system_general-general General
  706. * @subsubsection bx_system_general-cmts cmts
  707. *
  708. * @code bx_srv('system', 'cmts', ["sys_blocks", 1], 'TemplServices'); @endcode
  709. *
  710. * @code {{~system:cmts:TemplServices["sys_blocks", 1]~}} @endcode
  711. *
  712. * Comments block
  713. * @param $sObject - comments object name
  714. * @param $sId - content id assiciated tith the comments
  715. *
  716. * @see BxBaseServices::serviceCmts
  717. */
  718. /**
  719. * @ref bx_system_general-cmts "cmts"
  720. */
  721. public function serviceCmts ($sObject, $sId)
  722. {
  723. $o = BxDolCmts::getObjectInstance($sObject, $sId);
  724. if (!$o || !$o->isEnabled())
  725. return '';
  726. return $o->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => true));
  727. }
  728. public function _serviceProfileFunc ($sFunc, $iContentId, $aParams = array())
  729. {
  730. if (!$iContentId)
  731. return false;
  732. if (!($oAccount = BxDolAccount::getInstance($iContentId)))
  733. return false;
  734. return $oAccount->$sFunc(false, $aParams);
  735. }
  736. public function serviceAlertResponseProcessInstalled()
  737. {
  738. BxDolTranscoderImage::registerHandlersSystem();
  739. }
  740. public function serviceAlertResponseProcessStorageChange ($oAlert)
  741. {
  742. if ('sys_storage_default' != $oAlert->aExtras['option'])
  743. return;
  744. $aStorages = BxDolStorageQuery::getStorageObjects();
  745. foreach ($aStorages as $r) {
  746. if (0 == $r['current_size'] && 0 == $r['current_number'] && ($oStorage = BxDolStorage::getObjectInstance($r['object'])))
  747. $oStorage->changeStorageEngine($oAlert->aExtras['value']);
  748. }
  749. }
  750. public function serviceGetOptionsProfileBot()
  751. {
  752. $aResult = array(
  753. array('key' => '', 'value' => _t('_Select_one'))
  754. );
  755. $aAccountsIds = BxDolAccountQuery::getInstance()->getOperators();
  756. foreach($aAccountsIds as $iAccountId) {
  757. $aProfilesIds = BxDolAccount::getInstance($iAccountId)->getProfilesIds(true, false);
  758. foreach($aProfilesIds as $iProfileId) {
  759. $oProfile = BxDolProfile::getInstance($iProfileId);
  760. $aResult[] = array(
  761. 'key' => $iProfileId,
  762. 'value' => _t('_sys_profile_with_type', $oProfile->getDisplayName(), $oProfile->getModule()),
  763. );
  764. }
  765. }
  766. return $aResult;
  767. }
  768. public function serviceGetOptionsModuleListForPrivacySelector()
  769. {
  770. $aResult = array();
  771. $BxDolModuleQuery = BxDolModuleQuery::getInstance();
  772. $aModules = $BxDolModuleQuery->getModulesBy(array('type' => 'modules', 'active' => 1));
  773. foreach($aModules as $aModule){
  774. $oModule = BxDolModule::getInstance($aModule['name']);
  775. if($oModule instanceof iBxDolContentInfoService){
  776. if (!BxDolRequest::serviceExists($aModule['name'], 'act_as_profile'))
  777. continue;
  778. $aResult[$aModule['name']] = $aModule['title'];
  779. }
  780. }
  781. return $aResult;
  782. }
  783. public function serviceGetOptionsEmbedDefault()
  784. {
  785. $aResults = array(
  786. '' => _t('_None')
  787. );
  788. $aObjects = BxDolEmbedQuery::getObjects();
  789. foreach($aObjects as $aObject)
  790. $aResults[$aObject['object']] = $aObject['title'];
  791. return $aResults;
  792. }
  793. public function serviceGetOptionsLocationFieldDefault()
  794. {
  795. $aResults = array();
  796. $aObjects = BxDolLocationFieldQuery::getObjects();
  797. foreach($aObjects as $aObject)
  798. $aResults[$aObject['object']] = _t($aObject['title']);
  799. return $aResults;
  800. }
  801. public function serviceGetOptionsLocationMapDefault()
  802. {
  803. $aResults = array();
  804. $aObjects = BxDolLocationMapQuery::getObjects();
  805. foreach($aObjects as $aObject)
  806. $aResults[$aObject['object']] = _t($aObject['title']);
  807. return $aResults;
  808. }
  809. public function serviceGetOptionsLocationLeafletGetProviders()
  810. {
  811. return BxDolLocationMapLeaflet::getProviders();
  812. }
  813. public function serviceGetOptionsRelations()
  814. {
  815. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1));
  816. $aProfiles = array();
  817. foreach($aModules as $aModule) {
  818. $sMethod = 'act_as_profile';
  819. if(!BxDolRequest::serviceExists($aModule['name'], $sMethod) || !BxDolService::call($aModule['name'], $sMethod))
  820. continue;
  821. $aProfiles[$aModule['name']] = _t('_' . $aModule['name']);
  822. }
  823. $aResults = array();
  824. foreach($aProfiles as $sName1 => $sTitle1)
  825. foreach($aProfiles as $sName2 => $sTitle2)
  826. $aResults[$sName1 . '_' . $sName2] = $sTitle1 . ' - ' . $sTitle2;
  827. return $aResults;
  828. }
  829. public function serviceGetBadge($aBadge, $bIsCompact = false)
  830. {
  831. $sClass = '';
  832. $sStyleFont = '';
  833. $sStyleBg = '';
  834. if ($aBadge['color'] == '')
  835. $aBadge['color'] = '#ff0000';
  836. if ($aBadge['fontcolor'] == '')
  837. $aBadge['fontcolor'] = '#ffffff';
  838. if ($bIsCompact){
  839. $aBadge['is_icon_only'] = 1;
  840. $sClass .= ' bx-badge-compact-to';
  841. $sStyleFont = 'color: ' . $aBadge['color'];
  842. }
  843. else{
  844. $sStyleBg = 'background-color: ' . $aBadge['color'] . '; color: ' . $aBadge['fontcolor'];
  845. }
  846. if ($aBadge['is_icon_only'] == 1){
  847. $sClass .= ' bx-badge-compact';
  848. }
  849. return BxDolTemplate::getInstance()->parseHtmlByName('badge.html', array(
  850. 'bx_if:content' => array(
  851. 'condition' => $aBadge['is_icon_only'] != '1',
  852. 'content' => array('content' => _t($aBadge['text'])),
  853. ),
  854. 'bx_if:icon' => array(
  855. 'condition' => $aBadge['icon'] != '',
  856. 'content' => array('content' => BxDolTemplate::getInstance()->getIcon($aBadge['icon'], array('class' => 'bx-badge-icon sys-colored', 'style' => $sStyleFont))),
  857. ),
  858. 'title' => $aBadge['text'],
  859. 'style_font' => $sStyleFont,
  860. 'style_bg' => $sStyleBg,
  861. 'class' => $sClass,
  862. )
  863. );
  864. }
  865. private function _getSearchObject()
  866. {
  867. $sClass = 'BxTemplSearch';
  868. $sElsName = 'bx_elasticsearch';
  869. $sElsMethod = 'is_configured';
  870. if(BxDolRequest::serviceExists($sElsName, $sElsMethod) && BxDolService::call($sElsName, $sElsMethod) && !bx_get('cat') && !bx_get('type')) {
  871. $oModule = BxDolModule::getInstance($sElsName);
  872. bx_import('Search', $oModule->_aModule);
  873. $sClass = 'BxElsSearch';
  874. }
  875. bx_alert('system', 'search_keyword', 0, 0, array('class' => &$sClass));
  876. $oSearch = new $sClass(bx_get('section'));
  877. $oSearch->setLiveSearch(bx_get('live_search') ? 1 : 0);
  878. $oSearch->setMetaType(bx_process_input(bx_get('type')));
  879. $oSearch->setCategoryObject(bx_process_input(bx_get('cat')));
  880. return $oSearch;
  881. }
  882. }
  883. /** @} */