Aquarionics

/home/a/aquarion/sites/www.aquarionics.com/epistula/chapters/archive.inc.php

All my code (That is, anything not in the "Others" list on the right) is BSD licenced.

You can also view this page as text/plain or colour-coded source


<?PHP
/*******************************************************************************
    Chapter - Archive
********************************************************************************

    Show lists of previous items by date range

    $Id: archive.inc.php,v 1.1.1.1 2004/05/16 17:39:14 aquarion Exp $

    $log$

*******************************************************************************/

$error = 0;
$day = false;
$month = false;
$year = false;

$prefix = "/archive";

$page->title = ("Archive Index");

if (in_array($wanted[1],$types)){
    $types = array($wanted[1]);
    array_shift($wanted);
    $page->title = $types[0]." Archive Index";
    $prefix .= "/".$types[0];
}

if (isset($wanted[1]) && $wanted[1] != ""){
    if ($wanted[1] == "*"){
        $year = $wanted[1];
    } elseif (!is_numeric($wanted[1]) && $wanted[1] < 1000){
        $page->content .= $page->subheading("Not A Number");
        $page->content .= $wanted[1]." is not a a valid Year (Should be a four digit number). Go away";
        $error++;
    } elseif ($wanted[1] < date("Y",$_EP['began'])){
        $page->content .= $page->subheading("Not A Valid Year");
        $page->content .= $wanted[1]." is before the site began";
        $error ++;
    } else {
        $year = $wanted[1];
    }
}


if (isset($wanted[2])){
    if (!is_numeric($wanted[2]) && $wanted[2] > 12){
        $page->content .= $page->subheading("Invalid Month");
        $page->content .= $wanted[2]." is not a a valid Month (Should be a two digit number). Go away";
        $error++;
    } else {
        $month = $wanted[2];
    }
}

if (isset($wanted[3])){

    if (stristr($wanted[3], "-")){
        $str = explode("-", $wanted[3]);
        $day = $wanted[3];
        foreach($str as $s){
            if (!is_numeric($s) && $wanted[3] > 31){
                $page->content .= $page->subheading("Invalid Day");
                $page->content .= "That's not a a valid Day (Should be a two digit number). Go away";
                $error++;
                break;
            }
        }
        

    } elseif (!is_numeric($wanted[3]) && $wanted[3] > 31){
        $page->content .= $page->subheading("Invalid Day");
        $page->content .= "That's not a a valid Day (Should be a two digit number). Go away";
        $error++;
    } else {
        $day = $wanted[3];
    }
}


