Skip to content
This repository was archived by the owner on Nov 26, 2023. It is now read-only.

Commit b500d94

Browse files
committed
Reversed previous commit
1 parent 8875903 commit b500d94

File tree

3 files changed

+151
-66
lines changed

3 files changed

+151
-66
lines changed

system/user/addons/json/README.md

+57-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# JSON #
22

3+
Output ExpressionEngine data in JSON format.
4+
35
## Requirements
46

57
- ExpressionEngine 4.x, 5.x or 6.x
@@ -12,10 +14,9 @@
1214
I don't own Assets, Matrix and Playa modules, so if you use Assets, Matrix or Playa fields I recommend to verify whether changes to the code are required and to test this plugin on a local or development server before using it on a production/live server.
1315
Since this plugin only outputs data I don't expect any damage but I will not accept any liability for any problems risen from using this plugin.
1416

15-
***Do not select duplicate custom fields in channels***
17+
***No duplicate custom fields in channels!***
1618

17-
Since EE4 it is possible to use custom fields outside of field groups as well as inside field groups. This plugin will not work when a new custom field is assigned as a standalone custom field as well as a grouped custom field within the same channel. You need to choose to use either a grouped custom field or a standalone custom field. This is because newly created custom fields get their own table in the database.
18-
Since legacy custom fields do not have their own table they will work fine either way.
19+
Since EE4 it is possible to use custom fields outside of field groups as well as inside field groups. This plugin will not work when a custom field is assigned as a standalone custom field as well as a grouped custom field within the same channel. You need to choose to use either a grouped custom field or a standalone custom field.
1920

2021
***Fluid fieldtype***
2122

