1<?php
2/*
3Plugin Name: highlight.js
4Plugin URI: http://softwaremaniacs.org/soft/highlight/
5Description: Syntax highlighting with language autodetection
6Version: 5.7
7Author: Ivan Sagalaev
8Author URI: http://softwaremaniacs.org/about/
9*/
10
11add_option('hljs_languages', '');
12$components = explode(DIRECTORY_SEPARATOR, dirname(__FILE__));
13$l = sizeof($components);
14$script_path = get_settings('home') . '/' . $components[$l - 3] . '/' . $components[$l - 2] . '/' . $components[$l - 1];
15if (!get_option('hljs_script_path')) {
16  add_option('hljs_script_path', $script_path . '/highlight.pack.js');
17}
18if (!get_option('hljs_css_path')) {
19  add_option('hljs_css_path', $script_path . '/styles/default.css');
20}
21add_option('hljs_css', '');
22
23function init_highlighting_on_load() {
24  $languages_str = get_option('hljs_languages');
25  if ($languages_str) {
26    $languages = explode(',', $languages_str);
27    foreach ($languages as $i => $language) {
28      $languages[$i] = '\'' . trim($language) . '\'';
29    }
30    $languages_str = implode(', ', $languages);
31  }
32  ?>
33<script type="text/javascript" src="<?php echo get_option('hljs_script_path');?>"></script>
34<script type="text/javascript">hljs.initHighlightingOnLoad(<?php echo $languages_str; ?>);</script>
35<?php
36  $css_path = get_option('hljs_css_path');
37  if ($css_path) {?>
38<link rel="stylesheet" href="<?php echo $css_path ?>" />
39<?php
40  }
41  $css = get_option('hljs_css');
42  if ($css) {?>
43<style type="text/css">
44<?php echo $css ?>
45</style>
46<?php
47  }
48}
49add_action('wp_head', 'init_highlighting_on_load');
50
51function add_hljs_subpanel() {
52  if (function_exists('add_options_page')) {
53    add_options_page('highlight.js options', 'highlight.js', 'manage_options', __FILE__, 'hljs_subpanel');
54  }
55}
56add_action('admin_menu', 'add_hljs_subpanel');
57
58function hljs_subpanel() {
59  if (isset($_POST['hljs_script_path'])) {
60    update_option('hljs_languages', $_POST['hljs_languages']);
61    update_option('hljs_script_path', $_POST['hljs_script_path']);
62    update_option('hljs_css_path', $_POST['hljs_css_path']);
63    update_option('hljs_css', $_POST['hljs_css']);
64    ?><div class="updated"><p><strong>Options updated.</strong></p></div><?php
65	} ?>
66<div class="wrap">
67  <form method="post">
68    <h2>highlight.js options</h2>
69
70    <div>
71      <p><label for="id_hljs_languages">Highlight Languages:</label> <input type="text" name="hljs_languages" id="id_hljs_languages" value="<?php echo get_option('hljs_languages'); ?>" /></p>
72      <p><small>List here languages that you want to highlight on your blog like this: php, html, css. Empty string means "all known languages". For the list
73      of supported languages refer to <a href="http://softwaremaniacs.org/soft/highlight/">highlight.js homepage</a>.</small></p>
74    </div>
75
76    <div>
77      <p><label for="id_hljs_script_path">Path to highlight.pack.js:</label> <input type="text" name="hljs_script_path" id="id_hljs_script_path" value="<?php echo get_option('hljs_script_path'); ?>" /></p>
78      <p><small>Let's you place the script in a convenient place</small></p>
79    </div>
80
81    <div>
82      <p><label for="id_hljs_css_path">Path to CSS (if any):</label> <input type="text" name="hljs_css_path" id="id_hljs_css_path" value="<?php echo get_option('hljs_css_path'); ?>" /></p>
83      <p><small>You can choose one of the bundled style files or leave it empty</small></p>
84    </div>
85
86    <div>
87      <p><label for="id_hljs_css">Custom CSS:</label></p>
88      <p><textarea name="hljs_css" id="id_hljs_css" rows="20" cols="70"><?php echo get_option('hljs_css'); ?></textarea></p>
89      <p><small>Normally styling of code snippets goes into site's main CSS files. But you can
90      write it here if you can't access site's CSS or just like it this way.</small></p>
91    </div>
92
93    <div class="submit">
94      <input type="submit" name="info_update" value="Update options »" />
95    </div>
96  </form>
97</div><?php
98
99}
100?>
101