extlink.module 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. // $Id: extlink.module,v 1.6 2010/10/17 00:38:24 quicksketch Exp $
  3. function extlink_menu() {
  4. $items = array();
  5. $items['admin/config/user-interface/extlink'] = array(
  6. 'title' => 'External links',
  7. 'description' => 'Alter the display of external links on the site.',
  8. 'page callback' => 'drupal_get_form',
  9. 'page arguments' => array('extlink_admin_settings'),
  10. 'access callback' => 'user_access',
  11. 'access arguments' => array('administer site configuration'),
  12. );
  13. return $items;
  14. }
  15. /**
  16. * Implementation of hook_init().
  17. */
  18. function extlink_init() {
  19. $path = drupal_get_path('module', 'extlink');
  20. drupal_add_js($path .'/extlink.js');
  21. drupal_add_js(array('extlink' => array(
  22. 'extTarget' => variable_get('extlink_target', 0),
  23. 'extClass' => variable_get('extlink_class', 'ext'),
  24. 'extSubdomains' => variable_get('extlink_subdomains', 1),
  25. 'extExclude' => variable_get('extlink_exclude', ''),
  26. 'extInclude' => variable_get('extlink_include', ''),
  27. 'extAlert' => variable_get('extlink_alert', 0),
  28. 'extAlertText' => variable_get('extlink_alert_text', 'This link will take you to an external web site. We are not responsible for their content.'),
  29. 'mailtoClass' => variable_get('extlink_mailto_class', 'mailto'))), 'setting'
  30. );
  31. if (variable_get('extlink_class', 'ext') == 'ext' || variable_get('extlink_mailto_class', 'mailto') == 'mailto') {
  32. drupal_add_css($path . '/extlink.css');
  33. }
  34. }
  35. function extlink_admin_settings() {
  36. $form = array();
  37. $form['extlink_class'] = array(
  38. '#type' => 'checkbox',
  39. '#title' => t('Add icon to external links'),
  40. '#return_value' => 'ext',
  41. '#default_value' => variable_get('extlink_class', 'ext'),
  42. '#description' => t('Places an !icon icon next to external links.', array('!icon' => theme_image(array('path' => drupal_get_path('module', 'extlink') .'/extlink.png', 'alt' => t('External Links icon'), 'attributes' => array())))),
  43. );
  44. $form['extlink_mailto_class'] = array(
  45. '#type' => 'checkbox',
  46. '#title' => t('Add icon to mailto links'),
  47. '#return_value' => 'mailto',
  48. '#default_value' => variable_get('extlink_mailto_class', 'mailto'),
  49. '#description' => t('Places an !icon icon next to mailto links.', array(
  50. '!icon' => theme_image(array(
  51. 'path' => drupal_get_path('module', 'extlink') . '/mailto.png',
  52. 'alt' => t('Email links icon'),
  53. 'attributes' => '',
  54. )),
  55. )),
  56. );
  57. $form['extlink_subdomains'] = array(
  58. '#type' => 'checkbox',
  59. '#title' => t('Consider subdomains internal'),
  60. '#default_value' => variable_get('extlink_subdomains', 1),
  61. '#description' => t('If checked, links with the same primary domain will all be considered internal. A link from www.example.com to my.example.com would be considered internal. Links between the www. and non-www. domain are always considered internal.'),
  62. );
  63. $form['extlink_target'] = array(
  64. '#type' => 'checkbox',
  65. '#title' => t('Open external links in a new window'),
  66. '#return_value' => '_blank',
  67. '#default_value' => variable_get('extlink_target', 0),
  68. '#description' => t('Should all external links be opened in a new window?'),
  69. );
  70. $form['extlink_alert'] = array(
  71. '#type' => 'checkbox',
  72. '#title' => t('Display pop-up warnings'),
  73. '#return_value' => '_blank',
  74. '#default_value' => variable_get('extlink_alert', 0),
  75. '#description' => t('Displays a pop-up warning when any external link is clicked.'),
  76. );
  77. $form['extlink_alert_text'] = array(
  78. '#type' => 'textarea',
  79. '#rows' => 3,
  80. '#title' => t('Pop-up warning text'),
  81. '#default_value' => variable_get('extlink_alert_text', 'This link will take you to an external web site. We are not responsible for their content.'),
  82. '#description' => t('Text to display in the pop-up external link warning box.'),
  83. '#wysiwyg' => FALSE,
  84. );
  85. $patterns = array(
  86. '<em>(example\.com)</em> ' . t('Matches example.com.'),
  87. '<em>(example\.com)|(example.net)</em> ' . t('Multiple patterns can be strung together by using a pipe. Matches example.com OR example.net.'),
  88. '<em>(links/goto/[0-9]+/[0-9]+)</em> ' . t('Matches links that go through the <a href="http://drupal.org/project/links">Links module</a> redirect.'),
  89. );
  90. $wildcards = array(
  91. '<em>.</em> ' . t('Matches any character.'),
  92. '<em>?</em> ' . t('The previous character or set is optional.'),
  93. '<em>\d</em> ' . t('Matches any digit (0-9).'),
  94. '<em>[a-z]</em> ' . t('Brackets may be used to match a custom set of characters. This matches any alphabetic letter.'),
  95. );
  96. $form['patterns'] = array(
  97. '#tree' => FALSE,
  98. '#type' => 'fieldset',
  99. '#title' => t('Pattern matching'),
  100. '#collapsible' => TRUE,
  101. '#collapsed' => TRUE,
  102. '#description' =>
  103. '<p>' . t('External links uses patterns (regular expressions) to match the "href" property of links.') . '</p>' .
  104. t('Here are some common patterns.') .
  105. theme('item_list', $patterns) .
  106. t('Common special characters:') .
  107. theme('item_list', $wildcards) .
  108. '<p>' . t('All special characters (<em>^ $ . ? ( ) | * +</em>) must also be escaped with backslashes. Patterns are not case-sensitive. Any <a href="http://www.javascriptkit.com/javatutors/redev2.shtml">pattern supported by JavaScript</a> may be used.') . '</p>',
  109. );
  110. $form['patterns']['extlink_exclude'] = array(
  111. '#type' => 'textfield',
  112. '#title' => t('Exclude links matching the pattern'),
  113. '#maxlength' => NULL,
  114. '#default_value' => variable_get('extlink_exclude', ''),
  115. '#description' => t('Enter a regular expression for links that you wish to exclude from being considered external.'),
  116. );
  117. $form['patterns']['extlink_include'] = array(
  118. '#type' => 'textfield',
  119. '#title' => t('Include links matching the pattern'),
  120. '#maxlength' => NULL,
  121. '#default_value' => variable_get('extlink_include', ''),
  122. '#description' => t('Enter a regular expression for internal links that you wish to be considered external.'),
  123. );
  124. return system_settings_form($form);
  125. }