-
Notifications
You must be signed in to change notification settings - Fork 0
/
funi_video.module
219 lines (192 loc) · 6.54 KB
/
funi_video.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?php
//$Id$
/**
* Implementation of hook_init().
*/
/*
function funi_video_init() {
funi_video_embed();
}
*/
// User permissions
define('FUNI_VIDEO_ADMIN_PERM', 'Administer Funi Video module');
/**
* Implementation of hook_menu().
*/
/*
function funi_video_menu() {
$items = array();
$items['admin/build/funi_video'] = array(
'title' => t('Funi Players'),
'description' => t('Funi Video Settings page.'),
'page callback' => 'drupal_get_form',
'page arguments' => array('funi_video_admin_settings'),
'access arguments' => array(FUNI_VIDEO_ADMIN_PERM),
'type' => MENU_NORMAL_ITEM,
'file' => 'funi_video.admin.inc',
'weight' => 10,
);
return $items;
}
*/
/**
* Implementation of hook_perm().
*/
function funi_video_perm() {
return array(FUNI_VIDEO_ADMIN_PERM);
}
/**
* Implementation of hook_theme().
*/
function funi_video_theme() {
return array(
'funi_video_settings' => array(
'arguments' => array('form' => NULL),
'file' => 'funi_video.admin.inc',
),
'funi_video_admin_form_tabs' => array(
'arguments' => array('form' => NULL),
'file' => 'funi_video.admin.inc',
),
'funi_video_tabs' => array(
'arguments' => array('funi_video', 'active_tab' => 'none'),
),
'funi_video' => array(
'arguments' => array('funi_video'),
),
'funi_video_tab_access_denied' => array(
'arguments' => array('tab'),
),
'funi_video_admin_list' => array(
'arguments' => array('form' => NULL),
),
);
}
/**
* Load the funi_video data for form processing.
*/
/*
function funi_video_load($aid, $op = 'view') {
$funi_video = db_fetch_array(db_query('SELECT * FROM {funi_video} WHERE aid = %d', $aid));
if (!$funi_video) {
return FALSE;
}
return $funi_video;
}
*/
/**
* Implementation of nodeapi().
*/
function funi_video_nodeapi(&$node, $op, $teaser, $page) {
// we won't do anything if this is not the right node types
$types = array('show','movie','episode','ova','clip','special','trailer');
if(!in_array($node->type, $types)) return;
/*
* nodeapi logic for the VIDEOS table
*/
$video_types = array('movie','episode','ova','clip','special','trailer');
if(in_array($node->type, $video_types)) {
//kpr($node);
switch($op) {
// Now we need to take care of loading the active state from the
// database. An array containing our extra field needs to be returned.
case 'load':
return _funi_video_load_video($node);
break;
// Insert is called after the node has been validated and saved to the
// database. It gives us a chance to create our own record in the database.
case 'insert':
db_query('INSERT INTO {funivideo_videos} (nid, vid, rating) VALUES (%d, %d, %d)', $node->nid, $node->vid, $node->funivideo_videos_rating);
break;
// Update is called when an existing node has been changed. Here, we use a
// DELETE then an INSERT rather than an UPDATE. The reason is that a node
// created before this module was installed won't already have a rating
// saved so there would be nothing to update.
case 'update':
_funi_video_update_video($node);
break;
// Delete is called when the node is being deleted, it gives us a chance
// to delete the rating too.
// This will delete all revisions as well.
case 'delete':
db_query('DELETE FROM {funivideo_videos} WHERE nid = %d', $node->nid);
break;
// When a node revision is deleted, we need to remove the corresponding
// record from our table. The only way to handle revision deletion is by
// implementing hook_nodeapi().
case 'delete revision':
// Notice that we're matching a single revision based on the node's vid.
db_query('DELETE FROM {funivideo_videos} WHERE vid = %d', $node->vid);
break;
}
}
}
// helper queries
function _funi_video_load_video($node) {
$state = db_result(db_query('SELECT active_state FROM {funivideo_videos} WHERE nid = %d', $node->nid));
return array('funi_video_state' => $state);
}
// return an array calculated results on a video node for updating our video table
function _funi_video_active_calcs($node) {
module_load_include('inc', 'funi_video', 'funi_video.logic');
$calculated = array();
// show name
$calculated['show_name'] = _funi_video_group_name($node->nid);
/*
* active states
*/
$states = new funiVideoStates($node);
// active state
$calculated['streaming'] = $states->funimationIsActive();
$calculated['subscription'] = $states->subscriptionIsActive();
$calculated['hulu'] = $states->huluIsActive();
kpr($calculated);
exit();
return $calculated;
}
function _funi_video_insert_video($node) {
$calcs = _funi_video_active_calcs($node);
db_query('INSERT INTO {funivideo_videos} (nid, show_name, node_type, quality, fs_sunrise, fs_sunset, sub_sunrise, sub_sunset, active_state, exlusive_active, next_sunrise, last_check, next_check)
VALUES (%d, "%s", "%s", "%s", %d, %d, %d)',
$node->nid,
$calculated['show_name'],
$node->type,
$node->field_quality[0]['value'],
_funi_video_nix_time($node->field_sunrise_date[0]['value']),
_funi_video_nix_time($node->field_sunset_date[0]['value']),
_funi_video_nix_time($node->field_subscription_sunrise_date[0]['value']),
_funi_video_nix_time($node->field_subscription_sunset_date[0]['value'])
);
}
function _funi_video_update_video($node) {
$calcs = _funi_video_active_calcs($node);
db_query("UPDATE {funivideo_videos}
SET show_name = '%s',
node_type = '%s',
quality = '%s',
fs_sunrise = %d,
fs_sunset = %d,
sub_sunrise = %d
WHERE nid = %d",
$calculated['show_name'],
$node->type,
$node->field_quality[0]['value'],
_funi_video_nix_time($node->field_sunrise_date[0]['value']),
_funi_video_nix_time($node->field_sunset_date[0]['value']),
_funi_video_nix_time($node->field_subscription_sunrise_date[0]['value']),
$node->nid
);
}
// get a video's show name using the organic groups tables
function _funi_video_group_name($nid) {
$results = db_query('SELECT og.og_description FROM {og_ancestry} oa INNER JOIN {og} og ON oa.group_nid = og.nid WHERE oa.nid = %d', $nid); // Run the query
while ($fields = db_fetch_array($results)) { // Get the next result as an associative array
foreach($fields as $key => $value) { // Iterate over all of the fields in this row
$show_name = $value;
}
}
return $show_name;
}
function _funi_video_nix_time($timestamp) {
return !IS_NULL($timestamp) ? strtotime($timestamp) : NULL;
}