예제 #1
0
    # the file with the newly uploaded content.
    foreach ($data['data'] as $field) {
        # Set Filename
        $filename = ROOT_DIR . '/' . PUBLIC_ROOT . '/content/field-' . $field['ID'] . '.html';
        # Check for file
        if (!file_exists($filename)) {
            $unsaved++;
        }
        # Attempt to save content
        if (file_exists($filename) && file_put_contents($filename, $field['content'])) {
            $saved++;
        }
    }
    # Check for success
    switch (true) {
        # All saved
        case $saved > 0 && $unsaved === 0:
            JSON::parse(200, 'positive', '<i class="fa fa-check-circle"></i> Changes saved.', null, true);
            break;
            # Some saved
        # Some saved
        case $saved > 0 && $unsaved > 0:
            JSON::parse(200, 'warning', '<i class="fa fa-check-circle"></i> Some changes were not saved.', null, true);
            break;
            # No saved
        # No saved
        case $saved === 0 && $unsaved > 0:
            JSON::parse(200, 'negative', '<i class="fa fa-check-circle"></i> Changes were not saved.', array(0 => ROOT_DIR . '/' . PUBLIC_ROOT . '/content/field-' . $field['ID'] . '.html'), true);
            break;
    }
}
예제 #2
0
        break;
}
# New GUMP Object
$form = new GUMP();
# Get Input
$data = form_data();
# Validate Input
$form->validate($data, array('files' => 'required'));
# Run GUMP
$response = $form->run($data);
# Get Response
if ($response === false) {
    JSON::parse(100, 'negative', $form->get_readable_errors(true));
} else {
    # Split Base64
    $parts = explode(';', $data['files']);
    # Split Type
    $type = explode('/', $parts[0]);
    # File Extension
    $ext = $type[1];
    # Get File
    $file = base64_decode(preg_replace('#^data:image/\\w+;base64,#i', '', $data['files']));
    # Set filename
    $filename = ROOT_DIR . '/site/_media/' . time() . '.' . $ext;
    # Save File
    if (file_put_contents($filename, $file)) {
        JSON::parse(200, 'positive', 'Image saved', array('url' => str_replace(ROOT_DIR, '', $filename)), true);
    } else {
        JSON::parse(100, 'negative', 'Unable to save file', null, true);
    }
}
예제 #3
0
<?php

use CCK\Content;
# Create Content Object
$content = new Content($_cck_types, $_cck_config);
# Create Content
$content->create(form_data());
# Get Response
$response = $content->getResponse();
# Create Response Type
switch (true) {
    # Negative
    case $response['code'] === 100:
        $response['type'] = 'negative';
        break;
        # Positive
    # Positive
    case $response['code'] === 200:
        $response['type'] = 'positive';
        break;
}
# JSON
JSON::parse($response['code'], $response['type'], $response['message'], $response, true);
예제 #4
0
<?php

