Skip to content

Instantly share code, notes, and snippets.

@amcgowanca
Created December 14, 2015 10:49
Show Gist options
  • Save amcgowanca/c716759dfe38f43d3df6 to your computer and use it in GitHub Desktop.
Save amcgowanca/c716759dfe38f43d3df6 to your computer and use it in GitHub Desktop.
Preprocess field and replace HTTP with HTTPs for Sched.org schedules
<?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