You are here

function _htmlpurifier_load in HTML Purifier 6.2

Same name and namespace in other branches
  1. 5 htmlpurifier.module \_htmlpurifier_load()
  2. 6 htmlpurifier.module \_htmlpurifier_load()
  3. 7 htmlpurifier.module \_htmlpurifier_load()

Loads the HTML Purifier library, and performs global initialization.

3 calls to _htmlpurifier_load()
htmlpurifier_requirements in ./htmlpurifier.install
Implementation of hook_requirements().
_htmlpurifier_process in ./htmlpurifier.module
Processes HTML according to a format and returns purified HTML. Makes a cache pass if possible.
_htmlpurifier_settings in ./htmlpurifier.module
Generates a settings form for configuring HTML Purifier.

File

./htmlpurifier.module, line 260
Implements HTML Purifier as a Drupal filter.

Code

function _htmlpurifier_load() {
  static $done = false;
  if ($done) {
    return;
  }
  $done = true;
  $module_path = drupal_get_path('module', 'htmlpurifier');
  $library_path = $module_path;
  if (function_exists('libraries_get_path')) {
    $library_path = libraries_get_path('htmlpurifier');

    // This may happen if the user has HTML Purifier installed under the
    // old configuration, but also installed libraries and forgot to
    // move it over.  There is code for emitting errors in
    // htmlpurifier.install when this is the case.
    if (!file_exists("{$library_path}/library/HTMLPurifier.auto.php")) {

      // Check for an alternate phrasing and error about it
      if (file_exists("{$library_path}/HTMLPurifier.auto.php") && !file_exists("{$module_path}/library/HTMLPurifier.auto.php")) {
        echo "HTML Purifier was installed improperly; move contents of folder {$library_path} to {$library_path}/library";
        exit;
      }
      $library_path = $module_path;
    }
  }
  if (version_compare(phpversion(), '5') < 0) {

    // If your version of PHP is too old, you're going to fail anyway
    // when you attempt to include the HTML Purifier library, so we
    // might as well try to give a useful error message.
    echo 'Your version of PHP is too old to run HTML Purifier, needs PHP 5 or later';
    exit;
  }
  require_once "{$library_path}/library/HTMLPurifier.auto.php";
  require_once "{$module_path}/HTMLPurifier_DefinitionCache_Drupal.php";
  $factory = HTMLPurifier_DefinitionCacheFactory::instance();
  $factory
    ->register('Drupal', 'HTMLPurifier_DefinitionCache_Drupal');

  // Register the version as a variable:
  $current_version = variable_get('htmlpurifier_version_ours', FALSE);
  if ($current_version != HTMLPurifier::VERSION) {
    variable_set('htmlpurifier_version_ours', HTMLPurifier::VERSION);
  }
}