metatag.metatag.inc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. <?php
  2. /**
  3. * Implements hook_metatag_config_default().
  4. */
  5. function metatag_metatag_config_default() {
  6. // Optionally skip loading the defaults.
  7. if (!variable_get('metatag_load_defaults', TRUE)) {
  8. return;
  9. }
  10. $configs = array();
  11. $config = new stdClass();
  12. $config->instance = 'global';
  13. $config->api_version = 1;
  14. $config->disabled = FALSE;
  15. $config->config = array(
  16. 'title' => array('value' => '[current-page:title] | [site:name]'),
  17. 'generator' => array('value' => 'Drupal 7 (http://drupal.org)'),
  18. 'canonical' => array('value' => '[current-page:url:absolute]'),
  19. 'shortlink' => array('value' => '[current-page:url:unaliased]'),
  20. );
  21. $configs[$config->instance] = $config;
  22. $config = new stdClass();
  23. $config->instance = 'global:frontpage';
  24. $config->api_version = 1;
  25. $config->disabled = FALSE;
  26. $config->config = array(
  27. 'title' => array('value' => variable_get('site_slogan') ? '[site:name] | [site:slogan]' : '[site:name]'),
  28. 'canonical' => array('value' => '[site:url]'),
  29. 'shortlink' => array('value' => '[site:url]'),
  30. );
  31. $configs[$config->instance] = $config;
  32. $config = new stdClass();
  33. $config->instance = 'global:403';
  34. $config->api_version = 1;
  35. $config->disabled = FALSE;
  36. $config->config = array(
  37. 'canonical' => array('value' => '[site:url]'),
  38. 'shortlink' => array('value' => '[site:url]'),
  39. );
  40. $configs[$config->instance] = $config;
  41. $config = new stdClass();
  42. $config->instance = 'global:404';
  43. $config->api_version = 1;
  44. $config->disabled = FALSE;
  45. $config->config = array(
  46. 'canonical' => array('value' => '[site:url]'),
  47. 'shortlink' => array('value' => '[site:url]'),
  48. );
  49. $configs[$config->instance] = $config;
  50. $config = new stdClass();
  51. $config->instance = 'node';
  52. $config->api_version = 1;
  53. $config->disabled = FALSE;
  54. $config->config = array(
  55. 'title' => array('value' => '[node:title] | [site:name]'),
  56. 'description' => array('value' => '[node:summary]'),
  57. );
  58. $configs[$config->instance] = $config;
  59. if (module_exists('taxonomy')) {
  60. $config = new stdClass();
  61. $config->instance = 'taxonomy_term';
  62. $config->api_version = 1;
  63. $config->disabled = FALSE;
  64. $config->config = array(
  65. 'title' => array('value' => '[term:name] | [site:name]'),
  66. 'description' => array('value' => '[term:description]'),
  67. );
  68. $configs[$config->instance] = $config;
  69. }
  70. $config = new stdClass();
  71. $config->instance = 'user';
  72. $config->api_version = 1;
  73. $config->disabled = FALSE;
  74. $config->config = array(
  75. 'title' => array('value' => '[user:name] | [site:name]'),
  76. );
  77. if (variable_get('user_pictures')) {
  78. $config->config['image'] = array('value' => '[user:picture:url]');
  79. }
  80. $configs[$config->instance] = $config;
  81. // Before returning these, allow the bundled submodules to override them, thus
  82. // extending the "real" defaults before they can then be altered by other
  83. // modules.
  84. // See hook_metatag_bundled_config_alter() in the API documentation.
  85. drupal_alter('metatag_bundled_config', $configs);
  86. return $configs;
  87. }
  88. /**
  89. * Implements hook_metatag_config_instance_info().
  90. */
  91. function metatag_metatag_config_instance_info() {
  92. $info['global'] = array('label' => t('Global'));
  93. $info['global:frontpage'] = array('label' => t('Front page'));
  94. $info['global:403'] = array('label' => t('403 access denied'));
  95. $info['global:404'] = array('label' => t('404 page not found'));
  96. // Add instance information for entities.
  97. $entity_types = entity_get_info();
  98. foreach ($entity_types as $entity_type => $entity_info) {
  99. if (metatag_entity_supports_metatags($entity_type)) {
  100. $info[$entity_type] = array('label' => $entity_info['label']);
  101. foreach ($entity_info['bundles'] as $bundle => $bundle_info) {
  102. if (count($entity_info['bundles'] == 1) && $bundle == $entity_type) {
  103. // Skip default bundles (entities that do not really have bundles).
  104. continue;
  105. }
  106. if (metatag_entity_supports_metatags($entity_type, $bundle)) {
  107. $info[$entity_type . ':' . $bundle] = array('label' => $bundle_info['label']);
  108. }
  109. }
  110. }
  111. }
  112. return $info;
  113. }
  114. /**
  115. * Implements hook_metatag_info().
  116. */
  117. function metatag_metatag_info() {
  118. $info['groups']['advanced'] = array(
  119. 'label' => t('Advanced'),
  120. 'form' => array(
  121. '#weight' => 100,
  122. ),
  123. );
  124. // "Simple" meta tags go first.
  125. $weight = 0;
  126. $info['tags']['title'] = array(
  127. 'label' => t('Page title'),
  128. 'description' => t("The text to display in the title bar of a visitor's web browser when they view this page. This meta tag may also be used as the title of the page when a visitor bookmarks or favorites this page."),
  129. 'class' => 'DrupalTitleMetaTag',
  130. 'weight' => ++$weight,
  131. );
  132. $info['tags']['description'] = array(
  133. 'label' => t('Description'),
  134. 'description' => t("A brief and concise summary of the page's content, preferably 150 characters or less. The description meta tag may be used by search engines to display a snippet about the page in search results."),
  135. 'class' => 'DrupalTextMetaTag',
  136. 'weight' => ++$weight,
  137. 'form' => array(
  138. '#type' => 'textarea',
  139. '#rows' => 2,
  140. '#wysiwyg' => FALSE,
  141. ),
  142. );
  143. $info['tags']['abstract'] = array(
  144. 'label' => t('Abstract'),
  145. 'description' => t("A brief and concise summary of the page's content, preferably 150 characters or less. The abstract meta tag may be used by search engines for archiving purposes."),
  146. 'class' => 'DrupalTextMetaTag',
  147. 'weight' => ++$weight,
  148. 'form' => array(
  149. '#type' => 'textarea',
  150. '#rows' => 2,
  151. '#wysiwyg' => FALSE,
  152. ),
  153. );
  154. $info['tags']['keywords'] = array(
  155. 'label' => t('Keywords'),
  156. 'description' => t("A comma-separated list of keywords about the page. This meta tag is <em>not</em> supported by most search engines anymore."),
  157. 'class' => 'DrupalTextMetaTag',
  158. 'weight' => ++$weight,
  159. );
  160. // More advanced meta tags.
  161. $info['tags']['robots'] = array(
  162. 'label' => t('Robots'),
  163. 'description' => t("Provides search engines with specific directions for what to do when this page is indexed."),
  164. 'class' => 'DrupalListMetaTag',
  165. 'group' => 'advanced',
  166. 'weight' => ++$weight,
  167. 'form' => array(
  168. '#options' => array(
  169. 'index' => t('Allow search engines to index this page (assumed).'),
  170. 'follow' => t('Allow search engines to follow links on this page (assumed).'),
  171. 'noindex' => t('Prevents search engines from indexing this page.'),
  172. 'nofollow' => t('Prevents search engines from following links on this page.'),
  173. 'noarchive' => t('Prevents cached copies of this page from appearing in search results.'),
  174. 'nosnippet' => t('Prevents descriptions from appearing in search results, and prevents page caching.'),
  175. 'noodp' => t('Blocks the <a href="!opendirectory">Open Directory Project</a> description from appearing in search results.', array('!opendirectory' => 'http://www.dmoz.org/')),
  176. 'noydir' => t('Prevents Yahoo! from listing this page in the <a href="@ydir">Yahoo! Directory</a>.', array('@ydir' => 'http://dir.yahoo.com/')),
  177. 'noimageindex' => t('Prevent search engines from indexing images on this page.'),
  178. 'notranslate' => t('Prevent search engines from offering to translate this page in search results.'),
  179. ),
  180. ),
  181. );
  182. $info['tags']['news_keywords'] = array(
  183. 'label' => t('Google News Keywords'),
  184. 'description' => t('A comma-separated list of keywords about the page. This meta tag is used as an indicator in <a href="@google_news">Google News</a>.', array('@google_news' => 'http://support.google.com/news/publisher/bin/answer.py?hl=en&answer=68297')),
  185. 'class' => 'DrupalTextMetaTag',
  186. 'group' => 'advanced',
  187. 'weight' => ++$weight,
  188. );
  189. $info['tags']['standout'] = array(
  190. 'label' => t('Google Standout'),
  191. 'description' => t("Highlight standout journalism on the web, especially for breaking news; used as an indicator in <a href=\"@google_news\">Google News</a>. Warning: Don't abuse it, to be used a maximum of 7 times per calendar week!", array('@google_news' => 'https://support.google.com/news/publisher/answer/191283?hl=en&ref_topic=2484650')),
  192. 'class' => 'DrupalTextMetaTag',
  193. 'group' => 'advanced',
  194. 'weight' => ++$weight,
  195. );
  196. $info['tags']['generator'] = array(
  197. 'label' => t('Generator'),
  198. 'description' => t("Describes the name and version number of the software or publishing tool used to create the page."),
  199. 'class' => 'DrupalTextMetaTag',
  200. 'header' => 'X-Generator',
  201. 'context' => array('global'),
  202. 'group' => 'advanced',
  203. 'weight' => ++$weight,
  204. );
  205. $info['tags']['rights'] = array(
  206. 'label' => t('Rights'),
  207. 'description' => t("Details about intellectual property, such as copyright or trademarks; does not automatically protect the site's content or intellectual property."),
  208. 'class' => 'DrupalTextMetaTag',
  209. 'group' => 'advanced',
  210. 'weight' => ++$weight,
  211. 'replaces' => array(
  212. 'copyright',
  213. ),
  214. );
  215. $info['tags']['image_src'] = array(
  216. 'label' => t('Image'),
  217. 'description' => t("An image associated with this page, for use as a thumbnail in social networks and other services."),
  218. 'class' => 'DrupalLinkMetaTag',
  219. 'group' => 'advanced',
  220. 'weight' => ++$weight,
  221. 'devel_generate' => array(
  222. 'type' => 'image',
  223. ),
  224. );
  225. $info['tags']['canonical'] = array(
  226. 'label' => t('Canonical URL'),
  227. 'description' => t("Preferred page location or URL to help eliminate duplicate content for search engines."),
  228. 'class' => 'DrupalLinkMetaTag',
  229. 'group' => 'advanced',
  230. 'weight' => ++$weight,
  231. 'devel_generate' => array(
  232. 'type' => 'canonical',
  233. ),
  234. );
  235. $info['tags']['shortlink'] = array(
  236. 'label' => t('Shortlink URL'),
  237. 'description' => t('A brief URL, often created by a URL shortening service.'),
  238. 'class' => 'DrupalLinkMetaTag',
  239. 'group' => 'advanced',
  240. 'weight' => ++$weight,
  241. 'devel_generate' => array(
  242. 'type' => 'shortlink',
  243. ),
  244. );
  245. $info['tags']['publisher'] = array(
  246. 'label' => t('Publisher URL'),
  247. 'description' => '',
  248. 'class' => 'DrupalLinkMetaTag',
  249. 'group' => 'advanced',
  250. 'weight' => ++$weight,
  251. 'devel_generate' => array(
  252. 'type' => 'url',
  253. ),
  254. );
  255. $info['tags']['author'] = array(
  256. 'label' => t('Author URL'),
  257. 'description' => t("Used by some search engines to confirm authorship of the content on a page. Should be either the full URL for the author's Google+ profile page or a local page with information about the author."),
  258. 'class' => 'DrupalLinkMetaTag',
  259. 'group' => 'advanced',
  260. 'weight' => ++$weight,
  261. 'devel_generate' => array(
  262. 'type' => 'url',
  263. ),
  264. );
  265. $info['tags']['original-source'] = array(
  266. 'label' => t('Original Source'),
  267. 'description' => '',
  268. 'class' => 'DrupalTextMetaTag',
  269. 'group' => 'advanced',
  270. 'description' => t("Used to indicate the URL that broke the story, and can link to either an internal URL or an external source. If the full URL is not known it is acceptable to use a partial URL or just the domain name."),
  271. 'weight' => ++$weight,
  272. 'devel_generate' => array(
  273. 'type' => 'url',
  274. ),
  275. );
  276. $info['tags']['prev'] = array(
  277. 'label' => t('Previous page URL'),
  278. 'description' => t('Used for paginated content. Meet Google recommendations to <a href="@google_pagination">indicate paginated content</a> by providing URL with rel="prev" link.', array('@google_pagination' => 'https://support.google.com/webmasters/answer/1663744')),
  279. 'class' => 'DrupalLinkMetaTag',
  280. 'group' => 'advanced',
  281. 'weight' => ++$weight,
  282. 'devel_generate' => array(
  283. 'type' => 'url',
  284. ),
  285. );
  286. $info['tags']['next'] = array(
  287. 'label' => t('Next page URL'),
  288. 'description' => t('Used for paginated content. Meet Google recommendations to <a href="@google_pagination">indicate paginated content</a> by providing URL with rel="next" link.', array('@google_pagination' => 'https://support.google.com/webmasters/answer/1663744')),
  289. 'class' => 'DrupalLinkMetaTag',
  290. 'group' => 'advanced',
  291. 'weight' => ++$weight,
  292. 'devel_generate' => array(
  293. 'type' => 'url',
  294. ),
  295. );
  296. $info['tags']['revisit-after'] = array(
  297. 'label' => t('Revisit After'),
  298. 'description' => t('Tell search engines when to index the page again. Very few search engines support this tag, it is more useful to use an <a href="@xmlsitemap">XML Sitemap</a> file.', array('@xmlsitemap' => 'https://www.drupal.org/project/xmlsitemap')),
  299. 'class' => 'DrupalDateIntervalMetaTag',
  300. 'group' => 'advanced',
  301. 'weight' => ++$weight,
  302. 'devel_generate' => array(
  303. 'type' => 'date',
  304. ),
  305. );
  306. $info['tags']['content-language'] = array(
  307. 'label' => t('Content language'),
  308. 'description' => t("A deprecated meta tag for defining this page's two-letter language code(s)."),
  309. 'class' => 'DrupalTextMetaTag',
  310. 'group' => 'advanced',
  311. 'weight' => ++$weight,
  312. 'element' => array(
  313. '#theme' => 'metatag_http_equiv',
  314. ),
  315. );
  316. return $info;
  317. }