Commit 022013d1 authored by Gábor Hojtsy's avatar Gábor Hojtsy

Introduce "administer node schedules" role. Example

scenario: every user (even anonymous) is alloved to
suggest a node, but they are not alloved to set a schedule
for it (only admins).
parent ded0d669
......@@ -5,8 +5,11 @@
return $system[$field];
}
function scheduler_perm() {
return array("administer node schedules");
}
function scheduler_link($type, $node = 0, $main = 0) {
if ($type == "system" && user_access("administer nodes")) {
$help["scheduler"] = t("The scheduler is a tool for automatically publishing and unpublishing posts at a particular time in the future.");
menu("admin/node/scheduler", t("schedule"), "scheduler_admin", $help["scheduler"], 8);
......@@ -14,7 +17,8 @@
}
function scheduler_write($node, $op, $arg) {
if (user_access("administer nodes") && ($node->timestamp_hidden || $node->timestamp_posted)) {
if (user_access("administer nodes") && user_access("administer node schedules") &&
($node->timestamp_hidden || $node->timestamp_posted)) {
if ($node->timestamp_hidden) {
$conds["timestamp_hidden"] = strtotime($node->timestamp_hidden);
}
......@@ -60,7 +64,7 @@
switch ($op) {
case "validate":
if (user_access("administer nodes")) {
if (user_access("administer nodes") && user_access("administer node schedules")) {
if ($node->timestamp_posted) {
if (strtotime($node->timestamp_posted) === -1) {
$error["timestamp_posted"] = theme("theme_error", t("Invalid date format"));
......@@ -84,22 +88,24 @@
scheduler_write($node, $op, $arg);
break;
case "form admin":
if ($node->nid) {
$date_format = "m/d/y H:i";
$sql = "SELECT timestamp_hidden, timestamp_posted FROM scheduler WHERE nid = '$node->nid'";
$result = db_query($sql);
$schedule = db_fetch_object($result);
if ($schedule->timestamp_posted) {
$node->timestamp_posted = date($date_format, $schedule->timestamp_posted);
}
if ($schedule->timestamp_hidden) {
$node->timestamp_hidden = date($date_format, $schedule->timestamp_hidden);
if (user_access("administer node schedules")) {
if ($node->nid) {
$date_format = "m/d/y H:i";
$sql = "SELECT timestamp_hidden, timestamp_posted FROM scheduler WHERE nid = '$node->nid'";
$result = db_query($sql);
$schedule = db_fetch_object($result);
if ($schedule->timestamp_posted) {
$node->timestamp_posted = date($date_format, $schedule->timestamp_posted);
}
if ($schedule->timestamp_hidden) {
$node->timestamp_hidden = date($date_format, $schedule->timestamp_hidden);
}
}
}
$form .= form_textfield(t("Automatically post document"), "timestamp_posted", ($node->timestamp_posted ? $node->timestamp_posted : ""), 30, 55, $error["timestamp_posted"] ? $error["timestamp_posted"] : sprintf(t("The date at which your document will be automatically posted. Leave empty if you don't want to schedule this document, or enter an English date format. Example input: '%s', '%s', '%s', '%s', '%s' ..."), date("j F Y G:i"), date("m/d/y H:i"), date("F j, Y H:i"), "1 week", "+1 day"));
$form .= form_textfield(t("Automatically hide document"), "timestamp_hidden", ($node->timestamp_hidden ? $node->timestamp_hidden : ""), 30, 55, $error["timestamp_hidden"] ? $error["timestamp_hidden"] : sprintf(t("The date at which your document will be automatically hidden. Leave empty if you don't want to schedule this document, or enter an English date format. Example input: '%s', '%s', '%s', '%s', '%s' ..."), date("j F Y G:i"), date("m/d/y H:i"), date("F j, Y H:i"), "next Thursday", "+1 week"));
return $form;
$form .= form_textfield(t("Automatically post document"), "timestamp_posted", ($node->timestamp_posted ? $node->timestamp_posted : ""), 30, 55, $error["timestamp_posted"] ? $error["timestamp_posted"] : sprintf(t("The date at which your document will be automatically posted. Leave empty if you don't want to schedule this document, or enter an English date format. Example input: '%s', '%s', '%s', '%s', '%s' ..."), date("j F Y G:i"), date("m/d/y H:i"), date("F j, Y H:i"), "1 week", "+1 day"));
$form .= form_textfield(t("Automatically hide document"), "timestamp_hidden", ($node->timestamp_hidden ? $node->timestamp_hidden : ""), 30, 55, $error["timestamp_hidden"] ? $error["timestamp_hidden"] : sprintf(t("The date at which your document will be automatically hidden. Leave empty if you don't want to schedule this document, or enter an English date format. Example input: '%s', '%s', '%s', '%s', '%s' ..."), date("j F Y G:i"), date("m/d/y H:i"), date("F j, Y H:i"), "next Thursday", "+1 week"));
return $form;
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment