#!/usr/bin/perl ########################################################## # News Script Xtra 05/May/2005 # © 1999-2005 EZscripting.com / Newsscript.co.uk # Script by Alexandre Golovkine Updated by Babelnotes.be ########################################################## # Instructions: http://www.newsscript.co.uk/instructions/ # FAQ: http://www.newsscript.co.uk/faq/ # Help Forum: http://www.newsscript.co.uk/helpforum/ ########################################################## my $script_name = 'http://www.savethebears.co.uk/scripts/newsscript.pl'; my $databasefile = "/home/sites/www.savethebears.co.uk/web/scripts/news.txt"; my $idField = "ID"; my $image_dir = "/home/sites/www.savethebears.co.uk/web/scripts/images"; my $image_url = "http://www.savethebears.co.uk/images"; my $html_template = "/home/sites/www.savethebears.co.uk/web/scripts/headlines.shtml"; my $record_template = "/home/sites/www.savethebears.co.uk/web/scripts/news.shtml"; my $admin_mode = 'editor'; my $select_image = 1; my $add_fields = 1; my $hspace = 9; my $vspace = 2; my $Username = 'jhulott'; my $Password = 'pebbles'; my $not_found = 'No results found


'; my $news_up = 1; my $newstarget = "_self"; ########################################################## # Page Selector my $textPrevious = "Previous"; my $textNext = "Next"; my $pageSelectorRange = 10; my $records_per_page = 10; ########################################################## # Scrolling News Headlines my $Number_of_headlines_to_scroll = 5; my $speed = 4; my $bgcolor = "#eeeeee"; ########################################################## # News letter my $Number_of_news = 10; my $head_news_separator = "

"; my $news_news_separator = "

