static function php($string, $urlInterpolation = false) { $string = (string) $string; false !== strpos($string, '&') && ($string = str_replace(array(''', '"', '>', '<', '&'), array("'", '"', '>', '<', '&'), $string)); $urlInterpolation && false !== strpos($string, '{') && ($string = str_replace(array('{/}', '{~}'), array(Patchwork::__HOST__(), Patchwork::__BASE__()), $string)); return $string; }
static function php($text, $url = '', $attributes = '') { $url = (string) $url; $a = strpos($url, '#'); if (false !== $a) { $hash = substr($url, $a); $url = substr($url, 0, $a); } else { $hash = ''; } return $url == htmlspecialchars(substr(Patchwork::__HOST__() . substr($_SERVER['REQUEST_URI'], 1), strlen(Patchwork::__BASE__()))) ? '<b class="linkloop">' . $text . '</b>' : '<a href="' . Patchwork::base($url, true) . $hash . '" ' . $attributes . '>' . $text . '</a>'; }
protected static function get_html(&$value, &$args) { $a = array(); if ($result = self::get_text($value, $a)) { $result = self::sanitizeHtml($result); $a = strip_tags($result); $a = html_entity_decode($a, ENT_COMPAT, 'UTF-8'); $a = preg_replace('/^[\\s\\pZ]+/u', '', $a); if ('' === $a) { $result = ''; } else { $result = preg_replace("'[ \t]+\$'m", '', trim($result)); $result = preg_replace("'\n{3,}'", "\n\n", $result); $result = preg_replace("'(?<!>)\n\n'", "<br>\n<br>\n", $result); $result = preg_replace("'(?<!>)\n'", "<br>\n", $result); $result = str_replace(array('{~}', '{/}', Patchwork::__BASE__(), Patchwork::__HOST__()), array('{~}', '{/}', '{~}', '{/}'), $result); } } return $result; }
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; } }