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


PHP safe_json_encode函数代码示例

本文整理汇总了PHP中safe_json_encode函数的典型用法代码示例。如果您正苦于以下问题:PHP safe_json_encode函数的具体用法?PHP safe_json_encode怎么用?PHP safe_json_encode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: safe_json_encode

 public static function safe_json_encode($value)
 {
     if (version_compare(PHP_VERSION, '5.4.0') >= 0) {
         $encoded = json_encode($value, JSON_PRETTY_PRINT);
     } else {
         $encoded = json_encode($value);
     }
     switch (json_last_error()) {
         case JSON_ERROR_NONE:
             return $encoded;
         case JSON_ERROR_DEPTH:
             return 'Maximum stack depth exceeded';
             // or trigger_error() or throw new Exception()
         // or trigger_error() or throw new Exception()
         case JSON_ERROR_STATE_MISMATCH:
             return 'Underflow or the modes mismatch';
             // or trigger_error() or throw new Exception()
         // or trigger_error() or throw new Exception()
         case JSON_ERROR_CTRL_CHAR:
             return 'Unexpected control character found';
         case JSON_ERROR_SYNTAX:
             return 'Syntax error, malformed JSON';
             // or trigger_error() or throw new Exception()
         // or trigger_error() or throw new Exception()
         case JSON_ERROR_UTF8:
             $clean = utf8ize($value);
             return safe_json_encode($clean);
         default:
             return 'Unknown error';
             // or trigger_error() or throw new Exception()
     }
 }
开发者ID:virtuemart-fr,项目名称:virtuemart-fr,代码行数:32,代码来源:vmjsapi.php

