Exemplo n.º 1
0
 static function compose($o)
 {
     $o->jquery_ui_theme = self::$uiTheme;
     $uiLoad = trim(self::$uiLoad);
     if ('' !== $uiLoad) {
         $uiLoad = explode(' ', $uiLoad);
         while (list(, $v) = each($uiLoad)) {
             $o->{strtr($v, '.', '_')} = 1;
             if (isset(self::$uiDependency[$v])) {
                 $v = self::$uiDependency[$v];
                 foreach (explode(' ', $v) as $v) {
                     $v && ($uiLoad[] = $v);
                 }
             }
         }
     }
     if (!empty($o->ui_datepicker)) {
         $lang = Patchwork::__LANG__();
         if (isset(self::$langMap[$lang])) {
             $lang = self::$langMap[$lang];
         } else {
             if (!in_array($lang, explode(' ', self::$langAvail))) {
                 $lang = substr($lang, 0, 2);
                 if (!in_array($lang, explode(' ', self::$langAvail))) {
                     $lang = '';
                 }
             }
         }
         $lang && ($o->ui_datepicker_lang = $lang);
     }
     return $o;
 }
Exemplo n.º 2
0
 protected function prepare()
 {
     if (PATCHWORK_I18N) {
         $this->lang = Patchwork::__LANG__();
         if (!isset($this->alt)) {
             $a = array();
             $base = preg_quote($_SERVER['PATCHWORK_BASE'], "'");
             $base = explode('__', $base, 2);
             $base[1] = '/' === $base[1] ? '[^?/]+(/?)' : ".+?({$base[1]})";
             $base = "'^({$base[0]}){$base[1]}(.*)\$'D";
             if (preg_match($base, Patchwork::__URI__(), $base)) {
                 unset($base[0]);
                 foreach ($GLOBALS['CONFIG']['i18n.lang_list'] as $k => $v) {
                     if ('' === $k) {
                         continue;
                     }
                     $v = $base[1] . $v . $base[2] . ($this->lang === $k ? $base[3] : Patchwork::translateRequest($base[3], $k));
                     $a[] = (object) array('lang' => $k, 'title' => isset(self::$nativeLang[$k]) ? self::$nativeLang[$k] : $k, 'href' => $v);
                 }
             } else {
                 user_error('Something is wrong between Patchwork::__URI__() and PATCHWORK_BASE');
             }
             $this->alt =& $a;
         }
         return count($this->alt);
     } else {
         return 0;
     }
 }
Exemplo n.º 3
0
 function __construct($headers, $options)
 {
     $this->agent = $options['agent'];
     $this->args = $options['args'];
     $this->lang = isset($options['lang']) ? $options['lang'] : p::__LANG__();
     parent::__construct($headers, $options);
 }
Exemplo n.º 4
0
    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;
    }
 protected function evalVar($a, $translate = false, $forceType = false)
 {
     if ('' === $a) {
         return "''";
     }
     if ('~' === $a) {
         $a = 'g$__BASE__';
     }
     if ('/' === $a) {
         $a = 'g$__HOST__';
     }
     if ('"' === $a[0] || "'" === $a[0]) {
         $b = '"' === $a[0];
         if (!$b) {
             $a = '"' . substr(preg_replace('/(?<!\\\\)((?:\\\\\\\\)*)"/su', '$1\\\\"', $a), 1, -1) . '"';
         }
         $a = preg_replace("/(?<!\\\\)\\\\((?:\\\\\\\\)*)'/su", '$1\'', $a);
         $a = preg_replace('/(?<!\\\\)((\\\\?)(?:\\\\\\\\)*)\\$/su', '$1$2\\\\$', $a);
         $a = eval("return {$a};");
         if ($b && '' !== trim($a)) {
             if ($translate) {
                 $a = TRANSLATOR::get($a, Patchwork::__LANG__(), false);
                 /**/
                 if (DEBUG) {
                     Patchwork::watch('debugSync');
                 }
             } else {
                 $this->mode = 'concat';
                 $this->concat = array('');
                 $this->concatLast = 0;
                 $this->makeVars($a);
                 if (!$this->concatLast) {
                     $this->concat[0] = TRANSLATOR::get($this->concat[0], Patchwork::__LANG__(), false);
                     /**/
                     if (DEBUG) {
                         Patchwork::watch('debugSync');
                     }
                 }
                 for ($i = 0; $i <= $this->concatLast; $i += 2) {
                     if ('' !== $this->concat[$i]) {
                         $this->concat[$i] = $this->makeVar("'" . $this->concat[$i]);
                     } else {
                         unset($this->concat[$i]);
                     }
                 }
                 $this->mode = 'echo';
                 return count($this->concat) > 1 ? $this->getConcat($this->concat) : current($this->concat);
             }
         }
         $a = "'" . $a;
     } else {
         if (preg_match("/^{$this->Xnumber}\$/su", $a)) {
             $a = eval("return \"'\" . {$a};");
         } else {
             if (!preg_match("/^(?:{$this->Xvar}|[dag]\\\$|\\\$+)\$/su", $a)) {
                 $a = preg_split("/({$this->Xvar}|{$this->Xnumber})/su", $a, -1, PREG_SPLIT_DELIM_CAPTURE);
                 $i = 1;
                 $len = count($a);
                 while ($i < $len) {
                     $a[$i - 1] = trim($a[$i - 1]);
                     $b = $i > 1 && '-' === $a[$i][0] && '' === $a[$i - 1];
                     $a[$i] = $this->evalVar($a[$i], false, 'number');
                     if ($b && '0' === $a[$i]) {
                         $a[$i - 1] = '-';
                     }
                     $i += 2;
                 }
                 $a = implode($a);
                 return $a;
             }
         }
     }
     return $this->makeVar($a, $forceType);
 }
Exemplo n.º 6
0
 function T($string, $lang = false)
 {
     if (!$lang) {
         $lang = Patchwork::__LANG__();
     }
     return TRANSLATOR::get($string, $lang, true);
 }
Exemplo n.º 7
0
 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('&gt;', '&lt;', '&quot;', '&#039;', '&amp;'), 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;
     }
 }