metatag_dc.metatag.inc 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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.modified' => array('value' => '[node:changed:custom:Y-m-d\TH:iP]'),
  40. 'dcterms.description' => array('value' => '[node:summary]'),
  41. 'dcterms.language' => array('value' => '[node:language]'),
  42. 'dcterms.title' => array('value' => '[node:title]'),
  43. );
  44. break;
  45. case 'taxonomy_term':
  46. $config->config += array(
  47. 'dcterms.description' => array('value' => '[term:description]'),
  48. 'dcterms.title' => array('value' => '[term:name]'),
  49. );
  50. break;
  51. case 'user':
  52. $config->config += array(
  53. 'dcterms.creator' => array('value' => '[user:name]'),
  54. 'dcterms.date' => array('value' => '[user:created:custom:Y-m-d\TH:iP]'),
  55. 'dcterms.title' => array('value' => '[user:name]'),
  56. );
  57. break;
  58. }
  59. }
  60. }
  61. /**
  62. * Implements hook_metatag_info().
  63. * Dublin Core Elements taken from http://purl.org/dc/elements/1.1/.
  64. */
  65. function metatag_dc_metatag_info() {
  66. $info['groups']['dublin-core'] = array(
  67. 'label' => t('Dublin Core'),
  68. '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="http://dublincore.org/">Dublin Core Metadata Initiative (DCMI)</a>.'),
  69. 'form' => array(
  70. '#weight' => 70,
  71. ),
  72. );
  73. // Dublin Core meta tags stack after the Twitter Cards tags.
  74. $weight = 70;
  75. $info['tags']['dcterms.title'] = array(
  76. 'label' => t('Dublin Core Title'),
  77. 'description' => t('The name given to the resource.'),
  78. 'class' => 'DrupalTextMetaTag',
  79. 'group' => 'dublin-core',
  80. 'element' => array(
  81. '#type' => 'term',
  82. '#theme' => 'metatag_dc',
  83. ),
  84. 'weight' => ++$weight,
  85. );
  86. $info['tags']['dcterms.creator'] = array(
  87. 'label' => t('Dublin Core Creator'),
  88. '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.'),
  89. 'group' => 'dublin-core',
  90. 'class' => 'DrupalTextMetaTag',
  91. 'element' => array(
  92. '#theme' => 'metatag_dc',
  93. ),
  94. 'weight' => ++$weight,
  95. );
  96. $info['tags']['dcterms.subject'] = array(
  97. 'label' => t('Dublin Core Subject'),
  98. '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.'),
  99. 'class' => 'DrupalTextMetaTag',
  100. 'group' => 'dublin-core',
  101. 'element' => array(
  102. '#theme' => 'metatag_dc',
  103. ),
  104. 'weight' => ++$weight,
  105. );
  106. $info['tags']['dcterms.description'] = array(
  107. 'label' => t('Dublin Core Description'),
  108. '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.'),
  109. 'group' => 'dublin-core',
  110. 'class' => 'DrupalTextMetaTag',
  111. 'element' => array(
  112. '#theme' => 'metatag_dc',
  113. ),
  114. 'weight' => ++$weight,
  115. );
  116. $info['tags']['dcterms.publisher'] = array(
  117. 'label' => t('Dublin Core Publisher'),
  118. '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.'),
  119. 'group' => 'dublin-core',
  120. 'class' => 'DrupalTextMetaTag',
  121. 'element' => array(
  122. '#theme' => 'metatag_dc',
  123. ),
  124. 'weight' => ++$weight,
  125. );
  126. $info['tags']['dcterms.contributor'] = array(
  127. 'label' => t('Dublin Core Contributor'),
  128. '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.'),
  129. 'group' => 'dublin-core',
  130. 'class' => 'DrupalTextMetaTag',
  131. 'element' => array(
  132. '#theme' => 'metatag_dc',
  133. ),
  134. 'weight' => ++$weight,
  135. );
  136. $info['tags']['dcterms.date'] = array(
  137. 'label' => t('Dublin Core Date'),
  138. '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].'),
  139. 'class' => 'DrupalTextMetaTag',
  140. 'group' => 'dublin-core',
  141. 'element' => array(
  142. '#theme' => 'metatag_dc',
  143. ),
  144. 'weight' => ++$weight,
  145. 'devel_generate' => array(
  146. 'type' => 'date',
  147. ),
  148. );
  149. $info['tags']['dcterms.modified'] = array(
  150. 'label' => t('Dublin Core Modified Date'),
  151. 'description' => t('Date on which the resource was changed.'),
  152. 'class' => 'DrupalTextMetaTag',
  153. 'group' => 'dublin-core',
  154. 'element' => array(
  155. '#theme' => 'metatag_dc',
  156. ),
  157. 'weight' => ++$weight,
  158. 'devel_generate' => array(
  159. 'type' => 'date',
  160. ),
  161. );
  162. $info['tags']['dcterms.type'] = array(
  163. 'label' => t('Dublin Core Type'),
  164. '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.'),
  165. 'class' => 'DrupalTextMetaTag',
  166. 'group' => 'dublin-core',
  167. 'form' => array(
  168. '#type' => 'select',
  169. '#options' => _metatag_dc_dcmi_type_vocabulary_options(),
  170. '#empty_option' => t('- None -'),
  171. ),
  172. 'element' => array(
  173. '#theme' => 'metatag_dc',
  174. ),
  175. 'weight' => ++$weight,
  176. );
  177. $info['tags']['dcterms.format'] = array(
  178. 'label' => t('Dublin Core Format'),
  179. '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].'),
  180. 'class' => 'DrupalTextMetaTag',
  181. 'group' => 'dublin-core',
  182. 'element' => array(
  183. '#theme' => 'metatag_dc',
  184. ),
  185. 'devel_generate' => array(
  186. 'maxlength' => 1,
  187. ),
  188. 'weight' => ++$weight,
  189. );
  190. $info['tags']['dcterms.identifier'] = array(
  191. 'label' => t('Dublin Core Identifier'),
  192. '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.'),
  193. 'class' => 'DrupalTextMetaTag',
  194. 'group' => 'dublin-core',
  195. 'element' => array(
  196. '#theme' => 'metatag_dc',
  197. ),
  198. 'weight' => ++$weight,
  199. );
  200. $info['tags']['dcterms.source'] = array(
  201. 'label' => t('Dublin Core Source'),
  202. '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.'),
  203. 'group' => 'dublin-core',
  204. 'class' => 'DrupalTextMetaTag',
  205. 'element' => array(
  206. '#theme' => 'metatag_dc',
  207. ),
  208. 'weight' => ++$weight,
  209. );
  210. $info['tags']['dcterms.language'] = array(
  211. 'label' => t('Dublin Core Language'),
  212. 'description' => t('A language of the resource. Recommended best practice is to use a controlled vocabulary such as RFC 4646 [RFC4646].'),
  213. 'class' => 'DrupalTextMetaTag',
  214. 'group' => 'dublin-core',
  215. 'element' => array(
  216. '#theme' => 'metatag_dc',
  217. ),
  218. 'devel_generate' => array(
  219. 'maxlength' => 1,
  220. ),
  221. 'weight' => ++$weight,
  222. );
  223. $info['tags']['dcterms.relation'] = array(
  224. 'label' => t('Dublin Core Relation'),
  225. '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.'),
  226. 'group' => 'dublin-core',
  227. 'class' => 'DrupalTextMetaTag',
  228. 'element' => array(
  229. '#theme' => 'metatag_dc',
  230. ),
  231. 'weight' => ++$weight,
  232. );
  233. $info['tags']['dcterms.coverage'] = array(
  234. 'label' => t('Dublin Core Coverage'),
  235. '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.'),
  236. 'group' => 'dublin-core',
  237. 'class' => 'DrupalTextMetaTag',
  238. 'element' => array(
  239. '#theme' => 'metatag_dc',
  240. ),
  241. 'weight' => ++$weight,
  242. );
  243. $info['tags']['dcterms.rights'] = array(
  244. 'label' => t('Dublin Core Rights'),
  245. '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.'),
  246. 'group' => 'dublin-core',
  247. 'class' => 'DrupalTextMetaTag',
  248. 'element' => array(
  249. '#theme' => 'metatag_dc',
  250. ),
  251. 'weight' => ++$weight,
  252. );
  253. return $info;
  254. }
  255. /**
  256. * Function that returns the DCMI type options.
  257. * Types taken from http://dublincore.org/documents/dcmi-type-vocabulary/.
  258. */
  259. function _metatag_dc_dcmi_type_vocabulary_options() {
  260. $options = array(
  261. 'Collection',
  262. 'Dataset',
  263. 'Event',
  264. 'Image',
  265. 'InteractiveResource',
  266. 'MovingImage',
  267. 'PhysicalObject',
  268. 'Service',
  269. 'Software',
  270. 'Sound',
  271. 'StillImage',
  272. 'Text',
  273. );
  274. return drupal_map_assoc($options);
  275. }