aboutsummaryrefslogtreecommitdiff
path: root/video.module
blob: 2212e203686a9315f36be49fad95820aae11be05 (plain)
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
<?php
/* $Id$ */

/**

Created by Fabio Varesano on June 2005.
Please, send bug reports, feature requests, or other comments to me:
Fabio Varesano   fvaresano at yahoo dot it

Database definition:
@code
  CREATE TABLE video (
    nid int(10) unsigned NOT NULL default '0',
    vidfile text NOT NULL default '',
    videox int(4) NOT NULL default '',
    videoy int(4) NOT NULL default '',
    size varchar(30) NOT NULL default '',
    clicks int(10) unsigned NOT NULL default '0',
    PRIMARY KEY  (nid)
  )
@endcode


*/

/********************************************************************
 * General Hooks
 ********************************************************************/

function video_help($section = "admin/help#video") {
  switch ($section) {
    case "admin/help#video":
      return t("<p>The videos module is used to insert into drupal Quick Time videos as nodes.</p>");
    case "admin/modules#description":
      return t("Allows QuickTime videos nodes.");
    case 'node/add#video':
      return t("Video allow you to insert QuickTime videos as nodes");
      break;
  }
}


/**
 * Implementation of hook_menu().
 */
function video_menu() {
  global $user;
  //if ($may_cache) {
    $items[] = array(
      'path' => 'node/add/video',
      'title' => t('video'),
      'access' => user_access('create videos'));
    $items[] = array(
      'path' => 'video/goto',
      'callback' => '_video_page_goto',
      'type' => MENU_CALLBACK,
      'callback arguments' => arg(3),
      'access' => user_access('access content'));
    //}

  if (arg(0) == 'node' && is_numeric(arg(1))) {
    $node = node_load(array('nid' => arg(1)));

    if ($node->type == 'video') {
      $items[] = array('path' => 'node/'. arg(1) .'/play',
        'title' => t('play'),
        'callback' => 'video_play',
        'access' => user_access('access content'),
        'weight' => 3,
        'type' => MENU_LOCAL_TASK);
      $items[] = array('path' => 'node/'.arg(1).'/download',
        'title' => t('download'),
        'callback' => 'video_download',
        'access' => user_access('access content'),
        'weight' => 5,
        'type' => MENU_LOCAL_TASK);
    }
  }
  return $items;
}

function video_link($type, $node = 0, $main = 0) {
  $links = array();
  // Node links for a video
  if ($type == 'node' && $node->type == 'video' && $node->vidfile) {
    $links[] = l(t('play'), "node/$node->nid/play", array('class' => 'outgoing', 'title' => t('play %link', array('%link' => $node->title))))." ". t("or"). " ".
               l(t('download'), "video/goto/$node->nid", array('class' => 'outgoing', 'title' => t('visit %link', array('%link' => $node->title)))) ." ".$node->title. (user_access("access statistics") ? " ({$node->clicks})" : "");
  }
  return $links;
}

function video_perm() {
  return array('create videos');
}

function video_settings() {
// put something good here
}



/********************************************************************
 * Node Hooks
 ********************************************************************/

function video_node_name($node) {
  return t("video");
}

function video_access($op, $node) {
  switch($op) {
    case 'view': 
      return $node->status;   // see book.module for reference

    case 'create':
      return user_access("create videos");
  }
}

function video_form(&$node, &$param) {
  $output .= form_textfield(t("Video File"), "vidfile", $node->vidfile, 60, 65535, t("Put here the video file path. You can use both relative path (something/video.mov) or absolute (http://www.myvideo.com/videos/videos.mov).") . ($error['vidfile'] ? $error['vidfile'] : ''), NULL, TRUE);

  $output .= form_textfield(t('Video Size x'), 'videox', $node->videox, 4, 4, t("Horizontal video pixel size."), null, true);
  $output .= form_textfield(t('Video Size y'), 'videoy', $node->videoy, 4, 4, t("Horizontal video pixel size."), null, true);
  $output .= form_textfield(t('Size'), 'size', $node->size, 10, 30, t("Dimension of your video. Also provide size unit (KB or MB)."), null, true);

  if (function_exists('taxonomy_node_form')) {
     $output .= implode('', taxonomy_node_form('video', $node));
  }

  $output .= form_textarea(t("Body"), "body", $node->body, 60, 20, t("Textual description of the video.") . ($error['body'] ? $error['body'] : ''));
  $output .= filter_form('format', $node->format);

  return $output;
}

function video_insert($node) {
	
	//print_r($_FILES);
	//print("FUCK");
	//file_save_upload($_FILES['edit']['tmp_name'], '/home/fabio/public_html/adrenalinteam.it/videos/'. $_FILES['userfile']['name'], true);
	//move_uploaded_file ($_FILES['edit']['tmp_name'], );
	//print_r(file_check_upload($node));
	//die();
   db_query("INSERT INTO {video} (nid, vidfile, size, videox, videoy) VALUES ('%d', '%s', '%s', '%d', '%d')",
	$node->nid, $node->vidfile, $node->size, $node->videox, $node->videoy);
}

function video_update($node) {
//print_r($node);// die();
	//printf("UPDATE {video} (nid, rider, image, vidfile, spot, move, size, videox, videoy) VALUES (%d, '%s', '%s','%s','%s','%s','%s', %d, %d)",
	//$node->nid, $node->rider, $node->image, $node->vidfile, $node->spot, $node->move,  $node->size, $node->videox, $node->videoy); die();
	//printf("UPDATE {video} SET rider = '%s', image = '%s', vidfile = '%s', spot = '%s', move = '%s', size = '%d', videox = '%d', videoy = '%d' WHERE nid = '%d'", $node->rider, $node->image, $node->vidfile, $node->spot, $node->move, $node->size, $node->videox, $node->videoy, $node->nid); die();
	db_query("UPDATE {video} SET vidfile = '%s', size = '%s', videox = '%d', videoy = '%d' WHERE nid = '%d'", $node->vidfile, $node->size, $node->videox, $node->videoy, $node->nid);
}

