Source for file host.php

Documentation is available at host.php

  1. <?php
  2. class midgard_admin_sitewizard_host {
  3.  
  4. var $_host;
  5. var $_empty_style;
  6. var $_attachment_page;
  7. var $_sitegroup;
  8. var $name;
  9. var $port;
  10. var $prefix;
  11. var $root;
  12. var $owner;
  13. var $style;
  14. function midgard_admin_sitewizard_host($id = false, $sitegroup = 0) {
  15. if ($id) {
  16. $this->_host = mgd_get_host($id);
  17. } else {
  18. $this->_host = false;
  19. }
  20. $this->_empty_style = mgd_get_object_by_guid("3c92dd79d80e88fce424a324e1096580");
  21. $this->_attachment_page = mgd_get_object_by_guid('a93523b8d13b1190fc562ffdabe08f44');
  22.  
  23. if ($sitegroup) {
  24. $this->_sitegroup = mgd_get_sitegroup($sitegroup);
  25. $this->owner = $sitegroup->admingroup;
  26. } else {
  27. $this->_sitegroup = 0;
  28. $this->owner = 0;
  29. }
  30. $this->name = "";
  31. $this->port = 0;
  32. $this->prefix = "";
  33. $this->root = null;
  34. $this->style = $this->_empty_style->id;
  35. }
  36. function create() {
  37. $this->_get_template_settings();
  38. $host = mgd_get_host();
  39. $host->name = $this->name;
  40. $host->port = $this->port;
  41. $host->prefix = $this->prefix;
  42. $host->owner = $this->owner;
  43. $host->style = $this->style;
  44. $host->root = $this->root;
  45. $host->online = true;
  46. $host->auth = false;
  47. if ($this->_check_against_overlap()) {
  48. $host_created = $host->create();
  49. if ($host_created) {
  50. $host = mgd_get_host($host_created);
  51. if ($this->_sitegroup != $_MIDGARD["sitegroup"]) {
  52. $host->setsitegroup($this->_sitegroup->id);
  53. }
  54. $this->_create_attachment_host();
  55. return $host->id;
  56. }
  57. } else {
  58. return false;
  59. }
  60.  
  61. }
  62. function _get_template_settings() {
  63. // Check for settings in the root page
  64. $root_page = mgd_get_page($this->root);
  65.  
  66. // Allow application to define style
  67. // Needed for applications like OpenPSA
  68. $custom_style = $root_page->parameter("midgard.admin.sitewizard","custom_style");
  69. if ($custom_style) {
  70. $style = mgd_get_object_by_guid($custom_style);
  71. $this->style = $style->id;
  72. }
  73. }
  74. function _check_against_overlap() {
  75. $wizard_host = mgd_get_host($_MIDGARD["host"]);
  76. if ($this->name == $wizard_host->name && $this->prefix == $wizard_host->prefix) {
  77. return false;
  78. }
  79. // TODO: check for overlap with other Midgard hosts
  80. return true;
  81. }
  82. function _attachment_host_found() {
  83.  
  84. // Check if attachment host exists
  85. $attachment_host_found = false;
  86. $hosts = mgd_list_hosts();
  87. if ($hosts) {
  88. while ($hosts->fetch()) {
  89. if ($hosts->name == $this->name && $hosts->prefix == "/attachment/".$this->_sitegroup->guid() && ($hosts->port == $this->port || $hosts->port == 0)) {
  90. return true;
  91. }
  92. }
  93. }
  94. return false;
  95. }
  96. function _create_attachment_host() {
  97. if (!$this->_attachment_host_found()) {
  98. // Create Aegir-style attachment host
  99. // TODO: we will eventually be able to switch to Midgard's built-in attachment server
  100. $attachment_host = mgd_get_host();
  101. $attachment_host->name = $this->name;
  102. $attachment_host->port = $this->port;
  103. $attachment_host->prefix = "/attachment/".$this->_sitegroup->guid();
  104. $attachment_host->owner = $this->owner;
  105. $attachment_host->root = $this->_attachment_page->id;
  106. $attachment_host->style = $this->_empty_style->id;
  107. $attachment_host->online = true;
  108. $attachment_host->auth = false;
  109. $attachment_host_created = $attachment_host->create();
  110. if ($attachment_host_created) {
  111. $attachment_host = mgd_get_host($attachment_host_created);
  112.  
  113. if ($this->_sitegroup != $_MIDGARD["sitegroup"]) {
  114. $attachment_host->setsitegroup($this->_sitegroup->id);
  115. }
  116.  
  117. return $attachment_host->id;
  118. }
  119. }
  120. return false;
  121. }
  122.  
  123. }
  124. ?>

Documentation generated on Mon, 21 Nov 2005 18:16:10 +0100 by phpDocumentor 1.3.0RC3