Skip to content

Commit 15c6d97

Browse files
author
emilye
committed
initial commit to cma
0 parents  commit 15c6d97

23 files changed

+2128
-0
lines changed

LICENSE.txt

Lines changed: 339 additions & 0 deletions
Large diffs are not rendered by default.

css/telvue.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.now-next-airing {
2+
text-align: center;
3+
}
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
<?php
2+
3+
/**
4+
* @file
5+
* Feeds parser class for Telvue
6+
*/
7+
8+
/**
9+
* Class definition for Telvue Parser.
10+
*
11+
* Parses RSS feeds returned from Telvue schedule.
12+
*/
13+
class FeedsTelvueParser extends FeedsParser {
14+
15+
/**
16+
* Parse the extra mapping sources provided by this parser.
17+
*
18+
* @param $fetcher_result FeedsFetcherResult
19+
* @param $source FeedsSource
20+
*
21+
* @see FeedsParser::parse()
22+
*/
23+
public function parse(FeedsSource $source, FeedsFetcherResult $fetcher_result) {
24+
25+
$mediarss_feed = $fetcher_result->getRaw();
26+
27+
$result = new FeedsParserResult();
28+
29+
/**
30+
* @see common_syndication_parser_parse()
31+
*/
32+
if (!defined('LIBXML_VERSION') || (version_compare(phpversion(), '5.1.0', '<'))) {
33+
@$sxml = simplexml_load_string($mediarss_feed, NULL);
34+
}
35+
else {
36+
@$sxml = simplexml_load_string($mediarss_feed, NULL, LIBXML_NOERROR | LIBXML_NOWARNING | LIBXML_NOCDATA);
37+
}
38+
39+
// Got a malformed XML.
40+
if ($sxml === FALSE || is_null($sxml)) {
41+
throw new Exception(t('FeedsTelvueParser: Malformed XML source.'));
42+
}
43+
44+
if ($this->isRssFeed($sxml)) {
45+
$result = $this->parseRss20($sxml, $source, $fetcher_result);
46+
}
47+
else {
48+
throw new Exception(t('FeedsTelvueParser: Unknown type of feed.'));
49+
}
50+
return $result;
51+
}
52+
53+
/**
54+
* Check if given feed object is a RSS feed.
55+
*
56+
* @param SimpleXMLElement $sxml
57+
*
58+
* @return boolen
59+
* TRUE if given SimpleXML object is RSS feed or FALSE
60+
*/
61+
protected function isRssFeed(SimpleXMLElement $sxml) {
62+
return $sxml->getName() == 'rss';
63+
}
64+
65+
/**
66+
* Add the extra mapping sources provided by this parser.
67+
*/
68+
public function getMappingSources() {
69+
return parent::getMappingSources() + array(
70+
'guid' => array(
71+
'name' => t('GUID'),
72+
),
73+
'link' => array(
74+
'name' => t('Link'),
75+
),
76+
'title' => array(
77+
'name' => t('Title'),
78+
'description' => t('Title.'),
79+
),
80+
'author' => array(
81+
'name' => t('Author'),
82+
'description' => t('Author or uploader of the video.'),
83+
),
84+
'published' => array(
85+
'name' => t('Published'),
86+
),
87+
'description' => array(
88+
'name' => t('Description'),
89+
),
90+
'tags' => array(
91+
'name' => t('Tags'),
92+
'description' => t('This can be imported directly with Taxonomy "tags" vocabularies.'),
93+
),
94+
95+
96+
// http://www.telvue.com/support/product-documentation/princeton-server-api-docs/schedule-methods/get-channel-schedule-as-rss-rest/
97+
'channel' => array(
98+
'name' => t('channel'),
99+
),
100+
'psg_eventid' => array(
101+
'name' => t('eventId'),
102+
),
103+
'psg_duration' => array(
104+
'name' => t('duration'),
105+
),
106+
'psg_end_datetime' => array(
107+
'name' => t('end_datetime'),
108+
),
109+
'psg_programcode' => array(
110+
'name' => t('programCode'),
111+
),
112+
'psg_episode' => array(
113+
'name' => t('episode'),
114+
),
115+
'psg_episodecode' => array(
116+
'name' => t('episodeCode'),
117+
),
118+
'psg_thumbnail' => array(
119+
'name' => t('thumbnail'),
120+
),
121+
122+
);
123+
}
124+
125+
126+
127+
/**
128+
* Parse RSS 2.0 feed
129+
*
130+
* @param SimpleXMLElement $sxml
131+
* @param FeedsFetcherResult $fetcher_result
132+
* @param FeedsSource $source
133+
*/
134+
private function parseRss20(SimpleXMLElement $sxml, FeedsSource $source, FeedsFetcherResult $fetcher_result) {
135+
136+
// XML was parsed successfully, so we can begin to process items
137+
$result = new FeedsParserResult();
138+
$fetcher_result->title = (string) $sxml->channel->title;
139+
$fetcher_result->description = (string) $sxml->channel->description;
140+
$fetcher_result->link = (string) $sxml->channel->link;
141+
$feed_title = (string) $sxml->channel->title;
142+
143+
$namespaces = $sxml->getNamespaces(true);
144+
145+
foreach ($sxml->xpath('//item') as $entry) {
146+
147+
// Get nodes in media: namespace for media information
148+
$psg = $entry->children($namespaces['psg']);
149+
150+
$start_parts = explode(' -', $entry->pubDate);
151+
$end_parts = explode(' -', $psg->end_datetime[0]);
152+
153+
//shift
154+
$hours = $start_parts[1]/100;
155+
$shift = 60*60*$hours;
156+
157+
$start = strtotime($start_parts[0]) - $shift;
158+
$end = strtotime($end_parts[0]) - $shift;
159+
160+
//$start = strtotime($start_parts[0]);
161+
//$end = strtotime($end_parts[0]);
162+
163+
$item = array(
164+
'guid' => (string) $entry->guid,
165+
'link' => (string) $entry->link,
166+
'title' => html_entity_decode((string) $entry->title),
167+
'author' => (string) $entry->author,
168+
'description' => html_entity_decode((string) $entry->description),
169+
// $media object doesn't exist.
170+
//'tags' => explode(',', (string) $media->group->keywords),
171+
'published' => (string) $start,
172+
'channel' => (string) $feed_title,
173+
'psg_eventid' => (string) $psg->eventId[0],
174+
'psg_duration' => (string) $psg->duration[0],
175+
'psg_end_datetime' => $end,
176+
'psg_programcode' => (string) $psg->programcode[0],
177+
'psg_episode' => (string) $psg->episode[0],
178+
'psg_episodecode' => (string) $psg->episodecode[0],
179+
'psg_thumbnail' => (string) $psg->thumbnail[0],
180+
181+
);
182+
183+
// Populate the FeedsFetcherResult object with the parsed results.
184+
$result->items[] = $item;
185+
}
186+
187+
return $result;
188+
}
189+
190+
/**
191+
* Display seconds as HH:MM:SS, with leading 0's.
192+
*
193+
* @param $seconds
194+
* The number of seconds to display.
195+
*/
196+
public function secsToTime($seconds) {
197+
// Number of seconds in an hour.
198+
$unith = 3600;
199+
// Number of seconds in a minute.
200+
$unitm = 60;
201+
202+
// '/' given value by num sec in hour... output = HOURS
203+
$hh = intval($seconds / $unith);
204+
205+
// Multiply number of hours by seconds, then subtract from given value.
206+
// Output = REMAINING seconds.
207+
$ss_remaining = ($seconds - ($hh * 3600));
208+
209+
// Take remaining seconds and divide by seconds in a min... output = MINS.
210+
$mm = intval($ss_remaining / $unitm);
211+
// Multiply number of mins by seconds, then subtract from remaining seconds.
212+
// Output = REMAINING seconds.
213+
$ss = ($ss_remaining - ($mm * 60));
214+
215+
$output = '';
216+
217+
// If we have any hours, then prepend that to our output.
218+
if ($hh) {
219+
$output .= "$hh:";
220+
}
221+
222+
// Create a safe-for-output MM:SS.
223+
$output .= sprintf($hh ? "%02d:%02d" : "%d:%02d", $mm, $ss);
224+
225+
return $output;
226+
}
227+
}
228+
229+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; Basic information
2+
name = Feeds: Telvue Schedule
3+
description = Defines psg elements found in the Telvue's Schedule feed so they can be mapped by Feeds.
4+
core = 7.x
5+
package = Feeds
6+
dependencies[] = "feeds"
7+
8+
; Files
9+
files[] = feeds_telvue.install
10+
files[] = feeds_telvue.module
11+
files[] = FeedsTelvueParser.inc
12+
13+
14+
; Information added by Drupal.org packaging script on 2014-04-29
15+
version = "7.x-1.0-alpha5"
16+
core = "7.x"
17+
project = "telvue"
18+
datestamp = "1398793128"
19+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/**
4+
* @file
5+
* Handles actions upon enabling and disabling the module.
6+
*/
7+
8+
/**
9+
* Implements hook_enable().
10+
*/
11+
function feeds_telvue_enable() {
12+
// Clear the cache to display in Feeds as available plugin.
13+
cache_clear_all('plugins:feeds:plugins', 'cache');
14+
}
15+
16+
/**
17+
* Implements hook_disable().
18+
*/
19+
function feeds_telvue_disable() {
20+
// Clear the cache to display in Feeds as available plugin.
21+
cache_clear_all('plugins:feeds:plugins', 'cache');
22+
}
23+
24+
/**
25+
* Implements hook_install().
26+
*/
27+
function feeds_telvue_install() {
28+
db_query("UPDATE {system} SET weight = 999 WHERE name = 'feeds_telvue'");
29+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/**
4+
* @file
5+
* Adds a MediaRSS feed processor to the Feeds module.
6+
*/
7+
8+
/**
9+
* Implements ctools_plugin_api().
10+
*/
11+
12+
function feeds_telvue_ctools_plugin_api($owner, $api) {
13+
if ($owner == 'feeds' && $api == 'plugins') {
14+
return array('version' => 1);
15+
}
16+
}
17+
18+
/**
19+
* Implements hook_feeds_plugins().
20+
*/
21+
function feeds_telvue_feeds_plugins() {
22+
$info = array();
23+
$info['FeedsTelvueParser'] = array(
24+
'name' => 'Telvue Schedule RSS parser',
25+
'description' => 'Parse Schedule feeds from Tevlue playback server.',
26+
'help' => 'Use PHP SimpleXML parser to parse Telvue feed for custom psg elements.',
27+
'handler' => array(
28+
'parent' => 'FeedsParser',
29+
'class' => 'FeedsTelvueParser',
30+
'file' => 'FeedsTelvueParser.inc',
31+
'path' => drupal_get_path('module', 'feeds_telvue'),
32+
),
33+
);
34+
return $info;
35+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.now-next-airing {
2+
text-align: center;
3+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name = Telvue Blocks
2+
package = Community Media
3+
description = "Defines Blocks to Display Now Playing, Playing Next, and Now and Next blocks populated from a Telvue."
4+
core = 7.x
5+
dependencies[] = "telvue"
6+
7+
configure = admin/structure/block
8+
9+
10+
; Information added by Drupal.org packaging script on 2014-04-29
11+
version = "7.x-1.0-alpha5"
12+
core = "7.x"
13+
project = "telvue"
14+
datestamp = "1398793128"
15+

0 commit comments

Comments
 (0)