<?PHP
/*
 * T-Rex is Lonely: A web comic?
 * This code is not intended for general consumption, but is available if you
 * want it.
 *
 * Copyright (C) 2009 Gregor Richards
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

require_once("lib/db.php");
require_once(
"lib/src.php");
if (!isset(
$private)) $private false;

$subtitles = array("A web comic?""Celebrate schadenfreude!""Utahraptor's favorite web comic.");

// make sure an ID is provided
openDB();
$latest latestID(!$private);
if (!isset(
$_REQUEST["id"])) {
    
// support RSSPECT
    
if (strpos($_SERVER["HTTP_USER_AGENT"], "RSSPECT.com") !== false) {
        
$curid $latest;
    } else {
        
header("Location: ?id=" $latest);
        exit(
0);
    }
} else {
    
$curid intval($_REQUEST["id"]);
}

if (
$latest && $curid && $curid <= $latest) {
    
$comic comicById($curid$private);
} else {
    
$curid = -1;
    
$comic comicById(-1$private);
}

?>
<!doctype html>
<html>
<head>
<title>T-Rex is Lonely Comics</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link rel="StyleSheet" href="trilc.css" type="text/css"/>
<link rel="alternate" type="application/rss+xml" title="T-Rex is Lonely Comics" href="http://rsspect.com/rss/lonelydino.xml"/>
</head>
<body>
    <p>
        <span class="header">T-Rex is Lonely</span><br/>
        <?PHP print $subtitles[mt_rand(0count($subtitles) - 1)]; ?>
    </p>

    <div class="main">
        <img src="<?PHP print $comic["file"]; ?>"
             title="<?PHP print htmlentities($comic["alt"], ENT_COMPAT"UTF-8"); ?>"
             alt="<?PHP print htmlentities($comic["alt"], ENT_COMPAT"UTF-8"); ?>"
             style="max-width: 100%" />

        <p>
            <span class="left">
                <a href="?id=1">First</a> &mdash;
<?PHP
if ($curid 1) {
    print 
"<a href='?id=" . ($curid-1) . "'>Prev</a>";
} else {
    print 
"Prev";
}
?>
            </span>
            <span class="right">
<?PHP
if ($curid $latest) {
    print 
"<a href='?id=" . ($curid+1) . "'>Next</a>";
} else {
    print 
"Next";
}
?>
                &mdash; <a href="?">Latest</a>
            </span>

            <span class="heading"><?PHP print $comic["title"]; ?></span><br/>
            <span class="small">Posted <?PHP print $comic["postdate"]; ?> by <?PHP
print "<a href=\"archives.php?creator=" urlencode($comic["creator"]) . "\">" $comic["creator"] . "</a>";
?></span><br/>
            <span class="small">
<?PHP
if (strpos($comic["comics"], "file:") === 0) {
    print 
"<a href=\"" htmlentities(substr($comic["comics"], 5)) . "\">Source</a>";
} else {
    print 
"Sources: ";
    foreach (
explode(","$comic["comics"]) as $cnum) {
        
$cnum intval($cnum);
        if (
$cnum 10$cnum "0" $cnum; else $cnum "" $cnum;
        if (
$cnum != "00") {
            
/*print "<a href=\"http://google.com/search?btnI&amp;q=" .
              urlencode("site:www.qwantz.com \"comic2-$cnum.png\"") .
              "\">$cnum</a> ";*/
            
print "<a href=\"http://codu.org/imgs/dinosaurComic.php?comics=$cnum&amp;same\">$cnum</a>" .
                
"<a href=\"http://codu.org/imgs/dinosaurComic.php?comics=$cnum&amp;same&amp;google\">.</a> ";
        }
    }
}
?></span><br/>
            <a href="archives.php">Archives</a>
        </p>

<?PHP
// get news
// To show news for multiple days: $sql = "SELECT * FROM news WHERE postdate <= " . $comic["postdateunix"] . " ORDER BY postdate DESC LIMIT 1;";
$sql "SELECT * FROM news WHERE postdate <= " $comic["postdateunix"] .
       
" AND postdate >= " . ($comic["postdateunix"] - 24 60 60) .
       
