Exemple #1
0
function do_page($entries)
{
    foreach ($entries as $file) {
        $m = substr($file, 0, 6);
        $d = substr($file, 7, 2);
        print do_entry($file, $m, $d);
    }
}
Exemple #2
0
function read_layout()
{
    global $layout;
    global $name;
    global $email;
    global $datelist;
    global $monthlist;
    global $m;
    global $absoluteurl;
    global $topdir;
    global $rsslink;
    $mode = 'none';
    $fd = @fopen($layout, 'r');
    if ($fd === false) {
        print "You suck!  Couldn't find {$layout}.\n";
    } else {
        fclose($fd);
    }
    // get the monthlist and datelist
    make_datelist();
    // decide if we're going to want prev/next month buttons
    $do_left = $m != $monthlist[0];
    $do_right = $m != $monthlist[count($monthlist) - 1];
    $key = array_search($m, $monthlist);
    if ($do_left) {
        $prevmonth = $monthlist[$key - 1];
        $prev = month(substr($prevmonth, 4, 2)) . ' ' . substr($prevmonth, 0, 4);
        $prevabbr = abbrmonth(substr($prevmonth, 4, 2)) . ' ' . substr($prevmonth, 0, 4);
    }
    if ($do_right) {
        $nextmonth = $monthlist[$key + 1];
        $next = month(substr($nextmonth, 4, 2)) . ' ' . substr($nextmonth, 0, 4);
        $nextabbr = abbrmonth(substr($nextmonth, 4, 2)) . ' ' . substr($nextmonth, 0, 4);
    }
    $thismonth = $m;
    $thism = month(substr($m, 4, 2)) . ' ' . substr($m, 0, 4);
    $rss = "{$absoluteurl}/{$topdir}/rss.php";
    $headerfile = @file("header.html");
    if (!$headerfile) {
        $headerfile = array();
    }
    $leftfile = @file("leftbar.html");
    if (!$leftfile) {
        $leftfile = array();
    }
    // parse the layout
    $file = file($layout);
    foreach ($file as $line) {
        // nothing special happening
        if ($mode == 'none') {
            // check for special inline constants
            $tmp = $line;
            $line = preg_replace('/(?im)<## title ##>/', $name, preg_replace('/(?im)<## email ##>/', $email, preg_replace('/(?im)<## prevmonth ##>/', $prevmonth, preg_replace('/(?im)<## nextmonth ##>/', $nextmonth, preg_replace('/(?im)<## thismonth ##>/', $thismonth, preg_replace('/(?im)<## prev ##>/', $prev, preg_replace('/(?im)<## next ##>/', $next, preg_replace('/(?im)<## prevabbr ##>/', $prevabbr, preg_replace('/(?im)<## nextabbr ##>/', $nextabbr, preg_replace('/(?im)<## this ##>/', $thism, preg_replace('/(?im)<## rsslink ##>/', $rss, preg_replace('/(?im)<## include-header ##>/', join('', $headerfile), preg_replace('/(?im)<## include-leftbar ##>/', join('', $leftfile), $tmp)))))))))))));
            // check for flow control commands
            if (substr($line, 0, 4) == '### ') {
                $tmp = trim(substr($line, 4));
                if ($tmp == 'ifemail') {
                    if ($email == '') {
                        $mode = 'silent';
                    }
                } else {
                    if ($tmp == 'ifprev') {
                        if ($do_left == false) {
                            $mode = 'silent';
                        }
                    } else {
                        if ($tmp == 'ifnext') {
                            if ($do_right == false) {
                                $mode = 'silent';
                            }
                        } else {
                            if ($tmp == 'ifprevnext') {
                                if ($do_left == false && $do_right == false) {
                                    $mode = 'silent';
                                }
                            } else {
                                if ($tmp == 'ifrss') {
                                    if ($rsslink != true) {
                                        $mode = 'silent';
                                    }
                                } else {
                                    if ($tmp == 'loopentries') {
                                        $mode = 'entryloop';
                                        unset($entryformatting);
                                    }
                                }
                            }
                        }
                    }
                }
            } else {
                if ($mode != 'silent') {
                    print $line;
                }
            }
            // in the entry loop, make a list of the formatting lines so we can
            // loop through them once we've parsed the entries
        } else {
            if ($mode == 'entryloop') {
                if (substr($line, 0, 4) == '### ') {
                    $tmp = trim(substr($line, 4));
                    if ($tmp == 'endloopentries') {
                        foreach ($datelist as $date) {
                            do_entry($m, $date, $entryformatting);
                        }
                        $mode = 'none';
                        continue;
                    }
                }
                $entryformatting[count($entryformatting)] = $line;
                // we were being quiet, because of a conditional
            } else {
                if ($mode == 'silent') {
                    if (substr($line, 0, 4) == '### ') {
                        $tmp = trim(substr($line, 4));
                        if ($tmp == 'endif') {
                            $mode = 'none';
                        }
                    }
                }
            }
        }
    }
}