From f8329dd47cacd51c9d421c980064d0cd7fbc584e Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sat, 27 Apr 2002 13:19:37 +0000 Subject: Patch by Moshe Weitzman: - request_uri() behaves on non-apache web servers. i've tested on IIS and apache (many platforms). - modules may now implement the _search_item() hook which overrides the default formatting of search results. modules already can customize which fields are indexed. no module currently uses this hook but externalpage.module expects to do so. - added an optional $attribs argument to l(), lm(), and la() which is an associative array of attributes which are inserted into the tag (feature #146). - drupal_str_replace() is deleted (i had recently added it). i verified that no scripts are currently calling this function. use strtr() or str_replace() instead. - arbitrary elements may be added to the and blocks of an RSS feed by passing the $args associative array. the core RSS engine is now able to support elements like and [1] and RSS 1.0[2] [1] http://backend.userland.com/rss092 [2] http://groups.yahoo.com/group/rss-dev/files/namespace.html --- includes/common.inc | 85 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 57 insertions(+), 28 deletions(-) (limited to 'includes') diff --git a/includes/common.inc b/includes/common.inc index 1ba5d3ddb..adaf43dbc 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -88,7 +88,16 @@ function path_uri($brief = 0) { } function request_uri() { - return getenv("REQUEST_URI"); + // since request_uri() is only available on apache, we generate equivalent using other environment vars. + + global $REQUEST_URI, $PATH_INFO, $QUERY_STRING; + + if ($REQUEST_URI) { + return $REQUEST_URI; + } + else { + return $PATH_INFO . "?" . $QUERY_STRING; + } } function path_img() { @@ -169,9 +178,20 @@ function variable_del($name) { * @param $type module type of this item */ function search_item($item, $type) { - $output .= " ". $item["count"] . "  ". $item["title"] ."
"; - $output .= " $type ". ($item["user"] ? " - ". $item["user"] : "") ."". ($item["date"] ? " - ". format_date($item["date"], "small") : "") .""; - $output .= "

"; + + /* + ** Modules may implement the "search_item" hook in order to overwrite + ** the default function to display search results. + */ + + if (module_hook($type, "search_item")) { + $output = module_invoke($type, "search_item", $item); + } + else { + $output .= " ". $item["count"] ."  ". $item["title"] ."
"; + $output .= " $type ". ($item["user"] ? " - ". $item["user"] : "") ."". ($item["date"] ? " - ". format_date($item["date"], "small") : "") .""; + $output .= "

"; + } return $output; } @@ -272,21 +292,6 @@ function search_type($type = 0, $action = 0, $query = 0, $options = 0) { return search_form($action, $query, $options) . search_data(); } -function drupal_str_replace($from, $to, $subject) { - - /* - ** Multiple item replace which works for *all* PHP versions - ** (PHP 4.05+ supports this natively using similar syntax). - ** $from and $to should be same sized arrays, $subject is the - ** source text. - */ - - for ($i = 0; $i < count($from); $i++) { - $subject = str_replace($from[$i], $to[$i], $subject); - } - - return $subject; -} function drupal_goto($url) { @@ -394,23 +399,33 @@ function format_info($body, $block) { return "
$block
$body
\n"; } -function format_rss_channel($title, $link, $description, $items, $language = "en") { +function format_rss_channel($title, $link, $description, $items, $language = "en", $args = array()) { + // arbitrary elements may be added using the $args associative array + $output .= "\n"; $output .= " ". htmlentities(strip_tags($title)) ."\n"; $output .= " ". htmlentities(strip_tags($link)) ."\n"; $output .= " ". htmlentities($description) ."\n"; $output .= " ". htmlentities(strip_tags($language)) ."\n"; + foreach ($args as $key => $value) { + $output .= "<$key>" . htmlentities(strip_tags($value)) . ""; + } $output .= $items; $output .= "\n"; return $output; } -function format_rss_item($title, $link, $description) { +function format_rss_item($title, $link, $description, $args = array()) { + // arbitrary elements may be added using the $args associative array + $output .= "\n"; $output .= " ". htmlentities(strip_tags($title)) ."\n"; $output .= " ". htmlentities(strip_tags($link)) ."\n"; $output .= " ". htmlentities($description) ."\n"; + foreach ($args as $key => $value) { + $output .= "<$key>" . htmlentities(strip_tags($value)) . ""; + } $output .= "\n"; return $output; @@ -622,22 +637,35 @@ function drupal_url($args = array(), $script = "node") { * to another drupal page * * @param $args dictionary of arguments to be passed to the script - * @param $linktext text of the link + * @param $text text of the link * @param $title optional, popup title * @param $script script to be invoked; optional, defaults to node + * @param $attributes optional, dictionary of attributes for the tag such as 'target', 'name', 'class', etc. */ -function l($linktext, $args = array(), $title = "", $script = "node") { - return "$linktext"; +function l($text, $args = array(), $title = "", $script = "node", $attributes = array()) { + $t = array(); + foreach ($attributes as $key => $value) { + $t[] = "$key=\"$value\""; + } + return "$text"; } -function la($linktext, $args = array(), $title = "") { +function la($text, $args = array(), $title = "", $attributes = array()) { // we don't call l() to avoid another duplication of the array - return "$linktext"; + $t = array(); + foreach ($attributes as $key => $value) { + $t[] = "$key=\"$value\""; + } + return "$text"; } -function lm($linktext, $args = array(), $title = "") { +function lm($text, $args = array(), $title = "", $attributes = array()) { // we don't call l() to avoid another duplication of the array - return "$linktext"; + $t = array(); + foreach ($attributes as $key => $value) { + $t[] = "$key=\"$value\""; + } + return "$text"; } function field_get($string, $name) { @@ -674,6 +702,7 @@ function link_page() { $links = array_merge($links, module_invoke($name, "link", "page")); } } + return $links; } } -- cgit v1.2.3