Skip to content

Instantly share code, notes, and snippets.

@yec
Created January 17, 2013 01:55
Show Gist options
  • Save yec/4552839 to your computer and use it in GitHub Desktop.
Save yec/4552839 to your computer and use it in GitHub Desktop.
commit c49692be4b1e9990bf7b01a8202 and drush on media-7.x-2.0-unstable7
diff --git a/includes/MediaBrowserUpload.inc b/includes/MediaBrowserUpload.inc
index 194c109..65e9977 100644
--- a/includes/MediaBrowserUpload.inc
+++ b/includes/MediaBrowserUpload.inc
@@ -15,7 +15,7 @@ class MediaBrowserUpload extends MediaBrowserPlugin {
* Implements MediaBrowserPluginInterface::access().
*/
public function access($account = NULL) {
- return file_entity_access('create', $account);
+ return file_entity_access('create', NULL, $account);
}
/**
diff --git a/includes/media.browser.inc b/includes/media.browser.inc
index fd91c17..fb13c65 100644
--- a/includes/media.browser.inc
+++ b/includes/media.browser.inc
@@ -12,22 +12,7 @@ function media_browser($selected = NULL) {
$output = array();
$output['#attached']['library'][] = array('media', 'media_browser_page');
- // Build out browser settings. Permissions- and security-related behaviors
- // should not rely on these parameters, since they come from the HTTP query.
- // @TODO make sure we treat parameters as user input.
- $params = drupal_get_query_parameters() + array(
- 'types' => array(),
- 'multiselect' => FALSE,
- );
-
- // Transform text 'true' and 'false' to actual booleans.
- foreach ($params as $k => $v) {
- if ($v === 'true') { $params[$k] = TRUE; }
- elseif ($v === 'false') { $params[$k] = FALSE; }
- }
-
- array_walk_recursive($params, 'media_recursive_check_plain');
- $params = media_set_browser_params($params);
+ $params = media_set_browser_params();
// If one or more files have been selected, the browser interaction is now
// complete. Return empty page content to the dialog which now needs to close,
@@ -170,22 +155,35 @@ function media_browser($selected = NULL) {
*
* It also offers a chance for some meddler to meddle with them.
*
- * @param array $params
- * An array of parameters provided when a media_browser is launched.
- *
* @see media_browser()
*/
-function media_set_browser_params(array $params = NULL) {
- $stored_params = &drupal_static(__FUNCTION__, array());
+ function media_set_browser_params() {
+ $params = &drupal_static(__FUNCTION__, array());
- if (isset($params)) {
- $stored_params = $params;
- // Allow modules to alter the parameters.
- drupal_alter('media_browser_params', $stored_params);
- }
+ if (empty($params)) {
+ // Build out browser settings. Permissions- and security-related behaviors
+ // should not rely on these parameters, since they come from the HTTP query.
+ // @TODO make sure we treat parameters as user input.
+ $params = drupal_get_query_parameters() + array(
+ 'types' => array(),
+ 'multiselect' => FALSE,
+ );
+
+ // Transform text 'true' and 'false' to actual booleans.
+ foreach ($params as $k => $v) {
+ if ($v === 'true') { $params[$k] = TRUE; }
+ elseif ($v === 'false') { $params[$k] = FALSE; }
+ }
+
+ array_walk_recursive($params, 'media_recursive_check_plain');
+
+ // Allow modules to alter the parameters.
+ drupal_alter('media_browser_params', $params);
+ }
+
+ return $params;
+ }
- return $stored_params;
-}
/**
* For sanity in grammar.
diff --git a/includes/media.filter.inc b/includes/media.filter.inc
index 4e9d64c..b8f8065 100644
--- a/includes/media.filter.inc
+++ b/includes/media.filter.inc
@@ -180,14 +180,29 @@ function media_token_to_markup($match, $wysiwyg = FALSE) {
// Display the field elements.
$element = array();
$element['content']['file'] = media_get_file_without_label($file, $tag_info['view_mode'], $settings);
+ // Overwrite or set the file #alt attribute if it has been set in this instance.
+ if (!empty($element['content']['file']['#attributes']['alt'])) {
+ $element['content']['file']['#alt'] = $element['content']['file']['#attributes']['alt'];
+ }
+ // Overwrite or set the file #title attribute if it has been set in this instance.
+ if (!empty($element['content']['file']['#attributes']['title'])) {
+ $element['content']['file']['#title'] = $element['content']['file']['#attributes']['title'];
+ }
field_attach_prepare_view('file', array($file->fid => $file), $tag_info['view_mode']);
entity_prepare_view('file', array($file->fid => $file));
$element['content'] += field_attach_view('file', $file, $tag_info['view_mode']);
if (count(element_children($element['content'])) > 1) {
// Add surrounding divs to group them together.
- // We dont want divs when there are no additional fields to allow them
- // to display inline.
- $element['content']['#prefix'] = '<div>';
+ // We dont want divs when there are no additional fields to allow files
+ // to display inline with text, without breaking p tags.
+ $attributes = array(
+ 'class' => array(
+ 'media',
+ 'media-element-container',
+ 'media-' . $element['content']['file']['#view_mode'],
+ ),
+ );
+ $element['content']['#prefix'] = '<div ' . drupal_attributes($attributes) . '>';
$element['content']['#suffix'] = '</div>';
}
}
@@ -380,6 +395,22 @@ function media_format_form($form, $form_state, $file) {
'#default_value' => $default_view_mode
);
+ if ($file->type === 'image') {
+ $form['options']['alt'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Alternate text'),
+ '#description' => t('This text will be used by screen readers, search engines, or when the image cannot be loaded.'),
+ '#default_value' => isset($file->field_file_image_alt_text['und'][0]['safe_value']) ? $file->field_file_image_alt_text['und'][0]['safe_value'] : '',
+ );
+
+ $form['options']['title'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Title'),
+ '#description' => t('The title is used as a tool tip when the user hovers the mouse over the image.'),
+ '#default_value' => isset($file->field_file_image_title_text['und'][0]['safe_value']) ? $file->field_file_image_title_text['und'][0]['safe_value'] : '',
+ );
+ }
+
// Similar to a form_alter, but we want this to run first so that media.types.inc
// can add the fields specific to a given type (like alt tags on media).
// If implemented as an alter, this might not happen, making other alters not
diff --git a/includes/media.theme.inc b/includes/media.theme.inc
index d801baa..b5c82dd 100644
--- a/includes/media.theme.inc
+++ b/includes/media.theme.inc
@@ -20,61 +20,6 @@ function theme_media_file_list($element) {
return '<div class="media-file-list">' . theme('form_element', $element, $element['#children']) . '</div>';
}
-/**
- * Default theming function for creating the browser frame.
- *
- * Assumes an array of file objects as $files and an
- * array of $parameters
- *
- * @param $variables
- * array of variables
- * @return unknown_type
- */
-function theme_media_browser_content_frame($variables) {
- // Pull out all the variables into a usable form
- extract($variables);
- // Did we get any files back?
- if (! count($files)) {
- // @TODO display no files found
- }
-
- $html = array();
-
- // On the first invocation, load javascript and build the browser frame
- if ($invoke) {
-
-
- }
- // Render the results limiter
- $html[] = theme('media_browser_control_result_limit', array('parameters' => $parameters));
- // Render the actual content
- $form = drupal_get_form('media_file_listing_form', $files, $parameters);
- $html[] = drupal_render($form);
-
- // Make sure to close the wrapping div
- if ($invoke) {
- $html[] = '</div>';
- }
- return implode("\n", $html);
-}
-
-/**
- * Display a item list of files as thumbnails. Implements
- * the admin thumbnail theme for now- serves as a wrapper
- *
- * @param $files
- * An array of file objects to display.
- * @return
- */
-function theme_media_browser_thumbnails($variables) {
- $files = $variables['files'];
- $style_name = $variables['style_name'];
- $thumbnails = array();
- foreach ($files as $file) {
- $thumbnails[] = theme('media_admin_thumbnail', array('file' => $file, 'style_name' => $style_name));
- }
- return theme('item_list', array('items' => $thumbnails, 'attributes' => array('class' => 'media_content_navigator results')));
-}
/**
@@ -128,49 +73,6 @@ function template_preprocess_media_dialog_page(&$variables) {
$variables['messages'] = theme('status_messages');
}
-/* ******************************************** */
-/* Content navigation controls */
-/* ******************************************** */
-
-
-/**
- * Theme function to display the results limiting- 10, 30, 50 results
- * per page.
- *
- * @param $variables
- * array parameters
- * @return unknown
- */
-function theme_media_browser_control_result_limit($variables) {
- // Pull out all the variables into a usable form
- extract($variables);
-
- if (!isset($limits)) {
- $limits = array(10, 30, 50);
- }
-
- // @NOTE these do not need to be aware of the current
- // page because clicking them will reset the
- // display to 1 -> $limit
- $parameters['page'] = 0;
- // save the active limit
- $current_limit = $parameters['limit'];
- $per_display = array();
- foreach ($limits as $limit) {
- if ($limit == $current_limit) {
- $class = 'active';
- }
- else {
- $class = '';
- }
- // set the value of this limit parameter to this limit value
- $parameters['limit'] = $limit;
- $per_display[] = l($limit, $limit, array('query' => $parameters, 'attributes' => array('class' => $class)));
- }
-
- return theme('item_list', array('items' => $per_display, 'attributes' => array('class' => 'result_limit')));
-}
-
/**
* Adds a wrapper around a preview of a media file.
* @param unknown_type $element
diff --git a/includes/media.variables.inc b/includes/media.variables.inc
index 938f6e4..e3b8cd3 100644
--- a/includes/media.variables.inc
+++ b/includes/media.variables.inc
@@ -130,7 +130,7 @@ function media_variable_default($name = NULL) {
// Name of the theme to use in media popup dialogs, defaults to admin_theme
'dialog_theme' => '',
// @TODO: Make a configuration form with this.
- 'file_extensions' => FILE_ENTITY_DEFAULT_ALLOWED_EXTENSIONS . ' mp3 mov mp4 m4a m4v mpeg avi ogg oga ogv wmv ico',
+ 'file_extensions' => variable_get('file_entity_default_allowed_extensions', 'jpg jpeg gif png txt doc docx xls xlsx pdf ppt pptx pps ppsx odt ods odp') . ' mp3 mov mp4 m4a m4v mpeg avi ogg oga ogv wmv ico',
'max_filesize' => '',
'debug' => FALSE,
diff --git a/js/plugins/media.views.js b/js/plugins/media.views.js
index f5f44d0..9dfe231 100644
--- a/js/plugins/media.views.js
+++ b/js/plugins/media.views.js
@@ -65,6 +65,14 @@ Drupal.media.browser.views.select = function(view) {
* Sets up event-handlers for selecting items in the view.
*/
Drupal.media.browser.views.setup = function(view) {
+ // Ensure we only setup each view once..
+ if ($(view).hasClass('media-browser-views-processed')) {
+ return;
+ }
+
+ // Reset the list of selected files
+ Drupal.media.browser.selectMedia([]);
+
// Catch the click on a media item
$('.view-content .media-item', view).bind('click', function () {
var fid = $(this).closest('a[data-fid]').data('fid'),
@@ -120,6 +128,9 @@ Drupal.media.browser.views.setup = function(view) {
}
Drupal.media.browser.selectMedia(selectedFiles);
});
+
+ // Add the processed class, so we dont accidentally process the same element twice..
+ $(view).addClass('media-browser-views-processed');
}
}(jQuery));
diff --git a/js/wysiwyg-media.js b/js/wysiwyg-media.js
index 003ed88..66ef30b 100644
--- a/js/wysiwyg-media.js
+++ b/js/wysiwyg-media.js
@@ -171,7 +171,8 @@ InsertMedia.prototype = {
insert: function (formatted_media) {
var element = create_element(formatted_media.html, {
fid: this.mediaFile.fid,
- view_mode: formatted_media.type
+ view_mode: formatted_media.type,
+ attributes: formatted_media.options
});
var markup = outerHTML(element),
diff --git a/media.info b/media.info
index e4bd654..edb80a6 100644
--- a/media.info
+++ b/media.info
@@ -20,9 +20,9 @@ files[] = tests/media.entity.test
configure = admin/config/media/browser
-; Information added by drupal.org packaging script on 2012-11-18
-version = "7.x-2.0-unstable7"
-core = "7.x"
+
+; Information added by drush on 2013-01-16
+version = "unknown"
project = "media"
-datestamp = "1353227523"
+datestamp = "1358387122"
diff --git a/media.install b/media.install
index ad86f2b..3f6712f 100644
--- a/media.install
+++ b/media.install
@@ -845,11 +845,9 @@ function media_update_7208() {
include_once DRUPAL_ROOT . '/includes/file.mimetypes.inc';
$mapping = file_mimetype_mapping();
+ // We do not migrate this type, since there is no way to handle its weight.
+ unset($existing_types['default']);
foreach ($existing_types as $type) {
- if ($type->name == 'default') {
- // We do not migrate this type, since there is no way to handle its weight.
- continue;
- }
$extensions = isset($type->type_callback_args['extensions']) ? $type->type_callback_args['extensions'] : array();
$mimetypes = isset($type->type_callback_args['mimetypes']) ? $type->type_callback_args['mimetypes'] : array();
// Add mimetypes by extensions.
@@ -874,6 +872,9 @@ function media_update_7208() {
$new_type->mimetypes = array_merge($type->mimetypes, $new_type->mimetypes);
$new_type->streams = array_merge($type->streams, $new_type->streams);
}
+ else {
+ $new_type = $type;
+ }
file_type_save($new_type);
}
db_drop_table('media_type');
@@ -881,6 +882,9 @@ function media_update_7208() {
// Special treatment for old media application type to new file_entity
// document one. Add some more mimetypes to document.
$document_type = file_type_load('document');
+ if (!$document_type) {
+ return;
+ }
foreach($mapping['mimetypes'] as $mimetype) {
$is_document = strpos($mimetype, 'document') !== FALSE || strpos($mimetype, 'application/vnd.ms-') !== FALSE;
if ($is_document && !in_array($mimetype, $document_type->mimetypes)) {
diff --git a/media.module b/media.module
index 6e28da0..12d6996 100644
--- a/media.module
+++ b/media.module
@@ -113,7 +113,7 @@ function media_menu() {
'description' => 'Configure the behavior and display of the media browser.',
'page callback' => 'drupal_get_form',
'page arguments' => array('media_admin_config_browser'),
- 'access arguments' => array('administer files'),
+ 'access arguments' => array('administer media browser'),
'file' => 'includes/media.admin.inc',
);
@@ -243,6 +243,10 @@ function media_admin_paths() {
*/
function media_permission() {
return array(
+ 'administer media browser' => array(
+ 'title' => t('Administer media browser'),
+ 'description' => t('Access media browser settings.'),
+ ),
'import media' => array(
'title' => t('Import media files from the local filesystem'),
'description' => t('Simple file importer'),
@@ -578,7 +582,7 @@ function media_form_file_entity_add_upload_alter(&$form, &$form_state) {
// If the list of allowed extensions is the default provided by file_entity
// then change the default to the more permissive media extension list.
- if (isset($validators['file_validate_extensions']) && $validators['file_validate_extensions'] == array(FILE_ENTITY_DEFAULT_ALLOWED_EXTENSIONS)) {
+ if (isset($validators['file_validate_extensions']) && $validators['file_validate_extensions'] == array(variable_get('file_entity_default_allowed_extensions', 'jpg jpeg gif png txt doc docx xls xlsx pdf ppt pptx pps ppsx odt ods odp'))) {
$validators['file_validate_extensions'] = array(media_variable_get('file_extensions'));
}
}
@@ -930,13 +934,15 @@ function media_element_process(&$element, &$form_state, $form) {
'#prefix' => '<div class="preview launcher">',
'#suffix' => '</div>',
'#weight' => 0,
- 'content' => !empty($file) ? media_get_thumbnail_preview($file) : array(),
+ 'content' => $file ? media_get_thumbnail_preview($file) : array(),
);
+ // @todo: Perhaps this language logic should be handled by JS since the state
+ // changes on client side after choosing an item.
$element['select'] = array(
'#type' => 'link',
'#href' => '',
- '#title' => t('Select media'),
+ '#title' => $file ? t('Replace') : t('Add'),
'#attributes' => array('class' => array('button', 'launcher')),
'#options' => array('fragment' => FALSE, 'external' => TRUE),
'#weight' => 10,
@@ -945,7 +951,7 @@ function media_element_process(&$element, &$form_state, $form) {
$element['edit'] = array(
'#type' => 'link',
'#href' => 'media/' . $fid . '/edit/nojs',
- '#title' => t('Edit media'),
+ '#title' => t('Edit'),
'#attributes' => array(
'class' => array(
'ctools-use-modal', 'use-ajax', // Required for CTools modal to work.
@@ -958,7 +964,7 @@ function media_element_process(&$element, &$form_state, $form) {
$element['remove'] = array(
'#type' => 'link',
'#href' => '',
- '#title' => t('Remove media'),
+ '#title' => t('Remove'),
'#attributes' => array('class' => array('button', 'remove')),
'#options' => array('fragment' => FALSE, 'external' => TRUE),
'#weight' => 30,
diff --git a/modules/media_internet/media_internet.info b/modules/media_internet/media_internet.info
index 190889d..00602da 100644
--- a/modules/media_internet/media_internet.info
+++ b/modules/media_internet/media_internet.info
@@ -5,9 +5,9 @@ core = 7.x
dependencies[] = media
files[] = includes/MediaBrowserInternet.inc
-; Information added by drupal.org packaging script on 2012-11-18
-version = "7.x-2.0-unstable7"
-core = "7.x"
+
+; Information added by drush on 2013-01-16
+version = "unknown"
project = "media"
-datestamp = "1353227523"
+datestamp = "1358387122"
diff --git a/modules/media_internet/media_internet.module b/modules/media_internet/media_internet.module
index e785037..2905ec3 100644
--- a/modules/media_internet/media_internet.module
+++ b/modules/media_internet/media_internet.module
@@ -52,10 +52,22 @@ function media_internet_permission() {
* @todo Convert the form arguments to just one array of options/parameters.
*/
function media_internet_add($form, &$form_state = array(), $types = NULL) {
+ $providers = array();
+ foreach (media_internet_get_providers() as $key => $provider) {
+ if (empty($provider['hidden']) || $provider['hidden'] != TRUE) {
+ // @todo Convert this to show provider images in a nice format.
+ $class = drupal_clean_css_identifier(drupal_strtolower($provider['title']));
+ $providers[] = array(
+ 'data' => check_plain($provider['title']),
+ 'class' => array($class),
+ );
+ }
+ }
+
$form['embed_code'] = array(
'#type' => 'textfield',
- '#title' => t('URL or Embed code'),
- '#description' => t('Input a url or embed code from one of the listed providers.'),
+ '#title' => t('Enter a URL to an image'),
+ '#description' => t('Enter a URL to an image on the web.'),
'#attributes' => array('class' => array('media-add-from-url')),
// There is no standard specifying a maximum length for a URL. Internet
// Explorer supports upto 2083 (http://support.microsoft.com/kb/208427), so
@@ -64,41 +76,26 @@ function media_internet_add($form, &$form_state = array(), $types = NULL) {
'#required' => TRUE,
);
-
- // @todo:
- // Add live previews back (currently broken)
-
- //$form['preview'] = array(
- // '#type' => 'item',
- // '#title' => t('Preview'),
- // '#markup' => '<div id="media-add-from-url-preview"></div>'
- //);
+ // If any providers are enabled it is assumed that some kind of embed is supported
+ if ($providers) {
+ $form['embed_code']['#title'] = t('Enter an image URL or an embed code');
+ $form['embed_code']['#description'] = t('Enter a URL or the embed code from a media provider.');
+
+ $form['providers'] = array(
+ '#theme' => 'item_list',
+ '#title' => t('Supported providers'),
+ '#items' => $providers,
+ '#attributes' => array(
+ 'class' => array('media-internet-providers'),
+ ),
+ );
+ }
$form['#validators'] = array();
if ($types) {
$form['#validators']['media_file_validate_types'] = array($types);
}
- $providers = array();
- foreach (media_internet_get_providers() as $key => $provider) {
- if (empty($provider['hidden']) || $provider['hidden'] != TRUE) {
- // @todo Convert this to show provider images in a nice format.
- $class = drupal_clean_css_identifier(drupal_strtolower($provider['title']));
- $providers[] = array(
- 'data' => check_plain($provider['title']),
- 'class' => array($class),
- );
- }
- }
- $form['providers'] = array(
- '#theme' => 'item_list',
- '#title' => t('Supported providers'),
- '#items' => $providers,
- '#attributes' => array(
- 'class' => array('media-internet-providers'),
- ),
- );
-
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
diff --git a/modules/mediafield/mediafield.info b/modules/mediafield/mediafield.info
index 37f663c..13cb532 100644
--- a/modules/mediafield/mediafield.info
+++ b/modules/mediafield/mediafield.info
@@ -4,9 +4,9 @@ package = Media
core = 7.x
dependencies[] = media
-; Information added by drupal.org packaging script on 2012-11-18
-version = "7.x-2.0-unstable7"
-core = "7.x"
+
+; Information added by drush on 2013-01-16
+version = "unknown"
project = "media"
-datestamp = "1353227523"
+datestamp = "1358387122"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment