emvideo.module

Tracking 6.x-3.x branch
  1. drupal
    1. 6 contributions/emfield/contrib/emvideo/emvideo.module

Embedded Video module is a handler for 3rd party video files.

Functions & methods

NameDescription
emvideo_content_is_emptyImplementation of hook_content_is_empty().
emvideo_convert_to_seconds
emvideo_embed_form
emvideo_emfield_infoImplementation of hook_emfield_info().
emvideo_emfield_rssProviders may supply an enclosure for rss feeds. This expects something in a file format, so would be an object in the format of $file->filepath, $file->filesize, and $file->filemime. Calls the providers hook EMVIDEO_PROVIDER_RSS($item, $teaser).
emvideo_emfield_settingsImplementation of hook_emfield_settings().
emvideo_fieldImplementation of hook_field().
emvideo_field_formatterImplementation of hook_field_formatter().
emvideo_field_formatter_infoImplementation of hook_field_formatter_info()
emvideo_field_infoImplementation of hook_field_info().
emvideo_field_settingsImplementation of hook_field_settings().
emvideo_handler_arg_provider
emvideo_menuImplementation of hook_menu().
emvideo_modalPage callback for emvideo/thickbox/shadowbox. This will display our video in a modal window defined by the corresponding modal module. As it's a direct callback, it displays no HTML other than the video.
emvideo_seconds_to_time
emvideo_themeImplementation of hook_theme().
emvideo_views_apiImplementation of hook_views_api().
emvideo_widgetImplementation of hook_widget()
emvideo_widget_infoImplementation of hook_widget_info
emvideo_widget_settings

Constants

NameDescription
EMVIDEO_DEFAULT_PREVIEW_HEIGHT
EMVIDEO_DEFAULT_PREVIEW_WIDTH
EMVIDEO_DEFAULT_THUMBNAIL_HEIGHT
EMVIDEO_DEFAULT_THUMBNAIL_WIDTH
EMVIDEO_DEFAULT_VIDEO_HEIGHT
EMVIDEO_DEFAULT_VIDEO_WIDTHDefine our constants and default variables.

File

