Commit 55927616 authored by Kjartan's avatar Kjartan

This is a major change to the system, needs more testing!

Committing Changes by Moshe Weitzman:
- admin_user_account(), user_edit(), and user_view() no longer have any
  hard code for authentication modules. instead authentication modules
  implement the _user hook.
- fixed a couple 'help' typos.
- linked the 'REGISTER' text in the login block to the register page.
  this page now advertises DA better if site employs DA.
- admins may now edit everything about a user account (was a feature
  request).
- user #1 may now login immediately, in addition to receiving his
  password via email.

Other changes:
- modules and themes are now enabled/disabled in the administrative /
  settings / modules | themes pages. Requires SQL update and things must
  be enabled before your site returns to normal. TODO: enable all
  functionality. (For now just do UPDATE system SET status = 1;)
- removed $themes from conf.php.
- added a $theme->system() function where theme can specify settings.
  All themes in the Drupal CVS have been updated to use this.
- added _system hook to modules. TODO: update modules to use this.
- changed strange use of sprintf to the usual strtr. The disadvantage of
  sprintf is that it requires translations to keep the string order,
  which may not be possible in all languages.
- an invalid/nonexisting theme in a user profile will now fallback to the
  BaseTheme instead of crashing.
parent 3ffe07f5
......@@ -21,22 +21,6 @@
# If required, update PHP's include path to include your PEAR directory:
// ini_set("include_path", ".:/path/to/pear");
#
# Themes:
#
$themes = array("UnConeD" => array(
"themes/unconed/unconed.theme",
"Internet explorer, Netscape, Opera"),
"Marvin" => array(
"themes/marvin/marvin.theme",
"Internet explorer, Netscape, Opera"),
"Stone Age" => array(
"themes/example/example.theme",
"Internet explorer, Netscape, Opera, Lynx"),
"Goofy" => array(
"themes/goofy/goofy.theme",
"Internet explorer, Netscape, Opera"));
#
# Languages / translation / internationalization:
# The first language listed in this associative array will
......
......@@ -3,6 +3,10 @@
// initialize modules:
function module_init() {
require_once("modules/user.module");
require_once("modules/drupal.module");
require_once("modules/system.module");
require_once("modules/watchdog.module");
module_list();
}
......@@ -38,21 +42,13 @@ function module_list() {
static $list;
if (!$list) {
if ($handle = @opendir("modules")) {
$list = array();
while ($file = readdir($handle)) {
if (".module" == substr($file, -7)) {
$filename = substr($file, 0, -7);
$list[$filename] = $filename;
include "modules/$filename.module";
}
}
closedir($handle);
asort($list);
}
else {
$list = array();
$list = array("drupal" => "drupal", "system" => "system", "user" => "user", "watchdog" => "watchdog");
$result = db_query("SELECT name, filename FROM system WHERE type = 'module' AND status = '1' ORDER BY name");
while ($module = db_fetch_object($result)) {
$list[$module->name] = $module->name;
@include_once "modules/$module->filename";
}
asort($list);
}
return $list;
......@@ -109,4 +105,4 @@ function module_rehash($name) {
}
}
?>
?>
\ No newline at end of file
<?php
// $Id$
/**
* Basic theme
*
* @package theme system
*/
class BaseTheme {
function system($field) {
$system["name"] = "I need a name o'wise one!";
$system["author"] = "What is your name master?";
$system["description"] = "What am I mighty one?";
return $system[$field];
}
function header($title = "") {
$output .= "<html><head><title>". variable_get(site_name, "drupal") ."</title></head><body>";
$output .= "<table border=\"0\" cellspacing=\"4\" cellpadding=\"4\"><tr><td valign=\"top\" width=\"170\">";
......@@ -68,18 +81,35 @@ function footer() {
}
function theme_init() {
global $user, $themes;
function theme_list() {
static $list;
if ($user->theme && file_exists($themes[$theme_name = $user->theme][0])) {
include_once $themes[$theme_name][0];
if (!$list) {
$list = array();
$result = db_query("SELECT * FROM system where type = 'theme' AND status = '1' ORDER BY name");
while ($theme = db_fetch_object($result)) {
$list[$theme->name] = $theme;
}
}
else {
include_once $themes[$theme_name = variable_get("theme_default", key($themes))][0];
return $list;
}
function theme_init() {
global $user;
$themes = theme_list();
$name = $user->theme ? $user->theme : variable_get("theme_default", 0);
if (is_object($themes[$name])) {
include_once($themes[$name]->filename);
$theme_class = "Theme_$user->theme";
@$obj =& new $theme_class;
return $obj;
}
$theme_class = 'Theme_'. $theme_name;
return new $theme_class();
watchdog("warning", "No valid themes enabled.");
@$obj =& new BaseTheme;
return $obj;
}
function theme_blocks($region, &$theme) {
......
......@@ -5,8 +5,14 @@
page_header();
eval(variable_get("site_frontpage_extra", "") .";");
module_invoke(variable_get("site_frontpage", "node"), "page");
if (module_hook(variable_get("site_frontpage", "node"), "page")) {
eval(variable_get("site_frontpage_extra", "") .";");
module_invoke(variable_get("site_frontpage", "node"), "page");
}
else {
$theme->header();
$theme->footer();
}
page_footer();
......
......@@ -178,7 +178,7 @@ function blog_page_user($uid = 0, $date = 0, $all = 0) {
$output .= "<a href=\"module.php?mod=blog&op=view&id=$account->uid\" title=\"". t("Show recent blogs by this user") ."\">". t("show recent blogs") ."</a>";
}
$theme->box(sprintf(t("%s's blog"), $account->name), $output);
$theme->box(strtr(t("%u's blog"), array("%u" => $account->name)), $output);
}
function blog_page_last() {
......@@ -302,7 +302,7 @@ function blog_link($type, $node = 0, $main) {
$links[] = "<a href=\"module.php?mod=node&op=edit&id=$node->nid\" title=\"". t("Edit this blog entry.") ."\">". t("edit this blog") ."</a>";
}
else {
$links[] = "<a href=\"module.php?mod=blog&op=view&id=$node->uid\" title=\"". sprintf(t("Read %s's latest blog entries."), $node->name) ."\">". sprintf(t("%s's blog"), $node->name) ."</a>";
$links[] = "<a href=\"module.php?mod=blog&op=view&id=$node->uid\" title=\"". strtr(t("Read %u's latest blog entries."), array("%u" => $node->name)) ."\">". strtr(t("%u's blog"), array("%u", $node->name)) ."</a>";
}
}
......
......@@ -178,7 +178,7 @@ function blog_page_user($uid = 0, $date = 0, $all = 0) {
$output .= "<a href=\"module.php?mod=blog&op=view&id=$account->uid\" title=\"". t("Show recent blogs by this user") ."\">". t("show recent blogs") ."</a>";
}
$theme->box(sprintf(t("%s's blog"), $account->name), $output);
$theme->box(strtr(t("%u's blog"), array("%u" => $account->name)), $output);
}
function blog_page_last() {
......@@ -302,7 +302,7 @@ function blog_link($type, $node = 0, $main) {
$links[] = "<a href=\"module.php?mod=node&op=edit&id=$node->nid\" title=\"". t("Edit this blog entry.") ."\">". t("edit this blog") ."</a>";
}
else {
$links[] = "<a href=\"module.php?mod=blog&op=view&id=$node->uid\" title=\"". sprintf(t("Read %s's latest blog entries."), $node->name) ."\">". sprintf(t("%s's blog"), $node->name) ."</a>";
$links[] = "<a href=\"module.php?mod=blog&op=view&id=$node->uid\" title=\"". strtr(t("Read %u's latest blog entries."), array("%u" => $node->name)) ."\">". strtr(t("%u's blog"), array("%u", $node->name)) ."</a>";
}
}
......
......@@ -390,7 +390,7 @@ function book_view($node, $main = 0) {
$output .= " <tr><td colspan=\"3\">$location</td></tr>";
$output .= " <tr><td colspan=\"3\"><hr /></td></tr>";
$output .= " <tr><td colspan=\"3\"><b><big>". check_output($node->title) ."</big></b>". ($node->body ? "<br /><small><i>". sprintf(t("Last updated by %s on %s"), format_name($node), format_date($node->created)) ."</i></small> " : "") ."</td></tr>";
$output .= " <tr><td colspan=\"3\"><b><big>". check_output($node->title) ."</big></b>". ($node->body ? "<br /><small><i>". strtr(t("Last updated by %u on %d"), array("%u" => format_name($node), "%d" => format_date($node->created))) ."</i></small> " : "") ."</td></tr>";
}
if ($node->body) {
......@@ -607,7 +607,7 @@ function book_admin_view_line($node, $depth = 0) {
$output .= " <td><div style=\"padding-left: ". (25 * $depth) ."px;\"><a href=\"node.php?id=$node->nid\">". check_output($node->title) ."</a></div></td>";
$output .= " <td align=\"center\">$revision</td>";
$output .= " <td><a href=\"admin.php?mod=node&op=edit&id=$node->nid\">". t("edit node") ."</td>";
//TODO: get this link to work. Must pass $nid along so it is received by book_node_link()
//TODO: get this link to work. Must pass $nid along so it is received by book_node_link()
//$output .= " <td><a href=\"admin.php?mod=book&nid=$node->nid&op=Edit+book+outline\">". t("edit book outline") ."</td>";
$output .= " <td><a href=\"admin.php?mod=node&op=delete&id=$node->nid\">". t("delete node") ."</td>";
$output .= "</tr>";
......@@ -635,7 +635,7 @@ function book_admin_view($nid, $depth = 0) {
$output .= "<h3>". check_output($node->title) ."</h3>";
$output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">";
//TODO: change colspan below to 3 after adding new link in book_admin_view_line()
//TODO: change colspan below to 3 after adding new link in book_admin_view_line()
$output .= " <tr><th>title</th><th>rev</th><th colspan=\"2\">operations</th></tr>";
$output .= book_admin_view_line($node);
$output .= book_admin_view_book($nid);
......@@ -686,7 +686,7 @@ function book_admin() {
*/
$links = book_admin_links();
print "<small>". implode(" &middot; ", $links) ."</small><hr />";
switch ($op) {
......@@ -712,7 +712,7 @@ function book_admin() {
function book_help() {
?>
<p>The Collaborative Book is a magnificient mechanism for organizing content authored by many users.
You may use it to organize a Manual (e.g. <a href="http://www.drupal.org">Drupal Handbook</a>),
to <a href="#faq">maintain an FAQ</a>, or to manage any outline-like content. Books can have
......@@ -792,6 +792,6 @@ function book_help() {
</ul>
<?php
}
}
?>
......@@ -390,7 +390,7 @@ function book_view($node, $main = 0) {
$output .= " <tr><td colspan=\"3\">$location</td></tr>";
$output .= " <tr><td colspan=\"3\"><hr /></td></tr>";
$output .= " <tr><td colspan=\"3\"><b><big>". check_output($node->title) ."</big></b>". ($node->body ? "<br /><small><i>". sprintf(t("Last updated by %s on %s"), format_name($node), format_date($node->created)) ."</i></small> " : "") ."</td></tr>";
$output .= " <tr><td colspan=\"3\"><b><big>". check_output($node->title) ."</big></b>". ($node->body ? "<br /><small><i>". strtr(t("Last updated by %u on %d"), array("%u" => format_name($node), "%d" => format_date($node->created))) ."</i></small> " : "") ."</td></tr>";
}
if ($node->body) {
......@@ -607,7 +607,7 @@ function book_admin_view_line($node, $depth = 0) {
$output .= " <td><div style=\"padding-left: ". (25 * $depth) ."px;\"><a href=\"node.php?id=$node->nid\">". check_output($node->title) ."</a></div></td>";
$output .= " <td align=\"center\">$revision</td>";
$output .= " <td><a href=\"admin.php?mod=node&op=edit&id=$node->nid\">". t("edit node") ."</td>";
//TODO: get this link to work. Must pass $nid along so it is received by book_node_link()
//TODO: get this link to work. Must pass $nid along so it is received by book_node_link()
//$output .= " <td><a href=\"admin.php?mod=book&nid=$node->nid&op=Edit+book+outline\">". t("edit book outline") ."</td>";
$output .= " <td><a href=\"admin.php?mod=node&op=delete&id=$node->nid\">". t("delete node") ."</td>";
$output .= "</tr>";
......@@ -635,7 +635,7 @@ function book_admin_view($nid, $depth = 0) {
$output .= "<h3>". check_output($node->title) ."</h3>";
$output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">";
//TODO: change colspan below to 3 after adding new link in book_admin_view_line()
//TODO: change colspan below to 3 after adding new link in book_admin_view_line()
$output .= " <tr><th>title</th><th>rev</th><th colspan=\"2\">operations</th></tr>";
$output .= book_admin_view_line($node);
$output .= book_admin_view_book($nid);
......@@ -686,7 +686,7 @@ function book_admin() {
*/
$links = book_admin_links();
print "<small>". implode(" &middot; ", $links) ."</small><hr />";
switch ($op) {
......@@ -712,7 +712,7 @@ function book_admin() {
function book_help() {
?>
<p>The Collaborative Book is a magnificient mechanism for organizing content authored by many users.
You may use it to organize a Manual (e.g. <a href="http://www.drupal.org">Drupal Handbook</a>),
to <a href="#faq">maintain an FAQ</a>, or to manage any outline-like content. Books can have
......@@ -792,6 +792,6 @@ function book_help() {
</ul>
<?php
}
}
?>
......@@ -110,8 +110,9 @@ function drupal_auth($username, $password, $server) {
$message = new xmlrpcmsg("drupal.login", array(new xmlrpcval($username, "string"), new xmlrpcval($password, "string")));
// TODO remove hard coded Port 80
// TODO manage server/path such that HTTP_HOST/xml.rpc.php is not assumed
$client = new xmlrpc_client("/xmlrpc.php", $server, 80);
$result = $client->send($message, 5);
if ($result && !$result->faultCode()) {
$value = $result->value();
......@@ -131,11 +132,29 @@ function drupal_page() {
function drupal_auth_help() {
$site = variable_get("site_name", "this web site");
$output = "
<p><a href=\"http://www.drupal.org\">Drupal</a> is the name of the software which powers %s. There are Drupal websites all over the world, and many of them share their registration databases so that users may freely login to any Drupal site using a single <b>Drupal ID</b>.</p>
<p>So please feel free to login to your account here at %s with a username from another Drupal site. The format of a Drupal ID is similar to an email address: <b>username</b>@<i>server</i>. An example of valid Drupal ID is <b>mwlily</b><i>@www.drupal.org</i>.</p>";
$output = "<p><a href=\"http://www.drupal.org\">Drupal</a> is the name of the software which powers %s. There are Drupal websites all over the world, and many of them share their registration databases so that users may freely login to any Drupal site using a single <b>Drupal ID</b>.</p>\n";
$output .= "<p>So please feel free to login to your account here at %s with a username from another Drupal site. The format of a Drupal ID is similar to an email address: <b>username</b>@<i>server</i>. An example of valid Drupal ID is <b>mwlily</b><i>@www.drupal.org</i>.</p>";
return strtr(t($output), array("%s" => "<i>$site</i>"));
}
return sprintf(t($output), $site, $site);
function drupal_user($type, $edit, $user) {
global $HTTP_HOST;
$module = "drupal";
$name = module_invoke($module, "info", "name");
switch ($type) {
case "view_private":
$result = user_get_authname($user, $module);
if ($result) {
$output .= form_item("$name ID", $result);
}
else {
// TODO: use a variation of path_uri() instead of $HTTP_HOST below
$output .= form_item("$name ID", "$user->name@$HTTP_HOST");
}
return $output;
}
}
?>
\ No newline at end of file
......@@ -110,8 +110,9 @@ function drupal_auth($username, $password, $server) {
$message = new xmlrpcmsg("drupal.login", array(new xmlrpcval($username, "string"), new xmlrpcval($password, "string")));
// TODO remove hard coded Port 80
// TODO manage server/path such that HTTP_HOST/xml.rpc.php is not assumed
$client = new xmlrpc_client("/xmlrpc.php", $server, 80);
$result = $client->send($message, 5);
if ($result && !$result->faultCode()) {
$value = $result->value();
......@@ -131,11 +132,29 @@ function drupal_page() {
function drupal_auth_help() {
$site = variable_get("site_name", "this web site");
$output = "
<p><a href=\"http://www.drupal.org\">Drupal</a> is the name of the software which powers %s. There are Drupal websites all over the world, and many of them share their registration databases so that users may freely login to any Drupal site using a single <b>Drupal ID</b>.</p>
<p>So please feel free to login to your account here at %s with a username from another Drupal site. The format of a Drupal ID is similar to an email address: <b>username</b>@<i>server</i>. An example of valid Drupal ID is <b>mwlily</b><i>@www.drupal.org</i>.</p>";
$output = "<p><a href=\"http://www.drupal.org\">Drupal</a> is the name of the software which powers %s. There are Drupal websites all over the world, and many of them share their registration databases so that users may freely login to any Drupal site using a single <b>Drupal ID</b>.</p>\n";
$output .= "<p>So please feel free to login to your account here at %s with a username from another Drupal site. The format of a Drupal ID is similar to an email address: <b>username</b>@<i>server</i>. An example of valid Drupal ID is <b>mwlily</b><i>@www.drupal.org</i>.</p>";
return strtr(t($output), array("%s" => "<i>$site</i>"));
}
return sprintf(t($output), $site, $site);
function drupal_user($type, $edit, $user) {
global $HTTP_HOST;
$module = "drupal";
$name = module_invoke($module, "info", "name");
switch ($type) {
case "view_private":
$result = user_get_authname($user, $module);
if ($result) {
$output .= form_item("$name ID", $result);
}
else {
// TODO: use a variation of path_uri() instead of $HTTP_HOST below
$output .= form_item("$name ID", "$user->name@$HTTP_HOST");
}
return $output;
}
}
?>
\ No newline at end of file
......@@ -12,7 +12,7 @@ function jabber_info($field = 0) {
}
}
function startElement($parser, $name, $attributes) {
function jabber_start($parser, $name, $attributes) {
global $jabber;
if ($attributes["ID"]) {
......@@ -24,10 +24,10 @@ function startElement($parser, $name, $attributes) {
}
}
function endElement($parser, $name) {
function jabber_end($parser, $name) {
}
function characterData($parser, $data) {
function jabber_data($parser, $data) {
global $jabber;
$jabber["data"] = $data;
......@@ -77,8 +77,8 @@ function jabber_auth($username, $password, $server) {
if ($session) {
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
xml_set_element_handler($xml_parser, "jabber_start", "jabber_end");
xml_set_character_data_handler($xml_parser, "jabber_data");
/*
** Switch the given socket descriptor '$session' to non-blocking mode:
......@@ -153,7 +153,24 @@ function jabber_auth_help() {
<p>You may login to %s using a <b>Jabber ID</b>. The format of a Jabber ID is the same as an email address: <b>name</b><i>@server</i> An example of valid Jabber ID is <b>mwlily</b><i>@jabber.com</i>.</p>
<p>Jabber is an <a href=\"http://www.opensource.org\">open source</a> instant messaging system designed to give the power of choice and freedom back to the users of instant messaging. By creating an extensible and powerful server and protocol, Jabber has succeeded in this goal. Not only does Jabber allow its users to use (and create) clients for numerous platforms, but it allows people to communicate to whomever they want in the way which is most convenient for them.</p>";
return sprintf(t($output), $site);
return strtr(t($output), array("%s" => "<i>$site</i>"));
}
function jabber_user($type, $edit, $user) {
$module = "jabber";
$name = module_invoke($module, "info", "name");
switch ($type) {
case "view_private":
$result = user_get_authname($user, $module);
$output .= form_item("$name ID", $result);
return $output;
case "edit_form":
$result = user_get_authname($user, $module);
$output .= form_textfield("$name ID", "authname_" . $module, $result, 30, 55, strtr(t("You may login to %s using a valid %id."), array("%s" => variable_get("site_name", "this web site"), "%id" => "<a href=\"module.php?mod=user&op=help#$module\">$name ID</a>"), ""));
return $output;
case "edit_validate":
return user_validate_authmap($user, $edit["authname_$module"], $module);
}
}
?>
\ No newline at end of file
......@@ -458,7 +458,7 @@ function node_admin_edit($node) {
$output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">";
$output .= " <tr><th>older revisions</th><th colspan=\"3\">operations</th></tr>";
foreach ($node->revisions as $key => $revision) {
$output .= " <tr><td>". sprintf(t("revision #%d revised by %s on %s"), $key, format_name(user_load(array("uid" => $revision["uid"]))), format_date($revision["timestamp"], "small")) . ($revision["history"] ? "<br /><small>". $revision["history"] ."</small>" : "") ."</td><td><a href=\"node.php?id=$node->nid&revision=$key\">". t("view revision") ."</a></td><td><a href=\"admin.php?mod=node&op=rollback+revision&id=$node->nid&revision=$key\">". t("rollback revision") ."</a></td><td><a href=\"admin.php?mod=node&op=delete+revision&id=$node->nid&revision=$key\">". t("delete revision") ."</a></td></tr>";
$output .= " <tr><td>". strtr(t("revision #%r revised by %u on %d"), array("%r" => $key, "%u" => format_name(user_load(array("uid" => $revision["uid"]))), "%d" => format_date($revision["timestamp"], "small"))) . ($revision["history"] ? "<br /><small>". $revision["history"] ."</small>" : "") ."</td><td><a href=\"node.php?id=$node->nid&revision=$key\">". t("view revision") ."</a></td><td><a href=\"admin.php?mod=node&op=rollback+revision&id=$node->nid&revision=$key\">". t("rollback revision") ."</a></td><td><a href=\"admin.php?mod=node&op=delete+revision&id=$node->nid&revision=$key\">". t("delete revision") ."</a></td></tr>";
}
$output .= "</table>";
}
......@@ -741,7 +741,7 @@ function node_validate($node, &$error) {
$node->uid = $account->uid;
}
else {
$error["name"] = "<div style=\"color: red;\">". sprintf(t("The name '%s' does not exist."), $node->name) ."</div>";
$error["name"] = "<div style=\"color: red;\">". strtr(t("The name '%u' does not exist."), array ("%u" => $node->name)) ."</div>";
}
/*
......@@ -898,7 +898,7 @@ function node_add($type) {
foreach (module_list() as $name) {
if (module_hook($name, "node") && node_access("create", array("type" => $name))) {
$output .= "<li>";
$output .= " <a href=\"module.php?mod=node&op=add&type=$name\" title=\"". sprintf(t("Add a new %s."), module_invoke($name, "node", "name")) ."\">". module_invoke($name, "node", "name") ."</a>";
$output .= " <a href=\"module.php?mod=node&op=add&type=$name\" title=\"". strtr(t("Add a new %s."), module_invoke($name, "node", "name")) ."\">". module_invoke($name, "node", "name") ."</a>";
$output .= " <div style=\"margin-left: 20px;\">". module_invoke($name, "node", "description") ."</div>";
$output .= "</li>";
}
......
......@@ -458,7 +458,7 @@ function node_admin_edit($node) {
$output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">";
$output .= " <tr><th>older revisions</th><th colspan=\"3\">operations</th></tr>";
foreach ($node->revisions as $key => $revision) {
$output .= " <tr><td>". sprintf(t("revision #%d revised by %s on %s"), $key, format_name(user_load(array("uid" => $revision["uid"]))), format_date($revision["timestamp"], "small")) . ($revision["history"] ? "<br /><small>". $revision["history"] ."</small>" : "") ."</td><td><a href=\"node.php?id=$node->nid&revision=$key\">". t("view revision") ."</a></td><td><a href=\"admin.php?mod=node&op=rollback+revision&id=$node->nid&revision=$key\">". t("rollback revision") ."</a></td><td><a href=\"admin.php?mod=node&op=delete+revision&id=$node->nid&revision=$key\">". t("delete revision") ."</a></td></tr>";
$output .= " <tr><td>". strtr(t("revision #%r revised by %u on %d"), array("%r" => $key, "%u" => format_name(user_load(array("uid" => $revision["uid"]))), "%d" => format_date($revision["timestamp"], "small"))) . ($revision["history"] ? "<br /><small>". $revision["history"] ."</small>" : "") ."</td><td><a href=\"node.php?id=$node->nid&revision=$key\">". t("view revision") ."</a></td><td><a href=\"admin.php?mod=node&op=rollback+revision&id=$node->nid&revision=$key\">". t("rollback revision") ."</a></td><td><a href=\"admin.php?mod=node&op=delete+revision&id=$node->nid&revision=$key\">". t("delete revision") ."</a></td></tr>";
}
$output .= "</table>";
}
......@@ -741,7 +741,7 @@ function node_validate($node, &$error) {
$node->uid = $account->uid;
}
else {
$error["name"] = "<div style=\"color: red;\">". sprintf(t("The name '%s' does not exist."), $node->name) ."</div>";
$error["name"] = "<div style=\"color: red;\">". strtr(t("The name '%u' does not exist."), array ("%u" => $node->name)) ."</div>";
}
/*
......@@ -898,7 +898,7 @@ function node_add($type) {
foreach (module_list() as $name) {
if (module_hook($name, "node") && node_access("create", array("type" => $name))) {
$output .= "<li>";
$output .= " <a href=\"module.php?mod=node&op=add&type=$name\" title=\"". sprintf(t("Add a new %s."), module_invoke($name, "node", "name")) ."\">". module_invoke($name, "node", "name") ."</a>";
$output .= " <a href=\"module.php?mod=node&op=add&type=$name\" title=\"". strtr(t("Add a new %s."), module_invoke($name, "node", "name")) ."\">". module_invoke($name, "node", "name") ."</a>";
$output .= " <div style=\"margin-left: 20px;\">". module_invoke($name, "node", "description") ."</div>";
$output .= "</li>";
}
......
......@@ -32,11 +32,15 @@ function system_link($type) {
$links[] = "<a href=\"admin.php?mod=system\">settings and filters</a>";
}
/*if ($type == "admin" && user_access("administer modules and themes")) {
$links[] = "<a href=\"admin.php?mod=system&op=modules\">modules and themes</a>";
}*/
return $links ? $links : array();
}
function system_view_options() {
global $conf, $cmodes, $corder, $themes;
global $conf, $cmodes, $corder;
// general settings:
$output .= "<h3>General settings</h3>\n";
$output .= form_textfield("Name", "site_name", variable_get("site_name", "drupal"), 55, 55, "The name of this website.");
......@@ -66,14 +70,14 @@ function system_view_options() {
// comment settings:
$output .= "<h3>Comment settings</h3>\n";
$output .= form_select("Default display mode", "default_comment_mode", $conf[default_comment_mode], $cmodes, "The default mode in which comments are displayed.");
$output .= form_select("Default display order", "default_comment_order", $conf[default_comment_order], $corder, "The default order in which comments are displayed.");
$output .= form_select("Default display mode", "default_comment_mode", $conf["default_comment_mode"], $cmodes, "The default mode in which comments are displayed.");
$output .= form_select("Default display order", "default_comment_order", $conf["default_comment_order"], $corder, "The default order in which comments are displayed.");
for ($count = -1; $count < 6; $count++) $threshold[$count] = "Filter - $count";
$output .= "<hr />\n";
// layout settings:
$output .= "<h3>Layout settings</h3>\n";
foreach ($themes as $key=>$value) $options .= "<OPTION VALUE=\"$key\"". (variable_get("theme_default", key($themes)) == $key ? " SELECTED" : "") .">$key</OPTION>\n";
foreach (theme_list() as $key=>$value) $options .= "<OPTION VALUE=\"$key\"". (variable_get("theme_default", 0) == $key ? " SELECTED" : "") .">$key</OPTION>\n";
$output .= form_item("Default theme", "<SELECT NAME=\"edit[theme_default]\">$options</SELECT>", "The default theme as seen by visitors or anonymous users.");
$output .= "<hr />\n";
......@@ -127,31 +131,138 @@ function system_view($type) {
return form($form);
}
/**
* Module configuration
*
* @author Kjartan Mannes
* @group system.module
* @return string module list
*/
function system_modules() {
$result = db_query("SELECT name, status FROM system WHERE type = 'module'");
$status = array();
while ($module = db_fetch_object($result)) {
$status[$module->name] = $module->status;
}
db_query("DELETE FROM system WHERE type = 'module'");
if ($handle = @opendir("modules")) {
$modules = array();
while ($file = readdir($handle)) {
if (".module" == substr($file, -7)) {
$name = substr($file, 0, -7);
$modules[$name] = array("filename" => "$file", "status" => $status[$name]);
include_once("modules/$file");
}
}
closedir($handle);
asort($modules);
}
$required = array("user", "drupal", "system", "watchdog");
$output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">\n";
$output .= " <tr><th>module</th><th colspan=\"2\">operations</th></tr>\n";
foreach (module_list() as $name) {
$output .= " <tr><td>$name</td><td>". (module_hook($name, "page") ? "<a href=\"module.php?mod=$name\">view</a>" : "&nbsp;") ."</td><td>". (module_hook($name, "admin") ? "<a href=\"admin.php?mod=$name\">admin</a>" : "&nbsp;") ."</td></tr>\n";
$output .= " <tr><th>module</th><th>description</th><th>status</th><th colspan=\"2\">operations</th></tr>\n";
foreach ($modules as $name => $module) {
$output .= " <tr><td>$name</td><td>". check_output(module_invoke($name, "system", "description")) ."</td><td>". (in_array($name, $required) ? "Enabled" : form_select("", "status][$name", $module["status"], array(t("Disabled"), t("Enabled")))) ."</td><td>". (module_hook($name, "page") ? "<a href=\"module.php?mod=$name\">view</a>" : "&nbsp;") ."</td><td>". (module_hook($name, "admin") ? "<a href=\"admin.php?mod=$name\">admin</a>" : "&nbsp;") ."</td></tr>\n";
if (!in_array($name, $required)) {
db_query("INSERT INTO system SET name = '$name', type = 'module', filename = '$module[filename]', status = '$module[status]'");
}
}
$output .= "</table>\n";
$output .= "</table><br />\n";
$output .= form_submit("Save module settings");
return $output;
return form($output);
}
/**
* Theme configuration
*
* This function handles the Drupal themes and lets the site administrator enable or disable them as they wish.
*
* @author Kjartan Mannes
* @package system.module
* @return string theme list
*/
function system_themes() {
$result = db_query("SELECT * FROM system WHERE type = 'theme' ORDER BY filename");
$status = array();
while ($theme = db_fetch_object($result)) {
$_themes[$theme->name] = $theme;
}
if ($handle = @opendir("themes")) {
$themes = array();
while ($dir = readdir($handle)) {
if (!substr_count($dir, ".") && is_dir("themes/$dir")) {
if ($handle2 = @opendir("themes/$dir")) {
while ($file = readdir($handle2)) {
if (".theme" == substr($file, -6)) {
include_once("themes/$dir/$file");
$name = substr($file, 0, -6);
$_theme = "theme_$name";
if (class_exists($_theme)) {
$_theme =& new $_theme;
$_themes[$name]->filename = "themes/$dir/$file";
if (method_exists($_theme, "system")) {
$_themes[$name]->displayname = $_theme->system("name");
$_themes[$name]->author = $_theme->system("author");
if (empty($_themes[$name]->description)) {
$_themes[$name]->description = $_theme->system("description");
}
}
$themes[$name] = $_themes[$name];
unset($_theme);
}
}
}
closedir($handle2);
}
}
}
closedir($handle);
asort($themes);
}
db_query("DELETE FROM system WHERE type = 'theme'");
$output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">\n";
$output .= " <tr><th>theme</th><th>name</th><th>description</th><th>author</th><th>status</th></tr>\n";
foreach ($themes as $name => $theme) {
$output .= " <tr><td>$name</td><td>$theme->displayname</td><td>". form_textfield("", "$name][description", $theme->description, 40, 255)."</td><td>$theme->author</td><td>". form_select("", "$name][status", $theme->status, array(t("Disabled"), t("Enabled"))) ."</td></tr>\n";
db_query("INSERT INTO system SET name = '$name', type = 'theme', filename = '$theme->filename', status = '$theme->status', description = '$theme->description'");
}
$output .= "</table><br />\n";
$output .= form_submit("Save theme settings");
return form($output);
}
function system_admin() {
global $edit, $op, $type;
if (user_access("administer settings and filters")) {
print "<small><a href=\"admin.php?mod=system&type=options\">site settings</a> | <a href=\"admin.php?mod=system&type=filter\">content filters</a> | <a href=\"admin.php?mod=system&op=modules\">modules</a> | <a href=\"admin.php?mod=system&op=help\">help</a></small><hr />\n";
print "<small><a href=\"admin.php?mod=system&type=options\">site settings</a> | <a href=\"admin.php?mod=system&type=filter\">content filters</a> | <a href=\"admin.php?mod=system&op=modules\">modules</a> | <a href=\"admin.php?mod=system&op=themes\">themes</a> | <a href=\"admin.php?mod=system&op=help\">help</a></small><hr />\n";
switch ($op) {
case "help":
system_help();
break;
case "Save module settings":
foreach ($edit["status"] as $name => $status) {
db_query("UPDATE system SET status = '$status' WHERE name = '$name'");
}
case "modules":
print system_modules();
break;
case "Save theme settings":
foreach ($edit as $name => $settings) {
db_query("UPDATE system SET status = '". check_query($settings["status"]) ."', description = '". check_query($settings["description"]) ."' WHERE name = '$name'");
}
case "themes":
print system_themes();
break;
case "Reset to defaults":
print status(system_default($edit));
print system_view($type);
......
......@@ -32,11 +32,15 @@ function system_link($type) {
$links[] = "<a href=\"admin.php?mod=system\">settings and filters</a>";
}
/*if ($type == "admin" && user_access("administer modules and themes")) {
$links[] = "<a href=\"admin.php?mod=system&op=modules\">modules and themes</a>";
}*/
return $links ? $links : array();
}
function system_view_options() {
global $conf, $cmodes, $corder, $themes;
global $conf, $cmodes, $corder;
// general settings:
$output .= "<h3>General settings</h3>\n";
$output .= form_textfield("Name", "site_name", variable_g