Skip to content

Commit f3603e9

Browse files
committed
1.2.3
* new thingiverse logo. * fix thingiverse object images.
1 parent bf68a27 commit f3603e9

7 files changed

Lines changed: 59 additions & 209 deletions

CHANGELOG

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
1.2.3 Jul, 2025
2+
* new thingiverse logo.
3+
* fix thingiverse object images.
4+
15
1.2 - Jun, 2023
26
* new token from Thingiverse
37

lib/thingiverse_stream.php

Lines changed: 48 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -36,172 +36,98 @@ function __construct( $type = "newest", $user = null ) {
3636
}
3737
}
3838

39+
private function initialize_stream_common($url, $cache_id, $is_hits = true) {
40+
41+
$cached_thing = Thingiverse::get_object_from_cache($cache_id);
42+
43+
if (false === $cached_thing) {
44+
$obj = Thingiverse::get_authorized_url_json($url);
45+
$items = $is_hits ? $obj->hits : $obj;
46+
47+
foreach ($items as $key => $lock)
48+
{
49+
$thing = new ThingiverseThing();
50+
$thing->initialize_from_json($lock);
51+
array_push($this->things, $thing);
52+
}
53+
54+
Thingiverse::log_message("Renewing KEY: " . $cache_id);
55+
set_transient($cache_id, $this->things, Thingiverse::CACHE_TTL_WIDGET);
56+
} else {
57+
$this->things = $cached_thing;
58+
}
59+
}
60+
3961
function initialize_stream_newest() {
40-
$this->url = Thingiverse::BASE_URL . "/rss/newest";
4162
$this->title = "Newest Things";
42-
$this->load_stream_from_rss_url();
63+
$this->url = Thingiverse::BASE_URL . "/api/v2/search/things?sort=newest";
64+
$cache_id = "thingiverse-press-stream-newest-global";
65+
$this->initialize_stream_common($this->url,$cache_id,true);
4366
}
4467

4568
function initialize_stream_featured() {
46-
$this->url = Thingiverse::BASE_URL . "/rss/featured";
4769
$this->title = "Featured Things";
48-
$this->load_stream_from_rss_url();
70+
$this->url = Thingiverse::BASE_URL . "/api/v2/search/things?sort=featured";
71+
$cache_id = "thingiverse-press-stream-featured-global";
72+
$this->initialize_stream_common($this->url,$cache_id,true);
4973
}
5074

5175
function initialize_stream_popular() {
52-
$this->url = Thingiverse::BASE_URL . "/rss/popular";
5376
$this->title = "Popular Things";
54-
$this->load_stream_from_rss_url();
77+
$this->url = Thingiverse::BASE_URL . "/api/v2/search/things?sort=popular&posted_after=now-30d";
78+
$cache_id = "thingiverse-press-stream-popular-global";
79+
$this->initialize_stream_common($this->url,$cache_id,true);
5580
}
5681

5782
function initialize_stream_derivatives() {
58-
$this->url = Thingiverse::BASE_URL . "/rss/derivatives";
5983
$this->title = "Newest Derivatives";
60-
$this->load_stream_from_rss_url();
84+
$this->url = Thingiverse::BASE_URL . "/api/v2/search/things?sort=derivatives";
85+
$cache_id = "thingiverse-press-stream-derivatives-global";
86+
$this->initialize_stream_common($this->url,$cache_id,true);
6187
}
6288

6389
// Newest instances has the thing creator, not the instance creator as author.
6490
// Fall back to HTML parsing.
6591
function initialize_stream_instances() {
66-
$this->url = Thingiverse::BASE_URL . "/made-things";
6792
$this->title = "Newest Instances";
68-
$this->load_stream_from_instances_url();
93+
$this->url = Thingiverse::BASE_URL . "/api/v2/search/things?sort=makes";
94+
$cache_id = "thingiverse-press-stream-instances-global";
95+
$this->initialize_stream_common($this->url,$cache_id,true);
6996
}
7097

7198
function initialize_stream_designed() {
72-
$this->user_id = Thingiverse::user_id_from_name($this->user);
73-
$this->url = Thingiverse::BASE_URL . "/rss/user:$this->user_id";
74-
$this->title = "Newest Things";
75-
$this->load_stream_from_rss_url();
99+
$this->user_url = (is_null($this->user) ? null : Thingiverse::BASE_URL . "/$this->user/designs");
100+
$this->url = Thingiverse::BASE_API_URL . "/users/$this->user/search/?type=designs&sort=newest";
101+
$cache_id = "thingiverse-press-stream-designs-$this->user";
102+
$this->initialize_stream_common($this->url,$cache_id,true);
76103
}
77104

78105
function initialize_stream_likes() {
79-
$this->user_id = Thingiverse::user_id_from_name($this->user);
80-
$this->url = Thingiverse::BASE_URL . "/rss/user:$this->user_id/likes";
81-
$this->title = "Newest Likes";
82-
$this->load_stream_from_rss_url();
106+
$this->user_url = (is_null($this->user) ? null : Thingiverse::BASE_URL . "/$this->user/likes");
107+
$this->url = Thingiverse::BASE_URL . "/api/users/$this->user/likes";
108+
$cache_id = "thingiverse-press-stream-likes-$this->user";
109+
$this->initialize_stream_common($this->url,$cache_id,false);
83110
}
84111

85112
function initialize_stream_made() {
86-
87113
$this->user_url = (is_null($this->user) ? null : Thingiverse::BASE_URL . "/$this->user/makes");
88114
$this->url = Thingiverse::BASE_API_URL . "/users/$this->user/search/?type=makes&sort=newest";
89115
$cache_id = "thingiverse-press-stream-makes-$this->user";
90-
$cached_thing = Thingiverse::get_object_from_cache($cache_id);
91-
92-
if(false === $cached_thing){
93-
$obj = Thingiverse::get_authorized_url_json($this->url);
94-
95-
foreach($obj->hits as $key => $lock)
96-
{
97-
$thing = new ThingiverseThing();
98-
$thing -> initialize_from_json($lock);
99-
array_push($this->things, $thing);
100-
}
101-
102-
Thingiverse::log_message("Renewing KEY: ".$cache_id);
103-
set_transient($cache_id, $this->things, Thingiverse::CACHE_TTL_WIDGET);
104-
} else {
105-
$this -> things = $cached_thing;
106-
}
116+
$this->initialize_stream_common($this->url,$cache_id,true);
107117
}
108118

109-
110119
function initialize_stream_collections() {
111-
112120
$this->user_url = (is_null($this->user) ? null : Thingiverse::BASE_URL . "/$this->user/collections");
113121
$this->url = Thingiverse::BASE_API_URL . "/users/$this->user/search/?type=collections&sort=newest";
114122
$cache_id = "thingiverse-press-stream-collections-$this->user";
115-
$cached_thing = Thingiverse::get_object_from_cache($cache_id);
116-
117-
if(false === $cached_thing){
118-
$obj = Thingiverse::get_authorized_url_json($this->url);
119-
120-
foreach($obj->hits as $key => $lock)
121-
{
122-
$thing = new ThingiverseThing();
123-
$thing -> initialize_from_json($lock);
124-
$thing -> url = $lock -> absolute_url;
125-
array_push($this->things, $thing);
126-
}
127-
128-
Thingiverse::log_message("Renewing KEY: ".$cache_id);
129-
set_transient($cache_id, $this->things, Thingiverse::CACHE_TTL_WIDGET);
130-
} else {
131-
$this -> things = $cached_thing;
132-
}
123+
$this->initialize_stream_common($this->url,$cache_id,true);
133124
}
134125

