media.theme.inc 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <?php
  2. /**
  3. * @file
  4. * Media Theming
  5. *
  6. * Theming functions for the Media module.
  7. */
  8. /**
  9. * Display the media file browser.
  10. * @TODO this is depreciated I think
  11. * @param array $element
  12. * The form element.
  13. * @return string
  14. */
  15. function theme_media_file_browser($element) {
  16. // Add the CSS for our display.
  17. $output = '<div class="media browser">' . $element . '</div>';
  18. return $output;
  19. }
  20. /**
  21. * Display a media file list.
  22. * @TODO this is depreciated I think
  23. * @param array $element
  24. * The form element.
  25. * @return string
  26. */
  27. function theme_media_file_list($element) {
  28. // Add the CSS for our display.
  29. return '<div class="media-file-list">' . theme('form_element', $element, $element['#children']) . '</div>';
  30. }
  31. /**
  32. * Display a browser pane.
  33. * @TODO this is depreciated I think
  34. *
  35. * @param array $form
  36. * The form element.
  37. * @return string
  38. */
  39. function theme_media_browser_pane($form) {
  40. return;
  41. $output = array();
  42. // render the drawers
  43. $output[] = '<div' . drupal_attributes($form['#attributes']) . '>';
  44. // render the drawer list
  45. $output[] = ' <div class="browser drawers">';
  46. $output[] = drupal_render_form(null, $form['drawers']);
  47. $output[] = ' </div>';
  48. // render the drawer displays
  49. $output[] = drupal_render_form(null, $form);
  50. $output[] = '</div>';
  51. return implode("\n", $output);
  52. }
  53. /**
  54. * Default theming function for creating the browser frame.
  55. * Assumes an array of file objects as $files and an
  56. * array of $parameters
  57. * @param $variables
  58. * array of variables
  59. * @return unknown_type
  60. */
  61. function theme_media_browser_content_frame($variables) {
  62. // Pull out all the variables into a usable form
  63. extract($variables);
  64. // Did we get any files back?
  65. if (! count($files)) {
  66. // @TODO display no files found
  67. }
  68. $html = array();
  69. // On the first invocation, load javascript and build the browser frame
  70. if ($invoke) {
  71. }
  72. // Render the results limiter
  73. $html[] = theme('media_browser_control_result_limit', array('parameters' => $parameters));
  74. // Render the actual content
  75. $form = drupal_get_form('media_file_listing_form', $files, $parameters);
  76. $html[] = drupal_render($form);
  77. // Make sure to close the wrapping div
  78. if ($invoke) {
  79. $html[] = '</div>';
  80. }
  81. return implode("\n", $html);
  82. }
  83. /**
  84. * Display a item list of files as thumbnails. Implements
  85. * the admin thumbnail theme for now- serves as a wrapper
  86. *
  87. * @param $files
  88. * An array of file objects to display.
  89. * @return
  90. */
  91. function theme_media_browser_thumbnails($variables) {
  92. $files = $variables['files'];
  93. $style_name = $variables['style_name'];
  94. $thumbnails = array();
  95. foreach ($files as $file) {
  96. $thumbnails[] = theme('media_admin_thumbnail', array('file' => $file, 'style_name' => $style_name));
  97. }
  98. return theme('item_list', array('items' => $thumbnails, 'attributes' => array('class' => 'media_content_navigator results')));
  99. }
  100. /**
  101. * Theme a thumbnail.
  102. * @param $variables
  103. * array items being passed in
  104. */
  105. function theme_media_admin_thumbnail($variables) {
  106. $path = drupal_get_path('module', 'media');
  107. $file = $variables['file'];
  108. $style_name = $variables['style_name'];
  109. if (isset($file)) {
  110. $file_url = file_create_url($file->uri);
  111. }
  112. else {
  113. return '';
  114. }
  115. $output = '';
  116. if (module_exists('styles')) {
  117. $thumbnail = theme('styles',
  118. array(
  119. 'field_type' => 'file',
  120. 'style_name' => $style_name,
  121. 'uri' => $file->uri,
  122. 'description' => t('Thumbnail for !filename.', array('!filename' => $file->filename)),
  123. 'object' => $variables['file'],
  124. ));
  125. }
  126. else {
  127. // Display a thumbnail for images.
  128. if (strstr($file->filemime, 'image')) {
  129. $thumbnail = theme('image_style',
  130. array(
  131. 'style_name' => 'thumbnail',
  132. 'path' => $file->uri,
  133. 'alt' => t('Thumbnail for !filename.', array('!filename' => $file->filename)),
  134. )
  135. );
  136. }
  137. // Display the 'unknown' icon for other file types.
  138. else {
  139. $thumbnail = theme('image',
  140. array(
  141. 'path' => $path . '/images/file-unknown.png',
  142. 'alt' => t('Thumbnail for !filename.', array('!filename' => $file->filename)),
  143. 'attributes' => array('class' => 'file-unknown'),
  144. ));
  145. }
  146. }
  147. $output .= l($thumbnail,
  148. $file_url,
  149. array(
  150. 'html' => TRUE,
  151. 'attributes' => array('class' => 'media-thumbnail'),
  152. ));
  153. return $output;
  154. }
  155. /**
  156. * Theme operations for a thumbnail.
  157. */
  158. function theme_media_admin_thumbnail_operations($variables) {
  159. $destination = drupal_get_destination();
  160. $file = $variables['file'];
  161. $output = l(t('edit'), 'media/' . $file->fid . '/edit', array('query' => $destination));
  162. return $output;
  163. }
  164. /**
  165. * Add messages to the page.
  166. */
  167. function template_preprocess_media_dialog_page(&$variables) {
  168. $variables['messages'] = theme('status_messages');
  169. }
  170. /* ******************************************** */
  171. /* Content navigation controls */
  172. /* ******************************************** */
  173. /**
  174. * Theme function to display the results limiting- 10, 30, 50 results
  175. * per page.
  176. *
  177. * @param $variables
  178. * array parameters
  179. * @return unknown
  180. */
  181. function theme_media_browser_control_result_limit($variables) {
  182. // Pull out all the variables into a usable form
  183. extract($variables);
  184. if (!isset($limits)) {
  185. $limits = array(10, 30, 50);
  186. }
  187. // @NOTE these do not need to be aware of the current
  188. // page because clicking them will reset the
  189. // display to 1 -> $limit
  190. $parameters['page'] = 0;
  191. // save the active limit
  192. $current_limit = $parameters['limit'];
  193. $per_display = array();
  194. foreach ($limits as $limit) {
  195. if ($limit == $current_limit) {
  196. $class = 'active';
  197. }
  198. else {
  199. $class = '';
  200. }
  201. // set the value of this limit parameter to this limit value
  202. $parameters['limit'] = $limit;
  203. $per_display[] = l($limit, $limit, array('query' => $parameters, 'attributes' => array('class' => $class)));
  204. }
  205. return theme('item_list', array('items' => $per_display, 'attributes' => array('class' => 'result_limit')));
  206. }
  207. /**
  208. * Stolen from file.module theme_file_link
  209. *
  210. * @param $variables
  211. * An associative array containing:
  212. * - file: A file object to which the link will be created.
  213. */
  214. function theme_media_link($variables) {
  215. $file = $variables['file'];
  216. $url = 'media/' . $file->fid;
  217. $icon = theme('file_icon', array('file' => $file));
  218. // Set options as per anchor format described at
  219. // http://microformats.org/wiki/file-format-examples
  220. $options = array(
  221. 'attributes' => array(
  222. 'type' => $file->filemime . '; length=' . $file->filesize,
  223. ),
  224. );
  225. // Use the description as the link text if available.
  226. if (empty($file->description)) {
  227. $link_text = check_plain($file->filename);
  228. }
  229. else {
  230. $link_text = check_plain($file->description);
  231. $options['attributes']['title'] = check_plain($file->filename);
  232. }
  233. return '<span class="file">' . $icon . ' ' . l($link_text, $url, $options) . '</span>';
  234. }
  235. /**
  236. * Adds a wrapper around a preview of a media file.
  237. * @param unknown_type $element
  238. * @return unknown_type
  239. */
  240. function theme_media_thumbnail($variables) {
  241. $label = '';
  242. $element = $variables['element'];
  243. $destination = drupal_get_destination();
  244. // Wrappers to go around the thumbnail
  245. $prefix = '<div class="media-item"><div class="media-thumbnail">';
  246. $suffix = '</div></div>';
  247. // Arguments for the thumbnail link
  248. $thumb = $element['#children'];
  249. $target = 'media/' . $element['#file']->fid . '/edit';
  250. $options = array('query' => $destination, 'html' => TRUE, 'attributes' => array('title' => t('Click to edit details')));
  251. // Element should be a field renderable array... This is a little wonky - admitted.
  252. if (!empty($element['#show_names']) && $element['#name']) {
  253. $label = '<div class="label-wrapper"><label class="media-filename">' . $element['#name'] . '</label></div>';
  254. }
  255. // How can I attach CSS here?
  256. //$element['#attached']['css'][] = drupal_get_path('module', 'media') . '/css/media.css';
  257. drupal_add_css(drupal_get_path('module', 'media') . '/css/media.css');
  258. $output = $prefix;
  259. if (!empty($element['#add_link'])) {
  260. $output .= l($thumb, $target, $options);
  261. }
  262. else {
  263. $output .= $thumb;
  264. }
  265. $output .= $label . $suffix;
  266. return $output;
  267. }
  268. function template_preprocess_media_thumbnail(&$variables) {
  269. // Set the name for the thumbnail to be the filename. This is done here so
  270. // that other modules can hijack the name displayed if it should not be the
  271. // filename.
  272. $variables['element']['#name'] = isset($variables['element']['#file']->filename) ? check_plain($variables['element']['#file']->filename) : NULL;
  273. }
  274. /**
  275. * Field formatter for displaying a file as a large icon.
  276. */
  277. function theme_media_formatter_large_icon($variables) {
  278. $file = $variables['file'];
  279. $icon_dir = media_variable_get('icon_base_directory') . '/' . media_variable_get('icon_set');
  280. $icon = file_icon_path($file, $icon_dir);
  281. $variables['path'] = $icon;
  282. // theme_image() requires the 'alt' attribute passed as its own variable.
  283. // @see http://drupal.org/node/999338
  284. if (!isset($variables['alt']) && isset($variables['attributes']['alt'])) {
  285. $variables['alt'] = $variables['attributes']['alt'];
  286. }
  287. return theme('image', $variables);
  288. }