function crayon_exception_info($e, $return = TRUE) { $print = '<br/><b>Uncaught ' . get_class($e) . ':</b> ' . $e->getMessage() . CRAYON_BL . '<b>File:</b> ' . CrayonUtil::path_rel($e->getFile()) . CRAYON_BL . '<b>Line:</b> ' . $e->getLine() . CRAYON_BL . '<br/>'; if ($return) { return $print; } else { echo $print; } }
public static function email($to, $from = NULL) { if (($log_contents = CrayonUtil::file(CRAYON_LOG_FILE)) !== FALSE) { $headers = $from ? 'From: ' . $from : ''; $result = @mail($to, 'Crayon Syntax Highlighter Log', $log_contents, $headers); self::log('The log was emailed to the admin.', 'Log Email'); } else { // Will result in nothing if we can't email self::log("The log could not be emailed to {$to}.", 'Log Email'); } }
function is_inline($inline = NULL) { if ($inline === NULL) { return $this->is_inline; } else { $inline = CrayonUtil::str_to_bool($inline, FALSE); $this->is_inline = $inline; } }
<?php $crayon_root_theme_editor = dirname(dirname(dirname(__FILE__))); require_once $crayon_root_theme_editor . '/crayon_wp.class.php'; require_once CrayonWP::wp_load_path(); $theme = CrayonResources::themes()->get_default(); $editing = false; if (isset($_GET['curr_theme'])) { $theme = CrayonResources::themes()->get($_GET['curr_theme']); } if (isset($_GET['editing'])) { $editing = CrayonUtil::str_to_bool($_GET['editing'], FALSE); } // var_dump($_GET); // var_dump($theme); // var_dump($editing); ?> <div id="icon-options-general" class="icon32"><br> </div> <h2>Crayon Syntax Highlighter <?php crayon_e('Theme Editor'); ?> </h2> <h3> <?php if ($editing) { echo sprintf(crayon__('Editing "%s" Theme'), $theme->name()); } else { echo sprintf(crayon__('Creating Theme From "%s"'), $theme->name());
public static function plain_code($code, $encoded = TRUE) { if (is_array($code)) { // When used as a preg_replace_callback $code = $code[1]; } if (!$encoded) { $code = CrayonUtil::htmlentities($code); } if (CrayonGlobalSettings::val(CrayonSettings::TRIM_WHITESPACE)) { $code = trim($code); } return '<pre class="crayon-plain-tag">' . $code . '</pre>'; }
public static function clean_name($id) { $id = CrayonUtil::hyphen_to_space(strtolower(trim($id))); return CrayonUtil::ucwords($id); }
public function get_url($id) { return CrayonGlobalSettings::plugin_path() . CrayonUtil::pathf(CRAYON_FONT_DIR) . $id . '.css'; }
public function filename($id, $user = NULL) { return CrayonUtil::path_slash($id) . parent::filename($id, $user); }
public static function is_touch() { // Only detect once if (self::$touchscreen !== NULL) { return self::$touchscreen; } if (($devices = self::lines(CRAYON_TOUCH_FILE, 'lw')) !== FALSE) { if (!isset($_SERVER['HTTP_USER_AGENT'])) { return false; } // Create array of device strings from file $user_agent = strtolower($_SERVER['HTTP_USER_AGENT']); self::$touchscreen = self::strposa($user_agent, $devices) !== FALSE; return self::$touchscreen; } else { CrayonLog::syslog('Error occurred when trying to identify touchscreen devices'); } }
<?php require_once dirname(dirname(__FILE__)) . '/global.php'; require_once CRAYON_PARSER_PHP; if (($langs = CrayonParser::parse_all()) != FALSE) { echo '<table class="crayon-table" cellspacing="0" cellpadding="0"><tr class="crayon-table-header">', '<td>ID</td><td>Name</td><td>Version</td><td>File Extensions</td><td>Aliases</td><td>State</td></tr>'; $keys = array_values($langs); for ($i = 0; $i < count($langs); $i++) { $lang = $keys[$i]; $tr = $i == count($langs) - 1 ? 'crayon-table-last' : ''; echo '<tr class="', $tr, '">', '<td>', $lang->id(), '</td>', '<td>', $lang->name(), '</td>', '<td>', $lang->version(), '</td>', '<td>', implode(', ', $lang->ext()), '</td>', '<td>', implode(', ', $lang->alias()), '</td>', '<td class="', strtolower(CrayonUtil::space_to_hyphen($lang->state_info())), '">', $lang->state_info(), '</td>', '</tr>'; } echo '</table><br/>Languages that have the same extension as their name don\'t need to explicitly map extensions.'; } else { echo 'No languages could be found.'; }
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 ''; } }
function mode($name = NULL, $value = NULL) { if (is_string($name) && CrayonParser::is_mode($name)) { $name = trim(strtoupper($name)); if ($value == NULL && array_key_exists($name, $this->modes)) { return $this->modes[$name]; } else { if (is_string($value)) { if (CrayonUtil::str_equal_array(trim($value), array('ON', 'YES', '1'))) { $this->modes[$name] = TRUE; } else { if (CrayonUtil::str_equal_array(trim($value), array('OFF', 'NO', '0'))) { $this->modes[$name] = FALSE; } } } } } else { return $this->modes; } }
public static function submit() { global $CRAYON_EMAIL; CrayonSettingsWP::load_settings(); $id = $_POST['id']; $message = $_POST['message']; $dir = CrayonResources::themes()->dirpath_for_id($id); $dest = $dir . 'tmp'; wp_mkdir_p($dest); if (is_dir($dir) && CrayonResources::themes()->exists($id)) { try { $zipFile = CrayonUtil::createZip($dir, $dest, TRUE); $result = CrayonUtil::emailFile(array('to' => $CRAYON_EMAIL, 'from' => get_bloginfo('admin_email'), 'subject' => 'Theme Editor Submission', 'message' => $message, 'file' => $zipFile)); CrayonUtil::deleteDir($dest); if ($result) { echo 1; } else { echo -3; } } catch (Exception $e) { CrayonLog::syslog($e->getMessage(), "THEME SUBMIT"); echo -2; } } else { echo -1; } exit; }
public static function capture_replace_pre($capture, $original, $id, $is_inline, $wp_content, $args = array()) { $code = $capture['code']; $oldAtts = $capture['atts']; $newAtts = array(); $encode = isset($args['encode']) ? $args['encode'] : FALSE; if (!isset($oldAtts[CrayonSettings::DECODE]) && $encode) { // Encode the content, since no decode information exists. $code = CrayonUtil::htmlentities($code); } // We always set decode=1 irrespectively - so at this point the code is assumed to be encoded $oldAtts[CrayonSettings::DECODE] = TRUE; $newAtts['class'] = CrayonUtil::html_attributes($oldAtts, CrayonGlobalSettings::val_str(CrayonSettings::ATTR_SEP), ''); return str_replace($original, CrayonUtil::html_element('pre', $code, $newAtts), $wp_content); }
/** * Sets/gets default value. * For dropdown settings, default value is array of all possible value strings. * @param $default */ function def($default = NULL) { // Only allow default to be set once if ($this->type === NULL && $default !== NULL) { // For dropdown settings if (is_array($default)) { // The only time we don't use $this->is_array // If empty, set to blank array if (empty($default)) { $default = array(''); } else { // Ensure all values are unique strings $default = CrayonUtil::array_unique_str($default); } $this->value = 0; // initial index $this->is_array = TRUE; $this->type = gettype(0); // Type is int (index) } else { $this->is_array = FALSE; $this->type = gettype($default); } $this->default = $default; } else { return $this->default; } }
public static function show_langs() { require_once CRAYON_PARSER_PHP; if (($langs = CrayonParser::parse_all()) != FALSE) { $langs = CrayonLangs::sort_by_name($langs); echo '<table class="crayon-table" cellspacing="0" cellpadding="0"><tr class="crayon-table-header">', '<td>ID</td><td>Name</td><td>Version</td><td>File Extensions</td><td>Aliases</td><td>State</td></tr>'; $keys = array_values($langs); for ($i = 0; $i < count($langs); $i++) { $lang = $keys[$i]; $tr = $i == count($langs) - 1 ? 'crayon-table-last' : ''; echo '<tr class="', $tr, '">', '<td>', $lang->id(), '</td>', '<td>', $lang->name(), '</td>', '<td>', $lang->version(), '</td>', '<td>', implode(', ', $lang->ext()), '</td>', '<td>', implode(', ', $lang->alias()), '</td>', '<td class="', strtolower(CrayonUtil::space_to_hyphen($lang->state_info())), '">', $lang->state_info(), '</td>', '</tr>'; } echo '</table><br/>Languages that have the same extension as their name don\'t need to explicitly map extensions.'; } else { echo 'No languages could be found.'; } exit; }
public static function comment_text($text) { global $comment; $comment_id = strval($comment->comment_ID); // Find if this post has Crayons if (array_key_exists($comment_id, self::$comment_queue)) { // XXX We want the plain post content, no formatting $the_content_original = $text; // Loop through Crayons $post_in_queue = self::$comment_queue[$comment_id]; foreach ($post_in_queue as $id => $v) { $atts = $v['atts']; $content = $v['code']; // The code we replace post content with $crayon = self::shortcode($atts, $content, $id); $crayon_formatted = $crayon->output(TRUE, FALSE); // Replacing may cause <p> tags to become disjoint with a <div> inside them, close and reopen them if needed if (!$crayon->is_inline()) { $text = preg_replace_callback('#' . self::REGEX_BETWEEN_PARAGRAPH_SIMPLE . '#msi', 'CrayonWP::add_paragraphs', $text); } // Replace the code with the Crayon $text = CrayonUtil::preg_replace_escape_back(self::regex_with_id($id), $crayon_formatted, $text, 1, $text); } } return $text; }