You are here

function _syntaxhighlighter_scan_lib_location in Syntax Highlighter 7

Same name and namespace in other branches
  1. 6.2 syntaxhighlighter.module \_syntaxhighlighter_scan_lib_location()
  2. 6 syntaxhighlighter.module \_syntaxhighlighter_scan_lib_location()
  3. 7.2 syntaxhighlighter.module \_syntaxhighlighter_scan_lib_location()

Do an exhaustive scan of file directories for the location of the syntaxhighlighter js lib, Allow the syntaxhighlighter js library to be installed in any of the following locations and under any sub-directory (except 'src'): 1) syntaxhighlighter module directory 2) sites/<site_domain>/files (whereever the file_directory_path() is) 3) sites/all/libraries 4) the install profile libraries directory

Return value

the file location of the js lib or NULL if not found

1 call to _syntaxhighlighter_scan_lib_location()
_syntaxhighlighter_get_lib_location in ./syntaxhighlighter.module

File

./syntaxhighlighter.module, line 362
Syntax highlight code using the Syntaxhighlighter javascript library. See http://alexgorbatchev.com/wiki/SyntaxHighlighter

Code

function _syntaxhighlighter_scan_lib_location() {
  $directories = array(
    drupal_get_path('module', 'syntaxhighlighter'),
    _syntaxhighlighter_file_directory_path(),
    'sites/all/libraries',
  );

  // When this function is called during Drupal's initial installation process,
  // the name of the profile that is about to be installed is stored in the
  // global $profile variable. At all other times, the regular system variable
  // contains the name of the current profile, and we can call variable_get()
  // to determine the profile.
  global $profile;
  if (!isset($profile)) {
    $profile = variable_get('install_profile', 'default');
  }
  $directories[] = "profiles/{$profile}/libraries";
  foreach ($directories as $d) {

    // note: file_scan_directory() returns a empty array if no file is found
    // in which case the foreach loop is not enter
    foreach (file_scan_directory($d, '/shCore\\.js$/', array(
      'nomask' => '/(\\.\\.?|CVS|src|pupload)$/',
    )) as $filename => $file_info) {

      // the path to syntaxhighlighter lib, (-18 to chop off "/scripts/shCore.js"
      // part at the end
      return substr($filename, 0, -18);
    }
  }
  return NULL;
}