Site hosted by Angelfire.com: Build your free website today!
# ndisplay.pl # This file contains the HTML used to generate your news. # # For more information on NewsPro customisations, see the online FAQ. # # Do not change $ndisplayversion below! It tells the script which version of ndisplay.pl this is. $ndisplayversion = 3; # # ********* # IMPORTANT: If you ever edit this file by hand, remove the exclamation mark # ********* from the next line: # # (do not remove the # or anything else, only the exclamation mark) # This will tell the script that it has been edited by hand, and disable web-based # editing. If you don't do this, your ndisplay.pl will likely become corrupted. # # You may use the following variables in DoNewsHTML: # $newsname, $newssubject, $newsdate, $newstext, $newsemail. # Also, remember that this is a Perl script you're editing. Make sure to escape necessary # characters: i.e. $,@,%,and ~ should be written as \$,\@,\%, and \~ (of course, you # shouldn't escape the $ sign in a variable). sub DoNewsHTML { # $newshtml = qq~

$newssubject Posted $newsdate by $newsname
$newstext

~; # } # # Archive Link Formatting. Edit the HTML below to change the style. # This defines the links on the main archive page, the one that # links to the individual monthly archives. # The location of the archive is $arcfile.$ArcHtmlExt and the # month the archive covers is $ArcDate{$arcfile}. # Reminder: if editing this file by hand, follow the instructions # at the top of the file or the script may not function. sub DoLinkHTML { $newshtml = qq~ $ArcDate{$arcfile}
~; } # # Headline Formatting. # This defines the headlines that will be produced if you enable headlines # (in Advanced Settings). # You have access to all the variables as in DoNewsHTML. # TIP: To link the headline to your full news article, use a link like: # $newssubject sub DoHeadlineHTML { $newshtml = qq~ $newssubject - $newsdate
~; } # # # New Files Formatting # The format of the file links on the new files list (enabled via Advanced Settings). # $fileurl: URL of the file # $filetitle: Name or title of the file # $filedate: Date the file was last modified sub DoNewFileHTML { $newshtml = qq~ $filetitle
~; } # Email Notification # How the e-mail notifications sent will look. # If you choose to have news items sent manually, in batches, # you'll be able to edit this before sending. Otherwise, this will be # the text of the message. # # You have access to all the new variables, as in DoNewsHTML. sub DoEmailText { $newshtml = qq~ --------------------------------- $newssubject --------------------------------- Posted $newsdate by $newsname: $newstext ~; } # Archive HTML # The news style used when archiving. # By default, calls DoNewsHTML. If you'd like a different style, replace this with something like # sub DoArchiveHTML { # $newshtml = qq~ #

$newssubject Posted $newsdate by $newsname
# $newstext #

# ~; # } sub DoArchiveHTML { &DoNewsHTML; } # Search HTML # Much like archive HTML - by default, uses DoNewsHTML. sub DoSearchHTML { &DoNewsHTML; } 1; push(@Addons_Loaded, 'Addon Manager'); $Addons_List{'Addon Manager 1.1'} = ['npa_add.pl', 'Displays a list of currently installed addons, along with download and upgrade information.', 'http://www.amphibianweb.com/addon.cgi?add&1.01']; push(@Addons_PageHandler, 'AddonManagerHandler'); push(@Addons_MainPage, 'AddonManagerMainPage'); push(@Addons_NPHTMLFoot, 'AddonManagerHTMLFoot'); sub AddonManagerHandler { if (query_string() eq 'addonmanager') { &ShowAddonManager; exit; } } sub AddonManagerHTMLFoot { if ($up == 3) { print qq~ Addon Manager |~; } } sub AddonManagerMainPage { if ($up == 3) { print qq~ Addon Manager: View currently installed or install new addons (small files which extend NewsPro's abilities).

