<?

require('fw.php');

function 
Links()
{
    print <<<EOF
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>PHP mini-framework demo</title>

    <link href="http://nizarium.com/css/main.css" rel="stylesheet" type="text/css">

    <meta name="description" content="Source code and demo of simple PHP mini-framework">
    <meta name="keywords" content="php,framework,miniframework,microframework,sample,demo">
    <meta name="author" content="ertaquo">

    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
</head>
<body class="plain">
    <h3>PHP mini-framework demo</h3>
    <p><a href="/source/index" rel="nofollow,noindex">index.php</a> - this file</p>
    <p><a href="/source/framework" rel="nofollow,noindex">fw.php</a> - framework source code (<a href="/download">download</a>)</p>
    <p><a href="/source/htaccess" rel="nofollow,noindex">.htaccess</a> - rewrite rules for Apache's mod_rewrite</p>
    <br><br>
    <p><a href="http://test.nizarium.com/">&laquo; Back to Nizarium test page</p>

<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-29629649-1']);
  _gaq.push(['_setDomainName', 'nizarium.com']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
</body>
</html>
EOF;
}

function 
Hello($who)
{
    if (empty(
$who)) return false;
    print 
'<html><body><h1>Hello, '.$who.'</h1></body></html>';
}

function 
UserInfo($username)
{
    print 
'Username: '.htmlspecialchars($username);
}

function 
ShowSource($file)
{
    
$files = array('index' => 'index.php''framework' => 'fw.php''htaccess' => '.htaccess');
    if (!isset(
$files[$file]))
        print 
'File not found';
    else
        
highlight_file($files[$file]);
}

function 
Download()
{
    
header('Content-Disposition: attachment; filename=fw.php');
    
header('Content-Type: application/x-php');
    print 
file_get_contents('fw.php');
}

class 
TestClass
{
    public function 
HelloFromTestClass()
    {
        print 
'Hello from TestClass';
    }

    public function 
FooBar()
    {
        print 
'foo is not bar';
    }
}

Request('/'Links);
Request('''/hello/{who}'Hello); // http://fw.nizarium.com/hello/somebody
Request('get''/users/{username}/info'UserInfo); // http://fw.nizarium.com/users/somebody/info
Request('get''/u/{userid}/info'UserInfo)->assert('userid''|^\d+$|'); // http://fw.nizarium.com/u/123/info
Request('/hello/from/test_class'TestClass); // http://fw.nizarium.com/hello/from/test_class
Request('/test/class/foo/bar'TestClass); // http://fw.nizarium.com/test/class/foo/bar

Request('''/source/{file}'ShowSource)->assert('file''|^[a-zA-Z0-9]+$|'); // http://fw.nizarium.com/source/index
Request('/download'Download); // http://fw.nizarium.com/download

require('fw.php');

?>