helper.inc 1.1 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
/**
 * @file
 * Helper functions.
 */

/**
 * Returns path of simplhtmldom library.
 *
 * @return bool|string
 *   Path to the library.
 */
function _simplhtmldom_get_library_path() {

  $file = 'simple_html_dom.php';
  $library = 'simplehtmldom';

  // Implement simple cache.
  $library_path = &drupal_static(__FUNCTION__);
  if (!empty($library_path)) {
    return $library_path;
  }

  // Support libraries module.
  if (module_exists('libraries') && function_exists('libraries_get_path')) {
    $library_path = libraries_get_path($library) . "/$file";
    if (file_exists($library_path)) {
      return $library_path;
    }
  }
  else {
    $paths = array(
      'sites/all/libraries/' . $library,
      drupal_get_path('module', 'simplehtmldom') . '/' . $library,
      drupal_get_path('module', 'simplehtmldom') . "/libraries",
      'profiles/' . variable_get('install_profile', 'default') . '/libraries/' . $library,
    );
    foreach ($paths as $library_dir) {
      $library_path = $library_dir . "/$file";
      if (file_exists($library_path)) {
        return $library_path;
      }
    }
  }
  return FALSE;
}