Projet

Général

Profil

Paste
Télécharger (3,06 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / highlightjs / highlight_js.module @ c8740e19

1
<?php
2

    
3
/**
4
 * @file
5
 * Provides the Highlight JS library.
6
 *
7
 * @author Juned Kazi
8
 */
9

    
10
/**
11
 * Implements hook_libraries_info().
12
 */
13
function highlight_js_libraries_info() {
14
  $libraries['highlightjs'] = array(
15
    'name' => 'highlightjs',
16
    'vendor url' => 'http://highlightjs.org/',
17
    'download url' => 'http://highlightjs.org/download/',
18
    'version' => '8.0',
19
    'files' => array(
20
      'js' => array(
21
        'highlight.pack.js',
22
      ),
23
      'css' => array(
24
        'styles/default.css',
25
      ),
26
    ),
27
  );
28
  return $libraries;
29
}
30

    
31
/**
32
 * Implementation of hook_menu().
33
 */
34
function highlight_js_menu() {
35
  $items['admin/config/user-interface/highlightjs'] = array(
36
    'title' => 'Highlight JS',
37
    'description' => 'Configure settings for Highlight js styles.',
38
    'access arguments' => array('administer highlight js'),
39
    'page callback' => 'drupal_get_form',
40
    'page arguments' => array('highlight_js_settings'),
41
  );
42
  return $items;
43
}
44

    
45
/**
46
 * Implementation of hook_perm().
47
 */
48
function highlight_js_permission() {
49
  return array(
50
    'administer highlight js' => array(
51
      'title' => t('Administer Highlight JS'),
52
      'description' => t('Configure the default highlight js style.')
53
    )
54
  );
55
}
56

    
57
/**
58
 * Settings form for module filter.
59
 */
60
function highlight_js_settings() {
61
  $options = highlight_js_list_themes();
62
  $form['highlightjs_style'] = array(
63
    '#type' => 'select',
64
    '#title' => t('Highlight JS default style'),
65
    '#default_value' => variable_get('highlightjs_style', 'default'),
66
    '#description' => t('Select the default code style format. Please refer to the !url page for a live demo of all the styles.',
67
                        array('!url' => l('Demo', 'http://highlightjs.org/static/test.html'))),
68
    '#options' => $options,
69
  );
70
  return system_settings_form($form);
71
}
72

    
73
/**
74
 * List the available themes.
75
 */
76
function highlight_js_list_themes() {
77
  static $themes;
78

    
79
  if (isset($themes)) {
80
    return $themes;
81
  }
82
  $themes = array();
83
  if (module_exists('libraries')) {
84
    $directory = libraries_get_path('highlightjs') . '/styles/';
85
    if (!empty($directory)) {
86
      $files = file_scan_directory($directory, '/.*\.css$/', array('key' => 'name'));
87
      foreach ($files as $key => $fileinfo) {
88
        $themes[drupal_strtolower($key)] = drupal_ucfirst($key);
89
      }
90
      natcasesort($themes);
91
    }
92
  }
93
  return $themes;
94
}
95

    
96
/**
97
 * Implements hook_init().
98
 */
99
function highlight_js_init() {
100
  if (($library = libraries_load('highlightjs')) && !empty($library['loaded'])) {
101

    
102
    // Load the highlight js to trigger the library function
103
    drupal_add_js(drupal_get_path('module', 'highlight_js') . '/highlight_js.js');
104
    // Loading it as CSS_THEME to override the default style css properties
105
    drupal_add_css(drupal_get_path('module', 'highlight_js') . '/highlight_js.css', array('group' => CSS_THEME, 'type' => 'file'));
106

    
107
    if (variable_get('highlightjs_style', 'default') != 'default') {
108
      drupal_add_css($library['library path'] . '/styles/' . variable_get('highlightjs_style', 'default') . '.css', array('group' => CSS_THEME, 'type' => 'file'));
109
    }
110
  }
111
}
112