summaryrefslogtreecommitdiff
path: root/modules/blog.module
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2001-09-16 11:33:14 +0000
committerDries Buytaert <dries@buytaert.net>2001-09-16 11:33:14 +0000
commit2d1e9126cb10f52e7711ce121f8bdaa5bdc71aa4 (patch)
tree51c3918085542ee9487bfb4bc95feee502281eec /modules/blog.module
parentf358893b52f364aefbdab41a5e1407d54f0c2b59 (diff)
downloadbrdo-2d1e9126cb10f52e7711ce121f8bdaa5bdc71aa4.tar.gz
brdo-2d1e9126cb10f52e7711ce121f8bdaa5bdc71aa4.tar.bz2
- Added the new user module!
Diffstat (limited to 'modules/blog.module')
-rw-r--r--modules/blog.module105
1 files changed, 56 insertions, 49 deletions
diff --git a/modules/blog.module b/modules/blog.module
index d036679c0..c8126d2f8 100644
--- a/modules/blog.module
+++ b/modules/blog.module
@@ -26,20 +26,28 @@ function blog_summary($node) {
return $node->body;
}
-function blog_feed_user($name = 0, $date = 0) {
+function blog_feed_user($uid = 0, $date = 0) {
global $user;
- $name = check_input($name ? $name : $user->name);
- $date = check_input($date ? $date : time());
+ if ($uid) {
+ $account = user_load(array("uid" => $uid, "status" => 1));
+ }
+ else {
+ $account = $user;
+ }
+
+ if (!$date) {
+ $date = time();
+ }
- $result = db_query("SELECT n.nid, n.title, n.timestamp, b.body FROM blog b LEFT JOIN node n ON b.nid = n.nid LEFT JOIN users u ON n.author = u.id WHERE u.name = '$name' AND n.timestamp > '". ($date - 2592000) ."' ORDER BY b.lid DESC LIMIT 15");
+ $result = db_query("SELECT n.nid, n.title, n.timestamp, b.body, u.name, u.uid FROM blog b LEFT JOIN node n ON b.nid = n.nid LEFT JOIN user u ON n.author = u.uid WHERE u.uid = '$uid' AND n.timestamp > '". ($date - 2592000) ."' ORDER BY b.lid DESC LIMIT 15");
while ($blog = db_fetch_object($result)) {
$items .= format_rss_item($blog->title, path_uri() ."node.php?id=$blog->nid", $blog->body);
}
$output .= "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n";
$output .= "<rss version=\"0.91\">\n";
- $output .= format_rss_channel("$name's blog", path_uri() ."module.php?mod=blog&op=view&name=". urlencode($name), "$name's blog", $items);
+ $output .= format_rss_channel("$account->name's blog", path_uri() ."module.php?mod=blog&op=view&id=$account->uid", "$account->name's blog", $items);
$output .= "</rss>\n";
header("Content-Type: text/xml");
@@ -49,9 +57,9 @@ function blog_feed_user($name = 0, $date = 0) {
}
function blog_feed_last() {
- $result = db_query("SELECT n.nid, n.title, n.timestamp, b.body, u.name FROM blog b LEFT JOIN node n ON b.nid = n.nid LEFT JOIN users u ON n.author = u.id ORDER BY b.lid DESC LIMIT 15");
+ $result = db_query("SELECT n.nid, n.title, n.timestamp, b.body, u.name, u.uid FROM blog b LEFT JOIN node n ON b.nid = n.nid LEFT JOIN user u ON n.author = u.uid ORDER BY b.lid DESC LIMIT 15");
while ($blog = db_fetch_object($result)) {
- $items .= format_rss_item($blog->title, path_uri() ."module.php?mod=blog&op=view&name=". urlencode($blog->name), $blog->body);
+ $items .= format_rss_item($blog->title, path_uri() ."module.php?mod=blog&op=view&id=". urlencode($blog->uid), $blog->body);
}
$output .= "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n";
@@ -65,13 +73,21 @@ function blog_feed_last() {
}
-function blog_page_user($name = 0, $date = 0) {
+function blog_page_user($uid = 0, $date = 0) {
global $theme, $user;
- $name = check_input($name ? $name : $user->name);
- $date = check_input($date ? $date : time());
+ if ($uid) {
+ $account = user_load(array("uid" => $uid, "status" => 1));
+ }
+ else {
+ $account = $user;
+ }
- $result = db_query("SELECT n.nid, n.title, n.comment, COUNT(c.cid) AS comments, n.timestamp, b.body FROM blog b LEFT JOIN node n ON b.nid = n.nid LEFT JOIN users u ON n.author = u.id LEFT JOIN comments c ON n.nid = c.lid WHERE u.name = '$name' AND n.timestamp <= '$date' AND n.timestamp >= '". ($date - 2592000) ."' GROUP BY n.nid ORDER BY n.nid DESC LIMIT 20");
+ if (!$date) {
+ $date = time();
+ }
+
+ $result = db_query("SELECT n.nid, n.title, n.comment, COUNT(c.cid) AS comments, n.timestamp, b.body, u.uid, u.name FROM blog b LEFT JOIN node n ON b.nid = n.nid LEFT JOIN user u ON n.author = u.uid LEFT JOIN comments c ON n.nid = c.lid WHERE u.uid = '$account->uid' AND n.timestamp <= '$date' AND n.timestamp >= '". ($date - 2592000) ."' GROUP BY n.nid ORDER BY n.nid DESC LIMIT 20");
$output .= "<table border=\"0\" cellpadding=\"4\" cellspacing=\"4\">";
@@ -81,14 +97,14 @@ function blog_page_user($name = 0, $date = 0) {
if ($date != date("dny", $blog->timestamp)) {
$date = date("dny", $blog->timestamp);
- $output .= "<tr><td colspan=\"2\"><b><a href=\"module.php?mod=blog&name=". urlencode($name) ."&date=". mktime(23, 59, 59, date("n", $blog->timestamp), date("d", $blog->timestamp), date("Y", $blog->timestamp)) ."\">". format_date($blog->timestamp, custom, "d M Y") .":</a></b></td></tr>";
+ $output .= "<tr><td colspan=\"2\"><b><a href=\"module.php?mod=blog&id=$blog->uid&date=". mktime(23, 59, 59, date("n", $blog->timestamp), date("d", $blog->timestamp), date("Y", $blog->timestamp)) ."\">". format_date($blog->timestamp, custom, "d M Y") .":</a></b></td></tr>";
}
- if ($user->id && $user->name == $name) {
+ if ($user->uid && $user->name == $name) {
$links[] = "<a href=\"submit.php?mod=blog&op=edit&id=$blog->nid\">". t("edit") ."</a>";
}
- if ($user->id && user_access("post blogs")) {
+ if ($user->uid && user_access("post blogs")) {
$links[] = "<a href=\"submit.php?mod=blog&type=blog&id=$blog->nid\">". t("blog it") ."</a>";
}
@@ -102,15 +118,15 @@ function blog_page_user($name = 0, $date = 0) {
}
$output .= "</table>";
- $output .= "<a href=\"module.php?mod=blog&op=feed&name=". urlencode($name) ."\"><img src=\"". $theme->image("xml.gif") ."\" width=\"36\" height=\"14\" align=\"right\" border=\"0\" /></a>\n";
+ $output .= "<a href=\"module.php?mod=blog&op=feed&id=$account->uid\"><img src=\"". $theme->image("xml.gif") ."\" width=\"36\" height=\"14\" align=\"right\" border=\"0\" /></a>\n";
- $theme->box(strtr(t("%a's blog"), array("%a" => $name)), $output, "main");
+ $theme->box(sprintf(t("%s's blog"), $account->name), $output, "main");
}
function blog_page_last() {
global $theme, $user;
- $result = db_query("SELECT n.author, n.nid, n.title, n.comment, COUNT(c.cid) AS comments, n.timestamp, b.body, u.name FROM blog b LEFT JOIN node n ON b.nid = n.nid LEFT JOIN users u ON n.author = u.id LEFT JOIN comments c ON n.nid = c.lid GROUP BY n.nid ORDER BY n.nid DESC LIMIT 20");
+ $result = db_query("SELECT n.nid, n.title, n.comment, COUNT(c.cid) AS comments, n.timestamp, b.body, u.uid, u.name FROM blog b LEFT JOIN node n ON b.nid = n.nid LEFT JOIN user u ON n.author = u.uid LEFT JOIN comments c ON n.nid = c.lid GROUP BY n.nid ORDER BY n.nid DESC LIMIT 20");
$output .= "<table border=\"0\" cellpadding=\"4\" cellspacing=\"4\">";
@@ -118,13 +134,13 @@ function blog_page_last() {
$links = array();
- $links[] = "<a href=\"module.php?mod=blog&op=view&name=". urlencode($blog->name) ."\">". strtr(t("%a's blog"), array("%a" => $blog->name)) ."</a>";
+ $links[] = "<a href=\"module.php?mod=blog&op=view&id=$blog->uid\">". sprintf("%s's blog", $blog->name) ."</a>";
- if ($blog->author == $user->id) {
+ if ($blog->uid == $user->uid) {
$links[] = "<a href=\"submit.php?mod=blog&op=edit&id=$blog->nid\">". t("edit") ."</a>";
}
- if ($user->id && user_access("post blogs")) {
+ if ($user->uid && user_access("post blogs")) {
$links[] = "<a href=\"submit.php?mod=blog&type=blog&id=$blog->nid\">". t("blog it") ."</a>";
}
@@ -148,7 +164,7 @@ function blog_remove($nid) {
$blog = node_get_object(array(nid => $nid, type => "blog"));
- if ($blog && $blog->author == $user->id) {
+ if ($blog && $blog->uid == $user->uid) {
node_save(array(nid => $nid), array(status => $status[dumped]));
node_del(array(type => "blog", nid => $nid));
}
@@ -163,7 +179,7 @@ function blog_view($node, $main = 0) {
function blog_form($edit = array()) {
global $REQUEST_URI, $id, $mod, $type, $user, $theme;
- if ($user->id && (user_access("administer blogs") || user_access("post blogs"))) {
+ if ($user->uid && (user_access("administer blogs") || user_access("post blogs"))) {
if ($mod == "node" || $edit[type] == "blog") {
// do nothing
}
@@ -217,12 +233,12 @@ function blog_form($edit = array()) {
function blog_save($edit) {
global $status, $user;
- if ($user->id && (user_access("administer blogs") || user_access("post blogs"))) {
+ if ($user->uid && (user_access("administer blogs") || user_access("post blogs"))) {
if ($edit["nid"]) {
node_save($edit, array(title, body, type => "blog"));
}
else {
- node_save($edit, array(attributes => node_attributes_save("blog", $edit), author => $user->id, body, comment => variable_get("blog_comment", 0), moderate => variable_get("blog_moderate", ""), promote => variable_get("blog_promote", 0), score => 0, status => variable_get("blog_status", $status[posted]), timestamp => time(), title, type => "blog", votes => 0));
+ node_save($edit, array(attributes => node_attributes_save("blog", $edit), author => $user->uid, body, comment => variable_get("blog_comment", 0), moderate => variable_get("blog_moderate", ""), promote => variable_get("blog_promote", 0), score => 0, status => variable_get("blog_status", $status[posted]), timestamp => time(), title, type => "blog", votes => 0));
}
}
}
@@ -230,7 +246,7 @@ function blog_save($edit) {
function blog_edit_history($nid) {
global $user;
- $result = db_query("SELECT n.nid, n.title, n.timestamp, b.body FROM blog b LEFT JOIN node n ON b.nid = n.nid WHERE n.author = '". check_input($user->id) ."' AND n.nid <= '". check_input($nid) ."' ORDER BY b.lid DESC LIMIT 15");
+ $result = db_query("SELECT n.nid, n.title, n.timestamp, b.body FROM blog b LEFT JOIN node n ON b.nid = n.nid WHERE n.author = '$user->uid' AND n.nid <= '". check_input($nid) ."' ORDER BY b.lid DESC LIMIT 15");
$output .= "<table cellpadding=\"3\" cellspacing=\"3\" border=\"0\" width=\"100%\">";
while ($blog = db_fetch_object($result)) {
@@ -242,13 +258,13 @@ function blog_edit_history($nid) {
}
function blog_page() {
- global $theme, $op, $name, $date;
+ global $theme, $id, $op, $date;
if (user_access("access blogs")) {
switch ($op) {
case "feed":
- if ($name) {
- blog_feed_user($name, $date);
+ if ($id) {
+ blog_feed_user($id, $date);
}
else {
blog_feed_last();
@@ -256,8 +272,8 @@ function blog_page() {
break;
default:
$theme->header();
- if ($name) {
- blog_page_user($name, $date);
+ if ($id) {
+ blog_page_user($id, $date);
}
else {
blog_page_last();
@@ -280,7 +296,7 @@ function blog_user() {
switch ($op) {
case "delete":
blog_remove($id);
- blog_page_user($user->name, time());
+ blog_page_user($user->uid, time());
break;
case "edit":
$theme->box(t("Submit a blog"), blog_form(node_get_array(array("nid" => $id, "type" => "blog"))), "main");
@@ -291,7 +307,7 @@ function blog_user() {
break;
case t("Submit"):
blog_save($edit);
- blog_page_user($user->name, time());
+ blog_page_user($user->uid, time());
break;
default:
$theme->box(t("Submit a blog"), blog_form($edit), "main");
@@ -309,11 +325,11 @@ function blog_link($type, $node = 0) {
if ($type == "menu" && user_access("post blogs")) {
$links[] = "<a href=\"submit.php?mod=blog\">". t("add blog entry") ."</a>";
- $links[] = "<a href=\"module.php?mod=blog&op=view&name=". urlencode($user->name) ."\">". t("view your blog") ."</a>";
+ $links[] = "<a href=\"module.php?mod=blog&op=view&id=$user->uid\">". t("view your blog") ."</a>";
}
if ($type == "node" && $node->type == "blog") {
- $links[] = "<a href=\"module.php?mod=blog&op=view&name=". urlencode($node->name) ."\">". strtr(t("%a's blog"), array("%a" => $node->name)) ."</a>";
+ $links[] = "<a href=\"module.php?mod=blog&op=view&id=$node->uid\">". strtr(t("%a's blog"), array("%a" => $node->name)) ."</a>";
}
return $links ? $links : array();
@@ -321,11 +337,12 @@ function blog_link($type, $node = 0) {
function blog_block() {
- global $name, $date, $user, $mod;
+ global $user;
+
+ $result = db_query("SELECT u.uid, u.name, n.timestamp, n.title, n.nid FROM node n LEFT JOIN user u ON n.author = u.uid WHERE n.type = 'blog' ORDER BY n.nid DESC LIMIT 10");
- $result = db_query("SELECT u.name, n.timestamp, n.title, n.nid FROM node n LEFT JOIN users u ON n.author = u.id WHERE n.type = 'blog' ORDER BY n.nid DESC LIMIT 10");
while ($node = db_fetch_object($result)) {
- $output .= "<a href=\"module.php?mod=blog&op=view&name=". urlencode($node->name) ."\">". check_output($node->title) ."</a><br />\n";
+ $output .= "<a href=\"module.php?mod=blog&op=view&id=$node->nid\">". check_output($node->title) ."</a><br />\n";
}
$block[0]["subject"] = "<a href=\"module.php?mod=blog\">". t("User blogs") ."</a>";
@@ -333,23 +350,13 @@ function blog_block() {
$block[0]["info"] = t("User blogs");
$block[0]["link"] = "module.php?mod=blog";
- $date = $date ? $date : time();
- $name = $name ? $name : $user->name;
-
- if (($mod == "blog") || ($mod == "block")) {
- // Only show this block on "blog pages" and in the admin block section.
- $calendar = new BlogCalendar($name, $date);
- $block[1]["subject"] = "<a href=\"module.php?mod=blog&name=". urlencode($name) ."\">" . t("Browse blog") . "</a>";
- $block[1]["content"] = $calendar->display();
- $block[1]["info"] = t("Calendar to browse blogs");
- }
-
return $block;
}
function blog_search($keys) {
- global $status, $user;
+ global $status;
+
$result = db_query("SELECT n.*, b.* FROM blog b LEFT JOIN node n ON n.nid = b.nid AND n.lid = b.lid WHERE (n.title LIKE '%$keys%' OR b.body LIKE '%$keys%') ORDER BY n.timestamp DESC LIMIT 20");
while ($blog = db_fetch_object($result)) {
$find[$i++] = array("title" => check_output($blog->title), "link" => (user_access("administer nodes") ? "admin.php?mod=node&type=blog&op=edit&id=$blog->nid" : "node.php?id=$blog->nid"), "user" => $blog->name, "date" => $blog->timestamp);