diff --git a/includes/common.inc b/includes/common.inc index b7210f6689c61f69241e7fd99fbd9d51ea712120..bae9c25549c88a0e4fab0ab4a9abb7775a98d646 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -1613,7 +1613,6 @@ function drupal_attributes($attributes = array()) { foreach ($attributes as $key => $value) { $t[] = $key .'="'. check_plain($value) .'"'; } - return ' '. implode($t, ' '); } } @@ -1973,6 +1972,14 @@ function clone($object) { '); } +/** + * Add a <link> tag to the page's HEAD. + */ +function drupal_add_link($attributes) { + drupal_set_html_head('<link'. drupal_attributes($attributes) .">\n"); +} + + /** * Add a JavaScript file to the output. * diff --git a/includes/theme.inc b/includes/theme.inc index 6f90399d76f514b082660d6f8ac0458b14041619..fa3a646aac4d71d8ce23b9b278bf1d4b0afbf736 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -501,7 +501,7 @@ function theme_links($links, $delimiter = ' | ') { function theme_image($path, $alt = '', $title = '', $attributes = NULL, $getsize = TRUE) { if (!$getsize || (file_exists($path) && (list($width, $height, $type, $image_attributes) = @getimagesize($path)))) { $attributes = drupal_attributes($attributes); - return "<img src=\"$path\" alt=\"$alt\" title=\"$title\" $image_attributes $attributes />"; + return '<img src="'. check_url($path) .'" alt="'. check_plain($alt) .'" title="'. check_plain($title) .'" '. $image_attributes . $attributes .'/>'; } } diff --git a/modules/blog.module b/modules/blog.module index bbf4e4d220ae1207961569934d5e668e6b60cfdd..31d4689b5496cd4dc57299633b7b87f536404bf7 100644 --- a/modules/blog.module +++ b/modules/blog.module @@ -148,7 +148,10 @@ function blog_page_user($uid) { $output .= theme('pager', NULL, variable_get('default_nodes_main', 10)); $output .= theme('xml_icon', url("blog/$account->uid/feed")); - drupal_set_html_head('<link rel="alternate" type="application/rss+xml" title="RSS - '. $title .'" href="'. url("blog/$account->uid/feed") .'" />'); + drupal_add_link(array('rel' => 'alternate', + 'type' => 'application/rss+xml', + 'title' => t('RSS - %title', array('%title' => $title)), + 'href' => url("blog/$account->uid/feed"))); return $output; } else { @@ -172,7 +175,10 @@ function blog_page_last() { $output .= theme('pager', NULL, variable_get('default_nodes_main', 10)); $output .= theme('xml_icon', url('blog/feed')); - drupal_set_html_head('<link rel="alternate" type="application/rss+xml" title="RSS - blogs" href="'. url('blog/feed') .'" />'); + drupal_add_link(array('rel' => 'alternate', + 'type' => 'application/rss+xml', + 'title' => t('RSS - blogs'), + 'href' => url("blog/feed"))); return $output; } @@ -195,7 +201,8 @@ function blog_form(&$node) { if ($iid && $item = db_fetch_object(db_query('SELECT i.*, f.title as ftitle, f.link as flink FROM {aggregator_item} i, {aggregator_feed} f WHERE i.iid = %d AND i.fid = f.fid', $iid))) { $node->title = $item->title; - $node->body = "<a href=\"$item->link\">$item->title</a> - <em>". $item->description ."</em> [<a href=\"$item->flink\">$item->ftitle</a>]\n"; + // Note: $item->description has been validated on aggregation. + $node->body = '<a href="'. check_url($item->link) .'">'. check_plain($item->title) .'</a> - <em>'. $item->description .'</em> [<a href="'. check_url($item->flink) .'">'. check_plain($item->ftitle) ."</a>]\n"; } } diff --git a/modules/blog/blog.module b/modules/blog/blog.module index bbf4e4d220ae1207961569934d5e668e6b60cfdd..31d4689b5496cd4dc57299633b7b87f536404bf7 100644 --- a/modules/blog/blog.module +++ b/modules/blog/blog.module @@ -148,7 +148,10 @@ function blog_page_user($uid) { $output .= theme('pager', NULL, variable_get('default_nodes_main', 10)); $output .= theme('xml_icon', url("blog/$account->uid/feed")); - drupal_set_html_head('<link rel="alternate" type="application/rss+xml" title="RSS - '. $title .'" href="'. url("blog/$account->uid/feed") .'" />'); + drupal_add_link(array('rel' => 'alternate', + 'type' => 'application/rss+xml', + 'title' => t('RSS - %title', array('%title' => $title)), + 'href' => url("blog/$account->uid/feed"))); return $output; } else { @@ -172,7 +175,10 @@ function blog_page_last() { $output .= theme('pager', NULL, variable_get('default_nodes_main', 10)); $output .= theme('xml_icon', url('blog/feed')); - drupal_set_html_head('<link rel="alternate" type="application/rss+xml" title="RSS - blogs" href="'. url('blog/feed') .'" />'); + drupal_add_link(array('rel' => 'alternate', + 'type' => 'application/rss+xml', + 'title' => t('RSS - blogs'), + 'href' => url("blog/feed"))); return $output; } @@ -195,7 +201,8 @@ function blog_form(&$node) { if ($iid && $item = db_fetch_object(db_query('SELECT i.*, f.title as ftitle, f.link as flink FROM {aggregator_item} i, {aggregator_feed} f WHERE i.iid = %d AND i.fid = f.fid', $iid))) { $node->title = $item->title; - $node->body = "<a href=\"$item->link\">$item->title</a> - <em>". $item->description ."</em> [<a href=\"$item->flink\">$item->ftitle</a>]\n"; + // Note: $item->description has been validated on aggregation. + $node->body = '<a href="'. check_url($item->link) .'">'. check_plain($item->title) .'</a> - <em>'. $item->description .'</em> [<a href="'. check_url($item->flink) .'">'. check_plain($item->ftitle) ."</a>]\n"; } } diff --git a/modules/blogapi.module b/modules/blogapi.module index d836c27fd401e4d06818ae083afa46394aa2fc66..3c6172837c3f3f370f79e63178879dbe05159a57 100644 --- a/modules/blogapi.module +++ b/modules/blogapi.module @@ -530,7 +530,10 @@ function blogapi_menu($may_cache) { $items = array(); if ($_GET['q'] == variable_get('site_frontpage', 'node')) { - drupal_set_html_head('<link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . url('blogapi/rsd', NULL, NULL, TRUE) . '" />'); + drupal_add_link(array('rel' => 'EditURI', + 'type' => 'application/rsd+xml', + 'title' => t('RSD'), + 'href' => url('blogapi/rsd', NULL, NULL, TRUE))); } if ($may_cache) { diff --git a/modules/blogapi/blogapi.module b/modules/blogapi/blogapi.module index d836c27fd401e4d06818ae083afa46394aa2fc66..3c6172837c3f3f370f79e63178879dbe05159a57 100644 --- a/modules/blogapi/blogapi.module +++ b/modules/blogapi/blogapi.module @@ -530,7 +530,10 @@ function blogapi_menu($may_cache) { $items = array(); if ($_GET['q'] == variable_get('site_frontpage', 'node')) { - drupal_set_html_head('<link rel="EditURI" type="application/rsd+xml" title="RSD" href="' . url('blogapi/rsd', NULL, NULL, TRUE) . '" />'); + drupal_add_link(array('rel' => 'EditURI', + 'type' => 'application/rsd+xml', + 'title' => t('RSD'), + 'href' => url('blogapi/rsd', NULL, NULL, TRUE))); } if ($may_cache) { diff --git a/modules/forum.module b/modules/forum.module index f117f6c80986df2cafcf93693fb5697dafeaaeab..6bb116511f0a991a055300d9239c58c0d87f423c 100644 --- a/modules/forum.module +++ b/modules/forum.module @@ -825,7 +825,10 @@ function theme_forum_display($forums, $topics, $parents, $tid, $sortby, $forum_p $output .= theme('forum_list', $forums, $parents, $tid); if ($tid && !in_array($tid, variable_get('forum_containers', array()))) { - drupal_set_html_head('<link rel="alternate" type="application/rss+xml" title="RSS - '. $title .'" href="'. url('taxonomy/term/'. $tid .'/0/feed') .'" />'); + drupal_add_link(array('rel' => 'alternate', + 'type' => 'application/rss+xml', + 'title' => 'RSS - '. $title, + 'href' => url('taxonomy/term/'. $tid .'/0/feed'))); $output .= theme('forum_topic_list', $tid, $topics, $sortby, $forum_per_page); $output .= theme('xml_icon', url("taxonomy/term/$tid/0/feed")); @@ -858,7 +861,7 @@ function theme_forum_list($forums, $parents, $tid) { $description .= ' <div class="name">'. l($forum->name, "forum/$forum->tid") ."</div>\n"; if ($forum->description) { - $description .= " <div class=\"description\">$forum->description</div>\n"; + $description .= ' <div class="description">'. check_plain($forum->description) ."</div>\n"; } $description .= "</div>\n"; @@ -877,7 +880,7 @@ function theme_forum_list($forums, $parents, $tid) { $description .= ' <div class="name">'. l($forum->name, "forum/$forum->tid") ."</div>\n"; if ($forum->description) { - $description .= " <div class=\"description\">$forum->description</div>\n"; + $description .= ' <div class="description">'. check_plain($forum->description) ."</div>\n"; } $description .= "</div>\n"; diff --git a/modules/forum/forum.module b/modules/forum/forum.module index f117f6c80986df2cafcf93693fb5697dafeaaeab..6bb116511f0a991a055300d9239c58c0d87f423c 100644 --- a/modules/forum/forum.module +++ b/modules/forum/forum.module @@ -825,7 +825,10 @@ function theme_forum_display($forums, $topics, $parents, $tid, $sortby, $forum_p $output .= theme('forum_list', $forums, $parents, $tid); if ($tid && !in_array($tid, variable_get('forum_containers', array()))) { - drupal_set_html_head('<link rel="alternate" type="application/rss+xml" title="RSS - '. $title .'" href="'. url('taxonomy/term/'. $tid .'/0/feed') .'" />'); + drupal_add_link(array('rel' => 'alternate', + 'type' => 'application/rss+xml', + 'title' => 'RSS - '. $title, + 'href' => url('taxonomy/term/'. $tid .'/0/feed'))); $output .= theme('forum_topic_list', $tid, $topics, $sortby, $forum_per_page); $output .= theme('xml_icon', url("taxonomy/term/$tid/0/feed")); @@ -858,7 +861,7 @@ function theme_forum_list($forums, $parents, $tid) { $description .= ' <div class="name">'. l($forum->name, "forum/$forum->tid") ."</div>\n"; if ($forum->description) { - $description .= " <div class=\"description\">$forum->description</div>\n"; + $description .= ' <div class="description">'. check_plain($forum->description) ."</div>\n"; } $description .= "</div>\n"; @@ -877,7 +880,7 @@ function theme_forum_list($forums, $parents, $tid) { $description .= ' <div class="name">'. l($forum->name, "forum/$forum->tid") ."</div>\n"; if ($forum->description) { - $description .= " <div class=\"description\">$forum->description</div>\n"; + $description .= ' <div class="description">'. check_plain($forum->description) ."</div>\n"; } $description .= "</div>\n"; diff --git a/modules/node.module b/modules/node.module index d03118ab62379cd95b7014eef4dc98ab7a6f1a34..15bbc9b2448ea71308fb049ef5dc15fe4f5968da 100644 --- a/modules/node.module +++ b/modules/node.module @@ -782,7 +782,7 @@ function node_admin_nodes() { foreach ($edit['nodes'] as $nid => $value) { if ($value) { $title = db_result(db_query('SELECT title FROM {node} WHERE nid = %d', $nid)); - $extra .= '<li>'. form_hidden('nodes]['. $nid, 1) . $title .'</li>'; + $extra .= '<li>'. form_hidden('nodes]['. $nid, 1) . check_plain($title) .'</li>'; } } $extra .= '</ul>'; @@ -1629,7 +1629,10 @@ function node_page_default() { $result = pager_query(db_rewrite_sql('SELECT n.nid, n.sticky, n.created FROM {node} n WHERE n.promote = 1 AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC'), variable_get('default_nodes_main', 10)); if (db_num_rows($result)) { - drupal_set_html_head('<link rel="alternate" type="application/rss+xml" title="RSS" href="'. url('node/feed', NULL, NULL, TRUE) .'" />'); + drupal_add_link(array('rel' => 'alternate', + 'type' => 'application/rss+xml', + 'title' => t('RSS'), + 'href' => url('node/feed', NULL, NULL, TRUE))); $output = ''; while ($node = db_fetch_object($result)) { diff --git a/modules/node/node.module b/modules/node/node.module index d03118ab62379cd95b7014eef4dc98ab7a6f1a34..15bbc9b2448ea71308fb049ef5dc15fe4f5968da 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -782,7 +782,7 @@ function node_admin_nodes() { foreach ($edit['nodes'] as $nid => $value) { if ($value) { $title = db_result(db_query('SELECT title FROM {node} WHERE nid = %d', $nid)); - $extra .= '<li>'. form_hidden('nodes]['. $nid, 1) . $title .'</li>'; + $extra .= '<li>'. form_hidden('nodes]['. $nid, 1) . check_plain($title) .'</li>'; } } $extra .= '</ul>'; @@ -1629,7 +1629,10 @@ function node_page_default() { $result = pager_query(db_rewrite_sql('SELECT n.nid, n.sticky, n.created FROM {node} n WHERE n.promote = 1 AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC'), variable_get('default_nodes_main', 10)); if (db_num_rows($result)) { - drupal_set_html_head('<link rel="alternate" type="application/rss+xml" title="RSS" href="'. url('node/feed', NULL, NULL, TRUE) .'" />'); + drupal_add_link(array('rel' => 'alternate', + 'type' => 'application/rss+xml', + 'title' => t('RSS'), + 'href' => url('node/feed', NULL, NULL, TRUE))); $output = ''; while ($node = db_fetch_object($result)) { diff --git a/modules/poll.module b/modules/poll.module index a9139a2b8af7942ca39516a1d00b0affb6d90579..412144023398bb08d2a2a1ec875c5a1769bf1e28 100644 --- a/modules/poll.module +++ b/modules/poll.module @@ -95,11 +95,12 @@ function poll_validate(&$node) { if (isset($node->title)) { // Check for at least two options and validate amount of votes: $realchoices = 0; + // Renumber fields + $node->choice = array_values($node->choice); foreach ($node->choice as $i => $choice) { if ($choice['chtext'] != '') { $realchoices++; } - if ($choice['chvotes'] < 0) { form_set_error("choice][$i][chvotes", t('Negative values are not allowed.')); } diff --git a/modules/poll/poll.module b/modules/poll/poll.module index a9139a2b8af7942ca39516a1d00b0affb6d90579..412144023398bb08d2a2a1ec875c5a1769bf1e28 100644 --- a/modules/poll/poll.module +++ b/modules/poll/poll.module @@ -95,11 +95,12 @@ function poll_validate(&$node) { if (isset($node->title)) { // Check for at least two options and validate amount of votes: $realchoices = 0; + // Renumber fields + $node->choice = array_values($node->choice); foreach ($node->choice as $i => $choice) { if ($choice['chtext'] != '') { $realchoices++; } - if ($choice['chvotes'] < 0) { form_set_error("choice][$i][chvotes", t('Negative values are not allowed.')); } diff --git a/modules/statistics.module b/modules/statistics.module index 62db34e55e4f84675c02fca499532c60ebfcc6fc..46e521b8021d888f2bdbff2f9515e54411594c61 100644 --- a/modules/statistics.module +++ b/modules/statistics.module @@ -144,11 +144,11 @@ function statistics_access_log($aid) { if ($access = db_fetch_object($result)) { $output = '<table border="1" cellpadding="2" cellspacing="2">'; $output .= ' <tr><th>'. t('Page URL') ."</th><td>". l(url($access->path, NULL, NULL, TRUE), $access->url) ."</td></tr>"; - $output .= ' <tr><th>'. t('Page title') ."</th><td>$access->title</td></tr>"; + $output .= ' <tr><th>'. t('Page title') .'</th><td>'. check_plain($access->title) .'</td></tr>'; $output .= ' <tr><th>'. t('Referrer') ."</th><td>". ($access->url ? l($access->url, $access->url) : '') ."</td></tr>"; $output .= ' <tr><th>'. t('Date') .'</th><td>'. format_date($access->timestamp, 'large') .'</td></tr>'; $output .= ' <tr><th>'. t('User') .'</th><td>'. format_name($access) .'</td></tr>'; - $output .= ' <tr><th>'. t('Hostname') ."</th><td>$access->hostname</td></tr>"; + $output .= ' <tr><th>'. t('Hostname') .'</th><td>'. check_plain($access->hostname) .'</td></tr>'; $output .= '</table>'; return $output; } diff --git a/modules/statistics/statistics.module b/modules/statistics/statistics.module index 62db34e55e4f84675c02fca499532c60ebfcc6fc..46e521b8021d888f2bdbff2f9515e54411594c61 100644 --- a/modules/statistics/statistics.module +++ b/modules/statistics/statistics.module @@ -144,11 +144,11 @@ function statistics_access_log($aid) { if ($access = db_fetch_object($result)) { $output = '<table border="1" cellpadding="2" cellspacing="2">'; $output .= ' <tr><th>'. t('Page URL') ."</th><td>". l(url($access->path, NULL, NULL, TRUE), $access->url) ."</td></tr>"; - $output .= ' <tr><th>'. t('Page title') ."</th><td>$access->title</td></tr>"; + $output .= ' <tr><th>'. t('Page title') .'</th><td>'. check_plain($access->title) .'</td></tr>'; $output .= ' <tr><th>'. t('Referrer') ."</th><td>". ($access->url ? l($access->url, $access->url) : '') ."</td></tr>"; $output .= ' <tr><th>'. t('Date') .'</th><td>'. format_date($access->timestamp, 'large') .'</td></tr>'; $output .= ' <tr><th>'. t('User') .'</th><td>'. format_name($access) .'</td></tr>'; - $output .= ' <tr><th>'. t('Hostname') ."</th><td>$access->hostname</td></tr>"; + $output .= ' <tr><th>'. t('Hostname') .'</th><td>'. check_plain($access->hostname) .'</td></tr>'; $output .= '</table>'; return $output; } diff --git a/modules/taxonomy.module b/modules/taxonomy.module index 6d6b7fb479d9a99578c9414b03fa5d34d31da287..0662c0fca52db8c11927ef9eeda7e44992160564 100644 --- a/modules/taxonomy.module +++ b/modules/taxonomy.module @@ -373,7 +373,7 @@ function taxonomy_overview() { $node_type = node_invoke($type, 'node_name'); $types[] = $node_type ? $node_type : $type; } - $rows[] = array('<strong>'.check_plain($vocabulary->name).'</strong>', implode(', ', $types), l(t('edit vocabulary'), "admin/taxonomy/edit/vocabulary/$vocabulary->vid"), l(t('add term'), "admin/taxonomy/add/term/$vocabulary->vid"), l(t('view terms'), "admin/taxonomy/$vocabulary->vid")); + $rows[] = array('<strong>'. check_plain($vocabulary->name) .'</strong>', implode(', ', $types), l(t('edit vocabulary'), "admin/taxonomy/edit/vocabulary/$vocabulary->vid"), l(t('add term'), "admin/taxonomy/add/term/$vocabulary->vid"), l(t('view terms'), "admin/taxonomy/$vocabulary->vid")); // Show terms if non-free. if (!$vocabulary->tags) { @@ -1082,7 +1082,10 @@ function taxonomy_term_page($str_tids = '', $depth = 0, $op = 'page') { $breadcrumbs = array_reverse($breadcrumbs); menu_set_location($breadcrumbs); - drupal_set_html_head('<link rel="alternate" type="application/rss+xml" title="RSS - '. $title .'" href="'. url('taxonomy/term/'. $rss_tids .'/'. $depth .'/feed') .'" />'); + drupal_add_link(array('rel' => 'alternate', + 'type' => 'application/rss+xml', + 'title' => 'RSS - '. $title, + 'href' => url('taxonomy/term/'. $rss_tids .'/'. $depth .'/feed'))); $output = taxonomy_render_nodes(taxonomy_select_nodes($tids, $operator, $depth, TRUE)); $output .= theme('xml_icon', url("taxonomy/term/$rss_tids/$depth/feed")); diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module index 6d6b7fb479d9a99578c9414b03fa5d34d31da287..0662c0fca52db8c11927ef9eeda7e44992160564 100644 --- a/modules/taxonomy/taxonomy.module +++ b/modules/taxonomy/taxonomy.module @@ -373,7 +373,7 @@ function taxonomy_overview() { $node_type = node_invoke($type, 'node_name'); $types[] = $node_type ? $node_type : $type; } - $rows[] = array('<strong>'.check_plain($vocabulary->name).'</strong>', implode(', ', $types), l(t('edit vocabulary'), "admin/taxonomy/edit/vocabulary/$vocabulary->vid"), l(t('add term'), "admin/taxonomy/add/term/$vocabulary->vid"), l(t('view terms'), "admin/taxonomy/$vocabulary->vid")); + $rows[] = array('<strong>'. check_plain($vocabulary->name) .'</strong>', implode(', ', $types), l(t('edit vocabulary'), "admin/taxonomy/edit/vocabulary/$vocabulary->vid"), l(t('add term'), "admin/taxonomy/add/term/$vocabulary->vid"), l(t('view terms'), "admin/taxonomy/$vocabulary->vid")); // Show terms if non-free. if (!$vocabulary->tags) { @@ -1082,7 +1082,10 @@ function taxonomy_term_page($str_tids = '', $depth = 0, $op = 'page') { $breadcrumbs = array_reverse($breadcrumbs); menu_set_location($breadcrumbs); - drupal_set_html_head('<link rel="alternate" type="application/rss+xml" title="RSS - '. $title .'" href="'. url('taxonomy/term/'. $rss_tids .'/'. $depth .'/feed') .'" />'); + drupal_add_link(array('rel' => 'alternate', + 'type' => 'application/rss+xml', + 'title' => 'RSS - '. $title, + 'href' => url('taxonomy/term/'. $rss_tids .'/'. $depth .'/feed'))); $output = taxonomy_render_nodes(taxonomy_select_nodes($tids, $operator, $depth, TRUE)); $output .= theme('xml_icon', url("taxonomy/term/$rss_tids/$depth/feed")); diff --git a/modules/throttle.module b/modules/throttle.module index 946e83bd728525e64d8cba5d90485557aecaa1f1..a21569242509418726c0ba6c6addeee197db925d 100644 --- a/modules/throttle.module +++ b/modules/throttle.module @@ -63,34 +63,42 @@ function throttle_exit() { } // update the throttle status + $message = ''; if ($max_users && $users > $max_users) { if (!$throttle) { variable_set('throttle_level', 1); - cache_clear_all(); - watchdog('throttle', t('Throttle: %users %user accessing site; throttle enabled.', array('%users' => "<em>$users</em>", '%user' => format_plural($users, 'user', 'users')))); + $message = format_plural($users, + '1 user accessing site; throttle enabled.', + '%count users accessing site; throttle enabled.'); } } elseif ($max_guests && $guests > $max_guests) { if (!$throttle) { variable_set('throttle_level', 1); - cache_clear_all(); - watchdog('throttle', t('Throttle: %guests %guest accessing site; throttle enabled.', array('%guests' => "<em>$guests</em>", '%guest' => format_plural($guests, 'guest', 'guests')))); + $message = format_plural($guests, + '1 guest accessing site; throttle enabled.', + '%count guests accessing site; throttle enabled.'); } } else { if ($throttle) { variable_set('throttle_level', 0); - cache_clear_all(); - watchdog('throttle', t('Throttle: %users %user, %guests %guest accessing site; throttle disabled.', array('%users' => "<em>$users</em>", '%user' => format_plural($users, 'user', 'users'), '%guests' => "<em>$guests</em>", '%guest' => format_plural($guests, 'guest', 'guests')))); + // Note: unorthodox format_plural() usage due to Gettext plural limitations. + $message = format_plural($users, '1 user', '%count users') .', '; + $message .= format_plural($guests, '1 guest accessing site; throttle disabled', '%count guests accessing site; throttle disabled'); } } + if ($message) { + cache_clear_all(); + watchdog('throttle', t('Throttle') .': '. $message); + } } } function _throttle_validate($value, $form) { if ($value != NULL) { if (!is_numeric($value) || $value < 0) { - form_set_error($form, t("'%value' is not a valid auto-throttle setting. Please enter a positive numeric value.", array('%value' => $value))); + form_set_error($form, t("'%value' is not a valid auto-throttle setting. Please enter a positive numeric value.", array('%value' => theme('placeholder', $value)))); } } } diff --git a/modules/throttle/throttle.module b/modules/throttle/throttle.module index 946e83bd728525e64d8cba5d90485557aecaa1f1..a21569242509418726c0ba6c6addeee197db925d 100644 --- a/modules/throttle/throttle.module +++ b/modules/throttle/throttle.module @@ -63,34 +63,42 @@ function throttle_exit() { } // update the throttle status + $message = ''; if ($max_users && $users > $max_users) { if (!$throttle) { variable_set('throttle_level', 1); - cache_clear_all(); - watchdog('throttle', t('Throttle: %users %user accessing site; throttle enabled.', array('%users' => "<em>$users</em>", '%user' => format_plural($users, 'user', 'users')))); + $message = format_plural($users, + '1 user accessing site; throttle enabled.', + '%count users accessing site; throttle enabled.'); } } elseif ($max_guests && $guests > $max_guests) { if (!$throttle) { variable_set('throttle_level', 1); - cache_clear_all(); - watchdog('throttle', t('Throttle: %guests %guest accessing site; throttle enabled.', array('%guests' => "<em>$guests</em>", '%guest' => format_plural($guests, 'guest', 'guests')))); + $message = format_plural($guests, + '1 guest accessing site; throttle enabled.', + '%count guests accessing site; throttle enabled.'); } } else { if ($throttle) { variable_set('throttle_level', 0); - cache_clear_all(); - watchdog('throttle', t('Throttle: %users %user, %guests %guest accessing site; throttle disabled.', array('%users' => "<em>$users</em>", '%user' => format_plural($users, 'user', 'users'), '%guests' => "<em>$guests</em>", '%guest' => format_plural($guests, 'guest', 'guests')))); + // Note: unorthodox format_plural() usage due to Gettext plural limitations. + $message = format_plural($users, '1 user', '%count users') .', '; + $message .= format_plural($guests, '1 guest accessing site; throttle disabled', '%count guests accessing site; throttle disabled'); } } + if ($message) { + cache_clear_all(); + watchdog('throttle', t('Throttle') .': '. $message); + } } } function _throttle_validate($value, $form) { if ($value != NULL) { if (!is_numeric($value) || $value < 0) { - form_set_error($form, t("'%value' is not a valid auto-throttle setting. Please enter a positive numeric value.", array('%value' => $value))); + form_set_error($form, t("'%value' is not a valid auto-throttle setting. Please enter a positive numeric value.", array('%value' => theme('placeholder', $value)))); } } }