Source of /cheapcms.php


<?
if ($_SERVER['SCRIPT_FILENAME'] == __FILE__)
{
    
$allowviewsource = 1;
    require_once(
"common.php");
    if (!isset(
$_REQUEST['viewsource']))
        
error_page("This page cannot be viewed alone.");
}
require_once(
"common.php");
require_once(
"mysql.php");

$g_channel_name = FALSE;
function
extra_head_info()
{
    global
$g_channel_name, $pagesroot;
    if (
$g_channel_name !== FALSE)
    {
        
$a = urlencode($g_channel_name);
        print
"<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS 2.0\" href=\"${pagesroot}rss.php?channel=$a\">";
    }
}

function
cheapcms($channel)
{
    global
$g_channel_name;
    
$g_channel_name = $channel;
    
$offset = 0;
    if (isset(
$_REQUEST['offset']))
    {
        
$offset = intval($_REQUEST['offset']);
        if (
$offset 0) $offset = 0;
    }
    
$length = $offset ? 11 : 6;
    
$customlength = FALSE;
    if (isset(
$_REQUEST['length']))
    {
        
$length = intval($_REQUEST['length']);
        if (
$length 1) $length = 1;
        
$customlength = TRUE;
    }
    
$all = isset($_REQUEST['all']);
    
    
$conn = db_connect('cheapcms', 'cheapcms');
    
$channel = mysql_real_escape_string($channel, $conn);
    
$sql = "SELECT id,posted,content FROM items WHERE channel='$channel' ORDER BY posted DESC, id DESC";
    if (!
$all)
        
$sql .= " LIMIT $offset,$length";
    
$channeldata = db_query("SELECT title from channels where channel='$channel'", $conn);
    
$rows = db_query($sql, $conn);
    
db_close($conn);
    
    if (!
$channeldata || count($channeldata) < 1)
        
error_page("Bad channel $channel", 1);
    
    
page_header($channeldata[0]['title']);
    
$foundlast = TRUE;
    
$rowcount = 0;
    foreach (
$rows as $i)
    {
        if (++
$rowcount >= $length && !$all)
        {
            
$foundlast = FALSE;
            break;
        }
        
$date = db_fromdatetime($i['posted']);
        
$date = date('l, j F, Y', $date);
        print
"<div class=\"cmspost\" id=\"p{$i['id']}\">";
        print
"<div class=\"postdate\"><a href=\"#p{$i['id']}\">$date</a></div>";
        print
$i['content'];
        print
"</div>";
    }
    if (!
$all && ($offset 0 || !$foundlast))
    {
        print
"<div id=\"cmsnav\">";
        
$l = "";
        if (
$customlength)
            
$l = "&amp;length=$length";
        if (
$offset)
        {
            
$prevoffset = $offset - $length + 1;
            if (
$prevoffset 0) $prevoffset = 0;
            print
"<a class=\"prev\" href=\"{$_SERVER['PHP_SELF']}?offset=$prevoffset$l\">&larr; Previous Page</a>";
        }
        else
            print
"<span class=\"prev\">&larr; Previous Page</span>";
        if (!
$foundlast)
        {
            
$nextoffset = $offset + $length - 1;
            print
"<a class=\"next\" href=\"{$_SERVER['PHP_SELF']}?offset=$nextoffset$l\">Next Page &rarr;</a>";
        }
        else
            print
"<span class=\"next\">Next Page &rarr;</span>";
        print
"<a class=\"all\" href=\"{$_SERVER['PHP_SELF']}?all=1\">Show All</a>";
        print
"</div>";
    }
    
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/​cheapcms.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