View source
<?php
function video_install() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
db_query("CREATE TABLE {video} (\n vid int(10) unsigned NOT NULL default '0',\n nid int(10) unsigned NOT NULL default '0',\n vtype varchar(32) NOT NULL default '',\n vidfile text NOT NULL default '',\n videox smallint(4) unsigned NOT NULL default '0',\n videoy smallint(4) unsigned NOT NULL default '0',\n size bigint(13) unsigned default NULL,\n download_counter int(10) unsigned NOT NULL default '0',\n play_counter int(10) unsigned NOT NULL default '0',\n video_bitrate int(10) unsigned default NULL,\n audio_bitrate int(10) unsigned default NULL,\n audio_sampling_rate int(10) unsigned default NULL,\n audio_channels enum('','5.1','stereo','mono') default NULL,\n playtime_seconds int(10) unsigned default NULL,\n download_folder varchar(255) NULL default NULL,\n disable_multidownload tinyint(1) unsigned NOT NULL default '0',\n use_play_folder tinyint(1) unsigned NOT NULL default '0',\n serialized_data text NULL default NULL,\n PRIMARY KEY (vid)\n ) TYPE=MyISAM COMMENT='size is in bytes' /*!40100 DEFAULT CHARACTER SET utf8 */;");
break;
case 'pgsql':
db_query("CREATE TABLE {video} (\n vid integer NOT NULL default '0',\n nid integer NOT NULL default '0',\n vtype varchar(32) NOT NULL default '',\n vidfile text NOT NULL default '',\n videox smallint NOT NULL default '0',\n videoy smallint NOT NULL default '0',\n size bigint default NULL,\n download_counter integer NOT NULL default '0',\n play_counter integer NOT NULL default '0',\n video_bitrate integer default NULL,\n audio_bitrate integer default NULL,\n audio_sampling_rate integer default NULL,\n audio_channels varchar(10) default NULL,\n playtime_seconds integer default NULL,\n download_folder varchar(255) NULL default NULL,\n disable_multidownload smallint NOT NULL default '0',\n use_play_folder smallint NOT NULL default '0',\n serialized_data text NULL default NULL,\n PRIMARY KEY (vid)\n );");
}
variable_set('video_resolution_1_name', '4:3 - Television');
variable_set('video_resolution_1_value', '400x300');
variable_set('video_resolution_2_name', '16:9 - Widescreen');
variable_set('video_resolution_2_value', '400x226');
}
function video_uninstall() {
db_query('DROP TABLE {video}');
variable_del('video_resolution_1_name');
variable_del('video_resolution_1_value');
variable_del('video_resolution_2_name');
variable_del('video_resolution_2_value');
}
function video_update_1() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {video} CHANGE videox videox smallint(4) NOT NULL default '0'");
$ret[] = update_sql("ALTER TABLE {video} CHANGE videoy videoy smallint(4) NOT NULL default '0'");
$ret[] = update_sql('ALTER TABLE {video} CHANGE size size bigint(13) default NULL');
$ret[] = update_sql('ALTER TABLE {video} ADD video_bitrate int(11) default NULL');
$ret[] = update_sql('ALTER TABLE {video} ADD audio_bitrate int(11) default NULL');
$ret[] = update_sql('ALTER TABLE {video} ADD audio_sampling_rate int(11) default NULL');
$ret[] = update_sql("ALTER TABLE {video} ADD audio_channels enum('','stereo','mono') default NULL");
$ret[] = update_sql('ALTER TABLE {video} ADD playtime_seconds int(11) default NULL');
}
return $ret;
}
function video_update_2() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {video} CHANGE clicks download_counter int(10) unsigned NOT NULL default '0'");
$ret[] = update_sql("ALTER TABLE {video} ADD play_counter int(10) unsigned NOT NULL default '0' AFTER download_counter");
$ret[] = update_sql("ALTER TABLE {video} CHANGE audio_channels audio_channels enum('','5.1','stereo','mono') default NULL");
$ret[] = update_sql('ALTER TABLE {video} ADD download_folder varchar(255) NULL default NULL');
$ret[] = update_sql("ALTER TABLE {video} ADD disable_multidownload tinyint(1) NOT NULL default '0'");
$ret[] = update_sql("ALTER TABLE {video} ADD use_play_folder tinyint(1) NOT NULL default '0'");
$ret[] = update_sql('ALTER TABLE {video} ADD custom_field_1 varchar(255) NULL default NULL');
$ret[] = update_sql('ALTER TABLE {video} ADD custom_field_2 varchar(255) NULL default NULL');
$ret[] = update_sql('ALTER TABLE {video} ADD custom_field_3 varchar(255) NULL default NULL');
$ret[] = update_sql('ALTER TABLE {video} ADD custom_field_4 varchar(255) NULL default NULL');
$ret[] = update_sql('ALTER TABLE {video} ADD custom_field_5 text NULL default NULL');
$ret[] = update_sql('ALTER TABLE {video} ADD custom_field_6 text NULL default NULL');
}
return $ret;
}
function video_update_3() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {video} CHANGE videox videox smallint(4) unsigned NOT NULL default '0'");
$ret[] = update_sql("ALTER TABLE {video} CHANGE videoy videoy smallint(4) unsigned NOT NULL default '0'");
$ret[] = update_sql('ALTER TABLE {video} CHANGE size size bigint(13) unsigned default NULL');
$ret[] = update_sql('ALTER TABLE {video} CHANGE video_bitrate video_bitrate int(11) unsigned default NULL');
$ret[] = update_sql('ALTER TABLE {video} CHANGE audio_bitrate audio_bitrate int(11) unsigned default NULL');
$ret[] = update_sql('ALTER TABLE {video} CHANGE audio_sampling_rate audio_sampling_rate int(11) unsigned default NULL');
$ret[] = update_sql('ALTER TABLE {video} CHANGE playtime_seconds playtime_seconds int(11) unsigned default NULL');
$ret[] = update_sql("ALTER TABLE {video} CHANGE disable_multidownload disable_multidownload tinyint(1) unsigned NOT NULL default '0'");
$ret[] = update_sql("ALTER TABLE {video} CHANGE use_play_folder use_play_folder tinyint(1) unsigned NOT NULL default '0'");
}
return $ret;
}
function video_update_4() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$ret[] = update_sql("ALTER TABLE {video} ADD vid int(10) unsigned NOT NULL default '0' FIRST");
$ret[] = update_sql('UPDATE {video} SET vid = nid');
$ret[] = update_sql('ALTER TABLE {video} CHANGE video_bitrate video_bitrate int(10) unsigned default NULL');
$ret[] = update_sql('ALTER TABLE {video} CHANGE audio_bitrate audio_bitrate int(10) unsigned default NULL');
$ret[] = update_sql('ALTER TABLE {video} CHANGE audio_sampling_rate audio_sampling_rate int(10) unsigned default NULL');
$ret[] = update_sql('ALTER TABLE {video} CHANGE playtime_seconds playtime_seconds int(10) unsigned default NULL');
$ret[] = update_sql('ALTER TABLE {video} ADD serialized_data text NULL default NULL');
$ret[] = update_sql('ALTER TABLE {video} DROP PRIMARY KEY, ADD PRIMARY KEY ( `vid` )');
}
return $ret;
}
function video_update_5() {
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
case 'pgsql':
$ret[] = update_sql("ALTER TABLE {video} ADD vtype varchar(32) NOT NULL default ''");
}
return $ret;
}
function _video_update_6_get_vtype($node) {
$file_type = '';
$vidfile = $node->vidfile;
if (!strpos($vidfile, '.') and !strpos($vidfile, '/') and !strpos($vidfile, '\\') and strlen($vidfile) == 11) {
$file_type = 'youtube';
}
else {
if (strpos($vidfile, 'google:') === 0) {
$file_type = 'google';
}
else {
if (db_result(db_query("SELECT count(fid) FROM {files} WHERE nid=%d", $node->nid)) > 0) {
$file_type = 'upload';
}
else {
if ($vidfile != '') {
$file_type = 'url';
}
else {
drupal_set_message(t('Could not determine video type of node %nid', array(
'%nid' => $node->nid,
)), 'error');
}
}
}
}
return $file_type;
}
function video_update_6() {
$videos = db_query("SELECT nid,vidfile FROM {video} WHERE vtype=''");
while ($video = db_fetch_object($videos)) {
db_query("UPDATE {video} SET vtype='%s' WHERE nid=%d", _video_update_6_get_vtype($video), $video->nid);
}
return array();
}
function video_update_7() {
variable_set('video_resolution_1_name', '4:3 - Television');
variable_set('video_resolution_1_value', '400x300');
variable_set('video_resolution_2_name', '16:9 - Widescreen');
variable_set('video_resolution_2_value', '400x226');
return array();
}
function video_update_8() {
$vnodes = db_query("SELECT n.nid,n.vid,serialized_data FROM {node} n INNER JOIN {video} v on n.nid = v.nid WHERE n.type = 'video' AND v.vtype = 'upload' AND v.serialized_data NOT LIKE '%video_fid%'");
while ($node = db_fetch_object($vnodes)) {
if ($node->vid) {
$result = db_query('SELECT * FROM {files} f INNER JOIN {file_revisions} r ON f.fid = r.fid WHERE r.vid = %d ORDER BY f.fid DESC', $node->vid);
if (!$result) {
continue;
}
$result = db_fetch_object($result);
$data = unserialize($node->serialized_data);
$data['video_fid'] = $result->fid;
$data = serialize($data);
$res = db_query("UPDATE {video} SET serialized_data='%s' WHERE nid=%d", $data, $node->nid);
}
}
return array();
}
function video_update_9() {
$res[] = update_sql("UPDATE {video} SET vidfile=CONCAT('http://www.youtube.com/watch?v=',vidfile) WHERE vtype='youtube' AND vidfile NOT LIKE '%youtube.com/watch%'");
return $res;
}
function video_update_10() {
$res[] = update_sql("UPDATE {video} SET vidfile=CONCAT('http://video.google.com/videoplay?docid=',SUBSTR(vidfile,8)) WHERE vtype='google' AND vidfile LIKE 'google:%'");
return $res;
}
function video_update_11() {
$res[] = update_sql('ALTER TABLE {video} DROP custom_field_1');
$res[] = update_sql('ALTER TABLE {video} DROP custom_field_2');
$res[] = update_sql('ALTER TABLE {video} DROP custom_field_3');
$res[] = update_sql('ALTER TABLE {video} DROP custom_field_4');
$res[] = update_sql('ALTER TABLE {video} DROP custom_field_5');
$res[] = update_sql('ALTER TABLE {video} DROP custom_field_6');
return $res;
}