SHOW:
|
|
- or go back to the newest paste.
1 | <?php | |
2 | /******************************************************************************* | |
3 | - | * Code Highlighting © 2010-2012, Bugo * |
3 | + | * Code Highlighting © 2010-2012, Bugo * |
4 | ******************************************************************************** | |
5 | - | * Subs-Highlight.php * |
5 | + | * Subs-Highlight.php * |
6 | ******************************************************************************** | |
7 | * License http://creativecommons.org/licenses/by-nc-nd/3.0/deed.ru CC BY-NC-ND * | |
8 | - | * Support and updates for this software can be found at http://dragomano.ru * |
8 | + | * Support and updates for this software can be found at http://dragomano.ru * |
9 | *******************************************************************************/ | |
10 | ||
11 | if (!defined('SMF')) | |
12 | - | die('Hacking attempt...'); |
12 | + | die('Hacking attempt...'); |
13 | ||
14 | ||
15 | global $darkThemeIDS, $darkThemeHighlightCSS, $lightThemeHighlightCSS; | |
16 | $darkThemeIDS = array(3, 5, 7, 9, 11, 13); | |
17 | $darkThemeHighlightCSS = "monokai_sublime.css"; | |
18 | $lightThemeHighlightCSS = "vs.css"; | |
19 | ||
20 | ||
21 | // Code tag | |
22 | function ch_code_tag(&$codes) | |
23 | { | |
24 | - | global $modSettings, $txt, $settings; |
24 | + | global $modSettings, $txt, $settings; |
25 | ||
26 | - | $codeWrapHTML1 = '<div class=\"block_code\" id=\"code_a" . $codecounter . "\"><pre><code>$1</code></pre></div>"'; |
26 | + | $codeWrapHTML1 = '<div class=\"block_code\" id=\"code_a" . $codecounter . "\"><pre><code>$1</code></pre></div>"'; |
27 | - | $codeWrapHTML2 = '<div class=\"block_code\" id=\"code_b" . $codecounter . "\"><pre><code class=\"" . $data[1] . "\">$1</code></pre></div>"'; |
27 | + | $codeWrapHTML2 = '<div class=\"block_code\" id=\"code_b" . $codecounter . "\"><pre><code class=\"" . $data[1] . "\">$1</code></pre></div>"'; |
28 | ||
29 | - | if (!empty($modSettings['ch_enable'])) |
29 | + | if (!empty($modSettings['ch_enable'])) |
30 | - | { |
30 | + | { |
31 | - | foreach ($codes as $tag => $dump) |
31 | + | foreach ($codes as $tag => $dump) |
32 | - | if ($dump['tag'] == 'code') unset($codes[$tag]); |
32 | + | if ($dump['tag'] == 'code') unset($codes[$tag]); |
33 | - | |
33 | + | |
34 | - | $codes[] = array( |
34 | + | $codes[] = array( |
35 | - | 'tag' => 'code', |
35 | + | 'tag' => 'code', |
36 | - | 'type' => 'unparsed_content', |
36 | + | 'type' => 'unparsed_content', |
37 | - | 'validate' => isset($disabled['code']) ? null : create_function('&$tag, &$data, $disabled', ' |
37 | + | 'validate' => isset($disabled['code']) ? null : create_function('&$tag, &$data, $disabled', ' |
38 | - | global $txt; |
38 | + | global $txt; |
39 | - | // select all and copy code to clipboard mod |
39 | + | // select all and copy code to clipboard mod |
40 | - | static $codecounter = 0; |
40 | + | static $codecounter = 0; |
41 | - | $codecounter++; |
41 | + | $codecounter++; |
42 | - | $tag[\'content\'] = "<div class=\"codeheader\">" . $txt[\'smf238\'] . ": <a href=\"javascript:void(0)\" title=\"" . $txt[\'codeselectall\'] . "\" onclick=\"javascript:selectall(\'code_a" . $codecounter . "\');return false;\">" . $txt[\'codeselectall\'] . "</a></div>' . $codeWrapHTML1 . '; |
42 | + | $tag[\'content\'] = "<div class=\"codeheader\">" . $txt[\'smf238\'] . ": <a href=\"javascript:void(0)\" title=\"" . $txt[\'codeselectall\'] . "\" onclick=\"javascript:selectall(\'code_a" . $codecounter . "\');return false;\">" . $txt[\'codeselectall\'] . "</a></div>' . $codeWrapHTML1 . '; |
43 | - | '), |
43 | + | '), |
44 | - | 'block_level' => true, |
44 | + | 'block_level' => true, |
45 | - | ); |
45 | + | ); |
46 | - | $codes[] = array( |
46 | + | $codes[] = array( |
47 | - | 'tag' => 'code', |
47 | + | 'tag' => 'code', |
48 | - | 'type' => 'unparsed_equals_content', |
48 | + | 'type' => 'unparsed_equals_content', |
49 | - | 'validate' => isset($disabled['code']) ? null : create_function('&$tag, &$data, $disabled', ' |
49 | + | 'validate' => isset($disabled['code']) ? null : create_function('&$tag, &$data, $disabled', ' |
50 | - | global $txt; |
50 | + | global $txt; |
51 | - | // select all and copy code to clipboard mod |
51 | + | // select all and copy code to clipboard mod |
52 | - | static $codecounter = 0; |
52 | + | static $codecounter = 0; |
53 | - | $codecounter++; |
53 | + | $codecounter++; |
54 | - | $tag[\'content\'] = "<div class=\"codeheader\">" . $txt[\'smf238\'] . ": " . $data[1] . " <a href=\"javascript:void(0)\" title=\"" . $txt[\'codeselectall\'] . "\" onclick=\"javascript:selectall(\'code_b" . $codecounter . "\');return false;\">" . $txt[\'codeselectall\'] . "</a></div>' . $codeWrapHTML2 . '; |
54 | + | $tag[\'content\'] = "<div class=\"codeheader\">" . $txt[\'smf238\'] . ": " . $data[1] . " <a href=\"javascript:void(0)\" title=\"" . $txt[\'codeselectall\'] . "\" onclick=\"javascript:selectall(\'code_b" . $codecounter . "\');return false;\">" . $txt[\'codeselectall\'] . "</a></div>' . $codeWrapHTML2 . '; |
55 | - | '), |
55 | + | '), |
56 | - | 'block_level' => true, |
56 | + | 'block_level' => true, |
57 | - | ); |
57 | + | ); |
58 | - | } |
58 | + | } |
59 | - | |
59 | + | |
60 | - | // Copyright Info |
60 | + | // Copyright Info |
61 | - | if (isset($context['current_action']) && $context['current_action'] == 'credits') |
61 | + | if (isset($context['current_action']) && $context['current_action'] == 'credits') |
62 | - | $context['copyrights']['mods'][] = '<a href="http://dragomano.ru/page/code-highlighting" target="_blank">Code Highlighting</a> © 2010–2012, Bugo'; |
62 | + | $context['copyrights']['mods'][] = '<a href="http://dragomano.ru/page/code-highlighting" target="_blank">Code Highlighting</a> © 2010–2012, Bugo'; |
63 | } | |
64 | ||
65 | // Code Highlighting | |
66 | function ch_load_theme() | |
67 | { | |
68 | - | global $txt, $modSettings, $context, $settings, $darkThemeIDS; |
68 | + | global $txt, $modSettings, $context, $settings, $darkThemeIDS, $darkThemeHighlightCSS, $lightThemeHighlightCSS; |
69 | - | |
69 | + | |
70 | - | loadLanguage('Highlight'); |
70 | + | loadLanguage('Highlight'); |
71 | - | |
71 | + | |
72 | - | if (!isset($modSettings['ch_enable'])) updateSettings(array('ch_enable' => '1')); |
72 | + | if (!isset($modSettings['ch_enable'])) updateSettings(array('ch_enable' => '1')); |
73 | - | if (!isset($modSettings['ch_tab'])) updateSettings(array('ch_tab' => '4')); |
73 | + | if (!isset($modSettings['ch_tab'])) updateSettings(array('ch_tab' => '4')); |
74 | - | |
74 | + | |
75 | - | // Highlight |
75 | + | // Highlight |
76 | - | if (!empty($modSettings['ch_enable'])) |
76 | + | if (!empty($modSettings['ch_enable'])) |
77 | - | { |
77 | + | { |
78 | - | $i = 0; |
78 | + | $i = 0; |
79 | - | $tab = ''; |
79 | + | $tab = ''; |
80 | - | if (!empty($modSettings['ch_tab'])) { |
80 | + | if (!empty($modSettings['ch_tab'])) { |
81 | - | while ($i < $modSettings['ch_tab']) { |
81 | + | while ($i < $modSettings['ch_tab']) { |
82 | - | $tab .= ' '; |
82 | + | $tab .= ' '; |
83 | - | $i++; |
83 | + | $i++; |
84 | - | } |
84 | + | } |
85 | - | } |
85 | + | } |
86 | ||
87 | - | $style_css = 'default.css'; |
87 | + | $style_css = 'default.css'; |
88 | - | if (in_array($settings['theme_id'], $darkThemeIDS)) |
88 | + | if (in_array($settings['theme_id'], $darkThemeIDS)) |
89 | - | { |
89 | + | { |
90 | - | $style_css = $darkThemeHighlightCSS; |
90 | + | $style_css = $darkThemeHighlightCSS; |
91 | - | } |
91 | + | } |
92 | - | else |
92 | + | else |
93 | - | { |
93 | + | { |
94 | - | $style_css = $lightThemeHighlightCSS; |
94 | + | $style_css = $lightThemeHighlightCSS; |
95 | - | } |
95 | + | } |
96 | - | |
96 | + | |
97 | - | $context['html_headers'] .= ' |
97 | + | $context['html_headers'] .= ' |
98 | - | <link rel="stylesheet" type="text/css" href="' . $settings['default_theme_url'] . '/styles/' . $style_css . '" />'; |
98 | + | <link rel="stylesheet" type="text/css" href="' . $settings['default_theme_url'] . '/styles/' . $style_css . '" />'; |
99 | - | |
99 | + | |
100 | - | if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'showoperations') return; |
100 | + | if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'showoperations') return; |
101 | - | |
101 | + | |
102 | - | if (!WIRELESS && !in_array($context['current_action'], array('helpadmin', 'printpage'))) |
102 | + | if (!WIRELESS && !in_array($context['current_action'], array('helpadmin', 'printpage'))) |
103 | - | $context['html_headers'] .= ' |
103 | + | $context['html_headers'] .= ' |
104 | - | <script type="text/javascript" src="' . $settings['default_theme_url'] . '/highlight.pack.js"></script> |
104 | + | <script type="text/javascript" src="' . $settings['default_theme_url'] . '/highlight.pack.js"></script> |
105 | - | <script type="text/javascript"> |
105 | + | <script type="text/javascript"> |
106 | - | hljs.configure({ |
106 | + | hljs.configure({ |
107 | - | tabReplace: "' . $tab . '", |
107 | + | tabReplace: "' . $tab . '", |
108 | - | useBR: true |
108 | + | useBR: true |
109 | - | }); |
109 | + | }); |
110 | - | hljs.initHighlightingOnLoad(); |
110 | + | hljs.initHighlightingOnLoad(); |
111 | - | </script>'; |
111 | + | </script>'; |
112 | - | |
112 | + | |
113 | - | } |
113 | + | } |
114 | - | |
114 | + | |
115 | - | // Preview |
115 | + | // Preview |
116 | - | if (!empty($modSettings['ch_enable']) && in_array($context['current_action'], array('post', 'post2'))) |
116 | + | if (!empty($modSettings['ch_enable']) && in_array($context['current_action'], array('post', 'post2'))) |
117 | - | $context['html_headers'] .= ' |
117 | + | $context['html_headers'] .= ' |
118 | - | <script type="text/javascript"> |
118 | + | <script type="text/javascript"> |
119 | - | var highlightPreviewCodeBlocks = function(){ |
119 | + | var highlightPreviewCodeBlocks = function(){ |
120 | - | if (highlightPreviewCodeBlocks.calling) |
120 | + | if (highlightPreviewCodeBlocks.calling) |
121 | - | return; |
121 | + | return; |
122 | - | highlightPreviewCodeBlocks.calling = true; |
122 | + | highlightPreviewCodeBlocks.calling = true; |
123 | - | var blocks = document.querySelectorAll("#preview_body pre code"); |
123 | + | var blocks = document.querySelectorAll("#preview_body pre code"); |
124 | - | Array.prototype.forEach.call(blocks, hljs.highlightBlock); |
124 | + | Array.prototype.forEach.call(blocks, hljs.highlightBlock); |
125 | - | highlightPreviewCodeBlocks.calling = false; |
125 | + | highlightPreviewCodeBlocks.calling = false; |
126 | - | }; |
126 | + | }; |
127 | - | |
127 | + | |
128 | - | document.querySelector("#preview_body").addEventListener("DOMSubtreeModified", highlightPreviewCodeBlocks, false); |
128 | + | document.querySelector("#preview_body").addEventListener("DOMSubtreeModified", highlightPreviewCodeBlocks, false); |
129 | - | </script>'; |
129 | + | </script>'; |
130 | ||
131 | } | |
132 | ||
133 | function ch_buffer(&$buffer) | |
134 | { | |
135 | - | global $modSettings, $txt, $settings, $darkThemeIDS; |
135 | + | global $modSettings, $txt, $settings, $darkThemeIDS, $darkThemeHighlightCSS, $lightThemeHighlightCSS; |
136 | ||
137 | - | $i = 0; |
137 | + | $i = 0; |
138 | - | $tab = ''; |
138 | + | $tab = ''; |
139 | - | if (!empty($modSettings['ch_tab'])) { |
139 | + | if (!empty($modSettings['ch_tab'])) { |
140 | - | while ($i < $modSettings['ch_tab']) { |
140 | + | while ($i < $modSettings['ch_tab']) { |
141 | - | $tab .= ' '; |
141 | + | $tab .= ' '; |
142 | - | $i++; |
142 | + | $i++; |
143 | - | } |
143 | + | } |
144 | - | } |
144 | + | } |
145 | ||
146 | - | $style_css = 'default.css'; |
146 | + | $style_css = 'default.css'; |
147 | - | if (in_array($settings['theme_id'], $darkThemeIDS)) |
147 | + | if (in_array($settings['theme_id'], $darkThemeIDS)) |
148 | - | { |
148 | + | { |
149 | - | $style_css = $darkThemeHighlightCSS; |
149 | + | $style_css = $darkThemeHighlightCSS; |
150 | - | } |
150 | + | } |
151 | - | else |
151 | + | else |
152 | - | { |
152 | + | { |
153 | - | $style_css = $lightThemeHighlightCSS; |
153 | + | $style_css = $lightThemeHighlightCSS; |
154 | - | } |
154 | + | } |
155 | - | |
155 | + | |
156 | - | $search = $replace = ''; |
156 | + | $search = $replace = ''; |
157 | - | |
157 | + | |
158 | - | if (!empty($modSettings['ch_enable']) && isset($txt['operation_title'])) |
158 | + | if (!empty($modSettings['ch_enable']) && isset($txt['operation_title'])) |
159 | - | { |
159 | + | { |
160 | - | $css = "\n\t\t" . '<link rel="stylesheet" type="text/css" href="' . $settings['default_theme_url'] . '/styles/' . $style_css . '" />'; |
160 | + | $css = "\n\t\t" . '<link rel="stylesheet" type="text/css" href="' . $settings['default_theme_url'] . '/styles/' . $style_css . '" />'; |
161 | - | $js = "\n\t\t" . '<script type="text/javascript" src="' . $settings['default_theme_url'] . '/highlight.pack.js"></script> |
161 | + | $js = "\n\t\t" . '<script type="text/javascript" src="' . $settings['default_theme_url'] . '/highlight.pack.js"></script> |
162 | - | <script type="text/javascript"> |
162 | + | <script type="text/javascript"> |
163 | - | hljs.configure({ |
163 | + | hljs.configure({ |
164 | - | tabReplace: "' . $tab . '", |
164 | + | tabReplace: "' . $tab . '", |
165 | - | useBR: true |
165 | + | useBR: true |
166 | - | }); |
166 | + | }); |
167 | - | hljs.initHighlightingOnLoad(); |
167 | + | hljs.initHighlightingOnLoad(); |
168 | - | </script>'; |
168 | + | </script>'; |
169 | - | $search = '<title>' . $txt['operation_title'] . '</title>'; |
169 | + | $search = '<title>' . $txt['operation_title'] . '</title>'; |
170 | - | $replace = $search . $css . $js; |
170 | + | $replace = $search . $css . $js; |
171 | - | } |
171 | + | } |
172 | - | |
172 | + | |
173 | - | return (isset($_REQUEST['xml']) ? $buffer : str_replace($search, $replace, $buffer)); |
173 | + | return (isset($_REQUEST['xml']) ? $buffer : str_replace($search, $replace, $buffer)); |
174 | } | |
175 | ||
176 | function ch_admin_areas(&$admin_areas) | |
177 | { | |
178 | - | global $txt; |
178 | + | global $txt; |
179 | - | |
179 | + | |
180 | - | loadLanguage('Highlight'); |
180 | + | loadLanguage('Highlight'); |
181 | - | |
181 | + | |
182 | - | $context['admin_areas']['config']['areas']['modsettings']['subsections']['highlight'] = array($txt['ch_title']); |
182 | + | $context['admin_areas']['config']['areas']['modsettings']['subsections']['highlight'] = array($txt['ch_title']); |
183 | } | |
184 | ||
185 | function ch_modifications(&$subActions) | |
186 | { | |
187 | - | $subActions['highlight'] = 'ch_settings'; |
187 | + | $subActions['highlight'] = 'ch_settings'; |
188 | } | |
189 | ||
190 | // Modification settings | |
191 | function ch_settings() | |
192 | { | |
193 | - | global $txt, $context, $scripturl, $modSettings; |
193 | + | global $txt, $context, $scripturl, $modSettings; |
194 | - | |
194 | + | |
195 | - | loadLanguage('Highlight'); |
195 | + | loadLanguage('Highlight'); |
196 | - | |
196 | + | |
197 | - | $context['settings_title'] = $txt['ch_settings']; |
197 | + | $context['settings_title'] = $txt['ch_settings']; |
198 | - | $context['post_url'] = $scripturl . '?action=featuresettings2;save;sa=highlight'; |
198 | + | $context['post_url'] = $scripturl . '?action=featuresettings2;save;sa=highlight'; |
199 | - | |
199 | + | |
200 | - | $config_vars = array( |
200 | + | $config_vars = array( |
201 | - | array('check', 'ch_enable'), |
201 | + | array('check', 'ch_enable'), |
202 | - | array('int', 'ch_tab') |
202 | + | array('int', 'ch_tab') |
203 | - | ); |
203 | + | ); |
204 | - | |
204 | + | |
205 | - | if (!empty($modSettings['ch_enable']) && function_exists('file_get_contents')) $config_vars[] = array('callback', 'ch_example'); |
205 | + | if (!empty($modSettings['ch_enable']) && function_exists('file_get_contents')) $config_vars[] = array('callback', 'ch_example'); |
206 | - | |
206 | + | |
207 | - | // Saving? |
207 | + | // Saving? |
208 | - | if (isset($_GET['save'])) |
208 | + | if (isset($_GET['save'])) |
209 | - | { |
209 | + | { |
210 | - | checkSession(); |
210 | + | checkSession(); |
211 | - | saveDBSettings($config_vars); |
211 | + | saveDBSettings($config_vars); |
212 | - | redirectexit('action=featuresettings;;sa=highlight'); |
212 | + | redirectexit('action=featuresettings;;sa=highlight'); |
213 | - | } |
213 | + | } |
214 | - | |
214 | + | |
215 | - | prepareDBSettingContext($config_vars); |
215 | + | prepareDBSettingContext($config_vars); |
216 | } | |
217 | ||
218 | // Example template | |
219 | function template_callback_ch_example() | |
220 | { | |
221 | - | global $txt, $context, $settings; |
221 | + | global $txt, $context, $settings; |
222 | - | |
222 | + | |
223 | - | loadLanguage('Highlight'); |
223 | + | loadLanguage('Highlight'); |
224 | - | |
224 | + | |
225 | - | if (file_exists($settings['default_theme_dir'] . '/css/admin.css')) |
225 | + | if (file_exists($settings['default_theme_dir'] . '/css/admin.css')) |
226 | - | { |
226 | + | { |
227 | - | $file = @file_get_contents($settings['default_theme_dir'] . '/css/admin.css'); |
227 | + | $file = @file_get_contents($settings['default_theme_dir'] . '/css/admin.css'); |
228 | - | $file = parse_bbc('[code]' . $file . '[/code]'); |
228 | + | $file = parse_bbc('[code]' . $file . '[/code]'); |
229 | - | echo '<dl><strong>' . $txt['ch_example'] . '</strong>' . $file . '</dl><dt></dt><dd></dd>'; |
229 | + | echo '<dl><strong>' . $txt['ch_example'] . '</strong>' . $file . '</dl><dt></dt><dd></dd>'; |
230 | - | } |
230 | + | } |
231 | } | |
232 | ||
233 | ?> |