Skip to content

Commit

Permalink
Merge pull request #271 from drupalprojects/7.x-3.x--bootswatch-https
Browse files Browse the repository at this point in the history
#270, #247: Trying http if https fails on Bootswatch API url
  • Loading branch information
soniktrooth committed Jun 1, 2016
2 parents 258b2a4 + 3811597 commit 1da221b
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions includes/utils.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/

// Constants
define('KALATHEME_BOOTSWATCH_API', 'https://bootswatch.com/api/3.json');
define('KALATHEME_BOOTSWATCH_API_URI', 'bootswatch.com/api/3.json');
define('KALATHEME_BOOTSWATCH_API', 'https://' . KALATHEME_BOOTSWATCH_API_URI);

// Use Libraries intregration if applicable
if (kalatheme_use_libraries()) {
Expand Down Expand Up @@ -147,9 +148,9 @@ function kalatheme_prepare_config_form(&$form) {
// Provide needed ajax wrappers
$form['actions']['submit']['#prefix'] = "<div id='kala-submit-change-title'>";
$form['actions']['submit']['#suffix'] = "</div>";

// Add custom submit and validate functions to handle custom bootstrap
// libraries. Note that because of https://www.drupal.org/node/943212 it's
// libraries. Note that because of https://www.drupal.org/node/943212 it's
// possible for this function to end up getting called before #submit exists.
if (isset($form['#submit'])) {
if (!in_array('kalatheme_custom_bootstrap_library_submit', $form['#submit'])) {
Expand All @@ -167,11 +168,11 @@ function kalatheme_prepare_config_form(&$form) {
else {
$form['#submit'][] = 'kalatheme_custom_bootstrap_library_submit';
}

if (!isset($form['#validate']) || isset($form['#validate']) && !in_array('kalatheme_custom_bootstrap_library_validate', $form['#validate'])) {
$form['#validate'][] = 'kalatheme_custom_bootstrap_library_validate';
}

return $form;
}

Expand Down Expand Up @@ -265,6 +266,10 @@ function kalatheme_get_bootswatch_themes() {
// Grab Bootstwatches from API or Drupal Cache
if (($bootswatches = cache_get('kalatheme:bootswatches', 'cache')) === FALSE) {
$bootswatch_info = drupal_http_request(KALATHEME_BOOTSWATCH_API);
if (!$bootswatch_info || $bootswatch_info->code != 200) {
// Sometimes https fails so lets try http instead.
$bootswatch_info = drupal_http_request('http://' . KALATHEME_BOOTSWATCH_API_URI);
}
if ($bootswatch_info && $bootswatch_info->code == 200) {
$data = json_decode($bootswatch_info->data);
if (isset($data->themes) && is_array($data->themes)) {
Expand Down Expand Up @@ -348,7 +353,7 @@ function kalatheme_backend_check() {
/**
* Check whether Kalatheme has write access to libraries and modules directories.
*
* This check indicates whether we have enough access to be able to use
* This check indicates whether we have enough access to be able to use
* authorize.php and the updater.
*
* @return boolean
Expand Down

0 comments on commit 1da221b

Please sign in to comment.