json() static public method

Converts an array to a JSON string It's basically a shortcut for json_encode()
static public json ( array $array ) : string
$array array The source array
return string The JSON string
Ejemplo n.º 1
0
 /**
  * Set a new cookie
  * 
  * <code>
  * 
  * cookie::set('mycookie', 'hello', 60);
  * // expires in 1 hour
  * 
  * </code>
  * 
  * @param  string  $key The name of the cookie
  * @param  string  $value The cookie content
  * @param  int     $lifetime The number of minutes until the cookie expires
  * @param  string  $path The path on the server to set the cookie for
  * @param  string  $domain the domain 
  * @param  boolean $secure only sets the cookie over https
  * @param  boolean $httpOnly avoids the cookie to be accessed via javascript
  * @return boolean true: the cookie has been created, false: cookie creation failed
  */
 public static function set($key, $value, $lifetime = 0, $path = '/', $domain = null, $secure = false, $httpOnly = true)
 {
     // convert array values to json
     if (is_array($value)) {
         $value = a::json($value);
     }
     // hash the value
     $value = static::hash($value) . '+' . $value;
     // store that thing in the cookie global
     $_COOKIE[$key] = $value;
     // store the cookie
     return setcookie($key, $value, static::lifetime($lifetime), $path, $domain, $secure, $httpOnly);
 }
Ejemplo n.º 2
0
 /**
  * Set a new cookie
  * 
  * <code>
  * 
  * cookie::set('mycookie', 'hello', 60);
  * // expires in 1 hour
  * 
  * </code>
  * 
  * @param  string  $key The name of the cookie
  * @param  string  $value The cookie content
  * @param  int     $expires The number of minutes until the cookie expires
  * @param  string  $path The path on the server to set the cookie for
  * @param  string  $domain the domain 
  * @param  boolean $secure only sets the cookie over https
  * @return boolean true: the cookie has been created, false: cookie creation failed
  */
 public static function set($key, $value, $expires = 0, $path = '/', $domain = null, $secure = false)
 {
     // convert minutes to seconds
     if ($expires > 0) {
         $expires = time() + $expires * 60;
     }
     // convert array values to json
     if (is_array($value)) {
         $value = a::json($value);
     }
     // hash the value
     $value = static::hash($value) . '+' . $value;
     // store that thing in the cookie global
     $_COOKIE[$key] = $value;
     // store the cookie
     return setcookie($key, $value, $expires, $path, $domain, $secure);
 }
Ejemplo n.º 3
0
 /**
  * Creates a new file
  * 
  * @param  string  $file The path for the new file
  * @param  mixed   $content Either a string or an array. Arrays will be converted to JSON. 
  * @param  boolean $append true: append the content to an exisiting file if available. false: overwrite. 
  * @return boolean 
  */
 static function write($file, $content, $append = false)
 {
     if (is_array($content)) {
         $content = a::json($content);
     }
     $mode = $append ? FILE_APPEND : false;
     $write = @file_put_contents($file, $content, $mode);
     @chmod($file, 0666);
     return $write;
 }
Ejemplo n.º 4
0
 public function testJson()
 {
     $this->assertEquals(json_encode($this->user), a::json($this->user));
 }
Ejemplo n.º 5
0
    ?>
	<script>
	var ctx = document.getElementById("myChart").getContext("2d");
	var data = {
		labels: <?php 
    echo a::json(array_keys($history));
    ?>
,
		datasets: [
			{
				label: "Kirby Stats",
				fillColor: "rgba(141, 174, 40, 0.3)",
				strokeColor: "rgba(141, 174, 40, 0.8)",
				pointColor: "rgba(220,220,220,1)",
				pointStrokeColor: "#fff",
				pointHighlightFill: "#fff",
				pointHighlightStroke: "rgba(220,220,220,1)",
				data: <?php 
    echo a::json(array_values($history));
    ?>
,
			},
		]
	};
	var myLineChart = new Chart(ctx).Line(data, {
		'bezierCurve': false,
		'responsive': true,
	});
	</script>
<?php 
}
Ejemplo n.º 6
0
 //if page is accessed thorugh ajax
 if (r::ajax()) {
     //store sanitized $_POST variables
     $currentTestData = r::postData(array('test', 'user', 'data'));
     //get logged user (if any)
     if ($user = Auth::loggedUser()) {
         //get user's session page
         $userSession = site()->find(implode(DS, array(c::get('sessions.folder'), $user->session())));
         //istantiate testSession object
         $tSession = new testSession($userSession, $user->username());
         //get user's current session status
         $userSessionStatus = $user->status();
         //if ajaxed $currentTestData equals user's current session status
         if (str::lower($currentTestData['test']) == str::lower($userSessionStatus)) {
             //if it was possitble to update user's results file (by appending $currentTestData)
             if (f::append($tSession->getUserResultsFile(), PHP_EOL . a::json($currentTestData))) {
                 //set updated user's session status to next avalibale test
                 $updatedStatus = $tSession->getNextTest($currentTestData['test']);
                 //if there aren't tests available, set user's session statuts to completed session
                 if (!$updatedStatus) {
                     $updatedStatus = c::get('session.status.completed');
                 }
                 //update user's session status to next avalibale test
                 $user->update(array('status' => $updatedStatus));
                 //return to tests page
                 $url = $pages->find(c::get('tests.folder'))->url();
             }
         }
     }
 } else {
     //go to errorPage, since page wasn't accessed through ajax
Ejemplo n.º 7
0
 private function sendWithPostmark()
 {
     if (!$this->options['postmark.key']) {
         return array('status' => 'error', 'msg' => l::get('email.error.invalid.key', 'Invalid API key'));
     }
     // reset the api key if we are in test mode
     if ($this->options['postmark.test']) {
         $this->options['postmark.key'] = 'POSTMARK_API_TEST';
     }
     $url = 'http://api.postmarkapp.com/email';
     $headers = array('Accept: application/json', 'Content-Type: application/json', 'X-Postmark-Server-Token: ' . $this->options['postmark.key']);
     $data = array('From' => $this->options['from'], 'To' => $this->options['to'], 'ReplyTo' => $this->options['replyto'], 'Subject' => $this->options['subject'], 'TextBody' => $this->options['body']);
     $response = $this->post($url, a::json($data), array('headers' => $headers));
     $code = @$response['http_code'];
     if ($code != 200) {
         return array('status' => 'error', 'msg' => l::get('email.error', 'The mail could not be sent!'), 'response' => $response);
     }
     return array('status' => 'success', 'msg' => l::get('email.success', 'The mail has been sent'), 'response' => $response);
 }
Ejemplo n.º 8
0
 function testArrayJson()
 {
     $this->assertEqual(a::json($this->arr), '{"cat":"miao","dog":"wuff","bird":"tweet"}');
 }
Ejemplo n.º 9
0
					return YAML.stringify(this.values);
				},
				section: function (){
					return message
				},
				records: function (){
					return this.values
				}
			},
			// watch:{

			// },
			methods:{
				addEntrie: function (v_index){
					newEntrie =  <?php 
echo a::json($blueprint);
?>
;
					this.values.push(newEntrie);
				},
				editEntrie: function (v_index){

					if (this.editedEntries[v_index]) {
						Vue.set(this.editedEntries, v_index, 0);
					}else{
						Vue.set(this.editedEntries, v_index, 1);
					};

					console.log(this.editedEntries);
				},
				removeEntrie: function (index){