metatag_google_plus.module 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. * Note: The $schemaorg variable must be added to the html tag of the
  48. * html.tpl.php template after the $rdf_namespaces variable, see README.txt
  49. * for details.
  50. */
  51. function metatag_google_plus_preprocess_html(&$variables) {
  52. if (!isset($variables['schemaorg'])) {
  53. $variables['schemaorg'] = '';
  54. }
  55. if (isset($variables['itemtype']) && !function_exists('zen_preprocess_html')) {
  56. $variables['schemaorg'] .= " itemscope itemtype=\"http://schema.org/{$variables['itemtype']}\"";
  57. }
  58. }