diff --git a/modules/filter/filter.test b/modules/filter/filter.test index 67d0833..2abda7b 100644 --- a/modules/filter/filter.test +++ b/modules/filter/filter.test @@ -739,7 +739,7 @@ class FilterSecurityTestCase extends DrupalWebTestCase { } function setUp() { - parent::setUp('php', 'filter_test'); + parent::setUp('filter_test'); $this->admin_user = $this->drupalCreateUser(array('administer modules', 'administer filters', 'administer site configuration')); $this->drupalLogin($this->admin_user); } diff --git a/modules/php/php.info b/modules/php/php.info deleted file mode 100644 index 669a138..0000000 --- a/modules/php/php.info +++ /dev/null @@ -1,6 +0,0 @@ -name = PHP filter -description = Allows embedded PHP code/snippets to be evaluated. -package = Core -version = VERSION -core = 8.x -files[] = php.test diff --git a/modules/php/php.install b/modules/php/php.install deleted file mode 100644 index 12944dd..0000000 --- a/modules/php/php.install +++ /dev/null @@ -1,45 +0,0 @@ - 'PHP code'))->fetchField(); - // Add a PHP code text format, if it does not exist. Do this only for the - // first install (or if the format has been manually deleted) as there is no - // reliable method to identify the format in an uninstall hook or in - // subsequent clean installs. - if (!$format_exists) { - $php_format = array( - 'format' => 'php_code', - 'name' => 'PHP code', - // 'Plain text' format is installed with a weight of 10 by default. Use a - // higher weight here to ensure that this format will not be the default - // format for anyone. - 'weight' => 11, - 'filters' => array( - // Enable the PHP evaluator filter. - 'php_code' => array( - 'weight' => 0, - 'status' => 1, - ), - ), - ); - $php_format = (object) $php_format; - filter_format_save($php_format); - - drupal_set_message(t('A PHP code text format has been created.', array('@php-code' => url('admin/config/content/formats/' . $php_format->format)))); - } -} - -/** - * Implements hook_disable(). - */ -function php_disable() { - 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.')); -} diff --git a/modules/php/php.module b/modules/php/php.module deleted file mode 100644 index 37bf9a1..0000000 --- a/modules/php/php.module +++ /dev/null @@ -1,140 +0,0 @@ -' . t('About') . ''; - $output .= '

' . t('The PHP filter module adds a PHP filter to your site, for use with text formats. This filter adds the ability to execute PHP code in any text field that uses a text format (such as the body of a content item or the text of a comment). PHP is a general-purpose scripting language widely-used for web development, and is the language with which Drupal has been developed. For more information, see the online handbook entry for the PHP filter module.', array('@filter' => url('admin/help/filter'), '@php-net' => 'http://www.php.net', '@php' => 'http://drupal.org/handbook/modules/php/')) . '

'; - $output .= '

' . t('Uses') . '

