charts_highstock-1.0.x-dev/charts_highstock.install

charts_highstock.install
<?php

/**
 * @file
 * Installation and update hooks for the Charts Highstock module.
 */

/**
 * Implements hook_requirements().
 */
function charts_highstock_requirements($phase) {
  $requirements = [];

  switch ($phase) {
    case 'runtime':
      $library_path = charts_highstock_find_library();
      $config = \Drupal::service('config.factory')->getEditable('charts.settings');
      $cdn = $config->get('advanced.requirements.cdn') ?? FALSE;

      if (!$library_path) {
        if ($cdn) {
          $requirements['charts_highstock_js'] = [
            'title' => t('Highstock Library'),
            'value' => t('Available through a CDN'),
            'severity' => REQUIREMENT_WARNING,
            'description' => t('You are using the Highstock library via a content delivery network. It is generally considered better practice to install the library files locally. Please see the README file inside charts_highstock for instructions to install the library.'),
          ];
        }
        else {
          $requirements['charts_highstock_js'] = [
            'title' => t('Highstock Library'),
            'value' => t('Not Installed'),
            'severity' => REQUIREMENT_ERROR,
            'description' => t('You are missing the Highstock library in your Drupal installation directory and you have opted not to use a CDN. Please either enable use of the CDN in the Chart Settings under the Advanced tab or see the README file inside charts_highstock for instructions to install the library.'),
          ];
        }
      }
      else {
        $requirements['charts_highstock_js'] = [
          'title' => t('Highstock Library'),
          'value' => t('Installed'),
          'severity' => REQUIREMENT_OK,
          'description' => t('You have installed the Chart.js library in your Drupal installation directory.'),
        ];
      }
      break;
  }

  if (function_exists('libraries_detect') && $highstock_info = libraries_detect('highstock')) {
    if (is_dir($highstock_info['library path'] . '/js/exporting-server')) {
      $requirements['charts_highstock_js'] = [
        'title' => t('Highstock vulnerability'),
        'severity' => REQUIREMENT_ERROR,
        'value' => t('Dangerous sample code present'),
        'description' => t('Your installation of the Highstock library at "@path" contains a directory named "exporting-server". This directory contains dangerous sample files that may compromise the security of your site. You must delete this directory before you may use the Charts Highstock module.', ['@path' => $highstock_info['library path']]),
      ];
    }
  }

  return $requirements;
}

/**
 * Get the location of the Highstock library.
 *
 * @return string
 *   The location of the library, or FALSE if the library isn't installed.
 */

function charts_highstock_find_library() {
  // The following logic is taken from libraries_get_libraries()
  $searchdir = [];

  // Similar to 'modules' and 'themes' directories inside an installation
  // profile, installation profiles may want to place libraries into a
  // 'libraries' directory.
  $searchdir[] = 'profiles/' . \Drupal::installProfile() . '/libraries';

  // Always search libraries.
  $searchdir[] = 'libraries';

  // Also search sites/<domain>/*.
  $container = \Drupal::getContainer();
  $site_path = $container->getParameter('site.path');
  $site_path = explode('/', $site_path);
  $site_name = $site_path[1];
  $searchdir[] = $site_name . '/libraries';

  foreach ($searchdir as $dir) {
    if (file_exists($dir . '/highstock/highstock.js')) {
      return $dir . '/highstock';
    }
  }

  return FALSE;
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc