Ejemplo n.º 1
0
 function testJSON()
 {
     $v = array(1, 2, 3);
     $a = Raxan::JSON('encode', $v);
     // encode
     $this->compare($a, '[1,2,3]', 'JSON encode');
     $a = Raxan::JSON('decode', '[1,2,3]');
     // decode
     $this->compare($a, $v, 'JSON decode');
 }
Ejemplo n.º 2
0
 /**
  * Returned encoded javascript value 
  */
 public static function encodeVar($v)
 {
     if (!is_numeric($v) && is_string($v)) {
         $v = '"' . Raxan::escapeText($v) . '"';
     } else {
         if ($v instanceof RaxanClientExtension || $v instanceof RaxanClientVariable) {
             // pass chain as value
             $v = $v . '';
         } else {
             if ($v === true) {
                 $v = 'true';
             } else {
                 if ($v === false) {
                     $v = 'false';
                 } else {
                     if (!is_scalar($v)) {
                         // encode arrays and objects
                         $v = Raxan::JSON('encode', $v);
                         // replace _pointer hash array with variable name due to json encoding.
                         // See RaxanClientVariable->_pointer
                         if (strpos($v, ':{"_pointer":"_v')) {
                             $v = preg_replace('/:\\{"_pointer"\\:"(_v[0-9]+)"\\}/', ':\\1', $v);
                         }
                         if (!$v) {
                             $v = '{}';
                         }
                     }
                 }
             }
         }
     }
     return $v;
 }
Ejemplo n.º 3
0
 /**
  * Returns string containing action scripts and client-side event bindings
  * @return String
  */
 protected function buildActionScripts($includeEvents = true)
 {
     // build event scripts
     $actions = $binds = '';
     if ($includeEvents) {
         if (isset($this->events['selectors'])) {
             $sels = $this->events['selectors'];
             foreach ($sels as $sel => $opts) {
                 // no need to bind page registered events on client
                 if ($sel != 'page') {
                     foreach ($opts as $opt) {
                         $de = $opt['delegate'];
                         $x = $de ? ',true' : '';
                         // setup extended options
                         if ($opt['_extendedOpt'] || is_string($de)) {
                             $x = array();
                             if ($opt['delegate']) {
                                 $x[] = 'dt:' . ($de !== true ? '"' . Raxan::escapeText($de) . '"' : 'true');
                             }
                             // delegate
                             if ($opt['delay']) {
                                 $x[] = 'dl:\'' . $opt['delay'] . '\'';
                             }
                             if ($opt['autoDisable']) {
                                 $x[] = 'ad:\'' . $opt['autoDisable'] . '\'';
                             }
                             if ($opt['autoToggle']) {
                                 $x[] = 'at:\'' . $opt['autoToggle'] . '\'';
                             }
                             if ($opt['inputCache']) {
                                 $x[] = 'ic:\'' . $opt['inputCache'] . '\'';
                             }
                             if ($opt['view']) {
                                 $x[] = 'vu:\'' . $opt['view'] . '\'';
                             }
                             if ($opt['confirm']) {
                                 $x[] = 'ct:\'' . Raxan::escapeText($opt['confirm']) . '\'';
                             }
                             if ($opt['targetWindow']) {
                                 $x[] = 'tw:\'' . Raxan::escapeText($opt['targetWindow']) . '\'';
                             }
                             if ($opt['repeat']) {
                                 $x[] = 'rpt:' . ($opt['repeat'] === true ? 'true' : (int) $opt['repeat']) . '';
                             }
                             $x = ',{' . implode(',', $x) . '}';
                         }
                         $script = is_array($opt['script']) ? Raxan::JSON('encode', $opt['script']) : '"' . Raxan::escapeText($opt['script']) . '"';
                         $binds .= '$bind("' . $sel . '","' . $opt['type'] . '","' . Raxan::escapeText($opt['value']) . '","' . Raxan::escapeText($opt['serialize']) . '","' . $opt['ptarget'] . '",' . $script . $x . ');';
                     }
                 }
             }
         }
     }
     $vars = implode(',', RaxanWebPage::$vars);
     $varsGlobal = implode(',', RaxanWebPage::$varsGlobal);
     if ($vars) {
         $vars = 'var ' . $vars . ';';
     }
     if ($varsGlobal) {
         $vars .= $varsGlobal . ';';
     }
     if (PHP_VERSION_ID < 50200) {
         // fix for issue #4
         foreach (RaxanWebPage::$actions as $i => $act) {
             if ($act) {
                 RaxanWebPage::$actions[$i] = $act->__toString();
             }
         }
     }
     if ($binds) {
         RaxanWebPage::$actions[] = $binds;
     }
     // add bindings to the end of the actions script queue
     $actions = str_ireplace('</script>', '<\\/script>', $vars . implode(';', RaxanWebPage::$actions));
     if ($actions) {
         // check if we should load jquery
         if (!isset($this->_scripts['JSI:jquery'])) {
             $this->loadScript('jquery', false, 1);
         }
         $actions = 'Raxan.ready(function() {' . $actions . '});';
     }
     return $actions;
 }