acquia.profile 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. // == Acuquia branding =========================================================
  3. /**
  4. * Implements hook_init().
  5. */
  6. function acquia_init() {
  7. global $conf;
  8. // Use this early opportunity to brand the install/runtime experience.
  9. // Once the generic theme settings are saved, or a custom theme's settings
  10. // are saved to override it, this will not be effective anymore, which is
  11. // intended.
  12. if (empty($conf['theme_settings'])) {
  13. $conf['theme_settings'] = array(
  14. 'default_logo' => 0,
  15. // Default to different logos depending on whether Drupal is installed or not.
  16. 'logo_path' => empty($conf['site_name']) ? 'profiles/acquia/AcquiaDrupalLogoInstaller.png' : 'profiles/acquia/AcquiaDrupalLogo.png',
  17. );
  18. }
  19. }
  20. /**
  21. * Implements hook_install_tasks_alter().
  22. */
  23. function acquia_install_tasks_alter(&$tasks, $install_state) {
  24. // Preselect the English language, so users can skip the language selection
  25. // form. We do not ship other languages with Acquia Drupal at this point.
  26. if (!isset($_GET['locale'])) {
  27. $_POST['locale'] = 'en';
  28. }
  29. }
  30. // == Configuration UI =========================================================
  31. /**
  32. * Implements hook_form_FORM_ID_alter().
  33. *
  34. * Allows the profile to alter the site configuration form.
  35. */
  36. function acquia_form_install_configure_form_alter(&$form, $form_state) {
  37. // Pre-populate the site name with the server name.
  38. $form['site_information']['site_name']['#default_value'] = $_SERVER['SERVER_NAME'];
  39. $form['site_information']['acquia_identifier'] = array(
  40. '#title' => st('Acquia subscription identifier'),
  41. '#description' => st('If you have an <a href="@url">Acquia Network subscription</a>, please enter the subscription identifier. You can also provide it later at Administer > Configuration > Acquia Network settings.', array('@url' => 'http://network.acquia.com/network/dashboard/subscription')),
  42. '#type' => 'textfield',
  43. '#required' => FALSE,
  44. );
  45. $form['site_information']['acquia_key'] = array(
  46. '#title' => st('Acquia subscription key'),
  47. '#description' => st('If you have an <a href="@url">Acquia Network subscription</a>, please enter the subscription key. You can also provide it later at Administer > Configuration > Acquia Network settings.', array('@url' => 'http://network.acquia.com/network/dashboard/subscription')),
  48. '#type' => 'textfield',
  49. '#required' => FALSE,
  50. );
  51. // Add both existing submit function and our submit function,
  52. // since adding just ours cancels the automated discovery of the original.
  53. $form['#validate'] = array('acquia_configure_form_validate', 'install_configure_form_validate');
  54. $form['#submit'] = array('acquia_configure_form_submit', 'install_configure_form_submit');
  55. }
  56. /**
  57. * Custom validation handler for Acquia Drupal install.
  58. */
  59. function acquia_configure_form_validate($form, &$form_state) {
  60. // Check credentials only if they provided.
  61. $form_state['values']['acquia_identifier'] = trim($form_state['values']['acquia_identifier']);
  62. $form_state['values']['acquia_key'] = trim($form_state['values']['acquia_key']);
  63. if (!empty($form_state['values']['acquia_identifier']) && !empty($form_state['values']['acquia_key'])) {
  64. if (!acquia_agent_valid_credentials($form_state['values']['acquia_identifier'], $form_state['values']['acquia_key'], acquia_agent_settings('acquia_network_address'))) {
  65. form_error($form, acquia_agent_connection_error_message());
  66. }
  67. }
  68. }
  69. /**
  70. * Custom submission handler for Acquia Drupal install.
  71. */
  72. function acquia_configure_form_submit($form, &$form_state) {
  73. variable_set('acquia_identifier', $form_state['values']['acquia_identifier']);
  74. variable_set('acquia_key', $form_state['values']['acquia_key']);
  75. }
  76. // == Automated install tasks ==================================================
  77. /**
  78. * Implements hook_install_tasks().
  79. */
  80. function acquia_install_tasks($install_state) {
  81. return array(
  82. // Just a hidden task callback.
  83. 'acquia_profile_setup' => array(),
  84. );
  85. }
  86. /**
  87. * Installer task callback.
  88. */
  89. function acquia_profile_setup() {
  90. global $language;
  91. // Add a node describing how to get started with Acquia Drupal
  92. $welcome_file = 'profiles/acquia/' . $language->language . '/welcome.txt';
  93. if (!file_exists($welcome_file)) {
  94. drupal_set_message(t('Could not find file @filepath.', array('@filepath' => $welcome_file)), 'error');
  95. $welcome_file = 'profiles/acquia/en/welcome.txt';
  96. }
  97. if ($welcome_node = _acquia_profile_create_node($welcome_file, 'page')) {
  98. node_save($welcome_node);
  99. variable_set('acquia_welcome', $welcome_node->nid);
  100. }
  101. else {
  102. drupal_set_message(t('The file @filepath could not be read. The welcome message will not be generated.', array('@filepath' => $welcome_file)), 'error');
  103. }
  104. }
  105. /**
  106. * Creates a node from the specified filename.
  107. *
  108. * The node body will contain the contents of the file. All relative links must
  109. * be identified within the file so they can be mapped to paths appropriate for
  110. * the installation.
  111. *
  112. * The relative links are identified in the file by surrounding the actual
  113. * link with double square brackets. For example:
  114. *
  115. * <a href="[[admin]]">Admin page</a>
  116. *
  117. * @param $filename
  118. * The name of the file to retrieve the text from.
  119. * @param $page_type
  120. * The type of node to create.
  121. */
  122. function _acquia_profile_create_node($filename, $page_type) {
  123. $contents = trim(file_get_contents($filename));
  124. if (!$contents) {
  125. return null;
  126. }
  127. // Grab the title from the document and then remove the title so it
  128. // isn't shown in the title and the body. The title will be encoded
  129. // in the document in the following form:
  130. // <h1 [class="..."]>{TITLE}</h1>
  131. $title_regexp = "/[\<]h1(\s*[^=\>]*=\"[^\"]*\")*\s*[\>](.*)\<\/h1\>/i";
  132. if (preg_match($title_regexp, $contents, $match)) {
  133. $title = $match[count($match) - 1];
  134. // Remove the title from the body of the document.
  135. $contents = preg_replace($title_regexp, '', $contents);
  136. }
  137. // Replace all local links with the full path.
  138. $link_regexp = "/(\[\[)([\/?\w+\-*]+)(\]\])/";
  139. $contents = preg_replace_callback($link_regexp, '_acquia_profile_url', $contents);
  140. $node = new stdClass();
  141. $node->title = $title;
  142. $node->body['und'][0]['value'] = $contents;
  143. $node->body['und'][0]['summary'] = $contents;
  144. $node->body['und'][0]['format'] = 'full_html';
  145. $node->uid = 1;
  146. $node->type = $page_type;
  147. $node->status = 1;
  148. $node->promote = 1;
  149. return $node;
  150. }
  151. /**
  152. * Helper function for preg_replace_callback()
  153. *
  154. * Calls url() on matched element 2.
  155. *
  156. * @param $matches
  157. * The array of regex matches.
  158. *
  159. * @return string
  160. * The local url.
  161. */
  162. function _acquia_profile_url($matches) {
  163. $options = array();
  164. $options['alias'] = TRUE;
  165. return check_url(url($matches[2], $options));
  166. }