Beispiel #1
0
 protected function getJs($data)
 {
     if (is_object($data) || is_array($data)) {
         $a = '{';
         foreach ($data as $k => $v) {
             $k = jsquote($k);
             is_string($k) || ($k = "'" . $k . "'");
             $a .= $k . ':' . $this->getJs($v) . ',';
         }
         $k = strlen($a);
         if ($k > 1) {
             $a[strlen($a) - 1] = '}';
         } else {
             $a = '{}';
         }
     } else {
         $a = jsquote($data);
     }
     return $a;
 }
 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))), ']', ')';
 }
Beispiel #3
0
 protected function getVar($name, $type, $prefix, $forceType)
 {
     if ((string) $name === (string) ($name - 0)) {
         return $name;
     }
     switch ($type) {
         case "'":
             $result = jsquote($name);
             break;
         case '$':
             $result = 'v' . str_repeat('.$', substr_count($prefix, '$')) . $this->getJsAccess($name);
             break;
         case 'd':
         case 'a':
         case 'g':
             $result = '' !== (string) $prefix ? "z('{$name}',{$prefix}" . ('g' === $type ? ',1' : '') . ')' : $type . $this->getJsAccess($name);
             if ('g.__BASE__' === $result) {
                 $result = 'r';
             }
             break;
         case '':
             $result = 'v' . $this->getJsAccess($name);
             break;
         default:
             $result = $type . $this->getJsAccess($name);
     }
     switch ($forceType) {
         case 'number':
             $result = "'" === $result[0] ? $result - 0 : "num({$result})";
             break;
         case 'unified':
             $result = "'" === $result[0] ? $result : "num({$result},1)";
             break;
         default:
             if ('concat' === $this->mode && "'" !== $result[0]) {
                 $result = "str({$result})";
             }
     }
     return $result;
 }
 protected static function writeAgent($loop)
 {
     if ($prevKeys = $loop->__toString()) {
         echo "w.x([", $prevKeys, ",[";
         $prevKeys = array();
         while ($data = $loop->loop()) {
             $data = (array) $data;
             if ($prevKeys !== array_keys($data)) {
                 $k = array_keys($data);
                 echo $prevKeys ? '],[' : '', count($k), ',', implode(',', array_map('jsquote', $k));
                 $prevKeys = $k;
             }
             foreach ($data as $value) {
                 echo ',';
                 if ($value instanceof \loop) {
                     self::writeAgent($value);
                 } else {
                     echo jsquote($value);
                 }
             }
         }
         echo ']])';
     } else {
         echo '0';
     }
 }
Beispiel #5
0
 static function php($string, $forceString = false)
 {
     $string = (string) $string;
     false !== strpos($string, '&') && ($string = str_replace(array('&#039;', '&quot;', '&gt;', '&lt;', '&amp;'), array("'", '"', '>', '<', '&'), $string));
     return jsquote($string);
 }