/[drupal]/contributions/modules/emfield/contrib/video_cck/providers/lastfm.inc
ViewVC logotype

Contents of /contributions/modules/emfield/contrib/video_cck/providers/lastfm.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Mon May 12 04:10:54 2008 UTC (18 months, 2 weeks ago) by alexua
Branch: MAIN
CVS Tags: DRUPAL-5--1-3, HEAD
Changes since 1.1: +3 -2 lines
File MIME type: text/x-php
Corrected all errors registered by Coder module in preperation for D6 port
1 <?php
2 // $Id: lastfm.inc,v 1.1 2008/03/21 14:26:22 aaron Exp $
3
4 define('VIDEO_CCK_LASTFM_MAIN_URL', 'http://www.lastfm.com/');
5
6 /**
7 * hook video_cck_PROVIDER_info
8 * this returns information relevant to a specific 3rd party video provider
9 * @return
10 * an array of strings requested by various admin and other forms
11 * 'name' => the translated name of the provider
12 * 'url' => the url to the main page for the provider
13 * 'settings_description' => a description of the provider that will be posted in the admin settings form
14 * 'supported_features' => an array of rows describing the state of certain supported features by the provider.
15 * These will be rendered in a table, with the columns being 'Feature', 'Supported', 'Notes'.
16 */
17 function video_cck_lastfm_info() {
18 $name = t('Last.fm');
19 $features = array(
20 array(t('Autoplay'), t('No'), ''),
21 array(t('RSS Attachment'), t('No'), ''),
22 array(t('Thumbnails'), t('No'), t('')),
23 );
24 return array(
25 'provider' => 'lastfm',
26 'name' => $name,
27 'url' => VIDEO_CCK_LASTFM_MAIN_URL,
28 'settings_description' => t('These settings specifically affect videos displayed from !lastfm.', array('!lastfm' => l($name, VIDEO_CCK_LASTFM_MAIN_URL, array('target' => '_blank')))),
29 'supported_features' => $features,
30 );
31 }
32
33 /**
34 * hook video_cck_PROVIDER_settings
35 * this should return a subform to be added to the video_cck_settings() admin settings page.
36 * note that a form field will already be provided, at $form['PROVIDER'] (such as $form['lastfm'])
37 * so if you want specific provider settings within that field, you can add the elements to that form field.
38 */
39 function video_cck_lastfm_settings() {
40 }
41
42 /**
43 * hook video_cck_PROVIDER_extract
44 * this is called to extract the video code from a pasted URL or embed code.
45 * @param $embed
46 * an optional string with the pasted URL or embed code
47 * @return
48 * either an array of regex expressions to be tested, or a string with the video code to be used
49 * if the hook tests the code itself, it should return either the string of the video code (if matched), or an empty array.
50 * otherwise, the calling function will handle testing the embed code against each regex string in the returned array.
51 */
52 function video_cck_lastfm_extract($embed = '') {
53 // http://www.last.fm/music/The+Shins/+videos/2794412
54 // <object width="340" height="289" id="player" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" align="middle"> <param name="movie" value="http://cdn.last.fm/videoplayer/33/VideoPlayer.swf" /> <param name="menu" value="false" /> <param name="quality" value="high" /> <param name="bgcolor" value="#000000" /> <param name="allowFullScreen" value="true" /> <param name="flashvars" value="embed=true&creator=The+Shins&title=Phantom+Limb&uniqueName=2794412&albumArt=http://cdn.last.fm/coverart/130x130/3243014.jpg&album=Wincing+the+Night+Away&duration=&image=http://userserve-ak.last.fm/serve/image:320/2794412.jpg&FSSupport=true" /> <embed src="http://cdn.last.fm/videoplayer/33/VideoPlayer.swf" menu="false" quality="high" bgcolor="#000000" width="340" height="289" name="player" align="middle" allowFullScreen="true" flashvars="embed=true&creator=The+Shins&title=Phantom+Limb&uniqueName=2794412&albumArt=http://cdn.last.fm/coverart/130x130/3243014.jpg&album=Wincing+the+Night+Away&duration=&image=http://userserve-ak.last.fm/serve/image:320/2794412.jpg&FSSupport=true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /> </object>
55
56 // thumb:
57 // http://userserve-ak.last.fm/serve/image:160/2794412.jpg
58
59 // src="http://www.lastfm.com/v/nvbQQnvxXDk"
60 // http://lastfm.com/watch?v=nvbQQnvxXDk
61 // http://www.lastfm.com/watch?v=YzFCA-xUc8w&feature=dir
62 if (preg_match('@cdn.last.fm@i', $embed, $matches)) {
63 if (preg_match('@uniqueName=([0-9]+)@i', $embed, $matches)) {
64 return $matches[1];
65 }
66 }
67 else if (preg_match('@last\.fm@i', $embed, $matches)) {
68 if (preg_match('@([0-9]+)@i', $embed, $matches)) {
69 return $matches[1];
70 }
71 }
72 return array(
73 );
74 }
75
76 /**
77 * hook video_cck_PROVIDER_embedded_link($video_code)
78 * returns a link to view the video at the provider's site
79 * @param $video_code
80 * the string containing the video to watch
81 * @return
82 * a string containing the URL to view the video at the original provider's site
83 */
84 function video_cck_lastfm_embedded_link($video_code) {
85 return '';
86 }
87
88 /**
89 * the embedded flash displaying the lastfm video
90 */
91 function theme_video_cck_lastfm_flash($embed, $width, $height, $autoplay) {
92 static $count;
93 if ($embed) {
94 // set css id count
95 $count++;
96 $output .= '<object width="'. $width .'" height="'. $height .'" id="emfield-videocck-player-lastfm-'. $count .'" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" align="middle"> <param name="movie" value="http://cdn.last.fm/videoplayer/33/VideoPlayer.swf" /> <param name="menu" value="false" /> <param name="quality" value="high" /> <param name="bgcolor" value="#000000" /> <param name="allowFullScreen" value="true" /> <param name="flashvars" value="embed=true&creator=&title=&uniqueName='. $embed .'&albumArt=&album=&duration=&image=http://userserve-ak.last.fm/serve/image:320/'. $embed .'.jpg&FSSupport=true" /> <embed src="http://cdn.last.fm/videoplayer/33/VideoPlayer.swf" menu="false" quality="high" bgcolor="#000000" width="'. $width .'" height="'. $height .'" name="player" align="middle" allowFullScreen="true" flashvars="embed=true&creator=&title=&uniqueName='. $embed .'&albumArt=&album=&duration=&image=http://userserve-ak.last.fm/serve/image:320/'. $embed .'.jpg&FSSupport=true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /> </object>';
97 }
98 return $output;
99 }
100
101 /**
102 * hook video_cck_PROVIDER_thumbnail
103 * returns the external url for a thumbnail of a specific video
104 * TODO: make the args: ($embed, $field, $item), with $field/$item provided if we need it, but otherwise simplifying things
105 * @param $field
106 * the field of the requesting node
107 * @param $item
108 * the actual content of the field from the requesting node
109 * @return
110 * a URL pointing to the thumbnail
111 */
112 function video_cck_lastfm_thumbnail($field, $item, $formatter, $node, $width, $height) {
113 $lastfm_id = $item['value'];
114
115 // if we have a large thumbnail size, then get the larger version available.
116 if ($width >= 320) {
117 $tn = "http://userserve-ak.last.fm/serve/image:320/$lastfm_id.jpg";
118 }
119 else {
120 $tn = "http://userserve-ak.last.fm/serve/image:160/$lastfm_id.jpg";
121 }
122 return $tn;
123 }
124
125 /**
126 * hook video_cck_PROVIDER_video
127 * this actually displays the full/normal-sized video we want, usually on the default page view
128 * @param $embed
129 * the video code for the video to embed
130 * @param $width
131 * the width to display the video
132 * @param $height
133 * the height to display the video
134 * @param $field
135 * the field info from the requesting node
136 * @param $item
137 * the actual content from the field
138 * @return
139 * the html of the embedded video
140 */
141 function video_cck_lastfm_video($embed, $width, $height, $field, $item, $autoplay) {
142 $output = theme('video_cck_lastfm_flash', $embed, $width, $height, $autoplay);
143 return $output;
144 }
145
146 /**
147 * hook video_cck_PROVIDER_video
148 * this actually displays the preview-sized video we want, commonly for the teaser
149 * @param $embed
150 * the video code for the video to embed
151 * @param $width
152 * the width to display the video
153 * @param $height
154 * the height to display the video
155 * @param $field
156 * the field info from the requesting node
157 * @param $item
158 * the actual content from the field
159 * @return
160 * the html of the embedded video
161 */
162 function video_cck_lastfm_preview($embed, $width, $height, $field, $item, $autoplay) {
163 $output = theme('video_cck_lastfm_flash', $embed, $width, $height, $autoplay);
164 return $output;
165 }

  ViewVC Help
Powered by ViewVC 1.1.2