Changeset 487315
- Timestamp:
- 01/10/2012 02:38:52 AM (14 years ago)
- Location:
- thingiverse-embed/trunk
- Files:
-
- 3 edited
-
lib/thingiverse_thing.php (modified) (5 diffs)
-
templates/thing.php (modified) (1 diff)
-
thingiverse-embed.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
thingiverse-embed/trunk/lib/thingiverse_thing.php
r377548 r487315 19 19 public $title = "Untitled"; 20 20 public $creator = "Unknown"; 21 public $creator_url ;21 public $creator_url = "http://www.thingiverse.com/"; 22 22 public $creator_img; 23 23 public $images = array(); … … 44 44 45 45 // Get thing $title, $creator, $creator_url 46 $title_node = $xp->query("//h1[attribute::id=\"pageTitle\"]")->item(0); 47 $this->title = str_replace(" by ", "", $title_node->childNodes->item(0)->wholeText); 48 $creator_url_node = $title_node->childNodes->item(1); 49 $this->creator_url = $creator_url_node->getAttribute("href"); 50 $this->creator = $creator_url_node->childNodes->item(0)->wholeText; 46 $title_node = $xp->query("//div[attribute::id=\"thing-meta\"]//h1")->item(0); 47 if($title_node->childNodes){ 48 $this->title = $title_node->childNodes->item(0)->wholeText; 49 } 50 $creator_url_node = $xp->query("//div[attribute::class=\"byline\"]/a")->item(0); 51 if($creator_url_node){ 52 $this->creator_url = $creator_url_node->getAttribute("href"); 53 $this->creator = $creator_url_node->childNodes->item(0)->wholeText; 54 } 51 55 52 56 // Get creator image … … 55 59 null : $creator_img_node->getAttribute("src"); 56 60 57 // Get left sidebar images of the thing 58 // Creates an array of assoc. arrays: href => "link to image", img => "image src" 59 $image_nodes = $xp->query("//a[starts-with(@href, \"/image:\")][descendant::img[attribute::class=\"render\"]]"); 60 foreach ($image_nodes as $img_node){ 61 $img = array("href" => $img_node->getAttribute("href"), 62 "img" => $img_node->childNodes->item(0)->getAttribute("src")); 63 array_push($this->images, $img); 64 } 65 if ( count($this->images) > 0 ) { 66 $this->main_image = $this->images[0]["img"]; 67 } 61 // Get thumbnail image of Thing. 62 $image_node = $xp->query("//div[attribute::id=\"thing-gallery-main\"]/a[starts-with(@href, \"/image:\")]/img[attribute::class=\"render\"]")->item(0); 63 if($image_node){ 64 $this->main_image = $image_node->getAttribute("src"); 65 } 68 66 69 67 // Get $description 70 $this->description = trim($this->nodeContent($xp->query("// h2[text()=\"Description\"]/following-sibling::p")->item(0), false));68 $this->description = trim($this->nodeContent($xp->query("//div[attribute::id=\"thing-description\"]")->item(0), false)); 71 69 72 70 // Get $instructions 73 $this->instructions = trim($this->nodeContent($xp->query("// h2[text()=\"Instructions\"]/following-sibling::p")->item(0), false));71 $this->instructions = trim($this->nodeContent($xp->query("//div[attribute::id=\"thing-instructions\"]/p")->item(0), false)); 74 72 75 73 // Get $downloads (array of assoc. arrays. name,img,url,size,count,render_error) 76 $download_nodes = $xp->query("// h2[text()=\"Downloads\"]/following-sibling::table");74 $download_nodes = $xp->query("//div[attribute::id=\"thing-files\"]/div[attribute::class=\"thing-file\"]"); 77 75 for($i = 0; $i < $download_nodes->length; $i++){ 78 76 $dln = $download_nodes->item($i); … … 81 79 $d->appendChild($b); 82 80 $dlxp = new DomXpath($d); 83 $size_count_str = $dlxp->query("//td")->item(1)->childNodes->item(2)->nodeValue; 81 82 $size_count_str = $dlxp->query("//div[attribute::class=\"thing-status\"]/div")->item(0)->nodeValue; 84 83 list($size, $count) = explode("/", $size_count_str); 84 // does this still work??? 85 85 $err_div = ($dlxp->query("//div[@class=\"BaseError\"]")->length > 0); 86 86 $dl = array( 87 "name" => trim($dlxp->query("// h3")->item(0)->nodeValue),87 "name" => trim($dlxp->query("//div[attribute::class=\"thing-status\"]/a")->item(0)->getAttribute("title")), 88 88 "img" => $dlxp->query("//img[@class=\"render\"]/attribute::src")->item(0)->value, 89 89 "url" => $dlxp->query("//a[starts-with(@href,\"/download\")]")->item(0)->getAttribute("href"), … … 94 94 array_push($this->downloads, $dl); 95 95 } 96 96 97 } 97 98 -
thingiverse-embed/trunk/templates/thing.php
r277072 r487315 6 6 </div> 7 7 <div class="thing-description"> 8 <?php echo $thing->description?>8 <?php echo strip_tags($thing->description); ?> 9 9 </div> 10 10 </div> -
thingiverse-embed/trunk/thingiverse-embed.php
r277438 r487315 39 39 $thing_url = Thingiverse::BASE_URL . "/thing:" . trim($thing_id); 40 40 41 $thing = new ThingiverseThing($thing_url); 41 if($thing_id != 'none'){ 42 $thing = new ThingiverseThing($thing_url); 43 } else { 44 $thing = null; 45 } 42 46 43 ob_start(); 44 include("templates/thing.php"); 45 $html = ob_get_contents(); 46 ob_end_clean(); 47 if($thing != null && ($thing->creator_url != "http://www.thingiverse.com/")){ 48 ob_start(); 49 include("templates/thing.php"); 50 $html = ob_get_contents(); 51 ob_end_clean(); 52 } else { 53 $html = "<pre>Error - could not find Thing {$thing_id}.</pre>"; 54 } 47 55 48 56 // TODO: think of something cool to do with inline content
Note: See TracChangeset
for help on using the changeset viewer.