"; ########################################################## # Search Term Highlighting my $highLighting = 1; my @highLightColors = ("#FFFF00", "#FF0000", "#00FFFF", "#00FF00", "#C0C0C0"); ########################################################## # Pure HTML tag my $start_pure_html = ''; my $end_pure_html = ''; ########################################################## # Ordering my $order = ""; # abc, cba, 123 or 321 my $order_by = ""; # fieldname on which to order ########################################################## # RSS Feed my $usefeeds = 1; my $feed = "feed.rss"; my $feed_title = "Save the Bears"; my $feed_description = "Read the latest news relating to Bears from around the world"; ########################################################## # EZscripting.com © 1999 - 2005 # The scripts are available for private and commercial use # Once purchased this script can be used in any website you build personally # You may not sell the script in any format to anybody # The scripts may only be distributed by EZscripting.com # Do not post or email all or part of the this code in any form whatsoever # The redistribution of modified versions of the scripts is prohibited # EZscripting.com accepts no responsibility or liability # whatsoever for any damages however caused when using our services or scripts # By downloading and using this script you agree to the terms and conditions ########################################################## use CGI qw/:standard/; $FORM{mode}=param('mode'); $FORM{record}=param('record'); $FORM{login}=param('login'); $FORM{password}=param('password'); $FORM{action}=param('action'); $FORM{new_field}=param('new_name'); $FORM{action}="default" if !$FORM{action}; $FORM{headlines} = param('headlines'); $FORM{search}=param('search'); $FORM{method}=param('method'); $FORM{field}=param('field'); #$FORM{order} = param('order'); #$FORM{order_by} = param('order_by'); $FORM{order} = $order; $FORM{order_by} = $order_by; $page=param('page')+1; $default_mode=1 if param('mode') eq 'shtml'; $default_mode=2 if param('mode') eq 'newsletter'; $default_mode=3 if param('mode') eq 'scrollingnews'; my @field_name = (); #check password if($Username && $FORM{mode} eq $admin_mode){ %COOKIES = get_cookie('USER_Login'); if($FORM{login}){ if($FORM{password} eq $Password && $FORM{login} eq $Username){ print "Set-Cookie: USER_Login=login&$FORM{login}&pass&$FORM{password}; path=/\n"; print "Location: $script_name?mode=$admin_mode\n\n"; exit; } else{print "Content-type: text/html\n\n"; error("Wrong account info !");} } elsif(!$COOKIES{login}){promt();} elsif($COOKIES{pass} ne $Password or $COOKIES{login} ne $Username){promt();} } if($FORM{action} eq 'logout'){ print "Set-Cookie: USER_Login=login&boerkenaas&pass&boerkenaas; path=/\n"; print "Location: $script_name\n\n"; exit; } sub CheckAdminMode { if ($FORM{mode} ne $admin_mode) { error("You need to be logged in!"); exit (1); } } print "Content-type: text/html\n\n" unless $FORM{action} eq 'delete'; create_db() unless -f $databasefile; my $txt; %SUB = ( default=> \&default, main => \&main, add => \&add, save => \&save, logout => \&logout, delete => \&delete, update => \&update, view => \&view, show => \&show, refresh_feed => \&refresh_feed, add_field => \&add_field ); $SUB{$FORM{action}}->(); html_text($txt); exit; ########################################################## sub read_file{ open(F, $_[0]) || error("Can't open file $_[0]!"); my @data = ; close F; return @data; } sub read_base{ my @content; my @data = read_file("$databasefile"); chomp $data[0]; @field_name=split('\|',$data[0]); my $p=0; my $idPosition=-1; foreach(@field_name){ $idPosition = $p if $_ eq $idField; $show_position=$p if $_ eq 'show'; $p++; } error ('Old style database, please use dbconvert.pl first!') if $idPosition<0; error('Bad database file') if @field_name<1; $word = $FORM{search}; $field = $FORM{field}; $method = $FORM{method}; my @keys; $position=-1; $p=0; if($field){foreach(@field_name){if($_ eq $field){$position=$p; last;}$p++;}} if($word=~m/\A"(.*)"\Z/){$keys[0]=$1;} elsif(!$action and ($method eq "perfect" or $method eq "exact")){$keys[0]=$word;} else{@keys= split(" ", $word);} my $b =0; for(1..@data-1){ chomp $data[$_]; @line=split('\|',$data[$_]); my $a=0; if($_[0] == 1){ if($line[$show_position] eq 'Yes'){ if(@keys){ if($field && $position>-1){ my $found=0; foreach $word (@keys){ if($method eq "perfect"){if ($line[$position] eq $word){$found=1; last;} } elsif($line[$position] =~m/$word/i){$found=1; last;} } if($found){ $content->[$b]->{'record'} = $line[0]; foreach $name (@field_name){$content->[$b]->{$name} = $line[$a++];} $b++; } } else{ my $found=0; foreach $word (@keys){ foreach $value (@line){ if($method eq "perfect"){if($value eq $word){$found=1; last;}} elsif($value=~m/$word/i){$found=1; last;} } } if($found){ $content->[$b]->{'record'} = $line[0]; foreach $name (@field_name){$content->[$b]->{$name} = $line[$a++];} $b++; } } } else{ $content->[$b]->{'record'} = $line[0]; foreach $name (@field_name){$content->[$b]->{$name} = $line[$a++];} $b++; } } } else{ $content->[$_]->{'record'} = $line[0]; foreach $name (@field_name){$content->[$_]->{$name} = $line[$a++];} } } return $content; } sub order{ my @new=(); my $valid_fieldname = 0; my $orderfield = $FORM{order_by}; my $field = ""; my $entry; chomp($orderfield); my @fields = @field_name; foreach $field(@fields) { if ($field eq $orderfield) { $valid_fieldname = 1; }; }; if ($valid_fieldname) { if ($FORM{order} eq '123' or $FORM{order} eq '321') { @new = sort { $a->{$orderfield} <=> $b->{$orderfield} } @data; if ($FORM{order} eq '321') { @new = reverse @new; } } if ($FORM{order} eq 'abc' or $FORM{order} eq 'cba') { @new = sort { uc($a->{$orderfield}) cmp uc($b->{$orderfield}) } @data; if ($FORM{order} eq 'cba') { @new = reverse @new; } } } else { print "Error : invalid field name $orderfield specified"; } return @new; } sub get_record{ my $text = $_[0]; $text =~ s{\[\[(.*?)\]\]}{exists($INSERT{$1}) ? $INSERT{$1} : ""}gsex; return $text; } sub get_html{ my @txt = read_file($_[0]); foreach(@txt){$txt.=$_;} $txt=~/(.*)