Further modules included.
[yaffs-website] / web / modules / contrib / php / php.module
1 <?php
2
3 /**
4  * @file
5  * Additional filter for PHP input.
6  */
7
8 use Drupal\Core\Routing\RouteMatchInterface;
9 use Drupal\Core\Url;
10
11 /**
12  * Implements hook_help().
13  */
14 function php_help($route_name, RouteMatchInterface $route_match) {
15   switch ($route_name) {
16     case 'help.page.php':
17       $output = '';
18       $output .= '<h3>' . t('About') . '</h3>';
19       $output .= '<p>' . t('The PHP Filter module adds a PHP filter to your site, for use with <a href=":filter">text formats</a>. 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). <a href=":php-net">PHP</a> 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 <a href=":php">PHP Filter module</a>.', [':filter' => Url::fromRoute('filter.admin_overview'), ':php-net' => 'http://www.php.net', ':php' => 'http://drupal.org/documentation/modules/php']) . '</p>';
20       $output .= '<h3>' . t('Uses') . '</h3>';
21       $output .= '<dl>';
22       $output .= '<dt>' . t('Enabling execution of PHP in text fields') . '</dt>';
23       $output .= '<dd>' . 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. <a href=":php-snippets">Example PHP snippets</a> can be found on Drupal.org.', [':php-snippets' => 'http://drupal.org/documentation/customization/php-snippets']) . '</dd>';
24       $output .= '</dl>';
25       return $output;
26   }
27 }
28
29 /**
30  * Implements hook_library_info_alter().
31  */
32 function php_library_info_alter(&$libraries, $extension) {
33   // Load php.admin.js whenever drupal.block library is added.
34   if ($extension == 'block' && isset($libraries['drupal.block'])) {
35     $libraries['drupal.block']['dependencies'][] = 'php/php.block.admin';
36   }
37 }
38
39 /**
40  * Evaluates a string of PHP code.
41  *
42  * This is a wrapper around PHP's eval(). It uses output buffering to capture
43  * both returned and printed text. Unlike eval(), we require code to be
44  * surrounded by <?php ?> tags; in other words, we evaluate the code as if it
45  * were a stand-alone PHP file.
46  *
47  * Using this wrapper also ensures that the PHP code which is evaluated can not
48  * overwrite any variables in the calling code, unlike a regular eval() call.
49  *
50  * This function is also used as an implementation of
51  * hook_filter_FILTER_process().
52  *
53  * @param string $code
54  *   The code to evaluate.
55  *
56  * @return string
57  *   A string containing the printed output of the code, followed by the
58  *   returned output of the code.
59  *
60  * @ingroup php_wrappers
61  *
62  * @see php_filter_info()
63  */
64 function php_eval($code) {
65   /* FIXME global $theme_path, $theme_info;
66
67   // Store current theme path.
68   $old_theme_path = $theme_path;
69
70   // Restore theme_path to the theme, as long as php_eval() executes,
71   // so code evaluated will not see the caller module as the current theme.
72   // If theme info is not initialized get the path from default theme.
73   if (!isset($theme_info)) {
74     $theme_path = drupal_get_path('theme', Drupal::config('system.theme')->get('default'));
75   }
76   else {
77     $theme_path = dirname($theme_info->filename);
78   }*/
79
80   ob_start();
81   print eval('?>' . $code);
82   $output = ob_get_contents();
83   ob_end_clean();
84
85   // Recover original theme path.
86   /* $theme_path = $old_theme_path; */
87
88   return $output;
89 }