#!/usr/bin/perl
#VGSEO2 indexOutput - AI+Do not publish Version.
#v1.0.0 release!
#v1.0.1 ampã®ãªã³ã¯å¦çãfix
#v1.0.2 deleteãªã³ã¯å¦çå®è£
#v1.0.3 ã³ãã¼ã©ã¤ããã¡ãã¥ã¼ãããç»åã®å·¦å³ãä¹±æ°å
#v1.0.4 favicon.icoã®å°å
¥
#v1.0.5 æ¤ç´¢ã¨ã³ã¸ã³ã«ãã£ãã·ã¥ï¼ã¤ã³ãã¯ã·ã³ã°ï¼ããã¦ãªããã¡ã¤ã³ã¯ãªã³ã¯ãåºåããªãã¹ãã é²æ¢æ©è½ã追å
#v1.0.6 èªåãµã¤ããããXMLéä¿¡æ©è½ã追å ï¼1æ¥1åã®ããã¯å¶å¾¡ä»ãï¼
#v1.0.7 URLç½®ææ©è½ã«ãã°ãããAã¿ã°å
ã®URLã«å¯¾è±¡ãã¼ã¯ã¼ããå
¥ã£ã¦ããã¨ç½®æããã¦ãã¾ããã°ãä¿®æ£ãã¾ããã
#v1.0.8 not foundãã¼ã¸ã301ãããã«å¤æ´ãã¦ã¯ãã¼ã©ã¼ããªãã£ã®æ£å¸¸åãå³ã
#v1.0.9 ããåé¿æ½ç sponsored
#v1.1.0 ld+jsonï¼æ§é åãã¼ã¯ã¢ããã®datePublishedã¨dateModifiedï¼æ¡å¼µ
#v1.1.1 ã¢ã³ã«ã¼ããã¹ãé¨åã®null, follow, ugc, sponsoredã®ä¹±æ°å
#CSVãã¡ã¤ã«ã®èªã¿è¾¼ã¿
$csvfileMainData = './csvfiles/mainData.csv'; # ã³ã³ãã³ãç¨
$csvfileDatasets = './csvfiles/htmlDataSets.csv';
$csvfileCssDatasets = './csvfiles/cssDataSets.csv';
###### ãªã³ã¯æ¶å»ãè¡ããããã¡ã¤ã³ã®ãªã¹ã
$delLog = "http://www.kaseo.net/temp/delete.txt";
###### nofollowãè¡ããããã¡ã¤ã³ã®ãªã¹ã
$nofollowdomains = "http://www.kaseo.net/temp/nofollowdomains.txt";
###### sponsoredãè¡ããããã¡ã¤ã³ã®ãªã¹ã
$sponsoreddomains = "http://www.kaseo.net/temp/sponsoreddomains.txt";
###### ugcãè¡ããããã¡ã¤ã³ã®ãªã¹ã
$ugcdomains = "http://www.kaseo.net/temp/ugcdomains.txt";
###### dofollowãè¡ããããã¡ã¤ã³ã®ãªã¹ã
$dofollowdomains = "http://www.kaseo.net/temp/dofollowdomains.txt";
###### yahooã«ãã£ãã·ã¥ããã¦ããããã§ãã¯ããã¹ã
$indexCountLog = "./indexCount.txt";
use utf8;
use CGI;
use Cwd;
use LWP::UserAgent;
use POSIX qw(strftime);
use File::Glob ':glob';
use File::Basename;
###### åæå¦ç
&decodem;
if ($form{page} =~ /^\s*?$/){
$pageName = '/';
} else {
$pageName =$form{page};
}
###### ã¡ã¤ã³å¦ç
local $HTML_Contents;
local @HTML_Contents;
##### HTMLã®ãã¼ã¿ã»ãããå¼ã³åºã
local @OUTPUT_HTML;
# ã¿ã°ãã¼ã¿ã®CSVãã¡ã¤ã«ããªã¼ãã³
open( FH, "<:encoding(utf8)", "$csvfileDatasets") or die "Can't open $csv_file: $!";
my @csv_tag_data = ;
close(FH);
# è¤æ°ãã¼ã¿ãå
¥ã£ãCSVãäºæ¬¡å
é
åã§æ»ãä¸æ¬å¦ç(ã¿ã°ãã¼ã¿)
local @tag_database = &get_array(@csv_tag_data);
#ã¿ã°æ
å ±ã®è¡ã®æ大æ°ãã«ã¦ã³ããã
my $maxRowHTML = &count_row_elements(@tag_database);
srand();
for (my $i =0; $maxRowHTML > $i;$i++){
# ã®åã®è¦ç´ æ°ãã«ã¦ã³ããã
my $target_column = $i; # 0-based indexãªã®ã§ã2åç®ã¯1ã«ãªãã¾ãã
my $count = &count_column_elements(\@tag_database, $target_column);
$count = int(rand($count));
$tag_database[$count][$target_column] =~ s/^"//;
$tag_database[$count][$target_column] =~ s/"$//;
push @OUTPUT_HTML, $tag_database[$count][$target_column] . "\n";
last if $i == 99;
}
##### CSSã®ãã¼ã¿ã»ãããå¼ã³åºã
local @OUTPUT_CSS;
# CSSãã¼ã¿ã®CSVãã¡ã¤ã«ããªã¼ãã³
open( FH, "<:encoding(utf8)", "$csvfileCssDatasets") or die "Can't open $csv_file: $!";
my @csv_css_data = ;
close(FH);
# è¤æ°ãã¼ã¿ãå
¥ã£ãCSVãäºæ¬¡å
é
åã§æ»ãä¸æ¬å¦ç(ã¿ã°ãã¼ã¿)
local @css_database = &get_array(@csv_css_data);
#ã¿ã°æ
å ±ã®è¡ã®æ大æ°ãã«ã¦ã³ããã
my $maxRowCSS = &count_row_elements(@css_database);
srand();
for (my $i =0; $maxRowCSS > $i;$i++){
# ã®åã®è¦ç´ æ°ãã«ã¦ã³ããã
my $target_column = $i; # 0-based indexãªã®ã§ã2åç®ã¯1ã«ãªãã¾ãã
my $count = &count_column_elements(\@css_database, $target_column);
$count = int(rand($count));
$css_database[$count][$target_column] =~ s/^"//;
$css_database[$count][$target_column] =~ s/"$//;
push @OUTPUT_CSS, $css_database[$count][$target_column] . "\n";
last if $i == 99;
}
# print $tag_database[0][0];
# print $tag_database[1][0];
# print $tag_database[2][0];
# print $tag_database[0][1];
# print $tag_database[1][1];
# print $tag_database[2][1];
# ã¡ã¤ã³ã³ã³ãã³ãã®CSVãã¡ã¤ã«ããªã¼ãã³
open( FH, "<:encoding(utf8)", "$csvfileMainData") or die "Can't open $csv_file: $!";
my @csv_data = ;
close(FH);
# è¤æ°ãã¼ã¿ãå
¥ã£ãCSVãäºæ¬¡å
é
åã§æ»ãä¸æ¬å¦ç(ã¡ã¤ã³ã³ã³ãã³ã)
local @database = &get_array(@csv_data);
#ãã¼ã¿ãã¼ã¹ã®åãåå¾ãã¦ããã®ãã¼ã¸ã®ãã¼ã¿ã確ä¿ãã(ã¡ã¤ã³ã³ã³ãã³ã)
local ($colPoint) = &getData(@database);
#ãã該å½ãã$colPoint(ãã£ã¬ã¯ããªå)ãåå¨ããªããã°Not Foundã¨ãã
if ($colPoint =~ /^\s*?$/){
&print_header_redirect_to_domain_top();
#&print_header_notfound();
#print "404 Not Found.";
exit;
}
# ãããã¼ã®ãµãã«ã¼ãã³å¼ã³åºã
local $link;
@OUTPUT_HTML = &print_header($colPoint, \@OUTPUT_HTML, \@OUTPUT_CSS);
my $delx = LWP::UserAgent->new();
my $delxtemp = $delx->get($delLog);
local $dellines = $delxtemp->content, "\n";
local @dellists = split ("\n", $dellines);
foreach my $line (@OUTPUT_HTML){
next unless $line;
$line =~ s/(\r\n|\n|\r)+/\n/ig;
push @HTML_Contents, $line;
}
#naviã¡ãã¥ã¼ã®ä¹±æ°çæ
srand;
local $navRand = int(rand(2));
push @HTML_Contents, "\n" unless $navRand;
push @HTML_Contents, "\n";
push @HTML_Contents, "" . $database[2][$colPoint] . "
\n";
# print $database[3][$colPoint] . ":3
\n";
$database[3][$colPoint] =~ s/^"//;
$database[3][$colPoint] =~ s/"$//;
#local @mainContents = split /\r\n|\r|\n/, $database[3][$colPoint];
#対çãã¼ã¯ã¼ãã®åå¾
my @kwds = split /,/, $database[5][$colPoint];
#ã³ã³ãã³ãå
ã«ãã対çãã¼ã¯ã¼ãã®ãªã³ã¯åå¦ç
my %replaced;
local $mflag = 0;
#ã¤ã³ãã¯ã¹æ°ãæ ¼ç´ãã¦ãããã¡ã¤ã«ãèªã¿è¾¼ã
open (IN, $indexCountLog);
local @indexCount = ;
local $indexCount = join '', @indexCount;
$indexCount =~ s/\s//ig;
$indexCount = 1 unless (-f "$indexCountLog");
foreach my $kwd (@kwds) {
my $escaped_kwd = quotemeta($kwd);
next if $replaced{$kwd};
if ($database[3][$colPoint] =~ /$escaped_kwd/ and $indexCount) {
$database[3][$colPoint] =~ s/$escaped_kwd/###A###$kwd###\/A###/i;
$replaced{$kwd} = 1;
$mflag = 1;
}
}
#### 被ãªã³ã¯ - relå±æ§ãã§ã³ã¸
local $reltype;
# ã¹ãã³ãµã¼ã $sponsoreddomains
my $spox = LWP::UserAgent->new();
my $spoxtemp = $spox->get($sponsoreddomains);
local $spolines = $spoxtemp->content, "\n";
local @spolists = split ("\n", $spolines);
foreach $spolists (@spolists){
next unless $spolists;
local ($spoline, $spoflag) = split ("<>", $spolists);
chomp $spoline;
$spoline =~ s/\s//ig;
if ($database[6][$colPoint] =~ /$spoline/i){
$reltype = 'sponsored';
last;
}
}
# ã¦ã¼ã¶ã¼ã¸ã§ãã¬ã¼ãã£ãã³ã³ãã³ã $ugcdomains
my $ugcx = LWP::UserAgent->new();
my $ugcxtemp = $ugcx->get($ugcdomains);
local $ugclines = $ugcxtemp->content, "\n";
local @ugclists = split ("\n", $ugclines);
foreach $ugclists (@ugclists){
next unless $ugclists;
local ($ugcline, $ugcflag) = split ("<>", $ugclists);
chomp $ugcline;
$ugcline =~ s/\s//ig;
if ($database[6][$colPoint] =~ /$ugcline/i){
$reltype = 'ugc';
last;
}
}
# ãã¼ãã©ãã¼ $nofollowdomains
my $nofx = LWP::UserAgent->new();
my $nofxtemp = $nofx->get($nofollowdomains);
local $noflines = $nofxtemp->content, "\n";
local @noflists = split ("\n", $noflines);
foreach $noflists (@noflists){
next unless $noflists;
local ($nofline, $nofflag) = split ("<>", $noflists);
chomp $nofline;
$nofline =~ s/\s//ig;
if ($database[6][$colPoint] =~ /$nofline/i){
$reltype = 'nofollow';
last;
}
}
# ãã¥ãã©ãã¼ $dofollowdomains
my $dofx = LWP::UserAgent->new();
my $dofxtemp = $dofx->get($dofollowdomains);
local $doflines = $dofxtemp->content, "\n";
local @doflists = split ("\n", $doflines);
foreach $doflists (@doflists){
next unless $doflists;
local ($dofline, $dofflag) = split ("<>", $doflists);
chomp $dofline;
$dofline =~ s/\s//ig;
if ($database[6][$colPoint] =~ /$dofline/i){
$reltype = 'follow';
last;
}
}
# ãããã«ã該å½ããªãã©ã³ãã å
my @values = ('sponsored', 'ugc', 'nofollow');
if (!$reltype) {
$reltype = $values[int(rand(@values))];
}
$database[3][$colPoint] =~ s/###A###(.*?)###\/A###/$1<\/a>/g;
my $random_width = int(rand(11)) + 15;
my $random_minsize = int(rand(51)) + 150;
my $random_margin = int(rand(6)) + 15;
#ç»åãã¼ã¸ã³ã®ä¹±æ°çæ
srand;
local $floatRand = int(rand(2));
local $floatImage;
if ($floatRand){
$floatImage = "right";
}else{
$floatImage = "left";
}
if ($mflag){
push @HTML_Contents, "\n" if $database[4][$colPoint];
} else {
if ($indexCount){
push @HTML_Contents, "<\/a>\n" if $database[4][$colPoint];
} else{
push @HTML_Contents, "\n" if $database[4][$colPoint];
}
}
#
ã¿ã°å
¥ãã¦ã³ã³ãã³ãã¡ã¤ã³çæ
local @contents = split /\r\n|\r|\n/, $database[3][$colPoint];
foreach my $contents (@contents){
next unless $contents;
$contents = "
$contents<\/p>\n";
push @HTML_Contents, $contents;
}
push @HTML_Contents, "\n" if $navRand;
#ã³ãã¼ã©ã¤ãçæ
local $rand;
srand;
$rand = int(rand(3));
if ($rand == 1){
$copy01 = 'Copyright';
} elsif($rand == 2) {
$copy01 = 'copyright';
} else {
$copy01 = '';
}
srand;
$rand = int(rand(3));
if ($rand == 1){
$copy02 = '(c)';
} elsif($rand == 2) {
$copy01 = '©';
} else {
$copy01 = '(C)';
}
srand;
$rand = int(rand(2));
if ($rand){
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime();
$year += 1900;
$mon++;
$copy03 = $year;
} else {
$copy03 = '';
}
srand;
$rand = int(rand(2));
if ($rand){
$copyA = "
";
$copyB = "
";
} else {
$copyA = "";
$copyB = "";
}
push @HTML_Contents, "$copyA$copy01 $copy02 $copy03 $database[1][$colPoint]$copyB\n";
push @HTML_Contents, "