Created
December 14, 2015 10:49
-
-
Save amcgowanca/c716759dfe38f43d3df6 to your computer and use it in GitHub Desktop.
Preprocess field and replace HTTP with HTTPs for Sched.org schedules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_preprocess_field(). | |
*/ | |
function HOOK_preprocess_field(&$variables) { | |
if ('field_FIELDNAME' == $variables['element']['#field_name'] && isset($GLOBALS['is_https']) && $GLOBALS['is_https']) { | |
if (!empty($variables['items'])) { | |
foreach (element_children($variables['items']) as $delta) { | |
if (!empty($variables['items'][$delta]['#markup'])) { | |
$matches = array(); | |
if (preg_match_all('/((https?:\/\/)?([a-z0-9\.-]+)(.sched.org\/js\/embed.js))/i', $variables['items'][$delta]['#markup'], $matches)) { | |
if (!empty($matches[0])) { | |
$replacement = str_replace('http://', 'https://', $matches[0]); | |
$variables['items'][$delta]['#markup'] = str_replace($matches[0], $replacement, $variables['items'][$delta]['#markup']); | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment