Adding Entry...
'; } elsif(r('process') eq 'doNewEntry') { # Blog Add New Entry Form my $pass = r('pass'); if($pass eq $config_adminPass) { my @categories = getCategories(); print 'Making new entry...
'; } else { print 'Wrong Password'; } } elsif(r('process') eq 'newEntry') { # Blog Add New Entry Page my $pass = r('pass'); if($pass eq $config_adminPass) { my @files = getFiles($config_postsDatabaseFolder); my @lastOne = split(/"/, $files[0]); my $i = 0; if($lastOne[4] eq '') { $i = sprintf("%05d",0); } else { $i = sprintf("%05d",$lastOne[4]+1); } unless(-d "$config_postsDatabaseFolder") { print 'The folder '.$config_postsDatabaseFolder.' does not exists...Creating it...'; mkdir($config_postsDatabaseFolder, 0755); } open(FILE, ">$config_postsDatabaseFolder/$i.$config_dbFilesExtension"); my $title = r('title'); my $content = ''; if($config_useHtmlOnEntries == 0) { $content = bbcode(r('content')); } else { $content = basic_r('content'); } my $category = r('category'); my $isPage = r('isPage'); if($title eq '' || $content eq '' || $category eq '') { die("All fields are neccesary!"); } my $date = getdate($config_gmt); print FILE $title.'"'.$content.'"'.$date.'"'.$category.'"'.$i; # 0: Title, 1: Content, 2: Date, 3: Category, 4: FileName print 'Your post '.$title.' has been saved. Go to Index'; close FILE; if($isPage == 1) { open(FILE, ">>$config_postsDatabaseFolder/pages.$config_dbFilesExtension.page"); print FILE $i.'-'; close FILE; } } else { print 'Wrong password!'; } } elsif(r('viewCat') ne '') { # Blog Category Display my $cat = r('viewCat'); my @entries = getFiles($config_postsDatabaseFolder); my @thisCategoryEntries = (); my @categories = (); foreach(@entries) { my @split = split(/"/, $_); # [0] = Title [1] = Content [2] = Date [3] = Category if($split[3] eq $cat) { push(@thisCategoryEntries, $_); } } # Pagination - This is the so called Pagination my $page = r('p'); # The current page if($page eq ''){ $page = 1; } # Makes page 1 the default page my $totalPages = ceil((scalar(@thisCategoryEntries))/$config_entriesPerPage); # How many pages will be? # What part of the array should i show in the page? my $arrayEnd = ($config_entriesPerPage*$page); # The array will start from this number my $arrayStart = $arrayEnd-($config_entriesPerPage-1); # And loop till this number # As arrays start from 0, i will lower 1 to these values $arrayEnd--; $arrayStart--; my $i = $arrayStart; # Start Looping... while($i<=$arrayEnd) { unless($thisCategoryEntries[$i] eq '') { my @finalEntries = split(/"/, $thisCategoryEntries[$i]); my @pages = getPages(); my $do = 1; foreach(@pages) { if($_ == $finalEntries[4]) { $do = 0; last; } } if($do == 1) { print '
'.$finalEntries[0].'
'.$finalEntries[1].'Comments - Edit - Delete
'; } } $i++; } # Now i will display the pages if($totalPages >= 1) { print '
Editing Entry...
'; } elsif(r('process') eq 'editSecured') { # Edit Entry Page my $pass = r('pass'); if($pass eq $config_adminPass) { my $id = r('fileName'); my $tempContent = ''; open(FILE, "<$config_postsDatabaseFolder/$id.$config_dbFilesExtension"); while(Editing Entry...
'; } else { print 'Wrong Pass.'; } } elsif(r('process') eq 'editEntry') { # Edit process my $pass = r('pass'); if($pass eq $config_adminPass) { my $title = r('title'); my $content = ''; if($config_useHtmlOnEntries == 0) { $content = bbcode(r('content')); } else { $content = basic_r('content'); } my $category = r('category'); my $fileName = r('fileName'); open(FILE, "+>$config_postsDatabaseFolder/$fileName.$config_dbFilesExtension"); if($title eq '' or $content eq '' or $category eq '') { die("All fields are neccesary!"); } my $date = getdate($config_gmt); print FILE $title.'"'.$content.'"'.$date.'"'.$category.'"'.$fileName; # 0: Title, 1: Content, 2: Date, 3: Category, 4: FileName print 'Your post '.$title.' has been edited. Go Back'; close FILE; } else { print 'Wrong password!'; } } elsif(r('delete') ne '') { # Delete Entry Page my $fileName = r('delete'); print 'Deletting Entry...
'; } elsif(r('process') eq 'deleteEntry') { # Delete Entry Process my $pass = r('pass'); if($pass eq $config_adminPass) { my $fileName = r('fileName'); my @pages = getPages(); my $isPage = 0; foreach(@pages) { if($_ == $fileName) { $isPage = 1; last; } } my $newPages; if($isPage == 1) { foreach(@pages) { if($_ != $fileName) { $newPages.=$_.'-'; } } open(FILE, "+>$config_postsDatabaseFolder/pages.$config_dbFilesExtension.page"); print FILE $newPages; close FILE; } unlink("$config_postsDatabaseFolder/$fileName.$config_dbFilesExtension"); print 'Entry deletted. Go to Index'; } else { print 'Wrong password!'; } } elsif(r('do') eq 'search') { # Search Function my $keyword = r('keyword'); my $do = 1; if(length($keyword) < $config_searchMinLength) { print 'The keyword must be at least '.$config_searchMinLength.' characters long!'; $do = 0; } my $by = r('by'); # This can be 0 (by title) or 1 (by id) based on the splitted array if(($by != 0) && ($by != 1)){ $by = 0; } # Just prevention from CURL or something... my $sBy = $by == 0 ? 'Title' : 'Content'; # This is a shorter way of "my $sBy = ''; if($by == 0) { $sBy = 'Title'; } else { $sBy = 'Content'; }" if($do == 1) { print 'Searching for '.$keyword.' by '.$sBy.'...'; my @entries = getFiles($config_postsDatabaseFolder); my $matches = 0; foreach(@entries) { my @currEntry = split(/"/, $_); if(($currEntry[$by] =~ m/$keyword/i)) { print ''.$currEntry[0].'
'; $matches++; } } print '
'.$entry[0].'
'.$entry[1].'Edit - Delete
'; # Now Display Comments unless(-d $config_commentsDatabaseFolder) # Does the comments folder exists? We will save comments there... { mkdir($config_commentsDatabaseFolder, 0755); } my $content = ''; open(FILE, "<$config_commentsDatabaseFolder/$fileName.$config_dbFilesExtension"); while(
Comments:
'; my @comments = split(/'/, $content); if($config_commentsDescending == 1) { @comments = reverse(@comments); # We want the newest first? (Edit at the top on the configuration if you do want newest first) } my $i = 0; foreach(@comments) { my @comment = split(/"/, $_); my $title = $comment[0]; my $author = $comment[1]; my $content = $comment[2]; my $date = $comment[3]; print 'Posted on '.$date.' by '.$author.''.$title.'
'; if($config_bbCodeOnCommentaries == 0) { print txt2html($content); } else { print bbcode($content); } print '
Delete
'; $i++; # This is used for deletting comments, to i know what comment number is it :] } } # Add comment form if($config_allowComments == 1) { print '
Add Comment
'; } } } elsif(r('sendComment') ne '') { # Send Comment Process my $fileName = r('sendComment'); my $title = r('title'); my $author = r('author'); my $content = r('content'); my $pass = r('pass'); my $date = getdate($config_gmt); my $do = 1; my $triedAsAdmin = 0; if($title eq '' || $author eq '' || $content eq '' || $pass eq '') { print 'All fields are neccessary. Go back and fill them all.'; $do = 0; } if($config_commentsSecurityCode == 1) { my $code = r('code'); my $originalCode = r('originalCode'); unless($code eq $originalCode) { print 'Security Code does not match. Please, try again'; $do = 0; } } if($config_securityQuestionOnComments == 1) { my $question = r('question'); unless(lc($question) eq lc($config_commentsSecurityAnswer)) { print 'Incorrect security answer. Please, try again.'; $do = 0; } } my $hasPosted = 0; # This is to see if the user has posted already, so we add him/her to the database :] foreach(@config_commentsForbiddenAuthors) { if($_ eq $author) { unless($pass eq $config_adminPass) # Prevent users from using nicks like "admin" { $do = 0; print 'Wrong password for using '.$_.' as nickname'; last; } else { $hasPosted = 1; } $triedAsAdmin = 1; } } # Start of author checking, for identity security open(FILE, "<$config_commentsDatabaseFolder/users.$config_dbFilesExtension.dat"); my $data = ''; while('; } # End of author checking, start adding comment if($do == 1) { if($title eq '' or $author eq '' or $content eq '') { print 'All fields are neccessary.'; } else { if(length($content) > $config_commentsMaxLenght) { print 'The content is too long! Max characters is '.$config_commentsMaxLenght.' you typed '.length($content); } else { my $content = $title.'"'.$author.'"'.$content.'"'.$date.'"'.$fileName."'"; # Add comment open(FILE, ">>$config_commentsDatabaseFolder/$fileName.$config_dbFilesExtension"); print FILE $content; close FILE; # Add coment number to a file with latest comments open(FILE, ">>$config_commentsDatabaseFolder/latest.$config_dbFilesExtension"); print FILE $content; close FILE; print 'Comment added. Thanks '.$author.'!
Deletting Comment...
'; } elsif(r('process') eq 'deleteComment') { # Delete Comment Process my $pass = r('pass'); if($pass eq $config_adminPass) { my $data = r('data'); my @info = split(/\./, $data); my $fileName = $info[0]; my $part = $info[1]; my $commentToDelete; my $content = ''; open(FILE, "<$config_commentsDatabaseFolder/$fileName.$config_dbFilesExtension"); while(Archive
'; my @entries = getFiles($config_postsDatabaseFolder); print 'No entries created yet.' if scalar(@entries) == 0; # Split the data in the post so i have them in this format "13 Dic 2008, 24:11|0001|Entry title" date|fileName|entryTitle my @dates = map { split(/"/, $_); @_[2].'|'.@_[4].'|'.@_[0]; } @entries; my @years; foreach(@dates) { my @date = split(/\|/, $_); my @y = split(/\s/, $date[0]); $y[2] =~ s/,//; if($y[2] =~ /^\d+$/) { push(@years, $y[2]); } } @years = reverse(sort(array_unique(@years))); for my $actualYear(@years) { print 'Year '.$actualYear.''; # Now i make my hash with the empty months, why define them? because this is the order they will be executed my %months = ('Jan'=>'', 'Feb'=>'', 'Mar'=>'', 'Apr'=>'', 'May'=>'','Jun'=>'','Jul'=>'','Aug'=>'','Sep'=>'','Oct'=>'','Nov'=>'','Dic'=>''); # Array with all entries from that year my @entries = grep { /$actualYear/; } @dates; # Now assign the post number to the hash foreach(@entries) { my @d = split(/\s/, $_); my @e = split(/\|/, $_); $months{$d[1]} .= $e[0].'|'.$e[1].'|'.$e[2].'&-;'; } # Now i have my months hash with a string to be splitted into all posts from that month while(my($k, $v) = each(%months)) { unless($k =~ /^\d/) { print '
'.$k.':
Day '.$d[0].': | '.$data[2].' |
Listing All Comments
'; my @comments = getComments(); # This is pagination... Again :] my $page = r('page'); # The current page if($page eq ''){ $page = 1; } # Makes page 1 the default page (Could be... $page = 1 if $page eq '') my $totalPages = ceil((scalar(@comments))/$config_commentsPerPage); # How many pages will be? # What part of the array should i show in the page? my $arrayEnd = ($config_commentsPerPage*$page); # The array will start from this number my $arrayStart = $arrayEnd-($config_commentsPerPage-1); # And loop till this number # As arrays start from 0, i will lower 1 to these values $arrayEnd--; $arrayStart--; my $i = $arrayStart; # Start Looping... if(scalar(@comments) > 0) { print 'Comment Title | Comment Author |
'.$finalEntries[0].' | '.$finalEntri es[1].' |
Smilies
Smilie | Code |
:'.$n[0].': |
'.$finalEntries[0].'
'.$finalEntries[1].''.$commentsLink.' - Edit - Delete
'; } } $i++; } # Now i will display the pages print '