" ORDER BY postdate DESC;";
$result $db->query($sql);
$news false;
if (
$result !== false && ($row $result->fetchArray()) !== false) {
    
$news = array("postdate" => strftime("%e %B, %Y"$row["postdate"]), "news" => stripslashes($row["news"]));
?>
        <hr/>
        <p>
            <span class="heading">Pseudo-News!</span><br/>
<?PHP
    
print "<span class=\"small\">" $news["postdate"] . "</span><br/>" $news["news"];
?>
        </p>
<?PHP
}
?>
            <!--<span class="rss-content">
            <span style="text-align: center">
            <h1>T-Rex is Lonely</h1>
            <img src="http://lonelydino.com/<?PHP print $comic["file"]; ?>"
                 title="<?PHP print htmlentities($comic["alt"], ENT_COMPAT"UTF-8"); ?>"
                 alt="<?PHP print htmlentities($comic["alt"], ENT_COMPAT"UTF-8"); ?>"
                 style="display: block; margin-left: auto; margin-right: auto"/><br/>
            <h2><?PHP print $comic["title"]; ?></h2>
            Posted <?PHP print $comic["postdate"]; ?> by <?PHP print $comic["creator"]; ?><br/>
            <hr/>
            </span>
            <?PHP if ($news !== false && $comic["postdate"] == $news["postdate"]) { ?>
            <h3 style="text-align: center">Pseudo-News!</h3>
            <p style="text-align: center">
            <?PHP print $news["postdate"]; ?><br/>
            <?PHP print $news["news"]; ?>
            </p>
            <?PHP ?>
            </span>-->

            <!--<span class="rss-title"><?PHP print $comic["postdate"] . ": " $comic["title"]; ?></span>-->
            <!--<span class="rss-link">http://lonelydino.com/?id=<?PHP print $curid?></span>-->
            <!--<span class="rss-id"><?PHP print $curid?></span>-->

<?PHP
if ($result !== false$result->finalize();

closeDB();
?>

        <hr/>

        <p>
            <span class="heading">So what the heck is this?</span><br/>
            Welcome to T-Rex is Lonely Comics! This site is a riff on two
            excellent web comics:
            <a href="http://garfieldminusgarfield.net/">Garfield Minus Garfield</a>
            and <a href="http://www.qwantz.com/">Dinosaur Comics</a>.

            When T-Rex's friends Dromi ... Dromicimimi? Dro... Dromiceiomimus
            and Utahraptor leave him, T-Rex becomes lonely, and has only his
            imagined audience (you) to keep him company.
        </p>

        <p>
            Unlike Garfield Minus Garfield, these are not created from single
            comics; the three frames in each episode are chosen carefully from
            the Dinosaur Comics archive. The intent is to tell a new story,
            with a new restraint. This may be updated every Sunday, Monday,
            Wednesday, Thursday and Friday at Midnight, UTC.
        </p>

        <p>
            Want to contribute? Talk to
            <a href="mailto:Richards@codu.org?subject=T-Rex%20is%20Lonely%20contribution">Gregor Richards</a>
            with a link to the
            <a href="http://codu.org/weird/dinosaurComicMunger.xhtml">munged comic</a>,
            a title, mouseover text, and the name you prefer to contribute
            under (can be a pseudonym). If he finds it hilarious, he may just
            queue it up! You don't have to use the comic munger linked here to
            make it, but if you don't, please include the original comic numbers
            that each frame came from; this site generates its comics
            automatically, so while an attached image is a good reference for
            laffs, it doesn't actually help Gregor to post the comic.
        </p>

        <p class="notice">
            Site, code, and anything found to be broken created by <a href="http://codu.org/">Gregor Richards</a> (<a href="mailto:Richards@codu.org">email</a>)<br/>
            Comics basically created by Ryan North, munged by <a href="contributors.php">contributors</a><br/>
            <a href="http://rsspect.com/rss/lonelydino.xml"><img src="rsssyndicate.png" width="80" height="15" style="border: 0px" title="Click to subscribe to my RSS feed! Powered by RSSPECT.com." alt="RSS"/></a>
            <a href="http://syndicated.livejournal.com/lonelydino/"><img src="lj.png" style="border: 0px" title="Click to go to my LiveJournal feed" alt="LJ"/></a>
        </p>

        <?PHP srcLink(); ?>

<?PHP
if ($private) {
?>

        <p>
            <a href="post.php">Post comics, post news, update profiles, etc</a>
        </p>
<?PHP ?>
    </div>
</body>
</html>