@@ -14,7 +14,7 @@ define('DEFAULT_FONTAWESOME_URL', 'http://fontawesome.io/./assets/font-awesome-4
14
14
* Form for kalatheme setup
15
15
*/
16
16
function kalatheme_setup_form () {
17
- require_once DRUPAL_ROOT . ' / ' . drupal_get_path ( ' theme ' , ' kalatheme ' ) . '/includes /utils.inc ' ;
17
+ require_once dirname ( __FILE__ ) . '/utils.inc ' ;
18
18
19
19
if (_kalatheme_backend_check ()) {
20
20
$ form ['backend_check ' ] = array (
@@ -28,7 +28,7 @@ function kalatheme_setup_form() {
28
28
'#prefix ' => '<div class="alert alert-danger"> ' ,
29
29
'#markup ' => t ("If you want Kalatheme to be able to install and enable your subtheme for you please make sure that both @lib_path and @theme_path exist and are writable. Otherwise it will just give you an archive to download. " , array (
30
30
'@lib_path ' => is_dir ('sites/all/libraries ' ) ? 'sites/all/libraries ' : 'sites/all ' ,
31
- '@theme_path ' => drupal_realpath ( substr ( drupal_get_path ( ' theme ' , ' kalatheme ' ), 0 , strrpos ( drupal_get_path ( ' theme ' , ' kalatheme ' ), ' / ' ))) ,
31
+ '@theme_path ' => ' sites/all/themes ' ,
32
32
)),
33
33
'#suffix ' => '</div> ' ,
34
34
);
@@ -178,6 +178,28 @@ function kalatheme_setup_form_validate($form, &$form_state) {
178
178
* @see kalatheme_setup_form_validate()
179
179
*/
180
180
function kalatheme_setup_form_submit ($ form , &$ form_state ) {
181
+ // Build the batch
182
+ $ batch = kalatheme_setup_batch ($ form , $ form_state );
183
+ batch_set ($ batch );
184
+ }
185
+
186
+ /**
187
+ * Form submission handler for kalatheme_setup_form().
188
+ *
189
+ * Uses BATCH API for file processing and HTTP request stuffs
190
+ *
191
+ * Uploads the file attached to the form, then attempts to extract the archive
192
+ * into a temporary location and verify it. Verifies the archive is a valid
193
+ * Bootsrap library and if possible installs the library into the libraries API
194
+ * directory. If not saves it for output to the user.
195
+ *
196
+ * Then builds a subtheme using the name provided and tries to install it. If
197
+ * it cannot it grabs the bootstrap library and outputs both as an archive for
198
+ * the user to install.
199
+ *
200
+ * @see kalatheme_setup_form_validate()
201
+ */
202
+ function kalatheme_setup_batch ($ form , &$ form_state ) {
181
203
// Let's begin to define some opps
182
204
$ operations = array ();
183
205
$ batch = array (
@@ -231,7 +253,8 @@ function kalatheme_setup_form_submit($form, &$form_state) {
231
253
$ operations [] = array ('_kalatheme_dress_you_up ' , array ($ machine_name ));
232
254
// Build the batch and cook it
233
255
$ batch ['operations ' ] = $ operations ;
234
- batch_set ($ batch );
256
+
257
+ return $ batch ;
235
258
}
236
259
237
260
/**
@@ -588,7 +611,7 @@ function _kalatheme_dress_you_up($machine_name, &$context) {
588
611
}
589
612
// Move from temp to legitness or output to the user for DL
590
613
$ booted = TRUE ;
591
- $ theme_path = drupal_realpath (substr ( drupal_get_path ( ' theme ' , ' kalatheme ' ), 0 , strrpos ( drupal_get_path ( ' theme ' , ' kalatheme ' ), ' / ' )) );
614
+ $ theme_path = drupal_realpath (' sites/all/themes ' );
592
615
$ library_path = drupal_realpath ('sites/all/libraries ' );
593
616
$ stuff = array (
594
617
file_directory_temp () . DIRECTORY_SEPARATOR . $ machine_name => $ theme_path . DIRECTORY_SEPARATOR . $ machine_name ,
@@ -700,7 +723,10 @@ function _kalatheme_batch_done($success, $results, $operations) {
700
723
// relevant
701
724
drupal_set_message (t ($ results ['message ' ]), 'warning ' , FALSE );
702
725
}
703
- drupal_goto ('admin/appearance ' );
726
+ // Only redirect if not an install profile
727
+ if (isset ($ GLOBALS ['conf ' ]['install_task ' ]) && $ GLOBALS ['conf ' ]['install_task ' ] === 'done ' ) {
728
+ drupal_goto ('admin/appearance ' );
729
+ }
704
730
}
705
731
706
732
/**
@@ -797,7 +823,7 @@ function _kalatheme_bootstrap_preview($form, &$form_state) {
797
823
* True if all good, message if no good
798
824
*/
799
825
function _kalatheme_backend_check () {
800
- $ theme_dir = drupal_realpath ( substr ( drupal_get_path ( ' theme ' , ' kalatheme ' ), 0 , strrpos ( drupal_get_path ( ' theme ' , ' kalatheme ' ), ' / ' ))) ;
826
+ $ theme_dir = ' sites/all/themes ' ;
801
827
$ libraries_dir = 'sites/all/libraries ' ;
802
828
// Create paths if needed
803
829
// $theme_path should already exist
@@ -810,7 +836,7 @@ function _kalatheme_backend_check() {
810
836
if (!file_prepare_directory ($ libraries_dir ) || !file_prepare_directory ($ theme_dir )) {
811
837
// @todo something
812
838
}
813
- return is_writable (drupal_realpath ($ libraries_dir )) && is_writable ($ theme_dir );
839
+ return is_writable (drupal_realpath ($ libraries_dir )) && is_writable (drupal_realpath ( $ theme_dir) );
814
840
}
815
841
816
842
/**
0 commit comments