Commit 89b2069e authored by Dries's avatar Dries

- Clean URL patch.
parent 97858f9b
<?php
// $Id$
include_once "includes/common.inc";
function status($message) {
if ($message) {
return "<b>Status:</b> $message<hr />\n";
}
}
function admin_page($mod) {
global $user;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
<title><?php echo variable_get("site_name", "drupal") . " " . t("administration pages"); ?></title>
<link rel="stylesheet" type="text/css" media="print" href="misc/print.css" />
<style type="text/css" title="layout" media="Screen">
@import url("misc/admin.css");
</style>
</head>
<body>
<?php
// NOTE: we include a dummy "print.css" to remove the "flash of unstyled content" (FUOC) problems in IE.
module_invoke_all("link", "admin");
/*
** Menu:
*/
print "<div id=\"menu\">";
echo "<h1><a href=\"index.php\">". variable_get("site_name", "drupal") ."</a></h1>";
print menu_tree() ;
print "</div>";
/*
** Body:
*/
print "<a href=\"http://drupal.org/\"><img align=\"right\" src=\"misc/druplicon-small.gif\" alt=\"Druplicon - Drupal logo\" border=\"0\" /></a>";
print "<div id=\"main\">";
if ($path = menu_path()) {
print "<h2>". la(t("Administration")) ." &gt; $path</h2>";
}
else {
print "<h2>". t("Administration") ."</h2>";
}
if ($menu = menu_menu()) {
print "$menu<br />";
}
print "<br /><hr /><br />";
if ($help = menu_help()) {
print "<small>$help</small><br /><br />";
}
if ($mod) {
print module_invoke($mod, "admin");
}
else {
print watchdog_overview("actions");
}
print "</div>";
db_query("DELETE FROM menu");
?>
</body>
</html>
<?php
}
if (user_access("access administration pages")) {
page_header();
admin_page($mod);
page_footer();
}
else {
print message_access();
}
?>
......@@ -2,7 +2,7 @@
// $Id$
function conf_init() {
global $HTTP_HOST;
global $HTTP_HOST, $PHP_SELF;
/*
** Try finding a matching configuration file by stripping the website's
......@@ -10,7 +10,9 @@ function conf_init() {
** default value 'conf'.
*/
$file = strtolower(strtr($HTTP_HOST . substr(request_uri(), 0, strrpos(request_uri(), "/")), "/:", ".."));
$uri = $PHP_SELF;
$file = strtolower(strtr($HTTP_HOST . substr($uri, 0, strrpos($uri, "/")), "/:", ".."));
while (strlen($file) > 4) {
if (file_exists("includes/$file.php")) {
......@@ -35,7 +37,7 @@ function error_handler($errno, $message, $filename, $line, $variables) {
function watchdog($type, $message, $link = NULL) {
global $user;
db_query("INSERT INTO watchdog (uid, type, message, link, location, hostname, timestamp) VALUES ('$user->uid', '%s', '%s', '%s', '%s', '%s', '%s')", $type, $message, $link, request_uri(), getenv("REMOTE_ADDR"), time());
db_query("INSERT INTO watchdog (uid, type, message, link, location, hostname, timestamp) VALUES ('$user->uid', '%s', '%s', '%s', '%s', '%s', '%s')", $type, $message, $link, $uri, getenv("REMOTE_ADDR"), time());
}
function throttle($type, $rate) {
......@@ -56,6 +58,18 @@ function check_php_setting($name, $value) {
}
}
function arg($index) {
global $q;
static $arguments;
if (empty($arguments)) {
$arguments = explode("/", $q);
}
return $arguments[$index];
}
function array2object($node) {
if (is_array($node)) {
......@@ -85,8 +99,11 @@ function object2array($node) {
}
function path_uri($brief = 0) {
global $HTTP_HOST;
$path = $HTTP_HOST . substr(request_uri(), 0, strrpos(request_uri(), "/")) ."/";
global $HTTP_HOST, $PHP_SELF;
$uri = $PHP_SELF;
$path = $HTTP_HOST . substr($uri, 0, strrpos($uri, "/")) ."/";
if (!$brief) {
$path = "http://". $path;
}
......@@ -133,9 +150,8 @@ function t($string, $args = 0) {
** translation string is for example:
**
** $msg = t("You must login below or <a href=\"%url\">create a new
** account</a> before viewing the next page.", array ("%url"
** => drupal_url(array ("mod" => "user", "op" => "register"),
** "module")));
** account</a> before viewing the next page.", array("%url"
** => url("user/register")));
*/
$string = ($languages && function_exists("locale") ? locale($string) : $string);
......@@ -277,12 +293,12 @@ function search_item($item, $type) {
* Render a generic search form.
*
* "Generic" means "universal usable" - that is, usable not only from
* module.php?mod=search, but also as a simple seach box (without
* 'site.com/search', but also as a simple seach box (without
* "Restrict search to", help text, etc) from theme's header etc.
* This means: provide options to only conditionally render certain
* parts of this form.
*
* @param $action Form action. Defaults to module.php?mod=search.
* @param $action Form action. Defaults to 'site.com/search'.
* @param $query Query string. Defaults to global $keys.
* @param $options != 0: Render additional form fields/text
* ("Restrict search to", help text, etc).
......@@ -291,7 +307,7 @@ function search_form($action = 0, $query = 0, $options = 0) {
global $keys;
if (!$action) {
$action = drupal_url(array("mod" => "search"), "module");
$action = url("search");
}
if (!$query) {
......@@ -310,8 +326,6 @@ function search_form($action = 0, $query = 0, $options = 0) {
$output .= " <input type=\"checkbox\" name=\"edit[type][$name]\" ". ($edit["type"][$name] ? " checked=\"checked\"" : "") ." /> ". t($name);
}
}
// TODO: (link to) search hints
}
$form .= "<br />";
......@@ -354,7 +368,7 @@ function search_data() {
*
* @param $type If set, search only nodes of this type.
* Otherwise, search all types.
* @param $action Form action. Defaults to module.php?mod=search.
* @param $action Form action. Defaults to 'site.com/search'.
* @param $query Query string. Defaults to global $keys.
* @param $options != 0: Render additional form fields/text
* ("Restrict search to", help text, etc).
......@@ -638,11 +652,11 @@ function format_name($object) {
global $PHP_SELF;
if ($object->uid && $object->name) {
if (strstr($PHP_SELF, "admin.php")) {
$output = la($object->name, array("mod" => "user", "op" => "edit", "id" => $object->uid), "", array("title" => t("Administer user profile.")));
if (strstr($PHP_SELF, "admin")) {
$output = l($object->name, "admin/user/edit/$object->uid", array("title" => t("Administer user profile.")));
}
else {
$output = lm($object->name, array("mod" => "user", "op" => "view", "id" => $object->uid), "", array("title" => t("View user profile.")));
$output = l($object->name, "user/view/$object->uid", array("title" => t("View user profile.")));
}
}
else {
......@@ -652,10 +666,6 @@ function format_name($object) {
return $output;
}
function format_tag($link, $text) {
return l(($text ? $text : $link), array("title" => $link));
}
function form($form, $method = "post", $action = 0, $options = 0) {
return "<form action=\"". ($action ? $action : htmlentities(request_uri())) ."\" method=\"$method\"". ($options ? " $options" : "") .">\n$form</form>\n";
}
......@@ -737,72 +747,22 @@ function drupal_parse_url($url = NULL) {
return $cache[$url];
}
/**
* Build an URL; use this functions when you must write an URL
* for example in a form or a redirect.
*
* @param $args dictionary of arguments to be passed to the script
* @param $script script to be invoked; optional, defaults to node
* @param $anchor optional, anchor name
*/
function drupal_url($args = array(), $script = "node", $anchor = 0) {
static $search, $replace;
if (!$search) {
/*
According to RFC 1738 [3] the special characters "$-_.+!*'()," and the
reserved characters "/:@#?&=" can be used unencoded within an URL
*/
$search = array("%24", "%2B", "%21", "%2A", "%27", "%28", "%29", "%2C", "%2F", "%3A", "%40", "%23", "%3F", "%26", "%3D");
$replace = array("$", "+", "!", "*", "'", "(", ")", ",", "/", ":", "@", "#", "?", "&", "=");
}
$t = array();
foreach ($args as $key => $value) {
$t[] = "$key=". str_replace($search, $replace, urlencode($value));
}
if (count($t)) {
return "$script.php?". implode("&amp;", $t) . ($anchor ? "#$anchor" : "");
}
else {
return "$script.php". ($anchor ? "#$anchor" : "");
}
function url($url, $query = NULL) {
return "?q=$url". ($query ? "&$query" : "");
}
/**
* Build a HTML link; use this functions when you must write a link
* to another drupal page
*
* @param $args dictionary of arguments to be passed to the script
* @param $text text of the link
* @param $anchor optional, anchor name
* @param $script script to be invoked; optional, defaults to node
* @param $attributes optional, dictionary of attributes for the <a> tag such as 'target', 'name', 'class', etc.
*/
function l($text, $args = array(), $script = "node", $anchor = "", $attributes = array()) {
$t = array();
foreach ($attributes as $key => $value) {
$t[] = "$key=\"$value\"";
}
return "<a href=\"". drupal_url($args, $script, $anchor) ."\" ". implode($t, " ") .">$text</a>";
}
function l($text, $url, $attributes = array(), $query = NULL) {
function la($text, $args = array(), $anchor = "", $attributes = array()) {
// we don't call l() to avoid another duplication of the array
$t = array();
foreach ($attributes as $key => $value) {
$t[] = "$key=\"$value\"";
if (!is_array($attributes)) {
print "$text - $url";
}
return "<a href=\"". drupal_url($args, "admin", $anchor) ."\" ". implode($t, " ") .">$text</a>";
}
function lm($text, $args = array(), $anchor = "", $attributes = array()) {
// we don't call l() to avoid another duplication of the array
$t = array();
foreach ($attributes as $key => $value) {
$t[] = "$key=\"$value\"";
}
return "<a href=\"". drupal_url($args, "module", $anchor) ."\" ". implode($t, " ") .">$text</a>";
return "<a href=\"". url($url, $query) ."\" ". implode($t, " ") .">$text</a>";
}
function field_get($string, $name) {
......@@ -825,7 +785,7 @@ function link_page() {
return $custom_links;
}
else {
$links[] = l(t("home"), array(), "index", "", array("title" => t("Return to the main page.")));
$links[] = "<a href=\"index.php\" title=\"". t("Return to the main page.") ."\">". t("home") ."</a>";
foreach (module_list() as $name) {
if (module_hook($name, "link")) {
$links = array_merge($links, module_invoke($name, "link", "page"));
......
......@@ -45,8 +45,7 @@
# top of every page.
// $custom_links = array(
// "<a href=\"index.php\">home</a>",
// "<a href=\"module.php?mod=user\">school</a>",
// "<a href=\"module.php?mod=blog\">work</a>");
// "<a href=\"blog\">journal</a>",
// "<a href=\"story\">articles</a>");
?>
......@@ -2,7 +2,7 @@
function menu_trail() {
global $REQUEST_URI;
global $QUERY_STRING;
static $trail = NULL;
/*
......@@ -12,8 +12,7 @@ function menu_trail() {
if (empty($trail)) {
$path = array();
$link = substr($REQUEST_URI, strrpos($REQUEST_URI, "/") + 1, strlen($REQUEST_URI));
$item = db_fetch_object(db_query("SELECT * FROM menu WHERE link = '%s'", $link));
$item = db_fetch_object(db_query("SELECT * FROM menu WHERE link LIKE '%%%s'", $QUERY_STRING));
/*
** Compile an array of menu objects that represent the path to
......@@ -38,14 +37,13 @@ function menu_trail() {
}
function menu_item($item) {
global $REQUEST_URI;
/*
** If you want to theme your links, or if you want to replace them
** by an image, this would be the function to customize.
*/
if (stristr($REQUEST_URI, $item->link) == $item->link) {
if (stristr(request_uri(), $item->link) == $item->link) {
return t($item->name);
}
else if ($item->title) {
......
......@@ -4,6 +4,7 @@
// initialize modules:
function module_init() {
// Note: changing this also requires changing system_admin() @ modules/system.module.
require_once "modules/admin.module";
require_once "modules/user.module";
require_once "modules/system.module";
require_once "modules/watchdog.module";
......
......@@ -295,7 +295,8 @@ function pager_link($from_new, $attributes = array()) {
$url["query"] = array_merge($url["query"], $attributes);
}
return drupal_url($url["query"], $url["script"]);
// TODO: should use 'url()':
// return drupal_url($url["query"], $url["script"]);
}
function pager_load_array($value, $element, $old_array) {
......
......@@ -3,19 +3,34 @@
include_once "includes/common.inc";
page_header();
check_php_setting("magic_quotes_gpc", 0);
check_php_setting("register_globals", 1);
if ($q) {
$mod = arg(0);
}
if (module_hook(variable_get("site_frontpage", "node"), "page")) {
module_invoke(variable_get("site_frontpage", "node"), "page");
if ($mod && module_hook($mod, "page")) {
if ($mod != "admin") {
page_header();
}
module_invoke($mod, "page");
if ($mod != "admin") {
page_footer();
}
}
else {
$theme->header();
$theme->footer();
}
page_header();
page_footer();
check_php_setting("magic_quotes_gpc", 0);
check_php_setting("register_globals", 1);
if (module_hook(variable_get("site_frontpage", "node"), "page")) {
module_invoke(variable_get("site_frontpage", "node"), "page");
}
else {
$theme->header();
$theme->footer();
}
page_footer();
}
?>
<?php
// $Id$
include_once "includes/common.inc";
if (module_hook($mod, "page")) {
page_header();
module_invoke($mod, "page");
page_footer();
}
else {
header("Location: index.php");
}
?>
<?php
// $Id$
include_once "includes/common.inc";
function status($message) {
if ($message) {
return "<b>Status:</b> $message<hr />\n";
}
}
function admin_page($mod) {
global $user;
if (user_access("access administration pages")) {
page_header();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
<title><?php echo variable_get("site_name", "drupal") . " " . t("administration pages"); ?></title>
<link rel="stylesheet" type="text/css" media="print" href="misc/print.css" />
<style type="text/css" title="layout" media="Screen">
@import url("misc/admin.css");
</style>
</head>
<body>
<?php
// NOTE: we include a dummy "print.css" to remove the "flash of unstyled content" (FUOC) problems in IE.
module_invoke_all("link", "admin");
/*
** Menu:
*/
print "<div id=\"menu\">";
echo "<h1><a href=\"index.php\">". variable_get("site_name", "drupal") ."</a></h1>";
print menu_tree() ;
print "</div>";
/*
** Body:
*/
print "<a href=\"http://drupal.org/\"><img align=\"right\" src=\"misc/druplicon-small.gif\" alt=\"Druplicon - Drupal logo\" border=\"0\" /></a>";
print "<div id=\"main\">";
if ($path = menu_path()) {
print "<h2>". l(t("Administration"), "admin") ." &gt; $path</h2>";
}
else {
print "<h2>". t("Administration") ."</h2>";
}
if ($menu = menu_menu()) {
print "$menu<br />";
}
print "<br /><hr /><br />";
if ($help = menu_help()) {
print "<small>$help</small><br /><br />";
}
if (arg(1)) {
print module_invoke(arg(1), "admin");
}
else {
print watchdog_overview("actions");
}
print "</div>";
db_query("DELETE FROM menu");
?>
</body>
</html>
<?php
page_footer();
}
else {
print message_access();
}
}
?>
This diff is collapsed.
This diff is collapsed.
......@@ -6,22 +6,26 @@ function archive_system($field){
return $system[$field];
}
function archive_display($original = 0) {
function archive_calendar($original = 0) {
// Prevent future dates:
// Extract today's date:
$today = mktime(23, 59, 59, date("n", time()), date("d", time()), date("Y", time()));
$original = (($original && $original <= $today) ? $original : $today);
// Extract information from the given date:
$month = date("n", $original);
$year = date("Y", $original);
$day = date("d", $original);
// Extract the requested date:
if (arg(0) == "archive" && arg(3)) {
$year = arg(1);
$month = arg(2);
$day = arg(3);
// Extract today's date:
$today = mktime(23, 59, 59, date("n", time()), date("d", time()), date("Y", time()));
$requested = mktime(23, 59, 59, $month, $day, $year);
}
else {
$year = date("Y", time());
$month = date("n", time());
$day = date("d", time());
// Extract the timestamp of the last day of today's month:
$thislast = mktime(23, 59, 59, date("n", time()), date("t", time()), date("Y", time()));
$requested = $today;
}
// Extract first day of the month:
$first = date("w", mktime(0, 0, 0, $month, 1, $year));
......@@ -38,7 +42,7 @@ function archive_display($original = 0) {
// Generate calendar header:
$output .= "\n<!-- calendar -->\n";
$output .= "<table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"1\">\n";
$output .= " <tr><td align=\"center\" colspan=\"7\"><small>". lm("&lt;", array("mod" => "archive", "date" => $prev)) ."&nbsp;". date("F Y", $original) ."&nbsp;". ($next <= $thislast ? lm("&gt;", array("mod" => "archive", "date" => $next)) : "&gt;") ."</small></td></tr>\n";
$output .= " <tr><td align=\"center\" colspan=\"7\"><small>". l("&lt;", "archive/". date("Y/m/d", $prev)) ." ". date("F Y", $requested) ." ". ($next <= time() ? l("&gt;", "archive/". date("Y/m/d", $next)) : "&gt;") ."</small></td></tr>\n";
// Generate the days of the week:
$somesunday = mktime(0, 0, 0, 3, 20, 1994);
......@@ -69,15 +73,14 @@ function archive_display($original = 0) {
// Print one cell:
$date = mktime(0, 0, 0, $month, $nday, $year);
if ($date == $original) {
if ($date == $requested) {
$output .= " <td align=\"center\"><small><b>$nday</b></small></td>\n";
}
else if ($date > $today) {
$output .= " <td align=\"center\"><small>$nday</small></td>\n";
}
else {
// due to text-decoration we use drupal_url() instead of lm()
$output .= " <td align=\"center\"><small>". lm($nday, array("mod" => "archive", "date" => $date), "", array("style" => "text-decoration: none;")) ."</small></td>\n";
$output .= " <td align=\"center\"><small>". l($nday, "archive/$year/$month/$nday", array("style" => "text-decoration: none;")) ."</small></td>\n";
}
// Start every week on a new line:
......@@ -112,7 +115,7 @@ function archive_block($op = "list", $delta = 0) {
switch ($delta) {
case 0:
$block["subject"] = t("Browse archives");
$block["content"] = archive_display($date);
$block["content"] = archive_calendar();
return $block;
}
}
......@@ -120,7 +123,7 @@ function archive_block($op = "list", $delta = 0) {
function archive_link($type) {
if ($type == "page" && user_access("access content")) {
$links[] = lm(t("archives"), array("mod" => "archive"), "", array("title" => t("Read the older content in our archive.")));
$links[] = l(t("archives"), "archive", array("title" => t("Read the older content in our archive.")));
}
return $links ? $links : array();
......@@ -132,50 +135,46 @@ function archive_page() {
$theme->header();
if (user_access("access content")) {
if ($op == t("Show")) {
$year = $edit["year"];
$month = $edit["month"];
$day = $edit["day"];
}
else {
$year = arg(1);
$month = arg(2);
$day = arg(3);
}
switch ($op) {
case t("Show"):
$date = mktime(0, 0, 0, $edit["month"], $edit["day"], $edit["year"]);
// Fall though
default:
/*
** Prepare the values of the form fields:
*/
$years = array(2000 => "2000", 2001 => "2001", 2002 => "2002", 2003 => "2003", 2004 => "2004", 2005 => "2005");
$months = array(1 => t("January"), 2 => t("February"), 3 => t("March"), 4 => t("April"), 5 => t("May"), 6 => t("June"), 7 => t("July"), 8 => t("August"), 9 => t("September"), 10 => t("October"), 11 => t("November"), 12 => t("December"));
for ($i = 1; $i <= 31; $i++) $days[$i] = $i;
$date = mktime(0, 0, 0, $month, $day, $year);
/*
** If a timestamp is being specified, extract the date:
*/
/*
** Prepare the values of the form fields:
*/
if ($date) {
$edit["year"] = date("Y", $date);
$edit["month"] = date("m", $date);
$edit["day"] = date("d", $date);
}
$years = array(2000 => "2000", 2001 => "2001", 2002 => "2002", 2003 => "2003", 2004 => "2004", 2005 => "2005");
$months = array(1 => t("January"), 2 => t("February"), 3 => t("March"), 4 => t("April"), 5 => t("May"), 6 => t("June"), 7 => t("July"), 8 => t("August"), 9 => t("September"), 10 => t("October"), 11 => t("November"), 12 => t("December"));
for ($i = 1; $i <= 31; $i++) $days[$i] = $i;