php.install 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the php module.
  5. */
  6. /**
  7. * Implements hook_enable().
  8. */
  9. function php_enable() {
  10. $format_exists = (bool) db_query_range('SELECT 1 FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'PHP code'))->fetchField();
  11. // Add a PHP code text format, if it does not exist. Do this only for the
  12. // first install (or if the format has been manually deleted) as there is no
  13. // reliable method to identify the format in an uninstall hook or in
  14. // subsequent clean installs.
  15. if (!$format_exists) {
  16. $php_format = array(
  17. 'format' => 'php_code',
  18. 'name' => 'PHP code',
  19. // 'Plain text' format is installed with a weight of 10 by default. Use a
  20. // higher weight here to ensure that this format will not be the default
  21. // format for anyone.
  22. 'weight' => 11,
  23. 'filters' => array(
  24. // Enable the PHP evaluator filter.
  25. 'php_code' => array(
  26. 'weight' => 0,
  27. 'status' => 1,
  28. ),
  29. ),
  30. );
  31. $php_format = (object) $php_format;
  32. filter_format_save($php_format);
  33. drupal_set_message(t('A <a href="@php-code">PHP code</a> text format has been created.', array('@php-code' => url('admin/config/content/formats/' . $php_format->format))));
  34. }
  35. }
  36. /**
  37. * Implements hook_disable().
  38. */
  39. function php_disable() {
  40. drupal_set_message(t('The PHP module has been disabled. Any existing content that was using the PHP filter will now be visible in plain text. This might pose a security risk by exposing sensitive information, if any, used in the PHP code.'));
  41. }