Commit a597354b authored by Steven Wittens's avatar Steven Wittens

- Code cleanup: improve format_plural usage, add some missing...

- Code cleanup: improve format_plural usage, add some missing placeholder/check calls, and introduce API for <link> tags.
parent 025bca28
......@@ -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.
*
......
......@@ -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 .'/>';
}
}
......
......@@ -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";
}
}
......
......@@ -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";
}
}
......
......@@ -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) {
......
......@@ -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) {
......
......@@ -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";
......
......@@ -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";
......
......@@ -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)) {
......
......@@ -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)) {
......
......@@ -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.'));
}
......
......@@ -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.'));
}
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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"));
......
......@@ -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"));
......
......@@ -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))));
}
}
}
......
......@@ -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))));
}
}
}
......
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