<?php /** * Compact semalt-blocker for non-composer installs */ require_once './../vendor/technosophos/PHPCompressor/src/lib/compactor.php'; $source = "./sources.php"; $target = "./../compact/semaltblocker.php"; print "Compacting semalt-blocker"; $compactor = new Compactor($target); // Use filters like this (Useable for things like stripping debug-only logging): $compactor->setFilter(function ($in) { $in = preg_replace('/require "\\.\\/\\.\\.\\/src\\/Domainparser\\.php";/', '', $in); $in = preg_replace('/require "\\.\\/\\.\\.\\/src\\/SemaltUpdater\\.php";/', '', $in); $in = preg_replace('/require "\\.\\/\\.\\.\\/src\\/Semalt\\.php";/', '', $in); $in = str_replace("'./../domains/blocked'", "'blocked'", $in); return $in; }); $compactor->compactAll($source); $compactor->report(); $compactor->close();
public function compact($output, $options = null) { $options = $options ? array_merge($this->options, $options) : $this->options; $compactor = new Compactor($options); return $compactor->squeeze($output); }
/** * Write Cache * * @param string $output Output data to cache * @return void */ public function _write_cache($output) { $CI =& get_instance(); $path = $CI->config->item('cache_path'); $cache_path = $path === '' ? APPPATH . 'cache/' : $path; if (!is_dir($cache_path) or !is_really_writable($cache_path)) { log_message('error', 'Unable to write cache file: ' . $cache_path); return; } $uri = $CI->config->item('base_url') . $CI->config->item('index_page') . $CI->uri->uri_string(); if (($cache_query_string = $CI->config->item('cache_query_string')) && !empty($_SERVER['QUERY_STRING'])) { if (is_array($cache_query_string)) { $uri .= '?' . http_build_query(array_intersect_key($_GET, array_flip($cache_query_string))); } else { $uri .= '?' . $_SERVER['QUERY_STRING']; } } $cache_path .= md5($uri); if (!($fp = @fopen($cache_path, 'w+b'))) { log_message('error', 'Unable to write cache file: ' . $cache_path); return; } if (flock($fp, LOCK_EX)) { // If output compression is enabled, compress the cache // itself, so that we don't have to do that each time // we're serving it if ($this->_compress_output === TRUE) { $output = gzencode($output); if ($this->get_header('content-type') === NULL) { $this->set_content_type($this->mime_type); } } $expire = time() + $this->cache_expiration * 60; // Put together our serialized info. $cache_info = serialize(array('expire' => $expire, 'headers' => $this->headers)); $output = $cache_info . 'ENDCI--->' . $output; /** * * @var * 压缩html 待写入缓存 */ //装载调取基础设置类 $CI->load->model('setting/base_setting'); //如果启用压缩 if ($CI->base_setting->get_setting('is_compactor') == TRUE) { $compactor = new Compactor(array('buffer_echo' => false)); $output = $compactor->squeeze($output); } for ($written = 0, $length = strlen($output); $written < $length; $written += $result) { if (($result = fwrite($fp, substr($output, $written))) === FALSE) { break; } } flock($fp, LOCK_UN); } else { log_message('error', 'Unable to secure a file lock for file at: ' . $cache_path); return; } fclose($fp); if (is_int($result)) { chmod($cache_path, 0640); log_message('debug', 'Cache file written: ' . $cache_path); // Send HTTP cache-control headers to browser to match file cache settings. $this->set_cache_header($this->CI->input->server('REQUEST_TIME'), $expire); } else { @unlink($cache_path); log_message('error', 'Unable to write the complete cache content at: ' . $cache_path); } }
<?php /** * Compact semalt-blocker for non-composer installs */ require_once './../vendor/technosophos/PHPCompressor/src/lib/compactor.php'; $source = "./sources.php"; $target = "./../compact/semaltblocker.php"; print "Compacting semalt-blocker"; $compactor = new Compactor($target); // Use filters like this (Useable for things like stripping debug-only logging): $compactor->setFilter(function ($in) { $in = str_replace('require "./../vendor/true/punycode/src/Punycode.php";', '', $in); $in = str_replace('require "./../src/SemaltBlocker/Domainparser.php";', '', $in); $in = str_replace('require "./../src/SemaltBlocker/Updater.php";', '', $in); $in = str_replace('require "./../src/SemaltBlocker/Blocker.php";', '', $in); $in = str_replace("'./../../domains/blocked'", "'blocked'", $in); return $in; }); $compactor->compactAll($source); $compactor->report(); $compactor->close(); print "Testing test.php output:" . PHP_EOL; passthru('php ./../compact/test.php');