/** * Internal function for making link to cache * * @return String containing an HTML tag reference to given reference */ protected function _cache_url($filename) { // build link from cache url + cache filename return Minimee_helper::remove_double_slashes($this->config->cache_url . '/' . $filename, TRUE); }
/** * Internal function for writing cache files * [Adapted from CodeIgniter Carabiner library] * * @param String of contents of the new file * @return boolean Returns true on successful cache, false on failure */ protected function _write_cache($file_data) { if ($this->EE->extensions->active_hook('minimee_pre_write_cache')) { Minimee_helper::log('Hook `minimee_pre_write_cache` has been activated.', 3); // pass contents of file, and instance of self $file_data = $this->EE->extensions->call('minimee_pre_write_cache', $file_data, $this); if ($this->EE->extensions->end_script === TRUE) { return; } } $filepath = Minimee_helper::remove_double_slashes($this->config->cache_path . '/' . $this->cache_filename); $success = file_put_contents($filepath, $file_data); if ($success === FALSE) { throw new Exception('There was an error writing cache file ' . $this->cache_filename . ' to ' . $this->config->cache_path); } if ($success === 0) { Minimee_helper::log('The new cache file is empty.', 2); } // borrowed from /system/expressionengine/libraries/Template.php // FILE_READ_MODE is set in /system/expressionengine/config/constants.php @chmod($filepath, FILE_READ_MODE); Minimee_helper::log('Cache file `' . $this->cache_filename . '` was written to ' . $this->config->cache_path, 3); // creating the compressed file if ($this->config->is_yes('save_gz')) { $z_file = gzopen($filepath . '.gz', 'w9'); gzwrite($z_file, $file_data); gzclose($z_file); @chmod($filepath . '.gz', FILE_READ_MODE); Minimee_helper::log('Gzipped file `' . $this->cache_filename . '.gz` was written to ' . $this->config->cache_path, 3); } // Do we need to clean up expired caches? if ($this->config->is_yes('cleanup')) { if ($handle = opendir($this->config->cache_path)) { while (false !== ($file = readdir($handle))) { if ($file == '.' || $file == '..' || $file === $this->cache_filename) { continue; } // matches should be deleted if (strpos($file, $this->cache_filename_hash) === 0) { @unlink($this->config->cache_path . '/' . $file); Minimee_helper::log('Cache file `' . $this->cache_filename . '` has expired. File deleted.', 3); } } closedir($handle); } } // free memory where possible unset($filepath, $z_file, $success); }
/** * Sanitise an individual setting * * @param string Name of setting * @param string potential value of setting * @return string Sanitised setting */ public function sanitise_setting($setting, $value) { switch ($setting) { /* Booleans default NO */ case 'cleanup': case 'disable': case 'minify_html': case 'save_gz': return ($value === TRUE or preg_match('/1|true|on|yes|y/i', $value)) ? 'yes' : 'no'; break; /* Booleans default YES */ /* Booleans default YES */ case 'combine_css': case 'combine_js': case 'css_prepend_mode': case 'minify_css': case 'minify_js': return ($value === FALSE or preg_match('/0|false|off|no|n/i', $value)) ? 'no' : 'yes'; break; /* ENUM */ /* ENUM */ case 'hash_method': return preg_match('/sha1|md5|sanitize|sanitise/i', $value) ? $value : 'sha1'; break; case 'remote_mode': return preg_match('/auto|curl|fgc/i', $value) ? $value : 'auto'; break; case 'js_library': return preg_match('/jsmin|jsminplus/i', $value) ? $value : 'jsmin'; break; case 'css_library': return preg_match('/cssmin|minify/i', $value) ? $value : 'minify'; break; /* String - Paths */ /* String - Paths */ case 'cache_path': case 'base_path': return rtrim(Minimee_helper::remove_double_slashes($value), '/'); break; /* String - URLs */ /* String - URLs */ case 'cache_url': case 'base_url': case 'css_prepend_url': return rtrim(Minimee_helper::remove_double_slashes($value, TRUE), '/'); break; /* Default */ /* Default */ default: return $value; break; } }