View source
  1. <?php
  2. /**
  3. * @file
  4. * Embedded Video module is a handler for 3rd party video files.
  5. */
  6. /**
  7. * Define our constants and default variables.
  8. */
  9. define('EMVIDEO_DEFAULT_VIDEO_WIDTH', 425);
  10. define('EMVIDEO_DEFAULT_VIDEO_HEIGHT', 350);
  11. define('EMVIDEO_DEFAULT_PREVIEW_WIDTH', 425);
  12. define('EMVIDEO_DEFAULT_PREVIEW_HEIGHT', 350);
  13. define('EMVIDEO_DEFAULT_THUMBNAIL_WIDTH', 120);
  14. define('EMVIDEO_DEFAULT_THUMBNAIL_HEIGHT', 90);
  15. /**
  16. * Implementation of hook_menu().
  17. */
  18. function emvideo_menu() {
  19. $items = emfield_provider_menus('emvideo');
  20. $items['emvideo/modal/%node'] = array(
  21. 'page callback' => 'emvideo_modal',
  22. 'page arguments' => array(2),
  23. 'access callback' => 'node_access',
  24. 'access arguments' => array('view', 2),
  25. 'type' => MENU_CALLBACK,
  26. );
  27. return $items;
  28. }
  29. /**
  30. * Implementation of hook_emfield_info().
  31. */
  32. function emvideo_emfield_info() {
  33. $name = t('Embedded Video Field');
  34. return array(
  35. '#name' => $name,
  36. '#settings_title' => t('Videos'),
  37. '#settings_description' => t('The following settings configure content with any fields controlled by @name.', array('@name' => $name)),
  38. );
  39. }
  40. /**
  41. * Implementation of hook_theme().
  42. */
  43. function emvideo_theme() {
  44. $themes = array(
  45. 'emvideo_video_embed' => array(
  46. 'arguments' => array('field' => NULL, 'item' => NULL, 'formatter' => NULL, 'node' => NULL, 'options' => array()),
  47. 'file' => 'emvideo.theme.inc',
  48. ),
  49. 'emvideo_video_thumbnail' => array(
  50. 'arguments' => array('field' => NULL, 'item' => NULL, 'formatter' => NULL, 'node' => NULL, 'no_link' => FALSE, 'options' => array()),
  51. 'file' => 'emvideo.theme.inc',
  52. ),
  53. 'emvideo_video_thumbnail_no_link' => array(
  54. 'arguments' => array('field' => NULL, 'item' => NULL, 'formatter' => NULL, 'node' => NULL, 'options' => array()),
  55. 'file' => 'emvideo.theme.inc',
  56. ),
  57. 'emvideo_video_thumbnail_provider_link' => array(
  58. 'arguments' => array('field' => NULL, 'item' => NULL, 'formatter' => NULL, 'node' => NULL, 'options' => array()),
  59. 'file' => 'emvideo.theme.inc',
  60. ),
  61. 'emvideo_video_thumbnail_path' => array(
  62. 'arguments' => array('field' => NULL, 'item' => NULL, 'formatter' => NULL, 'node' => NULL, 'no_link' => FALSE, 'options' => array()),
  63. 'file' => 'emvideo.theme.inc',
  64. ),
  65. 'emvideo_video_thumbnail_url' => array(
  66. 'arguments' => array('field' => NULL, 'item' => NULL, 'formatter' => NULL, 'node' => NULL, 'no_link' => FALSE, 'options' => array()),
  67. 'file' => 'emvideo.theme.inc',
  68. ),
  69. 'emvideo_video_video' => array(
  70. 'arguments' => array('field' => NULL, 'item' => NULL, 'formatter' => NULL, 'node' => NULL, 'options' => array()),
  71. 'file' => 'emvideo.theme.inc',
  72. ),
  73. 'emvideo_default' => array(
  74. 'arguments' => array('field' => NULL, 'item' => NULL, 'formatter' => NULL, 'node' => NULL, 'options' => array()),
  75. 'file' => 'emvideo.theme.inc',
  76. ),
  77. 'emvideo_video_preview' => array(
  78. 'arguments' => array('field' => NULL, 'item' => NULL, 'formatter' => NULL, 'node' => NULL, 'options' => array()),
  79. 'file' => 'emvideo.theme.inc',
  80. ),
  81. 'emvideo_video_replace' => array(
  82. 'arguments' => array('field' => NULL, 'item' => NULL, 'formatter' => NULL, 'node' => NULL, 'options' => array()),
  83. 'file' => 'emvideo.theme.inc',
  84. ),
  85. 'emvideo_video_replace_preview' => array(
  86. 'arguments' => array('field' => NULL, 'item' => NULL, 'formatter' => NULL, 'node' => NULL, 'options' => array()),
  87. 'file' => 'emvideo.theme.inc',
  88. ),
  89. 'emvideo_video_link' => array(
  90. 'arguments' => array('field' => NULL, 'item' => NULL, 'formatter' => NULL, 'node' => NULL, 'options' => array()),
  91. 'file' => 'emvideo.theme.inc',
  92. ),
  93. 'emvideo_video_url' => array(
  94. 'arguments' => array('field' => NULL, 'item' => NULL, 'formatter' => NULL, 'node' => NULL, 'options' => array()),
  95. 'file' => 'emvideo.theme.inc',
  96. ),
  97. 'emvideo_video_duration' => array(
  98. 'arguments' => array('field' => NULL, 'item' => NULL, 'formatter' => NULL, 'node' => NULL, 'options' => array()),
  99. 'file' => 'emvideo.theme.inc',
  100. ),
  101. 'emvideo_modal_generic' => array(
  102. 'arguments' => array('field' => NULL, 'item' => NULL, 'formatter' => NULL, 'node' => NULL, 'options' => array()),
  103. 'file' => 'emvideo.theme.inc'
  104. ),
  105. 'emvideo_thickbox' => array(
  106. 'arguments' => array('field' => NULL, 'item' => NULL, 'formatter' => NULL, 'node' => NULL, 'options' => array()),
  107. 'file' => 'emvideo.theme.inc'
  108. ),
  109. 'emvideo_lightbox2' => array(
  110. 'arguments' => array('field' => NULL, 'item' => NULL, 'formatter' => NULL, 'node' => NULL, 'options' => array()),
  111. 'file' => 'emvideo.theme.inc'
  112. ),
  113. 'emvideo_shadowbox' => array(
  114. 'arguments' => array('field' => NULL, 'item' => NULL, 'formatter' => NULL, 'node' => NULL, 'options' => array()),
  115. 'file' => 'emvideo.theme.inc'
  116. ),
  117. 'emvideo_formatter_video_video' => array(
  118. 'arguments' => array('element' => NULL),
  119. 'file' => 'emvideo.theme.inc'
  120. ),
  121. 'emvideo_formatter_video_thumbnail' => array(
  122. 'arguments' => array('element' => NULL),
  123. 'file' => 'emvideo.theme.inc'
  124. ),
  125. 'emvideo_formatter_video_thumbnail_no_link' => array(
  126. 'arguments' => array('element' => NULL),
  127. 'file' => 'emvideo.theme.inc'
  128. ),
  129. 'emvideo_formatter_video_thumbnail_provider_link' => array(
  130. 'arguments' => array('element' => NULL),
  131. 'file' => 'emvideo.theme.inc'
  132. ),
  133. 'emvideo_formatter_video_thumbnail_path' => array(
  134. 'arguments' => array('element' => NULL),
  135. 'file' => 'emvideo.theme.inc'
  136. ),
  137. 'emvideo_formatter_video_thumbnail_url' => array(
  138. 'arguments' => array('element' => NULL),
  139. 'file' => 'emvideo.theme.inc'
  140. ),
  141. 'emvideo_formatter_video_link' => array(
  142. 'arguments' => array('element' => NULL),
  143. 'file' => 'emvideo.theme.inc'
  144. ),
  145. 'emvideo_formatter_video_url' => array(
  146. 'arguments' => array('element' => NULL),
  147. 'file' => 'emvideo.theme.inc'
  148. ),
  149. 'emvideo_formatter_video_duration' => array(
  150. 'arguments' => array('element' => NULL),
  151. 'file' => 'emvideo.theme.inc'
  152. ),
  153. 'emvideo_formatter_video_embed' => array(
  154. 'arguments' => array('element' => NULL),
  155. 'file' => 'emvideo.theme.inc'
  156. ),
  157. 'emvideo_formatter_video_preview' => array(
  158. 'arguments' => array('element' => NULL),
  159. 'file' => 'emvideo.theme.inc'
  160. ),
  161. 'emvideo_formatter_default' => array(
  162. 'arguments' => array('element' => NULL),
  163. 'file' => 'emvideo.theme.inc'
  164. ),
  165. 'emvideo_formatter_thickbox' => array(
  166. 'arguments' => array('element' => NULL),
  167. 'file' => 'emvideo.theme.inc'
  168. ),
  169. 'emvideo_formatter_lightbox2' => array(
  170. 'arguments' => array('element' => NULL),
  171. 'file' => 'emvideo.theme.inc'
  172. ),
  173. 'emvideo_formatter_shadowbox' => array(
  174. 'arguments' => array('element' => NULL),
  175. 'file' => 'emvideo.theme.inc'
  176. ),
  177. 'emvideo_formatter_video_replace' => array(
  178. 'arguments' => array('element' => NULL),
  179. 'file' => 'emvideo.theme.inc'
  180. ),
  181. 'emvideo_formatter_video_replace_preview' => array(
  182. 'arguments' => array('element' => NULL),
  183. 'file' => 'emvideo.theme.inc'
  184. ),
  185. 'emvideo_modal_iframe' => array(
  186. 'arguments' => array('content' => ''),
  187. 'file' => 'emvideo.theme.inc',
  188. 'template' => 'emvideo_modal_iframe',
  189. ),
  190. 'emvideo_handler_field_duration' => array(
  191. 'arguments' => array('item' => NULL, 'field' => NULL, 'node' => NULL, 'values' => NULL, 'format' => NULL),
  192. ),
  193. );
  194. $themes += emfield_provider_themes('emvideo');
  195. return $themes;
  196. }
  197. /**
  198. * Implementation of hook_emfield_settings().
  199. *
  200. * This would be to add any extra settings (besides providers) to the emfield
  201. * settings configuration page.
  202. */
  203. function emvideo_emfield_settings() {
  204. $form = array();
  205. return $form;
  206. }
  207. /**
  208. * Implementation of hook_field_info().
  209. */
  210. function emvideo_field_info() {
  211. $fields = array(
  212. 'emvideo' => array(
  213. 'label' => t('Embedded Video'),
  214. 'description' => t('Automatically parse and display a third party video from its URL or embed code.'),
  215. 'callbacks' => array(
  216. 'tables' => CONTENT_CALLBACK_DEFAULT,
  217. 'arguments' => CONTENT_CALLBACK_DEFAULT,
  218. ),
  219. ),
  220. );
  221. return $fields;
  222. }
  223. /**
  224. * Implementation of hook_field_settings().
  225. */
  226. function emvideo_field_settings($op, $field) {
  227. switch ($op) {
  228. case 'views data':
  229. $data = emfield_emfield_field_settings($op, $field);
  230. $table_alias = content_views_tablename($field);
  231. $field_duration = $field['field_name'] .'_duration';
  232. $data[$table_alias][$field_duration] = $data[$table_alias][$field['field_name'] .'_embed'];
  233. $data[$table_alias][$field_duration]['title'] .= t(' - Duration');
  234. $data[$table_alias][$field_duration]['field']['title'] = $data[$table_alias][$field_duration]['title'];
  235. $data[$table_alias][$field_duration]['title short'] = t('Duration');
  236. $data[$table_alias][$field_duration]['field']['title short'] = $data[$table_alias][$field_duration]['title short'];
  237. $data[$table_alias][$field_duration]['field']['field'] = $field_duration;
  238. $data[$table_alias][$field_duration]['field']['handler'] = 'emvideo_handler_field_duration';
  239. $data[$table_alias][$field_duration]['argument']['field'] = $field_duration;
  240. $data[$table_alias][$field_duration]['argument']['handler'] = 'emvideo_handler_argument_duration';
  241. $data[$table_alias][$field_duration]['filter']['field'] = $field_duration;
  242. $data[$table_alias][$field_duration]['filter']['handler'] = 'content_handler_filter_numeric';
  243. $data[$table_alias][$field_duration]['sort']['field'] = $field_duration;
  244. return $data;
  245. case 'database columns':
  246. $columns = emfield_emfield_field_settings($op, $field);
  247. // Store duration in its own column for views.
  248. $columns = array_merge(
  249. $columns,
  250. array('duration' =>
  251. array(
  252. 'description' => t('Store the duration of a video in seconds.'),
  253. 'type' => 'int',
  254. 'unsigned' => TRUE,
  255. 'not null' => TRUE,
  256. 'default' => 0),
  257. )
  258. );
  259. return $columns;
  260. default:
  261. return emfield_emfield_field_settings($op, $field);
  262. }
  263. }
  264. /**
  265. * Implementation of hook_content_is_empty().
  266. */
  267. function emvideo_content_is_empty($item, $field) {
  268. return emfield_emfield_content_is_empty($item, $field);
  269. }
  270. /**
  271. * Implementation of hook_field().
  272. */
  273. function emvideo_field($op, &$node, $field, &$items, $teaser, $page) {
  274. $ret = emfield_emfield_field($op, $node, $field, $items, $teaser, $page, 'emvideo');
  275. if ($op == 'presave') {
  276. foreach ($items as $delta => $item) {
  277. $duration = emfield_include_invoke('emvideo', $item['provider'], 'duration', $item);
  278. $items[$delta]['duration'] = $duration ? $duration : 0;
  279. }
  280. }
  281. return $ret;
  282. }
  283. /**
  284. * Implementation of hook_field_formatter_info()
  285. */
  286. function emvideo_field_formatter_info() {
  287. $types = array('emvideo');
  288. $formats = array(
  289. 'default' => array(
  290. 'label' => t('Default'),
  291. 'field types' => $types,
  292. ),
  293. 'video_video' => array(
  294. 'label' => t('Full Size Video'),
  295. 'field types' => $types,
  296. ),
  297. 'video_preview' => array(
  298. 'label' => t('Preview Video'),
  299. 'field types' => $types,
  300. ),
  301. 'video_thumbnail_no_link' => array(
  302. 'label' => t('Image Thumbnail'),
  303. 'field types' => $types,
  304. ),
  305. 'video_thumbnail' => array(
  306. 'label' => t('Image Thumbnail (linked to node)'),
  307. 'field types' => $types,
  308. ),
  309. 'video_thumbnail_provider_link' => array(
  310. 'label' => t('Image Thumbnail (linked to original video)'),
  311. 'field types' => $types,
  312. ),
  313. 'video_thumbnail_path' => array(
  314. 'label' => t('Image Thumbnail (path to thumbnail)'),
  315. 'field types' => $types,
  316. ),
  317. 'video_thumbnail_url' => array(
  318. 'label' => t('Image Thumbnail (absolute url to thumbnail)'),
  319. 'field types' => $types,
  320. ),
  321. 'video_link' => array(
  322. 'label' => t('Link to original video'),
  323. 'field types' => $types,
  324. ),
  325. 'video_url' => array(
  326. 'label' => t('URL to original video'),
  327. 'field types' => $types,
  328. ),
  329. 'video_duration' => array(
  330. 'label' => t('Video duration'),
  331. 'field types' => $types,
  332. ),
  333. 'video_embed' => array(
  334. 'label' => t('Embed Code'),
  335. 'field types' => $types,
  336. ),
  337. 'video_replace' => array(
  338. 'label' => t('Thumbnail -> Full Size Video inline replacement'),
  339. 'field types' => $types,
  340. ),
  341. 'video_replace_preview' => array(
  342. 'label' => t('Thumbnail -> Preview Size Video inline replacement'),
  343. 'field types' => $types,
  344. ),
  345. );
  346. // Add thickbox formatter if thickbox module exists.
  347. if (module_exists('thickbox')) {
  348. $formats['thickbox'] = array(
  349. 'label' => t('Thickbox: Image Thumbnail -> Full Size Video'),
  350. 'field types' => $types,
  351. );
  352. }
  353. if (module_exists('lightbox2')) {
  354. $formats['lightbox2'] = array(
  355. 'label' => t('Lightbox2: Image Thumbnail -> Full Size Video'),
  356. 'field types' => $types,
  357. );
  358. }
  359. if (module_exists('shadowbox')) {
  360. $formats['shadowbox'] = array(
  361. 'label' => t('Shadowbox: Image Thumbnail -> Full Size Video'),
  362. 'field types' => $types,
  363. );
  364. }
  365. return $formats;
  366. }
  367. /**
  368. * Implementation of hook_field_formatter().
  369. */
  370. function emvideo_field_formatter($field, $item, $formatter, $node) {
  371. return emfield_emfield_field_formatter($field, $item, $formatter, $node, 'emvideo');
  372. }
  373. /** Widgets **/
  374. /**
  375. * Implementation of hook_widget_info
  376. */
  377. function emvideo_widget_info() {
  378. return array(
  379. 'emvideo_textfields' => array(
  380. 'label' => '3rd Party Video',
  381. 'field types' => array('emvideo'),
  382. 'multiple values' => CONTENT_HANDLE_CORE,
  383. 'callbacks' => array(
  384. 'default value' => CONTENT_CALLBACK_DEFAULT,
  385. ),
  386. ),
  387. );
  388. }
  389. function emvideo_widget_settings($op, $widget) {
  390. switch ($op) {
  391. case 'form':
  392. if ($widget['type'] == 'emvideo_textfields') {
  393. $form = (array)emfield_emfield_widget_settings('form', $widget, 'emvideo');
  394. $width = variable_get('emvideo_default_video_width', EMVIDEO_DEFAULT_VIDEO_WIDTH);
  395. $height = variable_get('emvideo_default_video_height', EMVIDEO_DEFAULT_VIDEO_HEIGHT);
  396. $form['video'] = array(
  397. '#type' => 'fieldset',
  398. '#title' => t('Video Display Settings'),
  399. '#description' => t('These settings control how this video is displayed in its full size, which defaults to @widthx@height.', array('@width' => $width, '@height' => $height)),
  400. '#collapsible' => TRUE,
  401. '#collapsed' => FALSE,
  402. );
  403. $form['video']['video_width'] = array(
  404. '#type' => 'textfield',
  405. '#title' => t('Video display width'),
  406. '#default_value' => empty($widget['video_width']) ? $width : $widget['video_width'],
  407. '#required' => TRUE,
  408. '#description' => t('The width of the video. It defaults to @width.', array('@width' => $width)),
  409. );
  410. $form['video']['video_height'] = array(
  411. '#type' => 'textfield',
  412. '#title' => t('Video display height'),
  413. '#default_value' => empty($widget['video_height']) ? $height : $widget['video_height'],
  414. '#required' => TRUE,
  415. '#description' => t('The height of the video. It defaults to @height.', array('@height' => $height)),
  416. );
  417. $form['video']['video_autoplay'] = array(
  418. '#type' => 'checkbox',
  419. '#title' => t('Autoplay'),
  420. '#default_value' => empty($widget['video_autoplay']) ? '' : $widget['video_autoplay'],
  421. '#description' => t('If supported by the provider, checking this box will cause the video to automatically begin after the video loads when in its full size.'),
  422. );
  423. $width = variable_get('emvideo_default_preview_width', EMVIDEO_DEFAULT_PREVIEW_WIDTH);
  424. $height = variable_get('emvideo_default_preview_height', EMVIDEO_DEFAULT_PREVIEW_HEIGHT);
  425. $form['preview'] = array(
  426. '#type' => 'fieldset',
  427. '#title' => t('Video Preview Settings'),
  428. '#description' => t('These settings control how this video is displayed in its preview size, which defaults to @widthx@height.', array('@width' => $width, '@height' => $height)),
  429. '#collapsible' => TRUE,
  430. '#collapsed' => FALSE,
  431. );
  432. $form['preview']['preview_width'] = array(
  433. '#type' => 'textfield',
  434. '#title' => t('Video preview width'),
  435. '#default_value' => empty($widget['preview_width']) ? $width : $widget['preview_width'],
  436. '#required' => TRUE,
  437. '#description' => t('The width of the preview video. It defaults to @width.', array('@width' => $width)),
  438. );
  439. $form['preview']['preview_height'] = array(
  440. '#type' => 'textfield',
  441. '#title' => t('Video preview height'),
  442. '#default_value' => empty($widget['preview_height']) ? $height : $widget['preview_height'],
  443. '#required' => TRUE,
  444. '#description' => t('The height of the preview video. It defaults to @height.', array('@height' => $height)),
  445. );
  446. $form['preview']['preview_autoplay'] = array(
  447. '#type' => 'checkbox',
  448. '#title' => t('Autoplay'),
  449. '#default_value' => empty($widget['preview_autoplay']) ? '' : $widget['preview_autoplay'],
  450. '#description' => t('If supported by the provider, checking this box will cause the video to automatically begin after the video loads when in its preview size.'),
  451. );
  452. $width = variable_get('emvideo_default_thumbnail_width', EMVIDEO_DEFAULT_THUMBNAIL_WIDTH);
  453. $height = variable_get('emvideo_default_thumbnail_height', EMVIDEO_DEFAULT_THUMBNAIL_HEIGHT);
  454. $form['tn'] = array(
  455. '#type' => 'fieldset',
  456. '#title' => t('Thumbnail'),
  457. '#description' => t('When displayed as a thumbnail, these settings control the image returned. Note that not all 3rd party video content providers offer thumbnails, and others may require an API key or other requirements. More information from the <a href="@settings">settings page</a>. The default size for thumbnails is @widthx@height.', array('@settings' => url('admin/content/emfield'), '@width' => $width, '@height' => $height)),
  458. '#collapsible' => TRUE,
  459. '#collapsed' => FALSE,
  460. );
  461. $form['tn']['thumbnail_width'] = array(
  462. '#type' => 'textfield',
  463. '#title' => t('Thumbnail width'),
  464. '#default_value' => empty($widget['thumbnail_width']) ? $width : $widget['thumbnail_width'],
  465. '#required' => TRUE,
  466. '#description' => t('The width of the thumbnail. It defaults to @width.', array('@width' => $width)),
  467. );
  468. $form['tn']['thumbnail_height'] = array(
  469. '#type' => 'textfield',
  470. '#title' => t('Thumbnail height'),
  471. '#default_value' => empty($widget['thumbnail_height']) ? $height : $widget['thumbnail_height'],
  472. '#required' => TRUE,
  473. '#description' => t('The height of the thumbnail. It defaults to @height.', array('@height' => $height)),
  474. );
  475. // Construct the description, hinting of Embedded Media Thumbnail if it
  476. // is not enabled.
  477. $default_path = variable_get('emvideo_default_thumbnail_path', '');
  478. $description = t("Path to a local default thumbnail image for cases when a thumbnail can't be found. For example, you might have a default thumbnail at %files.", array('%files' => 'files/thumbnail.png'));
  479. if (!module_exists('emthumb')) {
  480. $description .= ' '. t('You may be interested in activating the Embedded Media Thumbnails module as well, which will allow you to specify custom thumbnails on a per-node basis.');
  481. }
  482. $form['tn']['thumbnail_default_path'] = array(
  483. '#type' => 'textfield',
  484. '#title' => t('Default thumbnail path'),
  485. '#default_value' => empty($widget['thumbnail_default_path']) ? $default_path : $widget['thumbnail_default_path'],
  486. '#description' => $description,
  487. );
  488. $form['tn']['thumbnail_link_title'] = array(
  489. '#type' => 'textfield',
  490. '#title' => t('Thumbnail title'),
  491. '#default_value' => isset($widget['thumbnail_link_title']) ? $widget['thumbnail_link_title'] : variable_get('emvideo_default_thumbnail_link_title', t('See video')),
  492. '#description' => t("The title/alt to display when hovering over a thumbnail, or if an image is broken."),
  493. );
  494. if (module_exists('token')) {
  495. $form['tn']['thumbnail_link_title']['#suffix'] = theme('token_help', 'global');
  496. }
  497. }
  498. return $form;
  499. case 'validate':
  500. if ($widget['type'] == 'emvideo_textfields') {
  501. if (!is_numeric($widget['video_width']) || intval($widget['video_width']) != $widget['video_width'] || $widget['video_width'] < 1) {
  502. form_set_error('video_width', t('"Video width" must be a positive integer.'));
  503. }
  504. if (!is_numeric($widget['video_height']) || intval($widget['video_height']) != $widget['video_height'] || $widget['video_height'] < 1) {
  505. form_set_error('video_height', t('"Video height" must be a positive integer.'));
  506. }
  507. if (!is_numeric($widget['preview_width']) || intval($widget['preview_width']) != $widget['preview_width'] || $widget['preview_width'] < 1) {
  508. form_set_error('preview_width', t('"Preview width" must be a positive integer.'));
  509. }
  510. if (!is_numeric($widget['preview_height']) || intval($widget['preview_height']) != $widget['preview_height'] || $widget['preview_height'] < 1) {
  511. form_set_error('preview_height', t('"Preview height" must be a positive integer.'));
  512. }
  513. if (!is_numeric($widget['thumbnail_width']) || intval($widget['thumbnail_width']) != $widget['thumbnail_width'] || $widget['thumbnail_width'] < 1) {
  514. form_set_error('thumbnail_width', t('"Thumbnail width" must be a positive integer.'));
  515. }
  516. if (!is_numeric($widget['thumbnail_height']) || intval($widget['thumbnail_height']) != $widget['thumbnail_height'] || $widget['thumbnail_height'] < 1) {
  517. form_set_error('thumbnail_height', t('"Thumbnail height" must be a positive integer.'));
  518. }
  519. }
  520. break;
  521. case 'save':
  522. if ($widget['widget_type'] == 'emvideo_textfields') {
  523. $columns = array('video_width', 'video_height', 'video_autoplay', 'preview_width', 'preview_height', 'preview_autoplay', 'thumbnail_width', 'thumbnail_height', 'thumbnail_default_path', 'thumbnail_link_title');
  524. $columns = array_merge($columns, emfield_emfield_widget_settings('save', $widget, 'emvideo'));
  525. return $columns;
  526. }
  527. break;
  528. }
  529. }
  530. /**
  531. * Implementation of hook_widget()
  532. */
  533. function emvideo_widget(&$form, &$form_state, $field, $items, $delta = 0) {
  534. return emfield_emfield_widget($form, $form_state, $field, $items, $delta, 'emvideo');
  535. }
  536. function emvideo_embed_form($form_state = NULL, $field, $item, $formatter, $node, $options = array(), $other = array()) {
  537. $embed = $item['value'];
  538. $width = !empty($options['width']) ? $options['width'] : $field['widget']['video_width'];
  539. $height = !empty($options['height']) ? $options['height'] : $field['widget']['video_height'];
  540. $autoplay = !empty($options['autoplay']) ? $options['autoplay'] : $field['widget']['video_autoplay'];
  541. $title = !empty($options['title']) ? $options['title'] : t('Embed Code');
  542. $description = !empty($options['description']) ? $options['description'] : t('To embed this video on your own site, simply copy and paste the html code from this text area.');
  543. $text = emfield_include_invoke('emvideo', $item['provider'], 'video', $embed, $width, $height, $field, $item, $node, $autoplay, $options);
  544. $form = array();
  545. $form['emvideo_embed'] = array(
  546. '#type' => 'textarea',
  547. '#title' => $title,
  548. '#description' => $description,
  549. '#default_value' => $text,
  550. );
  551. return $form;
  552. }
  553. /**
  554. * Providers may supply an enclosure for rss feeds. This expects something in a
  555. * file format, so would be an object in the format of $file->filepath,
  556. * $file->filesize, and $file->filemime.
  557. * Calls the providers hook EMVIDEO_PROVIDER_RSS($item, $teaser).
  558. */
  559. function emvideo_emfield_rss($node, $items = array(), $teaser = NULL) {
  560. $rss_data = array();
  561. foreach ($items as $item) {
  562. // note only the first $item will get an RSS enclosure, other items may have media: data in the feed however
  563. if ($item['value'] && $item['provider']) {
  564. $rss_data[] = emfield_include_invoke('emvideo', $item['provider'], 'rss', $item, $teaser);
  565. }
  566. }
  567. return $rss_data;
  568. }
  569. function emvideo_handler_arg_provider($op, &$query, $argtype, $arg = '') {
  570. $ret = _emfield_handler_arg_provider($op, $query, $argtype, $arg, 'emvideo');
  571. return $ret;
  572. }
  573. /**
  574. * Page callback for emvideo/thickbox/shadowbox.
  575. * This will display our video in a modal window defined by the corresponding
  576. * modal module.
  577. * As it's a direct callback, it displays no HTML other than the video.
  578. * @param $node
  579. * The video node object.
  580. * @param $width
  581. * The width, in pixels, of the video.
  582. * @param $height
  583. * The height, in pixels, of the video.
  584. * @param $field_name
  585. * The name of the field to display
  586. * @param $provider
  587. * The provider of the video.
  588. * @param $code
  589. * The video code to display.
  590. * @param $extra
  591. * Some video codes have a '/' character, so we have to accomodate in the URL.
  592. */
  593. function emvideo_modal($node, $width, $height, $field_name, $provider, $code, $extra = NULL) {
  594. $field = content_fields($field_name);
  595. $field['widget']['video_width'] = $width;
  596. $field['widget']['video_height'] = $height;
  597. $field['widget']['video_autoplay'] = 1;
  598. // Respect any field access permissions.
  599. if (!content_access('view', $field, NULL, $node)) {
  600. drupal_access_denied();
  601. return;
  602. }
  603. // If the URL has an extra bit, then append that to the video code.
  604. // This broke shadowbox, which needs index.php to register as iFrame.
  605. if (isset($extra) && ($extra != 'index.php')) {
  606. $code .= '/'. $extra;
  607. }
  608. foreach ($node->{$field_name} as $video) {
  609. if ($video['provider'] == $provider && $video['value'] == $code) {
  610. $item = $video;
  611. }
  612. }
  613. // Suppress the Admin Menu, if that module/fuction exists.
  614. if (function_exists('admin_menu_suppress')) {
  615. admin_menu_suppress();
  616. }
  617. $output = theme('emvideo_video_video', $field, $item, 'video_video', $node, array('iframe' => TRUE));
  618. print theme('emvideo_modal_iframe', $output);
  619. }
  620. function emvideo_convert_to_seconds($time) {
  621. module_load_include('inc', 'emvideo', 'emvideo.theme');
  622. return _emvideo_convert_to_seconds($time);
  623. }
  624. function emvideo_seconds_to_time($time) {
  625. module_load_include('inc', 'emvideo', 'emvideo.theme');
  626. return _emvideo_seconds_to_time($time);
  627. }
  628. /**
  629. * Implementation of hook_views_api().
  630. */
  631. function emvideo_views_api() {
  632. return array(
  633. 'api' => 2,
  634. 'path' => drupal_get_path('module', 'emvideo') . '/includes/views',
  635. );
  636. }