asset_emfield.module

Tracking 5.x-2.x branch
  1. drupal
    1. 5 contributions/asset/contrib/asset_emfield/asset_emfield.module
    2. 6 contributions/asset/contrib/asset_emfield/asset_emfield.module

Asset Embedded Media Module

Integration with emfield for using 3rd-party embedded media as assets.

Functions & methods

NameDescription
asset_emfield_asset_formatterImplementation of hook_asset_formatter().
asset_emfield_asset_search
asset_emfield_asset_typeImplementation of hook_asset_type().
asset_emfield_invokehelper function to bridge hook_asset_type and emfield cck hooks
asset_emfield_system_listcopied-and-modified version of emfield_system_list, to load our own provider includes

File

View source
  1. <?php
  2. /**
  3. * @file
  4. * Asset Embedded Media Module
  5. *
  6. * Integration with emfield for using 3rd-party embedded media as assets.
  7. */
  8. /**
  9. * Implementation of hook_asset_type().
  10. */
  11. function asset_emfield_asset_type($op = 'info', &$asset = NULL) {
  12. switch ($op) {
  13. case 'info':
  14. return array(
  15. 'emfield_video' => array(
  16. 'name' => t('Embedded Video'),
  17. 'module' => 'asset_emfield',
  18. 'description' => t('Create a new video asset using embed code from a 3rd-party site.'),
  19. ),
  20. );
  21. break;
  22. case 'form':
  23. return asset_emfield_invoke('form', $asset);
  24. case 'validate':
  25. asset_emfield_invoke('validate', $asset);
  26. break;
  27. case 'insert':
  28. asset_emfield_invoke('submit', $asset);
  29. $field = $asset->emfield[0];
  30. db_query('INSERT INTO {asset_emfield} (aid, embed, value, provider, data) VALUES (%d, "%s", "%s", "%s", "%s")',
  31. $asset->aid, $field['embed'], $field['value'], $field['provider'], serialize($field['data']));
  32. break;
  33. case 'update':
  34. asset_emfield_invoke('submit', $asset);
  35. $field = $asset->emfield[0];
  36. db_query('UPDATE {asset_emfield} SET embed="%s", value="%s", provider="%s", data="%s" WHERE aid=%d',
  37. $field['embed'], $field['value'], $field['provider'], serialize($field['data']), $asset->aid);
  38. break;
  39. case 'load':
  40. $result = db_query('SELECT * FROM {asset_emfield} WHERE aid=%d', $asset->aid);
  41. while ($row = db_fetch_array($result)) {
  42. $asset->emfield[0] = $row;
  43. }
  44. $return = asset_emfield_invoke('load', $asset);
  45. return array('emfield' => $return['emfield']);
  46. case 'view':
  47. switch ($asset->type) {
  48. case 'emfield_video':
  49. return asset_render($asset, 'video_video');
  50. }
  51. break;
  52. case 'img':
  53. case 'icon':
  54. if ($asset->type == 'emfield_video') {
  55. $item = $asset->emfield[0];
  56. if ($item['value'] && $item['provider']) {
  57. // if we have emthumb installed, then give it a chance to override our thumbnail
  58. $thumbnail_url = module_invoke('emthumb', 'thumbnail_url', $item);
  59. // if we don't have a custom thumbnail, then see if the provider gives us one
  60. $thumbnail_url = $thumbnail_url ? $thumbnail_url : module_invoke('emfield', 'include_invoke', 'video_cck', $item['provider'], 'thumbnail', NULL, $item, NULL, NULL, 64, 64);
  61. return $thumbnail_url;
  62. }
  63. }
  64. break;
  65. }
  66. }
  67. /**
  68. * Implementation of hook_asset_formatter().
  69. */
  70. function asset_emfield_asset_formatter($op='info', $asset=null, $attr=array()) {
  71. $module_map = array(
  72. 'emfield_video' => 'video_cck',
  73. );
  74. $module = $module_map[$asset->type];
  75. switch ($op) {
  76. case 'info':
  77. foreach ($module_map as $module) {
  78. $cck_formats = module_invoke($module, 'field_formatter_info');
  79. foreach ($cck_formats as $key => $cck_format) {
  80. if ($key != 'default') {
  81. $formats[$key] = array(
  82. 'name' => $cck_format['label'],
  83. 'description' => $cck_format['description'],
  84. 'module' => 'asset_emfield',
  85. );
  86. }
  87. }
  88. }
  89. return $formats;
  90. case 'load':
  91. if ($asset->type == 'emfield_video') {
  92. $formats = array();
  93. $cck_formats = module_invoke($module, 'field_formatter_info');
  94. foreach ($cck_formats as $key => $cck_format) {
  95. if ($key != 'default') {
  96. $formats[] = $key;
  97. }
  98. }
  99. return $formats;
  100. }
  101. break;
  102. case 'render':
  103. return asset_emfield_invoke('render', $asset, $attr['format']);
  104. case 'form':
  105. // $function = 'asset_embed_'. $asset->embed['provider'] .'_'. $op;
  106. // if (function_exists($function)) {
  107. // return call_user_func($function, $asset, $attr);
  108. // }
  109. break;
  110. }
  111. }
  112. /**
  113. * helper function to bridge hook_asset_type and emfield cck hooks
  114. */
  115. function asset_emfield_invoke($op, &$asset, $a3 = NULL) {
  116. // TODO: use widget settings to provide a dynamic widget object
  117. $field = array(
  118. 'field_name' => 'emfield',
  119. 'type' => $map[$asset->type],
  120. 'required' => 1,
  121. 'multiple' => 0,
  122. 'db_storage' => 1, // ????
  123. 'widget' => array(
  124. 'default_value' => array(
  125. 0 => array('embed' => '', 'value' => ''),
  126. ),
  127. 'providers' => array(
  128. // leave empty to allow all
  129. ),
  130. 'type' => 'video_cck_textfields',
  131. 'label' => t('Embedded Media'),
  132. 'description' => '',
  133. ),
  134. );
  135. $module_map = array(
  136. 'emfield_video' => 'video_cck',
  137. );
  138. $module = $module_map[$asset->type];
  139. $node = new stdClass();
  140. // emfield_emfield_field_formatter checks for a node type, and if not will load
  141. // the field widget settings. the type doesn't really matter though.
  142. $node->type = '__asset';
  143. if ($op == 'form') {
  144. return emfield_emfield_widget($op, $node, $field, $asset->emfield, $module);
  145. }
  146. elseif ($op == 'render') {
  147. return module_invoke('emfield', 'emfield_field_formatter', $field, $asset->emfield[0], $a3, $node, $module);
  148. }
  149. else{
  150. return emfield_emfield_field($op, $node, $field, $asset->emfield, 0, 0, $module);
  151. }
  152. }
  153. function asset_emfield_asset_search($op = 'info', $type = NULL, $a3 = NULL) {
  154. // load all of our provider includes inside the asset_emfield module folder
  155. asset_emfield_system_list('asset_emfield');
  156. $module = 'video_cck';
  157. switch ($op) {
  158. case 'info':
  159. $providers = emfield_system_list($module);
  160. $searches = array();
  161. foreach ($providers as $provider) {
  162. $info = emfield_include_invoke($module, $provider->name, 'asset_search', 'info');
  163. if ($info && is_array($info)) {
  164. $searches = $searches + $info;
  165. }
  166. }
  167. return $searches;
  168. case 'url':
  169. $url = emfield_include_invoke($module, $type['emfield_provider'], 'asset_search', 'url', $type, $a3);
  170. return $url;
  171. case 'feed item':
  172. $asset = emfield_include_invoke($module, $type['emfield_provider'], 'asset_search', 'feed item', $type, $a3);
  173. return $asset;
  174. }
  175. }
  176. /**
  177. * copied-and-modified version of emfield_system_list, to load our own provider includes
  178. */
  179. function asset_emfield_system_list($module, $provider = NULL, $load = TRUE) {
  180. static $list = array();
  181. $files = drupal_system_listing("$provider\.inc", drupal_get_path('module', $module) ."/providers", 'name', 0);
  182. ksort($files);
  183. if ($load) {
  184. foreach ($files as $file) {
  185. if ($file && !isset($list[$file->name])) {
  186. include_once('./'. $file->filename);
  187. $list[$file->name] = $file->name;
  188. }
  189. }
  190. }
  191. return $files;
  192. }