示例2: respond_to_js

 /**
  * Responds to a search request for a choice.
  *
  * @return string a JSON response string.
  */
 public function respond_to_js()
 {
     $requestval = required_param('val', PARAM_CLEAN);
     $ret = array();
     $requestval = strtolower($requestval);
     foreach ($this->choices as $choice) {
         if (strpos(strtolower($choice), $requestval) !== false) {
             $ret[] = array('id' => $choice, 'label' => $choice);
         }
     }
     return safe_json_encode($ret);
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:17,代码来源:usersetuser.filter.php

示例3: updateAddPlay

function updateAddPlay()
{
    global $cfg, $db;
    //authenticate('access_playlist', false, false, true);
    sleep(1);
    $album_id = get('album_id');
    $query = mysql_query('SELECT COUNT(c.album_id) as counter, c.time FROM (SELECT time, album_id FROM counter WHERE album_id = "' . mysql_real_escape_string($album_id) . '" ORDER BY time DESC) c ORDER BY c.time');
    $played = mysql_fetch_assoc($query);
    $query = mysql_query('SELECT artist, artist_alphabetic, album, image_id, album.album_id, COUNT(*) AS counter
			FROM counter, album
			WHERE counter.album_id = album.album_id
			GROUP BY album.album_id
			ORDER BY counter DESC, time DESC
			LIMIT 1');
    $max_played = mysql_fetch_assoc($query);
    $popularity = round($played['counter'] / $max_played['counter'] * 100);
    $data = array();
    $data['played'] = (string) $played['counter'] . ' ' . ($played['counter'] == 1 ? ' time' : ' times');
    $data['last_played'] = date("Y-m-d H:i", $played['time']);
    $data['popularity'] = (int) $popularity;
    //$data['bar_popularity']		= (string) floor($popularity * 1.8);
    echo safe_json_encode($data);
}
开发者ID:jdeblese,项目名称:ompd-mod,代码行数:23,代码来源:additional.php

示例4: safe_json_encode

var previous_listpos		= <?php 
echo $listpos;
?>
;
var previous_isplaying		= -1; // force update
var previous_repeat			= -1;
var previous_shuffle		= -1;
var previous_gain			= -1;
var previous_miliseconds	= -1;
var previous_volume			= -1;
var playtime				= <?php 
echo safe_json_encode($playtime);
?>
;
var track_id				= <?php 
echo safe_json_encode($track_id);
?>
;
var timer_id				= 0;
var timer_function			= 'ajaxRequest("play.php?action=playlistStatus&menu=playlist", evaluateStatus)';
//var timer_function			= '';
var timer_delay				= 1000;
var list_length				= <?php 
echo $listlength;
?>
;
//console.trace();

function deletePLitem(data) {
	//console.trace();
	
开发者ID:jdeblese,项目名称:ompd-mod,代码行数:30,代码来源:playlistDel.php

示例5: switch

$mngr = rRatioRulesList::load();
$val = null;
switch ($cmd) {
    case "setrules":
        $mngr->set();
        break;
    case "checklabels":
        $hash = array();
        if (!isset($HTTP_RAW_POST_DATA)) {
            $HTTP_RAW_POST_DATA = file_get_contents("php://input");
        }
        if (isset($HTTP_RAW_POST_DATA)) {
            $vars = explode('&', $HTTP_RAW_POST_DATA);
            foreach ($vars as $var) {
                $parts = explode("=", $var);
                switch ($parts[0]) {
                    case "hash":
                        $hash[] = $parts[1];
                        break;
                }
            }
        }
        $mngr->checkLabels($hash);
        $val = array();
        break;
}
if (is_null($val)) {
    $val = $mngr->getContents();
}
cachedEcho(safe_json_encode($val), "application/json", true);
开发者ID:Rapiddot,项目名称:ruTorrent,代码行数:30,代码来源:action.php

示例6: authenticateOpensearch

function authenticateOpensearch($input)
{
    global $cfg, $db;
    header('Expires: Mon, 9 Oct 2000 18:00:00 GMT');
    header('Cache-Control: no-store, no-cache, must-revalidate');
    $sid = cookie('netjukebox_sid');
    $version = get('version');
    $query = mysql_query('SELECT logged_in, idle_time, ip, user_agent FROM session WHERE sid = BINARY "' . mysql_real_escape_string($sid) . '"');
    $session = mysql_fetch_assoc($query);
    if ($sid == '') {
        $data = array('Allow third-party cookies,', 'or add an exception for this domain!');
        $data = array($input, $data);
        echo safe_json_encode($data);
        exit;
    }
    if ($version != 1) {
        $data = array('Reinstall opensearch plugin!');
        $data = array($input, $data);
        echo safe_json_encode($data);
        exit;
    }
    if ($session['logged_in'] && $session['ip'] == $_SERVER['REMOTE_ADDR'] && $session['user_agent'] == substr($_SERVER['HTTP_USER_AGENT'], 0, 255) && $session['idle_time'] + $cfg['session_lifetime'] > time()) {
        return true;
    }
    $data = array('Login netjukebox!');
    $data = array($input, $data);
    echo safe_json_encode($data);
    exit;
}
开发者ID:jdeblese,项目名称:ompd-mod,代码行数:29,代码来源:opensearch.php

示例7: respond_to_js

 /**
  * Responds to a search request for a choice.
  *
  * @return string a JSON response string.
  */
 public function respond_to_js()
 {
     $requestval = required_param('val', PARAM_CLEAN);
     $ret = array();
     $sql = 'SELECT DISTINCT ' . $this->choicesfield . '
               FROM {' . $this->choicestable . '}
              WHERE ' . $this->choicesfield . ' LIKE ?';
     $vals = $this->DB->get_recordset_sql($sql, array('%' . $requestval . '%'));
     $choicesfield = $this->choicesfield;
     foreach ($vals as $val) {
         $ret[] = array('id' => $val->{$choicesfield}, 'label' => ucwords($val->{$choicesfield}));
     }
     return safe_json_encode($ret);
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:19,代码来源:searchselect.filter.php

示例8: array

//  | along with this program.  If not, see <http://www.gnu.org/licenses/>.  |
//  +------------------------------------------------------------------------+
global $cfg, $db;
require_once 'include/initialize.inc.php';
require_once 'include/play.inc.php';
if ($cfg['player_type'] == NJB_MPD) {
    $data = array();
    $query1 = mysql_query('SELECT player.player_name as pl, player_host, player_port FROM player, session WHERE (sid = BINARY "' . cookie('netjukebox_sid') . '") and player.player_id=session.player_id');
    $session1 = mysql_fetch_assoc($query1);
    $data['player'] = $session1['pl'];
    //$data['host'] = $session1['player_host'];
    $cfg['player_host'] = $data['host'] = $session1['player_host'];
    $cfg['player_port'] = $session1['player_port'];
    $cfg['player_pass'] = $session1['player_pass'];
    $status = mpdSilent('status');
    if ($status != false) {
        $data['volume'] = (int) $status['volume'];
    } else {
        $data['volume'] = -1;
    }
    // get mute volume
    if ($data['volume'] == 0) {
        $query = mysql_query('SELECT mute_volume FROM player WHERE player_id = ' . (int) $cfg['player_id']);
        $temp = mysql_fetch_assoc($query);
        $data['volume'] = -$temp['mute_volume'];
    }
    echo safe_json_encode($data);
}
?>
	
开发者ID:jdeblese,项目名称:ompd-mod,代码行数:29,代码来源:ajax-evaluate-status.php

示例9: get

 public function get()
 {
     return safe_json_encode($this->list);
 }
开发者ID:Rapiddot,项目名称:ruTorrent,代码行数:4,代码来源:lookat.php

示例10: test_responses

 /**
  * Test AJAX responses
  */
 public function test_responses()
 {
     global $DB, $SESSION;
     $name = 'datatable';
     $endpoint = 'test.php';
     $datatable = new deepsight_datatable_mock($DB, $name, $endpoint);
     // Test basic response.
     ob_start();
     $datatable->respond('mock');
     $contents = ob_get_contents();
     ob_end_clean();
     $this->assertEquals('Success', $contents);
     // Test nonexistent respond.
     ob_start();
     $datatable->respond('nonexistent');
     $contents = ob_get_contents();
     ob_end_clean();
     $expected = 'throw 1;{"result":"fail","msg":"Do not know how to respond to that request."}';
     $this->assertEquals($expected, $contents);
     // Test filter response.
     ob_start();
     $_POST['filtername'] = 'testfilter1';
     $datatable->respond('filter');
     $actual = ob_get_contents();
     ob_end_clean();
     $expected = 'success';
     $this->assertEquals($expected, $actual);
     // Test action response.
     ob_start();
     $_POST['actionname'] = 'testaction';
     $_POST['sesskey'] = sesskey();
     $_POST['elements'] = safe_json_encode(array());
     $datatable->respond('action');
     $actual = ob_get_contents();
     ob_end_clean();
     $expected = safe_json_encode(array('result' => 'success'));
     $this->assertEquals($expected, $actual);
     // Empty bulklist list.
     ob_start();
     $datatable->respond('bulklist_get');
     $actual = ob_get_contents();
     ob_end_clean();
     $actual = safe_json_decode($actual);
     $expected = array('result' => 'success', 'page_results_ids' => array(), 'page_results_values' => array(), 'total_results' => 0);
     $this->assertEquals($expected, $actual);
     // Test bulklist list with items.
     $bulklistparam = $datatable->get_bulklist_sess_param();
     $generatedids = array();
     for ($i = 0; $i < 2; $i++) {
         $user = new stdClass();
         $user->firstname = 'Test';
         $user->lastname = 'User ' . $i;
         $id = $DB->insert_record('local_elisprogram_usr', $user);
         $generatedids[] = $id;
         $SESSION->{$bulklistparam}[$id] = $id;
     }
     ob_start();
     $datatable->respond('bulklist_get');
     $actual = ob_get_contents();
     ob_end_clean();
     $actual = safe_json_decode($actual);
     $expected = array('result' => 'success', 'page_results_ids' => array_reverse($generatedids), 'page_results_values' => array('Test User 1', 'Test User 0'), 'total_results' => 2);
     $this->assertEquals($expected, $actual);
     // Test bulklist modify - removing.
     $_POST['modify'] = 'remove';
     $_POST['ids'] = array(2);
     ob_start();
     $datatable->respond('bulklist_modify');
     $actual = ob_get_contents();
     ob_end_clean();
     $actual = safe_json_decode($actual);
     $expected = array('result' => 'success', 'page_results_ids' => array(1), 'page_results_values' => array('Test User 0'), 'total_results' => 1);
     $this->assertEquals($expected, $actual);
     // Test bulklist modify - adding.
     $_POST['modify'] = 'add';
     $_POST['ids'] = array(2);
     ob_start();
     $datatable->respond('bulklist_modify');
     $actual = ob_get_contents();
     ob_end_clean();
     $actual = safe_json_decode($actual);
     $expected = array('result' => 'success', 'page_results_ids' => array(2, 1), 'page_results_values' => array('Test User 1', 'Test User 0'), 'total_results' => 2);
     $this->assertEquals($expected, $actual);
     // Test bulklist modify - deduplication.
     $_POST['modify'] = 'add';
     $_POST['ids'] = array(2);
     ob_start();
     $datatable->respond('bulklist_modify');
     $actual = ob_get_contents();
     ob_end_clean();
     $actual = safe_json_decode($actual);
     $expected = array('result' => 'success', 'page_results_ids' => array(2, 1), 'page_results_values' => array('Test User 1', 'Test User 0'), 'total_results' => 2);
     $this->assertEquals($expected, $actual);
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:97,代码来源:deepsight_datatable_test.php

示例11: playlistTrack

function playlistTrack()
{
    global $cfg, $db;
    authenticate('access_playlist', false, false, true);
    $track_id = get('track_id');
    $query = mysql_query('SELECT track.artist, album.artist AS album_artist, title, featuring, miliseconds, relative_file, album, album.image_id, album.album_id, track.genre, track.audio_bitrate, track.audio_dataformat, track.audio_bits_per_sample, track.audio_sample_rate, album.genre_id, track.audio_profile, track.track_artist, album.year as year, track.number, track.comment, track.track_id, track.year as trackYear, track.dr, album.album_dr
		FROM track, album 
		WHERE track.album_id = album.album_id
		AND track_id = "' . mysql_real_escape_string($track_id) . '"');
    $track = mysql_fetch_assoc($query);
    $query = mysql_query('SELECT image_front FROM bitmap WHERE image_id="' . mysql_real_escape_string($track['image_id']) . '"');
    $bitmap = mysql_fetch_assoc($query);
    $title = $track['title'];
    /* $query_ = mysql_query('SELECT title FROM track
    		WHERE DIFFERENCE(SOUNDEX(title), SOUNDEX("' . (mysql_real_escape_like($title)) . '")) > 0');
    	$query_ = mysql_query('SELECT SOUNDEX(title) FROM track');
    	 */
    /* $title = strtolower($title);
    	$separator = $cfg['separator'];
    	$count = count($separator);
    	$i=0;
    	
    	for ($i=0; $i<$count; $i++) {
    		$pos = strpos($title,strtolower($separator[$i]));
    		if ($pos !== false) {
    			$title = trim(substr($title, 0 , $pos));
    			//break;
    		}
    	}  */
    $other_track_version = false;
    if ($cfg['enable_core_track_search'] === TRUE) {
        $title = findCoreTrackTitle($title);
        $title = mysql_real_escape_like($title);
        $separator = $cfg['separator'];
        $count = count($separator);
        $query_string = '';
        $i = 0;
        for ($i = 0; $i < $count; $i++) {
            $query_string = $query_string . ' OR LOWER(title) LIKE "' . $title . $separator[$i] . '%"';
        }
        $filter_query = 'WHERE (LOWER(title) = "' . $title . '" ' . $query_string . ')';
        $query = mysql_query('SELECT title FROM track ' . $filter_query);
        if (strlen($title) > 0) {
            $num_rows = mysql_num_rows($query);
            if ($num_rows > 1) {
                $other_track_version = true;
            }
        }
    }
    $exploded = multiexplode($cfg['artist_separator'], $track['track_artist']);
    $inFavorite = false;
    if (isset($cfg['favorite_id'])) {
        $query = mysql_query("SELECT track_id FROM favoriteitem WHERE track_id = '" . $track_id . "' AND favorite_id = '" . $cfg['favorite_id'] . "' LIMIT 1");
        if (mysql_num_rows($query) > 0) {
            $inFavorite = true;
        }
    }
    $data = array();
    $data['album_artist'] = (string) ($track['album_artist'] == "Various Artists") ? rawurlencode($track['track_artist']) : rawurlencode($track['album_artist']);
    $data['track_artist'] = $exploded;
    $data['track_artist_url'] = $exploded;
    $data['track_artist_url_all'] = (string) rawurlencode($track['track_artist']);
    $data['title'] = (string) (trim($track['title']) !== '') ? $track['title'] : basename($track['relative_file']);
    $data['album'] = (string) (trim($track['album']) !== '') ? $track['album'] : basename(dirname($track['relative_file']));
    //$data['album']		= (string) $title;
    $data['by'] = (string) $by;
    $data['image_id'] = (string) $track['image_id'];
    $data['album_id'] = (string) $track['album_id'];
    $data['year'] = is_null($track['year']) ? (string) $track['trackYear'] : (string) $track['year'];
    $data['genre'] = (string) $track['genre'];
    $data['audio_dataformat'] = (string) strtoupper($track['audio_dataformat']);
    $data['audio_bits_per_sample'] = (string) $track['audio_bits_per_sample'];
    $data['audio_sample_rate'] = (string) $track['audio_sample_rate'];
    $data['genre_id'] = (string) $track['genre_id'];
    if ($track['audio_profile'] == 'Lossless compression') {
        $data['audio_profile'] = (string) floor($track['audio_bitrate'] / 1000) . ' kbps';
    } else {
        $data['audio_profile'] = (string) $track['audio_profile'];
    }
    $data['number'] = (string) $track['number'] . '. ';
    $data['miliseconds'] = (string) $track['miliseconds'];
    $data['other_track_version'] = (bool) $other_track_version;
    $data['comment'] = (string) $track['comment'];
    $data['track_id'] = (string) $track['track_id'];
    $data['relative_file'] = (string) $track['relative_file'];
    $data['inFavorite'] = (bool) $inFavorite;
    $data['dr'] = (string) $track['dr'];
    $data['album_dr'] = (string) $track['album_dr'];
    $data['title_core'] = $title;
    echo safe_json_encode($data);
}
开发者ID:jdeblese,项目名称:ompd-mod,代码行数:91,代码来源:play.php

示例12: do_deepsight_response

 /**
  * Routes ajax requests to the applicable object and displays response.
  */
 public function do_deepsight_response()
 {
     global $DB;
     $mode = $this->required_param('m');
     $classid = $this->required_param('id', PARAM_INT);
     $tabletype = $this->required_param('tabletype', PARAM_ALPHA);
     if (!in_array($tabletype, array('assigned', 'unassigned'), true)) {
         throw new Exception('Invalid table type specified');
     }
     // Authorization.
     $assignedauthorized = $tabletype === 'assigned' && $this->can_do_default() === true ? true : false;
     $unassignedauthorized = $tabletype === 'unassigned' && $this->can_do_add() === true ? true : false;
     if ($assignedauthorized !== true && $unassignedauthorized !== true) {
         echo safe_json_encode(array('result' => 'fail', 'msg' => get_string('not_permitted', 'local_elisprogram')));
     }
     // Build the table.
     $uniqid = optional_param('uniqid', null, PARAM_CLEAN);
     $table = $tabletype === 'assigned' ? $this->construct_assigned_table($uniqid) : $this->construct_unassigned_table($uniqid);
     if ($mode === 'action') {
         // We'll use page-specific can_do actions to authorize access to each requested action.
         $actionname = required_param('actionname', PARAM_ALPHAEXT);
         $candoactionmethod = 'can_do_action_' . $actionname;
         if (method_exists($this, $candoactionmethod) && $this->{$candoactionmethod}() === true) {
             $table->respond($mode);
         } else {
             echo safe_json_encode(array('result' => 'fail', 'msg' => get_string('not_permitted', 'local_elisprogram')));
         }
     } else {
         $table->respond($mode);
     }
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:34,代码来源:deepsightpage.class.php

示例13: test_filter_searchselect_respond

 /**
  * Test the searchselect filter's search function.
  *
  * @dataProvider searchselectfilter_respond_dataprovider
  */
 public function test_filter_searchselect_respond($filterdata, $expectedresponse)
 {
     global $DB;
     $expectedresponse = safe_json_encode($expectedresponse);
     // Insert test data.
     $cities = array('Springfield', 'Springfield', 'Springfield', 'Toronto', 'Toronto', 'Waterloo');
     foreach ($cities as $i => $city) {
         $user = new stdClass();
         $user->username = 'testuser' . $i;
         $user->idnumber = 'testuser' . $i;
         $user->city = $city;
         $DB->insert_record('local_elisprogram_usr', $user);
     }
     $name = 'searchselect';
     $label = 'Search Select';
     $endpoint = 'test.php';
     $fielddata = array('city' => 'City');
     $filter = new deepsight_filter_searchselect($DB, $name, $label, $fielddata, $endpoint, 'local_elisprogram_usr', 'city');
     $_POST['val'] = $filterdata;
     $response = $filter->respond_to_js();
     $this->assertEquals($expectedresponse, $response);
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:27,代码来源:deepsight_filter_test.php

示例14: pushBulletNotify

 public function pushBulletNotify($data)
 {
     global $pushBulletNotifications, $pushBulletEndpoint;
     $actions = array(1 => 'addition', 2 => 'finish', 3 => 'deletion');
     $section = $pushBulletNotifications[$actions[$data['action']]];
     $fields = array('{name}', '{label}', '{size}', '{downloaded}', '{uploaded}', '{ratio}', '{creation}', '{added}', '{finished}', '{tracker}');
     $values = array($data['name'], $data['label'], self::bytes($data['size']), self::bytes($data['downloaded']), self::bytes($data['uploaded']), $data['ratio'], strftime('%c', $data['creation']), strftime('%c', $data['added']), strftime('%c', $data['finished']), $data['tracker']);
     $title = str_replace($fields, $values, $section['title']);
     $body = str_replace($fields, $values, $section['body']);
     $client = new Snoopy();
     $client->user = $this->log["pushbullet_key"];
     $client->fetch($pushBulletEndpoint, "POST", "application/json", safe_json_encode(array('type' => 'note', 'title' => $title, 'body' => $body)));
 }
开发者ID:Rapiddot,项目名称:ruTorrent,代码行数:13,代码来源:history.php

示例15: eval

<?php

require_once '../../php/util.php';
eval(getPluginConf('geoip'));
require_once 'ip_db.php';
$db = new ipDB();
$db->add($_REQUEST["ip"], $_REQUEST["comment"]);
cachedEcho(safe_json_encode(array("ip" => $_REQUEST["ip"], "comment" => $_REQUEST["comment"])), "application/json");
开发者ID:Rapiddot,项目名称:ruTorrent,代码行数:8,代码来源:action.php


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