You are here

private static function ShareaholicPublic::js_snippet in Share Buttons, Related Posts, Content Analytics - Shareaholic 8

Same name and namespace in other branches
  1. 7.3 public.php \ShareaholicPublic::js_snippet()

The actual text for the JS snippet because drupal doesn't seem to be able to add JS from template like Wordpress does... Using heredocs for now

Return value

string JS block for shareaholic code

1 call to ShareaholicPublic::js_snippet()
ShareaholicPublic::insert_script_tag in ./public.php
Inserts the script code snippet into the head of the public pages of the site if they have accepted ToS and have apikey

File

./public.php, line 45

Class

ShareaholicPublic
This class is all about drawing the stuff in publishers' templates that visitors can see.

Code

private static function js_snippet() {
  $api_key = ShareaholicUtilities::get_option('api_key');
  $js_url = ShareaholicUtilities::asset_url('assets/pub/shareaholic.js');
  $base_settings = json_encode(ShareaholicPublicJS::get_base_settings());
  $overrides = ShareaholicPublicJS::get_overrides();
  $js_snippet = <<<DOC
<!-- Growth powered by Shareaholic - https://www.shareaholic.com -->
<link rel='preload' href='{<span class="php-variable">$js_url</span>}' as='script'>
<script data-cfasync='false'>
  //<![CDATA[
    _SHR_SETTINGS = {<span class="php-variable">$base_settings</span>};
  //]]>
</script>
<script
  data-cfasync='false'
  src='{<span class="php-variable">$js_url</span>}'
  data-shr-siteid='{<span class="php-variable">$api_key</span>}'
  async {<span class="php-variable">$overrides</span>}>
</script>
DOC;
  return $js_snippet;
}