function __construct($class) { is_string($class) && \Patchwork\Superloader::exists($class, false); // Do a lightweigh autoload parent::__construct($class); if (false !== ($parent = parent::getParentClass())) { $p = $parent->name; $top = $this->name; $i = strrpos($top, '__'); if (false !== $i && isset($top[$i + 2]) && '' === trim(substr($top, $i + 2), '0123456789')) { $this->isTop = false; $top = substr($top, 0, $i); } $top .= '__'; $i = strlen($top); while (isset($p[$i]) && $top === rtrim($p, '0123456789')) { $this->superStack[] = $parent; if (false === ($parent = $parent->getParentClass())) { break; } $p = $parent->name; } $this->superParent = $parent; } }
public final function __construct($args = array()) { $class = get_class($this); isset($this->contentType) or $this->contentType = constant($class . '::contentType'); $a = (array) $this->get; $this->get = (object) array(); $_GET = array(); foreach ($a as $key => &$a) { if (is_string($key)) { $default = $a; $a = $key; } else { $default = ''; } false !== strpos($a, "") && ($a = str_replace("", '', $a)); if (false !== strpos($a, '\\')) { $a = strtr($a, array('\\\\' => '\\', '\\:' => "")); $a = explode(':', $a); $b = count($a); do { false !== strpos($a[--$b], "") && ($a[$b] = strtr($a[$b], "", ':')); } while ($b); } else { $a = explode(':', $a); } $key = array_shift($a); $b = isset($args[$key]) ? (string) $args[$key] : $default; false !== strpos($b, "") && ($b = str_replace("", '', $b)); if ($a) { $b = FILTER::get($b, array_shift($a), $a); if (false === $b) { $b = $default; } } $_GET[$key] = $this->get->{$key} = $b; } $this->control(); if (!$this->contentType && '' !== ($a = strtolower(pathinfo(p\Superloader::class2file($class), PATHINFO_EXTENSION)))) { $this->contentType = isset(p\StaticResource::$contentType['.' . $a]) ? p\StaticResource::$contentType['.' . $a] : 'application/octet-stream'; } $this->contentType && header('Content-Type: ' . $this->contentType); }
static function loadAgent($agent) { p::setMaxage(-1); p::setPrivate(); p::setExpires('onmaxage'); $a = p::agentArgs($agent); $a = implode(',', array_map('jsquote', $a)); $agent = jsquote('agent_index' === $agent ? '' : p\Superloader::class2file(substr($agent, 6))); $lang = p::__LANG__(); $appId = p::$appId; $base = p::__BASE__(); if (PATCHWORK_I18N) { ob_start(); self::writeAgent(new \loop_altLang()); $b = substr(ob_get_clean(), 4, -1); } else { $b = '0'; } $lang = $lang ? " lang=\"{$lang}\"" : ''; $uri = p::__URI__(); $uri .= (false === strpos($uri, '?') ? '?' : '&') . 'p:=serverside'; false !== strpos($uri, '<') && ($uri = str_replace('<', '%3C', $uri)); false !== strpos($uri, '>') && ($uri = str_replace('>', '%3E', $uri)); echo $a = <<<EOHTML <!doctype html> <!--[if lt IE 7]><html{$lang} class="lt-ie9 lt-ie8 lt-ie7 ie6"><![endif]--> <!--[if IE 7]><html{$lang} class="lt-ie9 lt-ie8 ie7"><![endif]--> <!--[if IE 8]><html{$lang} class="lt-ie9 ie8"><![endif]--> <!--[if gt IE 8]><!--><html{$lang}><!--<![endif]--> <meta charset="utf-8"> <noscript><meta http-equiv="refresh" content="0; url={$uri}"></noscript> <script name="w\$">a=[{$agent},[{$a}],{$appId},{$b}]</script> <!--[if !IE]><!--><script name="w\$" src="data:text/javascript,a[4]=1"></script><!--<![endif]--> <script src="{$base}js/w?{$appId}"></script> EOHTML; }
static function send($agent) { header('Content-Type: text/javascript'); p::setMaxage(-1); echo 'w.k(', p::$appId, ',', jsquote(p::$base), ',', jsquote('agent_index' === $agent ? '' : p\Superloader::class2file(substr($agent, 6))), ',', jsquote(isset($_GET['__0__']) ? $_GET['__0__'] : ''), ',', '[', implode(',', array_map('jsquote', p::agentArgs($agent))), ']', ')'; }
static function syncCache($file, $depth) { if (0 === strpos($file, 'public/')) { p::touch('public'); p::updateAppId(); } else { if (0 === strpos($file, 'class/Patchwork/')) { self::resetCache(); } else { if (0 === strpos($file, 'class/')) { $file = p\Superloader::file2cache(substr($file, 6), $depth); @unlink($file); } } p\Debugger::purgeZcache(); } }
<?php // vi: set fenc=utf-8 ts=4 sw=4 et: #patchwork ../logger use Patchwork as p; use Patchwork\PHP\Shim as s; // Default settings $CONFIG += array('debug.allowed' => true, 'debug.password' => '', 'turbo' => false); defined('DEBUG') || define('DEBUG', $CONFIG['debug.allowed'] && (!$CONFIG['debug.password'] || isset($_COOKIE['debug_password']) && $CONFIG['debug.password'] == $_COOKIE['debug_password']) ? 1 : 0); DEBUG or error_reporting(E_ALL & ~(E_DEPRECATED | E_USER_DEPRECATED | E_STRICT)); if (p\Superloader::$turbo = !DEBUG && $CONFIG['turbo']) { spl_autoload_register(array('Patchwork\\Superloader', 'loadTurbo'), true, true); if (spl_autoload_unregister(array('Patchwork\\Superloader', 'loadAlias'))) { spl_autoload_register(array('Patchwork\\Superloader', 'loadAlias'), true, true); } } /**/ if ('\\' === DIRECTORY_SEPARATOR && !function_exists('__patchwork_file_exists')) { if (DEBUG) { // Replace file_exists() on Windows to check if character case is strict p\Shim(file_exists, s\WinfsCase, $file); p\Shim(is_file, s\WinfsCase, $file); p\Shim(is_dir, s\WinfsCase, $file); p\Shim(is_link, s\WinfsCase, $file); p\Shim(is_executable, s\WinfsCase, $file); p\Shim(is_readable, s\WinfsCase, $file); p\Shim(is_writable, s\WinfsCase, $file); } /**/ } /**/
static function loadAgent($agent, $args, $is_exo) { if (null === $agent) { return; } $a =& $_GET; if (false === $args) { $reset_get = true; $cache = ''; if ('s' === p::$requestMode) { ob_start(array(__CLASS__, 'ob_htmlspecialchars'), 32768); ++p::$ob_level; self::$get = (object) $a; } else { $args = array(); if (is_array($a)) { reset($a); while (list($k, $v) = each($a)) { $args[$k] = is_string($v) ? htmlspecialchars($v) : $v; } } self::$get = (object) $args; } self::$get->__DEBUG__ = DEBUG ? DEBUG : 0; self::$get->__HOST__ = htmlspecialchars(p::__HOST__()); $cache .= self::$get->__LANG__ = htmlspecialchars(p::__LANG__()); $cache .= self::$get->__BASE__ = htmlspecialchars(p::__BASE__()); self::$get->__AGENT__ = 'agent_index' === $agent ? '' : p\Superloader::class2file(substr($agent, 6)) . '/'; self::$get->__URI__ = htmlspecialchars(p::$uri); self::$get->__REFERER__ = isset($_SERVER['HTTP_REFERER']) ? htmlspecialchars($_SERVER['HTTP_REFERER']) : ''; self::$get->__LANG_ALT__ = new \loop_altLang(); self::$args = self::$get; if (!isset(self::$masterCache[$cache])) { self::$masterCache[$cache] = array(); } self::$cache =& self::$masterCache[$cache]; } else { $reset_get = false; $_GET =& $args; if ($agent instanceof \loop && $agent->__toString()) { $agent->autoResolve = false; while ($i = $agent->loop()) { $data = $i; } if (!(p::$binaryMode || $agent instanceof LoopFreezed)) { foreach ($data as &$v) { is_string($v) && ($v = htmlspecialchars($v)); } } $agent = $data->{'a$'}; $args = array_merge((array) $data, $args); } $BASE = p::__BASE__(); $agent = p::base($agent, true); if (0 === strncmp($agent, $BASE, strlen($BASE))) { $agent = substr($agent, strlen($BASE)); if ($is_exo) { user_error("Patchwork Security Restriction Error: an AGENT ({$agent}) is called with EXOAGENT"); $_GET =& $a; return; } } else { if ($is_exo) { $k = $CONFIG['i18n.lang_list'][p::__LANG__()]; $agent = implode($k, explode('__', $agent, 2)) . '?p:=s'; foreach ($args as $k => $v) { $agent .= '&' . urlencode($k) . '=' . urlencode($v); } if (ini_get_bool('allow_url_fopen')) { $agent = file_get_contents($agent); } else { $agent = new \HTTP_Request($agent); $agent->sendRequest(); $agent = $agent->getResponseBody(); } echo str_replace(array('>', '<', '"', ''', '&'), array('>', '<', '"', "'", '&'), $agent); } else { user_error("Patchwork Security Restriction Error: an EXOAGENT ({$agent}) is called with AGENT"); } $_GET =& $a; return; } try { $agent = p::resolveAgentClass($agent, $args); } catch (e\StaticResource $agent) { readfile($agent->getMessage()); $_GET =& $a; return; } self::$args = (object) $args; } self::render($agent); $_GET =& $a; if ($reset_get) { self::$get = false; } }
protected function tagRequire(&$token) { // Every require|include inside files in the include_path // is preprocessed thanks to Patchwork\Superloader::getProcessedPath(). if (\Patchwork\Superloader::$turbo && $this->dependencies['ConstantExpression']->nextExpressionIsConstant() && false !== ($a = \Patchwork\Superloader::getProcessedPath($this->expressionValue, true))) { $token =& $this->getNextToken(); $token[1] = ' ' . self::export($a) . str_repeat("\n", substr_count($token[1], "\n")); } else { parent::tagRequire($token); } }