View source
<?php
namespace RocketChat;
class RocketChat {
public static function checkIfTargetIsRocketChatPath(array &$paths, $target) {
if (empty($target)) {
watchdog("Rocket.Chat", "No page restriction, showing on all" . " pages.", WATCHDOG_DEBUG);
return TRUE;
}
$path = drupal_strtolower(drupal_get_path_alias($target));
$pages = implode(PHP_EOL, $paths);
$page_match = drupal_match_path($path, $pages);
if ($path != $_GET['q']) {
$page_match = $page_match || drupal_match_path($_GET['q'], $pages);
}
return $page_match;
}
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)) {
$version = variable_get('rocket_chat_livechat_version', "1.0.0");
$url = variable_get('rocket_chat_url', "http://localhost");
$javascript = LiveChat::getLivechatJavascript($url, $version);
drupal_add_js($javascript, array(
'type' => 'inline',
'scope' => 'footer',
'weight' => 0,
));
}
return $page;
}
public static function renderAdminPage() {
$form['rocket_chat_url'] = array(
'#type' => 'textfield',
'#title' => t('Rocket.Chat Server'),
'#default_value' => variable_get('rocket_chat_url', "https://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,
);
$form['rocket_chat_livechat_version'] = array(
'#type' => 'select',
'#title' => t('LiveChat widget version.'),
'#default_value' => variable_get('rocket_chat_livechat_version', "1.0.0"),
'#options' => array(
"1.0.0" => "Version 1.0.0",
"legacy" => "Legacy version",
),
'#description' => t("Version of the Livechat widget to load"),
'#required' => TRUE,
);
return system_settings_form($form);
}
public static function renderHelpPage(&$path, &$arg) {
$arguments = $arg;
$output = array();
$extensions = array();
switch ($path) {
case 'admin/config/services/rocket_chat':
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</a></li>
<li><a href="@rocketchat">Rocket.Chat</a></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>To use Rocket.Chat on the internet use a TLS (HTTPS) connection. See
<a href="@drupalHttps">Drupal Documentation HTTPS</a> and <a
href="rockechatHttps">Rocket.Chat Documentation HTTPS</a>
Respectively for instructions on the how.<br>
HTTP setups are not recommended and not supported by the maintainers.
For how to use Livechat see the <a href="@rocketchatLivechatDocs">Rocket.Chat Livechat Documentations</a>
<h2 id="installation">Installation</h2>
<ul>
<li>Go to
<a href="@rocketchatConfig">[web-site-url]/admin/config/services/rocket_chat</a>
and fill the config form,</li>
<li>Visit [web-site-url]/[path-chosen] then the widget will appear </li>
<li>If its not there Clear the caches and reload the page, the widget should now
appear.</li>
</ul>
<h2 id="configuration">Configuration</h2>
<p>in the Configuration of the module (located under the 'Web services' in the
configuration tab.)<br>
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 one of the maintainers will add it
to the task list.</p>
<h2 id="maintainers">Maintainers</h2>
<ul>
<li><a href="@sysosmaster">Sysosmaster</a> (Original Module creator)</li>
<li><a href="@idevit">idevit</a> (Community Plumbing)</li>
<li><a href="@gabriel">Gabriel Engel</a> (Creator Rocket.Chat)</li>
</ul>
helpPage;
$extensions['@drupal'] = 'https://www.drupal.org/project/drupal';
$extensions['@drupal-issue'] = 'https://www.drupal.org/project/issues/' . 'search/2649818';
$extensions['@drupalHttps'] = 'https://www.drupal.org/https-information';
$extensions['@rocketHttps'] = 'https://rocket.chat/docs/installation/' . 'manual-installation/configuring-ssl-reverse-proxy';
$extensions['@rocketchat'] = 'https://rocket.chat';
$extensions['@rocketchat-livechat'] = 'https://rocket.chat/docs/' . 'administrator-guides/livechat';
$extensions['@rocketchatLivechatDocs'] = 'https://rocket.chat/docs/' . 'administrator-guides/livechat';
$extensions['@rocketchatConfig'] = '/admin/config/services/rocket_chat';
$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;
}
}