All pastes #934491 Raw Edit

Miscellany

public php v1 · immutable
·published 2008-03-08 21:59 UTC
rendered paste body
<?php  ############################################  #                                          #  #  Author: AspieTom (tom@aspietom.co.uk)   #  #                                          #  #  Name: FanFiction.net Downloader (v0.1)  #  #  Type: PHP eFiction Module               #  #  License: GPL (see LICENSE.txt)          #  #                                          #  ############################################    class ffDetails  {    // A function to get text from between anchor tags.    // Credit: morgan.galpin@gmail.com (at http://uk3.php.net/ereg)    function returnSubStrings($text, $openingMarker, $closingMarker)    {      $openingMarkerLength = strlen($openingMarker);      $closingMarkerLength = strlen($closingMarker);      $result = array();      $position = 0;          while (($position = strpos($text, $openingMarker, $position)) !== false) {        $position += $openingMarkerLength;        if (($closingMarkerPosition = strpos($text, $closingMarker, $position)) !== false) {          $result[] = substr($text, $position, $closingMarkerPosition - $position);          $position = $closingMarkerPosition + $closingMarkerLength;        }      }          return $result;    }    // A function to get the contents of the third line - where most of the details are found.    function thirdLine($content)    {      $lineArray = $this->returnSubStrings($content, "target='rating'>", "</td>");      return $lineArray[0];    }    // A function to find the total number of chapters, and list the chapters by name.    function chapters($content)    {      $subArray = $this->returnSubStrings($content, "<SELECT title='chapter navigation' Name=chapter", '/select>');      $subStr = $subArray[0];      $chapters[0] = substr_count($subStr, "<option  value");      if($chapters[0] == 1)      {        $chapters[1][1] == "Story";        return $chapters;      }      $x = 1;          while($x < $chapters[0])      {        $firstSub = ($x==1) ? "<option  value=".$x." selected>".$x.". " : "<option  value=".$x." >".$x.". ";        $subArray = $this->returnSubStrings($subStr, $firstSub, "<option  value");        $tempName = $subArray[0];        $chapters[1][$x] = $tempName;	$x++;      }      $total = $chapters[0];      $subArray = $this->returnSubStrings($subStr, "<option  value=".$x." >".$x.". ", "<");      $chapters[1][$total] = $subArray[0];            return $chapters;    }    // A function to get the title of the story.    function title($content)    {      $subArray = $this->returnSubStrings($content, "<title>FanFiction.Net - ", ", a Harry Potter fanfic</title>");      return $subArray[0];    }    // A function to get the author of their story, and their ID.    function author($content)    {      $subArray = $this->returnSubStrings($content, "<td>Author: <a href='/u/", "'>");      $subArraySplit = explode("/", $subArray[0]);      return $subArraySplit;    }    // A function to get the age rating of the story.    function rating($thirdLine)    {      $subArray = $this->returnSubStrings($thirdLine, "Fiction Rated: ", "</a>");      return $subArray[0];    }    // A function to get the category that the story is in.    function category($thirdLine)    {      $subArray = explode(" - ", $thirdLine);      return $subArray[2];    }    // A function to get the main characters.    function characters($thirdLine)    {      $subArray = explode(" - ", $thirdLine);      return $subArray[3];    }    // A function to find the date that the story was originally published.    function published($thirdLine)    {      $subArray = explode(" - ", $thirdLine);      $nextArray = explode(": ", $subArray[5]);      return $nextArray[1];    }    // A function to find the date that the story was last updated.    function updated($thirdLine)    {      $subArray = explode(" - ", $thirdLine);      $nextArray = explode(": ", $subArray[6]);      return $nextArray[1];    }    // A function to find out the current status of the story.    function status($thirdLine)    {      if(preg_match("/Complete/i", $thirdLine))      {        return 2; // complete      }      else      {        return 1; // wip      }    }    // A function to get the summary of a story.    function summary($id, $authorID)    {      $url = "http://www.fanfiction.net/u/".$authorID."/";        $ch = curl_init();      curl_setopt($ch, CURLOPT_URL, $url);      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);      curl_setopt($ch, CURLOPT_TIMEOUT, 30);      curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");      $data = curl_exec($ch);      curl_close($ch);           $subArray = $this->returnSubStrings($data, "/s/$id", "</div></div></div>");      $storySub = $subArray[0];      $subArray = $this->returnSubStrings($storySub, "<div class='x-indent x-padtop'>", "<div class='gray x-padtop2'>");      return $subArray[0];    }  }  ?>