예제 #1
0
 function ShowLanguageWarning()
 {
     $locale = get_locale();
     if (!in_array($locale, CodeColorerOptions::GetLanguages())) {
         $msgFormat = __('Your current locale is %1$s, and CodeColorer has incomplete or does not have a translation into your language. It would be great, if you have a time to <a href="%2$s">help us to translate</a> it.', 'codecolorer');
         $this->cc->ShowWarning('language', __('CodeColorer translation is incomplete.', 'codecolorer'), sprintf($msgFormat, $locale, "http://kpumuk.info/projects/wordpress-plugins/codecolorer/#translation"));
     }
 }
예제 #2
0
 /**
  * Perform code highlightning
  */
 function PerformHighlightCodeBlock($text, $opts, $content, $suffix = '', $before = '', $after = '')
 {
     // Parse options
     $options = CodeColorerOptions::ParseOptions($opts, $suffix);
     // Load code from a file
     if (isset($options['file'])) {
         $uploadPath = wp_upload_dir();
         $baseDir = realpath($uploadPath['basedir']);
         $filePath = realpath(path_join($baseDir, $options['file']));
         # Security check: do not allow to display arbitrary files, only the ones from
         # uploads folder.
         if (false === $filePath || 0 !== strncmp($baseDir, $filePath, strlen($baseDir)) || !is_file($filePath)) {
             $text = 'Specified file is not in uploads folder, does not exists, or not a file.';
             $options['lang'] = 'text';
         } else {
             $text = file_get_contents($filePath);
         }
     }
     // Preprocess source text
     $text = str_replace(array("\\\"", "\\\\'"), array("\"", "\\'"), $text);
     $text = preg_replace('/(< \\?php)/i', '<?php', $text);
     $text = preg_replace('/(?:^(?:\\s*[\\r\\n])+|\\s+$)/', '', $text);
     if ($options['escaped']) {
         $text = html_entity_decode($text, ENT_QUOTES);
         $text = preg_replace('~&#x0*([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $text);
         $text = preg_replace('~&#0*([0-9]+);~e', 'chr(\\1)', $text);
     }
     $result = '';
     // Check if CodeColorer has been disabled for this particular block
     if (!$options['enabled']) {
         $result = '<code>' . $text . '</code>';
     } else {
         // See if we should force a height
         $num_lines = count(explode("\n", $text));
         $result = $this->PerformHighlightGeshi($text, $options);
         $result = $this->AddContainer($result, $options, $num_lines);
     }
     if ($options['inline']) {
         $blockID = $this->GetBlockID($content, false, '<span>', '</span>');
     } else {
         $blockID = $this->GetBlockID($content);
     }
     $this->blocks[$blockID] = $result;
     if ($options['inline']) {
         $result = $before . $blockID . $after;
     } else {
         $result = "\n\n{$blockID}\n\n";
     }
     return $result;
 }
예제 #3
0
 /**
  * Perform code highlightning
  */
 function PerformHighlightCodeBlock($text, $opts, $content, $suffix = '', $before = '', $after = '')
 {
     // Preprocess source text
     $text = str_replace(array("\\\"", "\\\\'"), array("\"", "\\'"), $text);
     $text = preg_replace('/(< \\?php)/i', '<?php', $text);
     $text = preg_replace('/(?:^(?:\\s*[\\r\\n])+|\\s+$)/', '', $text);
     // Parse options
     $options = CodeColorerOptions::ParseOptions($opts, $suffix);
     if ($options['escaped']) {
         $text = html_entity_decode($text, ENT_QUOTES);
         $text = preg_replace('~&#x0*([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $text);
         $text = preg_replace('~&#0*([0-9]+);~e', 'chr(\\1)', $text);
     }
     $result = '';
     // Check if CodeColorer has been disabled for this particular block
     if (!$options['enabled']) {
         $result = '<code>' . $text . '</code>';
     } else {
         // See if we should force a height
         $num_lines = count(explode("\n", $text));
         $result = $this->PerformHighlightGeshi($text, $options);
         $result = $this->AddContainer($result, $options, $num_lines);
     }
     if ($options['inline']) {
         $blockID = $this->GetBlockID($content, false, '<span>', '</span>');
     } else {
         $blockID = $this->GetBlockID($content);
     }
     $this->blocks[$blockID] = $result;
     if ($options['inline']) {
         $result = $before . $blockID . $after;
     } else {
         $result = "\n\n{$blockID}\n\n";
     }
     return $result;
 }
 /**
  * Process the language identifier attribute string
  */
 function FilterLanguage($lang)
 {
     $lang = strtolower($lang);
     if (strstr($lang, 'html')) {
         $lang = 'html4strict';
     } else {
         $langs = CodeColorerOptions::GetLanguageMappings();
         if ($langs[$lang]) {
             $lang = $langs[$lang];
         }
     }
     return $lang;
 }
예제 #5
0
 function PopulateDefaultValues($options)
 {
     if (!$options) {
         $options = array();
     }
     if (!isset($options['lang'])) {
         $options['lang'] = 'text';
     }
     $options['lang'] = CodeColorerOptions::FilterLanguage($options['lang']);
     // Whether CodeColorer should be enabled (bool)
     if (isset($options['enabled'])) {
         $options['enabled'] = CodeColorerOptions::ParseBoolean($options['enabled']);
     } elseif (isset($options['no_cc'])) {
         $options['enabled'] = !CodeColorerOptions::ParseBoolean($options['no_cc']);
     } else {
         $options['enabled'] = true;
     }
     // Whether code in block is already escaped (bool)
     if (!isset($options['escaped'])) {
         $options['escaped'] = false;
     } else {
         $options['escaped'] = CodeColorerOptions::ParseBoolean($options['escaped']);
     }
     // Whether horizontal wrapping should be disabled (bool)
     if (!isset($options['nowrap'])) {
         $options['nowrap'] = true;
     } else {
         $options['nowrap'] = CodeColorerOptions::ParseBoolean($options['nowrap']);
     }
     // Disable container border (bool)
     if (!isset($options['noborder'])) {
         $options['noborder'] = false;
     } else {
         $options['noborder'] = CodeColorerOptions::ParseBoolean($options['noborder']);
     }
     // Whether strict mode should be enabled (bool)
     if (!isset($options['strict'])) {
         $options['strict'] = NULL;
     } else {
         $options['strict'] = CodeColorerOptions::ParseBoolean($options['strict']);
     }
     // Whether code should be rendered inline
     if (!isset($options['inline'])) {
         $options['inline'] = false;
     } else {
         $option['inline'] = CodeColorerOptions::ParseBoolean($options['inline']);
     }
     // Tab size (int)
     if (!isset($options['tab_size'])) {
         $options['tab_size'] = intval(get_option('codecolorer_tab_size'));
     } else {
         $options['tab_size'] = intval($options['tab_size']);
     }
     // Font size (int)
     if (!isset($options['font_size'])) {
         $options['font_size'] = intval(get_option('codecolorer_font_size'));
     } else {
         $options['font_size'] = intval($options['font_size']);
     }
     // Line numbers (bool)
     if (!isset($options['line_numbers'])) {
         $options['line_numbers'] = CodeColorerOptions::ParseBoolean(get_option('codecolorer_line_numbers'));
     } else {
         $options['line_numbers'] = CodeColorerOptions::ParseBoolean($options['line_numbers']);
     }
     // var_dump(get_option('codecolorer_line_numbers'));
     // First line (int)
     if (!isset($options['first_line'])) {
         $options['first_line'] = 1;
     } else {
         $options['first_line'] = intval($options['first_line']);
     }
     if ($options['first_line'] < 1) {
         $options['first_line'] = 1;
     }
     // Disable keyword linking (bool)
     if (!isset($options['no_links'])) {
         $options['no_links'] = CodeColorerOptions::ParseBoolean(get_option('codecolorer_disable_keyword_linking'));
     } else {
         $options['no_links'] = CodeColorerOptions::ParseBoolean($options['no_links']);
     }
     // Lines to scroll (int)
     if (!isset($options['lines'])) {
         $options['lines'] = intval(get_option('codecolorer_lines_to_scroll'));
     } else {
         $options['lines'] = intval($options['lines']);
     }
     // Block width (int or string)
     if (!isset($options['width'])) {
         $options['width'] = get_option('codecolorer_width');
     }
     // Block height (int or string)
     if (!isset($options['height'])) {
         $options['height'] = get_option('codecolorer_height');
     }
     // Block width in RSS (int or string)
     if (!isset($options['rss_width'])) {
         $options['rss_width'] = get_option('codecolorer_rss_width');
     }
     // Custom CSS classes (string)
     if (!isset($options['class'])) {
         $options['class'] = get_option('codecolorer_css_class');
     }
     // Theme (string)
     if (!isset($options['theme'])) {
         $options['theme'] = get_option('codecolorer_theme');
         $options['inline_theme'] = get_option('codecolorer_inline_theme');
     } else {
         $options['inline_theme'] = $options['theme'];
     }
     if ($options['theme'] == 'default') {
         $options['theme'] = '';
         $options['inline_theme'] = '';
     }
     return $options;
 }