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 function __construct() { $this->set_default(self::DEFAULT_LANG, self::DEFAULT_LANG_NAME); $this->directory(CRAYON_LANG_PATH); $this->relative_directory(CRAYON_LANG_DIR); $this->extension('txt'); CrayonLog::debug("Setting lang directories"); $upload = CrayonGlobalSettings::upload_path(); if ($upload) { $this->user_directory($upload . CRAYON_LANG_DIR); if (!is_dir($this->user_directory())) { CrayonGlobalSettings::mkdir($this->user_directory()); CrayonLog::debug($this->user_directory(), "LANG USER DIR"); } } else { CrayonLog::syslog("Upload directory is empty: " . $upload . " cannot load languages."); } CrayonLog::debug($this->directory()); CrayonLog::debug($this->user_directory()); }
public static function load_settings($just_load_settings = FALSE) { if (self::$options === NULL) { // Load settings from db if (!(self::$options = get_option(self::OPTIONS))) { self::$options = CrayonSettings::get_defaults_array(); update_option(self::OPTIONS, self::$options); } // Initialise default global settings and update them from db CrayonGlobalSettings::set(self::$options); } if (!self::$is_fully_loaded && !$just_load_settings) { // Load everything else as well // For local file loading // This is used to decouple WP functions from internal Crayon classes CrayonGlobalSettings::site_url(home_url()); CrayonGlobalSettings::site_path(ABSPATH); CrayonGlobalSettings::plugin_path(plugins_url('', __FILE__)); $upload = wp_upload_dir(); CrayonLog::debug($upload, "WP UPLOAD FUNCTION"); CrayonGlobalSettings::upload_path(CrayonUtil::path_slash($upload['basedir']) . CRAYON_DIR); CrayonGlobalSettings::upload_url($upload['baseurl'] . '/' . CRAYON_DIR); CrayonLog::debug(CrayonGlobalSettings::upload_path(), "UPLOAD PATH"); CrayonGlobalSettings::set_mkdir('wp_mkdir_p'); // Load all available languages and themes CrayonResources::langs()->load(); CrayonResources::themes()->load(); // Ensure all missing settings in db are replaced by default values $changed = FALSE; foreach (CrayonSettings::get_defaults_array() as $name => $value) { // Add missing settings if (!array_key_exists($name, self::$options)) { self::$options[$name] = $value; $changed = TRUE; } } // A setting was missing, update options if ($changed) { update_option(self::OPTIONS, self::$options); } self::$is_fully_loaded = TRUE; } }
public static function post_get_excerpt($e) { CrayonLog::debug('post_get_excerpt'); self::$is_excerpt = FALSE; return $e; }
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 parse($id) { // Verify the language is loaded and has not been parsed before if (!($lang = CrayonResources::langs()->get($id))) { CrayonLog::syslog("The language with id '{$id}' was not loaded and could not be parsed."); return FALSE; } else { if ($lang->is_parsed()) { return; } } // Read language file $path = CrayonResources::langs()->path($id); CrayonLog::debug('Parsing language ' . $path); if (($file = CrayonUtil::lines($path, 'wcs')) === FALSE) { CrayonLog::debug('Parsing failed ' . $path); return FALSE; } // Extract the language name $name_pattern = '#^[ \\t]*name[ \\t]+([^\\r\\n]+)[ \\t]*#mi'; preg_match($name_pattern, $file, $name); if (count($name) > 1) { $name = $name[1]; $lang->name($name); $file = preg_replace($name_pattern, '', $file); } else { $name = $lang->id(); } // Extract the language version $version_pattern = '#^[ \\t]*version[ \\t]+([^\\r\\n]+)[ \\t]*#mi'; preg_match($version_pattern, $file, $version); if (count($version) > 1) { $version = $version[1]; $lang->version($version); $file = preg_replace($version_pattern, '', $file); } // Extract the modes $mode_pattern = '#^[ \\t]*(' . implode('|', array_keys(self::$modes)) . ')[ \\t]+(?:=[ \\t]*)?([^\\r\\n]+)[ \\t]*#mi'; preg_match_all($mode_pattern, $file, $mode_matches); if (count($mode_matches) == 3) { for ($i = 0; $i < count($mode_matches[0]); $i++) { $lang->mode($mode_matches[1][$i], $mode_matches[2][$i]); } $file = preg_replace($mode_pattern, '', $file); } /* Add reserved Crayon element. This is used by Crayon internally. */ $crayon_element = new CrayonElement(self::CRAYON_ELEMENT, $path, self::CRAYON_ELEMENT_REGEX); $lang->element(self::CRAYON_ELEMENT, $crayon_element); // Extract elements, classes and regex $pattern = '#^[ \\t]*([\\w:]+)[ \\t]+(?:\\[([\\w\\t ]*)\\][ \\t]+)?([^\\r\\n]+)[ \\t]*#m'; preg_match_all($pattern, $file, $matches); if (!empty($matches[0])) { $elements = $matches[1]; $classes = $matches[2]; $regexes = $matches[3]; } else { CrayonLog::syslog("No regex patterns and/or elements were parsed from language file at '{$path}'."); } // Remember state in case we encounter catchable exceptions $error = FALSE; for ($i = 0; $i < count($matches[0]); $i++) { // References $name =& $elements[$i]; $class =& $classes[$i]; $regex =& $regexes[$i]; $name = trim(strtoupper($name)); // Ensure both the element and regex are valid if (empty($name) || empty($regex)) { CrayonLog::syslog("Element(s) and/or regex(es) are missing in '{$path}'."); $error = TRUE; continue; } // Look for fallback element $pieces = explode(':', $name); if (count($pieces) == 2) { $name = $pieces[0]; $fallback = $pieces[1]; } else { if (count($pieces) == 1) { $name = $pieces[0]; $fallback = ''; } else { CrayonLog::syslog("Too many colons found in element name '{$name}' in '{$path}'"); $error = TRUE; continue; } } // Create a new CrayonElement $element = new CrayonElement($name, $path); $element->fallback($fallback); if (!empty($class)) { // Avoid setting known css to blank $element->css($class); } if ($element->regex($regex) === FALSE) { $error = TRUE; continue; } // Add the regex to the element $lang->element($name, $element); $state = $error ? CrayonLang::PARSED_ERRORS : CrayonLang::PARSED_SUCCESS; $lang->state($state); } /* Prevents < > and other html entities from being printed as is, which could lead to actual html tags * from the printed code appearing on the page - not good. This can also act to color any HTML entities * that are not picked up by previously defined elements. */ $html = new CrayonElement(self::HTML_CHAR, $path, self::HTML_CHAR_REGEX); $lang->element(self::HTML_CHAR, $html); }