Révision ca0757b9
Ajouté par Assos Assos il y a plus de 9 ans
drupal7/sites/all/modules/media/media.install | ||
---|---|---|
9 | 9 |
* Implements hook_install(). |
10 | 10 |
*/ |
11 | 11 |
function media_install() { |
12 |
// Create initial display settings. |
|
13 |
module_load_include('inc', 'file_entity', 'file_entity.file_api'); |
|
14 |
$default_image_styles = array( |
|
15 |
'preview' => 'media_thumbnail', |
|
16 |
'teaser' => 'medium', |
|
17 |
'full' => 'large', |
|
18 |
); |
|
19 |
// Only needed by sites that updated from Media 1.x. |
|
20 |
// @see media_entity_info_alter() |
|
21 |
if (variable_get('media__show_deprecated_view_modes')) { |
|
22 |
$default_image_styles['media_original'] = ''; |
|
23 |
} |
|
24 |
|
|
25 |
foreach ($default_image_styles as $view_mode => $image_style) { |
|
26 |
$existing_display = file_displays_load('image', $view_mode); |
|
27 |
|
|
28 |
if (empty($existing_display)) { |
|
29 |
$display_name = 'image__' . $view_mode . '__file_image'; |
|
30 |
$display = array( |
|
31 |
'api_version' => 1, |
|
32 |
'name' => $display_name, |
|
33 |
'status' => 1, |
|
34 |
'weight' => 5, |
|
35 |
'settings' => array('image_style' => $image_style), |
|
36 |
'export_type' => NULL, |
|
37 |
); |
|
38 |
file_display_save((object) $display); |
|
39 |
} |
|
40 |
} |
|
41 |
|
|
42 | 12 |
// Make sure that we set the icon base directory variable if it is not |
43 | 13 |
// already set. |
44 |
$base = variable_get('media__icon_base_directory', NULL);
|
|
14 |
$base = variable_get('media_icon_base_directory', NULL); |
|
45 | 15 |
if (!isset($base)) { |
46 | 16 |
$default_base = 'public://media-icons'; |
47 |
variable_set('media__icon_base_directory', $default_base);
|
|
17 |
variable_set('media_icon_base_directory', $default_base); |
|
48 | 18 |
} |
49 | 19 |
try { |
50 | 20 |
_media_install_copy_icons(); |
... | ... | |
58 | 28 |
* Copy the media file icons to files directory for use with image styles. |
59 | 29 |
*/ |
60 | 30 |
function _media_install_copy_icons() { |
61 |
$destination = variable_get('media__icon_base_directory', 'public://media-icons') . '/' . variable_get('media__icon_set', 'default');
|
|
31 |
$destination = variable_get('media_icon_base_directory', 'public://media-icons') . '/' . variable_get('media_icon_set', 'default');
|
|
62 | 32 |
if (!file_prepare_directory($destination, FILE_CREATE_DIRECTORY)) { |
63 | 33 |
throw new Exception("Unable to create directory $destination."); |
64 | 34 |
} |
65 | 35 |
// @todo If we ever add another default icon set, this should copy all images from one directory up. |
66 |
$source = drupal_get_path('module', 'media') . '/images/icons/' . variable_get('media__icon_set', 'default');
|
|
36 |
$source = drupal_get_path('module', 'media') . '/images/icons/' . variable_get('media_icon_set', 'default'); |
|
67 | 37 |
$files = file_scan_directory($source, '/.*\.(png|jpg)$/'); |
68 | 38 |
foreach ($files as $file) { |
69 | 39 |
$result = file_unmanaged_copy($file->uri, $destination, FILE_EXISTS_REPLACE); |
... | ... | |
78 | 48 |
*/ |
79 | 49 |
function media_uninstall() { |
80 | 50 |
// Remove variables. |
81 |
variable_del('media__wysiwyg_title'); |
|
82 |
variable_del('media__wysiwyg_icon_title'); |
|
83 |
variable_del('media__wysiwyg_default_view_mode'); |
|
84 |
variable_del('media__wysiwyg_upload_directory'); |
|
85 |
variable_del('media__wysiwyg_allowed_types'); |
|
86 |
variable_del('media__wysiwyg_allowed_attributes'); |
|
87 |
variable_del('media__wysiwyg_browser_plugins'); |
|
88 |
variable_del('media__dialog_theme'); |
|
89 |
variable_del('media__max_filesize'); |
|
90 |
variable_del('media__debug'); |
|
91 |
variable_del('media__file_list_size'); |
|
92 |
variable_del('media__xml_cache_expire'); |
|
93 |
variable_del('media__import_batch_size'); |
|
94 |
variable_del('media__fromurl_supported_schemes'); |
|
95 |
variable_del('media__icon_base_directory'); |
|
96 |
variable_del('media__icon_set'); |
|
97 |
variable_del('media__show_deprecated_view_modes'); |
|
98 |
variable_del('media__show_file_type_rebuild_nag'); |
|
99 |
variable_del('media__field_select_media_text'); |
|
100 |
variable_del('media__field_remove_media_text'); |
|
101 |
variable_del('media__browser_library_empty_message'); |
|
102 |
variable_del('media__browser_pager_limit'); |
|
103 |
variable_del('media__browser_viewtype_default'); |
|
104 |
variable_del('media__display_types_migration_mess'); |
|
51 |
variable_del('media_dialog_theme'); |
|
52 |
variable_del('media_icon_base_directory'); |
|
53 |
variable_del('media_icon_set'); |
|
54 |
variable_del('media_show_deprecated_view_modes'); |
|
55 |
|
|
56 |
// Dialog options. |
|
57 |
variable_del('media_dialogclass'); |
|
58 |
variable_del('media_modal'); |
|
59 |
variable_del('media_draggable'); |
|
60 |
variable_del('media_resizable'); |
|
61 |
variable_del('media_minwidth'); |
|
62 |
variable_del('media_width'); |
|
63 |
variable_del('media_height'); |
|
64 |
variable_del('media_position'); |
|
65 |
variable_del('media_zindex'); |
|
66 |
variable_del('media_backgroundcolor'); |
|
67 |
variable_del('media_opacity'); |
|
105 | 68 |
} |
106 | 69 |
|
107 | 70 |
/** |
... | ... | |
129 | 92 |
$dependencies['media'][7208] = array( |
130 | 93 |
'file_entity' => 7210, |
131 | 94 |
); |
95 |
$dependencies['media'][7212] = array( |
|
96 |
'file_entity' => 7210, |
|
97 |
); |
|
132 | 98 |
return $dependencies; |
133 | 99 |
} |
134 | 100 |
|
... | ... | |
916 | 882 |
} |
917 | 883 |
|
918 | 884 |
/** |
919 |
* DEPRECATED: Update {file_managed}.type with the new file types provided by |
|
920 |
* file_entity. (Types migration has been moved to admin/structure/file-types/upgrade', |
|
921 |
* where can be executed manually.) |
|
885 |
* Enable the hidden media_migrate_file_types module to provide a UI to update |
|
886 |
* {file_managed}.type with the new file types provided by file_entity. |
|
922 | 887 |
*/ |
923 | 888 |
function media_update_7209() { |
889 |
drupal_load('module', 'media_migrate_file_types'); |
|
924 | 890 |
|
891 |
if (_media_migrate_file_types_get_migratable_file_types()) { |
|
892 |
module_enable(array('media_migrate_file_types')); |
|
893 |
} |
|
925 | 894 |
} |
926 | 895 |
|
927 | 896 |
/** |
... | ... | |
932 | 901 |
} |
933 | 902 |
|
934 | 903 |
/** |
935 |
* Flush old version of the image style to make the thumbnails appear correctly. |
|
904 |
* Save a square_thumbnail image style in the database for legacy support if one |
|
905 |
* does not already exist. |
|
936 | 906 |
*/ |
937 | 907 |
function media_update_7211() { |
938 |
$style = image_style_load('square_thumbnail'); |
|
908 |
$default_style = array( |
|
909 |
'name' => 'square_thumbnail' |
|
910 |
); |
|
939 | 911 |
|
940 |
if ($style) { |
|
941 |
$style['name'] = 'media_thumbnail'; |
|
942 |
image_style_save($style); |
|
943 |
} |
|
912 |
// Clear the image cache to remove any old image styles that only exist in |
|
913 |
// code. |
|
914 |
cache_clear_all('*', 'cache_image', TRUE); |
|
915 |
|
|
916 |
// Check if the square_thumbnail image style exists. |
|
917 |
// The style will only exist if the user has customized it, otherwise it would |
|
918 |
// have been removed by clearing the image style cache. |
|
919 |
$existing_style = image_style_load('square_thumbnail'); |
|
920 |
|
|
921 |
// Save a square_thumbnail image style in the database for legacy support. |
|
922 |
// This is only necessary if a square_thumbnail image style doesn't already |
|
923 |
// exist. |
|
924 |
if (empty($existing_style)) { |
|
925 |
$style = image_style_save($default_style); |
|
926 |
|
|
927 |
$effect = array( |
|
928 |
'name' => 'image_scale_and_crop', |
|
929 |
'data' => array( |
|
930 |
'width' => 180, |
|
931 |
'height' => 180, |
|
932 |
'weight' => 0, |
|
933 |
), |
|
934 |
'isid' => $style['isid'], |
|
935 |
); |
|
944 | 936 |
|
945 |
// Replace any instances in display settings |
|
946 |
module_load_include('inc', 'file_entity', 'file_entity.file_api'); |
|
947 |
$entity_info = entity_get_info('file'); |
|
948 |
$view_modes = array('default' => array('label' => t('Default'))) + $entity_info['view modes']; |
|
949 |
foreach ($view_modes as $view_mode => $view_mode_info) { |
|
950 |
$displays = file_displays_load('image', $view_mode); |
|
951 |
foreach ($displays as $display) { |
|
952 |
if ($display->settings['image_style'] == 'square_thumbnail') { |
|
953 |
$display->settings['image_style'] = 'media_thumbnail'; |
|
954 |
file_display_save($display); |
|
955 |
} |
|
956 |
} |
|
937 |
image_effect_save($effect); |
|
957 | 938 |
} |
958 | 939 |
|
959 |
return t('Flushed image style and updated display styles.');
|
|
940 |
return t('Saved a square_thumbnail image style in the database for legacy support if one did not already exist.');
|
|
960 | 941 |
} |
961 | 942 |
|
962 | 943 |
/** |
... | ... | |
1068 | 1049 |
|
1069 | 1050 |
variable_del('media__xml_cache_expire'); |
1070 | 1051 |
} |
1052 |
|
|
1053 |
/** |
|
1054 |
* Enable the Media WYSIWYG submodule. |
|
1055 |
*/ |
|
1056 |
function media_update_7219() { |
|
1057 |
if (module_exists('wysiwyg')) { |
|
1058 |
module_enable(array('media_wysiwyg')); |
|
1059 |
} |
|
1060 |
} |
|
1061 |
|
|
1062 |
/** |
|
1063 |
* Delete the deprecated media__file_list_size variable. |
|
1064 |
*/ |
|
1065 |
function media_update_7220() { |
|
1066 |
variable_del('media__file_list_size'); |
|
1067 |
} |
|
1068 |
|
|
1069 |
/** |
|
1070 |
* Enable the Media Bulk Upload submodule. |
|
1071 |
*/ |
|
1072 |
function media_update_7221() { |
|
1073 |
if (module_exists('multiform') && module_exists('plupload')) { |
|
1074 |
module_enable(array('media_bulk_upload')); |
|
1075 |
} |
|
1076 |
} |
|
1077 |
|
|
1078 |
/** |
|
1079 |
* Delete the deprecated media__display_types_migration_mess variable. |
|
1080 |
*/ |
|
1081 |
function media_update_7222() { |
|
1082 |
variable_del('media__display_types_migration_mess'); |
|
1083 |
} |
|
1084 |
|
|
1085 |
/** |
|
1086 |
* Delete legacy variables. |
|
1087 |
*/ |
|
1088 |
function media_update_7223() { |
|
1089 |
variable_del('media__max_filesize'); |
|
1090 |
variable_del('media__debug'); |
|
1091 |
variable_del('media__xml_cache_expire'); |
|
1092 |
variable_del('media__show_file_type_rebuild_nag'); |
|
1093 |
variable_del('media__field_select_media_text'); |
|
1094 |
variable_del('media__field_remove_media_text'); |
|
1095 |
variable_del('media__browser_library_empty_message'); |
|
1096 |
variable_del('media__browser_pager_limit'); |
|
1097 |
variable_del('media__browser_viewtype_default'); |
|
1098 |
} |
|
1099 |
|
|
1100 |
/** |
|
1101 |
* Rename variables, removing variable namespace. |
|
1102 |
*/ |
|
1103 |
function media_update_7224() { |
|
1104 |
// Create an array of variables sans 'media' prefix. |
|
1105 |
$variables = array('wysiwyg_title', 'wysiwyg_icon_title', 'wysiwyg_default_view_mode', 'wysiwyg_upload_directory', 'wysiwyg_allowed_types', 'wysiwyg_allowed_attributes', 'wysiwyg_browser_plugins', 'dialog_theme', 'import_batch_size', 'fromurl_supported_schemes', 'icon_base_directory', 'icon_set', 'show_deprecated_view_modes'); |
|
1106 |
|
|
1107 |
foreach ($variables as $variable) { |
|
1108 |
// Find the value of the old variable. |
|
1109 |
$value = variable_get('media__' . $variable); |
|
1110 |
|
|
1111 |
// Port the value of the variable if it was set. |
|
1112 |
if (!is_null($value)) { |
|
1113 |
variable_set('media_' . $variable, $value); |
|
1114 |
} |
|
1115 |
|
|
1116 |
// Remove the old variable. |
|
1117 |
variable_del('media__' . $variable); |
|
1118 |
} |
|
1119 |
} |
|
1120 |
|
|
1121 |
/** |
|
1122 |
* Migrate variables to appropriate submodules. |
|
1123 |
*/ |
|
1124 |
function media_update_7225() { |
|
1125 |
$data = array( |
|
1126 |
'media_wysiwyg' => array( |
|
1127 |
'wysiwyg_title', |
|
1128 |
'wysiwyg_icon_title', |
|
1129 |
'wysiwyg_default_view_mode', |
|
1130 |
'wysiwyg_upload_directory', |
|
1131 |
'wysiwyg_allowed_types', |
|
1132 |
'wysiwyg_allowed_attributes', |
|
1133 |
'wysiwyg_browser_plugins', |
|
1134 |
), |
|
1135 |
'media_internet' => array( |
|
1136 |
'fromurl_supported_schemes', |
|
1137 |
), |
|
1138 |
'media_bulk_upload' => array( |
|
1139 |
'import_batch_size', |
|
1140 |
), |
|
1141 |
); |
|
1142 |
|
|
1143 |
foreach ($data as $module => $variables) { |
|
1144 |
foreach ($variables as $variable) { |
|
1145 |
// Only port variables to submodules if the submodule exists. |
|
1146 |
if (module_exists($module)) { |
|
1147 |
// Find the value of the old variable. |
|
1148 |
$value = variable_get('media_' . $variable); |
|
1149 |
|
|
1150 |
// Port the value of the variable if it was set. |
|
1151 |
if (!is_null($value)) { |
|
1152 |
variable_set($module . '_' . $variable, $value); |
|
1153 |
} |
|
1154 |
} |
|
1155 |
|
|
1156 |
// Remove the old variable. |
|
1157 |
variable_del('media_' . $variable); |
|
1158 |
} |
|
1159 |
} |
|
1160 |
} |
|
1161 |
|
|
1162 |
/** |
|
1163 |
* Accommodate the introduction of a new permission which restricts access to |
|
1164 |
* the media browser by granting it to existing users who were able to access |
|
1165 |
* it. |
|
1166 |
*/ |
|
1167 |
function media_update_7226() { |
|
1168 |
$roles = user_roles(FALSE, 'create files'); |
|
1169 |
|
|
1170 |
foreach ($roles as $rid => $role) { |
|
1171 |
user_role_grant_permissions($rid, array('access media browser')); |
|
1172 |
} |
|
1173 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules