static function resolve($agent)
 {
     static $cache = array();
     if (isset($cache[$agent])) {
         return $cache[$agent];
     } else {
         $cache[$agent] =& $trace;
     }
     $args = array();
     $BASE = p::__BASE__();
     $agent = rawurlencode($agent);
     $agent = str_replace(array('%21', '%7E', '%2A', '%28', '%29', '%2C', '%2F', '%3A', '%40', '%24', '%3B'), array('!', '~', '*', '(', ')', ',', '/', ':', '@', '$', ';'), $agent);
     $agent = p::base($agent, true);
     $agent = preg_replace("'^.*?://[^/]*'", '', $agent);
     $h = patchwork_http_socket($_SERVER['SERVER_ADDR'], $_SERVER['SERVER_PORT'], isset($_SERVER['HTTPS']));
     $keys = p::$lang;
     $keys = "GET {$agent}?p:=k:{$keys} HTTP/1.0\r\n";
     $keys .= "Host: {$_SERVER['HTTP_HOST']}\r\n";
     $keys .= "Connection: close\r\n\r\n";
     fwrite($h, $keys);
     $keys = array();
     while (false !== ($a = fgets($h))) {
         $keys[] = $a;
     }
     fclose($h);
     $h = '\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*\'';
     $h = "/w\\.k\\((-?[0-9]+),({$h}),({$h}),({$h}),\\[((?:{$h}(?:,{$h})*)?)\\]\\)/su";
     if (!preg_match($h, implode('', $keys), $keys)) {
         user_error('Error while getting meta info data for ' . htmlspecialchars($agent));
         p::disable(true);
     }
     $appId = (int) $keys[1];
     $base = stripcslashes(substr($keys[2], 1, -1));
     $agent = stripcslashes(substr($keys[3], 1, -1));
     $a = stripcslashes(substr($keys[4], 1, -1));
     $keys = eval('return array(' . $keys[5] . ');');
     if ('' !== $a) {
         $args['__0__'] = $a;
         $i = 0;
         foreach (explode('/', $a) as $a) {
             $args['__' . ++$i . '__'] = $a;
         }
     }
     if ($base === $BASE) {
         $appId = $base = false;
     } else {
         p::watch('foreignTrace');
     }
     return $trace = array($appId, $base, $agent, $keys, $args);
 }
Beispiel #2
0
 function metaCompose()
 {
     p::setMaxage($this->maxage);
     p::setExpires($this->expires);
     p::watch($this->watch);
     if ($this->canPost) {
         p::canPost();
     }
 }
 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);
 }