<?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);
use CCK\Content; # 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);