url_replace_filter.install 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * @file
  4. * Install file for URL Replace filter.
  5. *
  6. * @author: Frédéric G. MARAND <fgm@osinet.fr>
  7. *
  8. * @license General Public License version 2.0 or later
  9. */
  10. /**
  11. * Implementation of hook_requirements().
  12. *
  13. * Ensure the module is actually used in at least one filter.
  14. */
  15. function url_replace_filter_requirements($phase) {
  16. if ($phase != 'runtime') {
  17. return array();
  18. }
  19. $formats = _url_replace_filter_get_formats();
  20. $filter_id = 'url_replace_filter/0';
  21. $count = 0;
  22. foreach ($formats as $format) {
  23. if (!empty($format->{$filter_id})) {
  24. $count++;
  25. }
  26. }
  27. $req = array(
  28. 'title' => t('URL replace filter'),
  29. );
  30. if ($count) {
  31. $req['value'] = format_plural($count, "Used in 1 format.", "Used in @count formats.");
  32. $req['severity'] = REQUIREMENT_OK;
  33. }
  34. else {
  35. $req['value'] = t('Module is enabled but no format uses its filter. You should disable the module or use the filter in at least one format.');
  36. $req['severity'] = REQUIREMENT_INFO;
  37. }
  38. return array('url_replace_filter' => $req);
  39. }
  40. /**
  41. * Implementation of hook_disable().
  42. *
  43. * - Flush filter cache to remove content cached with this filter.
  44. */
  45. function url_replace_filter_disabled() {
  46. cache_clear_all('*', 'cache_filter', TRUE);
  47. }
  48. /**
  49. * Implementation of hook_uninstall().
  50. *
  51. * - Remove all configuration variables for the module.
  52. * - Remove instances of the filter in all input formats.
  53. * - Flush filter cache to remove content cached with this filter.
  54. */
  55. function url_replace_filter_uninstall() {
  56. // Delete configuration variables.
  57. foreach (array_keys($GLOBALS['conf']) as $name ) {
  58. if (strpos($name, 'url_replace_filter_') === 0) {
  59. variable_del($name);
  60. }
  61. }
  62. // Remove filter from input formats.
  63. $formats = _url_replace_filter_get_formats();
  64. foreach ($formats as $format) {
  65. db_query("DELETE FROM {filters} WHERE module = 'url_replace_filter'");
  66. }
  67. cache_clear_all('*', 'cache_filter', TRUE);
  68. }