media.media.inc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /**
  3. * @file
  4. * Media module integration for the Media module.
  5. */
  6. /**
  7. * Implements hook_media_browser_plugin_info().
  8. */
  9. function media_media_browser_plugin_info() {
  10. $plugins = array();
  11. // @TODO: Should we add a permission around this?
  12. $plugins['library'] = array(
  13. '#weight' => 10,
  14. );
  15. if (user_access('administer media') || user_access('edit media')) {
  16. $plugins['upload'] = array(
  17. '#weight' => -10,
  18. );
  19. }
  20. return $plugins;
  21. }
  22. /**
  23. * Implements hook_media_browser_plugin_view().
  24. */
  25. function media_media_browser_plugin_view($plugin_name, $params) {
  26. $path = drupal_get_path('module', 'media');
  27. $params += array(
  28. 'types' => array(),
  29. 'multiselect' => FALSE,
  30. );
  31. // The multiselect parameter is a string. So we check to see if it is set and
  32. // adjust the local variable accordingly.
  33. if ($params['multiselect'] != 'false' && $params['multiselect'] !== FALSE) {
  34. $params['multiselect'] = TRUE;
  35. }
  36. $redirect = array('media/browser', array('query' => array('render' => 'media-popup')));
  37. switch ($plugin_name) {
  38. case 'upload':
  39. $attached = array();
  40. if ($params['multiselect'] && module_exists('plupload')) {
  41. $upload_form_id = 'media_add_upload_multiple';
  42. $attached['js'] = array($path . '/js/plugins/media.upload_multiple.js');
  43. }
  44. else {
  45. $upload_form_id = 'media_add_upload';
  46. }
  47. module_load_include('inc', 'media', 'includes/media.pages');
  48. $upload_form = drupal_get_form($upload_form_id, $params);
  49. return array(
  50. '#title' => t('Upload'),
  51. 'form' => array($upload_form),
  52. '#attached' => $attached,
  53. );
  54. break;
  55. case 'library':
  56. return array(
  57. '#title' => t('Library'),
  58. '#attached' => array(
  59. 'js' => array(
  60. $path . '/js/plugins/media.library.js',
  61. ),
  62. 'css' => array(
  63. //@todo: should move this.
  64. $path . '/js/plugins/media.library.css',
  65. ),
  66. ),
  67. '#settings' => array(
  68. 'viewMode' => 'thumbnails',
  69. 'getMediaUrl' => url('media/browser/list'),
  70. // We should probably change this to load dynamically when requested
  71. // via the JS file.
  72. ) + $params,
  73. '#markup' => '<div id="container"><div id="scrollbox"><ul id="media-browser-library-list" class="media-list-thumbnails"></ul><div id="status"></div></div></div>',
  74. );
  75. break;
  76. }
  77. return array();
  78. }
  79. /**
  80. * Implements hook_media_display_types().
  81. *
  82. * This is used to display media in different ways on the admin section.
  83. * Perhaps should be merged in with the browser display.
  84. */
  85. function media_media_display_types() {
  86. $path = drupal_get_path('module', 'media');
  87. $display_types = array();
  88. $display_types['list'] = array(
  89. 'title' => t('List'),
  90. 'description' => t('Display as a list.'),
  91. 'icon' => $path . '/images/display-list.png',
  92. 'icon_active' => $path . '/images/display-list-active.png',
  93. 'callback' => 'media_admin_list',
  94. 'file' => drupal_get_path('module', 'media') . '/includes/media.admin.inc',
  95. );
  96. $display_types['thumbnails'] = array(
  97. 'title' => t('Thumbnails'),
  98. 'description' => t('Display as thumbnails.'),
  99. 'icon' => $path . '/images/display-thumbnails.png',
  100. 'icon_active' => $path . '/images/display-thumbnails-active.png',
  101. 'callback' => 'media_admin_thumbnails',
  102. 'file' => drupal_get_path('module', 'media') . '/includes/media.admin.inc',
  103. );
  104. return $display_types;
  105. }
  106. /**
  107. * Implements hook_media_operations().
  108. */
  109. function media_media_operations() {
  110. $operations = array(
  111. 'delete' => array(
  112. 'label' => t('Delete'),
  113. 'callback' => NULL,
  114. ),
  115. 'edit' => array(
  116. 'label' => t('Edit'),
  117. 'callback' => NULL,
  118. 'redirect' => 'media/%fids/multiedit'
  119. ),
  120. );
  121. if (!module_exists('multiform')) {
  122. // If the multiform module is not installed, do not show this option.
  123. unset($operations['edit']);
  124. }
  125. return $operations;
  126. }