function writeEvent($type, $data) { if ('php-error' === $type || 'php-exception' === $type) { \Patchwork::setMaxage(0); \Patchwork::setExpires('onmaxage'); $GLOBALS['patchwork_private'] = true; } if ($this->isFirstEvent) { // http://bugs.php.net/42098 workaround class_exists('Patchwork\\PHP\\Walker') || eval(';') || __autoload('Patchwork\\PHP\\Walker'); class_exists('Patchwork\\PHP\\Dumper') || eval(';') || __autoload('Patchwork\\PHP\\Dumper'); class_exists('Patchwork\\PHP\\JsonDumper') || eval(';') || __autoload('Patchwork\\PHP\\JsonDumper'); $data['patchwork'] = array('i18n' => PATCHWORK_I18N, 'debug' => DEBUG, 'turbo' => Superloader::$turbo, 'level' => PATCHWORK_PATH_LEVEL, 'zcache' => PATCHWORK_ZCACHE, 'paths' => $GLOBALS['patchwork_path']); } return parent::writeEvent($type, $data); }
static function render($agent, $liveAgent) { $config_maxage = $CONFIG['maxage']; // Get the calling URI if (isset($_COOKIE['R$'])) { p::$uri = $_COOKIE['R$']; setcookie('R$', '', 1, '/'); // Check the Referer header // T$ starts with 2 when the Referer's confidence is unknown // 1 when it is trusted if (isset($_SERVER['HTTP_REFERER']) && $_COOKIE['R$'] === $_SERVER['HTTP_REFERER']) { if (class_exists('SESSION', false)) { $_COOKIE['T$'] = '1'; s::regenerateId(); } else { self::$antiCsrfToken[0] = '1'; setcookie('T$', self::$antiCsrfToken, 0, $CONFIG['session.cookie_path'], $CONFIG['session.cookie_domain']); } } } else { p::$uri = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : p::$base; } if ($liveAgent) { // The output is both html and js, but iframe transport layer needs html p::$binaryMode = true; header('Content-Type: text/html'); echo '/*<script>/**/q="'; } else { echo 'w('; } p::openMeta($agent); try { if (isset($_GET['T$']) && !p::$antiCsrfMatch) { throw new e\PrivateResource(); } $a = new $agent($_GET); $group = p::closeGroupStage(); if ($is_cacheable = 'POST' !== $_SERVER['REQUEST_METHOD'] && !in_array('private', $group)) { $cagent = p::agentCache($agent, $a->get, 'js.ser', $group); $dagent = p::getContextualCachePath('jsdata.' . $agent, 'js.ser', $cagent); if ($liveAgent) { if (file_exists($dagent)) { if (filemtime($dagent) > $_SERVER['REQUEST_TIME']) { $data = unserialize(file_get_contents($dagent)); p::setMaxage($data['maxage']); p::setExpires($data['expires']); p::writeWatchTable($data['watch']); array_map('header', $data['headers']); p::closeMeta(); echo str_replace(array('\\', '"', '</'), array('\\\\', '\\"', '<\\/'), $data['rawdata']), '"//</script><script src="' . p::__BASE__() . 'js/QJsrsHandler"></script>'; return; } else { @(unlink($cagent) + unlink($dagent)); } } } else { if (file_exists($cagent)) { if (filemtime($cagent) > $_SERVER['REQUEST_TIME']) { $data = unserialize(file_get_contents($cagent)); p::setMaxage($data['maxage']); p::setExpires($data['expires']); p::writeWatchTable($data['watch']); array_map('header', $data['headers']); p::closeMeta(); echo $data['rawdata']; return; } else { @(unlink($cagent) + unlink($dagent)); } } } } ob_start(); ++p::$ob_level; try { $data = (object) $a->compose((object) array()); if (!p::$is_enabled) { p::closeMeta(); return; } $template = $a->getTemplate(); echo '{'; $comma = ''; foreach ($data as $key => $value) { $key = jsquote($key); is_string($key) || ($key = "'" . $key . "'"); echo $comma, $key, ':'; if ($value instanceof \loop) { self::writeAgent($value); } else { echo jsquote($value); } $comma = ','; } echo '}'; } catch (e\PrivateResource $data) { ob_end_clean(); --p::$ob_level; p::closeMeta(); throw $data; } $data = ob_get_clean(); --p::$ob_level; $a->metaCompose(); list($maxage, $group, $expires, $watch, $headers) = p::closeMeta(); } catch (e\PrivateResource $data) { if ($liveAgent) { echo 'false";(window.E||alert)("You must provide an auth token to get this liveAgent:\\n"+', jsquote($_SERVER['REQUEST_URI']), ')'; echo '//</script><script src="' . p::__BASE__() . 'js/QJsrsHandler"></script>'; } else { if ($data->getMessage()) { echo 'w.r(0,' . (int) (!DEBUG) . '));'; } else { echo ');window.E&&E("You must provide an auth token to get this agent:\\n"+', jsquote($_SERVER['REQUEST_URI']), ')'; } } exit; } if ($liveAgent) { echo str_replace(array('\\', '"', '</'), array('\\\\', '\\"', '<\\/'), $data), '"//</script><script src="' . p::__BASE__() . 'js/QJsrsHandler"></script>'; } else { echo $data; } if ('ontouch' === $expires && !($watch || $config_maxage == $maxage)) { $expires = 'auto'; } $expires = 'auto' === $expires && ($watch || $config_maxage == $maxage) ? 'ontouch' : 'onmaxage'; $is_cacheable = $is_cacheable && !in_array('private', $group) && ($maxage || 'ontouch' === $expires); if (!$liveAgent || $is_cacheable) { if ($is_cacheable) { ob_start(); } if ($config_maxage == $maxage && Superloader::$turbo) { $ctemplate = p::getContextualCachePath("templates/{$template}", 'txt'); $readHandle = true; if ($h = p::fopenX($ctemplate, $readHandle)) { p::openMeta('agent__template/' . $template, false); $template = new \ptlCompiler_js($template); echo $template = ',' . $template->compile() . ')'; fwrite($h, $template); flock($h, LOCK_UN); fclose($h); list(, , , $template) = p::closeMeta(); p::writeWatchTable($template, $ctemplate); } else { fpassthru($readHandle); flock($readHandle, LOCK_UN); fclose($readHandle); } $watch[] = 'public/templates/js'; } else { echo ',[1,', jsquote($template), ',0,0,0])'; } if ($is_cacheable) { $ob = true; $template = array('maxage' => $maxage, 'expires' => $expires, 'watch' => $watch, 'headers' => $headers, 'rawdata' => $data); $expires = 'ontouch' === $expires ? $config_maxage : $maxage; if ($h = p::fopenX($dagent)) { fwrite($h, serialize($template)); flock($h, LOCK_UN); fclose($h); touch($dagent, $_SERVER['REQUEST_TIME'] + $expires); p::writeWatchTable($watch, $dagent); } if ($h = p::fopenX($cagent)) { $ob = false; $template['rawdata'] .= $liveAgent ? ob_get_clean() : ob_get_flush(); fwrite($h, serialize($template)); flock($h, LOCK_UN); fclose($h); touch($cagent, $_SERVER['REQUEST_TIME'] + $expires); p::writeWatchTable($watch, $cagent); } if ($ob) { $liveAgent ? ob_end_clean() : ob_end_flush(); } } } }
static function php($string) { Patchwork::setMaxage(1); Patchwork::setExpires('onmaxage'); return $_SERVER['REQUEST_TIME']; }
function metaCompose() { p::setMaxage($this->maxage); p::setExpires($this->expires); p::watch($this->watch); if ($this->canPost) { p::canPost(); } }
protected static function getFromCache($cagent) { if (!file_exists($cagent)) { $cagent = substr($cagent, 0, -4) . '.post' . substr($cagent, -4); if ('POST' === $_SERVER['REQUEST_METHOD'] || !file_exists($cagent)) { $cagent = false; } } if ($cagent) { if (filemtime($cagent) > $_SERVER['REQUEST_TIME']) { $data = unserialize(file_get_contents($cagent)); p::setMaxage($data['maxage']); p::setExpires($data['expires']); p::writeWatchTable($data['watch']); array_map('header', $data['headers']); echo $data['rawdata']; return array((object) $data['v'], $data['template']); } else { unlink($cagent); } } return false; }