Revision ed912c77
Added by Assos Assos about 6 years ago
drupal7/sites/all/modules/libraries/libraries.module | ||
---|---|---|
25 | 25 |
} |
26 | 26 |
} |
27 | 27 |
|
28 |
/** |
|
29 |
* Implements hook_admin_menu_cache_info(). |
|
30 |
*/ |
|
31 |
function libraries_admin_menu_cache_info() { |
|
32 |
$caches['libraries'] = array( |
|
33 |
'title' => t('Libraries'), |
|
34 |
'callback' => 'libraries_cache_clear', |
|
35 |
); |
|
36 |
return $caches; |
|
37 |
} |
|
38 |
|
|
39 |
/** |
|
40 |
* Clears the cached library information. |
|
41 |
*/ |
|
42 |
function libraries_cache_clear() { |
|
43 |
foreach (libraries_flush_caches() as $bin) { |
|
44 |
// Using the wildcard argument leads to DrupalDatabaseCache::clear() |
|
45 |
// truncating the libraries cache table which is more performant that |
|
46 |
// deleting the rows. |
|
47 |
cache_clear_all('*', $bin, TRUE); |
|
48 |
} |
|
49 |
} |
|
50 |
|
|
28 | 51 |
/** |
29 | 52 |
* Gets the path of a library. |
30 | 53 |
* |
... | ... | |
77 | 100 |
$profile = drupal_get_path('profile', drupal_get_profile()); |
78 | 101 |
$config = conf_path(); |
79 | 102 |
|
103 |
// $config and $profile should never be empty in a proper Drupal setup. |
|
104 |
// However, we should never search into the root filesystem under any |
|
105 |
// circumstances, so just bail out in that case. |
|
106 |
if (!$profile || !$config) { |
|
107 |
return array(); |
|
108 |
} |
|
109 |
|
|
80 | 110 |
// Similar to 'modules' and 'themes' directories in the root directory, |
81 | 111 |
// certain distributions may want to place libraries into a 'libraries' |
82 | 112 |
// directory in Drupal's root directory. |
... | ... | |
546 | 576 |
$library['version'] = call_user_func_array($library['version callback'], array_merge(array($library), $library['version arguments'])); |
547 | 577 |
} |
548 | 578 |
else { |
549 |
$library['version'] = call_user_func($library['version callback'], $library, $library['version arguments']);
|
|
579 |
$library['version'] = call_user_func_array($library['version callback'], array(&$library, $library['version arguments']));
|
|
550 | 580 |
} |
551 | 581 |
if (empty($library['version'])) { |
552 | 582 |
$library['error'] = 'not detected'; |
... | ... | |
887 | 917 |
fclose($file); |
888 | 918 |
} |
889 | 919 |
|
920 |
/** |
|
921 |
* Gets the version information from a library's package.json file. |
|
922 |
* |
|
923 |
* @param $library |
|
924 |
* An associative array containing all information about the library. |
|
925 |
* @param $options |
|
926 |
* This callback expects no option. |
|
927 |
* @return |
|
928 |
* A string containing the version of the library. |
|
929 |
* |
|
930 |
* @see libraries_get_path() |
|
931 |
*/ |
|
932 |
function libraries_get_package_json_version($library, $options) { |
|
933 |
$file = DRUPAL_ROOT . '/' . $library['library path'] . '/package.json'; |
|
934 |
if (!file_exists($file)) { |
|
935 |
return; |
|
936 |
} |
|
937 |
|
|
938 |
$content = file_get_contents($file); |
|
939 |
if (!$content) { |
|
940 |
return; |
|
941 |
} |
|
942 |
|
|
943 |
$data = drupal_json_decode($content); |
|
944 |
if (isset($data['version'])) { |
|
945 |
return $data['version']; |
|
946 |
} |
|
947 |
} |
|
948 |
|
|
890 | 949 |
/** |
891 | 950 |
* Implements hook_help(). |
892 | 951 |
*/ |
893 | 952 |
function libraries_help($path, $arg) { |
894 | 953 |
switch ($path) { |
895 | 954 |
case 'admin/reports/libraries': |
896 |
return t('Click on a library for a status report or detailed installation instructions in case the library is not installed correctly.');
|
|
955 |
return t('Click on a library for a status report or detailed installation instructions.'); |
|
897 | 956 |
} |
898 | 957 |
} |
899 | 958 |
|
959 |
/** |
|
960 |
* Implements hook_permission(). |
|
961 |
*/ |
|
962 |
function libraries_permission() { |
|
963 |
return array( |
|
964 |
'access library reports' => array( |
|
965 |
'title' => t('View library reports'), |
|
966 |
), |
|
967 |
); |
|
968 |
} |
|
969 |
|
|
900 | 970 |
/** |
901 | 971 |
* Implements hook_menu(). |
902 | 972 |
*/ |
... | ... | |
907 | 977 |
'description' => 'An overview of libraries installed on this site.', |
908 | 978 |
'page callback' => 'drupal_get_form', |
909 | 979 |
'page arguments' => array('libraries_admin_overview'), |
910 |
'access arguments' => array('access site reports'),
|
|
980 |
'access arguments' => array('access library reports'),
|
|
911 | 981 |
'file' => 'libraries.admin.inc' |
912 | 982 |
); |
913 | 983 |
$items['admin/reports/libraries/%libraries_ui'] = array( |
... | ... | |
915 | 985 |
'description' => 'Status overview for a single library', |
916 | 986 |
'page callback' => 'drupal_get_form', |
917 | 987 |
'page arguments' => array('libraries_admin_library_status_form', 3), |
918 |
'access arguments' => array('access site reports'),
|
|
988 |
'access arguments' => array('access library reports'),
|
|
919 | 989 |
'file' => 'libraries.admin.inc' |
920 | 990 |
); |
921 | 991 |
return $items; |
... | ... | |
944 | 1014 |
function libraries_ui_load($name) { |
945 | 1015 |
return libraries_detect($name); |
946 | 1016 |
} |
1017 |
|
|
1018 |
/** |
|
1019 |
* Implements hook_theme(). |
|
1020 |
*/ |
|
1021 |
function libraries_theme($existing, $type, $theme, $path) { |
|
1022 |
// Because we extend the 'table' theme function, fetch the respective |
|
1023 |
// variables dynamically. |
|
1024 |
$common_theme = drupal_common_theme(); |
|
1025 |
$variables = $common_theme['table']['variables'] + array('title' => '', 'description' => ''); |
|
1026 |
return array( |
|
1027 |
'libraries_table_with_title' => array( |
|
1028 |
'variables' => $variables, |
|
1029 |
'file' => 'libraries.theme.inc', |
|
1030 |
), |
|
1031 |
); |
|
1032 |
} |
Also available in: Unified diff
Weekly update of contrib modules