You are here

class RocketChat in Rocket.Chat 7.2

Same name and namespace in other branches
  1. 7 RocketChat.class.inc \RocketChat\RocketChat

Class RocketChat.

Created by PhpStorm. User: Sysosmaster Date: 02/01/17 Time: 15:19.

@package RocketChat

Hierarchy

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
3 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.

File

src/RocketChat.class.inc, line 14

Namespace

RocketChat
View 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.", 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)) {
      $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;
  }

  /**
   * 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', "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 '&lt;front&gt;' 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);
  }

  /**
   * 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 &#39;guests&#39;.</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 &#39;Web services&#39; 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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RocketChat::checkIfTargetIsRocketChatPath public static function Check if path is in the config to render this element on.
RocketChat::hookPageAlter public static function Implements hook_page_alter().
RocketChat::renderAdminPage public static function Renders the Admin page.<
RocketChat::renderHelpPage public static function Implements hook_help().