'; - $output .= '
'; - $output .= '
' . t('Enabling execution of PHP in text fields') . '
'; - $output .= '
' . t('The PHP filter module allows users with the proper permissions to include custom PHP code that will get executed when pages of your site are processed. While this is a powerful and flexible feature if used by a trusted user with PHP experience, it is a significant and dangerous security risk in the hands of a malicious or inexperienced user. Even a trusted user may accidentally compromise the site by entering malformed or incorrect PHP code. Only the most trusted users should be granted permission to use the PHP filter, and all PHP code added through the PHP filter should be carefully examined before use. Example PHP snippets can be found on Drupal.org.', array('@php-snippets' => url('http://drupal.org/handbook/customization/php-snippets'))) . '
'; - $output .= '
'; - return $output; - } -} - -/** - * Implements hook_permission(). - */ -function php_permission() { - return array( - 'use PHP for settings' => array( - 'title' => t('Use PHP for settings'), - 'restrict access' => TRUE, - ), - ); -} - -/** - * Evaluate a string of PHP code. - * - * This is a wrapper around PHP's eval(). It uses output buffering to capture both - * returned and printed text. Unlike eval(), we require code to be surrounded by - * tags; in other words, we evaluate the code as if it were a stand-alone - * PHP file. - * - * Using this wrapper also ensures that the PHP code which is evaluated can not - * overwrite any variables in the calling code, unlike a regular eval() call. - * - * @param $code - * The code to evaluate. - * @return - * A string containing the printed output of the code, followed by the returned - * output of the code. - * - * @ingroup php_wrappers - */ -function php_eval($code) { - global $theme_path, $theme_info, $conf; - - // Store current theme path. - $old_theme_path = $theme_path; - - // Restore theme_path to the theme, as long as php_eval() executes, - // so code evaluated will not see the caller module as the current theme. - // If theme info is not initialized get the path from theme_default. - if (!isset($theme_info)) { - $theme_path = drupal_get_path('theme', $conf['theme_default']); - } - else { - $theme_path = dirname($theme_info->filename); - } - - ob_start(); - print eval('?>' . $code); - $output = ob_get_contents(); - ob_end_clean(); - - // Recover original theme path. - $theme_path = $old_theme_path; - - return $output; -} - -/** - * Tips callback for php filter. - */ -function _php_filter_tips($filter, $format, $long = FALSE) { - global $base_url; - if ($long) { - $output = '

' . t('Using custom PHP code') . '

'; - $output .= '

' . t('Custom PHP code may be embedded in some types of site content, including posts and blocks. While embedding PHP code inside a post or block is a powerful and flexible feature when used by a trusted user with PHP experience, it is a significant and dangerous security risk when used improperly. Even a small mistake when posting PHP code may accidentally compromise your site.') . '

'; - $output .= '

' . t('If you are unfamiliar with PHP, SQL, or Drupal, avoid using custom PHP code within posts. Experimenting with PHP may corrupt your database, render your site inoperable, or significantly compromise security.') . '

'; - $output .= '

' . t('Notes:') . '

'; - $output .= ''; - $output .= '

' . t('A basic example: Creating a "Welcome" block that greets visitors with a simple message.') . '

'; - $output .= ''; - $output .= '

' . t('Drupal.org offers some example PHP snippets, or you can create your own with some PHP experience and knowledge of the Drupal system.', array('@drupal' => url('http://drupal.org'), '@php-snippets' => url('http://drupal.org/handbook/customization/php-snippets'))) . '

'; - return $output; - } - else { - return t('You may post PHP code. You should include <?php ?> tags.'); - } -} - -/** - * Implements hook_filter_info(). - * - * Provide PHP code filter. Use with care. - */ -function php_filter_info() { - $filters['php_code'] = array( - 'title' => t('PHP evaluator'), - 'description' => t('Executes a piece of PHP code. The usage of this filter should be restricted to administrators only!'), - 'process callback' => 'php_eval', - 'tips callback' => '_php_filter_tips', - 'cache' => FALSE, - ); - return $filters; -} - diff --git a/modules/php/php.test b/modules/php/php.test deleted file mode 100644 index 8ead2ac..0000000 --- a/modules/php/php.test +++ /dev/null @@ -1,120 +0,0 @@ -drupalCreateUser(array('administer filters')); - $this->drupalLogin($admin_user); - - // Verify that the PHP code text format was inserted. - $php_format_id = 'php_code'; - $this->php_code_format = filter_format_load($php_format_id); - $this->assertEqual($this->php_code_format->name, 'PHP code', t('PHP code text format was created.')); - - // Verify that the format has the PHP code filter enabled. - $filters = filter_list_format($php_format_id); - $this->assertTrue($filters['php_code']->status, t('PHP code filter is enabled.')); - - // Verify that the format exists on the administration page. - $this->drupalGet('admin/config/content/formats'); - $this->assertText('PHP code', t('PHP code text format was created.')); - - // Verify that anonymous and authenticated user roles do not have access. - $this->drupalGet('admin/config/content/formats/' . $php_format_id); - $this->assertFieldByName('roles[1]', FALSE, t('Anonymous users do not have access to PHP code format.')); - $this->assertFieldByName('roles[2]', FALSE, t('Authenticated users do not have access to PHP code format.')); - } - - /** - * Create a test node with PHP code in the body. - * - * @return stdObject Node object. - */ - function createNodeWithCode() { - return $this->drupalCreateNode(array('body' => array(LANGUAGE_NONE => array(array('value' => ''))))); - } -} - -/** - * Tests to make sure the PHP filter actually evaluates PHP code when used. - */ -class PHPFilterTestCase extends PHPTestCase { - public static function getInfo() { - return array( - 'name' => 'PHP filter functionality', - 'description' => 'Make sure that PHP filter properly evaluates PHP code when enabled.', - 'group' => 'PHP', - ); - } - - /** - * Make sure that the PHP filter evaluates PHP code when used. - */ - function testPHPFilter() { - // Log in as a user with permission to use the PHP code text format. - $php_code_permission = filter_permission_name(filter_format_load('php_code')); - $web_user = $this->drupalCreateUser(array('access content', 'create page content', 'edit own page content', $php_code_permission)); - $this->drupalLogin($web_user); - - // Create a node with PHP code in it. - $node = $this->createNodeWithCode(); - - // Make sure that the PHP code shows up as text. - $this->drupalGet('node/' . $node->nid); - $this->assertText('print "SimpleTest PHP was executed!"', t('PHP code is displayed.')); - - // Change filter to PHP filter and see that PHP code is evaluated. - $edit = array(); - $langcode = LANGUAGE_NONE; - $edit["body[$langcode][0][format]"] = $this->php_code_format->format; - $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save')); - $this->assertRaw(t('Basic page %title has been updated.', array('%title' => $node->title)), t('PHP code filter turned on.')); - - // Make sure that the PHP code shows up as text. - $this->assertNoText('print "SimpleTest PHP was executed!"', t("PHP code isn't displayed.")); - $this->assertText('SimpleTest PHP was executed!', t('PHP code has been evaluated.')); - } -} - -/** - * Tests to make sure access to the PHP filter is properly restricted. - */ -class PHPAccessTestCase extends PHPTestCase { - public static function getInfo() { - return array( - 'name' => 'PHP filter access check', - 'description' => 'Make sure that users who don\'t have access to the PHP filter can\'t see it.', - 'group' => 'PHP', - ); - } - - /** - * Make sure that user can't use the PHP filter when not given access. - */ - function testNoPrivileges() { - // Create node with PHP filter enabled. - $web_user = $this->drupalCreateUser(array('access content', 'create page content', 'edit own page content')); - $this->drupalLogin($web_user); - $node = $this->createNodeWithCode(); - - // Make sure that the PHP code shows up as text. - $this->drupalGet('node/' . $node->nid); - $this->assertText('print', t('PHP code was not evaluated.')); - - // Make sure that user doesn't have access to filter. - $this->drupalGet('node/' . $node->nid . '/edit'); - $this->assertNoRaw('