- Renamed "form.admin" to "form admin".
- Added node_admin_settings() to let users set node defaults. * Added _nodeapi("conf") - Modified form_checkbox() to unset options. (Modified the patch from Ax.) - Removed the _save() hook. - Fixed a logical flaw in field_get() and field_set() which would break moderation. - Moved some admin menus around and cleaned up some typos.4.2.x
parent
3aba0fda70
commit
831ee21303
|
@ -723,7 +723,7 @@ function form_item($title, $value, $description = 0) {
|
|||
}
|
||||
|
||||
function form_checkbox($title, $name, $value = 1, $checked = 0, $description = 0) {
|
||||
return form_item(0, "<input type=\"checkbox\" name=\"edit[$name]\" value=\"". $value ."\"". ($checked ? " checked=\"checked\"" : "") ." /> $title", $description);
|
||||
return form_hidden($name, 0) . form_item(0, "<input type=\"checkbox\" name=\"edit[$name]\" value=\"". $value ."\"". ($checked ? " checked=\"checked\"" : "") ." /> $title", $description);
|
||||
}
|
||||
|
||||
function form_textfield($title, $name, $value, $size, $maxlength, $description = 0) {
|
||||
|
@ -819,7 +819,7 @@ function l($text, $url, $attributes = array(), $query = NULL) {
|
|||
}
|
||||
|
||||
function field_get($string, $name) {
|
||||
ereg(",$name=([^,]+)", ", $string", $regs);
|
||||
ereg(",?$name=([^,]+)", ", $string", $regs);
|
||||
return $regs[1];
|
||||
}
|
||||
|
||||
|
@ -839,7 +839,7 @@ function link_page() {
|
|||
}
|
||||
else {
|
||||
$links = module_invoke_all("link", "page");
|
||||
array_unshift($links, "<a href=\"$base_url\" title=\"". t("Return to the main page.") ."\">". t("home") ."</a>");
|
||||
array_unshift($links, "<a href=\"$base_url/\" title=\"". t("Return to the main page.") ."\">". t("home") ."</a>");
|
||||
return $links;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,50 +67,6 @@ function blog_user($type, &$edit, &$user) {
|
|||
}
|
||||
}
|
||||
|
||||
function blog_save($op, $node) {
|
||||
if ($op == "approve") {
|
||||
return array("promote" => 1);
|
||||
}
|
||||
|
||||
if ($op == "create") {
|
||||
if (user_access("administer nodes")) {
|
||||
/*
|
||||
** When an administrator creates blog entries through the admin
|
||||
** pages, they will not be changed unless explicitly specified.
|
||||
*/
|
||||
|
||||
return array("body" => filter($node->body), "teaser" => filter($node->teaser));
|
||||
}
|
||||
else {
|
||||
return array("body" => filter($node->body), "teaser" => filter($node->teaser), "promote" => 0, "moderate" => 1, "status" => 1);
|
||||
}
|
||||
}
|
||||
|
||||
if ($op == "decline") {
|
||||
return array("promote" => 0);
|
||||
}
|
||||
|
||||
if ($op == "update") {
|
||||
if (user_access("administer nodes")) {
|
||||
/*
|
||||
** When an administrator updates blog entries through the admin
|
||||
** pages, they will not be changed unless explicitly specified.
|
||||
*/
|
||||
|
||||
return array("body" => filter($node->body), "teaser" => filter($node->teaser));
|
||||
}
|
||||
else {
|
||||
/*
|
||||
** Updating your own blog entry will demote it (if promoted),
|
||||
** and will queue it in the moderation queue for promotion.
|
||||
*/
|
||||
|
||||
return array("body" => filter($node->body), "teaser" => filter($node->teaser), "promote" => 0, "moderate" => 1, "score" => 0, "votes" => 0, "users" => 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function blog_help() {
|
||||
?>
|
||||
<p>Drupal's blog module allows registered users to maintain an online blog, often referred to as an online journal or diary. They can be filled with daily thoughts, poetry, boneless blabber, spiritual theories, intimate details, valuable experiences, cynical rants, semi-coherent comments, writing experiments, artistic babblings, critics on current facts, fresh insights, diverse dreams, chronicles and mumbling madness available for public consumption. It is made up of individual entries that are timestamped and are typically viewed by day as you would a diary. Blogs often contain links to things you've seen, or agree/disagree with. A typical example of a long term blog can be seen at <a href="http://www.scripting.com/">http://www.scripting.com/</a>.</p>
|
||||
|
@ -296,4 +252,10 @@ function blog_block($op = "list", $delta = 0) {
|
|||
}
|
||||
}
|
||||
|
||||
function blog_validate(&$node) {
|
||||
// Make sure all fields are set properly:
|
||||
$node->body = filter($node->body);
|
||||
$node->teaser = filter($node->teaser);
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -67,50 +67,6 @@ function blog_user($type, &$edit, &$user) {
|
|||
}
|
||||
}
|
||||
|
||||
function blog_save($op, $node) {
|
||||
if ($op == "approve") {
|
||||
return array("promote" => 1);
|
||||
}
|
||||
|
||||
if ($op == "create") {
|
||||
if (user_access("administer nodes")) {
|
||||
/*
|
||||
** When an administrator creates blog entries through the admin
|
||||
** pages, they will not be changed unless explicitly specified.
|
||||
*/
|
||||
|
||||
return array("body" => filter($node->body), "teaser" => filter($node->teaser));
|
||||
}
|
||||
else {
|
||||
return array("body" => filter($node->body), "teaser" => filter($node->teaser), "promote" => 0, "moderate" => 1, "status" => 1);
|
||||
}
|
||||
}
|
||||
|
||||
if ($op == "decline") {
|
||||
return array("promote" => 0);
|
||||
}
|
||||
|
||||
if ($op == "update") {
|
||||
if (user_access("administer nodes")) {
|
||||
/*
|
||||
** When an administrator updates blog entries through the admin
|
||||
** pages, they will not be changed unless explicitly specified.
|
||||
*/
|
||||
|
||||
return array("body" => filter($node->body), "teaser" => filter($node->teaser));
|
||||
}
|
||||
else {
|
||||
/*
|
||||
** Updating your own blog entry will demote it (if promoted),
|
||||
** and will queue it in the moderation queue for promotion.
|
||||
*/
|
||||
|
||||
return array("body" => filter($node->body), "teaser" => filter($node->teaser), "promote" => 0, "moderate" => 1, "score" => 0, "votes" => 0, "users" => 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function blog_help() {
|
||||
?>
|
||||
<p>Drupal's blog module allows registered users to maintain an online blog, often referred to as an online journal or diary. They can be filled with daily thoughts, poetry, boneless blabber, spiritual theories, intimate details, valuable experiences, cynical rants, semi-coherent comments, writing experiments, artistic babblings, critics on current facts, fresh insights, diverse dreams, chronicles and mumbling madness available for public consumption. It is made up of individual entries that are timestamped and are typically viewed by day as you would a diary. Blogs often contain links to things you've seen, or agree/disagree with. A typical example of a long term blog can be seen at <a href="http://www.scripting.com/">http://www.scripting.com/</a>.</p>
|
||||
|
@ -296,4 +252,10 @@ function blog_block($op = "list", $delta = 0) {
|
|||
}
|
||||
}
|
||||
|
||||
function blog_validate(&$node) {
|
||||
// Make sure all fields are set properly:
|
||||
$node->body = filter($node->body);
|
||||
$node->teaser = filter($node->teaser);
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -57,48 +57,6 @@ function book_access($op, $node) {
|
|||
}
|
||||
}
|
||||
|
||||
function book_save($op, $node) {
|
||||
global $user;
|
||||
|
||||
if ($op == "approve") {
|
||||
return array("status" => 1);
|
||||
}
|
||||
|
||||
if ($op == "create") {
|
||||
if (user_access("administer nodes")) {
|
||||
return array("body" => filter($node->body), "teaser" => filter($node->body), "format", "parent", "weight", "log");
|
||||
}
|
||||
else {
|
||||
return array("body" => filter($node->body), "teaser" => filter($node->body), "format", "moderate" => 1, "parent", "promote" => 0, "status" => 1, "weight", "log");
|
||||
}
|
||||
}
|
||||
|
||||
if ($op == "decline") {
|
||||
return array("status" => 0);
|
||||
}
|
||||
|
||||
if ($op == "update") {
|
||||
if (user_access("administer nodes")) {
|
||||
/*
|
||||
** If a node administrator updates a book page, we don't create a
|
||||
** new revision unless we are explicitly instructed to.
|
||||
*/
|
||||
|
||||
return array("body" => filter($node->body), "teaser" => filter($node->body), "format", "parent", "weight", "log");
|
||||
}
|
||||
else {
|
||||
/*
|
||||
** If a regular user updates a book page, we always create a new
|
||||
** revision. All new revisions have to be approved (moderation)
|
||||
** and are not promoted by default. See also: book_load().
|
||||
*/
|
||||
|
||||
return array("body" => filter($node->body), "teaser" => filter($node->body), "created" => time(), "format", "moderate" => 1, "parent", "promote" => 0, "score" => 0, "status" => 1, "users" => "", "revisions", "votes" => 0, "weight", "log");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function book_link($type, $node = 0, $main = 0) {
|
||||
if ($type == "page" && user_access("access content")) {
|
||||
$links[] = l(t("collaborative book"), "book", array("title" => t("Read and contribute to the collaborative books.")));
|
||||
|
@ -166,20 +124,10 @@ function book_load($node) {
|
|||
}
|
||||
|
||||
function book_insert($node) {
|
||||
if (!user_access("administer nodes")) {
|
||||
$node->format = 0;
|
||||
$node->weight = 0;
|
||||
}
|
||||
|
||||
db_query("INSERT INTO book (nid, format, parent, weight, log) VALUES ('%d', '%d', '%d', '%d', '%s')", $node->nid, $node->format, $node->parent, $node->weight, $node->log);
|
||||
}
|
||||
|
||||
function book_update($node) {
|
||||
if (!user_access("administer nodes")) {
|
||||
$node->format = 0;
|
||||
$node->weight = 0;
|
||||
}
|
||||
|
||||
db_query("UPDATE book SET format = '%d', parent = '%d', weight = '%d', log = '%s' WHERE nid = '%d'", $node->format, $node->parent, $node->weight, $node->log, $node->nid);
|
||||
}
|
||||
|
||||
|
@ -187,12 +135,23 @@ function book_delete(&$node) {
|
|||
db_query("DELETE FROM book WHERE nid = '%d'", $node->nid);
|
||||
}
|
||||
|
||||
function book_validate($node, &$error) {
|
||||
function book_validate(&$node) {
|
||||
if ($node->format && user_access("create php content")) {
|
||||
// Do not filter PHP code, do not auto-extract a teaser
|
||||
$node->teaser = $node->body;
|
||||
}
|
||||
else {
|
||||
$node->format = 0;
|
||||
$node->body = filter($node->body);
|
||||
$node->teaser = filter($node->body);
|
||||
}
|
||||
|
||||
// Make sure user has permissions to create php content:
|
||||
$node->format = $node->format && user_access("create php content");
|
||||
|
||||
return $node;
|
||||
// Set default values for non administrators:
|
||||
if (!user_access("administer nodes")) {
|
||||
$node->format = 0;
|
||||
$node->weight = 0;
|
||||
$node->revision = 1;
|
||||
}
|
||||
}
|
||||
|
||||
function book_form(&$node, &$help, &$error) {
|
||||
|
|
|
@ -57,48 +57,6 @@ function book_access($op, $node) {
|
|||
}
|
||||
}
|
||||
|
||||
function book_save($op, $node) {
|
||||
global $user;
|
||||
|
||||
if ($op == "approve") {
|
||||
return array("status" => 1);
|
||||
}
|
||||
|
||||
if ($op == "create") {
|
||||
if (user_access("administer nodes")) {
|
||||
return array("body" => filter($node->body), "teaser" => filter($node->body), "format", "parent", "weight", "log");
|
||||
}
|
||||
else {
|
||||
return array("body" => filter($node->body), "teaser" => filter($node->body), "format", "moderate" => 1, "parent", "promote" => 0, "status" => 1, "weight", "log");
|
||||
}
|
||||
}
|
||||
|
||||
if ($op == "decline") {
|
||||
return array("status" => 0);
|
||||
}
|
||||
|
||||
if ($op == "update") {
|
||||
if (user_access("administer nodes")) {
|
||||
/*
|
||||
** If a node administrator updates a book page, we don't create a
|
||||
** new revision unless we are explicitly instructed to.
|
||||
*/
|
||||
|
||||
return array("body" => filter($node->body), "teaser" => filter($node->body), "format", "parent", "weight", "log");
|
||||
}
|
||||
else {
|
||||
/*
|
||||
** If a regular user updates a book page, we always create a new
|
||||
** revision. All new revisions have to be approved (moderation)
|
||||
** and are not promoted by default. See also: book_load().
|
||||
*/
|
||||
|
||||
return array("body" => filter($node->body), "teaser" => filter($node->body), "created" => time(), "format", "moderate" => 1, "parent", "promote" => 0, "score" => 0, "status" => 1, "users" => "", "revisions", "votes" => 0, "weight", "log");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function book_link($type, $node = 0, $main = 0) {
|
||||
if ($type == "page" && user_access("access content")) {
|
||||
$links[] = l(t("collaborative book"), "book", array("title" => t("Read and contribute to the collaborative books.")));
|
||||
|
@ -166,20 +124,10 @@ function book_load($node) {
|
|||
}
|
||||
|
||||
function book_insert($node) {
|
||||
if (!user_access("administer nodes")) {
|
||||
$node->format = 0;
|
||||
$node->weight = 0;
|
||||
}
|
||||
|
||||
db_query("INSERT INTO book (nid, format, parent, weight, log) VALUES ('%d', '%d', '%d', '%d', '%s')", $node->nid, $node->format, $node->parent, $node->weight, $node->log);
|
||||
}
|
||||
|
||||
function book_update($node) {
|
||||
if (!user_access("administer nodes")) {
|
||||
$node->format = 0;
|
||||
$node->weight = 0;
|
||||
}
|
||||
|
||||
db_query("UPDATE book SET format = '%d', parent = '%d', weight = '%d', log = '%s' WHERE nid = '%d'", $node->format, $node->parent, $node->weight, $node->log, $node->nid);
|
||||
}
|
||||
|
||||
|
@ -187,12 +135,23 @@ function book_delete(&$node) {
|
|||
db_query("DELETE FROM book WHERE nid = '%d'", $node->nid);
|
||||
}
|
||||
|
||||
function book_validate($node, &$error) {
|
||||
function book_validate(&$node) {
|
||||
if ($node->format && user_access("create php content")) {
|
||||
// Do not filter PHP code, do not auto-extract a teaser
|
||||
$node->teaser = $node->body;
|
||||
}
|
||||
else {
|
||||
$node->format = 0;
|
||||
$node->body = filter($node->body);
|
||||
$node->teaser = filter($node->body);
|
||||
}
|
||||
|
||||
// Make sure user has permissions to create php content:
|
||||
$node->format = $node->format && user_access("create php content");
|
||||
|
||||
return $node;
|
||||
// Set default values for non administrators:
|
||||
if (!user_access("administer nodes")) {
|
||||
$node->format = 0;
|
||||
$node->weight = 0;
|
||||
$node->revision = 1;
|
||||
}
|
||||
}
|
||||
|
||||
function book_form(&$node, &$help, &$error) {
|
||||
|
|
|
@ -671,7 +671,7 @@ function comment_link($type, $node = 0, $main = 0) {
|
|||
// comment settings:
|
||||
if (user_access("administer moderation")) {
|
||||
menu("admin/comment/votes", "comment moderation votes", "comment_admin", $help["settings"], 5);
|
||||
menu("admin/comment/matrix", "ccomment moderation matrix", "comment_admin", $help["settings"], 5);
|
||||
menu("admin/comment/matrix", "comment moderation matrix", "comment_admin", $help["settings"], 5);
|
||||
menu("admin/comment/filters", "comment moderation thresholds", "comment_admin", $help["settings"], 5);
|
||||
menu("admin/comment/roles", "initial comment scores", "comment_admin", $help["settings"], 5);
|
||||
}
|
||||
|
@ -1491,13 +1491,21 @@ function comment_update_index() {
|
|||
|
||||
function comment_nodeapi(&$node, $op, $arg = 0) {
|
||||
switch ($op) {
|
||||
case "form":
|
||||
if ($arg == "admin" && user_access("administer comments")) {
|
||||
return form_select(t("Allow user comments"), "comment", $node->comment, array(t("Disabled"), t("Read only"), t("Read-write")));
|
||||
}
|
||||
break;
|
||||
case "conf":
|
||||
$output[t("Comment")] = form_select("", "comment_$node->type", variable_get("comment_$node->type", 2), array("Disabled", "Read only", "Read/Write"));
|
||||
return $output;
|
||||
case "fields":
|
||||
return array("comment");
|
||||
case "form admin":
|
||||
if (user_access("administer comments")) {
|
||||
return form_select(t("Allow user comments"), "comment", isset($node->comment) ? $node->comment : variable_get("comment_$node->type", 2), array(t("Disabled"), t("Read only"), t("Read-write")));
|
||||
}
|
||||
break;
|
||||
case "validate":
|
||||
if (!user_access("administer nodes")) {
|
||||
unset($node->comment);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -671,7 +671,7 @@ function comment_link($type, $node = 0, $main = 0) {
|
|||
// comment settings:
|
||||
if (user_access("administer moderation")) {
|
||||
menu("admin/comment/votes", "comment moderation votes", "comment_admin", $help["settings"], 5);
|
||||
menu("admin/comment/matrix", "ccomment moderation matrix", "comment_admin", $help["settings"], 5);
|
||||
menu("admin/comment/matrix", "comment moderation matrix", "comment_admin", $help["settings"], 5);
|
||||
menu("admin/comment/filters", "comment moderation thresholds", "comment_admin", $help["settings"], 5);
|
||||
menu("admin/comment/roles", "initial comment scores", "comment_admin", $help["settings"], 5);
|
||||
}
|
||||
|
@ -1491,13 +1491,21 @@ function comment_update_index() {
|
|||
|
||||
function comment_nodeapi(&$node, $op, $arg = 0) {
|
||||
switch ($op) {
|
||||
case "form":
|
||||
if ($arg == "admin" && user_access("administer comments")) {
|
||||
return form_select(t("Allow user comments"), "comment", $node->comment, array(t("Disabled"), t("Read only"), t("Read-write")));
|
||||
}
|
||||
break;
|
||||
case "conf":
|
||||
$output[t("Comment")] = form_select("", "comment_$node->type", variable_get("comment_$node->type", 2), array("Disabled", "Read only", "Read/Write"));
|
||||
return $output;
|
||||
case "fields":
|
||||
return array("comment");
|
||||
case "form admin":
|
||||
if (user_access("administer comments")) {
|
||||
return form_select(t("Allow user comments"), "comment", isset($node->comment) ? $node->comment : variable_get("comment_$node->type", 2), array(t("Disabled"), t("Read only"), t("Read-write")));
|
||||
}
|
||||
break;
|
||||
case "validate":
|
||||
if (!user_access("administer nodes")) {
|
||||
unset($node->comment);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -69,24 +69,6 @@ function forum_taxonomy($op, $type, $object) {
|
|||
}
|
||||
}
|
||||
|
||||
function forum_save($op, $node) {
|
||||
if ($op == "approve") {
|
||||
return array("status" => 1);
|
||||
}
|
||||
|
||||
if ($op == "create") {
|
||||
return array("body" => filter($node->body), "teaser" => filter($node->teaser), "moderate" => 0, "status" => 1, "tid", "icon_num", "shadow" => 0);
|
||||
}
|
||||
|
||||
if ($op == "decline") {
|
||||
return array("status" => 0);
|
||||
}
|
||||
|
||||
if ($op == "update") {
|
||||
return array("body" => filter($node->body), "teaser" => filter($node->teaser), "tid", "icon_num", "shadow");
|
||||
}
|
||||
}
|
||||
|
||||
function forum_load($node) {
|
||||
$forum = db_fetch_object(db_query("SELECT * FROM forum WHERE nid = '%d'", $node->nid));
|
||||
|
||||
|
@ -185,13 +167,20 @@ function forum_view($node, $main = 0) {
|
|||
theme("node", $node, $main);
|
||||
}
|
||||
|
||||
function forum_validate($node) {
|
||||
// we use the validate hook to remember the old taxonomy terms
|
||||
$node->taxonomy = array_keys(taxonomy_node_get_terms($node->nid));
|
||||
if (!in_array($node->tid[0], $node->taxonomy)) {
|
||||
$node->taxonomy[] = $node->tid[0];
|
||||
function forum_validate(&$node) {
|
||||
// Make sure all fields are set properly:
|
||||
$node->body = filter($node->body);
|
||||
$node->teaser = filter($node->teaser);
|
||||
$node->icon = $node->icon ? $node->icon : "";
|
||||
$node->shadow = $node->shadow ? $node->shadow : 0;
|
||||
$node->tid = $node->tid ? $node->tid : 0;
|
||||
// We use the validate hook to remember the old taxonomy terms:
|
||||
if ($node->tid) {
|
||||
$node->taxonomy = array_keys(taxonomy_node_get_terms($node->nid));
|
||||
if (!in_array($node->tid[0], $node->taxonomy)) {
|
||||
$node->taxonomy[] = $node->tid[0];
|
||||
}
|
||||
}
|
||||
return $node;
|
||||
}
|
||||
|
||||
function forum_form(&$node, &$help, &$error) {
|
||||
|
|
|
@ -69,24 +69,6 @@ function forum_taxonomy($op, $type, $object) {
|
|||
}
|
||||
}
|
||||
|
||||
function forum_save($op, $node) {
|
||||
if ($op == "approve") {
|
||||
return array("status" => 1);
|
||||
}
|
||||
|
||||
if ($op == "create") {
|
||||
return array("body" => filter($node->body), "teaser" => filter($node->teaser), "moderate" => 0, "status" => 1, "tid", "icon_num", "shadow" => 0);
|
||||
}
|
||||
|
||||
if ($op == "decline") {
|
||||
return array("status" => 0);
|
||||
}
|
||||
|
||||
if ($op == "update") {
|
||||
return array("body" => filter($node->body), "teaser" => filter($node->teaser), "tid", "icon_num", "shadow");
|
||||
}
|
||||
}
|
||||
|
||||
function forum_load($node) {
|
||||
$forum = db_fetch_object(db_query("SELECT * FROM forum WHERE nid = '%d'", $node->nid));
|
||||
|
||||
|
@ -185,13 +167,20 @@ function forum_view($node, $main = 0) {
|
|||
theme("node", $node, $main);
|
||||
}
|
||||
|
||||
function forum_validate($node) {
|
||||
// we use the validate hook to remember the old taxonomy terms
|
||||
$node->taxonomy = array_keys(taxonomy_node_get_terms($node->nid));
|
||||
if (!in_array($node->tid[0], $node->taxonomy)) {
|
||||
$node->taxonomy[] = $node->tid[0];
|
||||
function forum_validate(&$node) {
|
||||
// Make sure all fields are set properly:
|
||||
$node->body = filter($node->body);
|
||||
$node->teaser = filter($node->teaser);
|
||||
$node->icon = $node->icon ? $node->icon : "";
|
||||
$node->shadow = $node->shadow ? $node->shadow : 0;
|
||||
$node->tid = $node->tid ? $node->tid : 0;
|
||||
// We use the validate hook to remember the old taxonomy terms:
|
||||
if ($node->tid) {
|
||||
$node->taxonomy = array_keys(taxonomy_node_get_terms($node->nid));
|
||||
if (!in_array($node->tid[0], $node->taxonomy)) {
|
||||
$node->taxonomy[] = $node->tid[0];
|
||||
}
|
||||
}
|
||||
return $node;
|
||||
}
|
||||
|
||||
function forum_form(&$node, &$help, &$error) {
|
||||
|
|
|
@ -115,15 +115,15 @@ function node_teaser($body) {
|
|||
return substr($body, 0, $size);
|
||||
}
|
||||
|
||||
function node_invoke($node, $name, $arg = 0) {
|
||||
function node_invoke(&$node, $hook, $arg = 0) {
|
||||
if (is_array($node)) {
|
||||
$function = $node["type"] ."_$name";
|
||||
$function = $node["type"] ."_$hook";
|
||||
}
|
||||
else if (is_object($node)) {
|
||||
$function = $node->type ."_$name";
|
||||
$function = $node->type ."_$hook";
|
||||
}
|
||||
else if (is_string($node)) {
|
||||
$function = $node ."_$name";
|
||||
$function = $node ."_$hook";
|
||||
}
|
||||
|
||||
if (function_exists($function)) {
|
||||
|
@ -131,10 +131,10 @@ function node_invoke($node, $name, $arg = 0) {
|
|||
}
|
||||
}
|
||||
|
||||
function node_invoke_all($hook, &$node, $op, $arg = 0) {
|
||||
function node_invoke_all(&$node, $hook, $op, $arg = 0) {
|
||||
$return = array();
|
||||
foreach (module_list() as $name) {
|
||||
if (module_hook($name, $hook)) {
|
||||
if ((module_hook($name, "node") || module_hook($name, "nodeapi")) && module_hook($name, $hook)) {
|
||||
$function = $name ."_". $hook;
|
||||
$result = $function($node, $op, $arg);
|
||||
if (isset($result)) {
|
||||
|
@ -183,32 +183,12 @@ function node_load($conditions) {
|
|||
return $node;
|
||||
}
|
||||
|
||||
function node_save($node, $filter) {
|
||||
function node_save($node) {
|
||||
|
||||
$fields = node_invoke_all("nodeapi", $node, "fields");
|
||||
|
||||
foreach ($filter as $key => $value) {
|
||||
/*
|
||||
** Only save those fields specified by the filter. If the filter
|
||||
** does not specify a default value, use the value of the $node's
|
||||
** corresponding field instead.
|
||||
*/
|
||||
|
||||
if (is_numeric($key)) {
|
||||
if (isset($node->$value)) {
|
||||
// The above check is mandatory.
|
||||
$edit->$value = $node->$value;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (isset($value)) {
|
||||
// The above check is mandatory.
|
||||
$edit->$key = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$node = $edit;
|
||||
/*
|
||||
** Fetch fields to save to node table:
|
||||
*/
|
||||
$fields = node_invoke_all($node, "nodeapi", "fields");
|
||||
|
||||
/*
|
||||
** Serialize the revisions field:
|
||||
|
@ -247,7 +227,8 @@ function node_save($node, $filter) {
|
|||
db_query("INSERT INTO node (". implode(", ", $k) .") VALUES (". implode(", ", $v) .")");
|
||||
|
||||
// Call the node specific callback (if any):
|
||||
module_invoke($node->type, "insert", $node);
|
||||
node_invoke($node, "insert");
|
||||
node_invoke_all($node, "nodeapi", "insert");
|
||||
}
|
||||
else {
|
||||
|
||||
|
@ -269,8 +250,8 @@ function node_save($node, $filter) {
|
|||
db_query("UPDATE node SET ". implode(", ", $q) ." WHERE nid = '$node->nid'");
|
||||
|
||||
// Call the node specific callback (if any):
|
||||
module_invoke($node->type, "update", $node);
|
||||
|
||||
node_invoke($node, "update");
|
||||
node_invoke_all($node, "nodeapi", "update");
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -471,10 +452,10 @@ function node_link($type, $node = 0, $main = 0) {
|
|||
menu("admin/node", "node management", "node_admin");
|
||||
menu("admin/node/nodes", "post overview");
|
||||
menu("admin/node/nodes/0", "new or updated posts", "node_admin", NULL, 0);
|
||||
menu("admin/node/nodes/1", "approval queue", "node_admin", NULL, 1);
|
||||
menu("admin/node/search", "search posts", "node_admin", $help["search"], 8);
|
||||
menu("admin/node/help", "help", "node_help", NULL, 9);
|
||||
menu("admin/node/edit", "edit node", "node_admin", NULL, 0, 1);
|
||||
menu("admin/node/settings", "content settings", "node_admin", NULL, 8);
|
||||
}
|
||||
|
||||
return $links ? $links : array();
|
||||
|
@ -540,6 +521,57 @@ function node_admin_nodes() {
|
|||
return table($header, $rows);
|
||||
}
|
||||
|
||||
/*
|
||||
**
|
||||
*/
|
||||
|
||||
function node_admin_settings($edit) {
|
||||
global $op;
|
||||
|
||||
if ($op == t("Save configuration")) {
|
||||
/*
|
||||
** Save the configuration options:
|
||||
*/
|
||||
|
||||
foreach ($edit as $name => $value) {
|
||||
variable_set($name, $value);
|
||||
}
|
||||
}
|
||||
|
||||
if ($op == t("Reset to defaults")) {
|
||||
/*
|
||||
** Reset the configuration options to their default value:
|
||||
*/
|
||||
|
||||
foreach ($edit as $name => $value) {
|
||||
variable_del($name);
|
||||
}
|
||||
}
|
||||
|
||||
$output = "<h3>" . t("Content settings") . "</h3>\n";
|
||||
|
||||
$output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">\n";
|
||||
$output .= "<tr><th>". t("Node") ."</th><th>\n";
|
||||
$output .= implode("</th><th>", array_keys(node_invoke_all($node, "nodeapi", "conf")));
|
||||
$output .= "</th></tr>\n";
|
||||
|
||||
foreach (module_list() as $name) {
|
||||
if (module_hook($name, "node")) {
|
||||
$node->type = $name;
|
||||
$output .= "<tr><td><p>$name</p></td><td align=\"center\">";
|
||||
$output .= implode("</td><td align=\"center\">", node_invoke_all($node, "nodeapi", "conf"));
|
||||
$output .= "</td></tr>\n";
|
||||
}
|
||||
}
|
||||
$output .= "</table><br />";
|
||||
|
||||
$output .= form_submit(t("Save configuration"));
|
||||
$output .= form_submit(t("Reset to defaults"));
|
||||
|
||||
return form($output);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the revision with the specified revision number.
|
||||
*/
|
||||
|
@ -681,6 +713,11 @@ function node_admin() {
|
|||
case t("Delete"):
|
||||
print node_delete($edit);
|
||||
break;
|
||||
case t("Save configuration"):
|
||||
case t("Reset to defaults"):
|
||||
case "settings":
|
||||
print node_admin_settings($edit);
|
||||
break;
|
||||
default:
|
||||
print node_admin_nodes();
|
||||
}
|
||||
|
@ -742,8 +779,8 @@ function node_feed($nodes = 0, $channel = array()) {
|
|||
}
|
||||
|
||||
function node_validate($node, &$error) {
|
||||
|
||||
global $user;
|
||||
$error = array();
|
||||
|
||||
/*
|
||||
** Convert the node to an object if necessary:
|
||||
|
@ -759,6 +796,18 @@ function node_validate($node, &$error) {
|
|||
$error["title"] = theme("theme_error", t("You have to specify a valid title."));
|
||||
}
|
||||
|
||||
/*
|
||||
** Common default values:
|
||||
*/
|
||||
|
||||
$node->teaser = node_teaser($node->body);
|
||||
|
||||
/*
|
||||
** Create a new revision when required:
|
||||
*/
|
||||
|
||||
$node = node_revision_create($node);
|
||||
|
||||
if (user_access("administer nodes")) {
|
||||
|
||||
/*
|
||||
|
@ -772,6 +821,10 @@ function node_validate($node, &$error) {
|
|||
if (!$node->date) {
|
||||
$node->date = date("M j, Y g:i a", $node->created);
|
||||
}
|
||||
|
||||
if (!is_numeric($node->status)) {
|
||||
$node->status = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
** Validate the "authored by"-field:
|
||||
|
@ -803,15 +856,20 @@ function node_validate($node, &$error) {
|
|||
$error["date"] = theme("theme_error", t("You have to specifiy a valid date."));
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Validate for normal users:
|
||||
$node->uid = $user->uid ? $user->uid : 0;
|
||||
$node->promote = 0;
|
||||
$node->status = 1;
|
||||
unset($node->static, $node->created);
|
||||
}
|
||||
|
||||
/*
|
||||
** Do node type specific validation checks.
|
||||
*/
|
||||
|
||||
$function = $node->type ."_validate";
|
||||
if (function_exists($function)) {
|
||||
$node = $function($node, $error);
|
||||
}
|
||||
$result = node_invoke($node, "validate");
|
||||
$error = $error + (is_array($result) ? $result : array()) + node_invoke_all($node, "nodeapi", "validate");
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
@ -835,6 +893,9 @@ function node_form($edit, $error = NULL) {
|
|||
$edit = node_validate($edit, $error);
|
||||
}
|
||||
|
||||
// Prepend extra node form:
|
||||
$form = implode("", node_invoke_all($edit, "nodeapi", "form.pre", $error));
|
||||
|
||||
/*
|
||||
** Get the node specific bits:
|
||||
*/
|
||||
|
@ -843,6 +904,9 @@ function node_form($edit, $error = NULL) {
|
|||
if (function_exists($function)) {
|
||||
$form .= $function($edit, $help, $error, $param);
|
||||
}
|
||||
|
||||
// Append extra node form:
|
||||
$form .= implode("", node_invoke_all($edit, "nodeapi", "form.post", $error));
|
||||
|
||||
/*
|
||||
** Add the help text:
|
||||
|
@ -913,11 +977,11 @@ function node_form($edit, $error = NULL) {
|
|||
$output .= form_textfield(t("Authored by"), "name", $edit->name, 20, 60, $error["name"]);
|
||||
$output .= form_textfield(t("Authored on"), "date", $edit->date, 20, 25, $error["date"]);
|
||||
$output .= "<br />";
|
||||
$output .= form_select(t("Set public/published"), "status", $edit->status, array(t("Disabled"), t("Enabled")));
|
||||
$output .= form_select(t("Promote to front page"), "promote", $edit->promote, array(t("Disabled"), t("Enabled")));
|
||||
$output .= form_select(t("Static on front page"), "static", $edit->static, array(t("Disabled"), t("Enabled")));
|
||||
$output .= implode("", node_invoke_all("nodeapi", $edit, "form", "admin"));
|
||||
$output .= form_select(t("Create new revision"), "revision", $edit->revision, array(t("Disabled"), t("Enabled")));
|
||||
$output .= form_select(t("Set public/published"), "status", isset($edit->status) ? $edit->status : variable_get("node_status_$edit->type", 1), array(t("Disabled"), t("Enabled")));
|
||||
$output .= form_select(t("Promote to front page"), "promote", isset($edit->promote) ? $edit->promote : variable_get("node_promote_$edit->type", 1), array(t("Disabled"), t("Enabled")));
|
||||
$output .= form_select(t("Static on front page"), "static", isset($edit->static) ? $edit->static : variable_get("node_static_$edit->type", 0), array(t("Disabled"), t("Enabled")));
|
||||
$output .= implode("", node_invoke_all($edit, "nodeapi", "form admin"));
|
||||
$output .= form_select(t("Create new revision"), "revision", isset($edit->revision) ? $edit->revision : variable_get("node_revision_$edit->type", 0), array(t("Disabled"), t("Enabled")));
|
||||
}
|
||||
|
||||
$output .= " </td>";
|
||||
|
@ -937,7 +1001,8 @@ function node_add($type) {
|
|||
|
||||
if ($type && node_access("create", $type)) {
|
||||
// Initialize settings
|
||||
$node = array("uid" => $user->uid, "name" => $user->name, "type" => $type, "status" => 1, "promote" => !module_exist("queue"), "moderate" => module_exist("queue"), "comment" => 2);
|
||||
// TODO : clean up this code.
|
||||
$node = array("uid" => $user->uid, "name" => $user->name, "type" => $type);
|
||||
foreach (array("title", "teaser", "body") as $field) {
|
||||
if ($edit[$field]) {
|
||||
$node[$field] = check_input($edit[$field]);
|
||||
|
@ -1075,12 +1140,6 @@ function node_submit($node) {
|
|||
return node_preview($node, $error);
|
||||
}
|
||||
|
||||
/*
|
||||
** Create a new revision when required:
|
||||
*/
|
||||
|
||||
$node = node_revision_create($node);
|
||||
|
||||
/*
|
||||
** Prepare the node's body:
|
||||
*/
|
||||
|
@ -1093,20 +1152,7 @@ function node_submit($node) {
|
|||
*/
|
||||
|
||||
if (node_access("update", $node)) {
|
||||
|
||||
/*
|
||||
** Compile a list of the node fields and their default values that users
|
||||
** and administrators are allowed to save when updating a node.
|
||||
*/
|
||||
|
||||
if (user_access("administer nodes")) {
|
||||
$fields = array("nid", "uid", "body", "comment", "created", "promote", "static", "moderate", "revisions", "status", "teaser" => node_teaser($node->body), "title", "type" => $node->type);
|
||||
}
|
||||
else {
|
||||
$fields = array("nid", "uid" => ($user->uid ? $user->uid : 0), "body", "teaser" => node_teaser($node->body), "title", "type" => $node->type);
|
||||
}
|
||||
|
||||
$nid = node_save($node, array_merge($fields, module_invoke($node->type, "save", "update", $node)));
|
||||
$nid = node_save($node);
|
||||
|
||||
/*
|
||||
** Update terms of the node
|
||||
|
@ -1136,19 +1182,7 @@ function node_submit($node) {
|
|||
|
||||
throttle("node", variable_get("max_node_rate", 900));
|
||||
|
||||
/*
|
||||
** Compile a list of the node fields and their default values that users
|
||||
** and administrators are allowed to save when inserting a new node.
|
||||
*/
|
||||
|
||||
if (user_access("administer nodes")) {
|
||||
$fields = array("uid", "body", "comment", "created", "promote", "static", "moderate", "status", "teaser" => node_teaser($node->body), "title", "type" => $node->type);
|
||||
}
|
||||
else {
|
||||
$fields = array("uid" => ($user->uid ? $user->uid : 0), "body", "comment" => 2, "teaser" => node_teaser($node->body), "title", "type" => $node->type);
|
||||
}
|
||||
|
||||
$nid = node_save($node, array_merge($fields, module_invoke($node->type, "save", "create", $node)));
|
||||
$nid = node_save($node);
|
||||
|
||||
/*
|
||||
** Insert terms of the node
|
||||
|
@ -1222,7 +1256,8 @@ function node_delete($edit) {
|
|||
** Call the node specific callback (if any):
|
||||
*/
|
||||
|
||||
module_invoke($node->type, "delete", $node);
|
||||
node_invoke($node, "delete");
|
||||
node_invoke_all($node, "nodeapi", "delete");
|
||||
|
||||
watchdog("special", "$node->type: deleted '$node->title'");
|
||||
$output = t("The node has been deleted.");
|
||||
|
@ -1311,8 +1346,14 @@ function node_update_index() {
|
|||
|
||||
function node_nodeapi(&$node, $op, $arg = 0) {
|
||||
switch ($op) {
|
||||
case "conf":
|
||||
$output[t("Publish")] = form_checkbox("", "node_status_$node->type", 1, variable_get("node_status_$node->type", 1));
|
||||
$output[t("Promote")] = form_checkbox("", "node_promote_$node->type", 1, variable_get("node_promote_$node->type", 1));
|
||||
$output[t("Static")] = form_checkbox("", "node_static_$node->type", 1, variable_get("node_static_$node->type", 0));
|
||||
$output[t("Revision")] = form_checkbox("", "node_revision_$node->type", 1, variable_get("node_revision_$node->type", 0));
|
||||
return $output;
|
||||
case "fields":
|
||||
return array("nid", "uid", "type", "title", "teaser", "body", "revisions", "score", "status", "promote", "static", "created", "changed", "users", "votes");
|
||||
return array("nid", "uid", "type", "title", "teaser", "body", "revisions", "status", "promote", "static", "created", "changed");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -115,15 +115,15 @@ function node_teaser($body) {
|
|||
return substr($body, 0, $size);
|
||||
}
|
||||
|
||||
function node_invoke($node, $name, $arg = 0) {
|
||||
function node_invoke(&$node, $hook, $arg = 0) {
|
||||
if (is_array($node)) {
|
||||
$function = $node["type"] ."_$name";
|
||||
$function = $node["type"] ."_$hook";
|
||||
}
|
||||
else if (is_object($node)) {
|
||||
$function = $node->type ."_$name";
|
||||
$function = $node->type ."_$hook";
|
||||
}
|
||||
else if (is_string($node)) {
|
||||
$function = $node ."_$name";
|
||||
$function = $node ."_$hook";
|
||||
}
|
||||
|
||||
if (function_exists($function)) {
|
||||
|
@ -131,10 +131,10 @@ function node_invoke($node, $name, $arg = 0) {
|
|||
}
|
||||
}
|
||||
|
||||
function node_invoke_all($hook, &$node, $op, $arg = 0) {
|
||||
function node_invoke_all(&$node, $hook, $op, $arg = 0) {
|
||||
$return = array();
|
||||
foreach (module_list() as $name) {
|
||||
if (module_hook($name, $hook)) {
|
||||
if ((module_hook($name, "node") || module_hook($name, "nodeapi")) && module_hook($name, $hook)) {
|
||||
$function = $name ."_". $hook;
|
||||
$result = $function($node, $op, $arg);
|
||||
if (isset($result)) {
|
||||
|
@ -183,32 +183,12 @@ function node_load($conditions) {
|
|||
return $node;
|
||||
}
|
||||
|
||||
function node_save($node, $filter) {
|
||||
function node_save($node) {
|
||||
|
||||
$fields = node_invoke_all("nodeapi", $node, "fields");
|
||||
|
||||
foreach ($filter as $key => $value) {
|
||||
/*
|
||||
** Only save those fields specified by the filter. If the filter
|
||||
** does not specify a default value, use the value of the $node's
|
||||
** corresponding field instead.
|
||||
*/
|
||||
|
||||
if (is_numeric($key)) {
|
||||
if (isset($node->$value)) {
|
||||
// The above check is mandatory.
|
||||
$edit->$value = $node->$value;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (isset($value)) {
|
||||
// The above check is mandatory.
|
||||
$edit->$key = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$node = $edit;
|
||||
/*
|
||||
** Fetch fields to save to node table:
|
||||
*/
|
||||
$fields = node_invoke_all($node, "nodeapi", "fields");
|
||||
|
||||
/*
|
||||
** Serialize the revisions field:
|
||||
|
@ -247,7 +227,8 @@ function node_save($node, $filter) {
|
|||
db_query("INSERT INTO node (". implode(", ", $k) .") VALUES (". implode(", ", $v) .")");
|
||||
|
||||
// Call the node specific callback (if any):
|
||||
module_invoke($node->type, "insert", $node);
|
||||
node_invoke($node, "insert");
|
||||
node_invoke_all($node, "nodeapi", "insert");
|
||||
}
|
||||
else {
|
||||
|
||||
|
@ -269,8 +250,8 @@ function node_save($node, $filter) {
|
|||
db_query("UPDATE node SET ". implode(", ", $q) ." WHERE nid = '$node->nid'");
|
||||
|
||||
// Call the node specific callback (if any):
|
||||
module_invoke($node->type, "update", $node);
|
||||
|
||||
node_invoke($node, "update");
|
||||
node_invoke_all($node, "nodeapi", "update");
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -471,10 +452,10 @@ function node_link($type, $node = 0, $main = 0) {
|
|||
menu("admin/node", "node management", "node_admin");
|
||||
menu("admin/node/nodes", "post overview");
|
||||
menu("admin/node/nodes/0", "new or updated posts", "node_admin", NULL, 0);
|
||||
menu("admin/node/nodes/1", "approval queue", "node_admin", NULL, 1);
|
||||
menu("admin/node/search", "search posts", "node_admin", $help["search"], 8);
|
||||
menu("admin/node/help", "help", "node_help", NULL, 9);
|
||||
menu("admin/node/edit", "edit node", "node_admin", NULL, 0, 1);
|
||||
menu("admin/node/settings", "content settings", "node_admin", NULL, 8);
|
||||
}
|
||||
|
||||
return $links ? $links : array();
|
||||
|
@ -540,6 +521,57 @@ function node_admin_nodes() {
|
|||
return table($header, $rows);
|
||||
}
|
||||
|
||||
/*
|
||||
**
|
||||
*/
|
||||
|
||||
function node_admin_settings($edit) {
|
||||
global $op;
|
||||
|
||||
if ($op == t("Save configuration")) {
|
||||
/*
|
||||
** Save the configuration options:
|
||||
*/
|
||||
|
||||
foreach ($edit as $name => $value) {
|
||||
variable_set($name, $value);
|
||||
}
|
||||
}
|
||||
|
||||
if ($op == t("Reset to defaults")) {
|
||||
/*
|
||||
** Reset the configuration options to their default value:
|
||||
*/
|
||||
|
||||
foreach ($edit as $name => $value) {
|
||||
variable_del($name);
|
||||
}
|
||||
}
|
||||
|
||||
$output = "<h3>" . t("Content settings") . "</h3>\n";
|
||||
|
||||
$output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">\n";
|
||||
$output .= "<tr><th>". t("Node") ."</th><th>\n";
|
||||
$output .= implode("</th><th>", array_keys(node_invoke_all($node, "nodeapi", "conf")));
|
||||
$output .= "</th></tr>\n";
|
||||
|
||||
foreach (module_list() as $name) {
|
||||
if (module_hook($name, "node")) {
|
||||
$node->type = $name;
|
||||
$output .= "<tr><td><p>$name</p></td><td align=\"center\">";
|
||||
$output .= implode("</td><td align=\"center\">", node_invoke_all($node, "nodeapi", "conf"));
|
||||
$output .= "</td></tr>\n";
|
||||
}
|
||||
}
|
||||
$output .= "</table><br />";
|
||||
|
||||
$output .= form_submit(t("Save configuration"));
|
||||
$output .= form_submit(t("Reset to defaults"));
|
||||
|
||||
return form($output);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the revision with the specified revision number.
|
||||
*/
|
||||
|
@ -681,6 +713,11 @@ function node_admin() {
|
|||
case t("Delete"):
|
||||
print node_delete($edit);
|
||||
break;
|
||||
case t("Save configuration"):
|
||||
case t("Reset to defaults"):
|
||||
case "settings":
|
||||
print node_admin_settings($edit);
|
||||
break;
|
||||
default:
|
||||
print node_admin_nodes();
|
||||
}
|
||||
|
@ -742,8 +779,8 @@ function node_feed($nodes = 0, $channel = array()) {
|
|||
}
|
||||
|
||||
function node_validate($node, &$error) {
|
||||
|
||||
global $user;
|
||||
$error = array();
|
||||
|
||||
/*
|
||||
** Convert the node to an object if necessary:
|
||||
|
@ -759,6 +796,18 @@ function node_validate($node, &$error) {
|
|||
$error["title"] = theme("theme_error", t("You have to specify a valid title."));
|
||||
}
|
||||
|
||||
/*
|
||||
** Common default values:
|
||||
*/
|
||||
|
||||
$node->teaser = node_teaser($node->body);
|
||||
|
||||
/*
|
||||
** Create a new revision when required:
|
||||
*/
|
||||
|
||||
$node = node_revision_create($node);
|
||||
|
||||
if (user_access("administer nodes")) {
|
||||
|
||||
/*
|
||||
|
@ -772,6 +821,10 @@ function node_validate($node, &$error) {
|
|||
if (!$node->date) {
|
||||
$node->date = date("M j, Y g:i a", $node->created);
|
||||
}
|
||||
|
||||
if (!is_numeric($node->status)) {
|
||||
$node->status = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
** Validate the "authored by"-field:
|
||||
|
@ -803,15 +856,20 @@ function node_validate($node, &$error) {
|
|||
$error["date"] = theme("theme_error", t("You have to specifiy a valid date."));
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Validate for normal users:
|
||||
$node->uid = $user->uid ? $user->uid : 0;
|
||||
$node->promote = 0;
|
||||
$node->status = 1;
|
||||
unset($node->static, $node->created);
|
||||
}
|
||||
|
||||
/*
|
||||
** Do node type specific validation checks.
|
||||
*/
|
||||
|
||||
$function = $node->type ."_validate";
|
||||
if (function_exists($function)) {
|
||||
$node = $function($node, $error);
|
||||
}
|
||||
$result = node_invoke($node, "validate");
|
||||
$error = $error + (is_array($result) ? $result : array()) + node_invoke_all($node, "nodeapi", "validate");
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
@ -835,6 +893,9 @@ function node_form($edit, $error = NULL) {
|
|||
$edit = node_validate($edit, $error);
|
||||
}
|
||||
|
||||
// Prepend extra node form:
|
||||
$form = implode("", node_invoke_all($edit, "nodeapi", "form.pre", $error));
|
||||
|
||||
/*
|
||||
** Get the node specific bits:
|
||||
*/
|
||||
|
@ -843,6 +904,9 @@ function node_form($edit, $error = NULL) {
|
|||
if (function_exists($function)) {
|
||||
$form .= $function($edit, $help, $error, $param);
|
||||
}
|
||||
|
||||
// Append extra node form:
|
||||
$form .= implode("", node_invoke_all($edit, "nodeapi", "form.post", $error));
|
||||
|
||||
/*
|
||||
** Add the help text:
|
||||
|
@ -913,11 +977,11 @@ function node_form($edit, $error = NULL) {
|
|||
$output .= form_textfield(t("Authored by"), "name", $edit->name, 20, 60, $error["name"]);
|
||||
$output .= form_textfield(t("Authored on"), "date", $edit->date, 20, 25, $error["date"]);
|
||||
$output .= "<br />";
|
||||
$output .= form_select(t("Set public/published"), "status", $edit->status, array(t("Disabled"), t("Enabled")));
|
||||
$output .= form_select(t("Promote to front page"), "promote", $edit->promote, array(t("Disabled"), t("Enabled")));
|
||||
$output .= form_select(t("Static on front page"), "static", $edit->static, array(t("Disabled"), t("Enabled")));
|
||||
$output .= implode("", node_invoke_all("nodeapi", $edit, "form", "admin"));
|
||||
$output .= form_select(t("Create new revision"), "revision", $edit->revision, array(t("Disabled"), t("Enabled")));
|
||||
$output .= form_select(t("Set public/published"), "status", isset($edit->status) ? $edit->status : variable_get("node_status_$edit->type", 1), array(t("Disabled"), t("Enabled")));
|
||||
$output .= form_select(t("Promote to front page"), "promote", isset($edit->promote) ? $edit->promote : variable_get("node_promote_$edit->type", 1), array(t("Disabled"), t("Enabled")));
|
||||
$output .= form_select(t("Static on front page"), "static", isset($edit->static) ? $edit->static : variable_get("node_static_$edit->type", 0), array(t("Disabled"), t("Enabled")));
|
||||
$output .= implode("", node_invoke_all($edit, "nodeapi", "form admin"));
|
||||
$output .= form_select(t("Create new revision"), "revision", isset($edit->revision) ? $edit->revision : variable_get("node_revision_$edit->type", 0), array(t("Disabled"), t("Enabled")));
|
||||
}
|
||||
|
||||
$output .= " </td>";
|
||||
|
@ -937,7 +1001,8 @@ function node_add($type) {
|
|||
|
||||
if ($type && node_access("create", $type)) {
|
||||
// Initialize settings
|
||||
$node = array("uid" => $user->uid, "name" => $user->name, "type" => $type, "status" => 1, "promote" => !module_exist("queue"), "moderate" => module_exist("queue"), "comment" => 2);
|
||||
// TODO : clean up this code.
|
||||
$node = array("uid" => $user->uid, "name" => $user->name, "type" => $type);
|
||||
foreach (array("title", "teaser", "body") as $field) {
|
||||
if ($edit[$field]) {
|
||||
$node[$field] = check_input($edit[$field]);
|
||||
|
@ -1075,12 +1140,6 @@ function node_submit($node) {
|
|||
return node_preview($node, $error);
|
||||
}
|
||||
|
||||
/*
|
||||
** Create a new revision when required:
|
||||
*/
|
||||
|
||||
$node = node_revision_create($node);
|
||||
|
||||
/*
|
||||
** Prepare the node's body:
|
||||
*/
|
||||
|
@ -1093,20 +1152,7 @@ function node_submit($node) {
|
|||
*/
|
||||
|
||||
if (node_access("update", $node)) {
|
||||
|
||||
/*
|
||||
** Compile a list of the node fields and their default values that users
|
||||
** and administrators are allowed to save when updating a node.
|
||||
*/
|
||||
|
||||
if (user_access("administer nodes")) {
|
||||
$fields = array("nid", "uid", "body", "comment", "created", "promote", "static", "moderate", "revisions", "status", "teaser" => node_teaser($node->body), "title", "type" => $node->type);
|
||||
}
|
||||
else {
|
||||
$fields = array("nid", "uid" => ($user->uid ? $user->uid : 0), "body", "teaser" => node_teaser($node->body), "title", "type" => $node->type);
|
||||
}
|
||||
|
||||
$nid = node_save($node, array_merge($fields, module_invoke($node->type, "save", "update", $node)));
|
||||
$nid = node_save($node);
|
||||
|
||||
/*
|
||||
** Update terms of the node
|
||||
|
@ -1136,19 +1182,7 @@ function node_submit($node) {
|
|||
|
||||
throttle("node", variable_get("max_node_rate", 900));
|
||||
|
||||
/*
|
||||
** Compile a list of the node fields and their default values that users
|
||||
** and administrators are allowed to save when inserting a new node.
|
||||
*/
|
||||
|
||||
if (user_access("administer nodes")) {
|
||||
$fields = array("uid", "body", "comment", "created", "promote", "static", "moderate", "status", "teaser" => node_teaser($node->body), "title", "type" => $node->type);
|
||||
}
|
||||
else {
|
||||
$fields = array("uid" => ($user->uid ? $user->uid : 0), "body", "comment" => 2, "teaser" => node_teaser($node->body), "title", "type" => $node->type);
|
||||
}
|
||||
|
||||
$nid = node_save($node, array_merge($fields, module_invoke($node->type, "save", "create", $node)));
|
||||
$nid = node_save($node);
|
||||
|
||||
/*
|
||||
** Insert terms of the node
|
||||
|
@ -1222,7 +1256,8 @@ function node_delete($edit) {
|
|||
** Call the node specific callback (if any):
|
||||
*/
|
||||
|
||||
module_invoke($node->type, "delete", $node);
|
||||
node_invoke($node, "delete");
|
||||
node_invoke_all($node, "nodeapi", "delete");
|
||||
|
||||
watchdog("special", "$node->type: deleted '$node->title'");
|
||||
$output = t("The node has been deleted.");
|
||||
|
@ -1311,8 +1346,14 @@ function node_update_index() {
|
|||
|
||||
function node_nodeapi(&$node, $op, $arg = 0) {
|
||||
switch ($op) {
|
||||
case "conf":
|
||||
$output[t("Publish")] = form_checkbox("", "node_status_$node->type", 1, variable_get("node_status_$node->type", 1));
|
||||
$output[t("Promote")] = form_checkbox("", "node_promote_$node->type", 1, variable_get("node_promote_$node->type", 1));
|
||||
$output[t("Static")] = form_checkbox("", "node_static_$node->type", 1, variable_get("node_static_$node->type", 0));
|
||||
$output[t("Revision")] = form_checkbox("", "node_revision_$node->type", 1, variable_get("node_revision_$node->type", 0));
|
||||
return $output;
|
||||
case "fields":
|
||||
return array("nid", "uid", "type", "title", "teaser", "body", "revisions", "score", "status", "promote", "static", "created", "changed", "users", "votes");
|
||||
return array("nid", "uid", "type", "title", "teaser", "body", "revisions", "status", "promote", "static", "created", "changed");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,32 +43,13 @@ function page_access($op, $node) {
|
|||
}
|
||||
|
||||
function page_save($op, $node) {
|
||||
|
||||
if ($op == "approve") {
|
||||
return array("status" => 1);
|
||||
}
|
||||
|
||||
if ($op == "create") {
|
||||
if ($node->format) { // do not filter PHP code, do not auto-extract a teaser
|
||||
return array("teaser" => $node->body, "format", "link", "description");
|
||||
}
|
||||
else {
|
||||
return array("body" => filter($node->body), "teaser" => filter($node->teaser), "format", "link", "description");
|
||||
}
|
||||
}
|
||||
|
||||
if ($op == "decline") {
|
||||
return array("status" => 0);
|
||||
}
|
||||
|
||||
if ($op == "update") {
|
||||
if ($node->format) { // do not filter PHP code, do not auto-extract a teaser
|
||||
return array("teaser" => $node->body, "format", "link", "description");
|
||||
}
|
||||
else {
|
||||
return array("body" => filter($node->body), "teaser" => filter($node->teaser), "format", "link", "description");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function page_insert($node) {
|
||||
|
@ -156,4 +137,16 @@ function page_form(&$node, &$help, &$error) {
|
|||
return $output;
|
||||
}
|
||||
|
||||
function page_validate(&$node) {
|
||||
if ($node->format && user_access("create php content")) {
|
||||
// Do not filter PHP code, do not auto-extract a teaser
|
||||
$node->teaser = $node->body;
|
||||
}
|
||||
else {
|
||||
$node->format = 0;
|
||||
$node->body = filter($node->body);
|
||||
$node->teaser = filter($node->body);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -43,32 +43,13 @@ function page_access($op, $node) {
|
|||
}
|
||||
|
||||
function page_save($op, $node) {
|
||||
|
||||
if ($op == "approve") {
|
||||
return array("status" => 1);
|
||||
}
|
||||
|
||||
if ($op == "create") {
|
||||
if ($node->format) { // do not filter PHP code, do not auto-extract a teaser
|
||||
return array("teaser" => $node->body, "format", "link", "description");
|
||||
}
|
||||
else {
|
||||
return array("body" => filter($node->body), "teaser" => filter($node->teaser), "format", "link", "description");
|
||||
}
|
||||
}
|
||||
|
||||
if ($op == "decline") {
|
||||
return array("status" => 0);
|
||||
}
|
||||
|
||||
if ($op == "update") {
|
||||
if ($node->format) { // do not filter PHP code, do not auto-extract a teaser
|
||||
return array("teaser" => $node->body, "format", "link", "description");
|
||||
}
|
||||
else {
|
||||
return array("body" => filter($node->body), "teaser" => filter($node->teaser), "format", "link", "description");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function page_insert($node) {
|
||||
|
@ -156,4 +137,16 @@ function page_form(&$node, &$help, &$error) {
|
|||
return $output;
|
||||
}
|
||||
|
||||
function page_validate(&$node) {
|
||||
if ($node->format && user_access("create php content")) {
|
||||
// Do not filter PHP code, do not auto-extract a teaser
|
||||
$node->teaser = $node->body;
|
||||
}
|
||||
else {
|
||||
$node->format = 0;
|
||||
$node->body = filter($node->body);
|
||||
$node->teaser = filter($node->body);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -232,29 +232,6 @@ function poll_perm() {
|
|||
return array("create polls", "vote on polls");
|
||||
}
|
||||
|
||||
function poll_save($op, $node) {
|
||||
if ($op == "approve") {
|
||||
return array("status" => 1, "promote" => 1);
|
||||
}
|
||||
|
||||
if ($op == "create") {
|
||||
if (user_access("administer nodes")) {
|
||||
return array("runtime", "active", "choice", "choices", "chvotes", "body" => "", "moderate" => 0, "status" => 1, "teaser" => poll_teaser($node));
|
||||
}
|
||||
else {
|
||||
return array("runtime", "active", "choice", "choices", "chvotes", "body" => "", "moderate" => 1, "status" => 0, "teaser" => poll_teaser($node));
|
||||
}
|
||||
}
|
||||
|
||||
if ($op == "decline") {
|
||||
return array("status" => 0, "promote" => 0);
|
||||
}
|
||||
|
||||
if ($op == "update") {
|
||||
return array("runtime", "active", "choice", "choices", "chvotes");
|
||||
}
|
||||
}
|
||||
|
||||
function poll_system($field){
|
||||
$system["description"] = t("Enables your site to capture votes on different topics in the form of multiple choice questions.");
|
||||
return $system[$field];
|
||||
|
@ -413,4 +390,8 @@ function poll_update($node) {
|
|||
}
|
||||
}
|
||||
|
||||
function poll_validate(&$node) {
|
||||
$node ->teaser = poll_teaser($node);
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -232,29 +232,6 @@ function poll_perm() {
|
|||
return array("create polls", "vote on polls");
|
||||
}
|
||||
|
||||
function poll_save($op, $node) {
|
||||
if ($op == "approve") {
|
||||
return array("status" => 1, "promote" => 1);
|
||||
}
|
||||
|
||||
if ($op == "create") {
|
||||
if (user_access("administer nodes")) {
|
||||
return array("runtime", "active", "choice", "choices", "chvotes", "body" => "", "moderate" => 0, "status" => 1, "teaser" => poll_teaser($node));
|
||||
}
|
||||
else {
|
||||
return array("runtime", "active", "choice", "choices", "chvotes", "body" => "", "moderate" => 1, "status" => 0, "teaser" => poll_teaser($node));
|
||||
}
|
||||
}
|
||||
|
||||
if ($op == "decline") {
|
||||
return array("status" => 0, "promote" => 0);
|
||||
}
|
||||
|
||||
if ($op == "update") {
|
||||
return array("runtime", "active", "choice", "choices", "chvotes");
|
||||
}
|
||||
}
|
||||
|
||||
function poll_system($field){
|
||||
$system["description"] = t("Enables your site to capture votes on different topics in the form of multiple choice questions.");
|
||||
return $system[$field];
|
||||
|
@ -413,4 +390,8 @@ function poll_update($node) {
|
|||
}
|
||||
}
|
||||
|
||||
function poll_validate(&$node) {
|
||||
$node ->teaser = poll_teaser($node);
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -28,6 +28,10 @@ function queue_link($type) {
|
|||
$links[] = l(t("view submissions"), "queue", array("title" => t("Moderate the content in the submission queue."))) ." (<span style=\"color: red;\">". queue_count() ."</span>)";
|
||||
}
|
||||
|
||||
if ($type == "admin" && user_access("administer nodes")) {
|
||||
menu("admin/node/nodes/1", "approval queue", "node_admin", NULL, 1);
|
||||
}
|
||||
|
||||
return $links ? $links : array();
|
||||
}
|
||||
|
||||
|
@ -45,7 +49,6 @@ function queue_vote($node, $vote) {
|
|||
global $user;
|
||||
|
||||
if (!field_get($node->users, $user->uid)) {
|
||||
|
||||
// Update submission's score- and votes-field:
|
||||
db_query("UPDATE node SET score = score $vote, votes = votes + 1, users = '". field_set($node->users, $user->uid, $vote) ."' WHERE nid = '$node->nid'");
|
||||
|
||||
|
@ -53,7 +56,9 @@ function queue_vote($node, $vote) {
|
|||
$node = node_load(array("nid" => $node->nid));
|
||||
|
||||
if (variable_get("queue_threshold_post", 3) <= $node->score) {
|
||||
node_save($node, array_merge(array("nid", "moderate" => 0), module_invoke($node->type, "save", "approve", $node)));
|
||||
$node->moderate = 0;
|
||||
$node->promote = 1;
|
||||
node_save($node);
|
||||
watchdog("special", "moderation: approved '$node->title'");
|
||||
}
|
||||
else if (variable_get("queue_threshold_dump", -2) >= $node->score) {
|
||||
|
@ -62,7 +67,9 @@ function queue_vote($node, $vote) {
|
|||
watchdog("special", "moderation: declined '$node->title' (rollback)");
|
||||
}
|
||||
else {
|
||||
node_save($node, array_merge(array("nid", "moderate" => 0), module_invoke($node->type, "save", "decline", $node)));
|
||||
$node->moderate = 0;
|
||||
$node->status = 0;
|
||||
node_save($node);
|
||||
watchdog("special", "moderation: declined '$node->title'");
|
||||
}
|
||||
}
|
||||
|
@ -72,7 +79,9 @@ function queue_vote($node, $vote) {
|
|||
watchdog("special", "moderation: expired '$node->title' (rollback)");
|
||||
}
|
||||
else {
|
||||
node_save($node, array_merge(array("nid", "moderate" => 0), module_invoke($node->type, "save", "decline", $node)));
|
||||
$node->moderate = 0;
|
||||
$node->status = 0;
|
||||
node_save($node);
|
||||
watchdog("special", "moderation: expired '$node->title'");
|
||||
}
|
||||
}
|
||||
|
@ -212,13 +221,25 @@ function queue_block($op = "list", $delta = 0) {
|
|||
|
||||
function queue_nodeapi(&$node, $op, $arg = 0) {
|
||||
switch ($op) {
|
||||
case "form":
|
||||
if ($arg == "admin" && user_access("administer moderation")) {
|
||||
return form_select(t("Moderation status"), "moderate", $node->moderate, array(t("Approved"), t("Awaiting approval")));
|
||||
case "conf":
|
||||
$output[t("Queue")] = form_checkbox("", "queue_$node->type", 1, variable_get("queue_$node->type", 0));
|
||||
return $output;
|
||||
case "fields":
|
||||
return array("moderate", "score", "users", "votes");
|
||||
case "form admin":
|
||||
if (user_access("administer moderation")) {
|
||||
return form_select(t("Moderation status"), "moderate", isset($node->moderate) ? $node->moderate : variable_get("queue_$node->type", 0), array(t("Approved"), t("Awaiting approval")));
|
||||
}
|
||||
break;
|
||||
case "validate":
|
||||
$node->promote = $node->moderate ? 0 : 1;
|
||||
if ($node->nid && $node->moderate) {
|
||||
// Reset votes when node is updated:
|
||||
$node->score = 0;
|
||||
$node->users = "";
|
||||
$node->votes = 0;
|
||||
}
|
||||
break;
|
||||
case "fields":
|
||||
return array("moderate");
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -40,30 +40,6 @@ function story_access($op, $node) {
|
|||
}
|
||||
}
|
||||
|
||||
function story_save($op, $node) {
|
||||
|
||||
if ($op == "approve") {
|
||||
return array("status" => 1, "promote" => 1);
|
||||
}
|
||||
|
||||
if ($op == "create") {
|
||||
if (user_access("administer nodes")) {
|
||||
return array("body" => filter($node->body), "teaser" => filter($node->teaser));
|
||||
}
|
||||
else {
|
||||
return array("moderate" => 1);
|
||||
}
|
||||
}
|
||||
|
||||
if ($op == "decline") {
|
||||
return array("status" => 0, "promote" => 0);
|
||||
}
|
||||
|
||||
if ($op == "update") {
|
||||
return array("body" => filter($node->body), "teaser" => filter($node->teaser));
|
||||
}
|
||||
}
|
||||
|
||||
function story_link($type) {
|
||||
if ($type == "menu.create" && user_access("create stories")) {
|
||||
$links[] = l(t("create story"), "node/add/story", array("title" => t("Add a new story.")));
|
||||
|
@ -105,4 +81,9 @@ function story_form(&$node, &$help, &$error) {
|
|||
}
|
||||
|
||||
|
||||
function story_validate(&$node) {
|
||||
// Make sure all fields are set properly:
|
||||
$node->body = filter($node->body);
|
||||
$node->teaser = filter($node->teaser);
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -40,30 +40,6 @@ function story_access($op, $node) {
|
|||
}
|
||||
}
|
||||
|
||||
function story_save($op, $node) {
|
||||
|
||||
if ($op == "approve") {
|
||||
return array("status" => 1, "promote" => 1);
|
||||
}
|
||||
|
||||
if ($op == "create") {
|
||||
if (user_access("administer nodes")) {
|
||||
return array("body" => filter($node->body), "teaser" => filter($node->teaser));
|
||||
}
|
||||
else {
|
||||
return array("moderate" => 1);
|
||||
}
|
||||
}
|
||||
|
||||
if ($op == "decline") {
|
||||
return array("status" => 0, "promote" => 0);
|
||||
}
|
||||
|
||||
if ($op == "update") {
|
||||
return array("body" => filter($node->body), "teaser" => filter($node->teaser));
|
||||
}
|
||||
}
|
||||
|
||||
function story_link($type) {
|
||||
if ($type == "menu.create" && user_access("create stories")) {
|
||||
$links[] = l(t("create story"), "node/add/story", array("title" => t("Add a new story.")));
|
||||
|
@ -105,4 +81,9 @@ function story_form(&$node, &$help, &$error) {
|
|||
}
|
||||
|
||||
|
||||
function story_validate(&$node) {
|
||||
// Make sure all fields are set properly:
|
||||
$node->body = filter($node->body);
|
||||
$node->teaser = filter($node->teaser);
|
||||
}
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue