summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Brachold <vdr07@deltab.de>2008-04-02 19:19:40 +0000
committerAndreas Brachold <vdr07@deltab.de>2008-04-02 19:19:40 +0000
commitda1b58f40422afe179307673e64bb04b4ce182c4 (patch)
treec84c414a7e5865a302d121fba8fc430f674d112c
parent0693cbbd82f182dedca795c0b2660ae08f4a0108 (diff)
downloadxxv-da1b58f40422afe179307673e64bb04b4ce182c4.tar.gz
xxv-da1b58f40422afe179307673e64bb04b4ce182c4.tar.bz2
* CHANNELS: Read data via SVDRP (drop direct reading channels.conf)
* CHANNELS: Change layout of CHANNELSGROUPS avoid floating id * MUSIC: Use mysql_enable_utf8 to connect GiantDisc database if enabled * HTTPD: Use now String::Escape to ellipsis strings at word boundary (avoid UTF-8 cutting) * Some: Remove warning if'nt {cgi}->param('limit') not defined
-rwxr-xr-xinstall-debian.sh3
-rwxr-xr-xinstall.sh1
-rw-r--r--lib/Bundle/Xxv.pm1
-rw-r--r--lib/XXV/MODULES/AUTOTIMER.pm2
-rw-r--r--lib/XXV/MODULES/CHANNELS.pm89
-rw-r--r--lib/XXV/MODULES/EPG.pm19
-rw-r--r--lib/XXV/MODULES/MUSIC.pm18
-rw-r--r--lib/XXV/MODULES/RECORDS.pm6
-rw-r--r--lib/XXV/MODULES/TIMERS.pm2
-rw-r--r--lib/XXV/OUTPUT/Html.pm16
10 files changed, 96 insertions, 61 deletions
diff --git a/install-debian.sh b/install-debian.sh
index f5be4c9..07a747b 100755
--- a/install-debian.sh
+++ b/install-debian.sh
@@ -54,7 +54,8 @@ apt-get install \
libhtml-template-perl \
liburi-perl \
libxml-rss-perl \
- libxml-simple-perl
+ libxml-simple-perl \
+ libstring-escape-perl
echo 'start mysql server'
/etc/init.d/mysql start
diff --git a/install.sh b/install.sh
index 182d9ca..5fd3bce 100755
--- a/install.sh
+++ b/install.sh
@@ -152,6 +152,7 @@ perlModules()
checkPerlModule Proc::ProcessTable
checkPerlModule SOAP::Lite
checkPerlModule SOAP::Transport::HTTP
+ checkPerlModule String::Escape
checkPerlModule Template
checkPerlModule Time::Local
checkPerlModule Time::HiRes
diff --git a/lib/Bundle/Xxv.pm b/lib/Bundle/Xxv.pm
index aa1be5c..f02c88b 100644
--- a/lib/Bundle/Xxv.pm
+++ b/lib/Bundle/Xxv.pm
@@ -50,6 +50,7 @@ Proc::Killfam
Proc::ProcessTable
SOAP::Lite
SOAP::Transport::HTTP
+String::Escape
Template
Time::Local
Time::HiRes
diff --git a/lib/XXV/MODULES/AUTOTIMER.pm b/lib/XXV/MODULES/AUTOTIMER.pm
index ab25359..74617ab 100644
--- a/lib/XXV/MODULES/AUTOTIMER.pm
+++ b/lib/XXV/MODULES/AUTOTIMER.pm
@@ -1188,7 +1188,7 @@ sub list {
my $rows;
my $sth;
- my $limit = CORE::int($console->{cgi} ? $console->{cgi}->param('limit') : 0);
+ my $limit = $console->{cgi} && $console->{cgi}->param('limit') ? CORE::int($console->{cgi}->param('limit')) : 0;
if($limit > 0) {
# Query total count of rows
my $rsth = $obj->{dbh}->prepare($sql);
diff --git a/lib/XXV/MODULES/CHANNELS.pm b/lib/XXV/MODULES/CHANNELS.pm
index c68676f..c7cbce1 100644
--- a/lib/XXV/MODULES/CHANNELS.pm
+++ b/lib/XXV/MODULES/CHANNELS.pm
@@ -3,7 +3,6 @@ package XXV::MODULES::CHANNELS;
use strict;
use Tools;
-use File::stat;
# This module method must exist for XXV
# ------------------
@@ -13,6 +12,7 @@ sub module {
my $args = {
Name => 'CHANNELS',
Prereq => {
+ 'Digest::MD5 qw(md5_hex)' => 'Perl interface to the MD5 Algorithm',
},
Description => gettext('This module reads new channels and stores them in the database.'),
Version => (split(/ /, '$Revision$'))[1],
@@ -21,12 +21,6 @@ sub module {
LastAuthor => (split(/ /, '$Author$'))[1],
Status => sub{ $obj->status(@_) },
Preferences => {
- file => {
- description => sprintf(gettext("Path of file '%s'"),'channels.conf'),
- default => '/var/lib/vdr/channels.conf',
- type => 'file',
- required => gettext('This is required!'),
- },
interval => {
description => gettext('How often channels are to be updated (in seconds)'),
default => 3 * 60 * 60,
@@ -196,11 +190,13 @@ sub _init {
return 0;
}
- my $version = 26; # Must be increment if rows of table changed
+ my $version = 27; # Must be increment if rows of table changed
# this tables hasen't handmade user data,
# therefore old table could dropped if updated rows
- if(!tableUpdated($obj->{dbh},'CHANNELS',$version,1)
- || !tableUpdated($obj->{dbh},'CHANNELGROUPS',$version,1)) {
+ if(!tableUpdated($obj->{dbh},'CHANNELS',$version,1)) {
+ return 0;
+ }
+ if(!tableUpdated($obj->{dbh},'CHANNELGROUPS',$version,1)) {
return 0;
}
@@ -229,9 +225,8 @@ sub _init {
$obj->{dbh}->do(qq|
CREATE TABLE IF NOT EXISTS CHANNELGROUPS (
- Id int(11) auto_increment not NULL,
+ Id int(11) not NULL,
Name varchar(100) default 'unknown',
- Counter int(11) default '0',
PRIMARY KEY (Id)
) COMMENT = '$version'
|);
@@ -335,10 +330,10 @@ sub insertGrp {
my $name = shift || 0;
lg sprintf('Add new group of channels "%s".', $name);
- my $sth = $obj->{dbh}->prepare('INSERT INTO CHANNELGROUPS SET Name=?, Counter=?');
+ my $sth = $obj->{dbh}->prepare('REPLACE INTO CHANNELGROUPS SET Name=?, Id=?');
$sth->execute($name, $pos)
or return error sprintf("Couldn't execute query: %s.",$sth->errstr);
- return $sth->{mysql_insertid};
+ return $pos;
}
# ------------------
@@ -347,43 +342,55 @@ sub readData {
my $obj = shift || return error('No object defined!');
my $watcher = shift;
my $console = shift;
- my $file = $obj->{file} || return error ('No Channels File');
- return con_err($console, sprintf(gettext("Couldn't find channels.conf as file '%s'!"),$file)) if( ! -e $file);
+ # Read channels over SVDRP
+ my $lstc = $obj->{svdrp}->command('lstc :groups');
+ my $vdata = [ grep(/^250/, @$lstc) ];
+
+ unless(scalar @$vdata) {
+ # Delete old Records
+ $obj->{dbh}->do('DELETE FROM CHANNELS');
+ $obj->{dbh}->do('DELETE FROM CHANNELGROUPS');
+
+ my $msg = gettext('No channels available!');
+ con_err($console,$msg);
+ return;
+ }
- # only if file modification from last read time
- my $mtime = (stat($file)->mtime);
+ my $md5sum = md5_hex(@$vdata);
+ # only if channels modified
return
- if(! ref $console and defined $obj->{LastRefreshTime} and ($mtime > $obj->{LastRefreshTime}));
+ if(! ref $console and defined $obj->{LastMD5Sum} and ($md5sum ne $obj->{LastMD5Sum}));
+ $obj->{LastMD5Sum} = $md5sum;
$obj->{dbh}->do('DELETE FROM CHANNELS');
$obj->{dbh}->do('DELETE FROM CHANNELGROUPS');
- my $fh = IO::File->new("< $file") or return con_err($console, sprintf(gettext("Couldn't open file '%s'! : %s"),$file,$!));
my $c = 0;
my $nPos = 1;
my $grp = 0;
- while ( defined (my $line = <$fh>) ) {
- $line =~ s/[\r|\n]//sig;
- next if($line eq "");
- my @data = split(':', $line, 13);
- $data[-1] = (split(':', $data[-1]))[0];
+ my $channelText;
+ my $grpText;
- if( $line =~ /^\:\@(\d*)\s*(.*)/ and $nPos <= $1) {
- $nPos = $1;
- my $grpText = $2;
- $grp = $obj->insertGrp($nPos, $grpText);
- } elsif( $line =~ /^\:(.+)/) {
- my $grpText = $1;
+ foreach my $line (@{$vdata}) {
+
+ next if($line eq "");
+ if($line =~ /250[\-|\s]0\s/) { # Channels groups
+ ($nPos, $grpText)
+ = $line =~ /^250[\-|\s]0\s\:\@(\d+)\s(.+)/si;
$grp = $obj->insertGrp($nPos, $grpText);
- } else {
- $grp = $obj->insertGrp(1, gettext("Channels"))
- if(!$grp);
- $c++
- if(scalar @data > 4 && $obj->insert(\@data, $nPos++, $grp));
+ } else {
+ # Insert dummy group
+ $grp = $obj->insertGrp(1, gettext("Channels")) if(!$grp);
+
+ ($nPos, $channelText)
+ = $line =~ /^250[\-|\s](\d+)\s(.+)/si;
+ my @data = split(':', $channelText, 13);
+ $data[-1] = (split(':', $data[-1]))[0];
+
+ $c++ if(scalar @data > 4 && $obj->insert(\@data, $nPos++, $grp));
}
}
- $fh->close;
# Cool we have new Channels!
my $LastChannel = $obj->_LastChannel;
@@ -404,7 +411,6 @@ sub readData {
} else {
$a cmp $b } } keys %CA;
- $obj->{LastRefreshTime} = $mtime;
return 1;
}
# ------------------
@@ -496,7 +502,8 @@ ORDER BY
if(exists $params->{desc} && $params->{desc} == 1);
my $rows;
- if($console->{cgi} && $console->{cgi}->param('limit')) {
+ my $limit = $console->{cgi} && $console->{cgi}->param('limit') ? CORE::int($console->{cgi}->param('limit')) : 0;
+ if($limit > 0) {
# Query total count of rows
my $rsth = $obj->{dbh}->prepare($sql);
$rsth->execute('%'.$id.'%')
@@ -506,9 +513,9 @@ ORDER BY
# Add limit query
if($console->{cgi}->param('start')) {
$sql .= " LIMIT " . CORE::int($console->{cgi}->param('start'));
- $sql .= "," . CORE::int($console->{cgi}->param('limit'));
+ $sql .= "," . $limit;
} else {
- $sql .= " LIMIT " . CORE::int($console->{cgi}->param('limit'));
+ $sql .= " LIMIT " . $limit;
}
}
diff --git a/lib/XXV/MODULES/EPG.pm b/lib/XXV/MODULES/EPG.pm
index 64f633f..c15ac20 100644
--- a/lib/XXV/MODULES/EPG.pm
+++ b/lib/XXV/MODULES/EPG.pm
@@ -714,7 +714,7 @@ sub search {
|;
my $sth;
- my $limit = CORE::int($console->{cgi} ? $console->{cgi}->param('limit') : 0);
+ my $limit = $console->{cgi} && $console->{cgi}->param('limit') ? CORE::int($console->{cgi}->param('limit')) : 0;
if($limit > 0) {
# Query total count of rows
my $rsth = $obj->{dbh}->prepare($sql);
@@ -838,7 +838,7 @@ order by
my $rows;
my $sth;
- my $limit = CORE::int($console->{cgi} ? $console->{cgi}->param('limit') : 0);
+ my $limit = $console->{cgi} && $console->{cgi}->param('limit') ? CORE::int($console->{cgi}->param('limit')) : 0;
if($limit > 0) {
# Query total count of rows
my $rsth = $obj->{dbh}->prepare($sql);
@@ -1065,7 +1065,12 @@ ORDER BY
or return con_err($console, sprintf("Couldn't execute query: %s.",$sth->errstr));
my $fields = $sth->{'NAME'};
my $erg = $sth->fetchall_arrayref();
- unshift(@$erg, $fields);
+ unless($console->typ eq 'AJAX') {
+# map {
+# $_->[5] = datum($_->[5],'short');
+# } @$erg;
+ unshift(@$erg, $fields);
+ }
$console->table($erg,
{
@@ -1152,7 +1157,13 @@ ORDER BY
or return con_err($console, sprintf("Couldn't execute query: %s.",$sth->errstr));
my $fields = $sth->{'NAME'};
my $erg = $sth->fetchall_arrayref();
- unshift(@$erg, $fields);
+
+ unless($console->typ eq 'AJAX') {
+# map {
+# $_->[5] = datum($_->[5],'short');
+# } @$erg;
+ unshift(@$erg, $fields);
+ }
$console->table($erg,
{
diff --git a/lib/XXV/MODULES/MUSIC.pm b/lib/XXV/MODULES/MUSIC.pm
index 807e298..afe6e61 100644
--- a/lib/XXV/MODULES/MUSIC.pm
+++ b/lib/XXV/MODULES/MUSIC.pm
@@ -163,6 +163,8 @@ sub new {
# paths
$self->{paths} = delete $attr{'-paths'};
+ $self->{charset} = delete $attr{'-charset'};
+
# who am I
$self->{MOD} = $self->module;
@@ -1157,6 +1159,22 @@ sub ConnectToMuggleDB {
AutoCommit => 1,
}) || error($DBI::errstr);
if($mdbh) {
+ my $charset = $obj->{charset};
+ if ($charset) {
+ my $NAMES = {
+ 'UTF-8' => 'utf8',
+ 'ISO-8859-1' => 'latin1',
+ 'ISO-8859-2' => 'latin2',
+ 'ISO-8859-5' => 'latin5',
+ 'ISO-8859-7' => 'latin7',
+ 'ISO-8859-15' => 'latin1',
+ };
+ my $n = $NAMES->{$charset} || 'latin1';
+ if (!($mdbh->do("SET NAMES '" . $n . "'"))) {
+ panic sprintf("Could not set charset: %s :", $n, $DBI::errstr);
+ }
+ $mdbh->{'mysql_enable_utf8'} = 1 if($n eq 'utf8');
+ }
$mdbh->{InactiveDestroy} = 1;
$mdbh->{mysql_auto_reconnect} = 1;
debug sprintf('Connect to database: %s successful.', $dsn);
diff --git a/lib/XXV/MODULES/RECORDS.pm b/lib/XXV/MODULES/RECORDS.pm
index f573675..13505c7 100644
--- a/lib/XXV/MODULES/RECORDS.pm
+++ b/lib/XXV/MODULES/RECORDS.pm
@@ -370,7 +370,7 @@ sub _notify_readData {
my $e = shift;
lg sprintf "notify events for %s:%d received: %x", $e->fullname, $e->cookie, $e->mask;
- if((time - $obj->{lastupdate}) > 15 # Only if last update prior 15 seconds (avoid callback chill)
+ if((time - $obj->{lastupdate}) > 3 # Only if last update prior 3 seconds (avoid callback chill)
&& $obj->readData()) {
$obj->{lastupdate} = time;
@@ -1613,7 +1613,7 @@ ORDER BY __IsRecording asc,
my $rows;
my $sth;
- my $limit = CORE::int($console->{cgi} ? $console->{cgi}->param('limit') : 0);
+ my $limit = $console->{cgi} && $console->{cgi}->param('limit') ? CORE::int($console->{cgi}->param('limit')) : 0;
if($limit > 0) {
# Query total count of rows
my $rsth = $obj->{dbh}->prepare($sql);
@@ -1722,7 +1722,7 @@ ORDER BY
my $rows;
my $sth;
- my $limit = CORE::int($console->{cgi} ? $console->{cgi}->param('limit') : 0);
+ my $limit = $console->{cgi} && $console->{cgi}->param('limit') ? CORE::int($console->{cgi}->param('limit')) : 0;
if($limit > 0) {
# Query total count of rows
my $rsth = $obj->{dbh}->prepare($sql);
diff --git a/lib/XXV/MODULES/TIMERS.pm b/lib/XXV/MODULES/TIMERS.pm
index a928013..ef28a4d 100644
--- a/lib/XXV/MODULES/TIMERS.pm
+++ b/lib/XXV/MODULES/TIMERS.pm
@@ -1269,7 +1269,7 @@ ORDER BY
my $rows;
my $sth;
- my $limit = CORE::int($console->{cgi} ? $console->{cgi}->param('limit') : 0);
+ my $limit = $console->{cgi} && $console->{cgi}->param('limit') ? CORE::int($console->{cgi}->param('limit')) : 0;
if($limit > 0) {
# Query total count of rows
my $rsth = $obj->{dbh}->prepare($sql);
diff --git a/lib/XXV/OUTPUT/Html.pm b/lib/XXV/OUTPUT/Html.pm
index bab6f6a..235fe06 100644
--- a/lib/XXV/OUTPUT/Html.pm
+++ b/lib/XXV/OUTPUT/Html.pm
@@ -24,6 +24,7 @@ sub module {
# 'Template' => 'Front-end module to the Template Toolkit',
# 'Compress::Zlib' => 'Interface to zlib compression library',
'HTML::TextToHTML' => 'convert plain text file to HTML. ',
+ 'String::Escape qw(elide)' => 'Registry of string functions, including backslash escapes'
},
Description => gettext('This receives and sends HTML messages.'),
Version => (split(/ /, '$Revision$'))[1],
@@ -234,22 +235,18 @@ sub parseTemplateFile {
my @lines;
foreach my $line (@text)
{
- if ( length( $line ) > $c ) {
- $line = substr( $line, 0, ( $c - 3 ) ) . '...';
- }
+ $line = elide( $line,$c );
--$l;
last if($l < 0);
push(@lines,$line);
}
$s = join("\r\n",@lines);
} else {
- if ( length( $s ) > ($c * $l) ) {
- $s = substr( $s, 0, ( ($c * $l) - 3 ) ) . '...';
- }
+ $s = elide( $s,($c * $l) );
}
}
- elsif ( length( $s ) > $c ) {
- $s = substr( $s, 0, ( $c - 3 ) ) . '...';
+ else {
+ $s = elide($s,$c);
}
return entities($s);
} else {
@@ -264,8 +261,7 @@ sub parseTemplateFile {
# value for truncate are optional
gettext => sub{
my $t = gettext($_[0]);
- $t = substr($t,0,$_[1]) . "..."
- if(defined $_[1] && length($t)>$_[1]);
+ $t = elide( $t, $_[1] ) if(defined $_[1]);
return entities($t);
},
version => sub{ return main::getVersion },