root > potd > potd.php

potd.php

application/x-php, 6306 bytes (load raw)
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

$bindir = 'bin';
require_once("$bindir/potd-lib.php");

$base=".";
$debug = isset($_GET["debug"]);

#if (isset($_SERVER['ORIG_PATH_INFO'])) $_SERVER['PATH_INFO']= $_SERVER['ORIG_PATH_INFO'];
#if (isset($_SERVER['ORIG_PATH_TRANSLATED'])) $_SERVER['PATH_TRANSLATED']= $_SERVER['ORIG_PATH_TRANSLATED'];

if (isset($_SERVER['SCRIPT_URL'])) {
        $self= $_SERVER['SCRIPT_URL'];
        if ($debug) print "SCRIPT_URL: $self\n";
       
        $pi = @$_SERVER['PATH_INFO'];
        if (!is_null($pi)) {
                $pi = $_SERVER['PATH_INFO'];
                if ($debug) print "PATH_INFO: $pi (".strlen($pi).")\n";

                $self= substr($self, 0, strlen($self) - strlen($pi));
                if ($debug) print "SELF: $self\n";
        }
}
else {
        $self= $_SERVER['SCRIPT_NAME'];
        if ($debug) print "SCRIPT_NAME: $self\n";
}

$proj= @$_REQUEST['proj'];
$sz= @$_REQUEST['size'];
$type= @$_REQUEST['type'];

#if ($debug) print_r($_SERVER);

if (!$proj) {
        if (@$_SERVER['PATH_INFO']) {
                $proj= substr($_SERVER['PATH_INFO'],1);
        }
        else if (sizeof($_GET)==1) {
                $kk= array_keys($_GET);
                if (!$_GET[$kk[0]]) $proj= $kk[0];
        }
       
        if ($proj && !$sz && preg_match('!^([\w\d-.]+)[/&;,-](\d+x\d+|[-\w]+(\.[-\w]+)?)$!',$proj,$m)) {
                $proj= $m[1];
                $sz= $m[2];
        }
}

if (!$sz) $type= 'home';
else if (preg_match('/^(\d+x\d+|full)\.(.+)$/', $sz, $m)) {
        if (!$type) $type = $m[2];
        $sz= preg_replace('/\.(.+)$/', '', $sz);
}
else if (!preg_match('/^(\d+x\d+|full)$/', $sz, $m)) {
        $type = $sz;
        $sz = null;
}

if (!$type && $proj) {
        $type = 'thumb';
}

$proj= str_replace( array( '<', '>', '/', '\\', '..' ), '', $proj );
$sz=   str_replace( array( '<', '>', '/', '\\', '..' ), '', $sz );
$type=   str_replace( array( '<', '>', '/', '\\', '..' ), '', $type );
$redir = null;

if ($debug) {
        print "\n<pre>\n";
        print "BASE: $base\n";
        print "SELF: $self\n";
        print "PROJ: $proj\n";
        print "SZ: $sz\n";
        print "TYPE: $type\n";
        print "\n</pre>\n";
}

if ( $proj && ( $sz || $type ) ) {
        $info = load_info("$base/$proj");
        if (!$sz) {
                if ($type == 'credits' || $type == 'license' || $type == 'info') {
                        $sz = null;
                        $type = 'credits';
                }
                else $sz= '800x600';
        }

        if ($type=='php') $type=='php.serialized';

        $d = dirname($self);

        if ($type == 'home') $redir = home_url($info);
        else if ($type == 'file') $redir = source_url($info);
        else if ($type == 'thumb') $redir = rendered_url($info, $sz);
        else if ($type == 'credits') $redir = "$d/$proj/potd.html";
        else {
                if ($sz && file_exists("$base/$proj/potd-$sz.$type")) {
                        $redir = "$d/$proj/potd-$sz.$type";
                }
                else if (file_exists("$base/$proj/potd.$type")) {
                        $redir = "$d/$proj/potd.$type";
                }
                else {
                        header("Status: 404 Not Found", true, 404);
                        if ($debug) print "FILES: $base/$proj/potd-$sz.$type | $base/$proj/potd.$type";
                        die("not found.\n");
                }
        }

        if ($debug) {
                print "\n<pre>\n";
                print "SELFDIR: $d\n";
                print "PROJ: $proj\n";
                print "SZ: $sz\n";
                print "TYPE: $type\n";
                print "REDIR: <a href='$redir'>$redir</a>\n";
                print "\n</pre>\n";
                exit(0);
        }

        if ($redir) {
                header("Location: $redir", true, 302);
                exit(0);
        }
}

