当前位置: 首页>>代码示例>>PHP>>正文


PHP Kit::jsonEncode方法代码示例

本文整理汇总了PHP中Kit::jsonEncode方法的典型用法代码示例。如果您正苦于以下问题:PHP Kit::jsonEncode方法的具体用法?PHP Kit::jsonEncode怎么用?PHP Kit::jsonEncode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Kit的用法示例。


在下文中一共展示了Kit::jsonEncode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: GetResource

 /**
  * GetResource
  *     Return the rendered resource to be used by the client (or a preview)
  *     for displaying this content.
  * @param integer $displayId If this comes from a real client, this will be the display id.
  * @return string
  */
 public function GetResource($displayId = 0)
 {
     // Make sure we are set up correctly
     if ($this->GetSetting('apiKey') == '' || $this->GetSetting('apiSecret') == '') {
         Debug::Error('Twitter Module not configured. Missing API Keys');
         return '';
     }
     // Load in the template
     $template = file_get_contents('modules/preview/HtmlTemplate.html');
     $isPreview = Kit::GetParam('preview', _REQUEST, _WORD, 'false') == 'true';
     // Replace the View Port Width?
     if ($isPreview) {
         $template = str_replace('[[ViewPortWidth]]', $this->width, $template);
     }
     // Information from the Module
     $duration = $this->duration;
     // Generate a JSON string of substituted items.
     $items = $this->getTwitterFeed($displayId, $isPreview);
     // Return empty string if there are no items to show.
     if (count($items) == 0) {
         return '';
     }
     $options = array('type' => $this->type, 'fx' => $this->GetOption('effect', 'none'), 'speed' => $this->GetOption('speed', 500), 'duration' => $duration, 'durationIsPerItem' => $this->GetOption('durationIsPerItem', 0) == 1, 'numItems' => count($items), 'itemsPerPage' => 1, 'originalWidth' => $this->width, 'originalHeight' => $this->height, 'previewWidth' => Kit::GetParam('width', _GET, _DOUBLE, 0), 'previewHeight' => Kit::GetParam('height', _GET, _DOUBLE, 0), 'scaleOverride' => Kit::GetParam('scale_override', _GET, _DOUBLE, 0));
     // Replace the control meta with our data from twitter
     $controlMeta = '<!-- NUMITEMS=' . count($items) . ' -->' . PHP_EOL . '<!-- DURATION=' . ($this->GetOption('durationIsPerItem', 0) == 0 ? $duration : $duration * count($items)) . ' -->';
     $template = str_replace('<!--[[[CONTROLMETA]]]-->', $controlMeta, $template);
     // Replace the head content
     $headContent = '';
     // Add the CSS if it isn't empty
     $css = $this->GetRawNode('styleSheet');
     if ($css != '') {
         $headContent .= '<style type="text/css">' . $css . '</style>';
     }
     $backgroundColor = $this->GetOption('backgroundColor');
     if ($backgroundColor != '') {
         $headContent .= '<style type="text/css">body, .page, .item { background-color: ' . $backgroundColor . ' }</style>';
     }
     // Add our fonts.css file
     $headContent .= '<link href="' . ($isPreview ? 'modules/preview/' : '') . 'fonts.css" rel="stylesheet" media="screen">';
     $headContent .= '<link href="' . ($isPreview ? 'modules/theme/twitter/' : '') . 'emoji.css" rel="stylesheet" media="screen">';
     $headContent .= '<style type="text/css">' . file_get_contents(Theme::ItemPath('css/client.css')) . '</style>';
     // Replace the Head Content with our generated javascript
     $template = str_replace('<!--[[[HEADCONTENT]]]-->', $headContent, $template);
     // Add some scripts to the JavaScript Content
     $javaScriptContent = '<script type="text/javascript" src="' . ($isPreview ? 'modules/preview/vendor/' : '') . 'jquery-1.11.1.min.js"></script>';
     // Need the cycle plugin?
     if ($this->GetSetting('effect') != 'none') {
         $javaScriptContent .= '<script type="text/javascript" src="' . ($isPreview ? 'modules/preview/vendor/' : '') . 'jquery-cycle-2.1.6.min.js"></script>';
     }
     // Need the marquee plugin?
     if (stripos($this->GetSetting('effect'), 'marquee')) {
         $javaScriptContent .= '<script type="text/javascript" src="' . ($isPreview ? 'modules/preview/vendor/' : '') . 'jquery.marquee.min.js"></script>';
     }
     $javaScriptContent .= '<script type="text/javascript" src="' . ($isPreview ? 'modules/preview/' : '') . 'xibo-layout-scaler.js"></script>';
     $javaScriptContent .= '<script type="text/javascript" src="' . ($isPreview ? 'modules/preview/' : '') . 'xibo-text-render.js"></script>';
     $javaScriptContent .= '<script type="text/javascript">';
     $javaScriptContent .= '   var options = ' . json_encode($options) . ';';
     $javaScriptContent .= '   var items = ' . Kit::jsonEncode($items) . ';';
     $javaScriptContent .= '   $(document).ready(function() { ';
     $javaScriptContent .= '       $("body").xiboLayoutScaler(options); $("#content").xiboTextRender(options, items); ';
     $javaScriptContent .= '   }); ';
     $javaScriptContent .= '</script>';
     // Replace the Head Content with our generated javascript
     $template = str_replace('<!--[[[JAVASCRIPTCONTENT]]]-->', $javaScriptContent, $template);
     // Replace the Body Content with our generated text
     $template = str_replace('<!--[[[BODYCONTENT]]]-->', '', $template);
     return $template;
 }
开发者ID:rovak73,项目名称:xibo-cms,代码行数:75,代码来源:twitter.module.php

示例2: jsonEncode

 /**
  * Json Encode, handling and logging errors
  * http://stackoverflow.com/questions/10199017/how-to-solve-json-error-utf8-error-in-php-json-decode
  * @param  mixed $mixed The item to encode
  * @return mixed The Encoded Item
  */
 public static function jsonEncode($mixed)
 {
     if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
         $encoded = json_encode($mixed, JSON_PRETTY_PRINT);
     } else {
         $encoded = json_encode($mixed);
     }
     switch (json_last_error()) {
         case JSON_ERROR_NONE:
             return $encoded;
         case JSON_ERROR_DEPTH:
             Debug::Audit('Maximum stack depth exceeded');
             return false;
         case JSON_ERROR_STATE_MISMATCH:
             Debug::Audit('Underflow or the modes mismatch');
             return false;
         case JSON_ERROR_CTRL_CHAR:
             Debug::Audit('Unexpected control character found');
             return false;
         case JSON_ERROR_SYNTAX:
             Debug::Audit('Syntax error, malformed JSON');
             return false;
         case JSON_ERROR_UTF8:
             $clean = Kit::utf8ize($mixed);
             return Kit::jsonEncode($clean);
         default:
             Debug::Audit('Unknown error');
             return false;
     }
 }
开发者ID:fignew,项目名称:xibo-cms,代码行数:36,代码来源:kit.class.php


注:本文中的Kit::jsonEncode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。