Plugin Directory

Changeset 487315


Ignore:
Timestamp:
01/10/2012 02:38:52 AM (14 years ago)
Author:
schmarty
Message:

Updates for the new Thingiverse design.

Also, bug fixes to better survive parse errors, site unavailability.

Location:
thingiverse-embed/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • thingiverse-embed/trunk/lib/thingiverse_thing.php

    r377548 r487315  
    1919  public $title = "Untitled";
    2020  public $creator = "Unknown";
    21   public $creator_url;
     21  public $creator_url = "http://www.thingiverse.com/";
    2222  public $creator_img;
    2323  public $images = array();
     
    4444
    4545    // 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    }
    5155
    5256    // Get creator image
     
    5559                         null : $creator_img_node->getAttribute("src");
    5660
    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    }
    6866
    6967    // 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));
    7169
    7270    // 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));
    7472
    7573    // 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\"]");
    7775    for($i = 0; $i < $download_nodes->length; $i++){
    7876      $dln = $download_nodes->item($i);
     
    8179      $d->appendChild($b);
    8280      $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;
    8483      list($size, $count) = explode("/", $size_count_str);
     84      // does this still work???
    8585      $err_div = ($dlxp->query("//div[@class=\"BaseError\"]")->length > 0);
    8686      $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")),
    8888              "img" => $dlxp->query("//img[@class=\"render\"]/attribute::src")->item(0)->value,
    8989              "url" => $dlxp->query("//a[starts-with(@href,\"/download\")]")->item(0)->getAttribute("href"),
     
    9494      array_push($this->downloads, $dl);
    9595    }
     96
    9697  }
    9798
  • thingiverse-embed/trunk/templates/thing.php

    r277072 r487315  
    66</div>
    77<div class="thing-description">
    8 <?php echo $thing->description ?>
     8<?php echo strip_tags($thing->description); ?>
    99</div>
    1010</div>
  • thingiverse-embed/trunk/thingiverse-embed.php

    r277438 r487315  
    3939  $thing_url = Thingiverse::BASE_URL . "/thing:" . trim($thing_id);
    4040
    41   $thing = new ThingiverseThing($thing_url);
     41  if($thing_id != 'none'){
     42    $thing = new ThingiverseThing($thing_url);
     43  } else {
     44    $thing = null;
     45  }
    4246
    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  }
    4755
    4856  // TODO: think of something cool to do with inline content
Note: See TracChangeset for help on using the changeset viewer.