function video_delete(&$node) {
  db_query("DELETE FROM {video} WHERE nid = '%s'", $node->nid);
  cache_clear_all("video:blogmarks:block");
}

function video_validate(&$node) {
  $result = db_query("SELECT * from {video} WHERE vidfile = '%s' and nid <> '%d'", $node->vidfile, $node->nid);
  if (db_num_rows($result) > 0) {
    $video = db_fetch_object($result);
    $othernode = node_load(array("nid" => $video->nid));
    form_set_error('video', t('A video %link-to-existing using that link already exists', array("%link-to-existing" => l($othernode->title, 'node/' . $othernode->nid . '/edit'))));
  }
}

function video_load($node) {
  return db_fetch_object(db_query("SELECT * FROM {video} WHERE nid = '%d'", $node->nid));
}

/********************************************************************
 * Block display functions
 ********************************************************************/

function video_block($op = "list", $delta = 0) {
  if ($op == "list") {
    return array(
      0 => array('info' => t("Top videos")),
      1 => array('info' => t("Latest videos")),
    );
  }
  elseif ($op == 'view') {
    switch ($delta) {
      case 0:
        return array(
          'subject' => t("Top videos"),
          'content' => video_block_list('top')
        );
      case 1:
        return array(
          'subject' => t("Latest videos"),
          'content' => video_block_list('new')
        );
    }
  }
}


function video_block_list($type = 'top') {
  $orderby = ($type == 'new') ?  'n.created' : 'v.clicks';
  return node_title_list(db_query_range(db_rewrite_sql("SELECT n.nid, n.title FROM {node} n, {video} v WHERE n.type = 'video' AND n.status = 1 AND n.moderate = 0 ORDER by $orderby DESC"),0, 10));
}



function _video_page_goto($id, $type = 'video') {
	global $base_url;
	if (in_array($type, array("video", "feed"))) {
		// DRUPAL 4.5 --> $result = db_query("SELECT n.nid, n.vidfile FROM {video} n ". node_access_join_sql() ." WHERE n.nid = '%d' AND  ". node_access_where_sql(), $id);
		$result = db_query(db_rewrite_sql("SELECT n.nid, n.vidfile FROM {video} n WHERE n.nid = '%d'"), $id);
//printf("SELECT n.nid, n.vidfile FROM {video} n ". node_access_join_sql() ." WHERE n.nid = '%d' AND  ". node_access_where_sql(), $id);
		//print("SELECT n.nid, n.vidfile FROM {video} n ". node_access_join_sql() ." WHERE n.nid = '%d' AND  ". node_access_where_sql());
		$wl = db_fetch_object($result);
//print_r($wl);
$type = "vidfile";
		if ($wl->$type!='')   {
       db_query("UPDATE {video} SET clicks = clicks + 1 where nid = '%d'", $id);
       //printf("UPDATE {video} SET clicks = clicks + 1 where nid = '%d'", $id);
       // Didn't this use to work?
       header("HTTP/1.0 301 Moved Permanently");
    }
    //print($base_url."/".$wl->$type);
		header("Location: " . $base_url."/".$wl->$type);
    //drupal_goto($wl->$type);
		print("ciao");
  }
}


function video_download() {
	 if ($node = node_load(array('nid' => arg(1)))) {
    _video_page_goto($node->nid);
  }
  else {
    drupal_not_found();
  }
}

/**
Implements play callback function from node menu
*/
function video_play() {
	 if ($node = node_load(array('nid' => arg(1)))) {
    print theme('video_play', $node, $node->title);
		//theme('page', $node, $node->title);
  }
  else {
    drupal_not_found();
  }
}

/**
Themeable functions for playing videos.
It prints a page with a quicktime player inside
linked to the file record of the node.
*/
function theme_video_play($node, $main = 0)
{
	//print_r($node);
	//print(url("video/goto/$node->nid")); die();
	$output = "\n<div id=\"video-player\">\n";
	$output .= '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="330" height="250" scale="tofit" codebase="http://www.apple.com/qtactivex/qtplugin.cab">          
                <param name="SRC" value="'.url("video/goto/$node->nid").'" />
                <param name="AUTOPLAY" value="true" />
                <param name="KIOSKMODE" value="false" />
                  <embed src="'.url("video/goto/$node->nid").'" width="'.$node->videox.'" height="'.$node->videoy.'" scale="tofit" autoplay="true" kioskmode="false" pluginspage="http://www.apple.com/quicktime/download/">
                  </embed>
             </object>
						 <p> ';
	$output .= t("Problems viewing videos?")."<br />";
	$output .= t("Download latest Quicktime Player")." ";
	$output .= '<a href="http://www.apple.com/quicktime/download" title="Link to QuickTime Downoad Page">'.t("here").'</a>';
	//l($text, $path, $attributes = array(), $query = NULL, $fragment = NULL, $absolute = FALSE)
	$output .= "</p> \n </div>\n";
	//node_prepare($node, $main);
	//$node->body = $output;
	//return node_prepare($node, $main);
	//print $output;
	return theme("page", $output, t("Playing")." ".$node->title);
}

function theme_video_content($node, $main = 0) {
  $output = "<div id=\"tablezone\">\n";
	$output .= theme_video_node_short($node);
  $output .= "</div>\n";
  $node->body = $output;
	return $node;
}

?>