metatag_dc.metatag.inc 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <?php
  2. /**
  3. * @file
  4. * Metatag integration for the metatag_dc module.
  5. */
  6. /**
  7. * Implements hook_metatag_bundled_config_alter().
  8. */
  9. function metatag_dc_metatag_bundled_config_alter(array &$configs) {
  10. foreach ($configs as &$config) {
  11. switch ($config->instance) {
  12. case 'global':
  13. $config->config += array(
  14. 'dcterms.format' => array('value' => 'text/html'),
  15. 'dcterms.identifier' => array('value' => '[current-page:url:absolute]'),
  16. 'dcterms.title' => array('value' => '[current-page:title]'),
  17. 'dcterms.type' => array('value' => 'Text'),
  18. );
  19. break;
  20. case 'global:frontpage':
  21. $config->config += array(
  22. 'dcterms.description' => array('value' => '[site:slogan]'),
  23. 'dcterms.identifier' => array('value' => '[site:url]'),
  24. 'dcterms.title' => array('value' => '[site:name]'),
  25. );
  26. break;
  27. // On error pages point everything to the homepage.
  28. case 'global:403':
  29. case 'global:404':
  30. $config->config += array(
  31. 'dcterms.identifier' => array('value' => '[site:url]'),
  32. 'dcterms.title' => array('value' => '[site:name]'),
  33. );
  34. break;
  35. case 'node':
  36. $config->config += array(
  37. 'dcterms.creator' => array('value' => '[node:author]'),
  38. 'dcterms.date' => array('value' => '[node:created:custom:Y-m-d\TH:iP]'),
  39. 'dcterms.description' => array('value' => '[node:summary]'),
  40. 'dcterms.language' => array('value' => '[node:language]'),
  41. 'dcterms.title' => array('value' => '[node:title]'),
  42. );
  43. break;
  44. case 'taxonomy_term':
  45. $config->config += array(
  46. 'dcterms.description' => array('value' => '[term:description]'),
  47. 'dcterms.title' => array('value' => '[term:name]'),
  48. );
  49. break;
  50. case 'user':
  51. $config->config += array(
  52. 'dcterms.creator' => array('value' => '[user:name]'),
  53. 'dcterms.date' => array('value' => '[user:created:custom:Y-m-d\TH:iP]'),
  54. 'dcterms.title' => array('value' => '[user:name]'),
  55. );
  56. break;
  57. }
  58. }
  59. }
  60. /**
  61. * Implements hook_metatag_info().
  62. * Dublin Core Elements taken from http://purl.org/dc/elements/1.1/.
  63. */
  64. function metatag_dc_metatag_info() {
  65. $info['groups']['dublin-core'] = array(
  66. 'label' => t('Dublin Core Basic Tags'),
  67. 'description' => t('The Dublin Core Metadata Element Set, aka "Dublin Core meta tags", are a set of internationally standardized metadata tags used to describe content to make identification and classification of content easier; the standards are controlled by the <a href="@url">Dublin Core Metadata Initiative (DCMI)</a>.', array('@url' => 'http://dublincore.org/')),
  68. 'form' => array(
  69. '#weight' => 70,
  70. ),
  71. );
  72. // Dublin Core meta tags stack after the Twitter Cards tags.
  73. $weight = 70;
  74. // Basic tags.
  75. $defaults = array(
  76. 'class' => 'DrupalTextMetaTag',
  77. 'group' => 'dublin-core',
  78. 'element' => array(
  79. '#type' => 'term',
  80. '#theme' => 'metatag_dc',
  81. ),
  82. );
  83. $info['tags']['dcterms.title'] = array(
  84. 'label' => t('Title'),
  85. 'description' => t('The name given to the resource.'),
  86. 'element' => array(
  87. '#type' => 'term',
  88. '#theme' => 'metatag_dc',
  89. ),
  90. 'weight' => ++$weight,
  91. ) + $defaults;
  92. $info['tags']['dcterms.creator'] = array(
  93. 'label' => t('Creator'),
  94. 'description' => t('An entity primarily responsible for making the resource. Examples of a Creator include a person, an organization, or a service. Typically, the name of a Creator should be used to indicate the entity.'),
  95. 'weight' => ++$weight,
  96. ) + $defaults;
  97. $info['tags']['dcterms.subject'] = array(
  98. 'label' => t('Subject'),
  99. 'description' => t('The topic of the resource. Typically, the subject will be represented using keywords, key phrases, or classification codes. Recommended best practice is to use a controlled vocabulary. To describe the spatial or temporal topic of the resource, use the Coverage element.'),
  100. 'weight' => ++$weight,
  101. ) + $defaults;
  102. $info['tags']['dcterms.description'] = array(
  103. 'label' => t('Description'),
  104. 'description' => t('An account of the resource. Description may include but is not limited to: an abstract, a table of contents, a graphical representation, or a free-text account of the resource.'),
  105. 'weight' => ++$weight,
  106. ) + $defaults;
  107. $info['tags']['dcterms.publisher'] = array(
  108. 'label' => t('Publisher'),
  109. 'description' => t('An entity responsible for making the resource available. Examples of a Publisher include a person, an organization, or a service. Typically, the name of a Publisher should be used to indicate the entity.'),
  110. 'weight' => ++$weight,
  111. ) + $defaults;
  112. $info['tags']['dcterms.contributor'] = array(
  113. 'label' => t('Contributor'),
  114. 'description' => t('An entity responsible for making contributions to the resource. Examples of a Contributor include a person, an organization, or a service. Typically, the name of a Contributor should be used to indicate the entity.'),
  115. 'weight' => ++$weight,
  116. ) + $defaults;
  117. $info['tags']['dcterms.date'] = array(
  118. 'label' => t('Date'),
  119. 'description' => t('A point or period of time associated with an event in the lifecycle of the resource. Date may be used to express temporal information at any level of granularity. Recommended best practice is to use an encoding scheme, such as the W3CDTF profile of ISO 8601 [W3CDTF].'),
  120. 'weight' => ++$weight,
  121. 'devel_generate' => array(
  122. 'type' => 'date',
  123. ),
  124. ) + $defaults;
  125. $info['tags']['dcterms.type'] = array(
  126. 'label' => t('Type'),
  127. 'description' => t('The nature or genre of the resource. Recommended best practice is to use a controlled vocabulary such as the DCMI Type Vocabulary [DCMITYPE]. To describe the file format, physical medium, or dimensions of the resource, use the Format element.'),
  128. 'form' => array(
  129. '#type' => 'select',
  130. '#options' => _metatag_dc_dcmi_type_vocabulary_options(),
  131. '#empty_option' => t('- None -'),
  132. ),
  133. 'weight' => ++$weight,
  134. ) + $defaults;
  135. $info['tags']['dcterms.format'] = array(
  136. 'label' => t('Format'),
  137. 'description' => t('The file format, physical medium, or dimensions of the resource. Examples of dimensions include size and duration. Recommended best practice is to use a controlled vocabulary such as the list of Internet Media Types [MIME].'),
  138. 'devel_generate' => array(
  139. 'maxlength' => 1,
  140. ),
  141. 'weight' => ++$weight,
  142. ) + $defaults;
  143. $info['tags']['dcterms.identifier'] = array(
  144. 'label' => t('Identifier'),
  145. 'description' => t('An unambiguous reference to the resource within a given context. Recommended best practice is to identify the resource by means of a string conforming to a formal identification system.'),
  146. 'weight' => ++$weight,
  147. ) + $defaults;
  148. $info['tags']['dcterms.source'] = array(
  149. 'label' => t('Source'),
  150. 'description' => t('A related resource from which the described resource is derived. The described resource may be derived from the related resource in whole or in part. Recommended best practice is to identify the related resource by means of a string conforming to a formal identification system.'),
  151. 'weight' => ++$weight,
  152. ) + $defaults;
  153. $info['tags']['dcterms.language'] = array(
  154. 'label' => t('Language'),
  155. 'description' => t('A language of the resource. Recommended best practice is to use a controlled vocabulary such as RFC 4646 [RFC4646].'),
  156. 'is_language' => TRUE,
  157. 'devel_generate' => array(
  158. 'maxlength' => 1,
  159. ),
  160. 'weight' => ++$weight,
  161. ) + $defaults;
  162. $info['tags']['dcterms.relation'] = array(
  163. 'label' => t('Relation'),
  164. 'description' => t('A related resource. Recommended best practice is to identify the related resource by means of a string conforming to a formal identification system.'),
  165. 'weight' => ++$weight,
  166. ) + $defaults;
  167. $info['tags']['dcterms.coverage'] = array(
  168. 'label' => t('Coverage'),
  169. 'description' => t('The spatial or temporal topic of the resource, the spatial applicability of the resource, or the jurisdiction under which the resource is relevant. Spatial topic and spatial applicability may be a named place or a location specified by its geographic coordinates. Temporal topic may be a named period, date, or date range. A jurisdiction may be a named administrative entity or a geographic place to which the resource applies. Recommended best practice is to use a controlled vocabulary such as the Thesaurus of Geographic Names [TGN]. Where appropriate, named places or time periods can be used in preference to numeric identifiers such as sets of coordinates or date ranges.'),
  170. 'weight' => ++$weight,
  171. ) + $defaults;
  172. $info['tags']['dcterms.rights'] = array(
  173. 'label' => t('Rights'),
  174. 'description' => t('Information about rights held in and over the resource. Typically, rights information includes a statement about various property rights associated with the resource, including intellectual property rights.'),
  175. 'weight' => ++$weight,
  176. ) + $defaults;
  177. return $info;
  178. }
  179. /**
  180. * List the DCMI 'type' options.
  181. *
  182. * Types taken from http://dublincore.org/documents/dcmi-type-vocabulary/.
  183. */
  184. function _metatag_dc_dcmi_type_vocabulary_options() {
  185. $options = array(
  186. 'Collection',
  187. 'Dataset',
  188. 'Event',
  189. 'Image',
  190. 'InteractiveResource',
  191. 'MovingImage',
  192. 'PhysicalObject',
  193. 'Service',
  194. 'Software',
  195. 'Sound',
  196. 'StillImage',
  197. 'Text',
  198. );
  199. return drupal_map_assoc($options);
  200. }