private function load() { if (empty($this->url)) { $this->error('The specified URL is empty, please provide a valid URL.'); return; } // Try to replace the URL with an absolute path if it is local, used to prevent scripts // from executing when they are loaded. $url = $this->url; if ($this->setting_val(CrayonSettings::DECODE_ATTRIBUTES)) { $url = CrayonUtil::html_entity_decode($url); } $url = CrayonUtil::pathf($url); $site_http = CrayonGlobalSettings::site_url(); $scheme = parse_url($url, PHP_URL_SCHEME); // Try to replace the site URL with a path to force local loading if (empty($scheme)) { // No url scheme is given - path may be given as relative $url = CrayonUtil::path_slash($site_http) . CrayonUtil::path_slash($this->setting_val(CrayonSettings::LOCAL_PATH)) . $url; } $http_code = 0; // If available, use the built in wp remote http get function. if (function_exists('wp_remote_get')) { $url_uid = 'crayon_' . CrayonUtil::str_uid($url); $cached = get_transient($url_uid, 'crayon-syntax'); CrayonSettingsWP::load_cache(); if ($cached !== FALSE) { $content = $cached; $http_code = 200; } else { $response = @wp_remote_get($url, array('sslverify' => false, 'timeout' => 20)); $content = wp_remote_retrieve_body($response); $http_code = wp_remote_retrieve_response_code($response); $cache = $this->setting_val(CrayonSettings::CACHE); $cache_sec = CrayonSettings::get_cache_sec($cache); if ($cache_sec > 1 && $http_code >= 200 && $http_code < 400) { set_transient($url_uid, $content, $cache_sec); CrayonSettingsWP::add_cache($url_uid); } } } else { if (in_array(parse_url($url, PHP_URL_SCHEME), array('ssl', 'http', 'https'))) { // Fallback to cURL. At this point, the URL scheme must be valid. $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // For https connections, we do not require SSL verification curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($ch, CURLOPT_FRESH_CONNECT, FALSE); curl_setopt($ch, CURLOPT_MAXREDIRS, 5); if (isset($_SERVER['HTTP_USER_AGENT'])) { curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); } $content = curl_exec($ch); $error = curl_error($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); } } if ($http_code >= 200 && $http_code < 400) { $this->code($content); } else { if (empty($this->code)) { // If code is also given, just use that $this->error("The provided URL ('{$this->url}'), parsed remotely as ('{$url}'), could not be accessed."); } } $this->needs_load = FALSE; }
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 function dirurl($user = NULL) { $path = $user ? CrayonGlobalSettings::upload_url() : CrayonGlobalSettings::plugin_path(); return CrayonUtil::path_slash($path . $this->relative_directory()); }
public function filename($id, $user = NULL) { return CrayonUtil::path_slash($id) . parent::filename($id, $user); }
public static function plugin_path($plugin_path = NULL) { if ($plugin_path === NULL) { return self::$plugin_path; } else { self::$plugin_path = CrayonUtil::path_slash($plugin_path); } }
/** * @param $path A directory * @param array $args Argument array: * hidden: If true, hidden files beginning with a dot will be included * ignoreRef: If true, . and .. are ignored * recursive: If true, this function is recursive * ignore: An array of paths to ignore * @return array Files in the directory */ public static function getFiles($path, $args = array()) { $hidden = self::set_default($args['hidden'], TRUE); $ignoreRef = self::set_default($args['ignoreRef'], TRUE); $recursive = self::set_default($args['recursive'], FALSE); $ignore = self::set_default($args['ignore'], NULL); $ignore_map = array(); if ($ignore) { foreach ($ignore as $i) { if (is_dir($i)) { $i = CrayonUtil::path_slash($i); } $ignore_map[$i] = TRUE; } } $files = glob($path . '*', GLOB_MARK); if ($hidden) { $files = array_merge($files, glob($path . '.*', GLOB_MARK)); } if ($ignoreRef || $ignore) { $result = array(); for ($i = 0; $i < count($files); $i++) { $file = $files[$i]; if (!isset($ignore_map[$file]) && (!$ignoreRef || basename($file) != '.' && basename($file) != '..')) { $result[] = $file; if ($recursive && is_dir($file)) { $result = array_merge($result, self::getFiles($file, $args)); } } } } else { $result = $files; } return $result; }
public static function upload_path($upload_path = NULL) { if ($upload_path === NULL) { return self::$upload_path; } else { self::$upload_path = CrayonUtil::path_slash($upload_path); } }