media_vimeo.styles.inc 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <?php
  2. /**
  3. * @file media_vimeo/includes/media_vimeo.styles.inc
  4. * Styles definitions for Media: Vimeo.
  5. */
  6. /**
  7. * Implementation of Styles module hook_styles_register().
  8. */
  9. function media_vimeo_styles_register() {
  10. return array(
  11. 'MediaVimeoStyles' => array(
  12. 'field_types' => 'file',
  13. 'name' => t('MediaVimeo'),
  14. 'description' => t('Media Vimeo styles.'),
  15. 'path' => drupal_get_path('module', 'media_vimeo') .'/includes',
  16. 'file' => 'media_vimeo.styles.inc',
  17. ),
  18. );
  19. }
  20. /**
  21. * Implements hook_styles_containers(). (Deprecated in version 2)
  22. */
  23. function media_vimeo_styles_containers() {
  24. return array(
  25. 'file' => array(
  26. 'containers' => array(
  27. 'media_vimeo' => array(
  28. 'label' => t('Vimeo Styles'),
  29. 'data' => array(
  30. 'streams' => array(
  31. 'vimeo',
  32. ),
  33. 'mimetypes' => array(
  34. 'video/vimeo',
  35. ),
  36. ),
  37. 'weight' => 0,
  38. 'filter callback' => 'media_vimeo_formatter_filter',
  39. 'themes' => array(
  40. 'field_formatter_styles' => 'media_vimeo_field_formatter_styles',
  41. 'styles' => 'media_vimeo_styles',
  42. 'preview' => 'media_vimeo_preview_style',
  43. ),
  44. 'description' => t('Vimeo Styles will display embedded Vimeo videos and thumbnails to your choosing, such as by resizing, setting colors, and autoplay. You can !manage.', array('!manage' => l(t('manage your Vimeo styles here'), 'admin/config/media/media-vimeo-styles'))),
  45. ),
  46. ),
  47. ),
  48. );
  49. }
  50. function media_vimeo_formatter_filter($variables) {
  51. if (isset($variables['object'])) {
  52. $object = isset($variables['object']->file) ? $variables['object']->file : $variables['object'];
  53. return (file_uri_scheme($object->uri) == 'vimeo') && ($object->filemime == 'video/vimeo');
  54. }
  55. }
  56. /**
  57. * Implementation of the File Styles module's hook_file_styles_filter().
  58. */
  59. function media_vimeo_file_styles_filter($object) {
  60. $file = isset($object->file) ? $object->file : $object;
  61. if ((file_uri_scheme($file->uri) == 'vimeo') && ($file->filemime == 'video/vimeo')) {
  62. return 'media_vimeo';
  63. }
  64. }
  65. /**
  66. * Implements hook_styles_styles().
  67. */
  68. function media_vimeo_styles_styles() {
  69. $styles = array(
  70. 'file' => array(
  71. 'containers' => array(
  72. 'media_vimeo' => array(
  73. 'styles' => array(
  74. 'vimeo_thumbnail' => array(
  75. 'name' => 'vimeo_thumbnail',
  76. 'effects' => array(
  77. array('label' => t('Thumbnail'), 'name' => 'thumbnail', 'data' => array('thumbnail' => 1)),
  78. array('label' => t('Resize'), 'name' => 'resize', 'data' => array('width' => 100, 'height' => 75)),
  79. ),
  80. ),
  81. 'vimeo_preview' => array(
  82. 'name' => 'vimeo_preview',
  83. 'effects' => array(
  84. array('label' => t('Autoplay'), 'name' => 'autoplay', 'data' => array('autoplay' => 0)),
  85. array('label' => t('Resize'), 'name' => 'resize', 'data' => array('width' => 220, 'height' => 165)),
  86. ),
  87. ),
  88. 'vimeo_full' => array(
  89. 'name' => 'vimeo_full',
  90. 'effects' => array(
  91. array('label' => t('Autoplay'), 'name' => 'autoplay', 'data' => array('autoplay' => 0)),
  92. array('label' => t('Resize'), 'name' => 'resize', 'data' => array('width' => 640, 'height' => 480)),
  93. array('label' => t('Full screen'), 'name' => 'fullscreen', 'data' => array('fullscreen' => 1)),
  94. ),
  95. ),
  96. ),
  97. ),
  98. ),
  99. ),
  100. );
  101. // Allow any image style to be applied to the thumbnail.
  102. foreach (image_styles() as $style_name => $image_style) {
  103. $styles['file']['containers']['media_vimeo']['styles']['vimeo_thumbnail_' . $style_name] = array(
  104. 'name' => 'vimeo_thumbnail_' . $style_name,
  105. 'image_style' => $style_name,
  106. 'effects' => array(
  107. array('label' => t('Thumbnail'), 'name' => 'thumbnail', 'data' => array('thumbnail' => 1)),
  108. ),
  109. );
  110. }
  111. return $styles;
  112. }
  113. /**
  114. * Implements hook_styles_presets().
  115. */
  116. function media_vimeo_styles_presets() {
  117. $presets = array(
  118. 'file' => array(
  119. 'square_thumbnail' => array(
  120. 'media_vimeo' => array(
  121. 'vimeo_thumbnail_square_thumbnail',
  122. ),
  123. ),
  124. 'thumbnail' => array(
  125. 'media_vimeo' => array(
  126. 'vimeo_thumbnail',
  127. ),
  128. ),
  129. 'small' => array(
  130. 'media_vimeo' => array(
  131. 'vimeo_preview',
  132. ),
  133. ),
  134. 'large' => array(
  135. 'media_vimeo' => array(
  136. 'vimeo_full',
  137. ),
  138. ),
  139. 'original' => array(
  140. 'media_vimeo' => array(
  141. 'vimeo_full',
  142. ),
  143. ),
  144. ),
  145. );
  146. return $presets;
  147. }
  148. /**
  149. * Implementation of Styles module hook_styles_default_containers().
  150. */
  151. function media_vimeo_styles_default_containers() {
  152. // We append Vimeo to the file containers.
  153. return array(
  154. 'file' => array(
  155. 'containers' => array(
  156. 'media_vimeo' => array(
  157. 'class' => 'MediaVimeoStyles',
  158. 'name' => 'media_vimeo',
  159. 'label' => t('Vimeo'),
  160. 'preview' => 'media_vimeo_preview_style',
  161. ),
  162. ),
  163. ),
  164. );
  165. }
  166. /**
  167. * Implementation of Styles module hook_styles_default_presets().
  168. */
  169. function media_vimeo_styles_default_presets() {
  170. $presets = array(
  171. 'file' => array(
  172. 'containers' => array(
  173. 'media_vimeo' => array(
  174. 'default preset' => 'unlinked_thumbnail',
  175. 'styles' => array(
  176. 'original' => array(
  177. 'default preset' => 'video',
  178. ),
  179. 'thumbnail' => array(
  180. 'default preset' => 'linked_thumbnail',
  181. ),
  182. 'square_thumbnail' => array(
  183. 'default preset' => 'linked_square_thumbnail',
  184. ),
  185. 'medium' => array(
  186. 'default preset' => 'linked_medium',
  187. ),
  188. 'large' => array(
  189. 'default preset' => 'large_video',
  190. ),
  191. ),
  192. 'presets' => array(
  193. 'video' => array(
  194. array(
  195. 'name' => 'video',
  196. 'settings' => array(),
  197. ),
  198. ),
  199. 'large_video' => array(
  200. array(
  201. 'name' => 'resize',
  202. 'settings' => array(
  203. 'width' => 640,
  204. 'height' => 390,
  205. ),
  206. ),
  207. array(
  208. 'name' => 'video',
  209. 'settings' => array(),
  210. ),
  211. ),
  212. ),
  213. ),
  214. ),
  215. ),
  216. );
  217. // Allow any image style to be applied to the thumbnail.
  218. foreach (image_styles() as $style_name => $image_style) {
  219. $presets['file']['containers']['media_vimeo']['presets']['linked_' . $style_name] = array(
  220. array(
  221. 'name' => 'linkToMedia',
  222. 'settings' => array(),
  223. ),
  224. array(
  225. 'name' => 'imageStyle',
  226. 'settings' => array(
  227. 'image_style' => $style_name,
  228. ),
  229. ),
  230. array(
  231. 'name' => 'thumbnail',
  232. 'settings' => array(),
  233. ),
  234. );
  235. $presets['file']['containers']['media_vimeo']['presets']['unlinked_' . $style_name] = $presets['file']['containers']['media_vimeo']['presets']['linked_' . $style_name];
  236. array_shift($presets['file']['containers']['media_vimeo']['presets']['unlinked_' . $style_name]);
  237. foreach ($image_style['effects'] as $effect) {
  238. if (in_array($effect['name'], array('image_scale', 'image_scale_and_crop', 'image_resize', 'image_crop'))) {
  239. $presets['file']['containers']['media_vimeo']['presets']['video_' . $style_name] = array(
  240. array(
  241. 'name' => 'resize',
  242. 'settings' => $effect['data'],
  243. ),
  244. array(
  245. 'name' => 'video',
  246. 'settings' => array(),
  247. ),
  248. );
  249. }
  250. }
  251. }
  252. return $presets;
  253. }