summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-11-03 06:47:23 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-11-03 06:47:23 +0000
commit0d8515deb750fe2a02ee6f9f12860caceed7248f (patch)
tree9898c0801cec5188f8e54229a2760a4ff15f44f5 /modules
parent3b2d24af0b8ca83415310e2b328cc60fa830837b (diff)
downloadbrdo-0d8515deb750fe2a02ee6f9f12860caceed7248f.tar.gz
brdo-0d8515deb750fe2a02ee6f9f12860caceed7248f.tar.bz2
#552478 by pwolanin, samj, dropcube, and sun: Improve link/header API and support on node/comment pages rel=canonical and rel=shortlink standards.
Diffstat (limited to 'modules')
-rw-r--r--modules/book/book.module6
-rw-r--r--modules/comment/comment.module3
-rw-r--r--modules/node/node.module4
-rw-r--r--modules/openid/tests/openid_test.module13
-rw-r--r--modules/rdf/rdf.module15
-rw-r--r--modules/simpletest/tests/browser_test.module9
-rw-r--r--modules/simpletest/tests/common.test2
-rw-r--r--modules/system/system.api.php21
-rw-r--r--modules/system/system.module46
9 files changed, 64 insertions, 55 deletions
diff --git a/modules/book/book.module b/modules/book/book.module
index a8425033e..834823272 100644
--- a/modules/book/book.module
+++ b/modules/book/book.module
@@ -940,21 +940,21 @@ function template_preprocess_book_navigation(&$variables) {
if ($prev = book_prev($book_link)) {
$prev_href = url($prev['href']);
- drupal_add_link(array('rel' => 'prev', 'href' => $prev_href));
+ drupal_add_html_head_link(array('rel' => 'prev', 'href' => $prev_href));
$variables['prev_url'] = $prev_href;
$variables['prev_title'] = check_plain($prev['title']);
}
if ($book_link['plid'] && $parent = book_link_load($book_link['plid'])) {
$parent_href = url($parent['href']);
- drupal_add_link(array('rel' => 'up', 'href' => $parent_href));
+ drupal_add_html_head_link(array('rel' => 'up', 'href' => $parent_href));
$variables['parent_url'] = $parent_href;
$variables['parent_title'] = check_plain($parent['title']);
}
if ($next = book_next($book_link)) {
$next_href = url($next['href']);
- drupal_add_link(array('rel' => 'next', 'href' => $next_href));
+ drupal_add_html_head_link(array('rel' => 'next', 'href' => $next_href));
$variables['next_url'] = $next_href;
$variables['next_title'] = check_plain($next['title']);
}
diff --git a/modules/comment/comment.module b/modules/comment/comment.module
index 762c71749..07fd233e3 100644
--- a/modules/comment/comment.module
+++ b/modules/comment/comment.module
@@ -362,9 +362,6 @@ function comment_permalink($comment) {
$_GET['q'] = 'node/' . $node->nid;
$_GET['page'] = $page;
- // Set the node path as the canonical URL to prevent duplicate content.
- drupal_add_link(array('rel' => 'canonical', 'href' => url('node/' . $node->nid)));
-
// Return the node view, this will show the correct comment in context.
return menu_execute_active_handler('node/' . $node->nid, FALSE);
}
diff --git a/modules/node/node.module b/modules/node/node.module
index 84cc776ff..735fc30c4 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -2152,6 +2152,10 @@ function node_page_view(stdClass $node) {
if (isset($return['nodes'][$node->nid]['title'])) {
drupal_set_title($return['nodes'][$node->nid]['title']['items'][0]['#item']['value']);
}
+ // Set the node path as the canonical URL to prevent duplicate content.
+ drupal_add_html_head_link(array('rel' => 'canonical', 'href' => url('node/' . $node->nid)), TRUE);
+ // Set the non-aliased path as a default shortlink.
+ drupal_add_html_head_link(array('rel' => 'shortlink', 'href' => url('node/' . $node->nid, array('alias' => TRUE))), TRUE);
return $return;
}
diff --git a/modules/openid/tests/openid_test.module b/modules/openid/tests/openid_test.module
index 325e67d01..d8d914c22 100644
--- a/modules/openid/tests/openid_test.module
+++ b/modules/openid/tests/openid_test.module
@@ -97,7 +97,14 @@ function openid_test_yadis_x_xrds_location() {
* Menu callback; regular HTML page with <meta> element.
*/
function openid_test_yadis_http_equiv() {
- drupal_add_html_head('<meta http-equiv="X-XRDS-Location" content="' . url('openid-test/yadis/xrds', array('absolute' => TRUE)) . '" />');
+ $element = array(
+ '#tag' => 'meta',
+ '#attributes' => array(
+ 'http-equiv' => 'X-XRDS-Location',
+ 'content' => url('openid-test/yadis/xrds', array('absolute' => TRUE)),
+ ),
+ );
+ drupal_add_html_head($element, 'openid_test_yadis_http_equiv');
return t('This page includes a &lt;meta equiv=...&gt; element containing the URL of an XRDS document.');
}
@@ -105,7 +112,7 @@ function openid_test_yadis_http_equiv() {
* Menu callback; regular HTML page with OpenID 1.0 <link> element.
*/
function openid_test_html_openid1() {
- drupal_add_html_head('<link rel="openid.server" href="' . url('openid-test/endpoint', array('absolute' => TRUE)) . '" />');
+ drupal_add_html_head_link(array('rel' => 'openid.server', 'href' => url('openid-test/endpoint', array('absolute' => TRUE))));
return t('This page includes a &lt;link rel=...&gt; element containing the URL of an OpenID Provider Endpoint.');
}
@@ -113,7 +120,7 @@ function openid_test_html_openid1() {
* Menu callback; regular HTML page with OpenID 2.0 <link> element.
*/
function openid_test_html_openid2() {
- drupal_add_html_head('<link rel="openid2.provider" href="' . url('openid-test/endpoint', array('absolute' => TRUE)) . '" />');
+ drupal_add_html_head_link(array('rel' => 'openid2.provider', 'href' => url('openid-test/endpoint', array('absolute' => TRUE))));
return t('This page includes a &lt;link rel=...&gt; element containing the URL of an OpenID Provider Endpoint.');
}
diff --git a/modules/rdf/rdf.module b/modules/rdf/rdf.module
index b520bfb96..7da53d86b 100644
--- a/modules/rdf/rdf.module
+++ b/modules/rdf/rdf.module
@@ -384,10 +384,17 @@ function rdf_preprocess_node(&$variables) {
// In full node mode, the title is not displayed by node.tpl.php so it is
// added in the head tag of the HTML page.
if ($variables['page']) {
- $title_attributes['property'] = empty($variables['node']->rdf_mapping['title']['predicates']) ? NULL : $variables['node']->rdf_mapping['title']['predicates'];
- $title_attributes['content'] = $variables['node_title'];
- $title_attributes['about'] = $variables['node_url'];
- drupal_add_html_head('<meta' . drupal_attributes($title_attributes) . ' />');
+ $element = array(
+ '#tag' => 'meta',
+ '#attributes' => array(
+ 'content' => $variables['node_title'],
+ 'about' => $variables['node_url'],
+ ),
+ );
+ if (!empty($variables['node']->rdf_mapping['title']['predicates'])) {
+ $element['#attributes']['property'] = $variables['node']->rdf_mapping['title']['predicates'];
+ }
+ drupal_add_html_head($element, 'rdf_node');
}
// Adds RDFa markup for the date.
diff --git a/modules/simpletest/tests/browser_test.module b/modules/simpletest/tests/browser_test.module
index 7fee6666a..fcd8b6d36 100644
--- a/modules/simpletest/tests/browser_test.module
+++ b/modules/simpletest/tests/browser_test.module
@@ -57,7 +57,14 @@ function browser_test_print_post_form_submit($form, &$form_state) {
function browser_test_refresh_meta() {
if (!isset($_GET['refresh'])) {
$url = url('browser_test/refresh/meta', array('absolute' => TRUE, 'query' => array('refresh' => 'true')));
- drupal_add_html_head('<meta http-equiv="Refresh" content="0; URL=' . $url . '">');
+ $element = array(
+ '#tag' => 'meta',
+ '#attributes' => array(
+ 'http-equiv' => 'Refresh',
+ 'content' => '0; URL=' . $url,
+ ),
+ );
+ drupal_add_html_head($element, 'browser_test_refresh_meta');
return '';
}
echo 'Refresh successful';
diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test
index 135ca18cb..5672961f3 100644
--- a/modules/simpletest/tests/common.test
+++ b/modules/simpletest/tests/common.test
@@ -530,7 +530,7 @@ class CascadingStylesheetsTestCase extends DrupalWebTestCase {
$css_preprocessed = '<style type="text/css">' . drupal_load_stylesheet_content($css, TRUE) . '</style>';
drupal_add_css($css, 'inline');
$styles = drupal_get_css();
- $this->assertEqual($styles, "\n" . $css_preprocessed, t('Rendering preprocessed inline CSS adds it to the page.'));
+ $this->assertEqual($styles, "\n" . $css_preprocessed . "\n", t('Rendering preprocessed inline CSS adds it to the page.'));
}
/**
diff --git a/modules/system/system.api.php b/modules/system/system.api.php
index 36a06df8d..339f82d04 100644
--- a/modules/system/system.api.php
+++ b/modules/system/system.api.php
@@ -2282,6 +2282,27 @@ function hook_drupal_goto_alter(&$path, &$options, &$http_response_code) {
}
/**
+ * Alter XHTML HEAD tags before they are rendered by drupal_get_html_head().
+ *
+ * Elements available to be altered are only those added using
+ * drupal_add_html_head_link() or drupal_add_html_head(). CSS and JS files
+ * are handled using drupal_add_css() and drupal_add_js(), so the head links
+ * for those files will not appear in the $head_elements array.
+ *
+ * @param $head_elements
+ * An array of renderable elements. Generally the values of the #attributes
+ * array will be the most likely target for changes.
+ */
+function hook_html_head_alter(&$head_elements) {
+ foreach($head_elements as $key => $element) {
+ if (isset($element['#attributes']['rel']) && $element['#attributes']['rel'] == 'canonical') {
+ // I want a custom canonical url.
+ $head_elements[$key]['#attributes']['href'] = mymodule_canonical_url();
+ }
+ }
+}
+
+/**
* Alter the full list of installation tasks.
*
* @param $tasks
diff --git a/modules/system/system.module b/modules/system/system.module
index 0b587db77..da1089b92 100644
--- a/modules/system/system.module
+++ b/modules/system/system.module
@@ -179,12 +179,6 @@ function system_theme() {
'system_powered_by' => array(
'variables' => array(),
),
- 'meta_generator_html' => array(
- 'variables' => array('version' => NULL),
- ),
- 'meta_generator_header' => array(
- 'variables' => array('version' => NULL),
- ),
'system_compact_link' => array(
'variables' => array(),
),
@@ -318,6 +312,12 @@ function system_element_info() {
'#ajax_commands' => array(),
);
+ $types['html_tag'] = array(
+ '#theme' => 'html_tag',
+ '#attributes' => array(),
+ '#value' => NULL,
+ );
+
// Input elements.
$types['submit'] = array(
'#input' => TRUE,
@@ -1718,22 +1718,6 @@ function system_init() {
}
/**
- * Implement MODULE_preprocess_HOOK().
- */
-function system_preprocess_page(&$variables) {
- // Get the major version
- list($version, ) = explode('.', VERSION);
-
- // Emit the META tag in the HTML HEAD section
- theme('meta_generator_html', array('version' => $version));
-
- // Emit the HTTP Header too
- theme('meta_generator_header', array('version' => $version));
-
- $variables['head'] = drupal_get_html_head();
-}
-
-/**
* Implement hook_form_FORM_ID_alter().
*/
function system_form_user_profile_form_alter(&$form, &$form_state) {
@@ -2974,24 +2958,6 @@ function theme_system_compact_link() {
}
/**
- * Send Drupal and the major version number in the META GENERATOR HTML.
- *
- * @ingroup themeable
- */
-function theme_meta_generator_html($variables) {
- drupal_add_html_head('<meta name="Generator" content="Drupal ' . $variables['version'] . ' (http://drupal.org)" />');
-}
-
-/**
- * Send Drupal and the major version number in the HTTP headers.
- *
- * @ingroup themeable
- */
-function theme_meta_generator_header($variables) {
- drupal_add_http_header('X-Generator', 'Drupal ' . $variables['version'] . ' (http://drupal.org)');
-}
-
-/**
* Implement hook_image_toolkits().
*/
function system_image_toolkits() {