media.pages.inc

  1. cis7 sites/all/modules/ulmus/media/includes/media.pages.inc
  2. cle7 sites/all/modules/ulmus/media/includes/media.pages.inc
  3. ecd7 sites/all/modules/ulmus/media/includes/media.pages.inc
  4. elmsmedia7 sites/all/modules/ulmus/media/includes/media.pages.inc
  5. harmony7 sites/all/modules/ulmus/media/includes/media.pages.inc
  6. icor7 sites/all/modules/ulmus/media/includes/media.pages.inc
  7. meedjum_blog7 sites/all/modules/ulmus/media/includes/media.pages.inc
  8. mooc7 sites/all/modules/ulmus/media/includes/media.pages.inc

Common pages for the Media module.

Functions

Namesort descending Description
media_file_edit_modal CTools modal callback for editing a file.
media_file_page_edit_multiple Menu callback; Edit multiple files on the same page using multiform module.
media_upgrade_file_types File type migration page.
media_upgrade_file_types_confirm File types migration confirmation page.
media_upgrade_file_types_confirm_submit File types migration confirmation page sumit. Executes actual migration.
media_upgrade_file_types_submit File type migration page submit handler.

File

sites/all/modules/ulmus/media/includes/media.pages.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Common pages for the Media module.
  5. */
  6. /**
  7. * Menu callback; Edit multiple files on the same page using multiform module.
  8. *
  9. * @todo When http://drupal.org/node/1227706 is fixed, filter the $files
  10. * array using file_access($file, 'edit').
  11. *
  12. * @see media_file_operation_edit_multiple()
  13. */
  14. function media_file_page_edit_multiple($files) {
  15. if (empty($files)) {
  16. return MENU_ACCESS_DENIED;
  17. }
  18. $forms = array();
  19. foreach ($files as $file) {
  20. // To maintain unique form_ids, append the file id.
  21. $forms[] = array('media_edit_' . $file->fid, $file);
  22. }
  23. $form = call_user_func_array('multiform_get_form', $forms);
  24. $form['#attributes']['class'][] = 'media-multiedit-form';
  25. // Add the title to each 'subform'.
  26. foreach (element_children($form['multiform']) as $key) {
  27. $fid = $form['multiform'][$key]['fid']['#value'];
  28. $file = $files[$fid];
  29. $title = t('<em>Edit @type</em> @title', array('@type' => $file->type, '@title' => $file->filename));
  30. $form['multiform'][$key]['#prefix'] = '<h2>' . $title . '</h2>';
  31. $form['multiform'][$key]['actions']['#access'] = FALSE;
  32. }
  33. if (isset($form['buttons']['Delete'])) {
  34. $form['buttons']['Delete']['#access'] = FALSE;
  35. }
  36. // Add a cancel button at the bottom of the form.
  37. $form['buttons']['cancel'] = array(
  38. '#type' => 'link',
  39. '#title' => t('Cancel'),
  40. '#weight' => 50,
  41. );
  42. if (isset($_GET['destination'])) {
  43. $form['buttons']['cancel']['#href'] = $_GET['destination'];
  44. }
  45. else if (user_access('administer files')) {
  46. $form['buttons']['cancel']['#href'] = 'admin/content/file';
  47. }
  48. else {
  49. $form['buttons']['cancel']['#href'] = '<front>';
  50. }
  51. // Override the page title since each file form sets a title.
  52. drupal_set_title(t('Edit multiple files'));
  53. // Allow other modules to alter the form.
  54. drupal_alter('media_edit_multiple_form', $form);
  55. return $form;
  56. }
  57. /**
  58. * CTools modal callback for editing a file.
  59. */
  60. function media_file_edit_modal($form, &$form_state, $file, $js) {
  61. ctools_include('modal');
  62. ctools_include('ajax');
  63. $form_state['ajax'] = $js;
  64. form_load_include($form_state, 'inc', 'file_entity', 'file_entity.pages');
  65. $output = ctools_modal_form_wrapper('file_entity_edit', $form_state);
  66. if ($js) {
  67. $commands = $output;
  68. if ($form_state['executed']) {
  69. $commands = array(ctools_modal_command_dismiss(t('File saved')));
  70. }
  71. print ajax_render($commands);
  72. exit();
  73. }
  74. // Otherwise, just return the output.
  75. return $output;
  76. }
  77. /**
  78. * File type migration page.
  79. *
  80. * Allows site administrator to execute migration of old/disabled/deleted
  81. * file types to new ones.
  82. */
  83. function media_upgrade_file_types($form, &$form_state) {
  84. $migratable_types = _media_get_migratable_file_types();
  85. // Silently return if there are no file types that need migration.
  86. if (empty($migratable_types)) {
  87. return array(
  88. 'message' => array(
  89. '#markup' => t('There are no file types that need migration.'),
  90. ),
  91. );
  92. }
  93. $form['message'] = array(
  94. 'message' => array(
  95. '#markup' => t('This page allows you to migrate deprecated and/or disabled file types to new ones. It will migrate files from old type to new one and optionally migrate fields and delete old type.'),
  96. ),
  97. );
  98. $form['migrate_fields'] = array(
  99. '#type' => 'checkbox',
  100. '#title' => t('Migrate fields'),
  101. '#default_value' => TRUE,
  102. '#description' => t('Migrate fields and their values from old file types to new ones.'),
  103. );
  104. $form['delete_old_type'] = array(
  105. '#type' => 'checkbox',
  106. '#title' => t('Delete old type'),
  107. '#default_value' => FALSE,
  108. '#description' => t('Delete old file type if migration was successful and delete operation is possible (type is not exported in code).'),
  109. );
  110. $form['migrate_mimes'] = array(
  111. '#type' => 'checkbox',
  112. '#title' => t('Migrate type mime-type'),
  113. '#default_value' => TRUE,
  114. '#description' => t('Move mime-type from old type to new one.'),
  115. );
  116. $form['upgradable_types'] = array(
  117. '#type' => 'fieldset',
  118. '#title' => t('Upgradable file types'),
  119. );
  120. $options = array('- ' . t('Do not upgrade') . ' -');
  121. foreach (file_type_get_enabled_types() as $type) {
  122. $options[$type->type] = $type->label;
  123. }
  124. foreach ($migratable_types as $machine_name) {
  125. $type = file_type_load($machine_name);
  126. if (!$type) {
  127. $type = new stdClass;
  128. $type->label = $type->type = $machine_name;
  129. }
  130. $form['upgradable_types'][$machine_name] = array(
  131. '#type' => 'select',
  132. '#title' => $type->label,
  133. '#options' => $options,
  134. '#description' => t(
  135. 'Select file type which you want to migrate @type to. Select %no_upgrade if type should stay as it is.',
  136. array('@type' => $type->label, '%no_upgrade' => '- ' . t('Do not upgrade') . ' -')),
  137. );
  138. }
  139. $form['submit'] = array(
  140. '#type' => 'submit',
  141. '#value' => t('Start migraton'),
  142. );
  143. return $form;
  144. }
  145. /**
  146. * File type migration page submit handler.
  147. */
  148. function media_upgrade_file_types_submit($form, &$form_state) {
  149. $migratable_types = _media_get_migratable_file_types();
  150. $migrate = FALSE;
  151. foreach ($migratable_types as $type) {
  152. if ($form_state['values'][$type]) {
  153. $migrate = TRUE;
  154. break;
  155. }
  156. }
  157. // Return silently if no types were selected for migration.
  158. if (!$migrate) {
  159. return;
  160. }
  161. // Use confirmation page/form.
  162. $query = $form_state['values'];
  163. unset($query['op']);
  164. unset($query['submit']);
  165. unset($query['form_id']);
  166. unset($query['form_token']);
  167. unset($query['form_build_id']);
  168. $form_state['redirect'] = array(
  169. 'admin/structure/file-types/upgrade/confirm',
  170. array('query' => $query),
  171. );
  172. }
  173. /**
  174. * File types migration confirmation page.
  175. */
  176. function media_upgrade_file_types_confirm($form, &$form_state) {
  177. return confirm_form(
  178. $form,
  179. t('Do you really want to migrate selected file types?'),
  180. 'admin/structure/file-types/upgrade',
  181. NULL,
  182. t('Migrate')
  183. );
  184. }
  185. /**
  186. * File types migration confirmation page sumit. Executes actual migration.
  187. */
  188. function media_upgrade_file_types_confirm_submit($form, &$form_state) {
  189. $migratable_types = _media_get_migratable_file_types();
  190. foreach ($migratable_types as $type) {
  191. if ($_GET[$type] && $bundle_new = file_type_load($_GET[$type])) {
  192. // Old bundle might be deleted so let's fake some values.
  193. $bundle_old = file_type_load($type);
  194. if (empty($bundle_old)) {
  195. $bundle_old = new stdClass;
  196. $bundle_old->type = $type;
  197. $bundle_old->mimetypes = array();
  198. $bundle_old->export_type = 2;
  199. }
  200. // Migrate fields to new bundle.
  201. if ($_GET['migrate_fields']) {
  202. $old_fields = db_select('field_config_instance', 'fc')->fields('fc', array('field_name'))->condition('entity_type', 'file')->condition('bundle', $bundle_old->type)->execute()->fetchCol();
  203. $new_fields = db_select('field_config_instance', 'fc')->fields('fc', array('field_name'))->condition('entity_type', 'file')->condition('bundle', $bundle_new->type)->execute()->fetchCol();
  204. $fields_to_move = array_diff($old_fields, $new_fields);
  205. $fields_to_drop = array_diff($old_fields, $fields_to_move);
  206. db_update('field_config_instance')
  207. ->fields(array('bundle' => $bundle_new->type))
  208. ->condition('entity_type', 'file')
  209. ->condition('bundle', $bundle_old->type)
  210. ->condition('field_name', $fields_to_move, 'IN')
  211. ->execute();
  212. db_delete('field_config_instance')
  213. ->condition('entity_type', 'file')
  214. ->condition('bundle', $bundle_old->type)
  215. ->condition('field_name', $fields_to_drop, 'IN')
  216. ->execute();
  217. field_cache_clear();
  218. module_invoke_all('field_attach_rename_bundle', 'file', $bundle_old->type, $bundle_new->type);
  219. }
  220. // Migrate mimetypes to new bundle.
  221. if ($_GET['migrate_mimes']) {
  222. $changed = FALSE;
  223. foreach ($bundle_old->mimetypes as $mime) {
  224. if (!file_entity_match_mimetypes($bundle_new->mimetypes, $mime)) {
  225. $bundle_new->mimetypes[] = $mime;
  226. $changed = TRUE;
  227. }
  228. }
  229. if ($changed) {
  230. file_type_save($bundle_new);
  231. }
  232. }
  233. // Delete old bundle.
  234. if ($_GET['delete_old_type'] && $bundle_old->export_type == 1) {
  235. file_type_delete($bundle_old);
  236. }
  237. // Migrate files.
  238. db_update('file_managed')
  239. ->fields(array('type' => $bundle_new->type))
  240. ->condition('type', $bundle_old->type)
  241. ->execute();
  242. }
  243. }
  244. $form_state['redirect'] = 'admin/structure/file-types';
  245. }
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.