charts-8.x-4.x-dev/modules/charts_highcharts/charts_highcharts.install

modules/charts_highcharts/charts_highcharts.install
<?php

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

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

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

      if (!$library_path) {
        if ($cdn) {
          $requirements['charts_highcharts_js'] = [
            'title' => t('Highcharts Library'),
            'value' => t('Available through a CDN'),
            'severity' => REQUIREMENT_WARNING,
            'description' => t('You are using the Highcharts 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_highcharts for instructions to install the library.'),
          ];
        }
        else {
          $requirements['charts_highcharts_js'] = [
            'title' => t('Highcharts Library'),
            'value' => t('Not Installed'),
            'severity' => REQUIREMENT_ERROR,
            'description' => t('You are missing the Highcharts 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_highcharts for instructions to install the library.'),
          ];
        }
      }
      else {
        $requirements['charts_highcharts_js'] = [
          'title' => t('Highcharts Library'),
          'value' => t('Installed'),
          'severity' => REQUIREMENT_OK,
          'description' => t('You have installed the Highcharts.js library in your Drupal installation directory.'),
        ];
      }
      break;
  }

  if (function_exists('libraries_detect') && $highcharts_info = libraries_detect('highcharts')) {
    if (is_dir($highcharts_info['library path'] . '/js/exporting-server')) {
      $requirements['charts_highcharts_js'] = [
        'title' => t('Highcharts vulnerability'),
        'severity' => REQUIREMENT_ERROR,
        'value' => t('Dangerous sample code present'),
        'description' => t('Your installation of the Highcharts 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 Highcharts module.', ['@path' => $highcharts_info['library path']]),
      ];
    }
  }

  return $requirements;
}

/**
 * Get the location of the Highcharts library.
 *
 * @return string
 *   The location of the library, or FALSE if the library isn't installed.
 */
function charts_highcharts_find_library() {
  // The following logic is taken from libraries_get_libraries()
  $search_dir = [];

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

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

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

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

  return FALSE;
}

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

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