$defaultfeed = NULL;
$feeds = array();
$ff= glob("$base/potd-*.rss");
foreach ($ff as $f) {
        $n = basename($f);

        if (!preg_match('/^.*?(full|\d+x\d+)\.rss$/', $n, $m)) continue;
        $sz = $m[1];

        $feeds[$sz] = $n;
}

if ($feeds) {
        if (isset($feeds['400x300'])) $defaultfeed = $feeds['400x300'];
        else {
                $k = array_keys($feeds);
                $defaultfeed = $feeds[$k[0]];
        }
}

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
        <title>Pictures of the Day</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
       
        <style type="text/css">
                .picgrid td {
                        padding:1ex;
                        background-color:#F0F0F0;
                }
               
                .picgrid td ul {
                        margin-left: 0;
                        padding-left: 1ex;
                        list-style-type: none;
                }
        </style>
        <? if ($defaultfeed) { ?>
        <link rel="alternate" type="application/rss+xml" title="WikiPOTD feed - RSS 2.0" href="<?= escape_xml($defaultfeed) ?>" />
        <? } ?>
</head>
<body>
        <h1>Pictures of the Day</h1>

        <div class="notes">
                <? include("potd-notes.php"); ?>
        </div>
       
        <?
        if ($feeds) {
                ?>
                <p class="feeds">Condensed daily RSS feeds:
                <?
                $first = true;
                foreach ($feeds as $sz => $n) {
                        if ($first) $first = false;
                        else print ', ';
                        print '<a href="'.escape_xml($n).'" rel="alternate" type="application/rss+xml" title="WikiPOTD feed - RSS 2.0">'.escape_xml($sz).'</a>';
                }
                ?>
                </p>
                <?
        }
        ?>

        <table cellspacing="2" summary="pictures" class="picgrid">
        <?
        $dd= glob("$base/*", GLOB_ONLYDIR);
        foreach ($dd as $d) {
                if (!file_exists("$d/potd.name")) continue;
               
                $proj= basename($d);
               
                $ubase= $self;
                $ubase.= "/$proj/";
               
                $path= dirname($self);
                $path.= "/$proj/";
               
                $info = load_info($d);
                extract($info);
               
                $html = image_html($info, "200x150");
                ?>
                <tr>
                        <td width="10" style="text-align:center; vertical-align:top;">
                                <h4 style="margin:0; padding:0" id="<?= escape_xml($proj) ?>"><?= escape_xml($proj) ?></h4>
                                <?= $html ?>
                        </td>
                       
                        <td width="10" style="text-align:left; vertical-align:top; width:160px">
                                <ul>
                                <?
                                $ff= glob("$d/potd-*.snippet");
                                natsort($ff);
                               
                                foreach ($ff as $f) {
                                        $n= basename($f);
                                        if (!preg_match('!^potd-(\d+x\d+|full)\.snippet$!i',$n,$m)) continue;
                                        $n= $m[1];
                                       
                                        if ($debug) $n .= "?debug=1";
                                        ?>
                                        <li>
                                                <a href="<?= $ubase . $n ?>"><?= $n ?></a>&nbsp;<small>(<a href="<?= $path . 'potd-' . $n ?>.html">page</a>|<a href="<?= $path . 'potd-' . $n ?>.snippet">snippet</a>|<a href="<?= $path . 'potd-' . $n ?>.rss">rss</a>)</small>
                                        </li>
                                        <?
                                }
                                ?>
                                </ul>
                               
                                <ul>
                                        <li><b><a href="<?= $ubase ?>home">image home</a></b></li>
                                        <li><b><a href="<?= $ubase ?>credits">credits&nbsp;/&nbsp;license</a></b></li>
                                </ul>
                        </td>
                       
                        <td width="10" style="text-align:left; vertical-align:top;">
                                <ul>
                                <?
                                $ff= glob("$d/potd.*");
                                natsort($ff);
                               
                                foreach ($ff as $f) {
                                        $n= basename($f);
                                        ?>
                                        <li><a href="<?= $path . urlencode($n) ?>"><?= escape_xml($n) ?></a></li>
                                        <?
                                }
                                ?>
                                </ul>
                        </td>
                       
                </tr>
                <?
        }
        ?>
        </table>
</body>
</html>