diff --git a/lib/linguist/blob_helper.rb b/lib/linguist/blob_helper.rb index f18a9204..5f843ac6 100644 --- a/lib/linguist/blob_helper.rb +++ b/lib/linguist/blob_helper.rb @@ -287,6 +287,9 @@ module Linguist # See if there is a Language for the extension pathname.language || + # Look for idioms in first line + first_line_language || + # Try to detect Language from shebang line shebang_language end @@ -357,6 +360,20 @@ module Linguist end end + # Internal: Guess language from the first line. + # + # Look for leading "' . 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('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 .= 'register_globals is turned off. If you need to use forms, understand and use the functions in the Drupal Form API.', array('@formapi' => url('http://api.drupal.org/api/group/form_api/7'))) . 'print or return statement in your code to output content.') . 'template.php file rather than embedding it directly into a post or block.') . '' . t('A basic example: Creating a "Welcome" block that greets visitors with a simple message.') . '
'; + $output .= 'Add a custom block to your site, named "Welcome" . With its text format set to "PHP code" (or another format supporting PHP input), add the following in the Block body:
++print t(\'Welcome visitor! Thank you for visiting.\'); +') . '
To display the name of a registered user, use this instead:
+
+global $user;
+if ($user->uid) {
+ print t(\'Welcome @name! Thank you for visiting.\', array(\'@name\' => format_username($user)));
+}
+else {
+ print t(\'Welcome visitor! Thank you for visiting.\');
+}
+') . '' . 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/test/test_blob.rb b/test/test_blob.rb index ff045d9c..6c3f8757 100644 --- a/test/test_blob.rb +++ b/test/test_blob.rb @@ -278,6 +278,9 @@ class TestBlob < Test::Unit::TestCase # http://docs.racket-lang.org/scribble/ assert_equal Language['Racket'], blob("scribble.scrbl").language + + # https://github.com/drupal/drupal/blob/7.x/modules/php/php.module + assert_equal Language['PHP'], blob("drupal.module").language end def test_lexer