You are here

function _syntaxhighlighter_setup_autoloader_script in Syntax Highlighter 6.2

Same name and namespace in other branches
  1. 8 syntaxhighlighter.module \_syntaxhighlighter_setup_autoloader_script()
  2. 6 syntaxhighlighter.module \_syntaxhighlighter_setup_autoloader_script()
  3. 7.2 syntaxhighlighter.module \_syntaxhighlighter_setup_autoloader_script()
  4. 7 syntaxhighlighter.module \_syntaxhighlighter_setup_autoloader_script()

Create the autoload setup script file. Must call this whenever lib location and/or the enable brushes change. Make sure never call this if the js lib is not found

1 call to _syntaxhighlighter_setup_autoloader_script()
_syntaxhighlighter_get_lib_location in ./syntaxhighlighter.module
1 string reference to '_syntaxhighlighter_setup_autoloader_script'
syntaxhighlighter_settings_form in ./syntaxhighlighter.admin.inc
An admin form to specify which language to support for highlighting

File

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

Code

function _syntaxhighlighter_setup_autoloader_script() {
  $path = file_directory_path() . '/syntaxhighlighter.autoloader.js';
  if (variable_get('syntaxhighlighter_use_autoloader', FALSE)) {

    // use variable_get() instead of _syntaxhighlighter_get_lib_location()
    // because this function is only if the lib location is found
    $script_path = base_path() . variable_get('syntaxhighlighter_lib_location', NULL) . '/scripts/';
    $script_data = <<<HEREHERE
/*
 * This file is generated by the Syntaxhighlighter module
 */
HEREHERE;
    $script_data .= "\nfunction syntaxhighlighterAutoloaderSetup() {\n  SyntaxHighlighter.autoloader(\n";
    $need_ending = FALSE;
    $brushes = variable_get('syntaxhighlighter_enabled_languages', array(
      'shBrushPhp.js',
    ));
    foreach ($brushes as $b) {
      if ($b) {
        if ($need_ending) {
          $script_data .= ",\n";
        }
        $alias = strtolower(substr(substr($b, 7), 0, -3));
        $script_data .= "    '{$alias} {$script_path}{$b}'";
        $need_ending = TRUE;
      }
    }
    $script_data .= "\n);\n}\n";
    file_save_data($script_data, $path, FILE_EXISTS_REPLACE);
  }
  else {
    file_delete($path);
  }
}