Skip to content

Instantly share code, notes, and snippets.

@jasoncomes
Last active August 3, 2018 22:33
Show Gist options
  • Save jasoncomes/654f9cfa3b82487f24641dd58069d647 to your computer and use it in GitHub Desktop.
Save jasoncomes/654f9cfa3b82487f24641dd58069d647 to your computer and use it in GitHub Desktop.

SSR Widget Setup

Sites

accreditedschoolsonline.org
{PUBLISHER} = accreditedschoolsonline.org
{PARAMS} = &backgroundColor=%232dade4&cta=FIND%20ONLINE%20COLLEGES&ctaColor=%23fe3d00&height=325&title=FIND%20PROGRAMS&titleColor=%23363636
affordablecollegesonline.org
{PUBLISHER} = affordablecollegesonline.org
{PARAMS} = &backgroundColor=%23ffffff&cta=SEE%20AFFORDABLE%20SCHOOLS&ctaColor=%23fe3d00&height=325&title=FIND%20PROGRAMS&titleColor=%233299a9

Setup

Add he_ssr_platform_js function to site for global usage throughout templates/partials.

<?php

/**
 * SSR Platform Widget Request
 */
function he_ssr_platform_js($url, $publisher) 
{
    // Publisher required, fail otherwise.
    if (empty($publisher)) { 
        throw new \Exception('No publisher domain provided'); 
    }
    // Query params.
    $qsa = http_build_query([
        'publisher' => $publisher, 
        'url'       => 'https://www.' . $publisher . $_SERVER['REQUEST_URI']
    ]);
    $url = strpos($url, '?') === false ? "{$url}?{$qsa}" : "{$url}&{$qsa}";
    // Curl
    $ch = curl_init($url);
    
    if ($ch) {
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $js = curl_exec($ch);
        curl_close($ch);
        return $js;
    }
    
    return false;
}

?>

Replace Widget Markup in partials/templates.

<?php

echo he_ssr_platform_js(
    'https://platform.highereducation.com/widgets.html?widget=ssr-qdf{PARAMS}', 
    {PUBLISHER}
); 

?>

When replacing the Widget markup, keep in mind the only styles you'll need to keep from the previous widget are the widgets positioning/location styles or you may even stick the widget inside the parent widget container that controls the positioning/location of the widget. e.g. affordablecollegesonline.org

<div id="mob_widget_popup" class="" style="min-height: 572px;">

<?php

echo he_ssr_platform_js(
    'https://platform.highereducation.com/widgets.html?widget=ssr-qdf&backgroundColor=%23ffffff&cta=SEE%20AFFORDABLE%20SCHOOLS&ctaColor=%23fe3d00&height=325&title=FIND%20PROGRAMS&titleColor=%233299a9', 
    affordablecollegesonline.org
); 

?>

</div>

Cleanup.

Feel free to remove any and all widget styles/js that are no longer needed to cleanup theme. Replacing the form may cause existing JS functionality to fail if events are attached to the existing widget.

@jasoncomes
Copy link
Author

accreditedschoolsonline.org

screen shot 2018-06-15 at 1 01 22 pm

@jasoncomes
Copy link
Author

affordablecollegesonline.org

screen shot 2018-06-15 at 1 03 39 pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment