-
Notifications
You must be signed in to change notification settings - Fork 10
/
thingiverse-embed.php
75 lines (62 loc) · 2.54 KB
/
thingiverse-embed.php
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
<?php
/*
Plugin Name: Thingiverse Embed
Plugin URI: http://creatingwithcode.com/software/thingiverse-embed-wordpress/
Description: Adds a [thingiverse] shortcode to embed <a href="http://www.thingiverse.com/">Thingiverse</a> Things in a post or page, and a Thingiverse Stream widget to embed streams in sidebars.
Version: 0.1
Author: Marty McGuire
Author URI: http://www.creatingwithcode.com/
Copyright 2010 Marty McGuire
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
require_once("lib/thingiverse.php");
require_once("lib/thingiverse_thing.php");
require_once("thingiverse-stream-widget.php");
// [thingiverse thing_id="thing-id-number"]
function thingiverse_shortcode_func($atts, $content = null) {
extract(shortcode_atts(array(
'thing' => 'none',
'thing_id' => 'none'
), $atts));
if( $thing_id == 'none' && $thing != 'none' ){ $thing_id = $thing; }
$thing_url = Thingiverse::BASE_URL . "/thing:" . trim($thing_id);
if($thing_id != 'none'){
$thing = new ThingiverseThing($thing_url);
} else {
$thing = null;
}
if($thing != null && ($thing->creator_url != "http://www.thingiverse.com/")){
ob_start();
include("templates/thing.php");
$html = ob_get_contents();
ob_end_clean();
} else {
$html = "<pre>Error - could not find Thing {$thing_id}.</pre>";
}
// TODO: think of something cool to do with inline content
if($content != null){
}
return $html;
}
function enqueue_thingiverse_styles() {
$styleUrl = WP_PLUGIN_URL . '/thingiverse-embed/style.css';
$styleFile = WP_PLUGIN_DIR . '/thingiverse-embed/style.css';
if ( file_exists($styleFile) ) {
wp_register_style('thingiverse_style', $styleUrl);
wp_enqueue_style( 'thingiverse_style');
}
}
add_shortcode('thingiverse', 'thingiverse_shortcode_func');
add_action('widgets_init', create_function('', 'return register_widget("ThingiverseStreamWidget");'));
add_action( 'wp_print_styles', 'enqueue_thingiverse_styles' );
?>