Ejemplo n.º 1
0
function getStoryAttributes($xpath, $story)
{
    $story_author = $xpath->query("//div[@id='profile_top']/a[1]");
    $story_title = $xpath->query("//div[@id='profile_top']/b");
    $story_desc = $xpath->query("//div[@id='profile_top']/div");
    $story_image = $xpath->query("//div[@id='profile_top']/span/img/@src");
    $story_chapters = $xpath->query("//select[@id='chap_select']/option");
    // ========== GET STORY PROPERTIES ========== //
    foreach ($story_title as $title) {
        $story["title"] = stripAccents(verify($title->nodeValue));
        //echo "title: " . $story["title"] . "\r\n";
    }
    foreach ($story_author as $author) {
        $story["author"] = verify($author->nodeValue);
        //echo "author: " . $story["author"] . "\r\n";
    }
    foreach ($story_desc as $desc) {
        $story["desc"] = verify($desc->nodeValue);
        //echo "description: " . $story["desc"] . "\r\n";
    }
    foreach ($story_image as $image) {
        $story["image"] = verify($image->nodeValue);
        //echo "image src: " . $story["image"] . "\r\n";
    }
    $story["numChapter"] = 1;
    $story["hasChapters"] = $xpath->evaluate("boolean(//select[@id='chap_select'])");
    if (!isset($story["author"]) || !isset($story["title"]) || !isset($story["desc"])) {
        throw new WrongFormatException("Data received contained invalid format.");
    }
    $story["numChapter"] = 1;
    $story["chapters"] = array();
    $story["chapters"]["title"] = array();
    $story["chapters"]["content"] = array();
    if ($story["hasChapters"]) {
        foreach ($story_chapters as $chapter) {
            $new_url = $story["story_url"] . $story["numChapter"] . "/";
            $title = verify($chapter->nodeValue);
            if (startsWith($title, $story["numChapter"] . ".")) {
                $title = str_replace($story["numChapter"] . ". ", "", $title);
                array_push($story["chapters"]["title"], $title);
                array_push($story["chapters"]["content"], getChapter($new_url, $story["debug"]));
            } else {
                break;
            }
            $story["numChapter"]++;
        }
    } else {
        array_push($story["chapters"]["title"], $story["title"]);
        array_push($story["chapters"]["content"], getChapter($story["story_url"], $story["debug"]));
    }
    return $story;
}
Ejemplo n.º 2
0
function getStoryAttributes($xpath, $story)
{
    $parsedUrl = parse_url($story["story_url"]);
    $host = explode('.', $parsedUrl['host']);
    $subdomain = $host[0];
    $cookies = "HasVisited=bypass page next time; path=/; domain={$subdomain}.adult-fanfiction.org";
    $story_author = $xpath->query("//tr[5]/td[2]");
    $story_title = $xpath->query("//html/head/title");
    $story_chapters = $xpath->query("//select[@name='chapnav']/option");
    // ========== GET STORY PROPERTIES ========== //
    foreach ($story_title as $title) {
        $story["title"] = str_replace("Story: ", '', stripAccents(trim($title->nodeValue)));
    }
    foreach ($story_author as $author) {
        $story["author"] = str_replace("Author: ", '', str_replace("\t", '', str_replace("\n", '', $author->nodeValue)));
    }
    if (!isset($story["author"]) || !isset($story["title"])) {
        throw new WrongFormatException("Data received contained invalid format. Author: {$story['author']}, Title: {$story['title']}");
    }
    $story["desc"] = "";
    $story["numChapter"] = 1;
    $story["chapters"] = array();
    $story["chapters"]["title"] = array();
    $story["chapters"]["content"] = array();
    foreach ($story_chapters as $chapter) {
        $new_url = $story["story_url"] . "&chapter=" . $story["numChapter"];
        $title = trim($chapter->nodeValue);
        if (startsWith($title, $story["numChapter"] . ".")) {
            $title = str_replace($story["numChapter"] . ". ", "", $title);
            array_push($story["chapters"]["title"], $title);
            array_push($story["chapters"]["content"], \ForceUTF8\Encoding::fixUTF8(getChapter($new_url, $story["debug"], $cookies, $story["uniqid"])));
        } else {
            break;
        }
        $story["numChapter"]++;
    }
    return $story;
}
Ejemplo n.º 3
0
 public function getMain()
 {
     $output = "";
     $output .= "<h2>Search</h2>";
     $output .= SearchPage::getSearchForm($this->options["keywords"], $this->options);
     $results = $this->search($this->options);
     $output .= "<p>There are " . sizeof($results) . " results</p>";
     $output .= "<div id='allResults'><ul class='results'>";
     $chapter = 0;
     foreach ($results as $result) {
         $currentChapter = implode(".", array_slice(explode(".", $result["book_id"]), 0, 1));
         if ($result["type"] != "item" and $chapter != $currentChapter) {
             $chapter = $currentChapter;
             $chapterInformation = getChapter($currentChapter);
             $output .= "</ul>";
             $output .= "<h3>Chapter " . $currentChapter . ": " . parseAccents($chapterInformation["title"]) . "</h3>";
             $output .= "<ul class='results'>";
         }
         $output .= $this->printResult($result, false);
         // we never show the proofs in the preview, although it would be possible
     }
     $output .= "</div>";
     return $output;
 }
Ejemplo n.º 4
0
function makePassageHTML($book, $chapterStr, $chapterStr2, array $verses)
{
    // If we don't have two chapters, then get the pretty verses
    if ($chapterStr2 == null) {
        // Make sure the verses are in order
        sort($verses);
        $prettyVerses = makePrettyVerses($verses);
    }
    // Holds what we put into the passage
    $versesHTML = array();
    // If we have two chapters
    if ($chapterStr2 != null) {
        // If we have no verses, we want to get a range of chapters
        if (count($verses) == 0) {
            // Get the verses from the DB
            list($numVerses, $chVerses) = getChapterRange($book->getID(), $chapterStr, $chapterStr2);
            // If we didn't get anything back, then this was a bad request
            // so return an empty string.
            if (count($chVerses) == 0) {
                return '';
            }
            // We need to keep track of which verse we're on. How many verses
            // there are in each chapter is returned in the $numVerses array, so
            // we need to know which index (chapter) we're on.
            $verseCounter = 1;
            // Start on the first verse
            $verseCounterIdx = 0;
            // in the first chapter
            // Loop through all the verses we got back
            foreach ($chVerses as $verseTxt) {
                // Add the verse to the array
                array_push($versesHTML, makeVerse($verseCounter, $verseTxt));
                // Up the counter
                ++$verseCounter;
                // If we've gone over how many verses there are for this chapter,
                // and we're not on the last element, then
                if ($verseCounter > $numVerses[$verseCounterIdx] && $verseTxt !== end($chVerses)) {
                    // Reset to verse 1
                    $verseCounter = 1;
                    // Set the index to the next chapter
                    ++$verseCounterIdx;
                    // And add a chapter separator
                    array_push($versesHTML, makeChapterSeparator((int) $chapterStr + $verseCounterIdx));
                }
            }
            // Then make prettyVerses be a null so there is no colon
            $prettyVerses = null;
        } else {
            // Get the verses from the database
            list($numVerses, $chVerses) = getChapterVerseRange($book->getID(), $chapterStr, $chapterStr2, $verses);
            // If we didn't get anything back, then this was a bad request
            // so return an empty string.
            if (count($chVerses) == 0) {
                return '';
            }
            // This works the same as above
            $verseCounter = 1;
            $verseCounterIdx = 0;
            foreach ($chVerses as $verseTxt) {
                array_push($versesHTML, makeVerse($verseCounter, $verseTxt));
                ++$verseCounter;
                if ($verseCounter > $numVerses[$verseCounterIdx] && $verseTxt !== end($chVerses)) {
                    $verseCounter = 1;
                    ++$verseCounterIdx;
                    array_push($versesHTML, makeChapterSeparator((int) $chapterStr + $verseCounterIdx));
                }
            }
            // We want pretty verses to be an array with the starting and
            // ending numbers, so when we make the passage, they can be put in
            $prettyVerses = array($verses[0], $verses[1]);
        }
    } else {
        if (count($verses) > 0) {
            // Get the verses from the database
            $chVerses = getVerses($book->getID(), $chapterStr, $verses);
            // If we didn't get anything back, then this was a bad request
            // so return an empty string.
            if (count($chVerses) == 0) {
                return '';
            }
            // Loop through all the verses we got back
            for ($i = 0; $i < count($chVerses); ++$i) {
                // If any of them are an empty string, then we
                // made a bad request, so return an empty string
                if ($chVerses[$i] == '') {
                    return '';
                }
                // Otherwise, add the verse to the array
                array_push($versesHTML, makeVerse($verses[$i], $chVerses[$i]));
            }
        } else {
            // Get the verses from the database
            $chVerses = getChapter($book->getID(), $chapterStr);
            // If we didn't get anything back, then this was a bad request
            // so return an empty string.
            if (count($chVerses) == 0) {
                return '';
            }
            // Otherwise, add each verse to the array
            for ($vNum = 1; $vNum <= count($chVerses); ++$vNum) {
                array_push($versesHTML, makeVerse($vNum, $chVerses[$vNum - 1]));
            }
            // And make prettyVerses be a null so there is no colon
            $prettyVerses = null;
        }
    }
    // Then make the passage from the verses we created
    return makePassage($book, $chapterStr, $chapterStr2, $prettyVerses, $versesHTML);
}
Ejemplo n.º 5
0
     $json['message'] = "Downloading has been resumed in a different window!";
 } else {
     $activeDownloads = 0;
     $activeBuilds = 0;
     foreach ($_SESSION['downloads'] as &$download) {
         if ($download['status'] == Status::PENDING) {
             $download['status'] = Status::DOWNLOADING;
             $_SESSION[$download['id']] = array();
         } else {
             if ($download['status'] == Status::DOWNLOADING) {
                 if ($activeDownloads >= 3) {
                     continue;
                 }
                 $activeDownloads++;
                 try {
                     $_SESSION[$download['id']][] = (array) getChapter($download['story']['url'], $download['currentChapter'], $download['story']['metadata']);
                     if ($download['currentChapter'] == $download['totalChapters']) {
                         $download['status'] = Status::DOWNLOAD_COMPLETE;
                     } else {
                         $download['currentChapter']++;
                     }
                 } catch (Exception $ex) {
                     $app->getLog()->error($ex);
                     $download['status'] = Status::ERROR;
                     $download['statusMessage'] = "Failed to download chapter {$download['currentChapter']}.";
                     unset($_SESSION[$download['id']]);
                 }
             } else {
                 if ($download['status'] == Status::DOWNLOAD_COMPLETE) {
                     $download['status'] = Status::BUILDING;
                 } else {
Ejemplo n.º 6
0
 private function printNavigation($displayTitle = true)
 {
     $value = "";
     $value .= "<p class='navigation'>";
     // back
     if (sectionExists(intval($this->chapter["number"]) - 1)) {
         $previousChapter = getChapter(intval($this->chapter["number"]) - 1);
         if ($displayTitle) {
             $value .= "<span class='left'><a href='" . href("chapter/" . (intval($this->chapter["number"]) - 1)) . "'>";
             $value .= "&lt;&lt; Chapter " . (intval($this->chapter["number"]) - 1) . ": " . parseAccents($previousChapter["title"]);
         } else {
             $value .= "<span class='left'><a href='" . href("chapter/" . (intval($this->chapter["number"]) - 1)) . "' title='Chapter " . $previousChapter["number"] . ": " . parseAccents($previousChapter["title"]) . "'>";
             $value .= "&lt;&lt; Previous chapter";
         }
         $value .= "</a></span>";
     }
     // forward
     if (sectionExists(intval($this->chapter["number"]) + 1)) {
         $nextChapter = getChapter(intval($this->chapter["number"]) + 1);
         if ($displayTitle) {
             $value .= "<span class='right'><a href='" . href("chapter/" . (intval($this->chapter["number"]) + 1)) . "'>";
             $value .= "Chapter " . (intval($this->chapter["number"]) + 1) . ": " . parseAccents($nextChapter["title"]) . " &gt;&gt;";
         } else {
             $value .= "<span class='right'><a href='" . href("chapter/" . (intval($this->chapter["number"]) + 1)) . "' title='Chapter " . $nextChapter["number"] . ": " . parseAccents($nextChapter["title"]) . "'>";
             $value .= "Next chapter &gt;&gt;";
         }
         $value .= "</a></span>";
     }
     $value .= "</p>";
     return $value;
 }
Ejemplo n.º 7
0
<?php

require_once 'res/functions.php';
$manga = getChapter($_GET['siteId'], $_GET['mangaId'], $_GET['chapterId']);
$info = mangaInfo($_GET['siteId'], $_GET['mangaId']);
$nextpage = $_GET['page'] + 1;
$previouspage = $_GET['page'] - 1;
$nextchapter = $_GET['chapterId'] + 1;
$previouschapter = $_GET['chapterId'] - 1;
?>
<!DOCTYPE html>
<html>
<title><?php 
echo $info['title'] . " " . $_GET['chapterId'] . " - Page " . $_GET['page'];
?>
</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="viewport" content="height=device-height, initial-scale=1">
<link rel="stylesheet" type="text/css" href="styles/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="styles/styles.css">
<link href='http://fonts.googleapis.com/css?family=Oswald:300' rel='stylesheet' type='text/css'>
<script src="scripts/jquery-2.1.4.min.js"></script>
<script src="scripts/bootstrap.min.js"></script>

<script>

	/*$(document).ready(function() {
			$.(function() {

			});
Ejemplo n.º 8
0
 private function printLocation()
 {
     $value = "";
     $value .= "<p>You're at</p>";
     $value .= "<ul>";
     // TODO idea: display a dialog box asking the user whether he really wants to open the pdf (especially book.pdf) as it will take a while?
     switch ($this->tag["type"]) {
         // items have book_id equal to their enumeration number, so look up tag etc from position
         case "item":
             $containingTag = getEnclosingTag($this->tag["position"]);
             $chapter = getChapter(getChapterFromID($containingTag["book_id"]));
             $value .= "<li>Item&nbsp;" . $this->tag["book_id"] . " of the enumeration in <a href='" . href("tag/" . $containingTag["tag"]) . "'>" . ucfirst($containingTag["type"]) . "&nbsp;" . stripChapter($containingTag["book_id"]) . "</a> on <a href='" . href("download/" . $chapter["filename"] . ".pdf#nameddest=" . $containingTag["tag"]) . "'>page&nbsp;" . $this->tag["chapter_page"] . "</a> of <a href='" . href("chapter/" . $chapter["number"]) . "'>Chapter&nbsp;" . $chapter["number"] . ": " . parseAccents($chapter["title"]) . "</a>";
             break;
         case "chapter":
             $chapter = getChapter(getChapterFromID($this->tag["book_id"]));
             $value .= "<li>Chapter&nbsp;" . $this->tag["book_id"] . " on <a href='" . href("download/book.pdf#nameddest=" . $this->tag["tag"]) . "'>page&nbsp;" . $this->tag["book_page"] . "</a> of the book";
             break;
         case "equation":
             $containingTag = getEnclosingTag($this->tag["position"]);
             $chapter = getChapter(getChapterFromID($containingTag["book_id"]));
             $value .= "<li>Equation&nbsp;" . stripChapter($this->tag["book_id"]) . " in <a href='" . href("tag/" . $containingTag["tag"]) . "'>" . ucfirst($containingTag["type"]) . "&nbsp;" . stripChapter($containingTag["book_id"]) . "</a> on <a href='" . href("download/" . $chapter["filename"] . ".pdf#nameddest=" . $this->tag["tag"]) . "'>page&nbsp;" . $this->tag["chapter_page"] . "</a> of <a href='" . href("chapter/" . $chapter["number"]) . "'>Chapter&nbsp;" . $chapter["number"] . ": " . parseAccents($chapter["title"]) . "</a>";
             $value .= "<li>Equation&nbsp;" . $this->tag["book_id"] . " on <a href='" . href("download/book.pdf#nameddest=" . $this->tag["tag"]) . "'>page&nbsp;" . $this->tag["book_page"] . "</a> of the book";
             break;
         default:
             $chapter = getChapter(getChapterFromID($this->tag["book_id"]));
             $value .= "<li>" . ucfirst($this->tag["type"]) . "&nbsp;" . stripChapter($this->tag["book_id"]) . " on <a href='" . href("download/" . $chapter["filename"] . ".pdf#nameddest=" . $this->tag["tag"]) . "'>page&nbsp;" . $this->tag["chapter_page"] . "</a> of <a href='" . href("chapter/" . $chapter["number"]) . "'>Chapter&nbsp;" . $chapter["number"] . ": " . parseAccents($chapter["title"]) . "</a>";
             $value .= "<li>" . ucfirst($this->tag["type"]) . "&nbsp;" . $this->tag["book_id"] . " on <a href='" . href("download/book.pdf#nameddest=" . $this->tag["tag"]) . "'>page&nbsp;" . $this->tag["book_page"] . "</a> of the book";
             break;
     }
     if ($this->tag["type"] != "chapter") {
         $value .= "<li><a href='https://github.com/stacks/stacks-project/blob/master/" . $chapter["filename"] . ".tex#L" . $this->tag["begin"] . "-" . $this->tag["end"] . "'>lines " . $this->tag["begin"] . "&ndash;" . $this->tag["end"] . "</a> of <a href='https://github.com/stacks/stacks-project/blob/master/" . $chapter["filename"] . ".tex'><var>" . $chapter["filename"] . ".tex</var></a>";
     } else {
         $value .= "<li>which corresponds to the file <a href='https://github.com/stacks/stacks-project/blob/master/" . $chapter["filename"] . ".tex'><var>" . $chapter["filename"] . ".tex</var></a>";
     }
     $value .= "</ul>";
     return $value;
 }