Project

General

Profile

Paste
Download (1.58 KB) Statistics
| Branch: | Revision:

root / drupal7 / modules / php / php.install @ b0dc3a2e

1
<?php
2

    
3
/**
4
 * @file
5
 * Install, update and uninstall functions for the php module.
6
 */
7

    
8
/**
9
 * Implements hook_enable().
10
 */
11
function php_enable() {
12
  $format_exists = (bool) db_query_range('SELECT 1 FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'PHP code'))->fetchField();
13
  // Add a PHP code text format, if it does not exist. Do this only for the
14
  // first install (or if the format has been manually deleted) as there is no
15
  // reliable method to identify the format in an uninstall hook or in
16
  // subsequent clean installs.
17
  if (!$format_exists) {
18
    $php_format = array(
19
      'format' => 'php_code',
20
      'name' => 'PHP code',
21
      // 'Plain text' format is installed with a weight of 10 by default. Use a
22
      // higher weight here to ensure that this format will not be the default
23
      // format for anyone.
24
      'weight' => 11,
25
      'filters' => array(
26
        // Enable the PHP evaluator filter.
27
        'php_code' => array(
28
          'weight' => 0,
29
          'status' => 1,
30
        ),
31
      ),
32
    );
33
    $php_format = (object) $php_format;
34
    filter_format_save($php_format);
35

    
36
    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))));
37
  }
38
}
39

    
40
/**
41
 * Implements hook_disable().
42
 */
43
function php_disable() {
44
  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.'));
45
}