omega_tools.admin.inc 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?php
  2. /**
  3. * @todo
  4. */
  5. function omega_tools_theme_reset_confirm($form, &$form_state, $theme) {
  6. $themes = list_themes();
  7. $form_state['theme'] = $theme;
  8. return confirm_form($form,
  9. t('Are you sure you want to reset the theme %name?', array('%name' => $themes[$theme]->info['name'])),
  10. 'admin/appearance/settings/' . $theme,
  11. t('<p>You are about to purge the theme settings stored in the database for this theme.</p><p>This will revert to whatever information is set in the .info file, and erase any un-exported customizations.</p>'),
  12. t('Reset'),
  13. t('Cancel')
  14. );
  15. }
  16. /**
  17. * @todo
  18. */
  19. function omega_tools_theme_reset_confirm_submit($form, &$form_state) {
  20. $themes = list_themes();
  21. $theme = $form_state['theme'];
  22. omega_tools_revert_theme_settings($theme);
  23. $form_state['redirect'] = 'admin/appearance/settings/' . $theme;
  24. }
  25. /**
  26. * @todo
  27. */
  28. function omega_tools_theme_download($subtheme) {
  29. file_download('temporary', file_uri_target(omega_tools_write_archive(drupal_get_path('theme', $subtheme), $subtheme)));
  30. }
  31. /**
  32. * @todo
  33. */
  34. function omega_tools_theme_export($form, &$form_state, $theme) {
  35. $form_state['theme'] = $theme;
  36. $info = drupal_parse_info_file(drupal_get_path('theme', $theme) . '/' . $theme . '.info');
  37. $settings = isset($info['settings']) ? $info['settings'] : array();
  38. $settings = variable_get('theme_' . $theme . '_settings', $settings);
  39. $editable = _omega_tools_is_editable($theme);
  40. $form['settings'] = array(
  41. '#type' => 'textarea',
  42. '#title' => t('Theme settings'),
  43. '#description' => $editable ? t('You may now edit the theme settings before proceeding with the export and eventually saving them to the .info file of your theme. The theme settings provided in this form will be written into the .info file of the %name theme. All settings that are currently present in that file will be overwritten.', array('%name' => $info['name'])) : t("This theme is not editable and therefore you won't be able to export the theme settings automatically."),
  44. '#default_value' => omega_tools_build_info_file($settings, 'settings'),
  45. '#rows' => 30,
  46. '#element_validate' => array('_omega_tools_validate_theme_settings'),
  47. );
  48. $form['revert'] = array(
  49. '#type' => 'checkbox',
  50. '#title' => t('Revert theme settings'),
  51. '#description' => t('This will purge the theme settings from the database after exporting them to the .info file of this theme.'),
  52. '#default_value' => TRUE,
  53. '#access' => $editable,
  54. );
  55. $form['actions']['#type'] = 'actions';
  56. $form['actions']['submit'] = array(
  57. '#type' => 'submit',
  58. '#value' => t('Export'),
  59. '#access' => $editable,
  60. );
  61. $form['actions']['cancel'] = array(
  62. '#markup' => l(t('Cancel'), 'admin/appearance/settings/' . $theme),
  63. );
  64. return $form;
  65. }
  66. /**
  67. * @todo
  68. */
  69. function omega_tools_theme_export_submit($form, &$form_state) {
  70. $theme = $form_state['theme'];
  71. $info = drupal_parse_info_file(drupal_get_path('theme', $theme) . '/' . $theme . '.info');
  72. unset($info['settings']);
  73. omega_tools_write_info_file($theme, array_merge($info, drupal_parse_info_format($form_state['values']['settings'])));
  74. watchdog('theme', t('Theme settings for %theme exported and saved to .info file.', array('%theme' => $info['name'])));
  75. drupal_set_message(t('The theme settings for %theme have been exported and saved to the corresponding .info file.', array('%theme' => $info['name'])));
  76. if ($form_state['values']['revert']) {
  77. omega_tools_revert_theme_settings($theme);
  78. }
  79. $form_state['redirect'] = 'admin/appearance/settings/' . $theme;
  80. }
  81. /**
  82. * @todo
  83. */
  84. function omega_tools_subtheme_add($form, &$form_state) {
  85. system_rebuild_theme_data();
  86. $themes = omega_tools_base_themes();
  87. $starterkits = array();
  88. if (!empty($themes)) {
  89. $base = isset($form_state['values']['base']) ? $form_state['values']['base'] : 'omega';
  90. $starterkits = omega_tools_starterkits($base);
  91. $starter = isset($form_state['values']['starterkit']) ? $form_state['values']['starterkit'] : key($starterkits);
  92. $starter = !empty($starter) ? $starter : '_none';
  93. }
  94. $form['info'] = array(
  95. '#type' => 'fieldset',
  96. '#title' => t('Theme information'),
  97. );
  98. $form['info']['name'] = array(
  99. '#type' => 'textfield',
  100. '#title' => t('Name'),
  101. '#description' => t('The human-readable name for this theme.'),
  102. '#default_value' => isset($form_state['values']['name']) ? $form_state['values']['name'] : '',
  103. '#size' => 30,
  104. '#required' => TRUE,
  105. );
  106. $form['info']['machine_name'] = array(
  107. '#type' => 'machine_name',
  108. '#default_value' => isset($form_state['values']['machine_name']) ? $form_state['values']['machine_name'] : '',
  109. '#maxlength' => 30,
  110. '#machine_name' => array(
  111. 'source' => array('info', 'name'),
  112. ),
  113. '#element_validate' => array('_omega_tools_validate_theme_name'),
  114. );
  115. $form['info']['automated'] = array(
  116. '#type' => 'checkbox',
  117. '#title' => t('Install automatically'),
  118. '#description' => t('Please select wether you want to install this theme manually or if it should be automatically placed in the selected destination. This feature requires you to have write permission for the selected destination.'),
  119. '#default_value' => TRUE,
  120. '#element_validate' => array('omega_tools_subtheme_validate_automation'),
  121. );
  122. $form['info']['destination'] = array(
  123. '#type' => 'select',
  124. '#title' => t('Destination'),
  125. '#description' => t('The theme will be place in the path selected here.'),
  126. '#options' => omega_tools_sites_options(),
  127. '#default_value' => 'all',
  128. '#states' => array(
  129. 'visible' => array(
  130. ':input[name="automated"]' => array('checked' => TRUE),
  131. ),
  132. ),
  133. );
  134. $form['info']['base'] = array(
  135. '#type' => 'select',
  136. '#title' => t('Base theme'),
  137. '#description' => t('The base theme for this theme.'),
  138. '#options' => $themes,
  139. '#default_value' => $base,
  140. '#ajax' => array(
  141. 'callback' => '_omega_tools_starterkit_options_callback',
  142. 'wrapper' => 'starterkit-options-wrapper',
  143. 'method' => 'replace',
  144. 'effect' => 'fade',
  145. ),
  146. );
  147. $form['info']['starterkit_wrapper'] = array(
  148. '#prefix' => '<div id="starterkit-options-wrapper">',
  149. '#suffix' => '</div>',
  150. );
  151. $form['info']['starterkit_wrapper']['starterkit'] = array(
  152. '#type' => 'radios',
  153. '#title' => t('Starterkit'),
  154. '#options' => array('_none' => t('Proceed without using a starterkit') . '<div class="description">' . t('This is not recommended.') . '</div>') + $starterkits,
  155. '#description' => t('Starterkits simplify the process of creating new subthemes by providing a set of pre-defined files and settings. Choose wisely!'),
  156. '#default_value' => $starter,
  157. '#access' => !empty($starterkits),
  158. );
  159. $form['actions']['#type'] = 'actions';
  160. $form['actions']['submit'] = array(
  161. '#type' => 'submit',
  162. '#value' => t('Save and continue'),
  163. );
  164. return $form;
  165. }
  166. /**
  167. * @todo
  168. */
  169. function _omega_tools_starterkit_options_callback($form, $form_state) {
  170. return $form['info']['starterkit_wrapper'];
  171. }
  172. /**
  173. * @todo
  174. */
  175. function omega_tools_subtheme_validate_automation($element, $form_state) {
  176. $path = 'sites/' . $form_state['values']['destination'] . '/themes';
  177. if ($element['#value'] == TRUE && !file_prepare_directory($path, NULL)) {
  178. form_error($element, t('The destination that you selected is not writable. Please choose a different destination, or select the manual installation method.'));
  179. }
  180. }
  181. /**
  182. * @todo
  183. */
  184. function omega_tools_subtheme_add_submit($form, &$form_state) {
  185. $values = $form_state['values'];
  186. $subtheme = new stdClass;
  187. $subtheme->new = TRUE;
  188. $subtheme->name = $values['name'];
  189. $subtheme->machine_name = $values['machine_name'];
  190. $subtheme->starterkit = isset($values['starterkit']) && $values['starterkit'] != '_none' ? $values['starterkit'] : NULL;
  191. $subtheme->base = $values['base'];
  192. $subtheme->status = FALSE;
  193. $subtheme->default = FALSE;
  194. $subtheme->automated = $values['automated'];
  195. $subtheme->destination = $values['automated'] ? 'sites/' . $values['destination'] . '/themes/' . $subtheme->machine_name : NULL;
  196. $subtheme->path = 'temporary://omega-tools/' . $subtheme->machine_name . '-' . substr(hash('sha256', serialize($subtheme) . microtime()), 0, 8);
  197. if (omega_tools_subtheme_create($subtheme)) {
  198. omega_tools_cache_set($subtheme->machine_name, $subtheme);
  199. $form_state['redirect'] = 'admin/appearance/omega-tools/edit/' . $subtheme->machine_name;
  200. }
  201. }