Commit 44c48004 authored by Dries's avatar Dries

- here a bunch of changes to make "drupal" (for now) work with PHP 4.0.4
- tidied up some of the code and mainly working on the documentation
parent 83f6495c
...@@ -33,7 +33,7 @@ ErrorDocument 500 /error.php ...@@ -33,7 +33,7 @@ ErrorDocument 500 /error.php
php_value magic_quotes_runtime 0 php_value magic_quotes_runtime 0
php_value magic_quotes_sybase 0 php_value magic_quotes_sybase 0
php_value session.name DROPID php_value session.name DROPID
php_value session.auto_start 1 php_value session.auto_start 0
php_value session.cookie_lifetime 2000000 php_value session.cookie_lifetime 2000000
php_value session.gc_maxlifetime 2000000 php_value session.gc_maxlifetime 2000000
php_value session.cache_expire 200000 php_value session.cache_expire 200000
......
...@@ -77,7 +77,7 @@ function account_user_edit() { ...@@ -77,7 +77,7 @@ function account_user_edit() {
global $theme, $user; global $theme, $user;
if ($user->id) { if ($user->id) {
### Generate output/content: // Generate output/content:
$output .= "<FORM ACTION=\"account.php\" METHOD=\"post\">\n"; $output .= "<FORM ACTION=\"account.php\" METHOD=\"post\">\n";
$output .= "<B>Username:</B><BR>\n"; $output .= "<B>Username:</B><BR>\n";
$output .= "&nbsp; $user->userid<P>\n"; $output .= "&nbsp; $user->userid<P>\n";
...@@ -106,7 +106,7 @@ function account_user_edit() { ...@@ -106,7 +106,7 @@ function account_user_edit() {
$output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Save user information\"><BR>\n"; $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Save user information\"><BR>\n";
$output .= "</FORM>\n"; $output .= "</FORM>\n";
### Display output/content: // Display output/content:
$theme->header(); $theme->header();
$theme->box("Edit user settings", $output); $theme->box("Edit user settings", $output);
$theme->footer(); $theme->footer();
...@@ -276,7 +276,7 @@ function account_user($uname) { ...@@ -276,7 +276,7 @@ function account_user($uname) {
$output .= " <TR><TD ALIGN=\"right\" VALIGN=\"top\"><B>Signature:</B></TD><TD>". format_data($user->signature) ."</TD></TR>\n"; $output .= " <TR><TD ALIGN=\"right\" VALIGN=\"top\"><B>Signature:</B></TD><TD>". format_data($user->signature) ."</TD></TR>\n";
$output .= "</TABLE>\n"; $output .= "</TABLE>\n";
### Display account information: // Display account information:
$theme->header(); $theme->header();
$theme->box("View user settings", $output); $theme->box("View user settings", $output);
$theme->footer(); $theme->footer();
...@@ -306,7 +306,7 @@ function account_user($uname) { ...@@ -306,7 +306,7 @@ function account_user($uname) {
$diaries++; $diaries++;
} }
### Display account information: // Display account information:
$theme->header(); $theme->header();
if ($box1) $theme->box("User information for $uname", $box1); if ($box1) $theme->box("User information for $uname", $box1);
if ($box2) $theme->box("$uname has posted ". format_plural($comments, "comment", "comments") ." recently", $box2); if ($box2) $theme->box("$uname has posted ". format_plural($comments, "comment", "comments") ." recently", $box2);
...@@ -314,7 +314,7 @@ function account_user($uname) { ...@@ -314,7 +314,7 @@ function account_user($uname) {
$theme->footer(); $theme->footer();
} }
else { else {
### Display login form: // Display login form:
$theme->header(); $theme->header();
$theme->box("Create user account", account_create()); $theme->box("Create user account", account_create());
$theme->box("E-mail password", account_email()); $theme->box("E-mail password", account_email());
...@@ -323,18 +323,16 @@ function account_user($uname) { ...@@ -323,18 +323,16 @@ function account_user($uname) {
} }
function account_validate($user) { function account_validate($user) {
include "includes/ban.inc"; // Verify username and e-mail address:
### Verify username and e-mail address:
if (empty($user[real_email]) || (!eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$", $user[real_email]))) $error .= "<LI>the specified e-mail address is not valid.</LI>\n"; if (empty($user[real_email]) || (!eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$", $user[real_email]))) $error .= "<LI>the specified e-mail address is not valid.</LI>\n";
if (empty($user[userid]) || (ereg("[^a-zA-Z0-9_-]", $user[userid]))) $error .= "<LI>the specified username is not valid.</LI>\n"; if (empty($user[userid]) || (ereg("[^a-zA-Z0-9_-]", $user[userid]))) $error .= "<LI>the specified username is not valid.</LI>\n";
if (strlen($user[userid]) > 15) $error .= "<LI>the specified username is too long: it must be less than 15 characters.</LI>\n"; if (strlen($user[userid]) > 15) $error .= "<LI>the specified username is too long: it must be less than 15 characters.</LI>\n";
### Check to see whether the username or e-mail address are banned: // Check to see whether the username or e-mail address are banned:
if ($ban = ban_match($user[userid], $type2index[usernames])) $error .= "<LI>the specified username is banned for the following reason: <I>$ban->reason</I>.</LI>\n"; if ($ban = ban_match($user[userid], $type2index[usernames])) $error .= "<LI>the specified username is banned for the following reason: <I>$ban->reason</I>.</LI>\n";
if ($ban = ban_match($user[real_email], $type2index[addresses])) $error .= "<LI>the specified e-mail address is banned for the following reason: <I>$ban->reason</I>.</LI>\n"; if ($ban = ban_match($user[real_email], $type2index[addresses])) $error .= "<LI>the specified e-mail address is banned for the following reason: <I>$ban->reason</I>.</LI>\n";
### Verify whether username and e-mail address are unique: // Verify whether username and e-mail address are unique:
if (db_num_rows(db_query("SELECT userid FROM users WHERE LOWER(userid) = LOWER('$user[userid]')")) > 0) $error .= "<LI>the specified username is already taken.</LI>\n"; if (db_num_rows(db_query("SELECT userid FROM users WHERE LOWER(userid) = LOWER('$user[userid]')")) > 0) $error .= "<LI>the specified username is already taken.</LI>\n";
if (db_num_rows(db_query("SELECT real_email FROM users WHERE LOWER(real_email)=LOWER('$user[real_email]')")) > 0) $error .= "<LI>the specified e-mail address is already registered.</LI>\n"; if (db_num_rows(db_query("SELECT real_email FROM users WHERE LOWER(real_email)=LOWER('$user[real_email]')")) > 0) $error .= "<LI>the specified e-mail address is already registered.</LI>\n";
...@@ -537,7 +535,7 @@ function account_track_site() { ...@@ -537,7 +535,7 @@ function account_track_site() {
$theme->footer(); $theme->footer();
} }
### Security check: // Security check:
if (strstr($name, " ") || strstr($hash, " ")) { if (strstr($name, " ") || strstr($hash, " ")) {
watchdog("error", "account: attempt to provide malicious input through URI"); watchdog("error", "account: attempt to provide malicious input through URI");
exit(); exit();
......
<? <?
include "includes/common.inc";
// validate user permission: // validate user permission:
if (!$user->id || ($user->permissions != 1 && $user->id > 1)) exit(); if (!$user->id || ($user->permissions != 1 && $user->id > 1)) exit();
include "includes/common.inc";
function admin_page($mod) { function admin_page($mod) {
global $repository, $menu, $modules; global $repository, $menu, $modules;
......
This diff is collapsed.
...@@ -12,10 +12,10 @@ ...@@ -12,10 +12,10 @@
function ban_match($mask, $category) { function ban_match($mask, $category) {
### Perform query: // Perform query:
$result = db_query("SELECT * FROM bans WHERE type = $category AND LOWER('$mask') LIKE LOWER(mask)"); $result = db_query("SELECT * FROM bans WHERE type = $category AND LOWER('$mask') LIKE LOWER(mask)");
### Return result: // Return result:
return db_fetch_object($result); return db_fetch_object($result);
} }
...@@ -32,7 +32,7 @@ function ban_add($mask, $category, $reason, $message = "") { ...@@ -32,7 +32,7 @@ function ban_add($mask, $category, $reason, $message = "") {
$result = db_query("INSERT INTO bans (mask, type, reason, timestamp) VALUES ('$mask', '$category', '$reason', '". time() ."')"); $result = db_query("INSERT INTO bans (mask, type, reason, timestamp) VALUES ('$mask', '$category', '$reason', '". time() ."')");
$message = "added new ban with mask `$mask'.<P>\n"; $message = "added new ban with mask `$mask'.<P>\n";
### Add log entry: // Add log entry:
watchdog("message", "added new ban `$mask' to category `". $index2type[$category] ."' with reason `$reason'."); watchdog("message", "added new ban `$mask' to category `". $index2type[$category] ."' with reason `$reason'.");
} }
} }
...@@ -43,10 +43,10 @@ function ban_delete($id) { ...@@ -43,10 +43,10 @@ function ban_delete($id) {
$result = db_query("SELECT * FROM bans WHERE id = $id"); $result = db_query("SELECT * FROM bans WHERE id = $id");
if ($ban = db_fetch_object($result)) { if ($ban = db_fetch_object($result)) {
### Perform query: // Perform query:
$result = db_query("DELETE FROM bans WHERE id = $id"); $result = db_query("DELETE FROM bans WHERE id = $id");
### Deleted log entry: // Deleted log entry:
watchdog("message", "removed ban `$ban->mask' from category `". $index2type[$ban->type] ."'."); watchdog("message", "removed ban `$ban->mask' from category `". $index2type[$ban->type] ."'.");
} }
} }
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
include_once "includes/theme.inc"; include_once "includes/theme.inc";
include_once "includes/user.inc"; include_once "includes/user.inc";
global $user; session_start();
$theme = load_theme(); $theme = load_theme();
?> ?>
\ No newline at end of file
...@@ -41,7 +41,7 @@ function db_fetch_array($qid) { ...@@ -41,7 +41,7 @@ function db_fetch_array($qid) {
if ($qid) return mysql_fetch_array($qid); if ($qid) return mysql_fetch_array($qid);
} }
function db_result($qid, $field) { function db_result($qid, $field = 0) {
if ($qid) return mysql_result($qid, $field); if ($qid) return mysql_result($qid, $field);
} }
......
<? <?
function id2story($id) {
### Perform query:
$result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON s.author = u.id WHERE s.id = $id");
return db_fetch_object($result);
}
function load_theme() { function load_theme() {
global $user, $themes; global $user, $themes;
......
...@@ -14,20 +14,20 @@ function submission_vote($id, $vote, $comment) { ...@@ -14,20 +14,20 @@ function submission_vote($id, $vote, $comment) {
global $user, $submission_post_threshold, $submission_dump_threshold; global $user, $submission_post_threshold, $submission_dump_threshold;
if (!user_getHistory($user->history, "s$id")) { if (!user_getHistory($user->history, "s$id")) {
### Update submission's score- and votes-field: // Update submission's score- and votes-field:
db_query("UPDATE stories SET score = score $vote, votes = votes + 1 WHERE id = $id"); db_query("UPDATE stories SET score = score $vote, votes = votes + 1 WHERE id = $id");
### Update the comments (if required): // Update the comments (if required):
if ($comment) { if ($comment) {
watchdog("comment", "moderation: added comment with subject '$subject'"); watchdog("comment", "moderation: added comment with subject '$subject'");
db_query("INSERT INTO comments (sid, author, subject, comment, hostname, timestamp) VALUES($id, $user->id, '". check_input(substr($comment, 0, 29)) ." ...', '". check_input($comment) ."', '". getenv("REMOTE_ADDR") ."', '". time() ."')"); db_query("INSERT INTO comments (sid, author, subject, comment, hostname, timestamp) VALUES($id, $user->id, '". check_input(substr($comment, 0, 29)) ." ...', '". check_input($comment) ."', '". getenv("REMOTE_ADDR") ."', '". time() ."')");
} }
### Update user's history record: // Update user's history record:
user_setHistory($user, "s$id", $vote); // s = submission user_setHistory($user, "s$id", $vote); // s = submission
### Update story table (if required): // Update story table (if required):
$result = db_query("SELECT * FROM stories WHERE id = $id"); $result = db_query("SELECT * FROM stories WHERE id = $id");
if ($submission = db_fetch_object($result)) { if ($submission = db_fetch_object($result)) {
if ($submission->score >= $submission_post_threshold) { if ($submission->score >= $submission_post_threshold) {
......
...@@ -10,7 +10,7 @@ function submission_number() { ...@@ -10,7 +10,7 @@ function submission_number() {
return ($result) ? db_result($result, 0) : 0; return ($result) ? db_result($result, 0) : 0;
} }
### Display account settings: // Display account settings:
$content .= "<LI><A HREF=\"account.php?op=track&topic=comments\">track your comments</A></LI>\n"; $content .= "<LI><A HREF=\"account.php?op=track&topic=comments\">track your comments</A></LI>\n";
$content .= "<LI><A HREF=\"account.php?op=track&topic=stories\">track your stories</A></LI>\n"; $content .= "<LI><A HREF=\"account.php?op=track&topic=stories\">track your stories</A></LI>\n";
$content .= "<LI><A HREF=\"account.php?op=track&topic=site\">track $site_name</A></LI>\n"; $content .= "<LI><A HREF=\"account.php?op=track&topic=site\">track $site_name</A></LI>\n";
...@@ -99,7 +99,7 @@ function theme_moderation_results($theme, $story) { ...@@ -99,7 +99,7 @@ function theme_moderation_results($theme, $story) {
} }
function theme_related_links($theme, $story) { function theme_related_links($theme, $story) {
### Parse story for <A HREF="">-tags: // Parse story for <A HREF="">-tags:
$text = stripslashes("$story->abstract $story->updates $story->article"); $text = stripslashes("$story->abstract $story->updates $story->article");
while ($text = stristr($text, "<A HREF=")) { while ($text = stristr($text, "<A HREF=")) {
$link = substr($text, 0, strpos(strtolower($text), "</a>") + 4); $link = substr($text, 0, strpos(strtolower($text), "</a>") + 4);
...@@ -107,33 +107,15 @@ function theme_related_links($theme, $story) { ...@@ -107,33 +107,15 @@ function theme_related_links($theme, $story) {
if (!stristr($link, "mailto:")) $content .= "<LI>$link</LI>"; if (!stristr($link, "mailto:")) $content .= "<LI>$link</LI>";
} }
### Stories in the same category: // Stories in the same category:
$content .= " <LI>More about <A HREF=\"search.php?category=". urlencode($story->category) ."\">$story->category</A>.</LI>"; $content .= " <LI>More about <A HREF=\"search.php?category=". urlencode($story->category) ."\">$story->category</A>.</LI>";
### Stories from the same author: // Stories from the same author:
if ($story->userid) $content .= " <LI>Also by <A HREF=\"search.php?author=". urlencode($story->userid) ."\">$story->userid</A>.</LI>"; if ($story->userid) $content .= " <LI>Also by <A HREF=\"search.php?author=". urlencode($story->userid) ."\">$story->userid</A>.</LI>";
$theme->box("Related links", $content); $theme->box("Related links", $content);
} }
function theme_old_headlines($theme, $num = 10) {
global $user;
if ($user->stories) $result = db_query("SELECT id, subject, timestamp FROM stories WHERE status = 2 ORDER BY timestamp DESC LIMIT $user->stories, $num");
else $result = db_query("SELECT id, subject, timestamp FROM stories WHERE status = 2 ORDER BY timestamp DESC LIMIT $num, $num");
while ($story = db_fetch_object($result)) {
if ($time != date("F jS", $story->timestamp)) {
$content .= "<P><B>". date("l, M jS", $story->timestamp) ."</B></P>\n";
$time = date("F jS", $story->timestamp);
}
$content .= "<LI><A HREF=\"discussion.php?id=$story->id\">$story->subject</A></LI>\n";
}
$content .= "<P ALIGN=\"right\">[ <A HREF=\"search.php\"><FONT COLOR=\"$theme->hlcolor2\">more</FONT></A> ]</P>";
$theme->box("Older headlines", $content);
}
function theme_comment_moderation($id, $author, $score, $votes) { function theme_comment_moderation($id, $author, $score, $votes) {
global $user, $comment_votes; global $user, $comment_votes;
...@@ -154,9 +136,28 @@ function theme_new_headlines($theme, $num = 10) { ...@@ -154,9 +136,28 @@ function theme_new_headlines($theme, $num = 10) {
$content = ""; $content = "";
$result = db_query("SELECT id, subject FROM stories WHERE status = 2 ORDER BY id DESC LIMIT $num"); $result = db_query("SELECT id, subject FROM stories WHERE status = 2 ORDER BY id DESC LIMIT $num");
while ($story = db_fetch_object($result)) $content .= "<LI><A HREF=\"discussion.php?id=$story->id\">$story->subject</A></LI>\n"; while ($story = db_fetch_object($result)) $content .= "<LI><A HREF=\"discussion.php?id=$story->id\">". check_output($story->subject) ."</A></LI>\n";
$content .= "<P ALIGN=\"right\">[ <A HREF=\"search.php\"><FONT COLOR=\"$theme->hlcolor2\">more</FONT></A> ]</P>"; $content .= "<P ALIGN=\"right\">[ <A HREF=\"search.php\"><FONT COLOR=\"$theme->hlcolor2\">more</FONT></A> ]</P>";
$theme->box("Latest headlines", $content); $theme->box("Latest headlines", $content);
} }
function theme_old_headlines($theme, $num = 10) {
global $user;
if ($user->stories) $result = db_query("SELECT id, subject, timestamp FROM stories WHERE status = 2 ORDER BY timestamp DESC LIMIT $user->stories, $num");
else $result = db_query("SELECT id, subject, timestamp FROM stories WHERE status = 2 ORDER BY timestamp DESC LIMIT $num, $num");
while ($story = db_fetch_object($result)) {
if ($time != date("F jS", $story->timestamp)) {
$content .= "<P><B>". date("l, M jS", $story->timestamp) ."</B></P>\n";
$time = date("F jS", $story->timestamp);
}
$content .= "<LI><A HREF=\"discussion.php?id=$story->id\">". check_output($story->subject) ."</A></LI>\n";
}
$content .= "<P ALIGN=\"right\">[ <A HREF=\"search.php\"><FONT COLOR=\"$theme->hlcolor2\">more</FONT></A> ]</P>";
$theme->box("Older headlines", $content);
}
?> ?>
...@@ -42,7 +42,7 @@ function user_setHistory(&$user, $field, $value) { ...@@ -42,7 +42,7 @@ function user_setHistory(&$user, $field, $value) {
$history = $user->history; $history = $user->history;
if (!$value) { if (!$value) {
### remove entry: // remove entry:
$data = explode(";", $history); $data = explode(";", $history);
for (reset($data); current($data); next($data)) { for (reset($data); current($data); next($data)) {
$entry = explode(":", current($data)); $entry = explode(":", current($data));
...@@ -50,7 +50,7 @@ function user_setHistory(&$user, $field, $value) { ...@@ -50,7 +50,7 @@ function user_setHistory(&$user, $field, $value) {
} }
} }
else if (strstr($history, "$field:")) { else if (strstr($history, "$field:")) {
### found: update exsisting entry: // found: update exsisting entry:
$data = explode(";", $history); $data = explode(";", $history);
for (reset($data); current($data); next($data)) { for (reset($data); current($data); next($data)) {
$entry = explode(":", current($data)); $entry = explode(":", current($data));
...@@ -59,12 +59,12 @@ function user_setHistory(&$user, $field, $value) { ...@@ -59,12 +59,12 @@ function user_setHistory(&$user, $field, $value) {
} }
} }
else { else {
### not found: add new entry: // not found: add new entry:
$rval = "$history$field:$value;"; $rval = "$history$field:$value;";
} }
$user->history = $rval; $user->history = $rval;
### save new history: // save new history:
$query .= "UPDATE users SET "; $query .= "UPDATE users SET ";
foreach ($user->field as $key=>$field) { $value = $user->$field; $query .= "$field = '". addslashes($value) ."', "; } foreach ($user->field as $key=>$field) { $value = $user->$field; $query .= "$field = '". addslashes($value) ."', "; }
$query .= " id = $user->id WHERE id = $user->id"; $query .= " id = $user->id WHERE id = $user->id";
...@@ -75,4 +75,4 @@ function user_clean() { ...@@ -75,4 +75,4 @@ function user_clean() {
// todo - called by cron job // todo - called by cron job
} }
?> ?>
\ No newline at end of file
...@@ -10,7 +10,7 @@ function submission_number() { ...@@ -10,7 +10,7 @@ function submission_number() {
return ($result) ? db_result($result, 0) : 0; return ($result) ? db_result($result, 0) : 0;
} }
### Display account settings: // Display account settings:
$content .= "<LI><A HREF=\"account.php?op=track&topic=comments\">track your comments</A></LI>\n"; $content .= "<LI><A HREF=\"account.php?op=track&topic=comments\">track your comments</A></LI>\n";
$content .= "<LI><A HREF=\"account.php?op=track&topic=stories\">track your stories</A></LI>\n"; $content .= "<LI><A HREF=\"account.php?op=track&topic=stories\">track your stories</A></LI>\n";
$content .= "<LI><A HREF=\"account.php?op=track&topic=site\">track $site_name</A></LI>\n"; $content .= "<LI><A HREF=\"account.php?op=track&topic=site\">track $site_name</A></LI>\n";
...@@ -91,7 +91,7 @@ function display_moderation_results($theme, $story) { ...@@ -91,7 +91,7 @@ function display_moderation_results($theme, $story) {
} }
function display_related_links($theme, $story) { function display_related_links($theme, $story) {
### Parse story for <A HREF="">-tags: // Parse story for <A HREF="">-tags:
$text = stripslashes("$story->abstract $story->updates $story->article"); $text = stripslashes("$story->abstract $story->updates $story->article");
while ($text = stristr($text, "<A HREF=")) { while ($text = stristr($text, "<A HREF=")) {
$link = substr($text, 0, strpos(strtolower($text), "</a>") + 4); $link = substr($text, 0, strpos(strtolower($text), "</a>") + 4);
...@@ -99,10 +99,10 @@ function display_related_links($theme, $story) { ...@@ -99,10 +99,10 @@ function display_related_links($theme, $story) {
if (!stristr($link, "mailto:")) $content .= "<LI>$link</LI>"; if (!stristr($link, "mailto:")) $content .= "<LI>$link</LI>";
} }
### Stories in the same category: // Stories in the same category:
$content .= " <LI>More about <A HREF=\"search.php?category=". urlencode($story->category) ."\">$story->category</A>.</LI>"; $content .= " <LI>More about <A HREF=\"search.php?category=". urlencode($story->category) ."\">$story->category</A>.</LI>";
### Stories from the same author: // Stories from the same author:
if ($story->userid) $content .= " <LI>Also by <A HREF=\"search.php?author=". urlencode($story->userid) ."\">$story->userid</A>.</LI>"; if ($story->userid) $content .= " <LI>Also by <A HREF=\"search.php?author=". urlencode($story->userid) ."\">$story->userid</A>.</LI>";
$theme->box("Related links", $content); $theme->box("Related links", $content);
......
...@@ -2,20 +2,20 @@ ...@@ -2,20 +2,20 @@
include "includes/common.inc"; include "includes/common.inc";
### Security check: // Security check:
if (strstr($number, " ") || strstr($date, " ")) { if (strstr($number, " ") || strstr($date, " ")) {
watchdog("error", "main page: attempt to provide malicious input through URI"); watchdog("error", "main page: attempt to provide malicious input through URI");
exit(); exit();
} }
### Initialize/pre-process variables: // Initialize/pre-process variables:
$number = ($user->stories) ? $user->stories : 10; $number = ($user->stories) ? $user->stories : 10;
$date = ($date) ? $date : time(); $date = ($date) ? $date : time();
### Perform query: // Perform query:
$result = db_query("SELECT stories.*, users.userid, COUNT(comments.sid) AS comments FROM stories LEFT JOIN comments ON stories.id = comments.sid LEFT JOIN users ON stories.author = users.id WHERE stories.status = 2 AND stories.timestamp <= $date GROUP BY stories.id ORDER BY stories.timestamp DESC LIMIT $number"); $result = db_query("SELECT stories.*, users.userid, COUNT(comments.sid) AS comments FROM stories LEFT JOIN comments ON stories.id = comments.sid LEFT JOIN users ON stories.author = users.id WHERE stories.status = 2 AND stories.timestamp <= $date GROUP BY stories.id ORDER BY stories.timestamp DESC LIMIT $number");
### Display stories: // Display stories:
$theme->header(); $theme->header();
while ($story = db_fetch_object($result)) $theme->abstract($story); while ($story = db_fetch_object($result)) $theme->abstract($story);
$theme->footer(); $theme->footer();
......
<? <?
$module = array("block" => "ab_block", $module = array("help" => "ab_help",
"block" => "ab_block",
"admin" => "ab_admin"); "admin" => "ab_admin");
function ab_help() {
?>
<P>The content of the site can be almost entirely altered by means of blocks. Simply put, <I>admin blocks</I> are small bit of PHP code which will get plugged into the site. Admin blocks are typically used to add custom blocks to the site.</P>
<P>If you know how to script in PHP, admin blocks are pretty simple to create. Don't get your panties in a knot if you are not confident with PHP: simply use the standard admin blocks (i.e. those available by default) as they are just fine or ask an expert 'admin blocker' to help you creating custom admin blocks that fit your need.</P>
<P>Each admin block consists of a key of maximum 255 characters and an associated block of PHP code which can be as long as you want it to be. You can use any piece of PHP code to make up an admin block. A admin block's code is stored in the database and the engine or a particular module will use the key to find the associated piece of PHP code which will then be dynamically embedded in the engine or the module just-in-time for execution.</P>
<P>There are however some factors to keep in mind when using and creating admin blocks: admin blocks can be extremly useful and flexible, yet be dangerous and insecure if not properly used. If you are not confident with PHP, SQL or even with the site engine for that matter, avoid experimenting with admin blocks because you can - and you probably will - corrupt your database or even break your site! If you don't plan to do fancy stuff with admin blocks then you are probably save.</P>
<P>Remember that the code within each admin block must be valid PHP code, including things like terminating statements with a semicolon so the parser won't die. Therefore, it is highly recommended to test your admin blocks seperatly using a simple test script on top of a test database before migrating to your production environment running your real database.</P>
<P>Note that you can use any global variables, such as configuration parameters within the scope of an admin block and keep in mind that variables that have been given values in an admin block will retain these values in the engine or module afterwards.</P>
<P>You may as well use the <CODE>return</CODE> statement to return the actual content of the block.</P>
<P><U>A basic example:</U></P>
<P>Given the admin block with subject "Welcome", used to create a Welcome-block. The content for this admin block could be created by using:</P>
<PRE>
return "Welcome visitor, ... welcome message goes here ...";
</PRE>
<P>If we are however dealing with a registered user, we can customize the message by using:
<PRE>
if ($user) {
return "Welcome $user->userid, ... weclome message goes here ...";
}
else {
return "Welcome visitor, ... welcome message goes here ...";
}
</PRE>
<P>For more in depth example, we recommand you to check any of the available admin blocks and to go from there.</P>
<P>As said above, you can virtually use any piece of PHP code in an admin block: you can declare and use functions, consult the SQL database, access configuration settings and so on.</P>
<?
}
function ab_block() { function ab_block() {
$result = db_query("SELECT * FROM admin_blocks"); $result = db_query("SELECT * FROM admin_blocks");
$i = 0; $i = 0;
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
$module = array("admin" => "cron_admin"); $module = array("admin" => "cron_admin");
include_once "includes/function.inc";
function cron_save($edit) { function cron_save($edit) {
foreach ($edit as $key=>$value) { foreach ($edit as $key=>$value) {
db_query("UPDATE crons SET scheduled = '$value' WHERE module = '$key'"); db_query("UPDATE crons SET scheduled = '$value' WHERE module = '$key'");
......
This diff is collapsed.
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
$module = array("page" => "headline_page", $module = array("page" => "headline_page",
"cron" => "headline_cron", "cron" => "headline_cron",
"help" => "headline_help",
"block" => "headline_block", "block" => "headline_block",
"admin" => "headline_admin", "admin" => "headline_admin",
"export" => "headline_export"); "export" => "headline_export");
...@@ -65,6 +66,12 @@ function headline_cron() { ...@@ -65,6 +66,12 @@ function headline_cron() {
} }
} }
function headline_help() {
?>
The headline module both imports and exports RDF/RSS headlines.
<?
}
function headline_block() { function headline_block() {
$result = db_query("SELECT * FROM channel"); $result = db_query("SELECT * FROM channel");
while ($channel = db_fetch_object($result)) { while ($channel = db_fetch_object($result)) {
......
...@@ -90,14 +90,14 @@ function story_save($id, $subject, $abstract, $updates, $article, $category, $st ...@@ -90,14 +90,14 @@ function story_save($id, $subject, $abstract, $updates, $article, $category, $st
} }
function story_display($order = "date") { function story_display($order = "date") {
### Initialize variables: // Initialize variables:
$status = array("deleted", "pending", "public"); $status = array("deleted", "pending", "public");
$fields = array("author" => "author", "category" => "category", "date" => "timestamp DESC", "status" => "status DESC"); $fields = array("author" => "author", "category" => "category", "date" => "timestamp DESC", "status" => "status DESC");
### Perform SQL query: // Perform SQL query:
$result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON u.id = s.author ORDER BY s.$fields[$order]"); $result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON u.id = s.author ORDER BY s.$fields[$order]");
### Display stories: // Display stories:
$output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n"; $output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
$output .= " <TR>\n"; $output .= " <TR>\n";
$output .= " <TH ALIGN=\"right\" COLSPAN=\"5\">\n"; $output .= " <TH ALIGN=\"right\" COLSPAN=\"5\">\n";
......
...@@ -90,14 +90,14 @@ function story_save($id, $subject, $abstract, $updates, $article, $category, $st ...@@ -90,14 +90,14 @@ function story_save($id, $subject, $abstract, $updates, $article, $category, $st
} }
function story_display($order = "date") { function story_display($order = "date") {
### Initialize variables: // Initialize variables:
$status = array("deleted", "pending", "public"); $status = array("deleted", "pending", "public");
$fields = array("author" => "author", "category" => "category", "date" => "timestamp DESC", "status" => "status DESC"); $fields = array("author" => "author", "category" => "category", "date" => "timestamp DESC", "status" => "status DESC");
### Perform SQL query: // Perform SQL query:
$result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON u.id = s.author ORDER BY s.$fields[$order]"); $result = db_query("SELECT s.*, u.userid FROM stories s LEFT JOIN users u ON u.id = s.author ORDER BY s.$fields[$order]");
### Display stories: // Display stories:
$output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n"; $output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
$output .= " <TR>\n"; $output .= " <TR>\n";
$output .= " <TH ALIGN=\"right\" COLSPAN=\"5\">\n"; $output .= " <TH ALIGN=\"right\" COLSPAN=\"5\">\n";
......
...@@ -11,10 +11,10 @@ function watchdog_display($order = "date") { ...@@ -11,10 +11,10 @@ function watchdog_display($order = "date") {
$colors = array("#D8BFD8", "#6495ED", "#6A5ADF", "#FFFFFF", "#FFA500", "#FF3C3C"); $colors = array("#D8BFD8", "#6495ED", "#6A5ADF", "#FFFFFF", "#FFA500", "#FF3C3C");
$fields = array("date" => "id DESC", "username" => "user", "location" => "location", "message" => "message DESC", "level" => "level DESC"); $fields = array("date" => "id DESC", "username" => "user", "location" => "location", "message" => "message DESC", "level" => "level DESC");
### Perform query: // Perform query:
$result = db_query("SELECT l.*, u.userid FROM watchdog l LEFT JOIN users u ON l.user = u.id ORDER BY l.$fields[$order]"); $result = db_query("SELECT l.*, u.userid FROM watchdog l LEFT JOIN users u ON l.user = u.id ORDER BY l.$fields[$order]");
### Generate output: // Generate output:
$output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n"; $output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
$output .= " <TR>\n"; $output .= " <TR>\n";
$output .= " <TH ALIGN=\"right\" COLSPAN=\"4\">\n"; $output .= " <TH ALIGN=\"right\" COLSPAN=\"4\">\n";
......
...@@ -11,10 +11,10 @@ function watchdog_display($order = "date") { ...@@ -11,10 +11,10 @@ function watchdog_display($order = "date") {
$colors = array("#D8BFD8", "#6495ED", "#6A5ADF", "#FFFFFF", "#FFA500", "#FF3C3C"); $colors = array("#D8BFD8", "#6495ED", "#6A5ADF", "#FFFFFF", "#FFA500", "#FF3C3C");
$fields = array("date" => "id DESC", "username" => "user", "location" => "location", "message" => "message DESC", "level" => "level DESC"); $fields = array("date" => "id DESC", "username" => "user", "location" => "location", "message" => "message DESC", "level" => "level DESC");
### Perform query: // Perform query:
$result = db_query("SELECT l.*, u.userid FROM watchdog l LEFT JOIN users u ON l.user = u.id ORDER BY l.$fields[$order]"); $result = db_query("SELECT l.*, u.userid FROM watchdog l LEFT JOIN users u ON l.user = u.id ORDER BY l.$fields[$order]");
### Generate output: // Generate output:
$output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n"; $output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
$output .= " <TR>\n"; $output .= " <TR>\n";
$output .= " <TH ALIGN=\"right\" COLSPAN=\"4\">\n"; $output .= " <TH ALIGN=\"right\" COLSPAN=\"4\">\n";
......