add user password reset, add series image switch, add image licences, redesign exclude filters
This commit is contained in:
@@ -271,6 +271,7 @@ sub show_login_form{
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<style type="text/css">
|
||||
html,body{
|
||||
|
||||
@@ -46,6 +46,8 @@ sub setAttributesFromSeriesTemplate{
|
||||
){
|
||||
$event->{$attr}=$serie->{$attr};
|
||||
}
|
||||
$event->{series_image} = $serie->{image};
|
||||
$event->{series_image_label} = $serie->{licence};
|
||||
return $serie;
|
||||
}
|
||||
|
||||
@@ -97,7 +99,7 @@ sub setAttributesFromOtherEvent{
|
||||
event_id => $params->{source_event_id}
|
||||
});
|
||||
if (defined $event2){
|
||||
for my $attr ('title', 'user_title', 'excerpt', 'user_excerpt', 'content', 'html_content', 'topics', 'image', 'live', 'no_event_sync', 'podcast_url', 'archive_url'){
|
||||
for my $attr ('title', 'user_title', 'excerpt', 'user_excerpt', 'content', 'html_content', 'topics', 'image', 'series_image', 'live', 'no_event_sync', 'podcast_url', 'archive_url', 'image_label', 'series_image_label'){
|
||||
$event->{$attr}=$event2->{$attr};
|
||||
}
|
||||
$event->{rerun}=1;
|
||||
|
||||
@@ -246,20 +246,20 @@ sub modify_results {
|
||||
$result->{no_comment} = 1 if ( $result->{comment_count} == 0 );
|
||||
|
||||
#fix image url
|
||||
|
||||
if ((defined $config->{permissions}->{hide_event_images}) && ($config->{permissions}->{hide_event_images} eq '1')){
|
||||
$result->{image} = $result->{series_image};
|
||||
$result->{image_label} = $result->{series_image_label};
|
||||
}
|
||||
|
||||
if ( defined $result->{image} ) {
|
||||
$result->{thumb} = $result->{image};
|
||||
$result->{icon} = $result->{image};
|
||||
|
||||
$result->{image} =~ s/thumbs/images/g;
|
||||
$result->{image} =~ s/icons/images/g;
|
||||
|
||||
#fix thumbs url
|
||||
$result->{thumb} =~ s/images/thumbs/s;
|
||||
$result->{thumb} =~ s/icons/thumbs/s;
|
||||
|
||||
#fix icon url
|
||||
$result->{icon} =~ s/thumbs/icons/s;
|
||||
$result->{icon} =~ s/images/icons/s;
|
||||
my $url=$config->{locations}->{local_media_url}||'';
|
||||
if (defined $result->{image}){
|
||||
my $image=$result->{image};
|
||||
$result->{thumb} = $url.'/thumbs/'.$image;
|
||||
$result->{icon} = $url.'/icons/'.$image;
|
||||
$result->{image} = $url.'/images/'.$image;
|
||||
}
|
||||
}
|
||||
|
||||
$result->{location_css} = $result->{location} || '';
|
||||
@@ -1019,6 +1019,9 @@ sub get_query {
|
||||
,e.modified_by
|
||||
,e.comment_count
|
||||
,e.image
|
||||
,e.image_label
|
||||
,e.series_image
|
||||
,e.series_image_label
|
||||
,e.reference
|
||||
,e.recurrence
|
||||
,e.recurrence_count
|
||||
|
||||
@@ -16,7 +16,7 @@ our %EXPORT_TAGS = ( 'all' => [ @EXPORT_OK ] );
|
||||
|
||||
#column 'created_at' will be set at insert
|
||||
#column 'modified_at' will be set by default (do not update)
|
||||
my $sql_columns =['filename', 'name', 'description', 'created_by', 'modified_by', 'modified_at', 'studio_id', 'project_id'];
|
||||
my $sql_columns =['filename', 'name', 'description', 'created_by', 'modified_by', 'modified_at', 'studio_id', 'project_id', 'public', 'licence'];
|
||||
|
||||
sub get{
|
||||
my $config=shift;
|
||||
@@ -52,6 +52,15 @@ sub get{
|
||||
push @cond, 'modified_by = ?';
|
||||
push @$bind_values,$options->{modified_by};
|
||||
}
|
||||
if ((defined $options->{licence}) && ($options->{licence}ne'')){
|
||||
push @cond, 'licence = ?';
|
||||
push @$bind_values,$options->{licence};
|
||||
}
|
||||
if ((defined $options->{public}) && ($options->{public}ne'')){
|
||||
push @cond, 'public = ?';
|
||||
push @$bind_values,$options->{public};
|
||||
}
|
||||
|
||||
if ((defined $options->{search}) && ($options->{search}ne'')){
|
||||
push @cond, '(filename like ?'
|
||||
.' or name like ?'
|
||||
@@ -85,8 +94,8 @@ sub get{
|
||||
};
|
||||
#print STDERR Dumper($query).Dumper($bind_values);
|
||||
|
||||
my $dbh=db::connect($config);
|
||||
my $results=db::get($dbh, $query, $bind_values);
|
||||
my $dbh = db::connect($config);
|
||||
my $results = db::get($dbh, $query, $bind_values);
|
||||
|
||||
#print STDERR @$results."\n";
|
||||
return $results;
|
||||
@@ -96,8 +105,8 @@ sub insert_or_update{
|
||||
my $dbh=shift;
|
||||
my $image=shift;
|
||||
|
||||
$image->{name}='new' if ($image->{name}eq'');
|
||||
my $entry=get_by_filename($dbh, $image->{filename});
|
||||
$image->{name} = 'new' if $image->{name} eq '' ;
|
||||
my $entry = get_by_filename($dbh, $image->{filename});
|
||||
if (defined $entry){
|
||||
update($dbh, $image);
|
||||
}else{
|
||||
@@ -128,6 +137,10 @@ sub insert{
|
||||
return undef;
|
||||
}
|
||||
|
||||
for my $attr ('public'){
|
||||
$image->{$attr} = 0 unless (defined $image->{$attr}) && ($image->{$attr} eq '1');
|
||||
}
|
||||
|
||||
my $query=q{
|
||||
insert into calcms_images(
|
||||
}.join(',',@sql_columns).qq{
|
||||
@@ -137,7 +150,12 @@ sub insert{
|
||||
my @bind_values=map { $image->{$_} } @sql_columns;
|
||||
|
||||
#print STDERR Dumper($query).Dumper(\@bind_values);
|
||||
return db::put($dbh, $query, \@bind_values);
|
||||
my $result = db::put($dbh, $query, \@bind_values);
|
||||
|
||||
images::setSeriesLabels($dbh, $image);
|
||||
images::setEventLabels($dbh, $image);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
@@ -153,9 +171,17 @@ sub update{
|
||||
print STDERR "missing project_id at image::update\n";
|
||||
return undef;
|
||||
}
|
||||
unless (defined $image->{filename}){
|
||||
print STDERR "missing filename at image::update\n";
|
||||
return undef;
|
||||
}
|
||||
|
||||
$image->{modified_at}=time::time_to_datetime();
|
||||
|
||||
for my $attr ('public'){
|
||||
$image->{$attr} = 0 unless (defined $image->{$attr}) && ($image->{$attr} eq '1');
|
||||
}
|
||||
|
||||
my @set=();
|
||||
my $bind_values=[];
|
||||
for my $column (@$sql_columns){
|
||||
@@ -164,7 +190,7 @@ sub update{
|
||||
push @$bind_values,$image->{$column};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#conditions
|
||||
my $conditions=['filename=?'];
|
||||
push @$bind_values,$image->{filename};
|
||||
@@ -184,10 +210,16 @@ sub update{
|
||||
set $set
|
||||
where $conditions
|
||||
};
|
||||
#print STDERR Dumper($query).Dumper($bind_values);
|
||||
return db::put($dbh,$query,$bind_values);
|
||||
print STDERR Dumper($query).Dumper($bind_values);
|
||||
my $result= db::put($dbh,$query,$bind_values);
|
||||
|
||||
images::setSeriesLabels($dbh, $image);
|
||||
images::setEventLabels($dbh, $image);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
sub delete{
|
||||
my $dbh=shift;
|
||||
my $image=shift;
|
||||
@@ -196,8 +228,8 @@ sub delete{
|
||||
print STDERR "missing project_id at images::delete\n";
|
||||
return undef;
|
||||
}
|
||||
unless (defined $image->{project_id}){
|
||||
print STDERR "missing project_id at images::delete\n";
|
||||
unless (defined $image->{studio_id}){
|
||||
print STDERR "missing studio_id at images::delete\n";
|
||||
return undef;
|
||||
}
|
||||
unless (defined $image->{filename}){
|
||||
@@ -292,6 +324,206 @@ sub delete_file{
|
||||
}
|
||||
}
|
||||
|
||||
sub getPath{
|
||||
my $config=shift;
|
||||
my $options=shift;
|
||||
|
||||
my $dir = $config->{locations}->{local_media_dir};
|
||||
return undef unless defined $dir;
|
||||
return undef unless -e $dir;
|
||||
|
||||
my $filename=$options->{filename};
|
||||
return undef unless defined $filename;
|
||||
$filename=~s/^.*\///g;
|
||||
|
||||
my $type='thumbs';
|
||||
$type=$options->{type} if (defined $options->{type}) && ($options->{type}=~/^(images|thumbs|icons)$/);
|
||||
|
||||
my $path = $dir.'/'.$type.'/'.$filename;
|
||||
$path=~s/\/+/\//g;
|
||||
return $path;
|
||||
}
|
||||
|
||||
sub getInternalPath{
|
||||
my $config=shift;
|
||||
my $options=shift;
|
||||
|
||||
my $dir=$config->{locations}->{local_media_dir};
|
||||
return undef unless defined $dir;
|
||||
return undef unless -e $dir;
|
||||
|
||||
my $filename=$options->{filename};
|
||||
return undef unless defined $filename;
|
||||
$filename=~s/^.*\///g;
|
||||
|
||||
my $type='thumbs';
|
||||
$type=$options->{type} if (defined $options->{type}) && ($options->{type}=~/^(images|thumbs|icons)$/);
|
||||
|
||||
my $path = $dir.'/internal/'.$type.'/'.$filename;
|
||||
$path=~s/\/+/\//g;
|
||||
return $path;
|
||||
}
|
||||
|
||||
sub readFile{
|
||||
my $path=shift;
|
||||
my $content='';
|
||||
|
||||
print STDERR "read '$path'\n";
|
||||
return { error=> "source '$path' does not exist"} unless -e $path;
|
||||
return { error=> "cannot read source '$path'"} unless -r $path;
|
||||
|
||||
open my $file, '< :raw', $path or return { error => 'could not open image file. ' . $! . " $path" };
|
||||
binmode $file;
|
||||
$content = join("",<$file>);
|
||||
close $file;
|
||||
return {content => $content};
|
||||
}
|
||||
|
||||
sub writeFile{
|
||||
my $path=shift;
|
||||
my $content=shift;
|
||||
|
||||
print STDERR "save '$path'\n";
|
||||
open my $fh, '> :raw', $path or return { error => 'could not save image. ' . $! . " $path" };
|
||||
binmode $fh;
|
||||
print $fh $content;
|
||||
close $fh;
|
||||
return {};
|
||||
}
|
||||
|
||||
sub deleteFile{
|
||||
my $path=shift;
|
||||
return { error=> "source '$path' does not exist"} unless -e $path;
|
||||
#unlink $path;
|
||||
return {};
|
||||
|
||||
}
|
||||
|
||||
sub copyFile{
|
||||
my $source = shift;
|
||||
my $target = shift;
|
||||
my $errors = shift;
|
||||
|
||||
my $read=images::readFile($source);
|
||||
return $read if defined $read->{error};
|
||||
|
||||
my $write=images::writeFile($target, $read->{content});
|
||||
return $write;
|
||||
}
|
||||
|
||||
sub publish{
|
||||
my $config=shift;
|
||||
my $filename=shift;
|
||||
|
||||
print STDERR "publish\n";
|
||||
return undef unless defined $config;
|
||||
return undef unless defined $filename;
|
||||
my $errors=[];
|
||||
for my $type ('images','thumbs','icons'){
|
||||
my $source = getInternalPath($config, {filename=>$filename, type=>$type});
|
||||
my $target = getPath($config, {filename=>$filename, type=>$type});
|
||||
my $result = copyFile($source, $target, $errors);
|
||||
if (defined $result->{error}){
|
||||
push @$errors, $result->{error} ;
|
||||
print STDERR "error on copy '$source' to '$target': $result->{error}\n";
|
||||
}
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
|
||||
sub depublish{
|
||||
my $config=shift;
|
||||
my $filename=shift;
|
||||
|
||||
print STDERR "depublish\n";
|
||||
return undef unless defined $config;
|
||||
return undef unless defined $filename;
|
||||
my $errors=[];
|
||||
for my $type ('images','thumbs','icons'){
|
||||
my $path = getPath($config, {filename=>$filename, type=>$type});
|
||||
next unless defined $path;
|
||||
print STDERR "remove '$path'\n";
|
||||
unlink $path;
|
||||
#push @$errors, $result->{error} if defined $result->{error};
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
|
||||
sub checkLicence{
|
||||
my $config = shift;
|
||||
my $result = shift;
|
||||
|
||||
print STDERR "depublish\n";
|
||||
return undef unless defined $config;
|
||||
return undef unless defined $result;
|
||||
|
||||
return if $result->{licence}=~/\S/;
|
||||
if ((defined $result->{public}) && ($result->{public}eq'1')){
|
||||
depublish($config, $result->{filename});
|
||||
$result->{public}=0;
|
||||
}
|
||||
}
|
||||
|
||||
sub setEventLabels{
|
||||
my $dbh = shift;
|
||||
my $image = shift;
|
||||
|
||||
unless (defined $image->{project_id}){
|
||||
print STDERR "missing project_id at images::setEventLabels\n";
|
||||
return undef;
|
||||
}
|
||||
unless (defined $image->{studio_id}){
|
||||
print STDERR "missing studio_id at images::setEventLabels\n";
|
||||
return undef;
|
||||
}
|
||||
unless (defined $image->{filename}){
|
||||
print STDERR "missing filename at images::setEventLabels\n";
|
||||
return undef;
|
||||
}
|
||||
|
||||
my $query=qq{
|
||||
update calcms_events
|
||||
set image_label=?
|
||||
where image=?
|
||||
};
|
||||
my $bind_values=[$image->{licence}, $image->{filename}];
|
||||
print STDERR Dumper($query).Dumper($bind_values);
|
||||
|
||||
my $results= db::put($dbh, $query, $bind_values);
|
||||
print STDERR Dumper($results)." changes\n";
|
||||
return $results;
|
||||
}
|
||||
|
||||
sub setSeriesLabels{
|
||||
my $dbh = shift;
|
||||
my $image = shift;
|
||||
|
||||
unless (defined $image->{project_id}){
|
||||
print STDERR "missing project_id at images::setSeriesLabels\n";
|
||||
return undef;
|
||||
}
|
||||
unless (defined $image->{studio_id}){
|
||||
print STDERR "missing studio_id at images::setSeriesLabels\n";
|
||||
return undef;
|
||||
}
|
||||
unless (defined $image->{filename}){
|
||||
print STDERR "missing filename at images::setSeriesLabels\n";
|
||||
return undef;
|
||||
}
|
||||
|
||||
my $query=qq{
|
||||
update calcms_events
|
||||
set series_image_label=?
|
||||
where series_image=?
|
||||
};
|
||||
my $bind_values=[$image->{licence}, $image->{filename}];
|
||||
print STDERR Dumper($query).Dumper($bind_values);
|
||||
|
||||
my $results= db::put($dbh, $query, $bind_values);
|
||||
print STDERR Dumper($results)." changes\n";
|
||||
return $results;
|
||||
}
|
||||
|
||||
|
||||
#do not delete last line!
|
||||
1;
|
||||
|
||||
@@ -36,7 +36,7 @@ sub get{
|
||||
return undef unless defined $condition->{studio_id};
|
||||
|
||||
my $date_range_include=0;
|
||||
$date_range_include=1 if $condition->{date_range_include}==1;
|
||||
$date_range_include=1 if (defined $condition->{date_range_include}) && ($condition->{date_range_include}==1);
|
||||
|
||||
my $dbh=db::connect($config);
|
||||
|
||||
|
||||
@@ -78,6 +78,17 @@ sub get{
|
||||
return $projects;
|
||||
}
|
||||
|
||||
# requires at least project_id
|
||||
sub getImageById{
|
||||
my $config = shift;
|
||||
my $conditions = shift;
|
||||
|
||||
return undef unless defined $conditions->{project_id};
|
||||
my $projects=project::get($config, $conditions);
|
||||
return undef if scalar(@$projects) != 1;
|
||||
return $projects->[0]->{image};
|
||||
}
|
||||
|
||||
sub get_date_range{
|
||||
my $config=shift;
|
||||
my $query=qq{
|
||||
|
||||
@@ -71,7 +71,10 @@ sub save_content{
|
||||
my @keys=();
|
||||
for my $key ('series_name', 'title', 'excerpt', 'content', 'html_content',
|
||||
'user_title', 'user_excerpt', 'topic', 'html_topic',
|
||||
'episode', 'image', 'podcast_url', 'archive_url',
|
||||
'episode',
|
||||
'image', 'image_label',
|
||||
'series_image', 'series_image_label',
|
||||
'podcast_url', 'archive_url',
|
||||
'live', 'published', 'playout', 'archived', 'rerun', 'draft', 'disable_event_sync',
|
||||
'modified_by'
|
||||
){
|
||||
@@ -90,7 +93,7 @@ sub save_content{
|
||||
where id=?
|
||||
};
|
||||
|
||||
print STDERR $query.Dumper(\@bind_values);
|
||||
#print STDERR $query.Dumper(\@bind_values);
|
||||
db::put($dbh, $query, \@bind_values);
|
||||
return $entry;
|
||||
}
|
||||
@@ -409,6 +412,8 @@ sub insert_event{
|
||||
for my $attr ('program', 'series_name', 'title', 'excerpt', 'content', 'topic', 'image', 'episode', 'podcast_url', 'archive_url'){
|
||||
$event->{$attr}=$serie->{$attr} if defined $serie->{$attr};
|
||||
}
|
||||
$event->{series_image} = $serie->{image} if defined $serie->{image};
|
||||
$event->{series_image_label} = $serie->{licence} if defined $serie->{licence};
|
||||
|
||||
#overwrite series values from parameters
|
||||
for my $attr ('program', 'series_name', 'title', 'user_title', 'excerpt', 'user_except', 'content', 'topic', 'image', 'episode', 'podcast_url', 'archive_url'){
|
||||
@@ -462,6 +467,30 @@ sub add_event_dates{
|
||||
return $event;
|
||||
}
|
||||
|
||||
sub update_series_images{
|
||||
my $config = shift;
|
||||
my $options = shift;
|
||||
|
||||
return "missing project_id" unless defined $options->{project_id};
|
||||
return "missing studio_id" unless defined $options->{studio_id};
|
||||
return "missing series_id" unless defined $options->{series_id};
|
||||
return "missing series_image" unless defined $options->{series_image};
|
||||
|
||||
my $events=series::get_events(
|
||||
$config, {
|
||||
project_id => $options->{project_id},
|
||||
studio_id => $options->{studio_id},
|
||||
series_id => $options->{series_id},
|
||||
}
|
||||
);
|
||||
|
||||
for my $event (@$events){
|
||||
$event->{series_image} = $options->{series_image};
|
||||
series_events::save_content($config, $event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sub error{
|
||||
my $msg=shift;
|
||||
print "ERROR: $msg<br/>\n";
|
||||
|
||||
@@ -81,6 +81,17 @@ sub get{
|
||||
return $studios;
|
||||
}
|
||||
|
||||
sub getImageById{
|
||||
my $config = shift;
|
||||
my $conditions = shift;
|
||||
|
||||
return undef unless defined $conditions->{project_id};
|
||||
return undef unless defined $conditions->{studio_id};
|
||||
my $studios = studios::get($config, $conditions);
|
||||
return undef if scalar(@$studios) != 1;
|
||||
return $studios->[0]->{image};
|
||||
}
|
||||
|
||||
sub insert{
|
||||
my $config=shift;
|
||||
my $entry=shift;
|
||||
|
||||
Reference in New Issue
Block a user