aboutsummaryrefslogtreecommitdiff
path: root/bridges/ThingiverseBridge.php
blob: 077c195a3730a4c57a8df1fe8ab57b370ab7d513 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?php
class ThingiverseBridge extends BridgeAbstract {

	const NAME = 'Thingiverse Search';
	const URI = 'https://thingiverse.com';
	const DESCRIPTION = 'Returns feeds for search results';
	const MAINTAINER = 'AntoineTurmel';
	const PARAMETERS = array(
		array(
			'query' => array(
				'name' => 'Search query',
				'type' => 'text',
				'required' => true,
				'title' => 'Insert your search term here',
				'exampleValue' => 'vase'
			),
			'sortby' => array(
				'name' => 'Sort by',
				'type' => 'list',
				'required' => false,
				'values' => array(
					'Relevant' => 'relevant',
					'Text' => 'text',
					'Popular' => 'popular',
					'# of Makes' => 'makes',
					'Newest' => 'newest',
				),
				'defaultValue' => 'newest'
			),
			'category' => array(
				'name' => 'Category',
				'type' => 'list',
				'required' => false,
				'values' => array(
					'Any' => '',
					'3D Printing' => '73',
					'Art' => '63',
					'Fashion' => '64',
					'Gadgets' => '65',
					'Hobby' => '66',
					'Household' => '67',
					'Learning' => '69',
					'Models' => '70',
					'Tools' => '71',
					'Toys &amp; Games' => '72',
					'2D Art' => '144',
					'Art Tools' => '75',
					'Coins &amp; Badges' => '143',
					'Interactive Art' => '78',
					'Math Art' => '79',
					'Scans &amp; Replicas' => '145',
					'Sculptures' => '80',
					'Signs &amp; Logos' => '76',
					'Accessories' => '81',
					'Bracelets' => '82',
					'Costume' => '142',
					'Earrings' => '139',
					'Glasses' => '83',
					'Jewelry' => '84',
					'Keychains' => '130',
					'Rings' => '85',
					'Audio' => '141',
					'Camera' => '86',
					'Computer' => '87',
					'Mobile Phone' => '88',
					'Tablet' => '90',
					'Video Games' => '91',
					'Automotive' => '155',
					'DIY' => '93',
					'Electronics' => '92',
					'Music' => '94',
					'R/C Vehicles' => '95',
					'Robotics' => '96',
					'Sport &amp; Outdoors' => '140',
					'Bathroom' => '147',
					'Containers' => '146',
					'Decor' => '97',
					'Household Supplies' => '99',
					'Kitchen &amp; Dining' => '100',
					'Office' => '101',
					'Organization' => '102',
					'Outdoor &amp; Garden' => '98',
					'Pets' => '103',
					'Replacement Parts' => '153',
					'Biology' => '106',
					'Engineering' => '104',
					'Math' => '105',
					'Physics &amp; Astronomy' => '148',
					'Animals' => '107',
					'Buildings &amp; Structures' => '108',
					'Creatures' => '109',
					'Food &amp; Drink' => '110',
					'Model Furniture' => '111',
					'Model Robots' => '115',
					'People' => '112',
					'Props' => '114',
					'Vehicles' => '116',
					'Hand Tools' => '118',
					'Machine Tools' => '117',
					'Parts' => '119',
					'Tool Holders &amp; Boxes' => '120',
					'Chess' => '151',
					'Construction Toys' => '121',
					'Dice' => '122',
					'Games' => '123',
					'Mechanical Toys' => '124',
					'Playsets' => '113',
					'Puzzles' => '125',
					'Toy &amp; Game Accessories' => '149',
					'3D Printer Accessories' => '127',
					'3D Printer Extruders' => '152',
					'3D Printer Parts' => '128',
					'3D Printers' => '126',
					'3D Printing Tests' => '129',
				)
			),
			'showimage' => array(
				'name' => 'Show image in content',
				'type' => 'checkbox',
				'required' => false,
				'title' => 'Activate to show the image in the content',
				'defaultValue' => 'checked'
			)
		)
	);

	public function collectData(){
		$html = getSimpleHTMLDOM($this->getURI());

		$results = $html->find('div.thing-card');

		foreach($results as $result) {

			$item = array();

			$item['title'] = $result->find('span.ellipsis', 0);
			$item['uri'] = self::URI . $result->find('a', 1)->href;
			$item['author'] = $result->find('span.item-creator', 0);
			$item['content'] = '';

			$image = $result->find('img.card-img', 0)->src;

			if($this->getInput('showimage')) {
				$item['content'] .= '<img src="' . $image . '">';
			}

			$item['enclosures'] = array($image);

			$this->items[] = $item;
		}
	}

	public function getURI(){
		if(!is_null($this->getInput('query'))) {
			$uri = self::URI . '/search?q=' . urlencode($this->getInput('query'));
			$uri .= '&sort=' . $this->getInput('sortby');
			$uri .= '&category_id=' . $this->getInput('category');

			return $uri;
		}

		return parent::getURI();
	}
}