1 |
59ae487e
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Common pages for the Media Ckeditor module.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* Callback to fetch the markup of a file with certain overrides.
|
10 |
|
|
*/
|
11 |
|
|
function media_ckeditor_rendered_file_in_wysiwyg() {
|
12 |
|
|
|
13 |
|
|
// If you would like to see how the $tag_info variable below is built, please
|
14 |
|
|
// @see media_ckeditor/js/plugins/media/library.js.
|
15 |
|
|
$tag_info = drupal_get_query_parameters();
|
16 |
|
|
|
17 |
|
|
// Introductory sanity/security check.
|
18 |
|
|
if (!is_numeric($tag_info['fid'])) {
|
19 |
|
|
throw new Exception('Invalid file id.');
|
20 |
|
|
}
|
21 |
|
|
|
22 |
|
|
// Start with the file object.
|
23 |
|
|
$file = file_load($tag_info['fid']);
|
24 |
|
|
if (!$file) {
|
25 |
|
|
throw new Exception('Could not load media object');
|
26 |
|
|
}
|
27 |
|
|
|
28 |
|
|
// Now attempt to override any specified fields.
|
29 |
|
|
$fields = array();
|
30 |
|
|
foreach ($tag_info['fields'] as $key => $values) {
|
31 |
|
|
|
32 |
|
|
// Only operate on actual fields.
|
33 |
|
|
if (strpos($key, 'field_') === 0) {
|
34 |
|
|
$parsed_field = explode('[', str_replace(']', '', $key));
|
35 |
|
|
$field_name = $parsed_field[0];
|
36 |
|
|
|
37 |
|
|
if (isset($file->{$field_name})) {
|
38 |
|
|
|
39 |
|
|
// Make sure this is a valid field.
|
40 |
|
|
$field_info = field_info_field($field_name);
|
41 |
|
|
if ($field_info) {
|
42 |
|
|
$field_language = $parsed_field[1];
|
43 |
|
|
$column = key($field_info['columns']);
|
44 |
|
|
|
45 |
|
|
// Some field values will show up here as a flat string value, so
|
46 |
|
|
// convert it into a Drupal-friendly field value array.
|
47 |
|
|
if (is_string($values)) {
|
48 |
|
|
$values = array(array($column => $values));
|
49 |
|
|
}
|
50 |
|
|
|
51 |
|
|
// The values need to be urldecoded.
|
52 |
|
|
foreach ($values as $index => &$value) {
|
53 |
|
|
if (isset($value[$column])) {
|
54 |
|
|
$value[$column] = urldecode($value[$column]);
|
55 |
|
|
}
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
// Override the field on the file entity.
|
59 |
|
|
$fields[$field_name] = array($field_language => $values);
|
60 |
|
|
}
|
61 |
|
|
}
|
62 |
|
|
}
|
63 |
|
|
}
|
64 |
|
|
|
65 |
|
|
// Make sure it is indicated that this is a wysiwyg rendering.
|
66 |
|
|
$file->override['wysiwyg'] = TRUE;
|
67 |
|
|
|
68 |
|
|
// Now simply print the file entity and exit.
|
69 |
|
|
$build = media_ckeditor_render_file_with_overrides($file, $tag_info['view_mode'], $fields);
|
70 |
|
|
print drupal_render($build);
|
71 |
|
|
drupal_page_footer();
|
72 |
|
|
} |