BxBaseServices.php 41 KB

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