~isagalaev/+junk/highlight

261 by maniac
Передвижение всего исходного стаффа в src
1
<?php
2
/*
3
Plugin Name: highlight.js
4
Plugin URI: http://softwaremaniacs.org/soft/highlight/
5
Description: Syntax highlighting with language autodetection
342 by Ivan Sagalaev
Version 5.8
6
Version: 5.8
261 by maniac
Передвижение всего исходного стаффа в src
7
Author: Ivan Sagalaev
8
Author URI: http://softwaremaniacs.org/about/
9
*/
10
11
add_option('hljs_languages', '');
307 by Ivan Sagalaev
Replacing literal / with DIRECTORY_SEPARATOR in WP plugin
12
$components = explode(DIRECTORY_SEPARATOR, dirname(__FILE__));
261 by maniac
Передвижение всего исходного стаффа в src
13
$l = sizeof($components);
14
$script_path = get_settings('home') . '/' . $components[$l - 3] . '/' . $components[$l - 2] . '/' . $components[$l - 1];
15
if (!get_option('hljs_script_path')) {
263 by maniac
Новое дефолтное имя скрипта в плагине WP
16
  add_option('hljs_script_path', $script_path . '/highlight.pack.js');
261 by maniac
Передвижение всего исходного стаффа в src
17
}
18
if (!get_option('hljs_css_path')) {
19
  add_option('hljs_css_path', $script_path . '/styles/default.css');
20
}
21
add_option('hljs_css', '');
22
23
function 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>
280 by Maniac
Версия 5.0
35
<?php
261 by maniac
Передвижение всего исходного стаффа в src
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
}
49
add_action('wp_head', 'init_highlighting_on_load');
50
51
function 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
}
56
add_action('admin_menu', 'add_hljs_subpanel');
57
58
function 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>
280 by Maniac
Версия 5.0
69
261 by maniac
Передвижение всего исходного стаффа в src
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>
280 by Maniac
Версия 5.0
75
261 by maniac
Передвижение всего исходного стаффа в src
76
    <div>
289 by Maniac
"Path to highlight.pack.js" в плагине WP
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>
261 by maniac
Передвижение всего исходного стаффа в src
78
      <p><small>Let's you place the script in a convenient place</small></p>
79
    </div>
280 by Maniac
Версия 5.0
80
261 by maniac
Передвижение всего исходного стаффа в src
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>
280 by Maniac
Версия 5.0
85
261 by maniac
Передвижение всего исходного стаффа в src
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>
280 by Maniac
Версия 5.0
92
261 by maniac
Передвижение всего исходного стаффа в src
93
    <div class="submit">
94
      <input type="submit" name="info_update" value="Update options »" />
95
    </div>
96
  </form>
97
</div><?php
98
99
}
100
?>