Commit 1f056580 authored by Dries's avatar Dries

- improved submit.php:
  it now uses the new category code, incl content bindings.
  You can setup different "categories" which map on a content
  type.  Example:
    review   -> review.module
    article  -> story.module
    column   -> story.module
    announc. -> story.module
    addons   -> file.module
    themes   -> file.module
- "generalised" story.module and book.module's output.
- fixed bug in includes/timer.inc
- fixed glitch in theme example.theme: it said "$how by" but
  the variable $how has never been declared.
- added "drupal development settings" to display some timings
- more work on the categories/topics -> does NOT work yet
parent f1716fbd
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
include_once "includes/common.inc"; include_once "includes/common.inc";
if (variable_get(dev_timing, 0)) timer_start();
function account_get_user($uname) { function account_get_user($uname) {
$result = db_query("SELECT * FROM users WHERE userid = '$uname'"); $result = db_query("SELECT * FROM users WHERE userid = '$uname'");
return db_fetch_object($result); return db_fetch_object($result);
...@@ -562,4 +564,6 @@ function account_track_site() { ...@@ -562,4 +564,6 @@ function account_track_site() {
account_user($user->userid); account_user($user->userid);
} }
if (variable_get(dev_timing, 0)) timer_print();
?> ?>
\ No newline at end of file
...@@ -289,7 +289,7 @@ function comment_render($lid, $cid) { ...@@ -289,7 +289,7 @@ function comment_render($lid, $cid) {
if ($user->id) { if ($user->id) {
// Comment control: // Comment control:
$theme->box(t("Comment control"), "<DIV ALIGN=\"center\">". comment_controls($threshold, $mode, $order) ."</DIV>"); $theme->box(t("Comment control"), comment_controls($threshold, $mode, $order));
// Print moderation form: // Print moderation form:
print "<FORM METHOD=\"post\" ACTION=\"$REQUEST_URI\">\n"; print "<FORM METHOD=\"post\" ACTION=\"$REQUEST_URI\">\n";
......
...@@ -18,6 +18,13 @@ function node_get_array($field, $value) { ...@@ -18,6 +18,13 @@ function node_get_array($field, $value) {
return db_fetch_array(_node_get($field, $value)); return db_fetch_array(_node_get($field, $value));
} }
function node_get_category($nid) {
db_fetch_array(db_query("SELECT FROM"));
}
function node_get_topic($nid) {
}
function node_del($field, $value) { function node_del($field, $value) {
global $status; global $status;
if ($node = node_get_object($field, $value)) { if ($node = node_get_object($field, $value)) {
...@@ -123,7 +130,6 @@ function node_save($node) { ...@@ -123,7 +130,6 @@ function node_save($node) {
} }
} }
function node_invoke($node, $name, $arg = 0) { function node_invoke($node, $name, $arg = 0) {
if ($node[type]) $function = $node[type] ."_$name"; if ($node[type]) $function = $node[type] ."_$name";
if ($node->type) $function = $node->type ."_$name"; if ($node->type) $function = $node->type ."_$name";
......
...@@ -22,11 +22,26 @@ function category_save($edit) { ...@@ -22,11 +22,26 @@ function category_save($edit) {
foreach ($edit as $key=>$value) db_query("UPDATE category SET $key = '". check_input($value) ."' WHERE cid = '$edit[cid]'"); foreach ($edit as $key=>$value) db_query("UPDATE category SET $key = '". check_input($value) ."' WHERE cid = '$edit[cid]'");
} }
function category_del($id) { // delete category $cid:
db_query("DELETE FROM category WHERE cid = '$id'"); function category_del($cid) {
db_query("DELETE FROM category WHERE cid = '". check_input($cid) ."'");
db_query("DELETE FROM node_category WHERE cid = '". check_input($cid) ."'");
}
function category_node($nid, $cid) {
db_query("INSERT INTO node_category (nid, cid) VALUES ('". check_input($nid) ."', '". check_input($cid) ."')", 1);
}
function category_form_select($type, $edit = array(), $size = 1) {
$result = db_query("SELECT * FROM category WHERE type = '$type'");
while ($category = db_fetch_object($result)) {
$options .= "<OPTION VALUE=\"$category->cid\"". ($edit[$category->cid] ? "SELECTED" : "") .">". check_select($category->name) ."</OPTION>";
}
return "<SELECT NAME=\"category[]\" SIZE=\"$size\"". ($size > 1 ? "MULTIPLE" : "") .">$options</SELECT>\n";
} }
// ----- topic ----- // ----- topic -----
function _topic_get($field, $value) { function _topic_get($field, $value) {
return db_query("SELECT * FROM topic WHERE $field = '$value'"); return db_query("SELECT * FROM topic WHERE $field = '$value'");
} }
...@@ -57,16 +72,39 @@ function topic_tree($parent = 0, $name = "", $tree = array()) { ...@@ -57,16 +72,39 @@ function topic_tree($parent = 0, $name = "", $tree = array()) {
return $tree; return $tree;
} }
// renders a form to select one or more topics: // delete topic $tid:
function topic_form_select($type, $topics = array(), $size = 1) { function topic_del($tid) {
db_query("DELETE FROM topic WHERE tid = '". check_input($tid) ."'");
db_query("DELETE FROM node_topic WHERE tid = '". check_input($tid) ."'");
}
// add node $nid to topic $tid:
function topic_node($nid, $tid) {
db_query("INSERT INTO node_topic (nid, tid) VALUES ('". check_input($nid) ."', '". check_input($tid) ."')", 1);
}
// renders a HTML form to select one or more topics:
function topic_form_select($edit = array(), $size = 1) {
foreach (topic_tree() as $tid=>$name) { foreach (topic_tree() as $tid=>$name) {
$options .= "<OPTION VALUE=\"$tid\">$name</OPTION>\n"; $options .= "<OPTION VALUE=\"$tid\"". ($edit[$tid] ? "SELECTED" : "") .">". check_select($name) ."</OPTION>";
} }
return "<B>". t("Topic") .":</B><BR><SELECT NAME=\"edit[topic][]\" SIZE=\"$size\"". ($size > 1 ? "MULTIPLE" : "") .">$options</SELECT><P>\n"; return "<SELECT NAME=\"topic[]\" SIZE=\"$size\"". ($size > 1 ? "MULTIPLE" : "") .">$options</SELECT>\n";
}
// ----- structure -----
// add node $nid to category $cid and topic $tid:
function structure_save($nid, $cid, $tid) {
category_node($nid, $cid);
topic_node($nid, $tid);
} }
function topic_del($id) { // render a HMTL selection form:
db_query("DELETE FROM topic WHERE tid = '$id'"); function structure_form($type, $edit = array(), $size = 1) {
$output .= "<B>Category and topic:</B><BR>\n";
$output .= category_form_select($type, $edit, $size) ." ". topic_form_select($edit, $size) ."<BR>";
$output .= "<SMALL><I>". t("Select the category and the topic this sumbission belongs in.") ."</I></SMALL><P>";
return $output;
} }
?> ?>
\ No newline at end of file
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
function timer_print() { function timer_print() {
global $timer; global $timer;
$stop = explode(" ", microtime()); $stop = explode(" ", microtime());
$diff = $timer[0] - $stop[0]; $diff = $stop[0] - $timer[0];
print "<PRE>execution time: $diff ms</PRE>"; print "<PRE>execution time: $diff ms</PRE>";
} }
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
include_once "includes/common.inc"; include_once "includes/common.inc";
if (variable_get(dev_timing, 0)) timer_start();
// Initialize/pre-process variables: // Initialize/pre-process variables:
$number = ($user->nodes) ? $user->nodes : 10; $number = ($user->nodes) ? $user->nodes : 10;
$date = ($date > 0) ? $date : time(); $date = ($date > 0) ? $date : time();
...@@ -14,4 +16,6 @@ ...@@ -14,4 +16,6 @@
while ($story = db_fetch_object($result)) $theme->story($story); while ($story = db_fetch_object($result)) $theme->story($story);
$theme->footer(); $theme->footer();
if (variable_get(dev_timing, 0)) timer_print();
?> ?>
<?php <?php
include_once "includes/common.inc"; include_once "includes/common.inc";
if (variable_get(dev_timing, 0)) timer_start();
module_execute($mod, "page"); module_execute($mod, "page");
if (variable_get(dev_timing, 0)) timer_print();
?> ?>
...@@ -31,7 +31,7 @@ function account_help() { ...@@ -31,7 +31,7 @@ function account_help() {
<TR><TD>apple</TD><TD>Matches any string that has the text "apple" in it.<TD></TR> <TR><TD>apple</TD><TD>Matches any string that has the text "apple" in it.<TD></TR>
<TR><TD>^apple$</TD><TD>Matches the exact string "apple".<TD></TR> <TR><TD>^apple$</TD><TD>Matches the exact string "apple".<TD></TR>
<TR><TD>^apple</TD><TD>Matches any string that starts with "apple".<TD></TR> <TR><TD>^apple</TD><TD>Matches any string that starts with "apple".<TD></TR>
<TR><TD>domain\.com$</TD><TD>Matches any string that ends with "@domain.com". Note that you have to escape the dot in domain.com.</TD></TR> <TR><TD>domain\.com$</TD><TD>Matches any string that ends with "domain.com". Note that you have to escape the dot in domain.com.</TD></TR>
</TABLE> </TABLE>
<?php <?php
} }
......
...@@ -267,7 +267,7 @@ function book_update($id) { ...@@ -267,7 +267,7 @@ function book_update($id) {
function book_user() { function book_user() {
global $edit, $id, $op, $theme, $user; global $edit, $id, $op, $theme, $user;
$title = t("Submit a book page"); $title = t("Submit");
switch($op) { switch($op) {
case "update": case "update":
......
...@@ -267,7 +267,7 @@ function book_update($id) { ...@@ -267,7 +267,7 @@ function book_update($id) {
function book_user() { function book_user() {
global $edit, $id, $op, $theme, $user; global $edit, $id, $op, $theme, $user;
$title = t("Submit a book page"); $title = t("Submit");
switch($op) { switch($op) {
case "update": case "update":
......
...@@ -19,11 +19,14 @@ function settings_conf() { ...@@ -19,11 +19,14 @@ function settings_conf() {
$output .= "<INPUT NAME=\"edit[site_url]\" MAXLENGTH=\"55\" SIZE=\"30\" VALUE=\"". variable_get(site_url, "http://drupal/") ."\"><BR>\n"; $output .= "<INPUT NAME=\"edit[site_url]\" MAXLENGTH=\"55\" SIZE=\"30\" VALUE=\"". variable_get(site_url, "http://drupal/") ."\"><BR>\n";
$output .= "<I><SMALL>The fully qualified URL of this website: starts with \"http://\" and ends with a trailing slash!</SMALL></I><P>\n"; $output .= "<I><SMALL>The fully qualified URL of this website: starts with \"http://\" and ends with a trailing slash!</SMALL></I><P>\n";
$output .= "<B>Footer message:</B><BR>\n";
$output .= "<TEXTAREA NAME=\"edit[site_footer]\" COLS=\"55\" ROWS=\"3\" WRAP=\"virtual\">". variable_get(site_footer, "") ."</TEXTAREA><BR>\n";
$output .= "<I><SMALL>This text will be displayed at the bottom of each page. Useful to add a copyright notice to your pages.</SMALL></I><P>\n";
$output .= "<B>Anonymous user:</B><BR>\n"; $output .= "<B>Anonymous user:</B><BR>\n";
$output .= "<INPUT NAME=\"edit[anonymous]\" MAXLENGTH=\"55\" SIZE=\"30\" VALUE=\"". variable_get(anonymous, "Anonymous") ."\"><BR>\n"; $output .= "<INPUT NAME=\"edit[anonymous]\" MAXLENGTH=\"55\" SIZE=\"30\" VALUE=\"". variable_get(anonymous, "Anonymous") ."\"><BR>\n";
$output .= "<I><SMALL>The name displayed for anonymous users.</SMALL></I><P>\n"; $output .= "<I><SMALL>The name displayed for anonymous users.</SMALL></I><P>\n";
$output .= "<HR>\n"; $output .= "<HR>\n";
$output .= "<H3>Comment settings</H3>\n"; $output .= "<H3>Comment settings</H3>\n";
...@@ -72,10 +75,6 @@ function settings_conf() { ...@@ -72,10 +75,6 @@ function settings_conf() {
$output .= "<SELECT NAME=\"edit[theme_default]\">$options7</SELECT><BR>\n"; $output .= "<SELECT NAME=\"edit[theme_default]\">$options7</SELECT><BR>\n";
$output .= "<I><SMALL>The default theme displayed for anonymous users.</SMALL></I><P>\n"; $output .= "<I><SMALL>The default theme displayed for anonymous users.</SMALL></I><P>\n";
$output .= "<B>Footer message:</B><BR>\n";
$output .= "<TEXTAREA NAME=\"edit[theme_footer]\" COLS=\"55\" ROWS=\"3\" WRAP=\"virtual\">". variable_get(theme_footer, "") ."</TEXTAREA><BR>\n";
$output .= "<I><SMALL>This text will be displayed at the bottom of each page. Useful to add a copyright notice to your pages.</SMALL></I><P>\n";
$output .= "<HR>\n"; $output .= "<HR>\n";
$output .= "<H3>Development settings</H3>\n"; $output .= "<H3>Development settings</H3>\n";
......
...@@ -11,12 +11,14 @@ ...@@ -11,12 +11,14 @@
include_once "includes/section.inc"; include_once "includes/section.inc";
class Story { class Story {
function Story($userid, $title, $abstract, $body, $section, $timestamp) { $this->userid = $userid; function Story($story, $category = 0, $topic = 0) {
$this->title = $title; $this->userid = $story[userid] ? $story[userid] : $user->userid;
$this->abstract = $abstract; $this->title = $story[title];
$this->body = $body; $this->abstract = $story[abstract];
$this->section = $section; $this->body = $story[body];
$this->timestamp = $timestamp; $this->timestamp = $story[timestamp] ? $story[timestamp] : time();
$this->category = ($category ? $category : node_get_category($story[nid]));
$this->topic = ($topic ? $topic : node_get_topic($story[nid]));
} }
} }
...@@ -111,53 +113,51 @@ function story_view($node, $page = 1) { ...@@ -111,53 +113,51 @@ function story_view($node, $page = 1) {
} }
} }
function story_form($edit = array()) { function story_form($story = array()) {
global $allowed_html, $REQUEST_URI, $user; global $allowed_html, $REQUEST_URI, $user;
$output .= "<FORM ACTION=\"$REQUEST_URI\" METHOD=\"post\">\n"; $output .= "<FORM ACTION=\"$REQUEST_URI\" METHOD=\"post\">\n";
$output .= "<B>". t("Your name") .":</B><BR>\n"; $output .= "<B>". t("Your name") .":</B><BR>\n";
$output .= "<INPUT TYPE=\"hidden\" NAME=\"edit[userid]\" VALUE=\"$edit[userid]\">\n"; $output .= "<INPUT TYPE=\"hidden\" NAME=\"story[userid]\" VALUE=\"$story[userid]\">\n";
$output .= format_username(($edit[userid] ? $edit[userid] : $user->userid)) ."<P>"; $output .= format_username(($story[userid] ? $story[userid] : $user->userid)) ."<P>";
$output .= "<B>". t("Subject") .":</B><BR>\n"; $output .= "<B>". t("Subject") .":</B><BR>\n";
$output .= "<INPUT TYPE=\"text\" NAME=\"edit[title]\" SIZE=\"50\" MAXLENGTH=\"60\" VALUE=\"". check_textfield($edit[title]) ."\"><P>\n"; $output .= "<INPUT TYPE=\"text\" NAME=\"story[title]\" SIZE=\"50\" MAXLENGTH=\"60\" VALUE=\"". check_textfield($story[title]) ."\"><P>\n";
$output .= "<B>". t("Section") .":</B><BR>\n"; $output .= structure_form("story");
foreach ($sections = section_get() as $value) $options .= " <OPTION VALUE=\"". check_select($value) ."\"". ($edit[section] == $value ? " SELECTED" : "") .">". check_output($value) ."</OPTION>\n";
$output .= "<SELECT NAME=\"edit[section]\">$options</SELECT><P>\n";
$output .= "<B>". t("Abstract") .":</B><BR>\n"; $output .= "<B>". t("Abstract") .":</B><BR>\n";
$output .= "<TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"10\" NAME=\"edit[abstract]\">". check_textarea($edit[abstract]) ."</TEXTAREA><BR>\n"; $output .= "<TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"10\" NAME=\"story[abstract]\">". check_textarea($story[abstract]) ."</TEXTAREA><BR>\n";
$output .= "<SMALL><I>". t("Allowed HTML tags") .": ". htmlspecialchars($allowed_html) .".</I></SMALL><P>\n"; $output .= "<SMALL><I>". t("Allowed HTML tags") .": ". htmlspecialchars($allowed_html) .".</I></SMALL><P>\n";
$output .= "<B>". t("Body") .":</B><BR>\n"; $output .= "<B>". t("Body") .":</B><BR>\n";
$output .= "<TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"15\" NAME=\"edit[body]\">". check_textarea($edit[body]) ."</TEXTAREA><BR>\n"; $output .= "<TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"15\" NAME=\"story[body]\">". check_textarea($story[body]) ."</TEXTAREA><BR>\n";
$output .= "<SMALL><I>". t("Allowed HTML tags") .": ". htmlspecialchars($allowed_html) .".</I></SMALL><P>\n"; $output .= "<SMALL><I>". t("Allowed HTML tags") .": ". htmlspecialchars($allowed_html) .".</I></SMALL><P>\n";
if (user_access($user, "story")) { if (user_access($user, "story")) {
$output .= "<INPUT TYPE=\"hidden\" NAME=\"edit[timestamp]\" VALUE=\"$edit[timestamp]\">\n"; $output .= "<INPUT TYPE=\"hidden\" NAME=\"story[timestamp]\" VALUE=\"$story[timestamp]\">\n";
$output .= "<INPUT TYPE=\"hidden\" NAME=\"edit[nid]\" VALUE=\"$edit[nid]\">\n"; $output .= "<INPUT TYPE=\"hidden\" NAME=\"story[nid]\" VALUE=\"$story[nid]\">\n";
} }
$duplicate = db_result(db_query("SELECT COUNT(nid) FROM node WHERE title = '$title'")); $duplicate = db_result(db_query("SELECT COUNT(nid) FROM node WHERE title = '$title'"));
if (!$edit) { if (!$story) {
$output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Preview") ."\">\n"; $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Preview") ."\">\n";
} }
else if (!$edit[title]) { else if (!$story[title]) {
$output .= "<FONT COLOR=\"red\">". t("Warning: you did not supply a subject.") ."</FONT><P>\n"; $output .= "<FONT COLOR=\"red\">". t("Warning: you did not supply a subject.") ."</FONT><P>\n";
$output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Preview") ."\">\n"; $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Preview") ."\">\n";
} }
else if (!$edit[section]) { else if (!$story[section]) {
$output .= "<FONT COLOR=\"red\">". t("Warning: you did not supply a section.") ."</FONT><P>\n"; $output .= "<FONT COLOR=\"red\">". t("Warning: you did not supply a section.") ."</FONT><P>\n";
$output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Preview") ."\">\n"; $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Preview") ."\">\n";
} }
else if (!$edit[abstract]) { else if (!$story[abstract]) {
$output .= "<FONT COLOR=\"red\">". t("Warning: you did not supply an abstract.") ."</FONT><P>\n"; $output .= "<FONT COLOR=\"red\">". t("Warning: you did not supply an abstract.") ."</FONT><P>\n";
$output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Preview") ."\">\n"; $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Preview") ."\">\n";
} }
else if (!$edit[nid] && $duplicate) { else if (!$story[nid] && $duplicate) {
$output .= "<FONT COLOR=\"red\">". t("Warning: there is already a story with that subject.") ."</FONT><P>\n"; $output .= "<FONT COLOR=\"red\">". t("Warning: there is already a story with that subject.") ."</FONT><P>\n";
$output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Preview") ."\">\n"; $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Preview") ."\">\n";
} }
...@@ -170,8 +170,9 @@ function story_form($edit = array()) { ...@@ -170,8 +170,9 @@ function story_form($edit = array()) {
return $output; return $output;
} }
function story_save($edit) { function story_save($story, $category, $topic) {
node_save(array_diff(array_merge($edit, array(nid => $edit[nid], type => "story")), array(userid => $edit[userid]))); node_save(array_diff(array_merge($story, array(nid => $story[nid], type => "story")), array(userid => $story[userid])));
structure_save($category, $topic);
} }
function story_block() { function story_block() {
...@@ -215,7 +216,7 @@ function story_overview($query = array()) { ...@@ -215,7 +216,7 @@ function story_overview($query = array()) {
} }
function story_admin() { function story_admin() {
global $id, $edit, $mod, $keys, $op, $theme, $type, $user; global $id, $story, $category, $topic, $mod, $keys, $op, $theme, $type, $user;
print "<SMALL><A HREF=\"admin.php?mod=story&op=add\">add new story</A> | <A HREF=\"admin.php?mod=story&op=listing\">story listing</A> | <A HREF=\"admin.php?mod=story&op=search\">search story</A> | <A HREF=\"admin.php?mod=story\">overview</A> | <A HREF=\"admin.php?mod=story&op=help\">help</A></SMALL><HR>\n"; print "<SMALL><A HREF=\"admin.php?mod=story&op=add\">add new story</A> | <A HREF=\"admin.php?mod=story&op=listing\">story listing</A> | <A HREF=\"admin.php?mod=story&op=search\">search story</A> | <A HREF=\"admin.php?mod=story\">overview</A> | <A HREF=\"admin.php?mod=story&op=help\">help</A></SMALL><HR>\n";
...@@ -243,11 +244,11 @@ function story_admin() { ...@@ -243,11 +244,11 @@ function story_admin() {
print search_data($keys, $mod); print search_data($keys, $mod);
break; break;
case t("Preview"): case t("Preview"):
story_view(new Story(($edit[userid] ? $edit[userid] : $user->userid), $edit[title], $edit[abstract], $edit[body], $edit[section], ($edit[timestamp] ? $edit[timestamp] : time())), 0); story_view(new Story($story, $category, $topic),0);
print story_form($edit); print story_form($story);
break; break;
case t("Submit"): case t("Submit"):
story_save($edit); story_save($story, $category, $topic);
// fall through: // fall through:
default: default:
print story_overview(story_query($type)); print story_overview(story_query($type));
...@@ -256,19 +257,19 @@ function story_admin() { ...@@ -256,19 +257,19 @@ function story_admin() {
function story_user() { function story_user() {
global $edit, $op, $theme, $user; global $story, $category, $topic, $op, $theme, $user;
switch($op) { switch($op) {
case t("Preview"): case t("Preview"):
story_view(new Story($user->userid, $edit[title], $edit[abstract], $edit[body], $edit[section], ($edit[timestamp] ? $edit[timestamp] : time())), 0); story_view(new Story($story, $category, $topic), 0);
$theme->box("Submit a story", story_form($edit)); $theme->box("Submit", story_form($story));
break; break;
case t("Submit"): case t("Submit"):
story_save($edit); story_save($story, $category, $topic);
$theme->box(t("Submit a story"), t("Thank you for your submission.")); $theme->box(t("Submit"), t("Thank you for your submission."));
break; break;
default: default:
$theme->box("Submit a story", story_form()); $theme->box("Submit", story_form());
} }
} }
......
...@@ -11,12 +11,14 @@ ...@@ -11,12 +11,14 @@
include_once "includes/section.inc"; include_once "includes/section.inc";
class Story { class Story {
function Story($userid, $title, $abstract, $body, $section, $timestamp) { $this->userid = $userid; function Story($story, $category = 0, $topic = 0) {
$this->title = $title; $this->userid = $story[userid] ? $story[userid] : $user->userid;
$this->abstract = $abstract; $this->title = $story[title];
$this->body = $body; $this->abstract = $story[abstract];
$this->section = $section; $this->body = $story[body];
$this->timestamp = $timestamp; $this->timestamp = $story[timestamp] ? $story[timestamp] : time();
$this->category = ($category ? $category : node_get_category($story[nid]));
$this->topic = ($topic ? $topic : node_get_topic($story[nid]));
} }
} }
...@@ -111,53 +113,51 @@ function story_view($node, $page = 1) { ...@@ -111,53 +113,51 @@ function story_view($node, $page = 1) {
} }
} }
function story_form($edit = array()) { function story_form($story = array()) {
global $allowed_html, $REQUEST_URI, $user; global $allowed_html, $REQUEST_URI, $user;
$output .= "<FORM ACTION=\"$REQUEST_URI\" METHOD=\"post\">\n"; $output .= "<FORM ACTION=\"$REQUEST_URI\" METHOD=\"post\">\n";
$output .= "<B>". t("Your name") .":</B><BR>\n"; $output .= "<B>". t("Your name") .":</B><BR>\n";
$output .= "<INPUT TYPE=\"hidden\" NAME=\"edit[userid]\" VALUE=\"$edit[userid]\">\n"; $output .= "<INPUT TYPE=\"hidden\" NAME=\"story[userid]\" VALUE=\"$story[userid]\">\n";
$output .= format_username(($edit[userid] ? $edit[userid] : $user->userid)) ."<P>"; $output .= format_username(($story[userid] ? $story[userid] : $user->userid)) ."<P>";
$output .= "<B>". t("Subject") .":</B><BR>\n"; $output .= "<B>". t("Subject") .":</B><BR>\n";
$output .= "<INPUT TYPE=\"text\" NAME=\"edit[title]\" SIZE=\"50\" MAXLENGTH=\"60\" VALUE=\"". check_textfield($edit[title]) ."\"><P>\n"; $output .= "<INPUT TYPE=\"text\" NAME=\"story[title]\" SIZE=\"50\" MAXLENGTH=\"60\" VALUE=\"". check_textfield($story[title]) ."\"><P>\n";
$output .= "<B>". t("Section") .":</B><BR>\n"; $output .= structure_form("story");
foreach ($sections = section_get() as $value) $options .= " <OPTION VALUE=\"". check_select($value) ."\"". ($edit[section] == $value ? " SELECTED" : "") .">". check_output($value) ."</OPTION>\n";
$output .= "<SELECT NAME=\"edit[section]\">$options</SELECT><P>\n";
$output .= "<B>". t("Abstract") .":</B><BR>\n"; $output .= "<B>". t("Abstract") .":</B><BR>\n";
$output .= "<TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"10\" NAME=\"edit[abstract]\">". check_textarea($edit[abstract]) ."</TEXTAREA><BR>\n"; $output .= "<TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"10\" NAME=\"story[abstract]\">". check_textarea($story[abstract]) ."</TEXTAREA><BR>\n";
$output .= "<SMALL><I>". t("Allowed HTML tags") .": ". htmlspecialchars($allowed_html) .".</I></SMALL><P>\n"; $output .= "<SMALL><I>". t("Allowed HTML tags") .": ". htmlspecialchars($allowed_html) .".</I></SMALL><P>\n";
$output .= "<B>". t("Body") .":</B><BR>\n"; $output .= "<B>". t("Body") .":</B><BR>\n";
$output .= "<TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"15\" NAME=\"edit[body]\">". check_textarea($edit[body]) ."</TEXTAREA><BR>\n"; $output .= "<TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"15\" NAME=\"story[body]\">". check_textarea($story[body]) ."</TEXTAREA><BR>\n";
$output .= "<SMALL><I>". t("Allowed HTML tags") .": ". htmlspecialchars($allowed_html) .".</I></SMALL><P>\n"; $output .= "<SMALL><I>". t("Allowed HTML tags") .": ". htmlspecialchars($allowed_html) .".</I></SMALL><P>\n";
if (user_access($user, "story")) { if (user_access($user, "story")) {
$output .= "<INPUT TYPE=\"hidden\" NAME=\"edit[timestamp]\" VALUE=\"$edit[timestamp]\">\n"; $output .= "<INPUT TYPE=\"hidden\" NAME=\"story[timestamp]\" VALUE=\"$story[timestamp]\">\n";
$output .= "<INPUT TYPE=\"hidden\" NAME=\"edit[nid]\" VALUE=\"$edit[nid]\">\n"; $output .= "<INPUT TYPE=\"hidden\" NAME=\"story[nid]\" VALUE=\"$story[nid]\">\n";
} }
$duplicate = db_result(db_query("SELECT COUNT(nid) FROM node WHERE title = '$title'")); $duplicate = db_result(db_query("SELECT COUNT(nid) FROM node WHERE title = '$title'"));
if (!$edit) { if (!$story) {
$output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Preview") ."\">\n"; $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Preview") ."\">\n";
} }
else if (!$edit[title]) { else if (!$story[title]) {
$output .= "<FONT COLOR=\"red\">". t("Warning: you did not supply a subject.") ."</FONT><P>\n"; $output .= "<FONT COLOR=\"red\">". t("Warning: you did not supply a subject.") ."</FONT><P>\n";
$output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Preview") ."\">\n"; $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Preview") ."\">\n";
} }
else if (!$edit[section]) { else if (!$story[section]) {
$output .= "<FONT COLOR=\"red\">". t("Warning: you did not supply a section.") ."</FONT><P>\n"; $output .= "<FONT COLOR=\"red\">". t("Warning: you did not supply a section.") ."</FONT><P>\n";
$output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Preview") ."\">\n"; $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Preview") ."\">\n";
} }
else if (!$edit[abstract]) { else if (!$story[abstract]) {
$output .= "<FONT COLOR=\"red\">". t("Warning: you did not supply an abstract.") ."</FONT><P>\n"; $output .= "<FONT COLOR=\"red\">". t("Warning: you did not supply an abstract.") ."</FONT><P>\n";
$output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Preview") ."\">\n"; $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Preview") ."\">\n";
} }
else if (!$edit[nid] && $duplicate) { else if (!$story[nid] && $duplicate) {
$output .= "<FONT COLOR=\"red\">". t("Warning: there is already a story with that subject.") ."</FONT><P>\n"; $output .= "<FONT COLOR=\"red\">". t("Warning: there is already a story with that subject.") ."</FONT><P>\n";
$output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Preview") ."\">\n"; $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"". t("Preview") ."\">\n";
} }
...@@ -170,8 +170,9 @@ function story_form($edit = array()) { ...@@ -170,8 +170,9 @@ function story_form($edit = array()) {
return $output; return $output;
} }
function story_save($edit) { function story_save($story, $category, $topic) {
node_save(array_diff(array_merge($edit, array(nid => $edit[nid], type => "story")), array(userid => $edit[userid]))); node_save(array_diff(array_merge($story, array(nid => $story[nid], type => "story")), array(userid => $story[userid])));
structure_save($category, $topic);
} }
function story_block() { function story_block() {
...@@ -215,7 +216,7 @@ function story_overview($query = array()) { ...@@ -215,7 +216,7 @@ function story_overview($query = array()) {
} }