Commit dc095203 authored by Denis Walker's avatar Denis Walker

Moves project into "trunk" directory

parents
2007-10-28 - Version 0.2 "Oktoberfest"
Options component now allows users to change their hackergotchi (aeternus)
Pastebin now lets you view a plaintext version of pastes (aeternus)
Simple password security checks added to hopefully prevent weak passwords (chckens)
Members page now displays this academic year's banana leaderboard (chckens)
2007-09-25 - Version 0.1 "Ferocious Freshers"
First actual version with a number, below are some recent changes:
New member options component!
- MAC registration, contact details editing (aeternus)
- Password changing (chckens)
- Groups display, hackergotchi display (dez)
Beginnings of generic error handling support (chckens)
Fixes:
Improved usability of ShortURI interface (patch from davea)
Layout tweaks to defend against long titles (dez)
Fix calculation for banana summaries on Member pages (chckens)
What's in these 'ere folders:
components/
PHP components of the site, each drives a separate element - e.g.
static content, the library, the help system, etc.
htdocs/
Where all served content is to be found:
css/
Cascading StyleSheets
files/
Files for download (e.g. Help examples)
images/
Images used by the site skin
js/
JavaScript
tinymce/
Placeholder dir for TinyMCE, which should not itself
be stored in SVN
pictures/
Images used in the content (e.g. /Help)
lib/
Custom libraries used by the site - e.g. session library
plugins/
Custom Smarty plugins used by the site - e.g. banana drawing
function
static/
Static content for the static content components (includes help)
fragments/
Any HTML fragments used to make up parts of pages (e.g.
secondary bars)
templates/
Smarty templates
templates_c/
Compiled Smarty templates - do not use this dir
All components should set the following values
$smarty->assign("title", "Page Title String");
$smarty->assign("body", "output of module");
Optionally, you can set a right hand side panel
$smarty->assign("secondary", "side boxes");
You can turn on a meta refresh with
$smarty->assign("refresh", value);
Set additional stylesheets to be applied to screen output (strongly discouraged)
$smarty->assign("extra_styles", array('/path/to/additional/stylesheet.css'))
The master script supplies the following php variables:-
$path The path of the current selected page
$pathlist Broken out version of path in array
$component The pagemap record used for the current page:
[id] Record id
[path] path of the root node for this component
[depth] path depth
[component] component name
$smarty The smarty object
$DB The ADODB database object
$session The Session object
Session has the following properties
$session->loggedin TRUE if logged in
$session->username the username
$session->fullname the users real name
$session->data array for storing persistant data
any values stored in data[] will be persistant between pages
for as long as the users session cookie stays active.
<?php
/* as far as bananas are concerned, year ends after the beach party */
$yearstart = date("Y")."-06-30";
/* Banana viewing component. Looking a little obsolete since most of this is now in the members component */
$banana_index = array_search("Bananas", $pathlist);
if ((sizeof($pathlist) > $banana_index + 1) && (trim($pathlist[$banana_index + 1]) != "")) {
$mode = "detail";
$who = $pathlist[$banana_index + 1];
} else {
$mode = "summary";
}
if (isset($who))
$smarty->assign('who', "$who");
// banana admin bits
if ($mode == "detail") {
$smarty->assign("awards",$DB->GetAll("SELECT *, date_trunc('second', whn) FROM awards WHERE username=? AND whn > ? ORDER BY whn DESC", array($who, $yearstart)));
if ($session->loggedin) {
include("../lib/banana-admin.php");
}
}
$users = $DB->GetAll("SELECT username, sum(score) AS sum FROM awards WHERE whn > ? GROUP BY username ORDER BY sum(score) DESC, username", array($yearstart));
$smarty->assign('mode', "$mode");
$smarty->assign('users', $users);
$result = $smarty->fetch('bananas.tpl');
$smarty->assign('title', "Banana Awards");
$smarty->assign('body', $result);
?>
<?php
//include our admin functions
include("../lib/blog/admin.lib.php");
$admin = new admin();
//make our command list from the path
$request=$pathlist;
array_shift($request);
array_shift($request);
array_shift($request);
$smarty->assign("title", "Blog Admin");
if ($session->loggedin) $admin->menu(); else {
header("Location: {$admin->httpPath}");
exit;
}
ob_start();
//alter the debuging state on request
if ($request[0] == "debug") {
$_SESSION[debug] = $request[1];
}
//if logged in
if($session->loggedin && blogger($session->username)) {
//call appropriate functions..
switch (array_shift($request)) {
case "newentry":
$admin->printEntryForm() ;
$smarty->assign("subselect", _("Write new entry"));
if ($admin->blog->editor) $smarty->assign("action", "edit");
break;
case "Settings":
if ($_REQUEST['submit'] == "Save Settings") {
$admin->updateSettings();
} else {
$admin->printSettingsForm() ;
}
$smarty->assign("subselect", _("Settings"));
break;
case "postentry":
$admin->postEntry() ;
break;
case "postupdate":
$admin->updateEntry(array_shift($request)) ;
break;
case "update":
$admin->updateForm(array_shift($request)) ;
$smarty->assign("subselect", _("Edit entries"));
if ($admin->blog->editor) $smarty->assign("action", "edit");
break;
case "showentries":
$admin->printEntries() ;
$smarty->assign("subselect", _("Edit entries"));
break;
case "deleteentry":
$admin->deleteEntry(array_shift($request)) ;
break;
case "confirmdeleteentries":
$admin->confirmDeleteEntries();
break;
case "deleteentries":
$admin->deleteEntries();
break;
case "moderatecomments":
$admin->printComments();
$admin->printAuthorisedUsers();
$comments=_("Comments");
$result = $BlogDB->GetOne("SELECT count(comments.id) from comments join entries on comments.post = entries.id where moderated = false and entries.user_id = ".$admin->id.";");
if($result){
$comments .= " (".$result[0].")";
}
$smarty->assign("subselect", $comments);
break;
case "updatecomments":
$admin->updateComments();
break;
case "deletecomments":
$admin->deleteComments(array_shift($request));
break;
case "updateauthusers":
$admin->updateAuthorisedUsers();
break;
default:
$admin->mainPage();
}
}
else {
//run appropriate functions
switch (array_shift($request)) {
case "signup":
$admin->addUserForm();
$smarty->assign("subselect", _("Start a Blog"));
break;
case "adduser":
$admin->addUser();
break;
//or offer login box
default:
$admin->addUserForm();
$smarty->assign("subselect", _("Start a Blog"));
break;
}
}
?>
<div id="bottompanel">
<p><? echo _("Validate"); ?> : <a href="http://validator.w3.org/check?uri=referer">XHTML</a> / <a href="http://jigsaw.w3.org/css-validator/check/referer/">CSS</a></p>
</div>
<?php
$page = ob_get_contents();
ob_end_clean();
$smarty->assign("body", $page);
$smarty->assign("extra_styles", "/css/blog.css");
//if we are in debug mode display a bunch of stuff
if($_SESSION[debug]){
echo "<div class=\"debug\"><h2>"._("Debug Info")."</h2><pre>\n";
echo "**"._("Session")."**\n";
print_r($_SESSION);
echo "**"._("Request")."**\n";
print_r($_REQUEST);
echo "**"._("Class")."**\n";
print_r($admin);
echo "</pre></div>";
}
?>
<?php
/*
* feed script - outputs an feed. Currently supports both RSS 2.0 and ATOM
*/
// We're outputting raw XML, so want to turn the templating off
$no_template = TRUE;
//include the blog lib, and thus everything else we need
include("../lib/blog/blog.lib.php");
//setup our path and from that get the feed type and usernae
$request = explode('/', substr($_SERVER['PATH_INFO'], 1));
array_shift($request);
array_shift($request);
//default to rss (so old links and existing feed readers still work, would be nice to ditch this at some point)
$feedtype = 'rss';
if ($request[0] == 'rss' or $request[0] == 'atom'){
$feedtype = array_shift($request);
}
//grab the username
$user = array('username'=> array_shift($request));
//check the user is sane
if(!safeuname($user['username'])){
error(1,"Invalid username");
}
//check the user exists
$row = $BlogDB->GetRow("SELECT username, id, name, title, description FROM users WHERE username='".$user['username']."' AND enabled=true;");
if(!$row){
error(1, "No such user");
}
else {
//fetch the users info from the db
$user = $row;
if(substr(dirname($_SERVER['SCRIPT_NAME']), -1)=="/"){
$user['link'] = "http://".$_SERVER['HTTP_HOST']."/blogs/".$user['username']."/";
$user['feed'] = "http://".$_SERVER['HTTP_HOST']."/blog/feed/".$feedtype."/".$user['username']."";
}
else {
$user['link'] = "http://".$_SERVER['HTTP_HOST']."/blogs/".$user['username']."/";
$user['feed'] = "http://".$_SERVER['HTTP_HOST']."/blog/feed/".$feedtype."/".$user['username']."";
}
}
//check to see if we are only interested in one category
switch(array_shift($request)){
case "category":
$extra = " AND category=".(int)array_shift($request);
break;
default:
$extra = "";
}
//grab the first 15 entires
$query = "SELECT subject, body, timestamp, shortsubject FROM entries WHERE user_id=".$user['id'].$extra." ORDER BY timestamp DESC LIMIT 15;";
$result = $BlogDB->GetAll($query);
//if we have relivent entrys fetch them
if (count($result) > 0) {
$row = array_shift($result);
//set the publish dates in the required format
if($feedtype=='rss') {
$pubdate = date("r",strtotime($row['timestamp']));
}
if($feedtype=='atom') {
//this should be a date type c when we are on php5, untill then, this nasty hack should work.
$pubdate = ereg_replace(' ', 'T', $row['timestamp']).":00";
}
$entries = "";
//output this entry
if ($feedtype=='rss') {
do {
$entrydate = date("r",strtotime($row['timestamp']));
$entries .= "\t\t<item>\n";
$entries .= "\t\t\t<guid>".$user['link']."entry/".$row['shortsubject']."</guid>\n";
$entries .= "\t\t\t<title>" . $row['subject'] . "</title>\n";
$entries .= "\t\t\t<description><![CDATA[" . substr(strip_tags($row['body']),0,150) . " [...]]]></description>\n";
$entries .= "\t\t\t<link>".$user['link']."entry/".$row['shortsubject']."</link>\n";
$entries .= "\t\t\t<pubDate>" . $entrydate . "</pubDate>\n";
$entries .= "\t\t\t<dc:creator>".$user['name']."</dc:creator>\n";
$entries .= "\t\t\t<content:encoded><![CDATA[" . str_replace("'", "&#8217;", $row['body']) . "]]></content:encoded>\n";
$entries .= "\t\t</item>\n";
//and ever other
} while ($row = array_shift($result));
}
if($feedtype=='atom') {
do {
$entrydate = ereg_replace(' ', 'T', $row['timestamp']).":00";
$entries .= "\t<entry>\n";
$entries .= "\t\t<title>".htmlentities($row['subject'])."</title>\n";
$entries .= "\t\t<link rel=\"alternate\" type=\"text/html\" href=\"".$user['link']."entry/".$row['shortsubject']."\"/>\n";
$entries .= "\t\t<id>".$user['link']."entry/".$row['shortsubject']."</id>\n";
$entries .= "\t\t<updated>".$entrydate."</updated>\n";
$entries .= "\t\t<content type=\"xhtml\" xml:lang=\"en\" xml:base=\"".$user['link']."entry/"."\">\n";
$entries .= "\t\t<div xmlns=\"http://www.w3.org/1999/xhtml\">\n";
//just passing though the raw body will cause the feed to fail if the code isnt valid, perhaps we should chuck everything though tidy on its way in (or even out) once we're on php5
$config = array('output-xhtml' => true, 'show-body-only' => true, 'wrap' => false);
$tidy = new tidy;
$tidy->parseString($row['body'], $config, 'utf8');
$tidy->cleanRepair();
$entries .= $tidy;
$entries .= "\t\t</div>\n";
$entries .= "\t\t</content>\n";
$entries .= "\t</entry>\n";
} while ($row = array_shift($result));
}
}
if($feedtype=='rss') {
//tell the client its xml and utf8 encoded (which it should be)
header("Content-type: application/rss+xml; charset=utf-8");
echo "<?xml version=\"1.0\" ?>\n";
?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
>
<channel>
<title><?php print $user['title']?></title>
<description><?php print $user['description']?></description>
<link><?php print $user['link']?></link>
<pubDate><?php echo $pubdate; ?></pubDate>
<generator>SUCS Blogs - http://sucs.org/blogs/</generator>
<language>en</language>
<?php
// add our entrys here
echo $entries; ?>
</channel>
</rss>
<?
}
if($feedtype=='atom') {
//tell the client its xml and utf8 encoded (which it should be)
header("Content-type: application/atom+xml; charset=utf-8");
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
?>