function jpcache_filewrite($filename, $data) { $return = FALSE; // Lock file, ignore warnings as we might be creating this file $fpt = @fopen($filename, "rb"); @flock($fpt, LOCK_EX); // php.net suggested I should use wb to make it work under Windows $fp = @fopen($filename, "wb+"); if (!$fp) { // Strange! We are not able to write the file! jpcache_debug("Failed to open for write of {$filename}"); } else { fwrite($fp, $data, strlen($data)); fclose($fp); $return = TRUE; } // Release lock @flock($fpt, LOCK_UN); @fclose($fpt); // Return return $return; }
function do_txp_logging() { global $txpcfg, $prefs, $siteurl, $DB; if ($txpcfg == '') { jpcache_debug('Txp-logging disabled. Include jpcache after config.php.'); return; } include $txpcfg['txpath'] . '/lib/txplib_db.php'; $prefs = get_prefs(); $siteurl = $prefs['siteurl']; if ($prefs['logging'] == 'refer') { $this->logit('refer'); } elseif ($prefs['logging'] == 'all') { $this->logit(); } jpcache_debug('Logged hit per txp-configuration.'); }
function jpcache_end($contents) { jpcache_debug("Callback happened"); $datasize = strlen($contents); $datacrc = crc32($contents); if ($GLOBALS["JPCACHE_USE_GZIP"]) { $gzdata = gzcompress($contents, $GLOBALS["JPCACHE_GZIP_LEVEL"]); } else { $gzdata = $contents; } // If the connection was aborted, do not write the cache. // We don't know if the data we have is valid, as the user // has interupted the generation of the page. // Also check if jpcache is not disabled if (!connection_aborted() && $GLOBALS["JPCACHE_ON"] && $GLOBALS["JPCACHE_TIME"] >= 0) { jpcache_debug("Writing cached data to storage"); // write the cache with the current data jpcache_write($gzdata, $datasize, $datacrc); } // Handle type-specific additional code if required jpcache_do_end(); // Return flushed data return jpcache_flush($gzdata, $datasize, $datacrc); }