diff options
Diffstat (limited to 'includes')
-rw-r--r-- | includes/common.inc | 118 | ||||
-rw-r--r-- | includes/conf.php | 5 | ||||
-rw-r--r-- | includes/menu.inc | 8 | ||||
-rw-r--r-- | includes/module.inc | 1 | ||||
-rw-r--r-- | includes/pager.inc | 3 |
5 files changed, 47 insertions, 88 deletions
diff --git a/includes/common.inc b/includes/common.inc index 2acf36743..b22238693 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -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("&", $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")); diff --git a/includes/conf.php b/includes/conf.php index bebc4f491..b4c97313f 100644 --- a/includes/conf.php +++ b/includes/conf.php @@ -45,8 +45,7 @@ $languages = array("en" => "English"); # 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>"); ?> diff --git a/includes/menu.inc b/includes/menu.inc index fff05a4d8..345f42d03 100644 --- a/includes/menu.inc +++ b/includes/menu.inc @@ -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) { diff --git a/includes/module.inc b/includes/module.inc index e9994ba15..63e67801c 100644 --- a/includes/module.inc +++ b/includes/module.inc @@ -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"; diff --git a/includes/pager.inc b/includes/pager.inc index 8f93a5a54..0ec810171 100644 --- a/includes/pager.inc +++ b/includes/pager.inc @@ -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) { |