コード例 #1
0
 public static function langs()
 {
     if (self::$langs == NULL) {
         self::$langs = new CrayonLangs();
     }
     return self::$langs;
 }
コード例 #2
0
 public static function init_settings()
 {
     if (!self::$settings) {
         // Add settings
         self::$settings = array('home_url' => home_url(), 'css' => 'crayon-te', 'css_selected' => 'crayon-selected', 'code_css' => '#crayon-code', 'url_css' => '#crayon-url', 'url_info_css' => '#crayon-te-url-info', 'lang_css' => '#crayon-lang', 'title_css' => '#crayon-title', 'mark_css' => '#crayon-mark', 'range_css' => '#crayon-range', 'inline_css' => 'crayon-inline', 'inline_hide_css' => 'crayon-hide-inline', 'inline_hide_only_css' => 'crayon-hide-inline-only', 'hl_css' => '#crayon-highlight', 'switch_html' => '#content-html', 'switch_tmce' => '#content-tmce', 'tinymce_button' => 'a.mce_crayon_tinymce', 'submit_css' => '#crayon-te-ok', 'cancel_css' => '#crayon-te-cancel', 'content_css' => '#crayon-te-content', 'dialog_title_css' => '#crayon-te-title', 'submit_wrapper_css' => '#crayon-te-submit-wrapper', 'data_value' => 'data-value', 'attr_sep' => CrayonGlobalSettings::val_str(CrayonSettings::ATTR_SEP), 'css_sep' => '_', 'fallback_lang' => CrayonGlobalSettings::val(CrayonSettings::FALLBACK_LANG), 'dialog_title_add' => crayon__('Add Crayon Code'), 'dialog_title_edit' => crayon__('Edit Crayon Code'), 'submit_add' => crayon__('Add'), 'submit_edit' => crayon__('Save'), 'bar' => '#crayon-te-bar', 'bar_content' => '#crayon-te-bar-content', 'extensions' => CrayonResources::langs()->extensions_inverted());
     }
 }
コード例 #3
0
 public static function langs()
 {
     echo '<a name="langs"></a>';
     // Specialised dropdown for languages
     if (array_key_exists(CrayonSettings::FALLBACK_LANG, self::$options)) {
         if (($langs = CrayonParser::parse_all()) != FALSE) {
             $langs = CrayonLangs::sort_by_name($langs);
             self::span(crayon__('When no language is provided, use the fallback') . ': ');
             self::dropdown(CrayonSettings::FALLBACK_LANG, FALSE, TRUE, TRUE, $langs);
             // Information about parsing
             $parsed = CrayonResources::langs()->is_parsed();
             $count = count($langs);
             echo '</select>', CRAYON_BR, $parsed ? '' : '<span class="crayon-error">', sprintf(crayon_n('%d language has been detected.', '%d languages have been detected.', $count), $count), ' ', $parsed ? crayon__('Parsing was successful') : crayon__('Parsing was unsuccessful'), $parsed ? '. ' : '</span>';
             // Check if fallback from db is loaded
             $db_fallback = self::$options[CrayonSettings::FALLBACK_LANG];
             // Fallback name from db
             if (!CrayonResources::langs()->is_loaded($db_fallback) || !CrayonResources::langs()->exists($db_fallback)) {
                 echo '<br/><span class="crayon-error">', sprintf(crayon__('The selected language with id %s could not be loaded'), '<strong>' . $db_fallback . '</strong>'), '. </span>';
             }
             // Language parsing info
             echo CRAYON_BR, '<div id="crayon-subsection-langs-info"><div>' . self::button(array('id' => 'show-langs', 'title' => crayon__('Show Languages'))) . '</div></div>';
         } else {
             echo 'No languages could be parsed.';
         }
     }
 }
コード例 #4
0
 private static function init_tags_regex($force = FALSE, $flags = NULL, &$tags_regex = NULL)
 {
     CrayonSettingsWP::load_settings();
     self::init_tag_bits();
     // Default output
     if ($tags_regex === NULL) {
         $tags_regex =& self::$tags_regex;
     }
     if ($force || $tags_regex === "") {
         // Check which tags are in $flags. If it's NULL, then all flags are true.
         $in_flag = self::in_flag($flags);
         if ($in_flag[CrayonSettings::CAPTURE_MINI_TAG] && CrayonGlobalSettings::val(CrayonSettings::CAPTURE_MINI_TAG) || $force || ($in_flag[CrayonSettings::INLINE_TAG] && (CrayonGlobalSettings::val(CrayonSettings::INLINE_TAG) && CrayonGlobalSettings::val(CrayonSettings::INLINE_TAG_CAPTURE)) || $force)) {
             $aliases = CrayonResources::langs()->ids_and_aliases();
             self::$alias_regex = '';
             for ($i = 0; $i < count($aliases); $i++) {
                 $alias = $aliases[$i];
                 $alias_regex = CrayonUtil::esc_hash(CrayonUtil::esc_regex($alias));
                 if ($i != count($aliases) - 1) {
                     $alias_regex .= '|';
                 }
                 self::$alias_regex .= $alias_regex;
             }
         }
         // Add other tags
         $tags_regex = '#(?<!\\$)(?:(\\s*\\[\\s*crayon\\b)';
         // TODO this is duplicated in capture_crayons()
         $tag_regexes = array(CrayonSettings::CAPTURE_MINI_TAG => '(\\[\\s*(' . self::$alias_regex . ')\\b)', CrayonSettings::CAPTURE_PRE => '(<\\s*pre\\b)', CrayonSettings::INLINE_TAG => '(' . self::REGEX_INLINE_CLASS . ')' . '|(\\{\\s*(' . self::$alias_regex . ')\\b([^\\}]*)\\})', CrayonSettings::PLAIN_TAG => '(\\s*\\[\\s*plain\\b)', CrayonSettings::BACKQUOTE => '(`[^`]*`)');
         foreach ($tag_regexes as $tag => $regex) {
             if ($in_flag[$tag] && (CrayonGlobalSettings::val($tag) || $force)) {
                 $tags_regex .= '|' . $regex;
             }
         }
         $tags_regex .= ')#msi';
     }
 }
コード例 #5
0
 function language_detect()
 {
     // Attempt to detect the language
     if (!empty($id)) {
         $this->log("The language '{$id}' could not be loaded.");
     }
     $this->language = CrayonResources::langs()->detect($this->url, $this->setting_val(CrayonSettings::FALLBACK_LANG));
 }
コード例 #6
0
 public static function delim_to_internal($matches)
 {
     // Mark as mixed so we can show (+)
     self::$curr->is_mixed(TRUE);
     $capture_group = count($matches) - 2;
     $capture_groups = array_keys(self::$delimiters);
     $lang_id = $capture_groups[$capture_group];
     if (($lang = CrayonResources::langs()->get($lang_id)) === NULL) {
         return $matches[0];
     }
     $internal = sprintf('{{crayon-internal:%d}}', count(self::$delim_pieces));
     // TODO fix
     self::$delim_pieces[] = CrayonFormatter::format_code($matches[0], $lang, self::$curr);
     return $internal;
 }
