Commit 99d84c93 authored by Dries's avatar Dries

- Committed Marco's pager improvements.

- Fixed another annoyance with editing content.
parent 9c11b14d
......@@ -369,19 +369,11 @@ function check_form($text) {
return htmlspecialchars(stripslashes($text));
}
function check_export($text) {
return htmlspecialchars(stripslashes($text));
}
function check_code($text) {
return $text;
}
function check_preview($text) {
return check_output(check_input($text));
function check_query($text) {
return addslashes(stripslashes($text));
}
function check_query($text) {
function check_input($text) {
return addslashes(stripslashes($text));
}
......@@ -395,12 +387,19 @@ function filter($text) {
return $text;
}
function check_input($text) {
return check_query($text);
}
function check_output($text, $nl2br = 0) {
return ($text) ? ($nl2br ? str_replace("\r", "", str_replace("\n", "<br />", stripslashes($text))) : stripslashes($text)) : message_na();
if ($text) {
$text = stripslashes($text);
if (strip_tags($text, "<a><i><b><u><tt><code><cite><strong>") == $text) {
$text = nl2br($text);
}
}
else {
$text = message_na();
}
return $text;
}
function check_file($filename) {
......@@ -640,6 +639,34 @@ function form_weight($title = NULL, $name = "weight", $value = 0, $delta = 10, $
return form_select($title, $name, $value, $weights, $description, $extra);
}
/**
* Parse an URL; this function must be follow the changes of a clean url implementation
*
* @param string $url optional, url to parse; default to request_uri()
* @return array $result associative array:
* script => index/node/module/admin
* query => GET variables
*
*/
function drupal_parse_url($url = NULL) {
global $PHP_SELF;
static $cache;
if ($url == NULL) {
$url = $PHP_SELF ."?". getenv("QUERY_STRING");
}
if (!$cache[$url]) {
$parts = parse_url($url);
preg_match("/(\w+?)\.php/", $parts["path"], $found);
$cache[$url]["script"] = $found[1];
parse_str($parts["query"], $cache[$url]["query"]);
$cache[$url]["anchor"] = $parts["fragment"];
}
return $cache[$url];
}
/**
* Build an URL; use this functions when you must write an URL
* for example in a form or a redirect.
......@@ -649,9 +676,20 @@ function form_weight($title = NULL, $name = "weight", $value = 0, $delta = 10, $
* @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=". urlencode($value);
$t[] = "$key=". str_replace($search, $replace, urlencode($value));
}
if (count($t)) {
return "$script.php?". implode("&amp;", $t) . ($anchor ? "#$anchor" : "");
......
This diff is collapsed.
......@@ -157,7 +157,7 @@ function blog_page_user($uid = 0) {
$links[] = lm(t("view recent blog entries"), array("mod" => "blog", "op" => "view"), "", array("title" => t("View all recent blog entries.")));
$theme->box(t("%username's blog", array ("%username" => $account->name)), "<center>". $theme->links($links). "</center>");
$result = db_query_pager("SELECT nid FROM node WHERE type = 'blog' AND uid = '$account->uid' AND status = 1 ORDER BY nid DESC", $user->nodes ? $user->nodes : variable_get("default_nodes_main", 10));
$result = pager_query("SELECT nid FROM node WHERE type = 'blog' AND uid = '$account->uid' AND status = 1 ORDER BY nid DESC", $user->nodes ? $user->nodes : variable_get("default_nodes_main", 10));
while ($node = db_fetch_object($result)) {
node_view(node_load(array("nid" => $node->nid)), 1);
}
......@@ -168,7 +168,7 @@ function blog_page_user($uid = 0) {
function blog_page_last() {
global $user, $theme;
$result = db_query_pager("SELECT nid FROM node WHERE type = 'blog' AND status = 1 ORDER BY nid DESC", $user->nodes ? $user->nodes : variable_get("default_nodes_main", 10));
$result = pager_query("SELECT nid FROM node WHERE type = 'blog' AND status = 1 ORDER BY nid DESC", $user->nodes ? $user->nodes : variable_get("default_nodes_main", 10));
while ($node = db_fetch_object($result)) {
$output = node_view(node_load(array("nid" => $node->nid)), 1);
......
......@@ -157,7 +157,7 @@ function blog_page_user($uid = 0) {
$links[] = lm(t("view recent blog entries"), array("mod" => "blog", "op" => "view"), "", array("title" => t("View all recent blog entries.")));
$theme->box(t("%username's blog", array ("%username" => $account->name)), "<center>". $theme->links($links). "</center>");
$result = db_query_pager("SELECT nid FROM node WHERE type = 'blog' AND uid = '$account->uid' AND status = 1 ORDER BY nid DESC", $user->nodes ? $user->nodes : variable_get("default_nodes_main", 10));
$result = pager_query("SELECT nid FROM node WHERE type = 'blog' AND uid = '$account->uid' AND status = 1 ORDER BY nid DESC", $user->nodes ? $user->nodes : variable_get("default_nodes_main", 10));
while ($node = db_fetch_object($result)) {
node_view(node_load(array("nid" => $node->nid)), 1);
}
......@@ -168,7 +168,7 @@ function blog_page_user($uid = 0) {
function blog_page_last() {
global $user, $theme;
$result = db_query_pager("SELECT nid FROM node WHERE type = 'blog' AND status = 1 ORDER BY nid DESC", $user->nodes ? $user->nodes : variable_get("default_nodes_main", 10));
$result = pager_query("SELECT nid FROM node WHERE type = 'blog' AND status = 1 ORDER BY nid DESC", $user->nodes ? $user->nodes : variable_get("default_nodes_main", 10));
while ($node = db_fetch_object($result)) {
$output = node_view(node_load(array("nid" => $node->nid)), 1);
......
......@@ -399,16 +399,6 @@ function node_filter_line($text) {
** mark-up and use of line breaks and paragraphs.
*/
/*
** When block tags are used, regular line breaks get stripped.
** However, when only text formatting tags are used, Drupal will
** insert linebreaks.
*/
if (strip_tags($text, "<a><i><b><u><tt><code><cite><strong>") != $text) {
$text = ereg_replace("[\r\n]", "", $text);
}
/*
** Replace some common "artifacts":
*/
......@@ -549,7 +539,7 @@ function node_admin_nodes() {
$queries = array(array("ORDER BY n.created DESC", "new nodes"), array("ORDER BY n.changed DESC", "updated nodes"), array("WHERE n.status = 1 AND n.moderate = 0 ORDER BY n.nid DESC", "published nodes"), array("WHERE n.status = 0 AND n.moderate = 0 ORDER BY n.nid DESC", "non-published nodes"), array("WHERE n.status = 1 AND n.moderate = 1 ORDER BY n.nid DESC", "pending nodes"), array("WHERE n.status = 1 AND n.promote = 1 ORDER BY n.nid DESC", "promoted nodes"));
$result = db_query_pager("SELECT n.*, u.name, u.uid FROM node n LEFT JOIN users u ON n.uid = u.uid ". $queries[$query ? $query : 1][0], 50);
$result = pager_query("SELECT n.*, u.name, u.uid FROM node n LEFT JOIN users u ON n.uid = u.uid ". $queries[$query ? $query : 1][0], 50);
foreach ($queries as $key => $value) {
$links[] = la($value[1], array("mod" => "node", "op" => "nodes", "query" => $key));
......@@ -1348,14 +1338,14 @@ function node_page() {
if ($or) {
// this is an OR of terms
$result = db_query_pager("SELECT DISTINCT(n.nid), type FROM node n LEFT JOIN term_node r ON n.nid = r.nid WHERE tid IN (".implode(",", $terms).") AND ". ($id ? "nid = '$id' AND " : "") ."status = '1' ORDER BY static DESC, created DESC", ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10)));
$result = pager_query("SELECT DISTINCT(n.nid), type FROM node n LEFT JOIN term_node r ON n.nid = r.nid WHERE tid IN (".implode(",", $terms).") AND ". ($id ? "nid = '$id' AND " : "") ."status = '1' ORDER BY static DESC, created DESC", ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10)));
}
else if ($and) {
// this is an AND
$result = db_query_pager("SELECT n.nid, n.type FROM node n LEFT JOIN term_node r ON n.nid = r.nid WHERE tid IN (".implode(",", $terms).") AND ". ($id ? "nid = '$id' AND " : "") ."status = '1' GROUP BY n.nid, n.type, n.status, n.static, n.created HAVING COUNT(n.nid) = ".count($terms)." ORDER BY static DESC, created DESC", ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10)));
$result = pager_query("SELECT n.nid, n.type FROM node n LEFT JOIN term_node r ON n.nid = r.nid WHERE tid IN (".implode(",", $terms).") AND ". ($id ? "nid = '$id' AND " : "") ."status = '1' GROUP BY n.nid, n.type, n.status, n.static, n.created HAVING COUNT(n.nid) = ".count($terms)." ORDER BY static DESC, created DESC", ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10)));
}
else {
$result = db_query_pager("SELECT nid, type FROM node WHERE ". ($id ? "nid = '$id'" : "promote = '1'") ." AND status = '1' ORDER BY static DESC, created DESC", ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10)));
$result = pager_query("SELECT nid, type FROM node WHERE ". ($id ? "nid = '$id'" : "promote = '1'") ." AND status = '1' ORDER BY static DESC, created DESC", ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10)));
}
......
......@@ -399,16 +399,6 @@ function node_filter_line($text) {
** mark-up and use of line breaks and paragraphs.
*/
/*
** When block tags are used, regular line breaks get stripped.
** However, when only text formatting tags are used, Drupal will
** insert linebreaks.
*/
if (strip_tags($text, "<a><i><b><u><tt><code><cite><strong>") != $text) {
$text = ereg_replace("[\r\n]", "", $text);
}
/*
** Replace some common "artifacts":
*/
......@@ -549,7 +539,7 @@ function node_admin_nodes() {
$queries = array(array("ORDER BY n.created DESC", "new nodes"), array("ORDER BY n.changed DESC", "updated nodes"), array("WHERE n.status = 1 AND n.moderate = 0 ORDER BY n.nid DESC", "published nodes"), array("WHERE n.status = 0 AND n.moderate = 0 ORDER BY n.nid DESC", "non-published nodes"), array("WHERE n.status = 1 AND n.moderate = 1 ORDER BY n.nid DESC", "pending nodes"), array("WHERE n.status = 1 AND n.promote = 1 ORDER BY n.nid DESC", "promoted nodes"));
$result = db_query_pager("SELECT n.*, u.name, u.uid FROM node n LEFT JOIN users u ON n.uid = u.uid ". $queries[$query ? $query : 1][0], 50);
$result = pager_query("SELECT n.*, u.name, u.uid FROM node n LEFT JOIN users u ON n.uid = u.uid ". $queries[$query ? $query : 1][0], 50);
foreach ($queries as $key => $value) {
$links[] = la($value[1], array("mod" => "node", "op" => "nodes", "query" => $key));
......@@ -1348,14 +1338,14 @@ function node_page() {
if ($or) {
// this is an OR of terms
$result = db_query_pager("SELECT DISTINCT(n.nid), type FROM node n LEFT JOIN term_node r ON n.nid = r.nid WHERE tid IN (".implode(",", $terms).") AND ". ($id ? "nid = '$id' AND " : "") ."status = '1' ORDER BY static DESC, created DESC", ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10)));
$result = pager_query("SELECT DISTINCT(n.nid), type FROM node n LEFT JOIN term_node r ON n.nid = r.nid WHERE tid IN (".implode(",", $terms).") AND ". ($id ? "nid = '$id' AND " : "") ."status = '1' ORDER BY static DESC, created DESC", ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10)));
}
else if ($and) {
// this is an AND
$result = db_query_pager("SELECT n.nid, n.type FROM node n LEFT JOIN term_node r ON n.nid = r.nid WHERE tid IN (".implode(",", $terms).") AND ". ($id ? "nid = '$id' AND " : "") ."status = '1' GROUP BY n.nid, n.type, n.status, n.static, n.created HAVING COUNT(n.nid) = ".count($terms)." ORDER BY static DESC, created DESC", ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10)));
$result = pager_query("SELECT n.nid, n.type FROM node n LEFT JOIN term_node r ON n.nid = r.nid WHERE tid IN (".implode(",", $terms).") AND ". ($id ? "nid = '$id' AND " : "") ."status = '1' GROUP BY n.nid, n.type, n.status, n.static, n.created HAVING COUNT(n.nid) = ".count($terms)." ORDER BY static DESC, created DESC", ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10)));
}
else {
$result = db_query_pager("SELECT nid, type FROM node WHERE ". ($id ? "nid = '$id'" : "promote = '1'") ." AND status = '1' ORDER BY static DESC, created DESC", ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10)));
$result = pager_query("SELECT nid, type FROM node WHERE ". ($id ? "nid = '$id'" : "promote = '1'") ." AND status = '1' ORDER BY static DESC, created DESC", ($user->nodes ? $user->nodes : variable_get("default_nodes_main", 10)));
}
......
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