BuildUrl.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. namespace ModulesGarden\Servers\ZimbraEmail\Core\Helper;
  3. use \ModulesGarden\Servers\ZimbraEmail\Core\ServiceLocator;
  4. use \ModulesGarden\Servers\ZimbraEmail\Core\App\Controllers\Instances\Addon\Config;
  5. /**
  6. * Description of BuildUrl
  7. *
  8. * @author Rafał Ossowski <rafal.os@modulesgarden.com>
  9. */
  10. class BuildUrl
  11. {
  12. public static function getUrl($controller = null, $action = null, array $params = [], $isFullUrl = true)
  13. {
  14. if (isAdmin())
  15. {
  16. $url = 'addonmodules.php?module=' . getModuleName();
  17. }
  18. else
  19. {
  20. $url = 'clientarea.php?action=productdetails&id=' . di('request')->get('id');
  21. }
  22. if ($controller)
  23. {
  24. $url .= '&mg-page=' . $controller;
  25. if ($action)
  26. {
  27. $url .= '&mg-action=' . $action;
  28. }
  29. if ($params)
  30. {
  31. $url .= '&' . http_build_query($params);
  32. }
  33. }
  34. if ($isFullUrl)
  35. {
  36. $baseUrl = self::baseUrl();
  37. $url = $baseUrl . $url;
  38. }
  39. return $url;
  40. }
  41. public static function getBaseUrl()
  42. {
  43. return self::baseUrl();
  44. }
  45. public static function getNewUrl($protocol = 'http', $host = 'modulesgarden.com', $params = [])
  46. {
  47. $url = "{$protocol}://{$host}";
  48. if ($params)
  49. {
  50. $url .= '?' . http_build_query($params);
  51. }
  52. return $url;
  53. }
  54. public static function getAppAssetsURL()
  55. {
  56. return self::getAssetsURL(true);
  57. }
  58. public static function getAssetsURL($isApp = false)
  59. {
  60. $addon = ServiceLocator::call(Config::class);
  61. $name = $addon->getConfigValue('systemName');
  62. $template = $addon->getConfigValue('template', 'default');
  63. if (isAdmin())
  64. {
  65. return $isApp ? '../modules/' . self::getType() . '/' . $name . '/app/UI/Admin/Templates/assets'
  66. : '../modules/' . self::getType() . '/' . $name . '/templates/admin/assets';
  67. }
  68. return $isApp ? 'modules/' . self::getType() . '/' . $name . '/app/UI/Client/Templates/assets'
  69. : 'modules/' . self::getType() . '/' . $name . '/templates/client/' . $template . '/assets';
  70. }
  71. public static function isCustomIntegrationCss()
  72. {
  73. $modulePath = \ModulesGarden\Servers\ZimbraEmail\Core\ModuleConstants::getFullPath();
  74. $integrationPath = $modulePath . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'UI' . DIRECTORY_SEPARATOR
  75. . (isAdmin() ? 'Admin' : 'Client') . DIRECTORY_SEPARATOR . 'Templates' . DIRECTORY_SEPARATOR . 'assets'
  76. . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . 'integration.css';
  77. return file_exists($integrationPath);
  78. }
  79. public static function isCustomModuleCss()
  80. {
  81. $modulePath = \ModulesGarden\Servers\ZimbraEmail\Core\ModuleConstants::getFullPath();
  82. $integrationPath = $modulePath . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'UI' . DIRECTORY_SEPARATOR
  83. . (isAdmin() ? 'Admin' : 'Client') . DIRECTORY_SEPARATOR . 'Templates' . DIRECTORY_SEPARATOR . 'assets'
  84. . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . 'module_styles.css';
  85. return file_exists($integrationPath);
  86. }
  87. public static function getType()
  88. {
  89. if (strpos(trim(self::class, '\\'), 'ModulesGarden\Servers') === 0)
  90. {
  91. return 'servers';
  92. }
  93. return 'addons';
  94. }
  95. private static function baseUrl()
  96. {
  97. $protocol = 'https';
  98. if (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on')
  99. {
  100. $protocol = 'http';
  101. }
  102. $host = $_SERVER['HTTP_HOST'];
  103. $surfix = $_SERVER['PHP_SELF'];
  104. $surfix = explode('/', $surfix);
  105. array_pop($surfix);
  106. $surfix = implode('/', $surfix);
  107. return "{$protocol}://{$host}{$surfix}/";
  108. }
  109. }