~; } } sub ShowAddonManager { &NPHTMLHead("Addon Manager"); print qq~
Download NewsPro addons here.

A list of currently installed addons is below. To remove any of these, delete its file (listed along with its name below). To install new addons, download them from the NewsPro site and simply copy the files into your NewsPro directory.

~; my $i; foreach $i (sort keys %Addons_List) { my $name = $i; my $filename = $Addons_List{$i}->[0]; my $description = $Addons_List{$i}->[1]; my $imageurl = $Addons_List{$i}->[2]; if ($imageurl) { $imageurl =~ s/amphibian\.gagames\.com/www.amphibianweb.com/i; $imageurl = qq~~; } print qq~

$name: $description
Filename: $filename        $imageurl

~; } &NPHTMLFoot; } $npconfigversion = 3; # npconfig.pl # This file is designed to make advanced customizations easier. # The various settings in this file control most aspects of NewsPro. # To change the style of your news, edit ndisplay.pl. # NOTE: This file used to contain the Advanced Settings definition. # This has been moved to newspro.cgi as of version 2. sub SubmitFormFields { # This sets the different fields in newsdat.txt that you can submit via the Submit News # page. # To add a field, add its internal name (no spaces or odd characters) to # @formfields. # You will probably want to give the field a nicer name (spaces allowed): # $FormFields{'internal_form_name'} = "Full form name."; # where internal_form_name is the same as in @formfields. # Normally, a standard text field will be used for that field. If you need # to use different HTML, use the following: # $FormFieldsCustom{'internal_form_name'} = qq~ The HTML you want ~; # Note: the main news text box cannot be configured this way, it's hard-coded. # While custom HTML will not apply in Modify News, there is the option to use # a multi-line text box ( ~; # To use the built-in empty user variables, simply add 'uservar1' and 'uservar2' to # the end of @formfields. Uservar1 and uservar2 are already included in the database, however # if you need to add any of your own variables to the database, edit # SplitDataFile and JoinDataFile as well. # Example: # @formfields = ('newsname','newsdate','newsemail','newssubject','uservar1','uservar2'); # $DisableModify{'internal_form_name'} controls whether a field can be modified. # If it is set to 1, the field cannot be modified. # If it is set to 2, basic users cannot modify it (webmaster users and users with full remove can) @formfields = ('newsname','newsdate','newsemail','newssubject'); $FormFieldsName{'newsname'} = "Name"; $FormFieldsCustom{'newsname'} = $Cookies{'uname'}; $DisableModify{'newsname'} = 1; $FormFieldsName{'newsdate'} = "Date"; $FormFieldsCustom{'newsdate'} = GetTheDate(); $DisableModify{'newsdate'} = 1; $FormFieldsName{'newsemail'} = "E-mail"; $FormFieldsCustom{'newsemail'} = qq~~; $FormFieldsName{'newssubject'} = "Subject"; } sub SplitDataFile { # Splits an entry from newsdat.txt into its different variables. You can edit this if you need # to add fields to the database. Make sure to edit JoinDataFile as well. # In general, don't change the separator (``x). # Do NOT change the order of the existing items, or place any new variables # before the existing items. You can only add items to the END of the list. local ($splitdatafile) = @_; # Remove all newlines from string. $splitdatafile =~ s/\n//g; # The following is the line you want to edit if you need to change database fields: ($uservar3, $newstext, $newsname, $newsemail, $newssubject, $newsid, $uservar1, $uservar2) = split(/``x/, $splitdatafile); @newsarray = split(/``x/, $splitdatafile); return @newsarray; } sub JoinDataFile { # Like SplitDataFile above, except joins different variables before printing them to newsdat.txt # as one line. # The order of items must be the same as in SplitDataFile. $joinline = join('``x',$uservar3, $newstext, $newsname, $newsemail, $newssubject, $newsid, $uservar1, $uservar2); return $joinline; } 1; # NewsPro Messages File $nplangversion = 3.7; # # Language Name: ENGLISH $LangName = "ENGLISH"; # # By editing this file, you can change any of the messages # seen on NewsPro screens by basic - Standard or High - level # users. The administrator-only screens are English-only, as # if the administrator did not speak English, all documentation # would have to be translated as well, which is simply too great a task. # # Translators: please leave the above message intact, and in English. # Do change the language name to the name of your language in your language, however. # # Do NOT edit the internal message names, only the messages themselves. # Example: # 'DoNotEditMe' => 'TranslateOrEditMe' # # If you use the tilde (~) within a message, you must escape it, i.e. \~ # Characters which contain a tilde, such as ñ, are fine and don't need to be escaped. # # For the messages, the boundary of where you can edit is between q~ and the following ~, # Do not edit outside that boundary. # # START DATE INFORMATION @Week_Days = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); @Months = ('January','February','March','April','May','June','July','August','September','October','November','December'); # If times in your language use a 12 hour (AM/PM) clock, set the following to 1. # Otherwise, set it to 0. $nplang_12Hour = 1; # Set the following to the standard date format in your language. Users will be able to choose # any date format that they want, but the format below is the default. # See Change Settings for information on how date formats should be written. # Edit between q~ and ~; $nplang_DateFormat = q~ , , ~; # START MESSAGES %Messages = ( 'NewsPro' => q~NewsPro~, # You may want to still call the script NewsPro, or you may want to translate the name. 'ContentType' => q~~, # If your language needs a different character set, you may have to change this tag. 'MainPage_Welcome' => q~Welcome to NewsPro,~, # Will be used as: Welcome to NewsPro, (name)! 'MainPage_Choose' => q~Choose one of the options below to begin.~, # The following should be present in every language file except for the English one. # Use this example as a guide; translate it, remove the # from the beginning of the line, # and delete the empty one below. # 'MainPage_LangWarning' => q~The basic functions of this script are available in (language name), but all administrative functions are available only in English.
~, 'MainPage_LangWarning' => q~ ~, 'Section_Submit' => q~Submit News~, 'Section_Build' => q~Build News~, 'MainPage_Descriptions_Submit' => q~Add a new news item to the database.~, 'MainPage_Descriptions_Build' => q~Use the information in the database to generate the HTML news and archive files.~, 'MainPage_Descriptions_Build_NoAuto' => q~You must build news after submitting news before it will appear on your page.~, 'Section_Modify' => q~Modify News~, 'MainPage_Descriptions_Modify' => q~Remove or edit previously submitted news items.~, 'MainPage_Modify_1' => q~You may only edit news items that you have previously posted.~, 'MainPage_Modify_2' => q~You may edit any news item, including those that others have posted.~, 'Section_UserInfo' => q~User Info~, 'MainPage_Descriptions_UserInfo' => q~Change your password or e-mail address.~, 'Section_LogOut' => q~Log Out~, 'MainPage_Descriptions_LogOut' => q~Logs you out of the system, so that you can no longer access this script until you enter your username and password.~, 'MainPage_YourVersion' => q~Your version:~, 'MainPage_CurrentVersion' => q~Current version:~, 'MainPage_Upgrade' => q~Click here to upgrade.~, 'MainPage_Addons' => q~Addons~, 'MainPage_Download' => q~Download~, 'MainPage_WebPage' => q~Visit the NewsPro web page.~, 'MainPage_SendEmail' => q~Send an e-mail with comments, questions, suggestions, etc.~, # As help is not translated, the following should read "online help (English only)" when translated. 'HTMLFoot_Help' => q~online help~, 'Section_Main' => q~Main Page~, 'BackTo' => q~Back to~, #Used as a link, Back to (site name) 'Controls_Search' => q~Search our news archives:~, 'Controls_View' => q~View all news items~, 'Controls_Email' => q~Subscribe to our mailing list, and receive the latest news items by e-mail.~, 'Controls_EmailTextBox' => q~e-mail addr.~, # Used in a text box, to show where to enter your e-mail address. 'Controls_Subscribe' => q~Subscribe~, 'Controls_Unsubscribe' => q~Unsubscribe~, 'Submit_NewsText' => q~News Text~, 'Submit_GlossaryOn' => q~Glossary: On~, 'Off' => q~Off~, 'Submit' => q~Submit~, 'Reset' => q~Reset~, 'Save_NewsSaved' => q~News Saved~, 'Save_Message' => q~The news has been saved to the data file. Remember, you still have to build news before the changes will be visible. Build News can be accessed from the bar below.~, 'Build_Title' => q~News Built~, 'Build_Message' => q~The news HTML has been built from the database. The latest news should now be visible on your page.~, 'Modify_Posted' => q~Posted on~, # Used as: Posted on (date) 'Modify_By' => q~by~, # Used as: Posted on (date) by (name) 'Modify_Keep' => q~Keep:~, # Used as a choice between keeping or removing a post. 'Modify_Remove' => q~Remove:~, 'Modify_NoPerm' => q~You do not have permission to modify this.~, # The following six messages create one sentence: Save changes and finish modifying news or show next (number) items. 'Modify_Save' => q~Save changes~, 'And' => q~and~, 'Modify_Finish' => q~finish modifying news~, 'Modify_Or' => q~or~, 'Modify_Show' => q~show next~, 'Modify_Items' => q~items~, 'ModifySave_Title' => q~News Modified~, 'ModifySave_Message' => q~Your changes (if any) have been carried out. These changes have been made to the database, however the news must be built before they will appear on your page.~, 'Login_Is' => q~is logged in~, 'Login_OKMessage' => q~You have been logged in. A "cookie" has been saved to your computer which should allow you to access this system without logging in in the future. Your browser must accept cookies to use this system.~, 'Login_OKClick' => q~Click here to go to the main page.~, 'Login_NoTitle' => q~Username/Password Incorrect~, 'Login_NoMessage' => q~The information you entered is not valid. Please use your browser's back button and try again.~, 'Login_Title' => q~NewsPro Login (Authorized Users Only)~, 'Username' => q~Username~, 'Password' => q~Password~, 'Login_Login' => q~Log In~, 'UserInfo_Message' => q~You may change two options: your password and your e-mail address.~, 'Email' => q~Email~, 'UserInfoSave_Title' => q~User Info Changed~, 'UserInfoSave_Message' => q~Your information has been changed. If you changed your password, you may need to log in again.~, 'LogOut_Message' => q~You have been logged out.~, 'DisplayLink' => q~News managed by~, 'Viewnews_Error_1' => q~Invalid date information.~, 'Viewnews_Error_2' => q~No news items meet those criteria~, 'Viewnews_From' => q~News from~, # These two used as: News from (date) to (date) 'Viewnews_To' => q~to~, 'Viewnews_Error_3' => q~Invalid start/end news items.~, 'Viewnews_Items' => q~News Items~, 'Viewnews_Latest' => q~Latest News~, 'Viewnews_EmailAdd' => q~You have successfully been added to the mailing list.~, 'Viewnews_EmailFail' => q~does not appear to be a valid e-mail address.~, 'Viewnews_EmailUnsubSuccess' => q~has successfully been removed from the mailing list.~, 'Viewnews_EmailUnsubFail' => q~does not seem to be on the mailing list.~, 'Viewnews_EmailIncomplete' => q~Please fill in all necessary fields.~, 'Viewnews_Mailing' => q~Mailing List~, 'Viewnews_Success' => q~Success~, 'Viewnews_Failure' => q~Failure~, 'Viewnews_TMPLError' => q~Could not open viewnews.tmpl.~, 'Error' => q~Error~, 'Viewnews_NoResults' => q~This search returned no results.~, 'Viewnews_Results' => q~Search Results~, 'Viewnews_NoOpen' => q~Could not open file~, #Used as: could not open file (pathname) 'Category' => q~Category~, 'Preview' => q~Preview~ ); # The end! 1;# NPLIB.pl # Common routines for NewsPro scripts and addons. # Version: 3.8 build 34 # See newspro.cgi for license information. # Location of nsettings.cgi. # It is important that your nsettings.cgi is not visible over the Web. # One way of accomplishing it is to move it to a different directory, # and give it another name. You can set the following option to the new # path of nsettings.cgi. Use an absolute path (no trailing slash). # Example: # $nsettingspath = '/usr/home/me/securefiles/newspro-settings-5432.cgi'; $nsettingspath = ''; # Lifespan of cookies, in seconds. # 7776000 seconds is equal to 90 days. $cookieExpLength = 7776000; # END OF SETTINGS ########################################################### # Build number. DO NOT CHANGE! $nplibBuild = 8; require "nplang.pl"; @Abbrev_Week_Days = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat'); @Abbrev_Months = ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); # Load values for computing times $SEC = 1; $MIN = 60 * $SEC; $HR = 60 * $MIN; $DAY = 24 * $HR; $epoch = (localtime(2*$DAY))[5]; # Allow for bugs near localtime == 0. $YearFix = ((gmtime(946684800))[5] == 100) ? 100 : 0; # Get necessary localtime information into variables. sub BasicDateVars { my $thetime = shift; ($Second,$Minute,$Hour,$Month_Day, $Month,$Year,$Week_Day,$IsDST) = (localtime($thetime))[0,1,2,3,4,5,6,8]; $ActualMonth = $Month + 1; $Year = $Year + 1900; } sub GetTheDate { my $thetime = shift; unless ($thetime) { $thetime = time; if ($NPConfig{'TimeOffset'}) { $thetime += (3600 * $NPConfig{'TimeOffset'}); } } my $thedate = $NPConfig{'DateFormat'}; BasicDateVars($thetime); if ($IsDST == 1) { $Time_Zone = $NPConfig{'Daylight_Time_Zone'}; } else { $Time_Zone = $NPConfig{'Standard_Time_Zone'}; } if ($Second < 10) { $Second = "0$Second"; } if ($Minute < 10) { $Minute = "0$Minute"; } if ($Hour == 0) { if ($NPConfig{'12HourClock'}) {$Hour = "12";} $AMPM = "AM"; } elsif ($Hour < 12) { $AMPM = "AM"; } elsif ($Hour == 12) { $AMPM = "PM"; } else { if ($NPConfig{'12HourClock'}) {$Hour = $Hour - 12;} $AMPM = "PM"; } $Month_Name = $Months[$Month]; $Month_Number = $ActualMonth; $Weekday = $Week_Days[$Week_Day]; $Day = $Month_Day; $thedate =~ s/]+)>/${$1}/gi; return $thedate; } # DoGMTTime: Return date in GMT text format. Used for HTTP expiry dates # WARNING: Does not take time into account, always returns time of 00:00:00 (midnight) sub DoGMTTime { my $thetime = shift; my $thedate; my ($Second,$Minute,$Hour,$Month_Day, $Month,$Year,$Week_Day,$IsDST) = (localtime($thetime))[0,1,2,3,4,5,6,8]; if ($Month_Day < 10) { $Month_Day = "0$Month_Day"; } $Year = $Year + 1900; $thedate = "$Abbrev_Week_Days[$Week_Day], $Month_Day-$Abbrev_Months[$Month]-$Year 00:00:00 GMT"; return $thedate; } # YMDtoUNIX # Turns a date of form 1999-7-13 (July 13, 1999) into UNIX time. # Uses time of midnight. sub YMDtoUNIX { my ($textyear, $textmonth, $textday) = @_; my $unixtime; $textyear = $textyear - 1900; $textmonth = $textmonth - 1; $unixtime = timelocal(0,0,0, $textday, $textmonth, $textyear); return $unixtime; } # WriteConfigInfo: Saves %NPConfig settings to nsettings.cgi sub WriteConfigInfo { my $nsetpath = $nsettingspath; if ($abspath && !$nsetpath) { $nsetpath = "$abspath/nsettings.cgi"; } $nsetpath = 'nsettings.cgi' unless $nsetpath; NPopen('NPCFG', ">$nsetpath"); $NPConfig{'firsttime'} = "no"; foreach $key (keys %NPConfig) { $NPConfig{$key} =~ s/^\s+//; $NPConfig{$key} =~ s/\s+$//; $NPConfig{$key} =~ s/\n//g; $NPConfig{$key} =~ s/\r//g; if ($key ne '' && $NPConfig{$key} ne '') { print NPCFG "$key``x$NPConfig{$key}\n"; } } close(NPCFG); } # ReadConfigInfo: Reads configuration from nsettings.cgi into %NPConfig sub ReadConfigInfo { my $nsetpath = $nsettingspath; if ($abspath && !$nsetpath) { $nsetpath = "$abspath/nsettings.cgi"; } $nsetpath = 'nsettings.cgi' unless $nsetpath; NPopen('NPCFG', $nsetpath); my @npconfig = ; close(NPCFG); foreach $i (@npconfig) { ($varname, $varvalue) = split(/``x/, $i); $varvalue =~ s/^\s+//; $varvalue =~ s/\s+$//; $varvalue =~ s/\n//g; $NPConfig{$varname} = $varvalue; } } # Gets our ful URL. Needed for error messages. sub GetScriptURL { my $url = 'http://' . ($ENV{'HTTP_HOST'} ? $ENV{'HTTP_HOST'} : $ENV{'SERVER_NAME'}) . ($ENV{'SERVER_PORT'} != 80 ? ":$ENV{'SERVER_PORT'}" : '') . $ENV{'SCRIPT_NAME'}; return $url; } # header: A convenience that returns the full Content-type header. sub header { unless ($HeaderPrinted) { $HeaderPrinted = 1; return "Content-type: text/html\n\n"; } else { return ''; } } # ReadForm: Reads in POSTed form values to %in sub ReadForm { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); my @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; unless($in{$name}) {$in{$name} = $value;} else { $in{$name} .= "|x|$value"; } } } # GetCookies: Reads in HTTP Cookies to %Cookies sub GetCookies { # Load Encode/Decode Data @Cookie_Encode_Chars = ('\%', '\+', '\;', '\,', '\=', '\&', '\:\:', '\s'); %Cookie_Encode_Chars = ('\%', '%25', '\+', '%2B', '\;', '%3B', '\,', '%2C', '\=', '%3D', '\&', '%26', '\:\:', '%3A%3A', '\s', '+'); @Cookie_Decode_Chars = ('\+', '\%3A\%3A', '\%26', '\%3D', '\%2C', '\%3B', '\%2B', '\%25'); %Cookie_Decode_Chars = ('\+', ' ', '\%3A\%3A', '::', '\%26', '&', '\%3D', '=', '\%2C', ',', '\%3B', ';', '\%2B', '+', '\%25', '%'); local($cookie,$value); if ($ENV{'HTTP_COOKIE'}) { foreach (split(/; /,$ENV{'HTTP_COOKIE'})) { ($cookie,$value) = split(/=/); foreach $char (@Cookie_Decode_Chars) { $cookie =~ s/$char/$Cookie_Decode_Chars{$char}/g; $value =~ s/$char/$Cookie_Decode_Chars{$char}/g; } $Cookies{$cookie} = $value; } } } # SetCookies: Prints a HTTP header, setting any cookies passed to it. # WARNING: Must be run after GetCookies sub SetCookies { local(@cookies) = @_; local($cookie,$value,$char); print "Content-type: text/html\n"; while ( ($cookie,$value) = @cookies ) { foreach $char (@Cookie_Encode_Chars) { $cookie =~ s/$char/$Cookie_Encode_Chars{$char}/g; $value =~ s/$char/$Cookie_Encode_Chars{$char}/g; } print 'Set-Cookie: ' . $cookie . '=' . $value . ';'; $exptime = time + $cookieExpLength; $CookieExpires = DoGMTTime($exptime); print ' expires=' . $CookieExpires . ';'; print "\n"; shift(@cookies); shift(@cookies); } print "\n"; $HeaderPrinted = 1; } sub ClearCookies { print "Content-type: text/html\n"; print "Set-Cookie: uname=x; expires=Thu, 03-Feb-2000 00:00:00 GMT;\n"; print "Set-Cookie: pword=x; expires=Thu, 03-Feb-2000 00:00:00 GMT;\n\n"; $HeaderPrinted = 1; } sub query_string { return $ENV{'QUERY_STRING'}; } # Is this news item from a different date than the last one? sub isNewDate { my $isNewDate; my $mdy = "$Month_Day$Month$Year"; if ($isNewDate{$FileName} ne $mdy) { $isNewDate = 1; } else { $isNewDate = 0; } $isNewDate{$FileName} = $mdy; return $isNewDate; } ####### # NEWS DATABASE LOAD/SAVE ###### # Loads newsdat.txt, and reads news data into a variety of places. sub loadND { undef @NewsData; # Get form field information, add certain hard-coded ones (mainly date & time) &SubmitFormFields; my @ffields = @formfields; @ffield_add = ('newstext', 'newsid', 'newstime', 'newsrand', 'newscat'); if (@Addons_loadND_1) { &RunAddons(@Addons_loadND_1); } push(@ffields, @ffield_add); # Declare variables my $newsnum = 0; my $newsline; my $formfield; # Open newsdat.txt &NPopen('NEWSDAT', "$NPConfig{'admin_path'}/newsdat.txt"); $nd_age = (stat(NEWSDAT))[9]; # Begin line-by-line processing of newsdat.txt LOADLOOP: while () { # Remove ending newline character chomp($_); # Split news item into component variables, using npconfig.pl definition &SplitDataFile($_); # Split the news ID # into component variables. ($newstime, $newsrand, $newscat) = split(/\,/, $newsid); # Remove the news category from the news ID, so that the category can change. $newsid = join(',', $newstime, $newsrand, ''); # Check if we want to use TimeOffset if ($NPConfig{'TimeOffset'}) { $newstime += (3600 * $NPConfig{'TimeOffset'}); } if (@Addons_loadND_2) { &RunAddons(@Addons_loadND_2); } # Go through each defined form field. foreach $formfield (@ffields) { # Load that particular news variable into the appropriate place in @NewsData $NewsData[$newsnum]->{$formfield} = ${$formfield}; } # Establish a hash of news IDs $NewsID{$newsid} = $newsnum; # Increment $newsnum to continue the processing. $newsnum++; } if (@Addons_loadND_3) { &RunAddons(@Addons_loadND_3); } close(NEWSDAT); } # Saves newsdat.txt from @NewsData, which is set by &loadND sub saveND { my ($ndentry, $joinline, $key, $value); if (@Addons_saveND_Pre) { &RunAddons(@Addons_saveND_Pre); } NPopen('NEWSDAT', ">$NPConfig{'admin_path'}/newsdat.txt"); SAVELOOP: foreach $ndentry (@NewsData) { unless ($ndentry eq 'del') { while (($key, $value) = each %{$ndentry}) { ${$key} = $value; } if (@Addons_saveND_Loop) { &RunAddons(@Addons_saveND_Loop); } if ($NPConfig{'TimeOffset'}) { $newstime -= (3600 * $NPConfig{'TimeOffset'}); } $newsid = join(',', $newstime, $newsrand, $newscat); $joinline = &JoinDataFile; $joinline =~ s/\n//g; print NEWSDAT $joinline . "\n"; } } close(NEWSDAT); if (@Addons_saveND_Post) { &RunAddons(@Addons_saveND_Post); } } # Gets the news variables for a particular item. sub getNDvar { my $nn = shift; my $ff; foreach $ff (keys %{$NewsData[$nn]}) { ${$ff} = $NewsData[$nn]->{$ff}; } $newsdate = GetTheDate($newstime); } # Gets the news variables for a particular item. # Does not generate date information. sub getNDvar_nodate { my $nn = shift; my $ff; foreach $ff (keys %{$NewsData[$nn]}) { ${$ff} = $NewsData[$nn]->{$ff}; } } sub HTMLescape { my $text = shift; $text =~ s/&/&/g; $text =~ s//>/g; $text =~ s/"/"/g; return $text; } sub PrintSelectValues { my @values = @_; if ($values[0] eq 'same') { shift @values; foreach $i (@values) { print qq~ ~; } } else { my $count = 1; foreach $i (@values) { print qq~ ~; $count++ } } } # Mainly for debugging purposes. Defines a simple NPopen subroutine for cases when a full one isn't being included. sub MiniNPopen { my $npopendef = 'sub NPopen { my ($handle, $file) = @_; my $status = open($handle, $file); return $status; }'; eval $npopendef; } sub PastDaysTime { my $pastdays = shift; &BasicDateVars(time); my $enddate = &YMDtoUNIX($Year, $ActualMonth, $Month_Day); $enddate = $enddate + 86399; my $startdate = $enddate - ($pastdays * 86400); $startdate = $startdate + 1; return ($startdate, $enddate); } # Used to process some .tmpl (HTML Template files) sub ProcessTMPL { my $tmplpath = shift; my $tmplcontent = shift; my $tmpltitle = shift; unless ($tmplpath) { return 0; } unless ($TemplateCache{$tmplpath}) { NPopen(TMPLFILE, $tmplpath); while () { $TemplateCache{$tmplpath} .= $_; } close(TMPLFILE); } my $theresult = $TemplateCache{$tmplpath}; $theresult =~ s///g; $theresult =~ s/\{\[]+)>/${\(HTMLtoText(${$1}))}/g; $theresult =~ s/\{]+)\{[\'\"]([^\s\>\}\'\"]+)[\'\"]\}>/${\(HTMLtoText(${$1}{$2}))}/g; $theresult =~ s/\[]+)\[(\d+)\]>/${\(HTMLtoText(${$1}[$2]))}/g; $theresult =~ s/\{\[]+)>/${$1}/gi; $theresult =~ s/\{]+)\{[\'\"]([^\s\>\}\'\"]+)[\'\"]\}>/${$1}{$2}/g; $theresult =~ s/\[]+)\[(\d+)\]>/${$1}[$2]/g; $theresult =~ s//$tmplcontent/gi; $theresult =~ s//${\(HTMLtoText($tmplcontent))}/g; $theresult =~ s//$tmpltitle/gi; if (@Addons_ProcessTMPL) { &RunAddons(@Addons_ProcessTMPL); } return $theresult; } sub HTMLtoText { my $html = shift; $html =~ s/
/\n/gi; $html =~ s/<\/*(blockquote|ul|li|p)[^<>]*>/\n\n/gi; $html =~ s/\"]+)\"*[^>]*>([\s\S]+?)<\/a>/$2 (link: $1)/gi; $html =~ s/<[^>]+>//g; $html =~ s/\"/"/g; return $html; } # The following three subroutines are from the Perl Time::Local module. sub timegm { $ym = pack(C2, @_[5,4]); $cheat = $cheat{$ym} || &cheat; return -1 if $cheat<0 and $^O ne 'VMS'; $cheat + $_[0] * $SEC + $_[1] * $MIN + $_[2] * $HR + ($_[3]-1) * $DAY; } sub timelocal { my $t = &timegm; my $tt = $t; my (@lt) = localtime($t); my (@gt) = gmtime($t); if ($t < $DAY and ($lt[5] >= 70 or $gt[5] >= 70 )) { # Wrap error, too early a date # Try a safer date $tt = $DAY; @lt = localtime($tt); @gt = gmtime($tt); } my $tzsec = ($gt[1] - $lt[1]) * $MIN + ($gt[2] - $lt[2]) * $HR; my($lday,$gday) = ($lt[7],$gt[7]); if($lt[5] > $gt[5]) { $tzsec -= $DAY; } elsif($gt[5] > $lt[5]) { $tzsec += $DAY; } else { $tzsec += ($gt[7] - $lt[7]) * $DAY; } $tzsec += $HR if($lt[8]); $time = $t + $tzsec; return -1 if $cheat<0 and $^O ne 'VMS'; @test = localtime($time + ($tt - $t)); $time -= $HR if $test[2] != $_[2]; $time; } sub cheat { $year = $_[5]; $year -= 1900 if $year > 1900; $month = $_[4]; NPdie("Month '$month' out of range 0..11") if $month > 11 || $month < 0; NPdie ("Day '$_[3]' out of range 1..31") if $_[3] > 31 || $_[3] < 1; NPdie("Hour '$_[2]' out of range 0..23") if $_[2] > 23 || $_[2] < 0; NPdie("Minute '$_[1]' out of range 0..59") if $_[1] > 59 || $_[1] < 0; NPdie("Second '$_[0]' out of range 0..59") if $_[0] > 59 || $_[0] < 0; $guess = $^T; @g = gmtime($guess); $year += $YearFix if $year < $epoch; $lastguess = ""; $counter = 0; while ($diff = $year - $g[5]) { NPdie("Can't handle date (".join(", ",@_).")") if ++$counter > 255; $guess += $diff * (363 * $DAY); @g = gmtime($guess); if (($thisguess = "@g") eq $lastguess){ return -1; #date beyond this machine's integer limit } $lastguess = $thisguess; } while ($diff = $month - $g[4]) { NPdie("Can't handle date (".join(", ",@_).")") if ++$counter > 255; $guess += $diff * (27 * $DAY); @g = gmtime($guess); if (($thisguess = "@g") eq $lastguess){ return -1; #date beyond this machine's integer limit } $lastguess = $thisguess; } @gfake = gmtime($guess-1); #still being skeptic if ("@gfake" eq $lastguess){ return -1; #date beyond this machine's integer limit } $g[3]--; $guess -= $g[0] * $SEC + $g[1] * $MIN + $g[2] * $HR + $g[3] * $DAY; $cheat{$ym} = $guess; } 1;