135-
136126
function initialize_stream_favorites() {
137127
$this->user_url = (is_null($this->user) ? null : Thingiverse::BASE_URL . "/$this->user/favorites");
138128
$this->url = Thingiverse::BASE_API_URL . "/users/$this->user/favorites";
139129
$cache_id = "thingiverse-press-stream-favorites-$this->user";
140-
$cached_thing = Thingiverse::get_object_from_cache($cache_id);
141-
142-
if(false === $cached_thing){
143-
$obj = Thingiverse::get_authorized_url_json($this->url);
144-
145-
foreach($obj as $key => $lock)
146-
{
147-
$thing = new ThingiverseThing();
148-
$thing -> initialize_from_json($lock);
149-
array_push($this->things, $thing);
150-
}
151-
152-
Thingiverse::log_message("Renewing KEY: ".$cache_id);
153-
set_transient($cache_id, $this->things, Thingiverse::CACHE_TTL_WIDGET);
154-
} else {
155-
$this -> things = $cached_thing;
156-
}
157-
}
158-
159-
// Returns a DOM object for the specified URL. Pulls it from the transient
160-
// cache if it is available, otherwise fetches it.
161-
function get_dom_for_url($url){
162-
$dom = new DomDocument("1.0");
163-
// cache key - chop off "http://www.thingiverse.com" and sluggify
164-
$t_key = "thingiverse-stream-" . sanitize_title(substr($url,27));
165-
$dom_str = Thingiverse::get_object_from_cache($t_key);
166-
if(false === $dom_str){
167-
@$dom->load($url); // use @ to suppress parser warnings
168-
$xml_data = $dom->saveXML();
169-
set_transient($t_key, $xml_data, Thingiverse::CACHE_TTL_WIDGET);
170-
} else {
171-
@$dom->loadXML($dom_str); // use @ to suppress parser warnings
172-
}
173-
return $dom;
174-
}
175-
176-
function load_stream_from_rss_url() {
177-
$dom = $this->get_dom_for_url($this->url);
178-
// FIXME: check for parse error. set some kind of thing status!
179-
$this->parse_things_from_rss_dom($dom);
180-
}
181-
182-
function load_stream_from_instances_url() {
183-
$dom = $this->get_dom_for_url($this->url);
184-
// FIXME: check for parse error. set some kind of thing status!
185-
$this->parse_thing_instances_from_html_dom($dom);
186-
}
187-
188-
function parse_things_from_rss_dom($dom) {
189-
$xp = new DomXpath($dom);
190-
$thing_nodes = $xp->query("//item");
191-
foreach ($thing_nodes as $thing_node){
192-
$thing = ThingiverseThing::from_rss_item_dom($thing_node);
193-
array_push($this->things, $thing);
194-
}
130+
$this->initialize_stream_common($this->url,$cache_id,false);
195131
}
196-
197-
function parse_thing_instances_from_html_dom($dom) {
198-
$xp = new DomXpath($dom);
199-
$thing_nodes = $xp->query("//div[@class=\"instance_float\"]");
200-
foreach ( $thing_nodes as $thing_node ) {
201-
$thing = ThingiverseThing::from_html_instance_dom($thing_node);
202-
array_push($this->things, $thing);
203-
}
204-
}
205-
206132
}
207133
?>

lib/thingiverse_thing.php

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -52,91 +52,6 @@ function initialize_from_json($obj) {
5252
@$this->url = $obj-> public_url;
5353
}
5454

55-
public static function from_rss_item_dom( $dom ) {
56-
$thing = new ThingiverseThing();
57-
$d = new DOMDocument('1.0');
58-
$b = $d->importNode($dom->cloneNode(true),true);
59-
$d->appendChild($b);
60-
$xp = new DomXpath($d);
61-
$thing->title = $xp->query("//title/text()")->item(0)->wholeText;
62-
$thing->url = $xp->query("//link/text()")->item(0)->wholeText;
63-
$thing->creator = $xp->query("//author/text()")->item(0)->wholeText;
64-
$thing->creator_url = Thingiverse::BASE_URL . "/$thing->creator";
65-
66-
// TODO: convert to some kind of timestamp object
67-
$thing->created_at = ThingiverseThing::_ago(strtotime($xp->query("//pubDate/text()")->item(0)->wholeText));
68-
69-
// parse description, image out of <description> field
70-
$desc_html = ThingiverseThing::nodeContent($xp->query("//description")->item(0), false);
71-
$desc_dom = new DOMDocument('1.0');
72-
@$desc_dom->loadHTML($desc_html);
73-
$dxp = new DomXpath($desc_dom);
74-
$img_elem = $dxp->query("//img")->item(0);
75-
$thing->main_image = ($img_elem ? $img_elem->getAttribute("src") : null);
76-
$desc_elem = $dxp->query("//div")->item(1);
77-
$thing->description = trim(
78-
$desc_elem ?
79-
ThingiverseThing::nodeContent($desc_elem, false) :
80-
null );
81-
return $thing;
82-
}
83-
84-
public static function from_html_instance_dom( $dom ) {
85-
$thing = new ThingiverseThing();
86-
$d = new DOMDocument('1.0');
87-
$b = $d->importNode($dom->cloneNode(true),true);
88-
$d->appendChild($b);
89-
$xp = new DomXpath($d);
90-
91-
$tmpelem = $xp->query("//div[@class=\"thing_name\"]/a")->item(0);
92-
$thing->title = $tmpelem->childNodes->item(0)->wholeText;
93-
94-
$tmpelem = $xp->query("//div[@class=\"thing_info\"]/a")->item(0);
95-
$thing->creator = $tmpelem->childNodes->item(0)->wholeText;
96-
$thing->creator_url = Thingiverse::BASE_URL . "/$thing->creator";
97-
98-
$tmpelem = $xp->query("//div[@class=\"thing_info\"]/span")->item(0);
99-
$thing->created_at = $tmpelem->childNodes->item(0)->wholeText;
100-
101-
$tmpelem = $xp->query("//a")->item(0);
102-
$thing->url = $tmpelem->getAttribute("href");
103-
$thing->main_image = $tmpelem->childNodes->item(0)->getAttribute(src);
104-
return $thing;
105-
}
106-
107-
public static function from_html_made_dom( $dom ) {
108-
$thing = new ThingiverseThing();
109-
$d = new DOMDocument('1.0');
110-
$b = $d->importNode($dom->cloneNode(true),true);
111-
$d->appendChild($b);
112-
$xp = new DomXpath($d);
113-
114-
$tmpelem = $xp->query("//div[@class=\"thing_info\"]/a")->item(0);
115-
$thing->title = $tmpelem->childNodes->item(0)->wholeText;
116-
$tmpelem = $xp->query("//div[@class=\"thing_info\"]/a")->item(1);
117-
$thing->creator = $tmpelem->childNodes->item(0)->wholeText;
118-
$thing->creator_url = Thingiverse::BASE_URL . "/$thing->creator";
119-
120-
// TODO: Get the time somehow :(
121-
//$thing->created_at = "Unknown";
122-
123-
$tmpelem = $xp->query("//a")->item(2);
124-
$thing->url = Thingiverse::BASE_URL . $tmpelem->getAttribute("href");
125-
$thing->main_image = $tmpelem->childNodes->item(0)->getAttribute(src);
126-
return $thing;
127-
128-
}
129-
130-
private static function nodeContent ( $n, $outer = true ) {
131-
if( $n == null ) { return null; }
132-
$d = new DOMDocument('1.0');
133-
$b = $d->importNode($n->cloneNode(true),true);
134-
$d->appendChild($b); $h = $d->saveHTML();
135-
// remove outer tags
136-
if (!$outer) $h = substr($h,strpos($h,'>')+1,-(strlen($n->nodeName)+4));
137-
return $h . "\n";
138-
}
139-
14055
// From http://php.net/manual/en/function.time.php
14156
private static function _ago($tm,$rcs = 0) {
14257
$cur_tm = time(); $dif = $cur_tm-$tm;

makerbot-thingiverse-logo.png

100644100755
-3.65 KB
Loading

style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
.tv-stream-thing img {
1818
width: 65px;
1919
border-radius: 5px;
20+
height: 65px;
21+
object-fit: cover;
2022
}
2123
.tv-stream-thing-last img {
2224
filter: blur(0.2rem) grayscale(100%);
@@ -33,6 +35,8 @@
3335
.tv-stream-thing-last span img{
3436
filter: none;
3537
width:24px;
38+
height: 24px;
39+
object-fit: cover;
3640
}
3741

3842
.thingiverse-thing-card {

thingiverse-press.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Plugin Name: Thingiverse Press
44
Plugin URI:
55
Description: Adds a [thingiverse] shortcode to embed <a href="https://www.thingiverse.com/">Thingiverse</a> Things in a post or page, and a Thingiverse Stream widget to embed streams in sidebars.
6-
Version: 1.2
6+
Version: 1.2.3
77
Author: Lacosox.org
88
Author URI: https://lacosox.org
99

thingiverse-stream-widget.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ function update($new_instance, $old_instance) {
7272
$instance['type'] = strip_tags($new_instance['type']);
7373
$instance['user'] = strip_tags($new_instance['user']);
7474
$instance['max_items'] = strip_tags($new_instance['max_items']);
75-
$instance['show_see_more_at_last'] = strip_tags($new_instance['show_see_more_at_last']);
75+
$instance['show_see_more_at_last'] = isset($new_instance['show_see_more_at_last']) ? strip_tags($new_instance['show_see_more_at_last']) : '';
76+
7677
return $instance;
7778
}
7879

0 commit comments

Comments
 (0)