You are here

function _ckeditor_codemirror_get_version in CKEditor CodeMirror 8

Same name and namespace in other branches
  1. 8.2 ckeditor_codemirror.install \_ckeditor_codemirror_get_version()

Gets the version information for the ckeditor_codemirror library.

Return value

string A string containing the version of the library or empty if the version cannot be found.

2 calls to _ckeditor_codemirror_get_version()
CkeditorCodeMirrorBasicTest::testCheckStatusReportPage in tests/src/Functional/CkeditorCodeMirrorBasicTest.php
Check the library status on "Status report" page.
ckeditor_codemirror_requirements in ./ckeditor_codemirror.install
Implements hook_requirements().

File

./ckeditor_codemirror.install, line 53
Install, update and uninstall functions for the CKEditor CodeMirror module.

Code

function _ckeditor_codemirror_get_version() {

  // Provide defaults.
  $options = [
    'file' => 'plugin.js',
    'pattern' => '@version:\\s*\'?([0-9a-zA-Z\\.-]+)\'?@',
    'lines' => 20,
    'cols' => 200,
  ];
  $version = '';
  $library_path = _ckeditor_codemirror_get_library_path();
  $file = DRUPAL_ROOT . '/' . $library_path . '/codemirror/' . $options['file'];
  if (!empty($options['file']) && file_exists($file)) {
    $file = fopen($file, 'r');
    while ($options['lines'] && ($line = fgets($file, $options['cols']))) {
      if (preg_match($options['pattern'], $line, $version)) {
        break;
      }
      $options['lines']--;
    }
    fclose($file);
  }
  return $version[1];
}