You are here

function tb_megamenu_check_library in The Better Mega Menu 7

1 call to tb_megamenu_check_library()
tb_megamenu_configure_form in ./tb_megamenu.admin.inc

File

./tb_megamenu.functions.inc, line 3

Code

function tb_megamenu_check_library($module, $name) {
  $files = array();
  if ($library = libraries_detect($name)) {
    if (!empty($library['files']['css'])) {
      $files['css'] = libraries_get_path($name) . '/' . key($library['files']['css']);
    }
    if (!empty($library['js'])) {
      $files['js'] = libraries_get_path($name) . '/' . key($library['files']['js']);
    }
  }
  elseif ($library = drupal_get_library($module, $name)) {

    // Get all directories in /sites/all/libraries fully or partially matching $name.
    $paths = [];
    foreach (glob('sites/all/libraries/' . $name . '*') as $path) {
      if (is_dir($path)) {
        $paths[] = $path;
      }
    }

    // If one or more directories were found use the one with the highest version number.
    if (!empty($paths)) {
      $library_path = max($paths);
      if (!empty($library['css'])) {
        $files['css'] = $library_path . key($library['css']);
      }
      if (!empty($library['js'])) {
        $files['js'] = $library_path . key($library['js']);
      }
    }
  }
  return !empty($files) ? $files : FALSE;
}