metatag.metatag.inc 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. <?php
  2. /**
  3. * @file
  4. * Metatag API implementations to provide the basic meta tags.
  5. */
  6. /**
  7. * Implements hook_metatag_config_default().
  8. */
  9. function metatag_metatag_config_default() {
  10. // Optionally skip loading the defaults.
  11. if (!variable_get('metatag_load_defaults', TRUE)) {
  12. return;
  13. }
  14. $configs = array();
  15. $config = new stdClass();
  16. $config->instance = 'global';
  17. $config->api_version = 1;
  18. $config->disabled = FALSE;
  19. $config->config = array(
  20. 'title' => array('value' => '[current-page:title] | [current-page:pager][site:name]'),
  21. 'generator' => array('value' => 'Drupal 7 (https://www.drupal.org)'),
  22. 'canonical' => array('value' => '[current-page:url:absolute]'),
  23. 'shortlink' => array('value' => '[current-page:url:unaliased]'),
  24. );
  25. $configs[$config->instance] = $config;
  26. $config = new stdClass();
  27. $config->instance = 'global:frontpage';
  28. $config->api_version = 1;
  29. $config->disabled = FALSE;
  30. $config->config = array(
  31. 'title' => array('value' => variable_get('site_slogan') ? '[site:name] | [current-page:pager][site:slogan]' : '[site:name] | [current-page:pager]'),
  32. 'canonical' => array('value' => '[site:url]'),
  33. 'shortlink' => array('value' => '[site:url]'),
  34. );
  35. $configs[$config->instance] = $config;
  36. $config = new stdClass();
  37. $config->instance = 'global:403';
  38. $config->api_version = 1;
  39. $config->disabled = FALSE;
  40. $config->config = array(
  41. 'canonical' => array('value' => '[site:url]'),
  42. 'shortlink' => array('value' => '[site:url]'),
  43. );
  44. $configs[$config->instance] = $config;
  45. $config = new stdClass();
  46. $config->instance = 'global:404';
  47. $config->api_version = 1;
  48. $config->disabled = FALSE;
  49. $config->config = array(
  50. 'canonical' => array('value' => '[site:url]'),
  51. 'shortlink' => array('value' => '[site:url]'),
  52. );
  53. $configs[$config->instance] = $config;
  54. $config = new stdClass();
  55. $config->instance = 'node';
  56. $config->api_version = 1;
  57. $config->disabled = FALSE;
  58. $config->config = array(
  59. 'title' => array('value' => '[node:title] | [current-page:pager][site:name]'),
  60. 'description' => array('value' => '[node:summary]'),
  61. );
  62. $configs[$config->instance] = $config;
  63. if (module_exists('taxonomy')) {
  64. $config = new stdClass();
  65. $config->instance = 'taxonomy_term';
  66. $config->api_version = 1;
  67. $config->disabled = FALSE;
  68. $config->config = array(
  69. 'title' => array('value' => '[term:name] | [current-page:pager][site:name]'),
  70. 'description' => array('value' => '[term:description]'),
  71. );
  72. $configs[$config->instance] = $config;
  73. }
  74. $config = new stdClass();
  75. $config->instance = 'user';
  76. $config->api_version = 1;
  77. $config->disabled = FALSE;
  78. $config->config = array(
  79. 'title' => array('value' => '[user:name] | [site:name]'),
  80. );
  81. if (variable_get('user_pictures')) {
  82. $config->config['image_src'] = array('value' => '[user:picture:url]');
  83. }
  84. $configs[$config->instance] = $config;
  85. // Before returning these, allow the bundled submodules to override them, thus
  86. // extending the "real" defaults before they can then be altered by other
  87. // modules.
  88. // See hook_metatag_bundled_config_alter() in the API documentation.
  89. drupal_alter('metatag_bundled_config', $configs);
  90. return $configs;
  91. }
  92. /**
  93. * Implements hook_metatag_config_instance_info().
  94. */
  95. function metatag_metatag_config_instance_info() {
  96. $info['global'] = array('label' => t('Global'));
  97. $info['global:frontpage'] = array('label' => t('Front page'));
  98. $info['global:403'] = array('label' => t('403 access denied'));
  99. $info['global:404'] = array('label' => t('404 page not found'));
  100. // Add instance information for entities.
  101. $entity_types = entity_get_info();
  102. foreach ($entity_types as $entity_type => $entity_info) {
  103. if (metatag_entity_supports_metatags($entity_type)) {
  104. $info[$entity_type] = array('label' => $entity_info['label']);
  105. foreach ($entity_info['bundles'] as $bundle => $bundle_info) {
  106. if (count($entity_info['bundles']) == 1 && $bundle == $entity_type) {
  107. // Skip default bundles (entities that do not really have bundles).
  108. continue;
  109. }
  110. if (metatag_entity_supports_metatags($entity_type, $bundle)) {
  111. $info[$entity_type . ':' . $bundle] = array('label' => $bundle_info['label']);
  112. }
  113. }
  114. }
  115. }
  116. return $info;
  117. }
  118. /**
  119. * Implements hook_metatag_info().
  120. */
  121. function metatag_metatag_info() {
  122. $info['groups']['basic'] = array(
  123. 'label' => t('Basic tags'),
  124. 'form' => array(
  125. '#weight' => 1,
  126. '#collapsed' => FALSE,
  127. ),
  128. );
  129. $info['groups']['advanced'] = array(
  130. 'label' => t('Advanced tags'),
  131. 'form' => array(
  132. '#weight' => 2,
  133. ),
  134. );
  135. // "Simple" meta tags go first.
  136. $weight = 0;
  137. $info['tags']['title'] = array(
  138. 'label' => t('Page title'),
  139. '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."),
  140. 'maxlength' => 0,
  141. 'class' => 'DrupalTitleMetaTag',
  142. 'group' => 'basic',
  143. 'weight' => ++$weight,
  144. );
  145. $info['tags']['description'] = array(
  146. 'label' => t('Description'),
  147. 'description' => t("A brief and concise summary of the page's content, preferably 320 characters or less. The description meta tag may be used by search engines to display a snippet about the page in search results."),
  148. 'maxlength' => 380,
  149. 'class' => 'DrupalTextMetaTag',
  150. 'group' => 'basic',
  151. 'weight' => ++$weight,
  152. 'form' => array(
  153. '#type' => 'textarea',
  154. '#rows' => 2,
  155. '#wysiwyg' => FALSE,
  156. ),
  157. );
  158. $info['tags']['abstract'] = array(
  159. 'label' => t('Abstract'),
  160. 'description' => t("A brief and concise summary of the page's content, preferably 150 characters or less. Where as the description meta tag may be used by search engines to display a snippet about the page in search results, the abstract tag may be used to archive a summary about the page. This meta tag is <em>no longer</em> supported by major search engines."),
  161. 'maxlength' => 0,
  162. 'class' => 'DrupalTextMetaTag',
  163. 'group' => 'basic',
  164. 'weight' => ++$weight,
  165. 'form' => array(
  166. '#type' => 'textarea',
  167. '#rows' => 2,
  168. '#wysiwyg' => FALSE,
  169. ),
  170. );
  171. $info['tags']['keywords'] = array(
  172. 'label' => t('Keywords'),
  173. 'description' => t("A comma-separated list of keywords about the page. This meta tag is <em>not</em> supported by most search engines anymore."),
  174. 'maxlength' => 0,
  175. 'class' => 'DrupalTextMetaTag',
  176. 'group' => 'basic',
  177. 'weight' => ++$weight,
  178. );
  179. // More advanced meta tags.
  180. $info['tags']['robots'] = array(
  181. 'label' => t('Robots'),
  182. 'description' => t("Provides search engines with specific directions for what to do when this page is indexed."),
  183. 'class' => 'DrupalListMetaTag',
  184. 'group' => 'advanced',
  185. 'weight' => ++$weight,
  186. 'form' => array(
  187. '#options' => array(
  188. 'index' => t('Allow search engines to index this page (assumed).'),
  189. 'follow' => t('Allow search engines to follow links on this page (assumed).'),
  190. 'noindex' => t('Prevents search engines from indexing this page.'),
  191. 'nofollow' => t('Prevents search engines from following links on this page.'),
  192. 'noarchive' => t('Prevents cached copies of this page from appearing in search results.'),
  193. 'nosnippet' => t('Prevents descriptions from appearing in search results, and prevents page caching.'),
  194. 'noodp' => t('Blocks the <a href="!opendirectory">Open Directory Project</a> description from appearing in search results.', array('!opendirectory' => 'http://www.dmoz.org/')),
  195. 'noydir' => t('Prevents Yahoo! from listing this page in the <a href="@ydir">Yahoo! Directory</a>.', array('@ydir' => 'http://dir.yahoo.com/')),
  196. 'noimageindex' => t('Prevent search engines from indexing images on this page.'),
  197. 'notranslate' => t('Prevent search engines from offering to translate this page in search results.'),
  198. ),
  199. ),
  200. );
  201. $info['tags']['news_keywords'] = array(
  202. 'label' => t('Google News Keywords'),
  203. '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')),
  204. 'maxlength' => 0,
  205. 'class' => 'DrupalTextMetaTag',
  206. 'group' => 'advanced',
  207. 'weight' => ++$weight,
  208. );
  209. $info['tags']['standout'] = array(
  210. 'label' => t('Google Standout'),
  211. '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')),
  212. 'class' => 'DrupalTextMetaTag',
  213. 'group' => 'advanced',
  214. 'weight' => ++$weight,
  215. );
  216. $info['tags']['rating'] = array(
  217. 'label' => t('Content rating'),
  218. 'description' => t('Used to indicate the intended audience for the content.'),
  219. 'class' => 'DrupalTextMetaTag',
  220. 'group' => 'advanced',
  221. 'select_or_other' => TRUE,
  222. 'form' => array(
  223. '#type' => 'select',
  224. '#options' => array(
  225. 'general' => t('General'),
  226. 'mature' => t("Mature"),
  227. 'restricted' => t("Restricted"),
  228. '14 years' => t("14 years or Older"),
  229. 'safe for kids' => t("Safe for kids"),
  230. ),
  231. '#empty_option' => t('- None -'),
  232. ),
  233. 'weight' => ++$weight,
  234. );
  235. $info['tags']['referrer'] = array(
  236. 'label' => t('Referrer policy'),
  237. 'description' => t('Indicate to search engines and other page scrapers whether or not links should be followed. See <a href="http://w3c.github.io/webappsec/specs/referrer-policy/">the W3C specifications</a> for further details.'),
  238. 'class' => 'DrupalTextMetaTag',
  239. 'group' => 'advanced',
  240. 'select_or_other' => TRUE,
  241. 'form' => array(
  242. '#type' => 'select',
  243. '#options' => array(
  244. 'no-referrer' => t('No Referrer'),
  245. 'origin' => t('Origin'),
  246. 'no-referrer-when-downgrade' => t('No Referrer When Downgrade'),
  247. 'origin-when-cross-origin' => t('Origin When Cross-Origin'),
  248. 'unsafe-url' => t('Unsafe URL'),
  249. ),
  250. '#empty_option' => t('- None -'),
  251. ),
  252. 'weight' => ++$weight,
  253. );
  254. $info['tags']['generator'] = array(
  255. 'label' => t('Generator'),
  256. 'description' => t("Describes the name and version number of the software or publishing tool used to create the page."),
  257. 'class' => 'DrupalTextMetaTag',
  258. 'header' => 'X-Generator',
  259. 'context' => array('global'),
  260. 'group' => 'advanced',
  261. 'weight' => ++$weight,
  262. );
  263. $info['tags']['rights'] = array(
  264. 'label' => t('Rights'),
  265. 'description' => t("Details about intellectual property, such as copyright or trademarks; does not automatically protect the site's content or intellectual property."),
  266. 'class' => 'DrupalTextMetaTag',
  267. 'group' => 'advanced',
  268. 'weight' => ++$weight,
  269. 'replaces' => array(
  270. 'copyright',
  271. ),
  272. );
  273. $info['tags']['image_src'] = array(
  274. 'label' => t('Image'),
  275. 'description' => t("An image associated with this page, for use as a thumbnail in social networks and other services."),
  276. 'class' => 'DrupalLinkMetaTag',
  277. 'group' => 'advanced',
  278. 'weight' => ++$weight,
  279. 'image' => TRUE,
  280. 'devel_generate' => array(
  281. 'type' => 'image',
  282. ),
  283. );
  284. $info['tags']['canonical'] = array(
  285. 'label' => t('Canonical URL'),
  286. 'description' => t("Preferred page location or URL to help eliminate duplicate content for search engines."),
  287. 'class' => 'DrupalLinkMetaTag',
  288. 'group' => 'advanced',
  289. 'weight' => ++$weight,
  290. 'devel_generate' => array(
  291. 'type' => 'canonical',
  292. ),
  293. );
  294. $info['tags']['set_cookie'] = array(
  295. 'label' => t('Set cookie'),
  296. 'description' => t('<a href="https://www.metatags.org/meta_http_equiv_set_cookie">Sets a cookie</a> on the visitor\'s browser. Can be in either NAME=VALUE format, or a more verbose format including the path and expiration date; see the link for full details on the syntax.'),
  297. 'class' => 'DrupalTextMetaTag',
  298. 'group' => 'advanced',
  299. 'weight' => ++$weight,
  300. 'is_language' => TRUE,
  301. 'element' => array(
  302. '#theme' => 'metatag_http_equiv',
  303. ),
  304. );
  305. $info['tags']['shortlink'] = array(
  306. 'label' => t('Shortlink URL'),
  307. 'description' => t('A brief URL, often created by a URL shortening service.'),
  308. 'class' => 'DrupalLinkMetaTag',
  309. 'group' => 'advanced',
  310. 'weight' => ++$weight,
  311. 'replaces' => array(
  312. 'shorturl',
  313. ),
  314. 'devel_generate' => array(
  315. 'type' => 'shortlink',
  316. ),
  317. );
  318. $info['tags']['original-source'] = array(
  319. 'label' => t('Original Source'),
  320. 'description' => '',
  321. 'class' => 'DrupalTextMetaTag',
  322. 'group' => 'advanced',
  323. '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."),
  324. 'weight' => ++$weight,
  325. 'devel_generate' => array(
  326. 'type' => 'url',
  327. ),
  328. );
  329. $info['tags']['prev'] = array(
  330. 'label' => t('Previous page URL'),
  331. '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')),
  332. 'class' => 'DrupalLinkMetaTag',
  333. 'group' => 'advanced',
  334. 'weight' => ++$weight,
  335. 'devel_generate' => array(
  336. 'type' => 'url',
  337. ),
  338. );
  339. $info['tags']['next'] = array(
  340. 'label' => t('Next page URL'),
  341. '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')),
  342. 'class' => 'DrupalLinkMetaTag',
  343. 'group' => 'advanced',
  344. 'weight' => ++$weight,
  345. 'devel_generate' => array(
  346. 'type' => 'url',
  347. ),
  348. );
  349. $info['tags']['content-language'] = array(
  350. 'label' => t('Content language'),
  351. 'description' => t("Used to define this page's language code. May be the two letter language code, e.g. \"de\" for German, or the two letter code with a dash and the two letter ISO country code, e.g. \"de-AT\" for German in Austria. Still used by Bing."),
  352. 'class' => 'DrupalTextMetaTag',
  353. 'group' => 'advanced',
  354. 'weight' => ++$weight,
  355. 'is_language' => TRUE,
  356. 'element' => array(
  357. '#theme' => 'metatag_http_equiv',
  358. ),
  359. );
  360. $info['tags']['geo.position'] = array(
  361. 'label' => t('Geo position'),
  362. 'description' => t('Geo-spatial information in "latitude;longitude" format, e.g. "50.167958;-97.133185"; <a href="http://en.wikipedia.org/wiki/Geotagging#HTML_pages">see Wikipedia for details</a>.'),
  363. 'class' => 'DrupalTextMetaTag',
  364. 'group' => 'advanced',
  365. 'weight' => ++$weight,
  366. );
  367. $info['tags']['geo.placename'] = array(
  368. 'label' => t('Geo place name'),
  369. 'description' => t("A location's formal name."),
  370. 'class' => 'DrupalTextMetaTag',
  371. 'group' => 'advanced',
  372. 'weight' => ++$weight,
  373. );
  374. $info['tags']['geo.region'] = array(
  375. 'label' => t('Geo region'),
  376. 'description' => t("A location's two-letter international country code, with an optional two-letter region, e.g. \"US-NH\" for New Hampshire in the USA."),
  377. 'class' => 'DrupalTextMetaTag',
  378. 'group' => 'advanced',
  379. 'weight' => ++$weight,
  380. );
  381. $info['tags']['icbm'] = array(
  382. 'label' => t('ICBM'),
  383. 'description' => t('Geo-spatial information in "latitude, longitude" format, e.g. "50.167958, -97.133185"; <a href="https://en.wikipedia.org/wiki/ICBM_address">see Wikipedia for details</a>.'),
  384. 'class' => 'DrupalTextMetaTag',
  385. 'group' => 'advanced',
  386. 'weight' => ++$weight,
  387. );
  388. $info['tags']['refresh'] = array(
  389. 'label' => t('Refresh'),
  390. 'description' => t('The number of seconds to wait before refreshing the page. May also force redirect to another page using the format "5; url=http://example.com/", which would be triggered after five seconds.'),
  391. 'class' => 'DrupalTextMetaTag',
  392. 'group' => 'advanced',
  393. 'weight' => ++$weight,
  394. 'element' => array(
  395. '#theme' => 'metatag_http_equiv',
  396. ),
  397. );
  398. $info['tags']['revisit-after'] = array(
  399. 'label' => t('Revisit After'),
  400. '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')),
  401. 'class' => 'DrupalDateIntervalMetaTag',
  402. 'group' => 'advanced',
  403. 'weight' => ++$weight,
  404. 'devel_generate' => array(
  405. 'type' => 'date',
  406. ),
  407. );
  408. $info['tags']['pragma'] = array(
  409. 'label' => t('Pragma'),
  410. 'description' => t('Used to control whether a browser caches a specific page locally. Little used today. Should be used in conjunction with the Cache-Control meta tag.'),
  411. 'class' => 'DrupalTextMetaTag',
  412. 'group' => 'advanced',
  413. 'weight' => ++$weight,
  414. 'element' => array(
  415. '#theme' => 'metatag_http_equiv',
  416. ),
  417. );
  418. $info['tags']['cache-control'] = array(
  419. 'label' => t('Cache-Control'),
  420. 'description' => t('Used to control whether a browser caches a specific page locally. Little used today. Should be used in conjunction with the Pragma meta tag.'),
  421. 'class' => 'DrupalTextMetaTag',
  422. 'group' => 'advanced',
  423. 'weight' => ++$weight,
  424. 'element' => array(
  425. '#theme' => 'metatag_http_equiv',
  426. ),
  427. );
  428. $info['tags']['expires'] = array(
  429. 'label' => t('Expires'),
  430. 'description' => t("Control when the browser's internal cache of the current page should expire. The date must to be an <a href=\"@rfc\">RFC-1123</a>-compliant date string that is represented in Greenwich Mean Time (GMT), e.g. 'Thu, 01 Sep 2016 00:12:56 GMT'. Set to '0' to stop the page being cached entirely.", array('@rfc' => 'http://www.csgnetwork.com/timerfc1123calc.html')),
  431. 'class' => 'DrupalTextMetaTag',
  432. 'weight' => ++$weight,
  433. 'group' => 'advanced',
  434. 'devel_generate' => array(
  435. 'type' => 'date',
  436. ),
  437. );
  438. return $info;
  439. }