class RocketChat in Rocket.Chat 7
Same name and namespace in other branches
- 7.2 src/RocketChat.class.inc \RocketChat\RocketChat
Class RocketChat.
Created by PhpStorm. User: Sysosmaster Date: 02/01/17 Time: 15:19.
@package RocketChat
Hierarchy
- class \RocketChat\RocketChat
Expanded class hierarchy of RocketChat
2 files declare their use of RocketChat
- rocket_chat.module in ./
rocket_chat.module - Rocket.Chat Livechat Module.
- rocket_chat.test in ./
rocket_chat.test
6 string references to 'RocketChat'
- RocketChatTestUnitTest::pathFalseTest in ./
rocket_chat.test - RocketChatTestUnitTest::pathTrueTest in ./
rocket_chat.test - RocketChatTestUnitTest::setUp in ./
rocket_chat.test - Set up the test environment.
- rocket_chat_admin_page in ./
rocket_chat.module - Admin Page Render.
- rocket_chat_help in ./
rocket_chat.module - Implements hook_help().
File
- ./
RocketChat.class.inc, line 14
Namespace
RocketChatView source
class RocketChat {
/**
* Check if path is in the config to render this element on.
*
* @param array $paths
* Array of Paths to show the Widget on.
* @param string $target
* The current Path to check for.
*
* @return bool True if this target should have the widget, false if not.
* True if this target should have the widget, false if not.
*/
public static function checkIfTargetIsRocketChatPath(array &$paths, $target) {
if (empty($target)) {
watchdog("Rocket.Chat", "No page restriction, showing on all pages.", array(), WATCHDOG_DEBUG);
return TRUE;
}
$path = drupal_strtolower(drupal_get_path_alias($target));
$pages = implode(PHP_EOL, $paths);
// Compare the lowercase internal and lowercase path alias (if any).
$page_match = drupal_match_path($path, $pages);
if ($path != $_GET['q']) {
$page_match = $page_match || drupal_match_path($_GET['q'], $pages);
}
return $page_match;
}
/**
* Implements hook_page_alter().
*
* @param $page
* Current Render array for this Page.
*/
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;
}
/**
* Renders the Admin page.
*
* @return array
* The Structured Drupal Render Array for this Admin page.
*/
public static function renderAdminPage() {
$form['rocket_chat_url'] = array(
'#type' => 'textfield',
'#title' => t('Rocket.Chat Server'),
'#default_value' => variable_get('rocket_chat_url', "http://localhost"),
'#size' => 64,
'#maxlength' => 128,
'#description' => t("The URL of the Rocket.Chat server."),
'#required' => TRUE,
);
$form['rocket_chat_route'] = array(
'#type' => 'textarea',
'#title' => t('Paths to show the chat widget on.'),
'#default_value' => variable_get('rocket_chat_route', ""),
'#cols' => 20,
'#rows' => 15,
'#description' => t("use '<front>' to signify the front page. clear this field to make it show on all pages."),
'#required' => FALSE,
);
return system_settings_form($form);
}
/**
* Implements hook_help().
* @see \hook_help()
* @param $path
* Path to render on.
* @param $arg
* Arguments in this path
* @return string
*/
public static function renderHelpPage(&$path, &$arg) {
$arguments = $arg;
$output = array();
$extensions = array();
switch ($path) {
case 'admin/config/services/rocket_chat':
$output[] = <<<settingsPageHelp
Here you set the Settings for the Rocket.Chat module.<br>
<ul>
<li>In the <mark>Rocket.Chat Server</mark> setting you put the base Rocket.Chat url you use to contact the Rocket,chat server.</li>
<li>In the <mark>Paths to show the chat widget on</mark>. you put the drupal url's to show the widget on. With the following Special cases:
<ul>
<li>Leave the Textfield empty, this will make the widget show on all pages.</li>
<li>use the special '<front>' to specify the front page, so the widget is shown on the front page.</li>
<li>use a '*' at the end of an URL to signify all Url's below a certain path. like 'node/*' to make the widget shown on all nodes.</li>
</ul>
</li>
</ul>
settingsPageHelp;
break;
case 'admin/help#rocket_chat':
$output[] = <<<helpPage
<h1 id="_rocket-chat_-module-for-drupal-7-"><em>Rocket.Chat</em> Module for Drupal 7.</h1>
<h2 id="introduction">INTRODUCTION</h2>
<p>The Rocket.Chat Module enables a drupal site to integrate Rocket.Chat.<br>it is currently in its <strong><em>7.x-1.0</em></strong> release.
The following Features of rocket chat are imiplemented. </p>
<ul>
<li>A page with the <a href="@rocketchat-livechat">Livechat</a> widget.
This widget offer you the ability to communicate with
your website 'guests'.</li>
</ul>
<h2 id="requirements">Requirements</h2>
<p>This module is designed for:</p>
<ul>
<li><a href="@drupal">Drupal 7.35+</a></li>
<li><a href="@rocketchat">Rocket.Chat 0.48.1+</a></li>
</ul>
<p>It is tested with:</p>
<ul>
<li>Drupal 7.35</li>
<li>Rocket.Chat 0.48.1</li>
</ul>
<p>It needs the following Rocket.Chat modules enabled and configured.</p>
<ul>
<li>Livechat</li>
</ul>
<h2 id="recommendations">Recommendations</h2>
<p>We strongly recommand you run your Drupal and your Rocket.Chat behind a TLS/SSL proxy or webserver.
Currently it will only work when both the website and the webapp are in the same type of connection.
(so the drupal and Rocket.Chat are both reachable either over HTTP or HTTPS not one with HTTP and the other with HTTPS)</p>
<p>Furthermre we recommand you configure the Livechat to use Agents, and have some agents in the User mangement section of Livechat.</p>
<h2 id="installation">Installation</h2>
<ul>
<li>Install the module in your modules folder, then clear cache</li>
<li>Submit installation on your website configuration, clear cache</li>
<li>Switch to [web-site-url]/admin/config/services/rocket_chat and fill the config form,
then clear cache (one more time)</li>
<li>Visit [web-site-url]/[path-chosen] then the widget will appear </li>
</ul>
<h2 id="configuration">Configuration</h2>
<p>in the Configuration of the module (located under the 'Web services' in the configuration tab.)
you set the address of the Rocket.Chat server and the Patch on the drupal where the widget is enabled.</p>
<h2 id="troubleshooting">Troubleshooting</h2>
<p>Leave a detailed report of your issue in the <a href="@drupal-issue">issue queue</a> and the maintainers will add it to the task list.</p>
<h2 id="maintainers">Maintainers</h2>
<ul>
<li><a href="@gabriel">Gabriel Engel</a> (Creator Rocket.Chat)</li>
<li><a href="@idevit">idevit</a> (Community Plumbing)</li>
<li><a href="@sysosmaster">sysosmaster</a> (Original Module creator)</li>
</ul>
helpPage;
$extensions['@drupal'] = 'https://www.drupal.org/project/drupal';
$extensions['@drupal-issue'] = 'https://www.drupal.org/project/issues/search/2649818';
$extensions['@rocketchat'] = 'https://rocket.chat';
$extensions['@rocketchat-livechat'] = 'https://rocket.chat/docs/administrator-guides/livechat';
$extensions['@gabriel'] = 'https://www.drupal.org/u/gabriel-engel';
$extensions['@idevit'] = 'https://www.drupal.org/u/idevit';
$extensions['@sysosmaster'] = 'https://www.drupal.org/u/sysosmaster';
break;
}
$ret = "";
foreach ($output as $line) {
$ret .= '<p>' . t($line, $extensions) . '</p>';
}
return $ret;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RocketChat:: |
public static | function | Check if path is in the config to render this element on. | |
RocketChat:: |
public static | function | Implements hook_page_alter(). | |
RocketChat:: |
public static | function | Renders the Admin page. | |
RocketChat:: |
public static | function | Implements hook_help(). |