# Check user & validate data
switch (true) {
    # Not logged in
    case is_loggedin():
        JSON::parse(100, 'negative', '<i class="fa fa-exclamation-triangle"></i> You\'re already logged in!', null, true);
        break;
        # No post data
    # No post data
    case !is_form_data():
        JSON::parse(100, 'negative', '<i class="fa fa-exclamation-triangle"></i> There was a problem logging you in. (Error: No data received)', null, true);
        break;
}
# Create User Object
$_ce_user = new CMSEditor\User($_ce_config);
# New GUMP Object
$form = new GUMP();
# Get Input
$data = form_data();
# Validate Input
$form->validate($data, array('username' => 'required', 'password' => 'required'));
# Run GUMP
$response = $form->run($data);
# Get Response
if ($response === false) {
    JSON::parse(100, 'negative', $form->get_readable_errors(true));
} else {
    # Attempt login
    $_ce_user->login($data['username'], $data['password']);
}
예제 #5
0
class object2
{
    var $firstattr = 'firstvalue';
    var $secondattr = 'secondvalue';
}
//---- variables ---------------------------------------------------------------
$JSON = new JSON();
$object1 = new object1();
$JSON2 = new Services_JSON();
$submitted = false;
//---- logic -------------------------------------------------------------------
$origjsonstring = $JSON->stringify($object1);
$newjsonstring = $JSON2->encode($object1);
$origjson = $_REQUEST["origjson"];
if (!empty($origjson)) {
    $origjsonprintr = $JSON->parse(stripslashes($origjson));
    $submitted = true;
} else {
    $origjsonprintr = "Not submitted";
}
$newjson = $_REQUEST["newjson"];
if (!empty($newjson)) {
    $newjsonprintr = $JSON2->decode(stripslashes($newjson));
} else {
    $newjsonprintr = "Not submitted";
}
//---- content -----------------------------------------------------------------
?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<title>JSON parser test</title>
예제 #6
0
    # the file with the newly uploaded content.
    foreach ($data['data'] as $field) {
        # Set Filename
        $filename = ROOT_DIR . '/site/_content/index/' . $field['ID'] . '.html';
        # Check for file
        if (!is_writeable($filename)) {
            $unsaved++;
        }
        # Attempt to save content
        if (file_exists($filename) && file_put_contents($filename, trim($field['content'], "\t\r\n"))) {
            $saved++;
        }
    }
    # Check for success
    switch (true) {
        # All saved
        case $saved > 0 && $unsaved === 0:
            JSON::parse(200, 'positive', '<i class="fa fa-check-circle"></i> Changes saved.', null, true);
            break;
            # Some saved
        # Some saved
        case $saved > 0 && $unsaved > 0:
            JSON::parse(200, 'warning', '<i class="fa fa-check-circle"></i> Some changes were not saved.', null, true);
            break;
            # No saved
        # No saved
        case $saved === 0 && $unsaved > 0:
            JSON::parse(200, 'negative', '<i class="fa fa-check-circle"></i> Changes were not saved.', null, true);
            break;
    }
}
예제 #7
0
파일: JSONTest.php 프로젝트: firehed/input
 /**
  * @covers ::parse
  * @dataProvider formatErrors
  * @expectedException Firehed\Input\Exceptions\InputException
  * @expectedExceptionCode Firehed\Input\Exceptions\InputException::FORMAT_ERROR
  */
 public function testFormatError($json)
 {
     $parser = new JSON();
     $parser->parse($json);
 }
예제 #8
0
# Check Method is Post
if (!is_form_data()) {
    JSON::parse(100, 'negative', 'Invalid request. Requests to ' . $path . ' must be POST', null, true);
}
# Actions
$actions = array(1, 0, -1);
# Sanitize form data
$data = Helpers::sanitizeInput(form_data());
# Check for post IDs
if (!isset($data['posts']) || !isset($data['action'])) {
    JSON::parse(100, 'negative', 'Missing data.', $data, true);
}
# Get Post IDs
$posts = json_decode($data['posts'], true);
# Typecast Action
$action = (int) $data['action'];
# Check Action is Valid
if (!in_array($action, $actions)) {
    JSON::parse(100, 'negative', 'Invalid action.', null, true);
}
# Create new Content Object
$content = new Content($_cck_types, $_cck_config);
# Update each post
foreach ($posts as $post) {
    if (!$content->update($post, array('status' => $action))) {
        JSON::parse(100, 'negative', 'Post ID: ' . $post . ' was not updated.', null, true);
    }
}
# Return result
JSON::parse(200, 'positive', 'Posts updated', form_data(), true);
예제 #9
0
<?php

use CCK\Helpers;
# Check Method is Post
if (!is_form_data()) {
    JSON::parse(100, 'negative', 'Invalid request. Requests to ' . $path . ' must be POST', null, true);
}
# Sanitize form data
$data = Helpers::sanitizeInput(form_data());
# Check 'alias' is present
if (!isset($data['alias']) || !is_string($data['alias'])) {
    JSON::parse(100, 'negative', 'Alias input is not valid.', null, true);
}
# Generate Alias
$alias = cck_url_alias($data['alias']);
# Return result
JSON::parse(200, 'positive', 'Alias generate', array('alias' => $alias), true);
예제 #10
0
<?php

use CCK\Media;
$media = new Media($_cck_config);
# Get All Media
if ($theMedia = $media->get($_GET)) {
    JSON::parse(200, 'success', 'Status: OK', $theMedia, true);
}