Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*******************************************************************************
- * Code Highlighting © 2010-2012, Bugo *
- ********************************************************************************
- * Subs-Highlight.php *
- ********************************************************************************
- * License http://creativecommons.org/licenses/by-nc-nd/3.0/deed.ru CC BY-NC-ND *
- * Support and updates for this software can be found at http://dragomano.ru *
- *******************************************************************************/
- if (!defined('SMF'))
- die('Hacking attempt...');
- global $darkThemeIDS, $darkThemeHighlightCSS, $lightThemeHighlightCSS;
- $darkThemeIDS = array(3, 5, 7, 9, 11, 13);
- $darkThemeHighlightCSS = "monokai_sublime.css";
- $lightThemeHighlightCSS = "vs.css";
- // Code tag
- function ch_code_tag(&$codes)
- {
- global $modSettings, $txt, $settings;
- $codeWrapHTML1 = '<div class=\"block_code\" id=\"code_a" . $codecounter . "\"><pre><code>$1</code></pre></div>"';
- $codeWrapHTML2 = '<div class=\"block_code\" id=\"code_b" . $codecounter . "\"><pre><code class=\"" . $data[1] . "\">$1</code></pre></div>"';
- if (!empty($modSettings['ch_enable']))
- {
- foreach ($codes as $tag => $dump)
- if ($dump['tag'] == 'code') unset($codes[$tag]);
- $codes[] = array(
- 'tag' => 'code',
- 'type' => 'unparsed_content',
- 'validate' => isset($disabled['code']) ? null : create_function('&$tag, &$data, $disabled', '
- global $txt;
- // select all and copy code to clipboard mod
- static $codecounter = 0;
- $codecounter++;
- $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 . ';
- '),
- 'block_level' => true,
- );
- $codes[] = array(
- 'tag' => 'code',
- 'type' => 'unparsed_equals_content',
- 'validate' => isset($disabled['code']) ? null : create_function('&$tag, &$data, $disabled', '
- global $txt;
- // select all and copy code to clipboard mod
- static $codecounter = 0;
- $codecounter++;
- $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 . ';
- '),
- 'block_level' => true,
- );
- }
- // Copyright Info
- if (isset($context['current_action']) && $context['current_action'] == 'credits')
- $context['copyrights']['mods'][] = '<a href="http://dragomano.ru/page/code-highlighting" target="_blank">Code Highlighting</a> © 2010–2012, Bugo';
- }
- // Code Highlighting
- function ch_load_theme()
- {
- global $txt, $modSettings, $context, $settings, $darkThemeIDS, $darkThemeHighlightCSS, $lightThemeHighlightCSS;
- loadLanguage('Highlight');
- if (!isset($modSettings['ch_enable'])) updateSettings(array('ch_enable' => '1'));
- if (!isset($modSettings['ch_tab'])) updateSettings(array('ch_tab' => '4'));
- // Highlight
- if (!empty($modSettings['ch_enable']))
- {
- $i = 0;
- $tab = '';
- if (!empty($modSettings['ch_tab'])) {
- while ($i < $modSettings['ch_tab']) {
- $tab .= ' ';
- $i++;
- }
- }
- $style_css = 'default.css';
- if (in_array($settings['theme_id'], $darkThemeIDS))
- {
- $style_css = $darkThemeHighlightCSS;
- }
- else
- {
- $style_css = $lightThemeHighlightCSS;
- }
- $context['html_headers'] .= '
- <link rel="stylesheet" type="text/css" href="' . $settings['default_theme_url'] . '/styles/' . $style_css . '" />';
- if (isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'showoperations') return;
- if (!WIRELESS && !in_array($context['current_action'], array('helpadmin', 'printpage')))
- $context['html_headers'] .= '
- <script type="text/javascript" src="' . $settings['default_theme_url'] . '/highlight.pack.js"></script>
- <script type="text/javascript">
- hljs.configure({
- tabReplace: "' . $tab . '",
- useBR: true
- });
- hljs.initHighlightingOnLoad();
- </script>';
- }
- // Preview
- if (!empty($modSettings['ch_enable']) && in_array($context['current_action'], array('post', 'post2')))
- $context['html_headers'] .= '
- <script type="text/javascript">
- var highlightPreviewCodeBlocks = function(){
- if (highlightPreviewCodeBlocks.calling)
- return;
- highlightPreviewCodeBlocks.calling = true;
- var blocks = document.querySelectorAll("#preview_body pre code");
- Array.prototype.forEach.call(blocks, hljs.highlightBlock);
- highlightPreviewCodeBlocks.calling = false;
- };
- document.querySelector("#preview_body").addEventListener("DOMSubtreeModified", highlightPreviewCodeBlocks, false);
- </script>';
- }
- function ch_buffer(&$buffer)
- {
- global $modSettings, $txt, $settings, $darkThemeIDS, $darkThemeHighlightCSS, $lightThemeHighlightCSS;
- $i = 0;
- $tab = '';
- if (!empty($modSettings['ch_tab'])) {
- while ($i < $modSettings['ch_tab']) {
- $tab .= ' ';
- $i++;
- }
- }
- $style_css = 'default.css';
- if (in_array($settings['theme_id'], $darkThemeIDS))
- {
- $style_css = $darkThemeHighlightCSS;
- }
- else
- {
- $style_css = $lightThemeHighlightCSS;
- }
- $search = $replace = '';
- if (!empty($modSettings['ch_enable']) && isset($txt['operation_title']))
- {
- $css = "\n\t\t" . '<link rel="stylesheet" type="text/css" href="' . $settings['default_theme_url'] . '/styles/' . $style_css . '" />';
- $js = "\n\t\t" . '<script type="text/javascript" src="' . $settings['default_theme_url'] . '/highlight.pack.js"></script>
- <script type="text/javascript">
- hljs.configure({
- tabReplace: "' . $tab . '",
- useBR: true
- });
- hljs.initHighlightingOnLoad();
- </script>';
- $search = '<title>' . $txt['operation_title'] . '</title>';
- $replace = $search . $css . $js;
- }
- return (isset($_REQUEST['xml']) ? $buffer : str_replace($search, $replace, $buffer));
- }
- function ch_admin_areas(&$admin_areas)
- {
- global $txt;
- loadLanguage('Highlight');
- $context['admin_areas']['config']['areas']['modsettings']['subsections']['highlight'] = array($txt['ch_title']);
- }
- function ch_modifications(&$subActions)
- {
- $subActions['highlight'] = 'ch_settings';
- }
- // Modification settings
- function ch_settings()
- {
- global $txt, $context, $scripturl, $modSettings;
- loadLanguage('Highlight');
- $context['settings_title'] = $txt['ch_settings'];
- $context['post_url'] = $scripturl . '?action=featuresettings2;save;sa=highlight';
- $config_vars = array(
- array('check', 'ch_enable'),
- array('int', 'ch_tab')
- );
- if (!empty($modSettings['ch_enable']) && function_exists('file_get_contents')) $config_vars[] = array('callback', 'ch_example');
- // Saving?
- if (isset($_GET['save']))
- {
- checkSession();
- saveDBSettings($config_vars);
- redirectexit('action=featuresettings;;sa=highlight');
- }
- prepareDBSettingContext($config_vars);
- }
- // Example template
- function template_callback_ch_example()
- {
- global $txt, $context, $settings;
- loadLanguage('Highlight');
- if (file_exists($settings['default_theme_dir'] . '/css/admin.css'))
- {
- $file = @file_get_contents($settings['default_theme_dir'] . '/css/admin.css');
- $file = parse_bbc('[code]' . $file . '[/code]');
- echo '<dl><strong>' . $txt['ch_example'] . '</strong>' . $file . '</dl><dt></dt><dd></dd>';
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement