media.media.inc

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

Media module integration for the Media module.

Functions

Namesort descending Description
media_media_browser_plugin_info Implements hook_media_browser_plugin_info().
media_query_media_browser_alter Implements hook_query_media_browser_alter().

File

sites/all/modules/ulmus/media/media.media.inc
View source
  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. $info['upload'] = array(
  11. 'title' => t('Upload'),
  12. 'weight' => -10,
  13. 'class' => 'MediaBrowserUpload',
  14. );
  15. // Add a plugin for each View display using the 'media_browser' display type.
  16. $view_weight = 10;
  17. foreach (views_get_enabled_views() as $view) {
  18. foreach ($view->display as $display) {
  19. if ($display->display_plugin == 'media_browser') {
  20. $title = $display->display_title;
  21. if (!empty($display->display_options['title'])) {
  22. $title = $display->display_options['title'];
  23. }
  24. $info["{$view->name}--{$display->id}"] = array(
  25. 'title' => $title,
  26. // @TODO make this configurable.
  27. 'weight' => $view_weight++,
  28. 'class' => 'MediaBrowserView',
  29. 'view_name' => $view->name,
  30. 'view_display_id' => $display->id,
  31. );
  32. }
  33. }
  34. }
  35. return $info;
  36. }
  37. /**
  38. * Implements hook_query_media_browser_alter().
  39. */
  40. function media_query_media_browser_alter($query) {
  41. // Ensure that the query is against the file_managed table.
  42. $tables = $query->getTables();
  43. if (empty($tables['file_managed'])) {
  44. throw new Exception(t('Media browser being queried without the file_managed table.'));
  45. }
  46. $alias = $tables['file_managed']['alias'];
  47. $params = drupal_get_query_parameters();
  48. // How do we validate these? I don't know.
  49. // I think PDO should protect them, but I'm not 100% certain.
  50. array_walk_recursive($params, 'media_recursive_check_plain');
  51. $types = !empty($params['types']) ? $params['types'] : NULL;
  52. $url_include_patterns = !empty($params['url_include_patterns']) ? $params['url_include_patterns'] : NULL;
  53. $url_exclude_patterns = !empty($params['url_exclude_patterns']) ? $params['url_exclude_patterns'] : NULL;
  54. $allowed_schemes = !empty($params['schemes']) ? array_filter($params['schemes']) : array();
  55. $extensions = !empty($params['file_extensions']) ? array_filter(explode(' ', $params['file_extensions'])) : array();
  56. $or_condition = db_or();
  57. if (!empty($allowed_schemes)) {
  58. // Include local files with the allowed extensions and types.
  59. $local_wrappers = array_intersect_key(media_get_local_stream_wrappers(), $allowed_schemes);
  60. if (!empty($extensions) && !empty($local_wrappers)) {
  61. // Extension filtering.
  62. $local_condition = db_or();
  63. foreach (array_keys($local_wrappers) as $scheme) {
  64. foreach ($extensions as $extension) {
  65. $local_condition->condition($alias . '.uri', db_like($scheme . '://') . '%' . db_like('.' . $extension), 'LIKE');
  66. }
  67. }
  68. $or_condition->condition($local_condition);
  69. }
  70. if (!empty($types) && !empty($local_wrappers)) {
  71. // Type filtering.
  72. $local_condition = db_or();
  73. foreach (array_keys($local_wrappers) as $scheme) {
  74. $local_condition->condition($alias . '.type', $types, 'IN');
  75. }
  76. $or_condition->condition($local_condition);
  77. }
  78. // Include remote files with the allowed file types.
  79. // We cant filter extensions here, because remote file filenames usually
  80. // are a url or a parameter of a query.
  81. $remote_wrappers = array_intersect_key(media_get_remote_stream_wrappers(), $allowed_schemes);
  82. if (!empty($types) && !empty($remote_wrappers)) {
  83. $remote_condition = db_and();
  84. $wrapper_condition = db_or();
  85. foreach (array_keys($remote_wrappers) as $scheme) {
  86. $wrapper_condition->condition($alias . '.uri', db_like($scheme . '://') . '%', 'LIKE');
  87. }
  88. $remote_condition->condition($wrapper_condition);
  89. $remote_condition->condition($alias . '.type', $types, 'IN');
  90. $or_condition->condition($remote_condition);
  91. }
  92. }
  93. else {
  94. if (!empty($types)) {
  95. $query->condition($alias . '.type', $types, 'IN');
  96. }
  97. if (!empty($extensions)) {
  98. foreach ($extensions as $extension) {
  99. $or_condition->condition($alias . '.uri', db_like('.' . $extension), 'LIKE');
  100. }
  101. }
  102. }
  103. if ($or_condition->count()) {
  104. $query->condition($or_condition);
  105. }
  106. if ($url_include_patterns) {
  107. $query->condition($alias . '.uri', '%' . db_like($url_include_patterns) . '%', 'LIKE');
  108. // Insert stream related restrictions here.
  109. }
  110. if ($url_exclude_patterns) {
  111. $query->condition($alias . '.uri', '%' . db_like($url_exclude_patterns) . '%', 'NOT LIKE');
  112. }
  113. if (!user_access('administer files')) {
  114. $query->condition($alias . '.uri', db_like('private://') . '%', 'NOT LIKE');
  115. }
  116. // @todo This is possibly redundant since it's already filtered in the view.
  117. $query->condition($alias . '.status', FILE_STATUS_PERMANENT);
  118. foreach (array_keys(file_entity_get_hidden_stream_wrappers()) as $name) {
  119. $query->condition($alias . '.uri', db_like($name . '://') . '%', 'NOT LIKE');
  120. }
  121. }
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.