コード例 #7
0
 public static function validate_regex($regex, $element)
 {
     if (is_string($regex) && @get_class($element) == CRAYON_ELEMENT_CLASS) {
         // If the (?alt) tag has been used, insert the file into the regex
         $file = self::regex_match('#\\(\\?alt:(.+?)\\)#', $regex);
         if (count($file) == 2) {
             // Element 0 has full match, 1 has captured groups
             for ($i = 0; $i < count($file[1]); $i++) {
                 $file_lines = CrayonUtil::lines(dirname($element->path()) . crayon_s() . $file[1][$i], 'rcwh');
                 if ($file_lines !== FALSE) {
                     $file_lines = implode('|', $file_lines);
                     // If any spaces exist, treat them as whitespace
                     $file_lines = preg_replace('#[ \\t]+#msi', '\\s+', $file_lines);
                     $regex = str_replace($file[0][$i], "(?:{$file_lines})", $regex);
                 } else {
                     CrayonLog::syslog("Parsing of '{$element->path()}' failed, an (?alt) tag failed for the element '{$element->name()}'");
                     return FALSE;
                 }
             }
         }
         // If the (?default:element) function is used, replace the regex with the default, if exists
         $def = self::regex_match('#\\(\\?default(?:\\:(\\w+))?\\)#', $regex);
         if (count($def) == 2) {
             // Load default language
             $default = CrayonResources::langs()->get(CrayonLangs::DEFAULT_LANG);
             // If default has not been loaded, we can't use it, skip the element
             if (!$default) {
                 CrayonLog::syslog("Could not use default regex in the element '{$element->name()}' in '{$element->path()}'");
                 return FALSE;
             }
             for ($i = 0; $i < count($def[1]); $i++) {
                 // If an element has been provided
                 $element_name = !empty($def[1][$i]) ? $def[1][$i] : $element->name();
                 if (($default_element = $default->element($element_name)) != FALSE) {
                     $regex = str_replace($def[0][$i], '(?:' . $default_element->regex() . ')', $regex);
                 } else {
                     CrayonLog::syslog("The language at '{$element->path()}' referred to the Default Language regex for element '{$element->name()}', which did not exist.");
                     return FALSE;
                 }
             }
         }
         // If the (?html) tag is used, escape characters in html (<, > and &)
         $html = self::regex_match('#\\(\\?html:(.+?)\\)#', $regex);
         if (count($html) == 2) {
             for ($i = 0; $i < count($html[1]); $i++) {
                 $regex = str_replace($html[0][$i], htmlentities($html[1][$i]), $regex);
             }
         }
         // Ensure all parenthesis are atomic to avoid conflicting with element matches
         $regex = CrayonUtil::esc_atomic($regex);
         // Escape #, this is our delimiter
         $regex = CrayonUtil::esc_hash($regex);
         // Test if regex is valid
         if (@preg_match("#{$regex}#", '') === FALSE) {
             CrayonLog::syslog("The regex for the element '{$element->name()}' in '{$element->path()}' is not valid.");
             return FALSE;
         }
         return $regex;
     } else {
         return '';
     }
 }
コード例 #8
0
 function language($id = NULL)
 {
     if ($id === NULL || !is_string($id)) {
         return $this->language;
     }
     if (($lang = CrayonResources::langs()->get($id)) != FALSE || ($lang = CrayonResources::langs()->alias($id)) != FALSE) {
         // Set the language if it exists or look for an alias
         $this->language = $lang;
     } else {
         // Attempt to detect the language
         if (!empty($id)) {
             $this->log("The language '{$id}' could not be loaded.");
         }
         $this->language = CrayonResources::langs()->detect($this->url, $this->setting_val(CrayonSettings::FALLBACK_LANG));
     }
     // Prepare the language for use, even if we have no code, we need the name
     CrayonParser::parse($this->language->id());
 }
コード例 #9
0
 private static function init_tags_regex()
 {
     if (!self::$is_tags_regex_init) {
         if (CrayonGlobalSettings::val(CrayonSettings::CAPTURE_MINI_TAG) || CrayonGlobalSettings::val(CrayonSettings::INLINE_TAG)) {
             $aliases = CrayonResources::langs()->ids_and_aliases();
             for ($i = 0; $i < count($aliases); $i++) {
                 $alias = $aliases[$i];
                 $alias_regex = CrayonUtil::esc_hash(CrayonUtil::esc_regex($alias));
                 if ($i != count($aliases) - 1) {
                     $alias_regex .= '|';
                 }
                 self::$alias_regex .= $alias_regex;
             }
         }
         // Add other tags
         self::$tags_regex = '#(\\s*\\[\\s*crayon\\b)';
         if (CrayonGlobalSettings::val(CrayonSettings::CAPTURE_MINI_TAG)) {
             self::$tags_regex .= '|([\\[]\\s*(' . self::$alias_regex . '))';
         }
         if (CrayonGlobalSettings::val(CrayonSettings::CAPTURE_PRE)) {
             self::$tags_regex .= '|(<\\s*pre\\b)';
         }
         if (CrayonGlobalSettings::val(CrayonSettings::INLINE_TAG)) {
             self::$tags_regex .= '|(' . self::REGEX_INLINE_CLASS . ')' . '|([\\{]\\s*(' . self::$alias_regex . '))';
         }
         if (CrayonGlobalSettings::val(CrayonSettings::PLAIN_TAG)) {
             self::$tags_regex .= '|(\\s*\\[\\s*plain\\b)';
         }
         if (CrayonGlobalSettings::val(CrayonSettings::BACKQUOTE)) {
             self::$tags_regex .= '|(`[^`]*`)';
         }
         self::$tags_regex .= '#msi';
         self::$is_tags_regex_init = TRUE;
     }
 }