Source of /haley.php


<?
$allowviewsource
= 1;
require_once(
"common.php");
if (isset(
$_REQUEST['show']))
{
    
$brackets = array('[' => '<span class="brackets">', ']' => '</span>');
    
$show = intval($_REQUEST['show']);
    
$fp = @fopen("haleydat/$show", "r");
    if (!
$fp)
        
error_page("Strip #$show details not found");
    
$title = @myfgets($fp); if (!$title) error_page("Couldn't read strip #$show details", true);
    
$title = htmlentities($title);
    
page_header("#$show &ndash; $title &ndash; Haley Cryptograms");
    
printf("<p><a href=\"http://www.giantitp.com/comics/oots%04d.html\">Source</a></p>", $show);
    if (
$localhost)
        print
"<p><a href=\"haley.php?show=$show&amp;check=1\">Check</a></p>";
    print
"<div class=\"haley\">";
    print
"<div class=\"decode\"><div class=\"ciphertext\">ABCDEFGHIJKLMNOPQRSTUVWXYZ</div>";
    
$n = intval(myfgets($fp));
    
$list = array();
    for (
$i = 0$i $n$i++)
        
$list[] = myfgets($fp);
    if (
$n 0)
    {
        if (
strlen($list[0]) < 26)
            
$list[0] = substr($list[0] . "                          ", 0, 26);
        
$decstring = strtr($list[0] . strtolower($list[0]), array('['=>'',']'=>'',' '=>"_"));
    }
    else
        
$decstring = "????????????????????????????????????????????????????";
    foreach (
$list as $i)
        print
"<div class=\"cleartext\">" . strtr(str_replace(" ", "&nbsp;", $i), $brackets) . "</div>";
    print
"</div><div class=\"encode\">";
    
$n = intval(myfgets($fp));
    
$list = array();
    for (
$i = 0$i $n$i++)
        
$list[] = myfgets($fp);
    if (
$n 0)
    {
        if (
strlen($list[0]) < 26)
            
$list[0] = substr($list[0] . "                          ", 0, 26);
        
$encstring = strtr($list[0] . strtolower($list[0]), array('['=>'',']'=>'',' '=>"_"));
    }
    else
        
$encstring = "????????????????????????????????????????????????????";
    
$list = array_reverse($list);
    foreach (
$list as $i)
    {
        print
"<div class=\"ciphertext\">" . strtr(str_replace(" ", "&nbsp;", $i), $brackets) . "</div>";
        if (isset(
$_REQUEST['check']))
            print
"<div class=\"cleartext\">" . strtr(strtr(str_replace(' ', '_', $i), "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", $decstring), $brackets) . "</div>";
    }
    print
"<div class=\"cleartext\">ABCDEFGHIJKLMNOPQRSTUVWXYZ</div>";
    if (isset(
$_REQUEST['check']))
    {
        
$a = "";
        for (
$i = 0$i 26$i++)
        {
            
$j = strpos($decstring, chr(65 + $i));
            if (
$j === FALSE)
                
$a .= "_";
            else
                
$a .= chr(65 + $j);
        }
        print
"<div class=\"ciphertext\">$a</div>";
    }
    print
"</div>";
    print
"<div class=\"panel\">";
    
$clear = FALSE;
    while ((
$line = myfgets($fp)) !== FALSE)
    {
        if (
$line == "")
            print
"</div><div class=\"panel\">";
        else if (
$line{0} == "*")
        {
            print
"<p class=\"note\">" . substr($line, 1) . "</p>";
        }
        else
        {
            
$line = strtr($line, $brackets);
            if (!
$clear)
            {
                print
"<blockquote class=\"ciphertext\">$line</blockquote>";
                
# check with decode string for debugging purposes
                # note: I don't use this directly, to allow me to correct for typos etc in the comic
                
if (isset($_REQUEST['check']))
                    print
"<div class=\"cleartext\">" . strtr($line, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", $decstring) . "</div>";
            }
            else
            {
                print
"<div class=\"cleartext\">$line</div>";
                if (isset(
$_REQUEST['check']))
                    print
"<div class=\"ciphertext\">" . strtr($line, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", $encstring) . "</div>";
            }
            
$clear = !$clear;
        }
    }
    print
"</div></div>";
    print
"<p>";
    
$list = dirlist("haleydat");
    
$i = array_search($show, $list);
    if (
$i 0)
    {
        
$fp2 = fopen("haleydat/" . $list[$i-1], "r");
        
$title2 = myfgets($fp2);
        print
"<a href=\"haley.php?show=" . $list[$i-1] . "\">&larr; #" . $list[$i-1] . " &ndash; $title2</a> ";
    }
    if (
$i count($list) - 1)
    {
        
$fp2 = fopen("haleydat/" . $list[$i+1], "r");
        
$title2 = myfgets($fp2);
        print
"<a href=\"haley.php?show=" . $list[$i+1] . "\">#" . $list[$i+1] . " &ndash; $title2 &rarr;</a>";
    }
    print
"</p>";
    print
"<p><a href=\"haley.php\">Back</a></p>";
}
else if (isset(
$_REQUEST['summary']))
{
    
$brackets = array('[' => '<span class="brackets">', ']' => '</span>');
    
page_header("Summary &ndash; Haley Cryptograms");
    
$list = dirlist("haleydat");
    foreach (
$list as $i)
    {
        
$fp = @fopen("haleydat/$i", "r"); if (!$fp) continue;
        
$title = @myfgets($fp); if (!$title) continue;
        print
"<h2>#$i &ndash; " . htmlentities($title) . "</h2>\n";
        print
"<div class=\"haley\">";
        print
"<div class=\"decode\"><div class=\"ciphertext\">ABCDEFGHIJKLMNOPQRSTUVWXYZ</div>";
        
$n = intval(myfgets($fp));
        
$list = array();
        for (
$j = 0$j $n$j++)
            
$list[] = myfgets($fp);
        foreach (
$list as $j)
            print
"<div class=\"cleartext\">" . strtr(str_replace(" ", "&nbsp;", $j), $brackets) . "</div>";
        print
"</div><div class=\"encode\">";
        
$n = intval(myfgets($fp));
        
$list = array();
        for (
$j = 0$j $n$j++)
            
$list[] = myfgets($fp);
        
$list = array_reverse($list);
        foreach (
$list as $j)
            print
"<div class=\"ciphertext\">" . strtr(str_replace(" ", "&nbsp;", $j), $brackets) . "</div>";
        print
"<div class=\"cleartext\">ABCDEFGHIJKLMNOPQRSTUVWXYZ</div></div></div>\n";
        print
"<p><a href=\"haley.php?show=$i\">More...</a></p>\n";
        
fclose($fp);
    }
    print
"<p><a href=\"haley.php\">Back</a></p>";
}
else if (isset(
$_REQUEST['trans']))
{
    
error_page("Not yet implemented");
}
else
{
page_header("Haley Cryptograms");
?>
<p>In the webcomic <a href="http://www.giantitp.com/comics/oots.html">Order of the Stick</a>, the character Haley suffered for a long time from <a href="http://en.wikipedia.org/wiki/Aphasia">aphasia</a>, resulting in all her dialogue becoming substitution ciphers (the translation key changing from strip to strip). Below is a list of all the strips her ailment appeared in, with a translation of all her dialogue.</p>
<p>Letters in grey are guessed, not from the strip. Grey letters in the keys are guessed based on what the key looks like, grey letters in the text reflect typos in the original strip.</p>
<ul>
<li><a href="haley.php?summary=1">Summary</a></li>
<!--<li><a href="haley.php?trans=1">Automatic Translator</a></li> UNWRITTEN -->
<?
$list
= dirlist("haleydat");
foreach (
$list as $i)
{
    
$fp = @fopen("haleydat/$i", "r"); if (!$fp) continue;
    
$title = @myfgets($fp); if (!$title) continue;
    
fclose($fp);
    print
"<li><a href=\"haley.php?show=$i\">#$i &ndash; " . htmlentities($title) . "</a></li>\n";
}
?>
</ul>
<?
}
page_footer();
?>


Valid HTML 4.01 StrictValid CSSLevel Triple-A conformance icon, W3C-WAI Web Content Accessibility Guidelines 1.0
Retrieved from https://​www.mrphlip.com/​haley.php?​viewsource=yep.
Copyright © 2006–13 Phillip Bradbury. Some rights reserved.
This page is best viewed in a web browser at a screen resolution. Attempts to do otherwise may fail miserably.
Contact me