You are here

public static function RocketChat::hookPageAlter in Rocket.Chat 7

Same name and namespace in other branches
  1. 7.2 src/RocketChat.class.inc \RocketChat\RocketChat::hookPageAlter()

Implements hook_page_alter().

Parameters

$page: Current Render array for this Page.

1 call to RocketChat::hookPageAlter()
rocket_chat_page_alter in ./rocket_chat.module
Implements hook_page_alter().

File

./RocketChat.class.inc, line 49

Class

RocketChat
Class RocketChat.

Namespace

RocketChat

Code

public static function hookPageAlter(&$page) {
  $path = request_path();
  $paths_raw = variable_get('rocket_chat_route', "");
  $paths = explode("\r\n", $paths_raw);
  foreach ($paths as $key => $value) {
    if (empty($value)) {
      unset($paths[$key]);
    }
  }
  if (RocketChat::checkIfTargetIsRocketChatPath($paths, $path)) {
    $url = variable_get('rocket_chat_url', "http://localhost");
    $javascript = <<<JAVASCRIPT
(function (\$) {
    'use strict';
    // The embed javascript livechat code.
    (function (w, d, s, u) {
        w.RocketChat = function (c) { w.RocketChat._.push(c); }; w.RocketChat._ = []; w.RocketChat.url = u;
        var h;
        var j;
        h = d.getElementsByTagName(s)[0];
        j = d.createElement(s);
        j.async = true;
        j.src = '{<span class="php-variable">$url</span>}/packages/rocketchat_livechat/assets/rocket-livechat.js';
        h.parentNode.insertBefore(j, h);
    })(window, document, 'script', '{<span class="php-variable">$url</span>}/livechat');
})(jQuery);
JAVASCRIPT;
    drupal_add_js($javascript, array(
      'type' => 'inline',
      'scope' => 'footer',
      'weight' => 0,
    ));
  }
  return $page;
}