metatag_google_plus.module 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * @file
  4. * Primary hook implementations for Metatag: Google+.
  5. */
  6. /**
  7. * Implements hook_ctools_plugin_api().
  8. */
  9. function metatag_google_plus_ctools_plugin_api($owner, $api) {
  10. if ($owner == 'metatag' && $api == 'metatag') {
  11. return array('version' => 1);
  12. }
  13. }
  14. /**
  15. * Implements hook_theme().
  16. */
  17. function metatag_google_plus_theme() {
  18. $info['metatag_google_plus'] = array(
  19. 'render element' => 'element',
  20. );
  21. return $info;
  22. }
  23. /**
  24. * Theme callback for an Google+ meta tag.
  25. *
  26. * The format is:
  27. * <meta itemprop="[itemprop]" content="[value]" />
  28. */
  29. function theme_metatag_google_plus($variables) {
  30. $element = &$variables['element'];
  31. // The format is e.g. 'itemprop:name'. Remove 'itemprop:' and store the rest
  32. // in '#itemprop'.
  33. $element['#itemprop'] = substr($element['#name'], 9);
  34. $args = array(
  35. '#itemprop' => 'itemprop',
  36. '#value' => 'content',
  37. );
  38. element_set_attributes($element, $args);
  39. unset($element['#value']);
  40. return theme('html_tag', $variables);
  41. }
  42. /**
  43. * Implements hook_preprocess_html().
  44. *
  45. * Add itemtype when available.
  46. *
  47. * We will not add itemtype in the rdf_namespaces when using Zen and its derived
  48. * themes as Zen will serialize RDF Namespaces into an RDFa 1.1 prefix
  49. * attribute, which means itemtype will be included in prefix="...".
  50. *
  51. * @see zen_preprocess_html()
  52. */
  53. function metatag_google_plus_preprocess_html(&$variables) {
  54. if (isset($variables['itemtype']) && !function_exists('zen_preprocess_html')) {
  55. $variables['rdf_namespaces'] .= "\n itemscope itemtype= \"http://schema.org/{$variables['itemtype']}\"";
  56. }
  57. }