Methods for handling JSON output, usually for AJAX responses

/modules/Welcome/Controllers/WelcomeController.php Highlighted file source
Line 31: use Sprout\Helpers\Json;
Line 257: if (empty($_POST['host'])) Json::out(['result' => 'You must specify a host']);
Line 258: if (empty($_POST['user'])) Json::out(['result' => 'You must specify a user']);
Line 259: if (empty($_POST['pass'])) Json::out(['result' => 'You must specify a pass']);
Line 260: if (empty($_POST['database'])) Json::out(['result' => 'You must specify a database']);
Line 268: Json::out(['result' => 'Connection successful']);
Line 270: Json::out(['result' => $ex->getMessage()]);
Line 765: $data['settings'] = json_encode(['text' => $content]);
Line 788: $data['link'] = json_encode(['class' => '\Sprout\Helpers\LinkSpecPage', 'data' => '3']);
Line 799: $data['link'] = json_encode(['class' => '\Sprout\Helpers\LinkSpecPage', 'data' => '4']);
Line 809: $data['link'] = json_encode(['class' => '\Sprout\Helpers\LinkSpecPage', 'data' => '9']);
Line 820: $data['link'] = json_encode(['class' => '\Sprout\Helpers\LinkSpecPage', 'data' => '10']);

/sprout/Controllers/Admin/FileAdminController.php Highlighted file source
Line 39: use Sprout\Helpers\Json;
Line 165: * @return void Outputs JSON
Line 170: Json::error('Invalid "index" param');
Line 173: Json::error('Invalid "code" param');
Line 177: Json::error('Temporary directory does not exist');
Line 180: Json::error('Temporary directory is not writable');
Line 186: Json::error('Move of chunk to temporary directory failed');
Line 189: Json::confirm();
Line 196: * Outputs a JSON response.
Line 203: * @return void Outputs JSON
Line 208: Json::error('Invalid "num" param');
Line 211: Json::error('Invalid "code" param');
Line 219: Json::error($ex->getMessage());
Line 222: Json::confirm(array(
Line 292: * @get array result The full JSON response from the ajaxDragdropDone call
Line 375: * Output JSON should be:
Line 380: * @return void Outputs JSON
Line 390: Json::error('This type of file cannot be uploaded');
Line 393: Json::error('You must specify a name');
Line 405: Json::error($ex);
Line 435: return Json::error('Database error');
Line 446: return Json::error('Database error');
Line 478: return Json::error('Copying temporary file into media repository failed');
Line 485: Json::error($ex);
Line 495: Json::confirm([
Line 522: * @return void Outputs JSON directly (see {@see Json::out})
Line 526: if (empty($_GET['term'])) Json::out([]);
Line 542: Json::out(Pdb::q($q, $params, 'col'));
Line 556: * Used by some AJAX stuff to return a JSON error
Line 560: Json::out(array('valid' => 0, 'error' => $message));
Line 567: * Returns JSON.
Line 579: echo '<div>', json_encode($result), '</div>';
Line 909: $points = @json_decode($_POST['focal_points'], true);
Line 921: $data['focal_points'] = json_encode($points);
Line 968: $dest_link_spec = json_encode([
Line 1248: Cron::message("Deleted file: " . json_encode($file));
Line 1445: // Json return object
Line 1446: $json = array();
Line 1447: $json[] = array(
Line 1453: // Append one json record for each db record
Line 1463: $json[] = array(
Line 1472: Json::out($json);
Line 1545: * @param string $focal_point_data JSON to store in files.focal_points

/sprout/Controllers/Admin/HasCategoriesAdminController.php Highlighted file source
Line 29: use Sprout\Helpers\JsonForm;
Line 533: // Auto-generate form from JSON where possible
Line 536: $conf = $this->loadEditJson();
Line 600: // Auto-generate form from JSON where possible
Line 603: $conf = $this->loadEditJson();
Line 608: $data = array_merge($data, JsonForm::loadMultiEditData($conf, $default_link, $id, []));
Line 609: $data = array_merge($data, JsonForm::loadAutofillListData($conf, $this->table_name, $id, []));
Line 696: // Auto-generate form from JSON where possible
Line 699: $conf = $this->loadEditJson();
Line 704: $data = array_merge($data, JsonForm::loadMultiEditData($conf, $default_link, $id, []));
Line 705: $data = array_merge($data, JsonForm::loadAutofillListData($conf, $this->table_name, $id, []));

/sprout/Controllers/Admin/ManagedAdminController.php Highlighted file source
Line 32: use Sprout\Helpers\Json;
Line 33: use Sprout\Helpers\JsonForm;
Line 1208: // Auto-generate form from JSON where possible
Line 1211: $conf = $this->loadEditJson();
Line 1276: * Inject the visiblity fields into a loaded json configuration, so they actually save
Line 1278: * @param array $conf JSON add/edit configuration
Line 1340: // Auto-process form using JSON config
Line 1341: $conf = $this->loadEditJson();
Line 1343: return $this->saveJsonData($conf, $item_id);
Line 1379: // Auto-generate form from JSON where possible
Line 1382: $conf = $this->loadEditJson();
Line 1387: $data = array_merge($data, JsonForm::loadMultiEditData($conf, $default_link, $id, []));
Line 1388: $data = array_merge($data, JsonForm::loadAutofillListData($conf, $this->table_name, $id, []));
Line 1505: // Auto-process form using JSON config
Line 1506: $conf = $this->loadEditJson();
Line 1508: return $this->saveJsonData($conf, $item_id);
Line 1567: // Auto-generate form from JSON where possible
Line 1570: $conf = $this->loadEditJson();
Line 1575: $data = array_merge($data, JsonForm::loadMultiEditData($conf, $default_link, $id, []));
Line 1576: $data = array_merge($data, JsonForm::loadAutofillListData($conf, $this->table_name, $id, []));
Line 1855: * Multi-tag some items. Uses AJAX. Returns JSON.
Line 1857: public function postJsonMultiTag()
Line 1862: Json::error('Access denied');
Line 1866: Json::error('No items selected for tagging');
Line 1871: Json::error('No tags entered');
Line 1881: Json::confirm();
Line 1889: * @return void Echos JSON directly
Line 1902: Json::out($records);
Line 1907: Json::out($records);
Line 1915: * @return void Echos JSON directly
Line 1935: Json::out($records);
Line 1940: Json::out($records);

/sprout/Controllers/Admin/PageAdminController.php Highlighted file source
Line 46: use Sprout\Helpers\Json;
Line 825: $update_fields['settings'] = json_encode($settings);
Line 1012: $settings = json_decode($widget['settings'], true);
Line 1219: Json::out($out);
Line 1233: Json::confirm(array('groups' => array()));
Line 1240: if ($node === null) Json::error('Invalid parent page');
Line 1252: Json::confirm(array('groups' => $names));
Line 1313: $settings = json_encode($settings);
Line 1400: $settings = json_decode($widget['settings'], true);
Line 1404: $widget['settings'] = json_encode($settings);
Line 2168: $settings = json_decode($row['settings'], true);
Line 2771: * Return JSON list of custom widget templates as defined by skin config

/sprout/Controllers/AdminAjaxController.php Highlighted file source
Line 29: use Sprout\Helpers\Json;
Line 73: $settings = json_decode($_POST['settings'], true);
Line 77: $settings = json_decode($_GET['settings'], true);
Line 81: Json::error(
Line 95: Json::error($ex);
Line 116: Json::confirm(array(
Line 123: Json::error($ex);
Line 155: * Output is JSON with two keys, 'op' and 'val'. They are both
Line 159: * @return void Outputs JSON and then terminates
Line 170: Json::error($ex);
Line 184: Json::error('Invalid param type "' . $type . '"');
Line 187: Json::out([
Line 242: Json::out($ret);
Line 252: Json::error('Invalid class; missing interface');
Line 261: Json::out($args);
Line 276: if ($_POST['name'] == '') Json::error('Please enter a category name to add');
Line 277: if ($_POST['table'] == '') Json::error('Invalid arguments');
Line 293: Json::error('Database error');
Line 303: Json::out($out);
Line 343: Json::confirm(array(
Line 362: Json::confirm(array(
Line 390: Json::confirm(array(
Line 423: * Handle an upload of a document. Echos DIV-warapped JSON with the result of the import.
Line 459: echo '<div>', Enc::html(json_encode($out)), '</div>';
Line 465: * Demo AJAX JSON callback url for {@see Fb::conditionsList}
Line 469: * Output is JSON with two keys, 'op' and 'val'. They are both
Line 473: * @return void Outputs JSON and then terminates
Line 517: Json::out([

/sprout/Controllers/Controller.php Highlighted file source
Line 26: use Sprout\Helpers\JsonForm;
Line 139: $insert_data['data'] = json_encode($data);
Line 361: * Loads a config file for a JsonForm associated with this controller
Line 362: * @param string $file_name The config file name, e.g. 'register.json'
Line 367: protected function loadFormJson($file_name)
Line 372: throw new FileMissingException("Missing JSON file: {$conf_file}");
Line 374: throw new Exception("Empty JSON file");
Line 378: $conf = json_decode($conf, true);
Line 380: throw new Exception("Invalid JSON -- " . json_last_error_msg());
Line 387: * Loads a JSON config file for an automated edit-type form for this controller
Line 391: protected function loadEditJson()
Line 398: return $this->loadFormJson("{$class}_edit.json");
Line 403: * Generates a form view from a JSON config file
Line 409: $conf = $this->loadFormJson($file_name);
Line 423: protected function jsonExtraValidate($id, Validator $validator)
Line 435: * @param array $conf Json form configuration
Line 452: JsonForm::setParameterForColumns($items, $fk_cols, 'empty', null);
Line 471: JsonForm::setParameterForColumns($multi['items'], $fk_cols, 'empty', null);
Line 478: * Automatically saves the data associated with a submission on a JSON-generated form
Line 479: * @param array $conf Config loaded from a JSON file
Line 486: protected function saveJsonData(array $conf, &$item_id, $mode = '')
Line 500: list($data, $errs) = JsonForm::collateData($conf, $mode, $validator, $item_id);
Line 502: $this->jsonExtraValidate($item_id, $validator);
Line 558: $field_defns = JsonForm::flattenGroups($multed['items']);
Line 597: $auto = JsonForm::autofillOptionDefaults($auto, $this->table_name);

/sprout/Controllers/DbToolsController.php Highlighted file source
Line 51: use Sprout\Helpers\Json;
Line 148: if (strpos(Router::$method, 'json_') === 0) return;
Line 762: echo Json::out($res);
Line 1612: $target = Enc::html(json_encode($target, JSON_UNESCAPED_SLASHES));
Line 1753: $json = "{$t}{$t}{\n" .
Line 1767: $json .= "{$t}{$t}{$t}{$t}{$t}{\"func\": \"Validity::length\", \"args\": [0, {$field_len}]}\n";
Line 1769: $json .= "{$t}{$t}{$t}{$t}]\n" .
Line 1772: $fields_json[] = $json;
Line 1805: $_POST['_fields_json'] = implode(",\n", $fields_json);
Line 2046: $fields_json = array();
Line 2120: $json = "{$tab}{$tab}{\n" .
Line 2134: $json .= "{$tab}{$tab}{$tab}{$tab}{$tab}{\"func\": \"Validity::length\", \"args\": [0, {$field_len}]}\n";
Line 2137: $json .= "{$tab}{$tab}{$tab}{$tab}]\n" .
Line 2140: $fields_json[] = $json;
Line 2171: $_POST['_fields_json'] = implode(",\n", $fields_json);
Line 2246: $text = str_replace('FIELDS_JSON', $_POST['_fields_json'], $text);

/sprout/Controllers/FileUploadController.php Highlighted file source
Line 23: use Sprout\Helpers\Json;
Line 47: Json::error('Invalid data');
Line 64: Json::error('Invalid data');
Line 68: Json::error('Invalid data');
Line 77: Json::error('Invalid data');
Line 102: Json::error('Invalid data');
Line 106: Json::error('Invalid data');
Line 114: Json::error('Invalid data');
Line 148: Json::confirm([]);
Line 205: * @return void Outputs JSON
Line 213: Json::error('Temporary directory does not exist');
Line 216: Json::error('Temporary directory is not writable');
Line 221: Json::error('Error uploading chunk');
Line 226: Json::error('The uploaded file chunk was empty, there may have been a network fault during your upload');
Line 231: Json::error('Invalid data');
Line 240: Json::error('File upload wasn\'t started correctly');
Line 248: Json::error('File chunks received out of sequence, you may have experienced a network error');
Line 256: Json::error('Maximum number of upload chunks exceeded');
Line 264: Json::error('Move of chunk to temporary directory failed');
Line 267: Json::confirm();
Line 274: * Outputs a JSON response.
Line 281: * @return void Outputs JSON
Line 293: Json::error('Invalid number of chunks uploaded');
Line 302: Json::error('Final filesize didn\'t match upload size');
Line 305: Json::error($ex->getMessage());
Line 308: Json::confirm(array(
Line 318: * @get array result The full JSON response from the ajaxDragdropDone call

/sprout/Helpers/Fb.php Highlighted file source
Line 446: $out = '<div class="fb-chunked-upload" data-opts="' . Enc::html(json_encode($opts)) . '">';
Line 799: * A call to the URL should return JSON which contains an array of hashes, each with the following keys:
Line 866: * Endpoint to return (json):
Line 1277: $attrs['data-locale'] = json_encode($options['locale']);
Line 1369: $out = "<span id=\"{$id}_wrap\" class=\"fb-timepicker\" data-config=\"" . Enc::html(json_encode($params)) . "\">";
Line 1553: * Output POST data will be a JSON string of the condition rules,
Line 1563: * should output JSON with two keys, 'op' and 'val', which are both
Line 1701: * As JsonForm will auto-convert arrays into comma-separated strings, this field can easily be used with a MySQL

/sprout/Helpers/Json.php Highlighted file source
Line 20: * Methods for handling JSON output, usually for AJAX responses
Line 22: class Json
Line 26: * Sends a JSON message which has the success field set to zero
Line 37: $json = array('success' => 0, 'message' => $message->getMessage());
Line 40: $json['file'] = $message->getFile();
Line 41: $json['line'] = $message->getLine();
Line 42: $json['stacktrace'] = $message->getTraceAsString();
Line 46: $json = array('success' => 0, 'message' => $message);
Line 49: header('Content-type: application/json');
Line 50: echo json_encode($json);
Line 56: * Sends a JSON confirmation response, and then terminates.
Line 59: * If no data is provided, the returned JSON will only contain the 'success' key.
Line 69: header('Content-type: application/json');
Line 70: echo json_encode($data);
Line 76: * Outputs the JSON data (encoded) + correct mime type, then stops script execution
Line 78: * @param mixed $data Any kind of data to be JSON encoded
Line 79: * @param int $options E.g. JSON_PRETTY_PRINT, as per http://php.net/manual/en/function.json-encode.php
Line 85: header('Content-type: application/json');
Line 86: echo json_encode($data, $options);

/sprout/Helpers/JsonForm.php Highlighted file source
Line 21: * Processes forms using configuration stored in a JSON file which specifies database columns, their HTML input fields,
Line 24: * (generates the form) and {@see Controller::saveJsonData} (saves the POST submission)
Line 26: class JsonForm extends Form
Line 31: * @param array $conf The form config, pulled from JSON
Line 84: * @param array $auto Auto link opts, from a JSON form defintion
Line 108: * @param array $conf The form config, pulled from JSON
Line 175: * Expands item definitions for a field pulled from JSON
Line 289: return JsonForm::renderField($field, $name_prepend, $metadata);
Line 388: // The autofillList method receives the whole object in $options straight from the JSON
Line 401: * Renders the input for a field definition pulled from a JSON file
Line 475: * @param array $conf Config, typically loaded by Controller::loadFormJson()
Line 478: * validation before and/or after collating the JsonForm data
Line 600: * @param array $field_defn Field definition from JSON file
Line 667: * @param array $args Arguments in the JsonForm definition
Line 684: * Modify a JSON form config to make a particular field optional
Line 685: * @param array $conf The JSON form config
Line 695: * Modify a JSON form config to make a particular field required
Line 696: * @param array $conf The JSON form config
Line 706: * Modify a JSON form config to change the 'required' status of a particular field
Line 707: * This implements {@see JsonForm::makeOptional} and {@see JsonForm::makeRequired}
Line 708: * @param array $conf The JSON form config
A total of 273 lines in 19 files were found