@@ -456,20 +457,15 @@ function yourCallbackFunction(data) {
456457

457458
## Changelog
458459

459-
### v2.5.1
460-
461-
- Bugfix: Removed all remnants of fluid field data, since the Fluid fieldtype is not (yet) supported the remnant data is unusable at this point. Working on support for Fluid fieldtype
462-
- Bugfix: Updated the `members` function to fit EE6.x
463-
- **Note:** not tested with Assets, Matrix, Playa and Channel Files fieldtypes/modules
464-
465460
### v2.5.0
466461

467-
- ExpressionEngine 4+ compatibility
462+
- ExpressionEngine 4.x, 5.x or 6.x required
468463
- Several changes to the code due to database changes
469464
- Added support for File Grid fieldtype
470-
- Added support for legacy custom fields and data (EE2 and EE3 custom fields and data) for compatibility with upgraded versions of EE4+
471-
- Added `/system/user/addons/json/icon.png` for the EE6 control panel
472-
- **Note:** not tested with Assets, Matrix, Playa and Channel Files fieldtypes/modules
465+
- Added support for legacy custom fields and data (EE2 and EE3 custom fields and data)
466+
- Added `/system/user/addons/json/icon.png` for the control panel
467+
- Fluid fieldtype not supported
468+
- **Note:** not tested with Assets, Matrix and Playa
473469

474470
### v1.1.9
475471

@@ -479,8 +475,53 @@ function yourCallbackFunction(data) {
479475
- Added `/system/user/addons/json/README.md` for the add-on manual in the control panel (as of EE3)
480476
- **Note:** not tested with Assets, Matrix and Playa
481477

482-
## Attribution
478+
### v1.1.8
479+
480+
- Added `json_plugin_entries_end` and `json_plugin_members_end` hooks
481+
- Improved Wygwam support
482+
- Fixed intermittent disappearing `ee()->TMPL` object
483+
484+
### v1.1.7
485+
486+
- Added `offset` support for members
487+
488+
### v1.1.6
489+
490+
- Add Channel Files support.
491+
492+
### v1.1.5
493+
494+
- Add `root_node` and `item_root_node` parameters.
495+
496+
### v1.1.4
497+
498+
- Add manipulations to Assets fields
499+
500+
### v1.1.3
501+
502+
- Fix bug where show_categories parameter did not work
503+
504+
### v1.1.2
505+
506+
- Fix bug where `fields` parameter was not being honored
507+
- Fix bug causing fatal MySQL error when using the `fixed_order` parameter
508+
509+
### v1.1.1
510+
511+
- Fix WSOD on Plugins page
512+
- Fix PHP errors when an Assests field has no selection(s)
513+
514+
### v1.1.0
515+
516+
- Added support for the following fieldtypes: Assets, Grid, Playa, Relationships
517+
- Change IDs (entry_id, author_id, etc.) and Dates to integers
518+
- Added `show_categories` and `show_category_group` parameters to `{exp:json:entries}`
519+
- Added `{exp:json:search}`
520+
- Added JSONP support
521+
- Added `date_format` parameter
522+
- Added `content_type` parameter
483523

484-
This plugin is a fork of the excellent [JSON plugin](https://github.com/rsanchez/json) by [Rob Sanchez](https://github.com/rsanchez).
524+
## Upgrading from 1.0.x
485525

486-
Since I'm a jack of all trades and master of none, I could have never done this without the jumpstart Rob Sanchez's plugin gave me.
526+
- IDs (entry_id, author_id, etc.) and Dates are returned as integers
527+
- The following fieldtypes have different output: Playa, Assets. Please see docs above for an example of their output.
+8-11
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
<?php
22
/*
33
*
4-
* Original author: Rob Sanchez
5-
* Original author URL: https://github.com/rsanchez
6-
* Original docs URL: https://github.com/rsanchez/json
7-
*
8-
* Requires ExpressionEngine 4.x, 5.x or 6.x.
4+
* Requires ExpressionEngine 6.
95
* Older versions of ExpressionEngine are not supported.
106
*
11-
* EE4-EE6 compatibility created by Zignature.
7+
* EE6 compatibility created by Zignature.
8+
* https://github.com/zignature/json
129
*
1310
*/
1411
return array(
15-
'author' => 'Zignature',
16-
'author_url' => 'https://github.com/zignature',
12+
'author' => 'Rob Sanchez',
13+
'author_url' => 'https://github.com/rsanchez',
1714
'description' => 'Output ExpressionEngine channel entries in JSON format.',
18-
'docs_url' => 'https://github.com/zignature/json',
15+
'docs_url' => 'https://github.com/rsanchez/json',
1916
'name' => 'JSON',
2017
'settings_exist' => FALSE,
21-
'version' => '2.5.1',
22-
'namespace' => 'zignature/json'
18+
'version' => '2.5.0',
19+
'namespace' => 'rsanchez/json'
2320
);

system/user/addons/json/pi.json.php

+86-39
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ public function entries($entry_ids = null)
3030
{
3131
$this->initialize('entries');
3232

33-
// exit if ajax request is required and not found
33+
//exit if ajax request is required and not found
3434
if ($this->check_xhr_required())
3535
{
3636
return '';
3737
}
3838

39-
// instantiate channel module object
39+
//instantiate channel module object
4040
if (empty($this->channel))
4141
{
4242
require_once PATH_MOD.'channel/mod.channel.php';
@@ -55,7 +55,7 @@ public function entries($entry_ids = null)
5555
}
5656
else
5757
{
58-
// run through the channel module process to grab the entries
58+
//run through the channel module process to grab the entries
5959
$this->channel->uri = ($this->channel->query_string != '') ? $this->channel->query_string : 'index.php';
6060

6161
if ($this->channel->enable['custom_fields'] === TRUE)
@@ -107,7 +107,6 @@ public function entries($entry_ids = null)
107107
->join('channels_channel_field_groups', 'channel_field_groups_fields.group_id = channels_channel_field_groups.group_id')
108108
->join('channels', 'channels_channel_field_groups.channel_id = channels.channel_id')
109109
->where('channels.site_id', ee()->config->item('site_id'))
110-
->where('channel_fields.field_type !=', 'fluid_field')
111110
->where_in('channels.channel_name', explode('|', ee()->TMPL->fetch_param('channel')))
112111
->get()
113112
->result_array();
@@ -117,7 +116,6 @@ public function entries($entry_ids = null)
117116
->join('channels_channel_fields', 'channel_fields.field_id = channels_channel_fields.field_id')
118117
->join('channels', 'channels_channel_fields.channel_id = channels.channel_id')
119118
->where('channels.site_id', ee()->config->item('site_id'))
120-
->where('channel_fields.field_type !=', 'fluid_field')
121119
->where_in('channels.channel_name', explode('|', ee()->TMPL->fetch_param('channel')))
122120
->get()
123121
->result_array();
@@ -160,20 +158,19 @@ public function entries($entry_ids = null)
160158
{
161159
if (empty($this->fields) || in_array($field['field_name'], $this->fields))
162160
{
163-
164-
if ( ee()->db->table_exists('channel_data_field_'.$field['field_id']) )
161+
if ( ee()->db->table_exists('channel_data_field_'.$field['field_id']) AND ee()->db->field_exists('field_id_'.$field['field_id'], 'channel_data_field_'.$field['field_id']) )
165162
{
166163
$select[] = 'cdf_'.$field['field_id'].'.'.ee()->db->protect_identifiers('field_id_'.$field['field_id']).' AS '.ee()->db->protect_identifiers($field['field_name']);
167164
}
168-
// We got legacy channel data, let's get it
165+
// Legacy data?
169166
else
170167
{
171-
$select[] = 'lcd.'.ee()->db->protect_identifiers('field_id_'.$field['field_id']).' AS '.ee()->db->protect_identifiers($field['field_name']);
168+
$select[] = 'cd.'.ee()->db->protect_identifiers('field_id_'.$field['field_id']).' AS '.ee()->db->protect_identifiers($field['field_name']);
172169
}
173170
}
174171
}
175172

176-
// we need entry_id, always grab it
173+
//we need entry_id, always grab it
177174
if ( ! in_array('t.entry_id', $select))
178175
{
179176
$select[] = 't.entry_id';
@@ -188,19 +185,11 @@ public function entries($entry_ids = null)
188185
{
189186
ee()->db->join('channel_data_field_'.$field['field_id'].' cdf_'.$field['field_id'], 't.entry_id = cdf_'.$field['field_id'].'.entry_id');
190187
}
191-
// We got legacy channel data, let's join it
192-
else
193-
{
194-
// Make sure the legacy channel data has not already been joined
195-
if ( ! isset($is_legacy_data_joined) ) {
196-
// join legacy channel data
197-
ee()->db->join('channel_data lcd', 't.entry_id = lcd.entry_id');
198-
// Set flag because we want this join only once!
199-
$is_legacy_data_joined = TRUE;
200-
}
201-
}
202188
}
203189

190+
// legacy data
191+
ee()->db->join('channel_data cd', 't.entry_id = cd.entry_id');
192+
204193
ee()->db->where_in('t.entry_id', $this->entries_entry_ids);
205194

206195

@@ -260,7 +249,7 @@ public function entries($entry_ids = null)
260249
unset($entry['yearweek']);
261250
}
262251

263-
// format dates as javascript unix time (in microseconds!)
252+
//format dates as javascript unix time (in microseconds!)
264253
if (isset($entry['entry_date']))
265254
{
266255
$entry['entry_date'] = $this->date_format($entry['entry_date']);
@@ -278,14 +267,10 @@ public function entries($entry_ids = null)
278267

279268
foreach ($this->entries_custom_fields as &$field)
280269
{
281-
// check for file grid fieldtype, if found "convert" it to grid fieldtype
282-
$field_type = $field['field_type'];
283-
if ( $field_type == "file_grid" ) $field_type = "grid";
284-
285-
// call our custom callback for this fieldtype if it exists
286-
if (is_callable(array($this, 'entries_'.$field_type)))
270+
//call our custom callback for this fieldtype if it exists
271+
if (is_callable(array($this, 'entries_'.$field['field_type'])))
287272
{
288-
$entry[$field['field_name']] = call_user_func(array($this, 'entries_'.$field_type), $entry['entry_id'], $field, $entry[$field['field_name']], $entry);
273+
$entry[$field['field_name']] = call_user_func(array($this, 'entries_'.$field['field_type']), $entry['entry_id'], $field, $entry[$field['field_name']], $entry);
289274
}
290275
}
291276

@@ -345,7 +330,6 @@ public function entries($entry_ids = null)
345330
return $this->respond($this->entries, array(ee()->typography, 'parse_file_paths'));
346331
}
347332

348-
349333
protected function entries_matrix($entry_id, $field, $field_data)
350334
{
351335
if (is_null($this->entries_matrix_rows))
@@ -413,11 +397,74 @@ protected function entries_grid($entry_id, $field, $field_data)
413397
{
414398
if ( ! isset($this->entries_grid_rows[$field['field_id']]))
415399
{
416-
$query = ee()->db->where('fluid_field_data_id', '0')
417-
->where_in('entry_id', $this->entries_entry_ids)
400+
$query = ee()->db->where_in('entry_id', $this->entries_entry_ids)
418401
->order_by('row_order')
419402
->get('channel_grid_field_'.$field['field_id']);
420403

404+
foreach ($query->result_array() as $row)
405+
{
406+
if ( ! isset($this->entries_grid_rows[$field['field_id']][$row['entry_id']]))
407+
{
408+
$this->entries_grid_rows[$field['field_id']][$row['entry_id']] = array();
409+
}
410+
411+
$this->entries_grid_rows[$field['field_id']][$row['entry_id']][] = $row;
412+
}
413+
414+
$query->free_result();
415+
}
416+
417+
if (is_null($this->entries_grid_cols))
418+
{
419+
$query = ee()->db->order_by('col_order', 'ASC')
420+
->get('grid_columns');
421+
422+
foreach ($query->result_array() as $row)
423+
{
424+
if ( ! isset($this->entries_grid_cols[$row['field_id']]))
425+
{
426+
$this->entries_grid_cols[$row['field_id']] = array();
427+
}
428+
429+
$this->entries_grid_cols[$row['field_id']][$row['col_id']] = $row;
430+
}
431+
432+
$query->free_result();
433+
}
434+
435+
$data = array();
436+
437+
if (isset($this->entries_grid_rows[$field['field_id']][$entry_id]) && isset($this->entries_grid_cols[$field['field_id']]))
438+
{
439+
foreach ($this->entries_grid_rows[$field['field_id']][$entry_id] as $grid_row)
440+
{
441+
$row = array('row_id' => (int) $grid_row['row_id']);
442+
443+
foreach ($this->entries_grid_cols[$field['field_id']] as $col_id => $col)
444+
{
445+
// $row[$col['col_name']] = $grid_row['col_id_'.$col_id];
446+
$val = $grid_row['col_id_' . $col_id];
447+
if ($col['col_type'] == 'relationship')
448+
{
449+
$val = $this->entries_grid_relationship($col_id, $row['row_id'], $entry_id);
450+
}
451+
$row[$col['col_name']] = $val;
452+
}
453+
454+
$data[] = $row;
455+
}
456+
}
457+
458+
return $data;
459+
}
460+
461+
protected function entries_file_grid($entry_id, $field, $field_data)
462+
{
463+
if ( ! isset($this->entries_grid_rows[$field['field_id']]))
464+
{
465+
$query = ee()->db->where_in('entry_id', $this->entries_entry_ids)
466+
->order_by('row_order')
467+
->get('channel_grid_field_'.$field['field_id']);
421468

422469
foreach ($query->result_array() as $row)
423470
{
@@ -779,7 +826,8 @@ protected function entries_custom_field($entry_id, $field, $field_data, $entry,
779826
return $field_data;
780827
}
781828

782-
protected function entries_wygwam($entry_id, $field, $field_data, $entry) {
829+
protected function entries_wygwam($entry_id, $field, $field_data, $entry)
830+
{
783831
return $this->entries_custom_field($entry_id, $field, $field_data, $entry);
784832
}
785833

@@ -821,7 +869,7 @@ protected function entries_assets($entry_id, $field, $field_data, $entry)
821869
{
822870
$source_type = $row['source_type'];
823871
$filedir_id = $row['filedir_id'];
824-
// excise any other fields from this row
872+
//excise any other fields from this row
825873
$row = array_intersect_key($row, array_flip($fields));
826874
$row['file_id'] = (int) $row['file_id'];
827875
$row['date'] = $this->date_format($row['date']);
@@ -996,6 +1044,7 @@ public function members()
9961044
'm.timezone',
9971045
);
9981046

1047+
// for backwards compatibility
9991048
if (version_compare(APP_VER, '6.0.0', '>='))
10001049
{
10011050
$default_fields[1] = "m.role_id";
@@ -1056,8 +1105,7 @@ public function members()
10561105

10571106
if (ee()->TMPL->fetch_param('group_id'))
10581107
{
1059-
$m_group_id = version_compare(APP_VER, '6.0.0', '>=') ? 'm.role_id' : 'm.group_id';
1060-
ee()->db->where_in($m_group_id, explode('|', ee()->TMPL->fetch_param('group_id')));
1108+
ee()->db->where_in('m.group_id', explode('|', ee()->TMPL->fetch_param('group_id')));
10611109
}
10621110

10631111
if (ee()->TMPL->fetch_param('limit'))
@@ -1105,7 +1153,7 @@ protected function initialize($which = NULL)
11051153
switch($which)
11061154
{
11071155
case 'entries':
1108-
// initialize caches
1156+
//initialize caches
11091157
$this->entries = array();
11101158
$this->entries_entry_ids = array();
11111159
$this->entries_custom_fields = array();
@@ -1179,8 +1227,7 @@ protected function respond(array $response, $callback = NULL)
11791227
}
11801228

11811229
$response = function_exists('json_encode')
1182-
// ? json_encode($response,JSON_PRETTY_PRINT)
1183-
? json_encode($response)
1230+
? json_encode($response,JSON_PRETTY_PRINT) // json_encode($response,JSON_PRETTY_PRINT) for development
11841231
: ee()->javascript->generate_json($response, TRUE);
11851232

11861233
if ( ! is_null($callback))

0 commit comments

Comments
 (0)