RegistrarDNSHelper.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace MGModule\DNSManager2\mgLibs\custom\helpers;
  3. use \MGModule\DNSManager2 as main;
  4. class RegistrarDNSHelper
  5. {
  6. /**
  7. * This function is used to enable DNS Mamagement section in client area section
  8. * @return type
  9. */
  10. public static function prepareRegisrtrar()
  11. {
  12. //if we are not in domain details or in available actions function needs to be terminated
  13. if(!self::paresUrl())
  14. {
  15. return;
  16. }
  17. //when in "general option" section Domain ID needs to be taken from $_GET['id']
  18. $domainId = (int)$_GET['id'];
  19. if(empty($domainId))
  20. {
  21. //when showing DNS Records Domain ID needs to be taken from $_GET['domainid']
  22. $domainId = (int)$_GET['domainid'];
  23. }
  24. //when "save DNS" action is called Domain ID needs to be taken from $_POST['domainid']
  25. if(empty($domainId))
  26. {
  27. $domainId = (int)$_POST['domainid'];
  28. }
  29. if(empty($domainId))
  30. {
  31. return;
  32. }
  33. try
  34. {
  35. main\addon::I(true);
  36. $registrarHelper = new main\mgLibs\custom\dns\utils\CustomDnsRegistrarHelper($domainId);
  37. if(!$registrarHelper->isPackageActive())
  38. {
  39. return;
  40. }
  41. $file = $registrarHelper->creatreFunctionsFile(str_replace(
  42. DS.'mgLibs'.DS.'custom'.DS.'helpers','', realpath(dirname(__FILE__))));
  43. if(!file_exists($file))
  44. {
  45. throw new \Exception(
  46. $file.' '.
  47. main\mgLibs\lang::T('not found').'.'
  48. );
  49. }
  50. require_once($file);
  51. }
  52. catch(Exception $ex)
  53. {
  54. main\addon::dump($ex);
  55. logModuleCall(
  56. 'DNS Manager', __FUNCTION__, $ex->getMessage(), $ex->getMessage(), $ex->getTraceAsString()
  57. );
  58. }
  59. }
  60. /**
  61. * Function is used to parse URL address and detect if user is in avaialbe action section<Br />
  62. * What daoe it mean means it allow to run run action only when Domain ID is avaialble
  63. */
  64. public static function paresUrl()
  65. {
  66. $availableActions = array(
  67. 'domaindetails',
  68. 'domaindns'
  69. );
  70. global $CONFIG;
  71. $host = parse_url($CONFIG['SystemURL'])['host'];
  72. $url = "http" . (($_SERVER['SERVER_PORT'] == 443) ? "s://" : "://") . $host . $_SERVER['REQUEST_URI'];
  73. $urlDetails = parse_url($url);
  74. foreach ($urlDetails as $key)
  75. {
  76. foreach ($availableActions as $action)
  77. {
  78. preg_match("/$action/", $key, $match);
  79. if (isset($match[0]))
  80. {
  81. return true;
  82. }
  83. }
  84. }
  85. return false;
  86. }
  87. }