Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / htmlawed / htmlawed.module
1 <?php
2
3 /**
4  * @file
5  * Main module file for htmLawed Drupal module.
6  * The module uses the htmLawed PHP library to restrict and purify HTML
7  * to make content secure, and standard- and admin. policy-compliant.
8  */
9
10 use Drupal\Core\Routing\RouteMatchInterface;
11 use Drupal\Core\Url;
12
13 /**
14  * Implements hook_help().
15  */
16 function htmlawed_help($route_name, RouteMatchInterface $route_match) {
17
18   // If Libraries module is enabled, use htmLawed library through it;
19   // else use the htmLawed library provided with the htmLawed module;
20   // we need the library here to get the htmLawed version number and documentation.
21   $module_path = drupal_get_path('module', 'htmlawed');
22   if (function_exists('libraries_load') && ($library = libraries_load('htmLawed')) && !empty($library['loaded']) && function_exists('hl_version')) {
23     $doc_path = libraries_get_path('htmLawed') . '/';
24     $Libraries_api_used = 1;
25   }
26   else {
27     $doc_path = $module_path . '/htmLawed/';
28     include_once("$module_path/htmLawed/htmLawed.php");
29   }
30   
31   switch ($route_name) {
32         case 'help.page.htmlawed':
33       return t('The htmLawed module uses the @htmLawed PHP library (version @version) to restrict and purify HTML for compliance with admin. policy and standards and for security (htmLawed @documentation). The htmLawed library allows for fine-grained control of the HTML filtering process. The Drupal website may have @handbook and @other pages about the module.', array('@htmLawed' => \Drupal::l('htmLawed', Url::fromUri('http://www.bioinformatics.org/phplabware/internal_utilities/htmLawed')), '@other' => \Drupal::l(t('other'), Url::fromUri('https://www.drupal.org/search/site/htmlawed?f[0]=ss_meta_type%3Adocumentation')), '@handbook' => \Drupal::l(t('handbook'), Url::fromUri('http://drupal.org/node/255886')), '@version' => hl_version(), '@documentation' => \Drupal::l(t('documentation'), Url::fromUri('base:' . $doc_path . 'htmLawed_README.htm')))) . '<br /><br />' .
34       (!empty($Libraries_api_used) ? t('The htmLawed library active on this Drupal installation has been loaded through the Libraries module.') . '<br /><br />' : '') .
35       t('To enable and/or configure the htmLawed filter, such as for a text format, visit the @text_formats section of the Drupal administration site and configure the format that will use or uses the filter. More than one format can use the filter, each configured with its own settings for the filter.', array('@text_formats' => \Drupal::l(t('text formats'), Url::fromUri('base:admin/config/content/formats')))) . '<br /><br />' .
36       t('The htmLawed filter is configured by providing values in the form for its settings. The %Config. form-field is filled with comma-separated, quoted, key-value pairs like %example (these are interpreted as PHP array elements). The %Spec. form-field is an optional string of unquoted text. See the htmLawed library @documentation for more on how %Config. and %Spec. can be set, for instance, to permit all HTML, or restrict links to only certain domains. The default htmLawed filter settings allow the use of the a, em, strong, cite, code, ol, ul, li, dl, dt, dd, br and p HTML tags, and deny the id and style HTML attributes, and any unsafe markup (such as the the scriptable onclick attribute). Content in the %Help and %Helplong form-fields are used to inform users about the filter, such as about the tags that are allowed. ', array('%Config.' => 'Config.', '%Spec.' => 'Spec.', '%example' => "'safe'=>1, 'element'=>'a, em, strong'", '%Help' => 'Short tip', '%Helplong' => 'Long tip', '@documentation' => \Drupal::l(t('documentation'), Url::fromUri('base:' . $doc_path . 'htmLawed_README.htm')))) . '<br /><br />' .
37       t('To allow HTML comments such as the one used for the Drupal teaser-break indicator (%break_mark), add %comment_setting to the %Config. value of the htmLawed settings. To allow PHP codes (flanked by %php_begin and %php_end) add %save_php to the %Config. value of the htmLawed settings.', array('%save_php' => "'save_php' => 1", '%Config.' => 'Config.', '%break_mark' => '<!--break-->', '%comment_setting' => "'comment' => 2", '%php_begin' => '<?php', '%php_end' => '?>')) . '<br /><br />' .
38       t(' Depending on the types of filters that are also used, you may need to re-arrange the processing order of filters. The htmLawed filter would usually be the last filter to be run. If a filter generates HTML markup and is run before htmLawed, then htmLawed should be configured appropriately to permit such markup.') . '<br /><br />' .
39       t('Any in-built Drupal actions/filters to restrict HTML, correct broken HTML, or balance or properly nest HTML tags can be disabled since htmLawed performs these tasks. The htmLawed filter can also be used to restrict HTML attributes, limit URL protocols, etc. Note that htmLawed does not convert URLs into links nor does it convert line breaks into HTML br or p tags.') . '<br /><br />' .
40       t('It is important to understand the security implications of the htmLawed settings in use and the limitations of htmLawed. To keep the htmLawed script included with the module updated, replace the %htmLawed_php and %htmLawed_README_htm files inside the %htmLawed sub-directory of the module directory with newer versions downloaded from the @htmLawed website.', array('%htmLawed' => 'htmLawed', '%htmLawed_php' => 'htmLawed.php', '%htmLawed_README_htm' => 'htmLawed_README.htm', '@htmLawed' => \Drupal::l('htmLawed', Url::fromUri('http://www.bioinformatics.org/phplabware/internal_utilities/htmLawed')))) . '<br /><br />' .
41       t('For more helpful information, check the @website.', array('@website' => \Drupal::l('htmLawed module website', Url::fromUri('https://www.drupal.org/project/htmlawed'))));
42       break;
43     default:
44   }
45 }
46
47 /**
48  * Implements hook_libraries_info() for Libraries module (API 3.x).
49  */
50 function htmlawed_libraries_info() {
51   $libraries['htmLawed'] = array(
52     'name' => 'htmLawed',
53     'vendor url' => 'http://www.bioinformatics.org/phplabware/internal_utilities/htmLawed',
54     'download url' => 'http://www.bioinformatics.org/phplabware/internal_utilities/htmLawed',
55     'version arguments' => array(
56     // The htmLawed version is hard-coded within function hl_version() in htmLawed.php.
57       'file' => 'htmLawed.php',
58       'pattern' => "`return '([^']+)'`",
59       'lines' => 1500,
60       'cols' => 30,
61     ),
62     'files' => array(
63       'php' => array(
64         'htmLawed.php',
65       ),
66     ),
67   );
68   return $libraries;
69 }