public static function format_code($code, $language, $hl = NULL) { // Ensure the language is defined if ($language != NULL && $hl->is_highlighted()) { $code = self::clean_code($code, FALSE, FALSE, FALSE, TRUE); /* Perform the replace on the code using the regex, pass the captured matches for formatting before they are replaced */ try { CrayonParser::parse($language->id()); // Match language regex $elements = $language->elements(); $regex = $language->regex(); if (!empty($regex) && !empty($elements)) { // Get array of CrayonElements self::$elements = array_values($elements); $code = preg_replace_callback($regex, 'CrayonFormatter::format_match', $code); } } catch (Exception $e) { $error = 'An error occured when formatting: ' . $e->message(); $hl ? $hl->log($error) : CrayonLog::syslog($error); } return $code; } else { return self::clean_code($code, TRUE, TRUE, TRUE, TRUE); } }
public static function clear() { if (!@unlink(CRAYON_LOG_FILE)) { // Will result in nothing if we can't log self::log('The log could not be cleared', 'Log Clear'); } self::$file = NULL; // Remove file handle }
function crayon_exception_log($exception) { $info = crayon_exception_info($exception); // Log the exception CrayonLog::syslog(strip_tags($info)); if (CRAYON_DEBUG) { // Only print when debugging echo $info; } }
function __construct() { $this->set_default(self::DEFAULT_FONT, self::DEFAULT_FONT_NAME); $this->directory(CRAYON_FONT_PATH); $this->relative_directory(CRAYON_FONT_DIR); $this->extension('css'); CrayonLog::debug("Setting font directories"); $upload = CrayonGlobalSettings::upload_path(); if ($upload) { $this->user_directory($upload . CRAYON_FONT_DIR); if (!is_dir($this->user_directory())) { CrayonGlobalSettings::mkdir($this->user_directory()); CrayonLog::debug($this->user_directory(), "THEME DIR"); } } else { CrayonLog::syslog("Upload directory is empty: " . $upload); } CrayonLog::debug($this->directory()); CrayonLog::debug($this->user_directory()); }
public static function log() { $log = CrayonLog::log(); touch(CRAYON_LOG_FILE); $exists = file_exists(CRAYON_LOG_FILE); $writable = is_writable(CRAYON_LOG_FILE); if (!empty($log)) { echo '<div id="crayon-log-wrapper">', '<div id="crayon-log"><div id="crayon-log-text">', $log, '</div></div>', '<div id="crayon-log-controls">', '<input type="button" id="crayon-log-toggle" show_txt="', crayon__('Show Log'), '" hide_txt="', crayon__('Hide Log'), '" class="button-secondary" value="', crayon__('Show Log'), '"> ', '<input type="submit" id="crayon-log-clear" name="', self::LOG_CLEAR, '" class="button-secondary" value="', crayon__('Clear Log'), '"> ', '<input type="submit" id="crayon-log-email" name="', self::LOG_EMAIL_ADMIN . '" class="button-secondary" value="', crayon__('Email Admin'), '"> ', '<input type="submit" id="crayon-log-email" name="', self::LOG_EMAIL_DEV, '" class="button-secondary" value="', crayon__('Email Developer'), '"> ', '</div>', '</div>'; } echo '<span', !empty($log) ? ' class="crayon-span"' : '', '>', empty($log) ? crayon__('The log is currently empty.') . ' ' : ''; if ($exists) { $writable ? crayon_e('The log file exists and is writable.') : crayon_e('The log file exists and is not writable.'); } else { crayon_e('The log file does not exist and is not writable.'); } echo '</span>'; }
/** * Converts Crayon tags found in WP to <pre> form. * XXX: This will alter blog content, so backup before calling. * XXX: Do NOT call this while updating posts or comments, it may cause an infinite loop or fail. * @param $encode Whether to detect missing "decode" attribute and encode html entities in the code. */ public static function convert_tags($encode = FALSE) { $crayon_posts = CrayonSettingsWP::load_legacy_posts(); if ($crayon_posts === NULL) { return; } self::init_legacy_tag_bits(); $args = array('callback' => 'CrayonWP::capture_replace_pre', 'callback_extra_args' => array('encode' => $encode), 'ignore' => FALSE, 'preserve_atts' => TRUE, 'flags' => self::$legacy_flags, 'skip_setting_check' => TRUE); foreach ($crayon_posts as $postID) { $post = get_post($postID); $post_content = $post->post_content; $post_captures = self::capture_crayons($postID, $post_content, array(), $args); if ($post_captures['has_captured'] === TRUE) { $post_obj = array(); $post_obj['ID'] = $postID; $post_obj['post_content'] = addslashes($post_captures['content']); wp_update_post($post_obj); CrayonLog::syslog("Converted Crayons in post ID {$postID} to pre tags", 'CONVERT'); } if (CrayonGlobalSettings::val(CrayonSettings::COMMENTS)) { $comments = get_comments(array('post_id' => $postID)); foreach ($comments as $comment) { $commentID = $comment->comment_ID; $comment_captures = self::capture_crayons($commentID, $comment->comment_content, array(CrayonSettings::DECODE => TRUE), $args); if ($comment_captures['has_captured'] === TRUE) { $comment_obj = array(); $comment_obj['comment_ID'] = $commentID; $comment_obj['comment_content'] = $comment_captures['content']; wp_update_comment($comment_obj); CrayonLog::syslog("Converted Crayons in post ID {$postID}, comment ID {$commentID} to pre tags", 'CONVERT'); } } } } self::refresh_posts(); }
function log($var) { if ($this->setting_val(CrayonSettings::ERROR_LOG)) { CrayonLog::log($var); } }
public function add($id, $resource) { if (is_string($id) && !empty($id)) { $this->collection[$id] = $resource; asort($this->collection); CrayonLog::debug('Added resource: ' . $this->path($id)); } else { CrayonLog::syslog('Could not add resource: ', $id); } }
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'); } }
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 ''; } }
private function load_attr_file($path) { if (($lines = CrayonUtil::lines($path, 'lwc')) !== FALSE) { $attributes = array(); // key = language id, value = array of attr foreach ($lines as $line) { preg_match('#^[\\t ]*([^\\r\\n\\t ]+)[\\t ]+([^\\r\\n]+)#', $line, $matches); if (count($matches) == 3 && ($lang = $this->get($matches[1]))) { // If the langauges of the attribute exists, return it in an array // TODO merge instead of replace key? $attributes[$matches[1]] = explode(' ', $matches[2]); } } return $attributes; } else { CrayonLog::syslog('Could not load attr file: ' . $path); return FALSE; } }
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 function add_default() { if (!$this->is_state_loading()) { return FALSE; } else { if (!$this->is_loaded($this->default_id)) { CrayonLog::syslog('The default resource could not be loaded from \'' . $this->dir . '\'.'); // Add the default, but it will not be functionable $default = $this->resource_instance($this->default_id, $this->default_name); $this->add($this->default_id, $default); return TRUE; } } return FALSE; }
public static function post_get_excerpt($e) { CrayonLog::debug('post_get_excerpt'); self::$is_excerpt = FALSE; return $e; }