if ($error){
    return;
} else {
    $list = array();
    for ($i = 2000; $i <= date("Y"); $i++) {
        $list[] = array(
            'name' => $i,
            'link' => $prefix."/".$i,            
        );
    }
    $page->localnav .= $page->menu($list);
    if ($year == "*"){

        $qex = " where (MONTH(date_created) = '$month') and ";

        if (stristr($wanted[3], "-")){
            $str = explode("-", $wanted[3]);
            $qex .= "(DAYOFMONTH(date_created) BETWEEN ".$str[0]." AND ".$str[1].")";
        } else {
            $qex .= "(DAYOFMONTH(date_created) = '$day')";
        }

        $page->title = ("Archive of all entries published on $month-$day");
        $page->date = strtotime("$month-$day");


    } elseif ($day && $month && $year){
        $qex = " where (MONTH(date_created) = '$month') and (YEAR(date_created) = '$year')";

        if (stristr($wanted[3], "-")){
            $str = explode("-", $wanted[3]);
            $qex .= " and (DAYOFMONTH(date_created) BETWEEN ".$str[0]." AND ".$str[1].")";
        } else {
            $qex .= " and (DAYOFMONTH(date_created) = '$day')";
        }

        $page->title = ("Archive of $year-$month-$day");
        $page->date = strtotime("$year-$month-$day");
    }elseif ($month && $year){
        $qex = " where (MONTH(date_created) = '$month') and (YEAR(date_created) = '$year')";
        $page->title = ("Archive of $month/$year");
        $page->date = strtotime("$year-$month-1");
        $data = array();
        foreach($types as $type){
            $q = "select id, date_format(date_created,'%m-%d') AS monthday from $type"
                ." $qex";
            $result = safequery($q);
            while ($row = mysql_fetch_array($result)){
                $data[$row['monthday']] = $row['id'];
            }
        }

        $page->pagenav .= $page->subheading("Calender");
        $page->pagenav .= calendar ($data, $month, $year, $_EP['url']."/".$prefix, "local");

        
        $next = date("U",strtotime("+1 month",date("U",strtotime("$year-$month-01"))));
        if ($next > time()){
            $next = "Next";
        } else {
            $url = $prefix."/".date("Y/m",$next);
            $page->links[] = array (
                'rel' => "next",
                'title' => "Next Month",
                'href' =>  $_EP['url'].$url
            );
            $next = $page->ulink($url, "Next");
            }

        $prev = date("U",strtotime("-1 month",date("U",strtotime("$year-$month-01"))));
        if ($prev <= $_EP['began']){
            $prev = "Previous";
        } else {
            $url = $prefix."/".date("Y/m",$prev);
            $page->links[] = array (
                'rel' => "prev",
                'title' => "Previous Month",
                'href' =>  $_EP['url'].$url
            );
            $prev = $page->ulink($url,"Previous");
        }

        $page->links[] = array (
            'rel' => "first",
            'title' => "First Month",
            'href' =>  $_EP['url'].$prefix."/".date("Y/m",$_EP['began'])
        );
        $page->links[] = array (
            'rel' => "last",
            'title' => "Latest Month",
            'href' =>  $_EP['url'].$prefix."/".date("Y/m")
        );
        $page->pagenav .= "\n<div style=\"text-align: centred\">[ ".$prev." | ".$next." ]</div>";


        $page->links[] = array (
            'rel' => "up",
            'title' => "$year Archive",
            'href' => $_EP['url'].$prefix."/".$year
        );


    
    }elseif ($year){
        $page->date = strtotime("$year-1-1");
        $page->title = ("Archive of $year");
        if (($year + 1) <= date("Y")){
            $page->links[] = array (
                'rel' => "next",
                'title' => "Archive Index",
                'href' => $_EP['url'].$prefix."/".($year +1)
            );
        }

        $page->links[] = array (
            'rel' => "last",
            'title' => "Latest Year",
            'href' =>  $_EP['url'].$prefix."/".date("Y")
        );

        $page->links[] = array (
            'rel' => "first",
            'title' => "First Year",
            'href' =>  $_EP['url'].$prefix."/".date("Y", $_EP['began'])
        );

        if (($year - 1) >= date("Y",$_EP['began'])){
            $page->links[] = array (
                'rel' => "prev",
                'title' => "Archive Index",
                'href' => $_EP['url'].$prefix."/".($year -1)
            );
        }
        $page->links[] = array (
            'rel' => "up",
            'title' => "Archive Index",
            'href' => $_EP['url']."/archive/"
        );

        $data = array();
        foreach($types as $type){
            $q = "select id, date_format(date_created,'%m-%d') AS monthday from $type"
                ." where YEAR(date_created) = '$year'";
            $result = safequery($q);
            while ($row = mysql_fetch_array($result)){
                $data[$row['monthday']] = $row['id'];
            }
        }

        if ($year == date("Y")){
            $m_max = date("m");
        } else {
            $m_max = 12;
        }

        for ($m = 1; $m <= $m_max; $m++) {
            if ($m < 10){
                $mm = "0$m";
            } else {
                $mm = $m;
            }
            #echo "calendar (".$data.", ".$mm.", ".$year.");";
            $page->content .= calendar ($data, $mm, $year, $prefix);
        }

    } else {
        $page->links[] = array (
            'rel' => "up",
            'title' => "Up to Front Page",
            'href' => $_EP['url']
        );

        $text = <<<EOTEXT
            <p>Heya pop-pickers, these are the archives, or some of them. This, to be absolutely precise, is the date-sorted archive of Everything. If you're looking for "What Aquarion Wrote Here", this is where you need to be. Click one of the years to the left to narrow your search slightly in a exciting table-based calendar way. It should be noted that this site is overloaded with journal entries. If it's a journal entry you are looking for, that's fine, but if you want a writing or an article you'll probably be better off in the article or writing section, where all the available media is sorted by category-based goodness.</p>

            <p>Also available is the <a href="/category/">entire archive sorted by category</a>. Category is either more useful or totally useless depending on your POV. Some categories, for example, are hopelessly overloaded. I imported all the pre-categorisation articles in as Personal, for example, so that page currently comes out as a half-megabyte slog (800 items - even short introductions of them - will do that to a page). If something isn't working, shout at aquarion@suespammers.org. Happy Hunting.</p>
EOTEXT;

            $page->content = $page->item($text);

        $m_max = date("m");
        $year = date("Y");

        $data = array();
        foreach($types as $type){
            $q = "select id, date_format(date_created,'%m-%d') AS monthday from $type"
                ." where YEAR(date_created) = '$year'";
            $result = safequery($q);
            while ($row = mysql_fetch_array($result)){
                $data[$row['monthday']] = $row['id'];
            }
        }

        if ($year == date("Y")){
            $m_max = date("m");
        } else {
            $m_max = 12;
        }

        for ($m = 1; $m <= $m_max; $m++) {
            if ($m < 10){
                $mm = "0$m";
            } else {
                $mm = $m;
            }
            #echo "calendar (".$data.", ".$mm.", ".$year.");";
            $page->content .= calendar ($data, $mm, $year, $prefix);
        }
    }
    
    if ($qex){
        $page->content .= buildIndex($types,"archive",500,$qex);
    }
}

$page->localnav .= $page->menu($page->itemindex);

?>


Using a heavily customised version of Tom's PHPCode2ValidXHTML Thing

Nicholas 'Aquarion' Avenell is a web developer in London, you can find out more about him or how to get in touch.

There are more Articles, Projects, Journal Entries, Photographs and things that defy description here, too.

If you're looking for something specific, there are Calendar & Category -based lists of everything.

And if you want to follow stuff that appears here, try a Syndication Feed, or the generic Feed of everything.


Aquarion's last Twitter was: [updating]
Twitter last updated


© 2000 to 2008 inclusive Nicholas Avenell
All comments are the property of their creators, published with permission
(Unless otherwise indicated, the opinions and sentiments expressed on this site are those of the author and not of any organisation of which he is an affiliate, including his employer. Caveat Lector, E&OE. sigh)
0.917 seconds, 1 queries, 2.79Mb on Sat, 11 Oct 2008 06:05:41 +0000, Not cached
Generated by Epistula Version 2.0.3