コード例 #1
0
 /**
  * Manages the compilation of an <fb:js-string> node, which
  * is designed to inline the declaration and initialization of
  * a new Javascript string variable.  In a nutshell, the idea is for
  * something like this:
  *
  *  <fb:js-string var="myName">Jerry Coopersmith</fb:js-string>
  *
  * to render to something like this:
  *
  *  <script type="text/javascript">
  *       a<app-id>_myName = "Jerry Coopersmith";
  *  </script>
  *
  * The implementation is careful to prevent the use of nested <fb:js-string> tags, and
  * provisions are also made to support the one-dimensional arrays, as outline
  * on the FBML Wiki.
  *
  * @param node the FBMLNode modeling the <fb:js-string> tag.
  * @return a HTML string that helps define a new Javascript variable on the fly, where
  *         the new variable is set equal to the full rendering of the <fb:js-string>'s
  *         children.
  */
 public function fb_js_string($node)
 {
     $user_triggered = isset($this->_fbml_env['user_triggered']) ? $this->_fbml_env['user_triggered'] : false;
     $this->_fbml_env['user_triggered'] = true;
     if ($this->get_env('fb_js_string', false)) {
         throw new FBMLException("Cannot nest fb:js-string tags");
     }
     $this->_fbml_env['fb_js_string'] = true;
     // used to protect against fb:js-string within fb:js-string
     $html = $this->render_children($node);
     $this->_fbml_env['user_triggered'] = $user_triggered;
     unset($this->_fbml_env['fb_js_string']);
     $var = $node->attr('var', 'fbml', true);
     // extract the name of the JavaScript variable
     if (!preg_match('#^[a-zA-Z$_][a-zA-Z$_0-9]*(?:\\.[a-zA-Z$_][a-zA-Z$_0-9]*)?$#', $var)) {
         throw new FBMLException('"' . $var . '" isn\'t a legitimate JavaScript variable name');
     }
     if (strpos($var, '.') > 0) {
         // looks to be array access
         $var = explode('.', $var);
         $var[0] = 'a' . $this->get_env('app_id') . '_' . $var[0];
         $var = '(typeof ' . $var[0] . '!=\'undefined\'?' . $var[0] . ':' . $var[0] . '={}).' . $var[1];
     } else {
         $var = 'a' . $this->get_env('app_id') . '_' . $var;
     }
     return $this->onloadRegister($var . '=new fbjs_fbml_string(\'' . escape_js_quotes($html) . '\')');
 }
コード例 #2
0
ファイル: fbjs.php プロジェクト: luxurymask/platform
 public function postrender()
 {
     if (!$this->used) {
         return '';
     }
     // Go through all the inline scripts and sanitize
     $sanitized_scripts = array();
     if ($this->script_infos) {
         foreach ($this->script_infos as $script_info) {
             if (isset($script_info['inline'])) {
                 $sanitized_scripts[] = array('inline' => self::sanitize_code($script_info['inline'], $this->appid));
             } else {
                 if (isset($script_info['src'])) {
                     // FBOPEN:NOTE - if js sources are fetched from outside, these will
                     // have to be fetched, cached, sanitized, and stored.  Requests then
                     // would need to be directed to your cached version.  The open source
                     // code at this point does not support such caching.
                     // $sanitized_scripts[] = array('src' => FBJSUrlRef::get_url($script_info['src'], $this->appid, 'js'));
                 }
             }
         }
     }
     // If this is our first postrender build some bootstrapping code
     $bootstrap = false;
     if (!$this->postrendered) {
         $bootstrap = 'var app=new fbjs_sandbox(' . $this->appid . ');';
         $profile = $this->fbml->get_env('profile', false, 0);
         $validation_vars = get_fb_validation_vars(array('user' => $this->user), $this->appid, $profile ? array('profile' => $profile) : array());
         $bootstrap .= 'app.validation_vars=' . json_encode($validation_vars) . ';';
         $context = $this->fbml->add_context();
         $bootstrap .= 'app.context=\'' . escape_js_quotes($context) . '\';';
         $bootstrap .= 'app.contextd=\'' . escape_js_quotes($this->fbml->_contexts[$context]) . '\';';
         $bootstrap .= 'app.data=' . json_encode(array('user' => $this->user, 'installed' => $this->user ? is_platform_app_installed($this->appid, $this->user) : false, 'loggedin' => $this->user ? (bool) api_get_valid_session_key($this->user, $this->appid) : false)) . ';';
     }
     // Render all inline scripts
     $html = '';
     if ($this->fbml->_flavor->allows('script_onload')) {
         if (!$this->postrendered) {
             $bootstrap .= 'app.bootstrap();';
         }
         foreach ($sanitized_scripts as $script) {
             if (isset($script['inline'])) {
                 $html .= render_js_inline($script['inline']) . "\n";
             } else {
                 $script_include = '<script src="' . $script['src'] . '"></script>';
                 $html .= $script_include;
             }
         }
     } else {
         foreach ($sanitized_scripts as $script) {
             if (isset($script['inline'])) {
                 $bootstrap .= 'app.pending_bootstraps.push(\'' . escape_js_quotes($script['inline']) . '\');';
             } else {
                 // We don't support script include for this flavor at this time.
                 throw new FBMLJSParseError('Cannot allow external script');
             }
         }
     }
     $this->used = false;
     $this->postrendered = true;
     return render_js_inline($bootstrap) . $html;
 }
コード例 #3
0
    </div>
    <?php 
echo HTML::script('js/jquery-1.10.2.min.js');
?>
    <?php 
echo HTML::script('js/bootstrap.min.js');
?>
    <?php 
echo HTML::script('js/ms.js');
?>
    @yield('js')
</body>
<?php 
if (@$msg) {
    ?>
<script>
    $(function(){
        popup_msg(<?php 
    echo escape_js_quotes($msg['msg'], TRUE);
    ?>
, <?php 
    echo escape_js_quotes($msg['type'], TRUE);
    ?>
);
    });
</script>
<?php 
}
?>
</html>