Skip to content

Commit 5d9087b

Browse files
committedNov 16, 2018
Revert Taxonomy support
1 parent 4c0a3fe commit 5d9087b

11 files changed

+32
-207
lines changed
 

‎DOCUMENTATION.md

100644100755
-46
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ This behavior can be disabled via Fetch's settings (CP > Configure > Addons > Fe
4646

4747
### Types
4848

49-
* [**Taxonomy**](#taxonomies-examples): The Taxonomy's slug.
50-
* [**Taxonomies**](#taxonomies-examples): All Taxonomies or a comma-separated list of Taxonomy slugs.
51-
* [**Term**](#terms-examples): The Term's slug.
52-
* [**Terms**](#terms-examples): All Terms or a comma-separated list of term slugs.
5349
* [**Collection**](#collection-examples): The Collection's slug.
5450
* [**Entry**](#entry-examples): An Entry's ID or collection + slug.
5551
* [**Page**](#pages-examples): A single Page's URI.
@@ -74,48 +70,6 @@ This behavior can be disabled via Fetch's settings (CP > Configure > Addons > Fe
7470
| `debug` | URL: `http://domain.com/!/Fetch/collection/blog?debug=true` <br> Tag: `{{ fetch:blog debug="true" }}` |
7571
| `api_key` | URL: `http://domain.com/!/Fetch/collection/blog?api_key=[YOUR_KEY_HERE]` <br> Tag: `N/A`|
7672

77-
### Taxonomy Examples
78-
79-
**JS**
80-
81-
Fetch a single taxonomy
82-
```javascript
83-
axios.get('/!/Fetch/taxonomy/categories').then(...);
84-
```
85-
86-
Fetch all taxonomies
87-
```javascript
88-
axios.get('/!/Fetch/taxonomies').then(...);
89-
```
90-
91-
Fetch multiple taxonomies
92-
```javascript
93-
var globals = 'categories', 'types';
94-
95-
axios.get('/!/Fetch/taxonomies/?taxonomies='+encodeURIComponent(globals)).then(...);
96-
```
97-
98-
### Term Examples
99-
100-
**JS**
101-
102-
Fetch a single term
103-
```javascript
104-
axios.get('/!/Fetch/term/categories/cats').then(...);
105-
```
106-
107-
Fetch all terms
108-
```javascript
109-
axios.get('/!/Fetch/terms').then(...);
110-
```
111-
112-
Fetch multiple taxonomies
113-
```javascript
114-
var globals = 'cats', 'kittens';
115-
116-
axios.get('/!/Fetch/terms/?terms='+encodeURIComponent(globals)).then(...);
117-
```
118-
11973
### Collection Examples
12074

12175
**JS**

‎Fetch/Fetch.php

+25-112
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,15 @@
55
use Carbon\Carbon;
66
use Statamic\API\Str;
77
use Statamic\API\Page;
8-
use Statamic\API\Term;
98
use Statamic\API\Asset;
109
use Statamic\API\Entry;
1110
use Statamic\API\Search;
1211
use Statamic\API\Content;
13-
use Statamic\API\Taxonomy;
1412
use Statamic\API\GlobalSet;
1513
use Statamic\API\Collection;
1614
use Statamic\Extend\Extensible;
1715
use Statamic\Data\Pages\PageCollection;
1816
use Statamic\Data\Pages\Page as PageData;
19-
use Statamic\Data\Taxonomies\Taxonomy as TaxonomyData;
2017
use Illuminate\Support\Collection as IlluminateCollection;
2118

2219
class Fetch
@@ -29,17 +26,16 @@ class Fetch
2926
public $depth;
3027
public $locale;
3128
public $nested;
32-
private $page;
3329

30+
private $page;
3431
private $limit;
3532
private $offset;
3633
private $filter;
3734
private $taxonomy;
38-
private $index;
3935

36+
private $index;
4037
private $query;
4138
private $isSearch;
42-
private $withData = true;
4339

4440
private $data;
4541
private $hasNextPage;
@@ -52,107 +48,28 @@ public function __construct($params = null)
5248
$this->auth = (new FetchAuth)->isAuth();
5349
$this->deep = $this->checkDeep($params);
5450
$this->debug = bool(request('debug', $params->get('debug')));
55-
$this->depth = (int)(request('depth', $params->get('depth', null)));
51+
$this->depth = (int) (request('depth', $params->get('depth', null)));
5652
$this->locale = request('locale') ?: $params->get('locale') ?: default_locale();
5753
$this->nested = bool(request('nested', $params->get('nested', $this->getConfigBool('nested'))));
5854

59-
$this->page = (int)(request('page') ?: $params->get('page', 1));
60-
$this->limit = (int)(request('limit') ?: $params->get('limit'));
61-
$this->offset = (int)(request('offset') ?: $params->get('offset'));
55+
$this->page = (int) (request('page') ?: $params->get('page', 1));
56+
$this->limit = (int) (request('limit') ?: $params->get('limit'));
57+
$this->offset = (int) (request('offset') ?: $params->get('offset'));
6258
$this->filter = request('filter') ?: $params->get('filter');
6359
$this->taxonomy = request('taxonomy') ?: $params->get('taxonomy');
6460

6561
$this->index = request('index') ?: $params->get('index');
6662
$this->query = request('query') ?: $params->get('query');
6763
}
6864

69-
/**
70-
* Fetch taxonomy
71-
*/
72-
public function taxonomy($handle = null)
73-
{
74-
$handle = $handle ?: request()->segment(4);
75-
76-
if (!$taxonomy = Taxonomy::whereHandle($handle)) {
77-
return "Taxonomy [$handle] not found.";
78-
}
79-
80-
return $this->handle($taxonomy);
81-
}
82-
83-
/**
84-
* Fetch taxonomies
85-
*/
86-
public function taxonomies($taxonomies = null)
87-
{
88-
$taxonomies = $taxonomies ?: request('taxonomies');
89-
90-
if (!is_null($taxonomies) && !is_array($taxonomies)) {
91-
$taxonomies = explode(',', $taxonomies);
92-
}
93-
94-
if ($taxonomies) {
95-
$taxonomies = collect($taxonomies)->map(function ($handle) {
96-
return Taxonomy::whereHandle($handle);
97-
})->filter();
98-
} else {
99-
$taxonomies = Taxonomy::all();
100-
}
101-
102-
return $this->handle($taxonomies);
103-
}
104-
105-
/**
106-
* Fetch term
107-
*/
108-
public function term($slug = null)
109-
{
110-
if ($slug) {
111-
list($taxonomy, $slug) = explode('/', $slug, 2);
112-
} else {
113-
$taxonomy = request()->segment(4);
114-
$slug = request()->segment(5);
115-
}
116-
117-
if (!$term = Term::whereSlug($slug, $taxonomy)) {
118-
return "Term [$taxonomy/$slug] not found.";
119-
}
120-
121-
return $this->handle($term);
122-
}
123-
124-
/**
125-
* Fetch terms
126-
*/
127-
public function terms($terms = null)
128-
{
129-
$terms = $terms ?: request('terms');
130-
131-
if (!is_null($terms) && !is_array($terms)) {
132-
$terms = explode(',', $terms);
133-
}
134-
135-
if ($terms) {
136-
$terms = collect($terms)->map(function ($slug) {
137-
list($taxonomy, $slug) = explode('/', $slug, 2);
138-
139-
return Term::whereSlug($slug, $taxonomy);
140-
})->filter();
141-
} else {
142-
$terms = Term::all();
143-
}
144-
145-
return $this->handle($terms);
146-
}
147-
14865
/**
14966
* Fetch collection
15067
*/
15168
public function collection($name = null)
15269
{
15370
$name = $name ?: request()->segment(4);
15471

155-
if (!$collection = Collection::whereHandle($name)) {
72+
if (! $collection = Collection::whereHandle($name)) {
15673
return "Collection [$name] not found.";
15774
}
15875

@@ -165,7 +82,7 @@ public function collection($name = null)
16582
public function entry($id = null)
16683
{
16784
if (is_null($id) && request()->segment(5)) {
168-
$id = request()->segment(4) . '/' . request()->segment(5);
85+
$id = request()->segment(4).'/'.request()->segment(5);
16986
} else {
17087
$id = $id ?: request()->segment(4);
17188
}
@@ -188,16 +105,16 @@ public function page($uri = null)
188105
{
189106
$uri = $uri ?: request()->segment(4);
190107

191-
if (!$uri || $uri == 'home') {
108+
if (! $uri || $uri == 'home') {
192109
$page = Page::whereUri('/');
193110
} else {
194-
if (strpos('/' . request()->path(), $this->actionUrl('page')) !== false) {
111+
if (strpos('/'.request()->path(), $this->actionUrl('page')) !== false) {
195112
$uri = explode(ltrim($this->actionUrl('page'), '/'), request()->path())[1];
196113
}
197114

198115
$uri = Str::ensureLeft(trim($uri), '/');
199116

200-
if (!$page = Page::whereUri($uri)) {
117+
if (! $page = Page::whereUri($uri)) {
201118
return "Page [$uri] not found.";
202119
}
203120
}
@@ -212,7 +129,7 @@ public function pages($pages = null)
212129
{
213130
$pages = $pages ?: request('pages');
214131

215-
if (!is_null($pages) && !is_array($pages)) {
132+
if (! is_null($pages) && ! is_array($pages)) {
216133
$pages = explode(',', $pages);
217134
}
218135

@@ -242,7 +159,7 @@ public function global($handle = null)
242159
{
243160
$handle = $handle ?: request()->segment(4);
244161

245-
if (!$global = GlobalSet::whereHandle($handle)) {
162+
if (! $global = GlobalSet::whereHandle($handle)) {
246163
return "Page [$handle] not found.";
247164
}
248165

@@ -256,7 +173,7 @@ public function globals($globals = null)
256173
{
257174
$globals = $globals ?: request('globals');
258175

259-
if (!is_null($globals) && !is_array($globals)) {
176+
if (! is_null($globals) && ! is_array($globals)) {
260177
$globals = explode(',', $globals);
261178
}
262179

@@ -314,10 +231,10 @@ private function handle($data)
314231
}
315232

316233
$result = collect([
317-
'data' => $this->data,
318-
'page' => $this->page,
319-
'limit' => $this->limit,
320-
'offset' => $this->offset,
234+
'data' => $this->data,
235+
'page' => $this->page,
236+
'limit' => $this->limit,
237+
'offset' => $this->offset,
321238
'has_next_page' => $this->hasNextPage,
322239
'total_results' => $this->totalResults,
323240
]);
@@ -349,7 +266,7 @@ private function processNestedPages()
349266
*/
350267
private function processData()
351268
{
352-
if (!$this->data instanceof IlluminateCollection) {
269+
if (! $this->data instanceof IlluminateCollection) {
353270
$this->addTaxonomies($this->data);
354271

355272
$this->data = $this->getLocalisedData($this->data);
@@ -400,11 +317,11 @@ private function taxonomizeData()
400317
*/
401318
private function filterData()
402319
{
403-
if (!in_array($this->filter, ['published', 'unpublished'])) {
320+
if (! in_array($this->filter, ['published', 'unpublished'])) {
404321
return $this;
405322
}
406323

407-
$filter = 'filter' . Str::ucfirst($this->filter);
324+
$filter = 'filter'.Str::ucfirst($this->filter);
408325

409326
if ($this->data instanceof IlluminateCollection) {
410327
$this->data = $this->data->filter(function ($entry) use ($filter) {
@@ -514,18 +431,14 @@ private function getLocalisedData($rawData)
514431
*/
515432
private function goDeep($item)
516433
{
517-
if ($item instanceof TaxonomyData) {
518-
$item = [$item->data()];
519-
}
520-
521434
$item = collect($item)->map(function ($value, $key) {
522435
if (is_array($value)) {
523436
if ($key === 'children') {
524437
return $value;
525438
}
526439

527-
return collect($value)->map(function ($value, $key) {
528-
return $this->goDeep([$key => $value]);
440+
return collect($value)->map(function ($value) {
441+
return $this->goDeep($value);
529442
});
530443
}
531444

@@ -560,7 +473,7 @@ private function relatedData($value, $key)
560473
*/
561474
private function isRelatable($value, $key)
562475
{
563-
if ($key === 'id' && !$this->isSearch) {
476+
if ($key === 'id' && ! $this->isSearch) {
564477
return false;
565478
}
566479

@@ -601,7 +514,7 @@ private function addChildPagesToPage(PageData $page)
601514

602515
private function processPage(array $page)
603516
{
604-
if (!empty($page['children'])) {
517+
if (! empty($page['children'])) {
605518
$page['children'] = collect($page['children'])->map(function ($page) {
606519
return $this->processPage($page);
607520
})->all();

‎Fetch/FetchAuth.php

100644100755
+4-4
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ class FetchAuth
1010

1111
public function isAuth()
1212
{
13-
if ($this->getConfig('enable_api_key', false) && !$this->checkApiKey()) {
13+
if ($this->getConfig('enable_api_key', false) && ! $this->checkApiKey()) {
1414
return false;
1515
}
1616

17-
if (!empty($this->getConfig('ip_whitelist', [])) && !$this->checkServerAddr()) {
17+
if (! empty($this->getConfig('ip_whitelist', [])) && ! $this->checkServerAddr()) {
1818
return false;
1919
}
2020

21-
if (!empty($this->getConfig('domain_whitelist', [])) && !$this->checkRemoteDomain()) {
21+
if (! empty($this->getConfig('domain_whitelist', [])) && ! $this->checkRemoteDomain()) {
2222
return false;
2323
}
2424

@@ -47,7 +47,7 @@ private function checkApiKey()
4747

4848
private function checkRemoteDomain()
4949
{
50-
if (!getenv('HTTP_ORIGIN')) {
50+
if (! getenv('HTTP_ORIGIN')) {
5151
return true;
5252
}
5353

‎Fetch/FetchController.php

+1-41
Original file line numberDiff line numberDiff line change
@@ -12,52 +12,12 @@ public function __construct()
1212
{
1313
$this->fetch = new Fetch;
1414

15-
if (!$this->fetch->auth) {
15+
if (! $this->fetch->auth) {
1616
header("HTTP/1.1 401 Unauthorized");
1717
exit;
1818
}
1919
}
2020

21-
public function getTaxonomy()
22-
{
23-
return $this->fetch->taxonomy();
24-
}
25-
26-
public function postTaxonomy()
27-
{
28-
return $this->fetch->taxonomy();
29-
}
30-
31-
public function getTaxonomies()
32-
{
33-
return $this->fetch->taxonomies();
34-
}
35-
36-
public function postTaxonomies()
37-
{
38-
return $this->fetch->taxonomies();
39-
}
40-
41-
public function getTerm()
42-
{
43-
return $this->fetch->term();
44-
}
45-
46-
public function postTerm()
47-
{
48-
return $this->fetch->term();
49-
}
50-
51-
public function getTerms()
52-
{
53-
return $this->fetch->terms();
54-
}
55-
56-
public function postTerms()
57-
{
58-
return $this->fetch->terms();
59-
}
60-
6121
public function getCollection()
6222
{
6323
return $this->fetch->collection();

‎Fetch/FetchFieldtype.php

-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public function blank()
2020
* Pre-process the data before it gets sent to the publish page
2121
*
2222
* @param mixed $data
23-
*
2423
* @return array|mixed
2524
*/
2625
public function preProcess($data)
@@ -32,7 +31,6 @@ public function preProcess($data)
3231
* Process the data before it gets saved
3332
*
3433
* @param mixed $data
35-
*
3634
* @return array|mixed
3735
*/
3836
public function process($data)

‎Fetch/FetchServiceProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function boot()
1414
$excludes = Config::get('system.csrf_exclude', []);
1515
$actionUrl = $this->actionUrl('*');
1616

17-
if (!in_array($actionUrl, $excludes)) {
17+
if (! in_array($actionUrl, $excludes)) {
1818
$excludes[] = $actionUrl;
1919
Config::set('system.csrf_exclude', $excludes);
2020
}

‎Fetch/default.yaml

100644100755
File mode changed.

‎Fetch/meta.yaml

100644100755
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Fetch
2-
version: 4.3
2+
version: 4.2
33
description: Access data directly as JSON using GET/POST requests or via a simple tag.
44
url: https://statamic.com/marketplace/addons/fetch
55
developer: Aryeh Raber

‎Fetch/settings.yaml

100644100755
File mode changed.

‎LICENSE.md

100644100755
File mode changed.

‎README.md

100644100755
File mode changed.

0 commit comments

Comments
 (0)
Please sign in to comment.