package Gm_Core; ############################################################################### # Greymatter 1.8.2 # Copyright (c)2000-2008, The Greymatter team # http://greymatterforum.proboards82.com/ # By possessing this software, you agree not to hold the author responsible for # any problems that may arise from your installation or usage of Greymatter # itself, or from any content generated by yourself or others through the use of # this program. You may freely modify and redistribute this program, so # long as every copyright notice (including in this manual and in the Greymatter # code) remains fully intact. Finally, you may not sell or in any way # make a financial profit from this program, either in original or modified form. # Your possession of this software signifies that you agree to these terms; # please delete your copy of this software if you don't agree to these terms. # Original Creators Noah Grey ############################################################################### #============================================================================== # Note no exporting because items from this package should be fully qualified ## Gm Core # This package groups functions that deal with the core # functionality of GreyMatter: # - Admin screen functionality (but not display), such as writting to cplog, checking banned IPs # - Template Variable Translation # - Text Localization # - Configuration value retrieval (Gm can't run without configs) # # CONVENTIONS # 1. Return a string rather than printing, this is just more elegant. Leave prints # to the calling subroutine, if possible (especially if the calling subroutine is dealing # with displaying information to the user) # 2. Private subroutines should start with the '_' character. By private I mean # it will never be called outside of this package. # 3. If you have more than 1 or 2 parameters, especially if they are not required, # use named parameters such as in createRadioButton. By putting stuff in a # hash we gain the flexibility to add more optional parameters without having # to pass in '' placeholders or modify existing code. # 4. Subs starting with 'create' or 'get' should return a string. # 5. Subs starting with 'display' are expected to contain print statements # 6. Use ' and " where appropriate. If you don't have any variables or newlines # then use ', its quicker and cleaner. # 7. Don't put all text on one huge long line. It messes with some programs # that don't do line wraps. # # Some usefull DEBUG: warn join( ', ', map { $_ = "$_ = $params{$_}" } keys( %params ) ); use strict; use warnings; use Gm_Constants; use Gm_Storage; use Gm_Utils; use Gm_Web; use Gm_Security; # Global vars that are highly used, maybe make local sometime my $CONFIGS = Gm_Storage::getConfigs( errHandler=>\&Gm_Web::displayAdminErrorExit ); my $TEMPLATES = Gm_Storage::getTemplates( errHandler=>\&Gm_Web::displayAdminErrorExit ); # Global Language labels my %LABELS = (); %LABELS = %{Gm_Storage::loadLanguage( Gm_Constants::DEFAULT_LANG )}; #warn 'default language loaded'; ## leave until no more 'require gm_library' in gm.cgi ## Config # This gets the set config for the supplied config name (should be constants?) # ARG1: the configuration label for the requested config value # RETURNS: the value for which the label was given ## MOVE TO STORAGE -- OR MAKE THIS WRAPPER sub config { my $label = shift( @_ ); my $value = Gm_Constants::EMPTY; if( defined( $label ) ){ $value = defined( $CONFIGS->{ $label } ) ? $CONFIGS->{ $label } : Gm_Constants::EMPTY; } return( $value ); } ## Text # this gets the labels string for a given constant # ARG1: the label to return text from # (opt) ARG2: a hash reference to the parameters to replace on the returned label, # e.g. a string ENTRIES that equates to this 'There are $NUM entries' should be # called like this: Lang::getText( Lang::ENTRIES, { NUM=>'5' } ); # or this: Lang::getText( Lang::ENTRIES, \%params ); # which will return: 'There are 5 entries' # Note that if no ARG2 is provided, the string will be unchanged i.e. the user will # see 'There are $NUM entries' # RETURNS: localized text sub text { my $label = shift( @_ ) || Gm_Constants::EMPTY; my $params = shift( @_ ) || {}; my $theText = defined( $LABELS{ $label } ) ? $LABELS{ $label } : Gm_Constants::EMPTY; foreach my $p ( keys( %$params ) ){ ## TODO: SHOULD CHECK IF VALUE DEFINED? $theText =~ s/\$$p/$params->{$p}/gis; } return( $theText ); } ## Set Language # this sets the language of the given author # ARG author=> the hash returned by getAuthors, for a particular author sub setLanguage { my (%params) = @_; ## Setting up vars my $errHandler = $params{'errHandler'} || \&Gm_Utils::gmWarn; my $author = $params{'author'} || {}; my $lang = $author->{'lang'}; if( $lang ){ my %newLabels = %{Gm_Storage::loadLanguage( $lang )}; ## We are overlapping the labels here, so that if the new loaded language might # be missing any new labels, that the default labels will still be used, so that # some text is shown, rather than no text at all! %LABELS = (%LABELS, %newLabels ); } } # --------------- # write to cp log # --------------- ## Write to Control Panel Log # shorthand to write to the control panel log, used by admin # or user, but must pass handler if want error to look right # ARGS1 = message to write to control panel # (opt) ARGS2 = error handler # DEPRECATES: gm_writetocplog sub writeToCplog { my $writetologtext = shift(@_); # forcewrite is required so that when diagnostics and repair are run, it will log, this is required # since hasDiagRun requires that Diagnostics and Repair has modified the cplog my $forcewrite = shift(@_) || ''; my $errHandler = shift(@_) || \&Gm_Utils::gmWarn; if( $CONFIGS->{'gmkeeplog'} eq Gm_Constants::YES || $forcewrite ){ my ($gmdate) = Gm_Utils::getStdDate( $CONFIGS->{'gmserveroffset'} ); my $authorIp = $ENV{'REMOTE_ADDR'}; ## Checking to see if message was sanitized if( Gm_Security::hackWebTest( $writetologtext ) ){ $writetologtext = '[Aborted log - '. 'Hack Attempt] by '.$ENV{'REMOTE_ADDR'}.''; } ## TODO: make the date and ip and message some sort of internal format, such as :: seperated # then markup on display, so that we aren't storing data that is preformated (prevents date formats # for other countries, etc. LOCALIZE Gm_Storage::addLogMessage( msg=>"[$gmdate] [$authorIp]". " $writetologtext", errHandler=>$errHandler ); } } ## Ban Check # Determines if a given ip has been 'banned' # ARG ip => the ip address to check if banned, usually from the 'REMOTE_ADDR' environment # variable # (opt) ARG errHandler => the error handler used to display errors # RETURN: 0 if not banned, the Banlist entry if banned (so can access 'ip', 'host', etc.) sub banCheck { my (%params) = @_; my $errHandler = $params{'errHandler'} || \&Gm_Utils::gmWarn; my $currentip = $params{'ip'} || $ENV{'REMOTE_ADDR'}; my $gmbanlist = Gm_Storage::getBanlist( errHandler=>$errHandler ); my $isBanned = 0; foreach my $gmbanlistline ( keys(%$gmbanlist)) { my ($checkthisip, $checkthisiphost, $checkthisperson) = ($gmbanlist->{$gmbanlistline}{'ip'}, $gmbanlist->{$gmbanlistline}{'host'}, $gmbanlist->{$gmbanlistline}{'label'} ); ## This will make the checkthisip string safe, so that it can be run through a regex # otherwise a string like '1.2.3.4)' will cause gm to die. my $safeip = quotemeta( $checkthisip ); if (($currentip =~ m/$safeip/) && ($checkthisip ne Gm_Constants::EMPTY)) { $isBanned = $gmbanlist->{$gmbanlistline}; last; } } return( $isBanned ); } ## Process Ban Check # Determines if a given ip has been 'banned' and logs it and returns message to the user # ARG ip => the ip address to check if banned, usually from the 'REMOTE_ADDR' environment # variable # ARG action => the action the user was trying to perform # (opt) ARG errHandler => the error handler used to display errors # DEPRECATES: gm_bancheck sub processBanCheck { my (%params) = @_; my $errHandler = $params{'errHandler'} || \&Gm_Utils::gmWarn; my $currentip = $params{'ip'} || $ENV{'REMOTE_ADDR'}; my $action = $params{'action'} || 'accessing this program'; my $isBanned = banCheck( ip=>$currentip, errHandler=>$errHandler ); if( $isBanned ){ # Logging... my $banLabel = $isBanned->{'label'} ? ", \"$isBanned->{'label'}\"" : ''; my $cpMsg = ''.Gm_Core::text( Gm_Constants::BANNED_ACCESS, { IP=>$isBanned->{'ip'}, HOST=>$banLabel, ACTION=>$action } ).''; Gm_Core::writeToCplog( $cpMsg ); # Tell them why &$errHandler( Gm_Core::text( Gm_Constants::BANNED_DENY, { IP=>$ENV{'REMOTE_ADDR'}, ACTION=>$action } )); } } ## Reconstruct Entrylist (should this be just 'Construct'? # Goes through each entry and creates and saves the entrylist file # (opt) ARG errHandler => the error handler used to display errors sub reconstructEntrylist { my (%params) = @_; my $errHandler = $params{'errHandler'} || \&Gm_Utils::gmWarn; my $gmCounters = Gm_Storage::getCounters( errHandler=>$errHandler ); ## validating if( !defined( $gmCounters->{'entrytotal'} ) || $gmCounters->{'entrytotal'} =~ m/\D/gi ){ &$errHandler( 'There is an issue with gm-counters, please run Diagnostic and Repair and'. ' check the gm-counters file.' ); } ## TODO: THIS CODE DUPLICATES IN GM_DIAGNOSTICSPERFORM # $checkentrycounter = $newentrynumber; my $checkentrycounter = $gmCounters->{'entrytotal'}; my %rebuiltentrylist = (); do { my $checkentrycounterpadded = Gm_Utils::toEntryPadded( $checkentrycounter ); my $entryVars = getEntryVariables( entryid=>$checkentrycounter, errHandler=>$errHandler ); my $checkentryopenstatus = 'O'; my $checkentrymorestatus = Gm_Constants::N; if( $entryVars->{'thisentryopenstatus'} eq Gm_Constants::CLOSED ){ $checkentryopenstatus = 'C'; } if( $entryVars->{'thisentrymorebody'} ne Gm_Constants::EMPTY ){ $checkentrymorestatus = Gm_Constants::Y; } ## TODO: SHOULD THIS DO DIAGNOSTICS? SHOULD IT REPAIR? $rebuiltentrylist{$entryVars->{'thisentrynumber'}} = { id=>$entryVars->{'thisentrynumber'}, author=>$entryVars->{'thisentryauthor'}, subject=>$entryVars->{'thisentrysubject'}, created=>"$entryVars->{'thisentrymonthmonth'}\/$entryVars->{'thisentrydayday'}\/$entryVars->{'thisentryyear'}", createt=>"$entryVars->{'thisentryhourhour'}\:$entryVars->{'thisentryminuteminute'} $entryVars->{'thisentryampm'}", status=>$checkentryopenstatus, extended=>$checkentrymorestatus, music=>$entryVars->{'thisentrymusic'}, mood=>$entryVars->{'thisentrymood'}, emoticons=>$entryVars->{'thisentryemoticonsallowed'} }; $checkentrycounter--; } until $checkentrycounter < 1; Gm_Storage::setEntrylist( list=>\%rebuiltentrylist, errHandler=>$errHandler ); } ## Translate Archive Templates # Takes all the templates setup by the getArchiveVariables and applies them to # and gm template tokens in the given template string # ARG template => the template to which the given vars should be applied # ARG archiveVars => the output of getArchiveVariables # (opt) ARG errHandler => the error handler used to display errors # RETURN: a string that has had the archive variables applied to the given template # DEPRECATES: entrylistsubsub sub translateArchiveTemplates { my (%params) = @_; ## Setting up vars my $errHandler = $params{'errHandler'} || \&Gm_Utils::gmWarn; my $listsubsub = $params{'template'} || ''; my $archiveVars = $params{'archiveVars'} || &$errHandler('Invalid archiveVars parameter passed to translateArchiveTemplates'); #### ## TODO REFACTOR THIS INTO A LOOP, SIMPLY DO /{{$KEY}}/$A->{$KEY}/GI ### VARIABLES HAVE TO BE RENAMED TO TEMPLATE NAMES FOR SOME $listsubsub =~ s/{{year}}/$archiveVars->{'loglistyear'}/gi; $listsubsub =~ s/{{yearyear}}/$archiveVars->{'loglistyearyear'}/gi; $listsubsub =~ s/{{month}}/$archiveVars->{'loglistmonth'}/gi; $listsubsub =~ s/{{monthmonth}}/$archiveVars->{'loglistmonthmonth'}/gi; $listsubsub =~ s/{{monthword}}/$archiveVars->{'loglistmonthword'}/gi; $listsubsub =~ s/{{monthwordshort}}/$archiveVars->{'loglistmonthwordshort'}/gi; $listsubsub =~ s/{{monthwordupper}}/$archiveVars->{'loglistmonthwordupper'}/gi; $listsubsub =~ s/{{monthwordlower}}/$archiveVars->{'loglistmonthwordlower'}/gi; $listsubsub =~ s/{{monthworduppershort}}/$archiveVars->{'loglistmonthworduppershort'}/gi; $listsubsub =~ s/{{monthwordlowershort}}/$archiveVars->{'loglistmonthwordlowershort'}/gi; $listsubsub =~ s/{{day}}/$archiveVars->{'loglistday'}/gi; $listsubsub =~ s/{{dayday}}/$archiveVars->{'loglistdayday'}/gi; $listsubsub =~ s/{{hour}}/$archiveVars->{'loglisthour'}/gi; $listsubsub =~ s/{{hourhour}}/$archiveVars->{'loglisthourhour'}/gi; $listsubsub =~ s/{{militaryhour}}/$archiveVars->{'loglistmilitaryhour'}/gi; $listsubsub =~ s/{{minute}}/$archiveVars->{'loglistminute'}/gi; $listsubsub =~ s/{{minuteminute}}/$archiveVars->{'loglistminuteminute'}/gi; $listsubsub =~ s/{{ampm}}/$archiveVars->{'loglistampm'}/gi; $listsubsub =~ s/{{ampmlower}}/$archiveVars->{'loglistampmlower'}/gi; $listsubsub =~ s/{{ampmdot}}/$archiveVars->{'loglistampmdot'}/gi; $listsubsub =~ s/{{ampmdotlower}}/$archiveVars->{'loglistampmdotlower'}/gi; $listsubsub =~ s/{{author}}/$archiveVars->{'loglistauthor'}/gi; ## DUPLICATED BELOW, but needed? $listsubsub =~ s/{{entrysubject}}/$archiveVars->{'loglistsubject'}/gi; $listsubsub =~ s/{{entrynumber}}/$archiveVars->{'loglistnumber'}/gi; $listsubsub =~ s/{{entrynumberpadded}}/$archiveVars->{'loglistnumberpadded'}/gi; $listsubsub =~ s/{{pagelink}}/$archiveVars->{'loglistpagelink'}/gi; $listsubsub =~ s/{{pagearchivelogindexlink}}/$archiveVars->{'loglistpagearchivelogindexlink'}/gi; $listsubsub =~ s/{{entrymusic}}/$archiveVars->{'loglistentrymusic'}/gi; $listsubsub =~ s/{{entrymood}}/$archiveVars->{'loglistentrymood'}/gi; if ($listsubsub =~ m/{{author/i) { $listsubsub =~ s/{{author}}/$archiveVars->{'loglistentryauthor'}/gi; $listsubsub =~ s/{{authoremail}}/$archiveVars->{'loglistentryauthoremail'}/gi; $listsubsub =~ s/{{authorhomepage}}/$archiveVars->{'loglistentryauthorhomepage'}/gi; $listsubsub =~ s/{{authorentrycount}}/$archiveVars->{'loglistentryauthorentrycount'}/gi; } if (($listsubsub =~ m/{{weekbeginning/i) || ($listsubsub =~ m/{{weekending/i)) { $listsubsub =~ s/{{weekbeginningday}}/$archiveVars->{'loglistweekbeginningday'}/gi; $listsubsub =~ s/{{weekbeginningdayday}}/$archiveVars->{'loglistweekbeginningdayday'}/gi; $listsubsub =~ s/{{weekbeginningmonth}}/$archiveVars->{'loglistweekbeginningmonth'}/gi; $listsubsub =~ s/{{weekbeginningmonthmonth}}/$archiveVars->{'loglistweekbeginningmonthmonth'}/gi; $listsubsub =~ s/{{weekbeginningyear}}/$archiveVars->{'loglistweekbeginningyear'}/gi; $listsubsub =~ s/{{weekbeginningyearyear}}/$archiveVars->{'loglistweekbeginningyearyear'}/gi; $listsubsub =~ s/{{weekbeginningweekday}}/$archiveVars->{'loglistweekbeginningweekday'}/gi; $listsubsub =~ s/{{weekbeginningweekdayshort}}/$archiveVars->{'loglistweekbeginningweekdayshort'}/gi; $listsubsub =~ s/{{weekbeginningmonthword}}/$archiveVars->{'loglistweekbeginningmonthword'}/gi; $listsubsub =~ s/{{weekbeginningmonthwordshort}}/$archiveVars->{'loglistweekbeginningmonthwordshort'}/gi; $listsubsub =~ s/{{weekbeginningweekdayupper}}/$archiveVars->{'loglistweekbeginningweekdayupper'}/gi; $listsubsub =~ s/{{weekbeginningmonthwordupper}}/$archiveVars->{'loglistweekbeginningmonthwordupper'}/gi; $listsubsub =~ s/{{weekbeginningweekdaylower}}/$archiveVars->{'loglistweekbeginningweekdaylower'}/gi; $listsubsub =~ s/{{weekbeginningmonthwordlower}}/$archiveVars->{'loglistweekbeginningmonthwordlower'}/gi; $listsubsub =~ s/{{weekbeginningweekdayuppershort}}/$archiveVars->{'loglistweekbeginningweekdayuppershort'}/gi; $listsubsub =~ s/{{weekbeginningmonthworduppershort}}/$archiveVars->{'loglistweekbeginningmonthworduppershort'}/gi; $listsubsub =~ s/{{weekbeginningweekdaylowershort}}/$archiveVars->{'loglistweekbeginningweekdaylowershort'}/gi; $listsubsub =~ s/{{weekbeginningmonthwordlowershort}}/$archiveVars->{'loglistweekbeginningmonthwordlowershort'}/gi; $listsubsub =~ s/{{weekendingday}}/$archiveVars->{'loglistweekendingday'}/gi; $listsubsub =~ s/{{weekendingdayday}}/$archiveVars->{'loglistweekendingdayday'}/gi; $listsubsub =~ s/{{weekendingmonth}}/$archiveVars->{'loglistweekendingmonth'}/gi; $listsubsub =~ s/{{weekendingmonthmonth}}/$archiveVars->{'loglistweekendingmonthmonth'}/gi; $listsubsub =~ s/{{weekendingyear}}/$archiveVars->{'loglistweekendingyear'}/gi; $listsubsub =~ s/{{weekendingyearyear}}/$archiveVars->{'loglistweekendingyearyear'}/gi; $listsubsub =~ s/{{weekendingweekday}}/$archiveVars->{'loglistweekendingweekday'}/gi; $listsubsub =~ s/{{weekendingweekdayshort}}/$archiveVars->{'loglistweekendingweekdayshort'}/gi; $listsubsub =~ s/{{weekendingmonthword}}/$archiveVars->{'loglistweekendingmonthword'}/gi; $listsubsub =~ s/{{weekendingmonthwordshort}}/$archiveVars->{'loglistweekendingmonthwordshort'}/gi; $listsubsub =~ s/{{weekendingweekdayupper}}/$archiveVars->{'loglistweekendingweekdayupper'}/gi; $listsubsub =~ s/{{weekendingmonthwordupper}}/$archiveVars->{'loglistweekendingmonthwordupper'}/gi; $listsubsub =~ s/{{weekendingweekdaylower}}/$archiveVars->{'loglistweekendingweekdaylower'}/gi; $listsubsub =~ s/{{weekendingmonthwordlower}}/$archiveVars->{'loglistweekendingmonthwordlower'}/gi; $listsubsub =~ s/{{weekendingweekdayuppershort}}/$archiveVars->{'loglistweekendingweekdayuppershort'}/gi; $listsubsub =~ s/{{weekendingmonthworduppershort}}/$archiveVars->{'loglistweekendingmonthworduppershort'}/gi; $listsubsub =~ s/{{weekendingweekdaylowershort}}/$archiveVars->{'loglistweekendingweekdaylowershort'}/gi; $listsubsub =~ s/{{weekendingmonthwordlowershort}}/$archiveVars->{'loglistweekendingmonthwordlowershort'}/gi; } if (($listsubsub =~ m/karma}}/i) || ($listsubsub =~ m/karmalink}}/i)) { $listsubsub =~ s/{{positivekarmalink}}/$archiveVars->{'loglistentrypositivekarmalink'}/gi; $listsubsub =~ s/{{negativekarmalink}}/$archiveVars->{'loglistentrynegativekarmalink'}/gi; $listsubsub =~ s/{{positivekarma}}/$archiveVars->{'loglistentrypositivekarma'}/gi; $listsubsub =~ s/{{negativekarma}}/$archiveVars->{'loglistentrynegativekarma'}/gi; $listsubsub =~ s/{{totalkarma}}/$archiveVars->{'loglistentrytotalkarma'}/gi; } if ($listsubsub =~ m/{{comments/i) { $listsubsub =~ s/{{commentsnumber}}/$archiveVars->{'loglistentrycommentsnumber'}/gi; $listsubsub =~ s/{{commentstatussmart}}/$archiveVars->{'loglistentrycommentstatussmart'}/gi; $listsubsub =~ s/{{commentstatussmartupper}}/$archiveVars->{'loglistentrycommentstatussmartupper'}/gi; $listsubsub =~ s/{{commentstatussmartlower}}/$archiveVars->{'loglistentrycommentstatussmartlower'}/gi; } if( $listsubsub =~ m/{{entry/i ){ $listsubsub =~ s/{{entrymainbody}}/$archiveVars->{'loglistmainbody'}/gi; $listsubsub =~ s/{{entrymorebody}}/$archiveVars->{'loglistmorebody'}/gi; ## $listsubsub =~ s/{{entrycomments}}/$loglistcomments/gi; ## NO REFERENCE, COPY AND PASTE? if( $listsubsub =~ m/{{entrymainbodyfirstwords (\d+)}}/i ){ until( $listsubsub !~ m/{{entrymainbodyfirstwords (\d+)}}/isg ){ my $firstwordscount = $1; my $grabmainbodywords = $archiveVars->{'loglistmainbody'}; if( $grabmainbodywords =~ m/{{link/i ){ $grabmainbodywords =~ s/({{linkmo) (http|https|ftp)(:\/\/\S+?) (.+?)(\|)(.+?)(}})/$4/isg; $grabmainbodywords =~ s/({{link) (http|https|ftp)(:\/\/\S+?)(}})/$2$3/isg; $grabmainbodywords =~ s/({{link) (http|https|ftp)(:\/\/\S+?) (.+?)(}})/$4/isg; # {{linkblank}} TEMPLATE VARIABLE SO THAT CAN USE target="_blank" TO OPEN NEW WINDOWS $grabmainbodywords =~ s/({{linkblankmo) (http|https|ftp)(:\/\/\S+?) (.+?)(\|)(.+?)(}})/$4/isg; $grabmainbodywords =~ s/({{linkblank) (http|https|ftp)(:\/\/\S+?)(}})/$2$3/isg; $grabmainbodywords =~ s/({{linkblank) (http|https|ftp)(:\/\/\S+?) (.+?)(}})/$4/isg; } if( $grabmainbodywords =~ m/{{email/i ){ $grabmainbodywords =~ s/({{emailmo) (\S+\@\S+?) (.+?)(\|)(.+?)(}})/$3/isg; $grabmainbodywords =~ s/({{email) (\S+\@\S+?)(}})/$2/isg; $grabmainbodywords =~ s/({{email) (\S+\@\S+?) (.+?)(}})/$3/isg; } ## TODO: REFACTOR THIS TO UTIL $grabmainbodywords =~ s/<([^>]|\n)*>/ /g; $grabmainbodywords =~ s/{{(.*?)}}/ /g; $grabmainbodywords =~ s/\n/ /g; $grabmainbodywords =~ s/\r/ /g; $grabmainbodywords =~ s/\|\*\|/ /g; $grabmainbodywords =~ s/^\s+//; $grabmainbodywords =~ s/\s+$//; $grabmainbodywords =~ s/\s{2,}/ /g; my @grabmainbodywordslist = split (/ /, $grabmainbodywords); my @finalmainbodywordslist = (); if( $firstwordscount < 1 ){ $firstwordscount = 1; } for( my $i = 0; $i < $firstwordscount; $i++ ){ # $finalmainbodywordslist[$i] = $grabmainbodywordslist[$i]; push( @finalmainbodywordslist, $grabmainbodywordslist[$i] ) if( defined( $grabmainbodywordslist[$i] ) ); } my $finalmainbodyfirstwords = join (' ', @finalmainbodywordslist); $finalmainbodyfirstwords =~ s/^\s+//; $finalmainbodyfirstwords =~ s/\s+$//; $finalmainbodyfirstwords =~ s/\s{2,}//g; if( substr($finalmainbodyfirstwords, -1) =~ /\W/ ) { chop($finalmainbodyfirstwords); } if( substr($finalmainbodyfirstwords, -1) eq ' ' ){ chop($finalmainbodyfirstwords); } $listsubsub =~ s/{{entrymainbodyfirstwords ($firstwordscount)}}/$finalmainbodyfirstwords/isg; } } if( $listsubsub =~ m/{{entrymorebodyfirstwords (\d+)}}/i ){ until( $listsubsub !~ m/{{entrymorebodyfirstwords (\d+)}}/isg ){ my $firstwordscount = $1; if( $archiveVars->{'loglistmorebody'} eq Gm_Constants::EMPTY ){ $listsubsub =~ s/{{entrymorebodyfirstwords ($firstwordscount)}}//isg; } else { my $grabmorebodywords = $archiveVars->{'loglistmorebody'}; if ($grabmorebodywords =~ m/{{link/i) { $grabmorebodywords =~ s/({{linkmo) (http|https|ftp)(:\/\/\S+?) (.+?)(\|)(.+?)(}})/$4/isg; $grabmorebodywords =~ s/({{link) (http|https|ftp)(:\/\/\S+?)(}})/$2$3/isg; $grabmorebodywords =~ s/({{link) (http|https|ftp)(:\/\/\S+?) (.+?)(}})/$4/isg; # ADDED {{linkblank}} TEMPLATE VARIABLE SO CAN USE target="_blank" TO OPEN NEW WINDOWS $grabmorebodywords =~ s/({{linkblankmo) (http|https|ftp)(:\/\/\S+?) (.+?)(\|)(.+?)(}})/$4/isg; $grabmorebodywords =~ s/({{linkblank) (http|https|ftp)(:\/\/\S+?)(}})/$2$3/isg; $grabmorebodywords =~ s/({{linkblank) (http|https|ftp)(:\/\/\S+?) (.+?)(}})/$4/isg; } if ($grabmorebodywords =~ m/{{email/i) { $grabmorebodywords =~ s/({{emailmo) (\S+\@\S+?) (.+?)(\|)(.+?)(}})/$3/isg; $grabmorebodywords =~ s/({{email) (\S+\@\S+?)(}})/$2/isg; $grabmorebodywords =~ s/({{email) (\S+\@\S+?) (.+?)(}})/$3/isg; } $grabmorebodywords =~ s/<([^>]|\n)*>/ /g; $grabmorebodywords =~ s/{{(.*?)}}/ /g; $grabmorebodywords =~ s/\n/ /g; $grabmorebodywords =~ s/\r/ /g; $grabmorebodywords =~ s/\|\*\|/ /g; $grabmorebodywords =~ s/^\s+//; $grabmorebodywords =~ s/\s+$//; $grabmorebodywords =~ s/\s{2,}/ /g; my @grabmorebodywordslist = split (/ /, $grabmorebodywords); my @finalmorebodywordslist = (); if( $firstwordscount < 1 ){ $firstwordscount = 1; } for( my $i = 0; $i < $firstwordscount; $i++ ){ # $finalmorebodywordslist[$i] = $grabmorebodywordslist[$i]; push( @finalmorebodywordslist, $grabmorebodywordslist[$i] ) if( defined( $grabmorebodywordslist[$i] ) ); } my $finalmorebodyfirstwords = join (' ', @finalmorebodywordslist); $finalmorebodyfirstwords =~ s/^\s+//; $finalmorebodyfirstwords =~ s/\s+$//; $finalmorebodyfirstwords =~ s/\s{2,}//g; if( substr($finalmorebodyfirstwords, -1) =~ /\W/ ){ chop($finalmorebodyfirstwords); } if( substr($finalmorebodyfirstwords, -1) eq ' ' ){ chop($finalmorebodyfirstwords); } $listsubsub =~ s/{{entrymorebodyfirstwords ($firstwordscount)}}/$finalmorebodyfirstwords/isg; } } } } # End of if( $listsubsub =~ m/{{entry/i ){ return( $listsubsub ); } ## Translate Entry Templates # Takes all the templates setup by the getEntryVariables and applies them to # and gm template tokens in the entry # ARG template => the template to apply the tokens to # ARG entryVars => the output of getEntryVariables # (opt) ARG errHandler => the error handler used to display errors # RETURN: a hash reference that contains the variables # DEPRECATES: gm_formatentry sub translateEntryTemplates { my (%params) = @_; ## Setting up vars my $errHandler = $params{'errHandler'} || \&Gm_Utils::gmWarn; my $entrygetreturn = $params{'template'} || ''; my $entryVars = $params{'entryVars'} || &$errHandler('Invalid entryVars parameter passed to translateEntryTemplates'); my $gmEntrylist = Gm_Storage::getEntrylist( errHandler=>$errHandler ); my $gmCounters = Gm_Storage::getCounters( errHandler=>$errHandler ); my $domain = $CONFIGS->{'gmcgiwebpath'}; $domain =~ s@http://([^\/]+)?.*@$1@; my $entryreturn = $entrygetreturn; # $entryreturn =~ s/\|\*\|/\n/g; ## WHY IS THIS COMMENTED OUT? I DIDN'T DO THIS ## TODO: MAKE GENERIC TRANSLATE ENTRY, THIS IS NOT ENTRY SPECIFIC if( ($entryreturn =~ m/{{header}}/i) || ($entryreturn =~ m/{{footer}}/i) || ($entryreturn =~ m/{{sidebar}}/i) ){ $entryreturn =~ s/{{header}}/$TEMPLATES->{'gmheadertemplate'}/gi; $entryreturn =~ s/{{footer}}/$TEMPLATES->{'gmfootertemplate'}/gi; $entryreturn =~ s/{{sidebar}}/$TEMPLATES->{'gmsidebartemplate'}/gi; } ## TODO: MAKE GENERIC TRANSLATE ENTRY, THIS IS NOT ENTRY SPECIFIC if ($entryreturn =~ m/{{custom/i) { $entryreturn =~ s/{{customone}}/$TEMPLATES->{'gmcustomonetemplate'}/gi; $entryreturn =~ s/{{customtwo}}/$TEMPLATES->{'gmcustomtwotemplate'}/gi; $entryreturn =~ s/{{customthree}}/$TEMPLATES->{'gmcustomthreetemplate'}/gi; $entryreturn =~ s/{{customfour}}/$TEMPLATES->{'gmcustomfourtemplate'}/gi; $entryreturn =~ s/{{customfive}}/$TEMPLATES->{'gmcustomfivetemplate'}/gi; $entryreturn =~ s/{{customsix}}/$TEMPLATES->{'gmcustomsixtemplate'}/gi; $entryreturn =~ s/{{customseven}}/$TEMPLATES->{'gmcustomseventemplate'}/gi; $entryreturn =~ s/{{customeight}}/$TEMPLATES->{'gmcustomeighttemplate'}/gi; $entryreturn =~ s/{{customnine}}/$TEMPLATES->{'gmcustomninetemplate'}/gi; $entryreturn =~ s/{{customten}}/$TEMPLATES->{'gmcustomtentemplate'}/gi; } if( $entryreturn =~ m/{{logarchivelist}}/i ){ if( $CONFIGS->{'gmkeepmonthlyarchives'} eq Gm_Constants::NO ){ $entryreturn =~ s/{{logarchivelist}}//gi; } else { my $logarchivelistfinal = generateArchiveLogList( entryVars=>$entryVars, errHandler=>$errHandler ); $entryreturn =~ s/{{logarchivelist}}/$logarchivelistfinal/gi; } } if( $CONFIGS->{'gmgenerateentrypages'} eq Gm_Constants::YES ){ if( ($entryreturn =~ m/{{logshortentrylist/i) || ($entryreturn =~ m/{{logmoreentrylist/i) || ($entryreturn =~ m/{{logentrylist/i) ){ my $entryLogVars = generateEntryLogList( errHandler=>$errHandler ); $entryreturn =~ s/{{logshortentrylist}}/$entryLogVars->{'logshortentrylistfinal'}/gi; $entryreturn =~ s/{{logmoreentrylist}}/$entryLogVars->{'logmoreentrylistfinal'}/gi; $entryreturn =~ s/{{logentrylist}}/$entryLogVars->{'logentrylistfinal'}/gi; $entryreturn =~ s/{{logshortentrylist month}}/$entryLogVars->{'logshortentrylistmonthfinal'}/gi; $entryreturn =~ s/{{logshortentrylist day}}/$entryLogVars->{'logshortentrylistdayfinal'}/gi; $entryreturn =~ s/{{logshortentrylist year}}/$entryLogVars->{'logshortentrylistyearfinal'}/gi; $entryreturn =~ s/{{logmoreentrylist month}}/$entryLogVars->{'logmoreentrylistmonthfinal'}/gi; $entryreturn =~ s/{{logmoreentrylist day}}/$entryLogVars->{'logmoreentrylistdayfinal'}/gi; $entryreturn =~ s/{{logmoreentrylist year}}/$entryLogVars->{'logmoreentrylistyearfinal'}/gi; $entryreturn =~ s/{{logentrylist month}}/$entryLogVars->{'logentrylistmonthfinal'}/gi; $entryreturn =~ s/{{logentrylist day}}/$entryLogVars->{'logentrylistdayfinal'}/gi; $entryreturn =~ s/{{logentrylist year}}/$entryLogVars->{'logentrylistyearfinal'}/gi; $entryreturn =~ s/{{logshortentrylist number}}/$entryLogVars->{'logshortentrylistnumberfinal'}/gi; $entryreturn =~ s/{{logmoreentrylist number}}/$entryLogVars->{'logmoreentrylistnumberfinal'}/gi; $entryreturn =~ s/{{logentrylist number}}/$entryLogVars->{'logentrylistnumberfinal'}/gi; $entryreturn =~ s/{{logshortentrylist firsthalf}}/$entryLogVars->{'logshortentrylistfirsthalffinal'}/gi; $entryreturn =~ s/{{logshortentrylist secondhalf}}/$entryLogVars->{'logshortentrylistsecondhalffinal'}/gi; $entryreturn =~ s/{{logmoreentrylist firsthalf}}/$entryLogVars->{'logmoreentrylistfirsthalffinal'}/gi; $entryreturn =~ s/{{logmoreentrylist secondhalf}}/$entryLogVars->{'logmoreentrylistsecondhalffinal'}/gi; $entryreturn =~ s/{{logentrylist firsthalf}}/$entryLogVars->{'logentrylistfirsthalffinal'}/gi; $entryreturn =~ s/{{logentrylist secondhalf}}/$entryLogVars->{'logentrylistsecondhalffinal'}/gi; } if( ($entryreturn =~ m/{{logshortentrylist comments/i) || ($entryreturn =~ m/{{logmoreentrylist comments/i) || ($entryreturn =~ m/{{logentrylist comments/i) ){ my $entryLogCommentVars = generateEntryLogListComments( errHandler=>$errHandler ); $entryreturn =~ s/{{logshortentrylist comments}}/$entryLogCommentVars->{'logshortentrylistfinal'}/gi; $entryreturn =~ s/{{logmoreentrylist comments}}/$entryLogCommentVars->{'logmoreentrylistfinal'}/gi; $entryreturn =~ s/{{logentrylist comments}}/$entryLogCommentVars->{'logentrylistfinal'}/gi; $entryreturn =~ s/{{logshortentrylist commentsminimum}}/$entryLogCommentVars->{'logshortminimumentrylistfinal'}/gi; $entryreturn =~ s/{{logmoreentrylist commentsminimum}}/$entryLogCommentVars->{'logmoreminimumentrylistfinal'}/gi; $entryreturn =~ s/{{logentrylist commentsminimum}}/$entryLogCommentVars->{'logminimumentrylistfinal'}/gi; $entryreturn =~ s/{{logshortentrylist commentsnumber}}/$entryLogCommentVars->{'logshortnumberentrylistfinal'}/gi; $entryreturn =~ s/{{logmoreentrylist commentsnumber}}/$entryLogCommentVars->{'logmorenumberentrylistfinal'}/gi; $entryreturn =~ s/{{logentrylist commentsnumber}}/$entryLogCommentVars->{'lognumberentrylistfinal'}/gi; } if (($entryreturn =~ m/{{logshortentrylist /i) || ($entryreturn =~ m/{{logmoreentrylist /i) || ($entryreturn =~ m/{{logentrylist /i)) { my $gmauthors = Gm_Storage::getAuthors( errHandler=>$errHandler ); foreach my $author ( keys( %$gmauthors ) ) { my $thisentryloglistauthor = $gmauthors->{$author}{'author'}; my $entryLogAuthorVars = generateEntryLogListAuthor( author=>$thisentryloglistauthor, errHandler=>$errHandler ); $entryreturn =~ s/{{logshortentrylist $thisentryloglistauthor}}/$entryLogAuthorVars->{'logshortentrylistfinal'}/gi; $entryreturn =~ s/{{logmoreentrylist $thisentryloglistauthor}}/$entryLogAuthorVars->{'logmoreentrylistfinal'}/gi; $entryreturn =~ s/{{logentrylist $thisentryloglistauthor}}/$entryLogAuthorVars->{'logentrylistfinal'}/gi; } } } ## End of if generate entry pages if (($entryreturn =~ m/{{calendar}}/i) || ($entryreturn =~ m/{{calendarweek}}/i)) { my $usethisentryweekdaynumber = $entryVars->{'thisentryweekdaynumber'}; my $usethisentryday = $entryVars->{'thisentryday'}; my $usethisentrymonth = $entryVars->{'thisentrymonth'}; my $usethisentrymonthmonth = $entryVars->{'thisentrymonthmonth'}; my $usethisentrymonthword = $entryVars->{'thisentrymonthword'}; my $usethisentryyear = $entryVars->{'thisentryyear'}; my $usethisentryyearyear = $entryVars->{'thisentryyearyear'}; my ($calendarfull, $calendarweekfull) = generateCalendar( entryVars=>$entryVars, errHandler=>$errHandler ); $entryreturn =~ s/{{calendar}}/$calendarfull/gi; $entryreturn =~ s/{{calendarweek}}/$calendarweekfull/gi; } if( $entryreturn =~ m/{{calendar (..)\/(..)}}/i ){ my @sortedentries = sort { $gmEntrylist->{$b}{'id'} <=> $gmEntrylist->{$a}{'id'} } keys( %$gmEntrylist ); until( $entryreturn !~ m/{{calendar (..)\/(..)}}/ig ){ my $usethisentrymonthmonth = $1; my $usethisentryyear = $2; my $gotthecalendarmonth = Gm_Constants::NO; foreach my $entry ( @sortedentries ) { my $loglistnumber = $gmEntrylist->{$entry}{'id'}; my $loglistauthor = $gmEntrylist->{$entry}{'author'}; my $loglistsubject = $gmEntrylist->{$entry}{'subject'}; my $loglistdate = $gmEntrylist->{$entry}{'created'}; my $loglisttimeampm = $gmEntrylist->{$entry}{'createt'}; my $loglistopenstatus = $gmEntrylist->{$entry}{'status'}; my $loglistmorestatus = $gmEntrylist->{$entry}{'extended'}; my $loglistentrymusic = $gmEntrylist->{$entry}{'music'}; my $loglistentrymood = $gmEntrylist->{$entry}{'mood'}; my $loglistemoticonstatus = $gmEntrylist->{$entry}{'emoticons'}; my $gmLogListVars = getArchiveVariables( listEntry=>$gmEntrylist->{$entry} , errHandler=>$errHandler ); if( ($gmLogListVars->{loglistmonthmonth} eq $usethisentrymonthmonth) && ($gmLogListVars->{'loglistyear'} eq $usethisentryyear) && ($gotthecalendarmonth eq Gm_Constants::NO) ){ my %temp = (); $temp{'usethisentryweekdaynumber'} = $gmLogListVars->{'loglistentryweekdaynumber'}; $temp{'usethisentryday'} = $gmLogListVars->{'loglistday'}; $temp{'usethisentrymonth'} = $gmLogListVars->{'loglistmonth'}; $temp{'usethisentrymonthword'} = $gmLogListVars->{'loglistmonthword'}; $temp{'usethisentryyearyear'} = $gmLogListVars->{'loglistyearyear'}; ## wonky ness to not pollute entryVars %temp = ( %temp, %$entryVars ); my ($calendarfull, $calendarweekfull) = generateCalendar( entryVars=>\%temp, errHandler=>$errHandler ); $entryreturn =~ s/{{calendar $usethisentrymonthmonth\/$usethisentryyear}}/$calendarfull/gi; $gotthecalendarmonth = Gm_Constants::YES; } } ## seem to be deleting if not in the entries ( just finished looping ) if ($entryreturn =~ m/{{calendar $usethisentrymonthmonth\/$usethisentryyear}}/i) { $entryreturn =~ s/{{calendar $usethisentrymonthmonth\/$usethisentryyear}}//gi; } } } # emoticons can be off, so we provide {{smartemoticonscode}} to print them only when they are needed/wanted if( ($entryreturn =~ m/{{commentdivider}}/i) || ($entryreturn =~ m/{{entrycommentsform}}/i) || ($entryreturn =~ m/{{entrykarmaform}}/i) || ($entryreturn =~ m/{{searchform}}/i) ){ $entryreturn =~ s/{{commentdivider}}/$entryVars->{'thisentrycommentdivider'}/gi; $entryreturn =~ s/{{entrycommentsform}}/$entryVars->{'thisentrycommentsform'}/gi; $entryreturn =~ s/{{entrykarmaform}}/$entryVars->{'thisentrykarmaform'}/gi; $entryreturn =~ s/{{searchform}}/$entryVars->{'thisentrysearchform'}/gi; } if( $entryreturn =~ m/{{entry/i ){ $entryreturn =~ s/{{entrymainbody}}/$entryVars->{'thisentrymainbody'}/gi; $entryreturn =~ s/{{entrymorebody}}/$entryVars->{'thisentrymorebody'}/gi; $entryreturn =~ s/{{entrycomments}}/$entryVars->{'thisentrycomments'}/gi; if( $entryreturn =~ m/{{entrymainbodyfirstwords (\d+)}}/i ){ until( $entryreturn !~ m/{{entrymainbodyfirstwords (\d+)}}/isg ){ my $firstwordscount = $1; my $grabmainbodywords = $entryVars->{'thisentrymainbody'}; if( $grabmainbodywords =~ m/{{link/i ){ $grabmainbodywords =~ s/({{linkmo) (http|https|ftp)(:\/\/\S+?) (.+?)(\|)(.+?)(}})/$4/isg; $grabmainbodywords =~ s/({{link) (http|https|ftp)(:\/\/\S+?)(}})/$2$3/isg; $grabmainbodywords =~ s/({{link) (http|https|ftp)(:\/\/\S+?) (.+?)(}})/$4/isg; # ADDED {{linkblank}} TEMPLATE VARIABLE TO USE target="_blank" TO OPEN NEW WINDOWS $grabmainbodywords =~ s/({{linkblankmo) (http|https|ftp)(:\/\/\S+?) (.+?)(\|)(.+?)(}})/$4/isg; $grabmainbodywords =~ s/({{linkblank) (http|https|ftp)(:\/\/\S+?)(}})/$2$3/isg; $grabmainbodywords =~ s/({{linkblank) (http|https|ftp)(:\/\/\S+?) (.+?)(}})/$4/isg; } if( $grabmainbodywords =~ m/{{email/i ){ $grabmainbodywords =~ s/({{emailmo) (\S+\@\S+?) (.+?)(\|)(.+?)(}})/$3/isg; $grabmainbodywords =~ s/({{email) (\S+\@\S+?)(}})/$2/isg; $grabmainbodywords =~ s/({{email) (\S+\@\S+?) (.+?)(}})/$3/isg; } ## TODO: REFACTOR THIS TO UTILS $grabmainbodywords =~ s/<([^>]|\n)*>/ /g; $grabmainbodywords =~ s/{{(.*?)}}/ /g; $grabmainbodywords =~ s/\n/ /g; $grabmainbodywords =~ s/\r/ /g; $grabmainbodywords =~ s/\|\*\|/ /g; $grabmainbodywords =~ s/^\s+//; $grabmainbodywords =~ s/\s+$//; $grabmainbodywords =~ s/\s{2,}/ /g; my @grabmainbodywordslist = split (/ /, $grabmainbodywords); my @finalmainbodywordslist = (); if( $firstwordscount < 1 ){ $firstwordscount = 1; } for( my $i = 0; $i < $firstwordscount; $i++ ){ # $finalmainbodywordslist[$i] = $grabmainbodywordslist[$i]; push( @finalmainbodywordslist, $grabmainbodywordslist[$i] ) if( defined( $grabmainbodywordslist[$i] ) ); } my $finalmainbodyfirstwords = join (' ', @finalmainbodywordslist); $finalmainbodyfirstwords =~ s/^\s+//; $finalmainbodyfirstwords =~ s/\s+$//; $finalmainbodyfirstwords =~ s/\s{2,}//g; if( substr($finalmainbodyfirstwords, -1 ) =~ /\W/) { chop($finalmainbodyfirstwords); ## TODO: could this be chomped? } if( substr($finalmainbodyfirstwords, -1) eq ' '){ chop($finalmainbodyfirstwords); ## TODO: CHOMP? } $entryreturn =~ s/{{entrymainbodyfirstwords ($firstwordscount)}}/$finalmainbodyfirstwords/isg; } } ## TODO: THIS SECTION SIMILAR TO ABOVE, MAKE SUBROUTINE? if( $entryreturn =~ m/{{entrymorebodyfirstwords (\d+)}}/i ){ until( $entryreturn !~ m/{{entrymorebodyfirstwords (\d+)}}/isg ){ my $firstwordscount = $1; if( $entryVars->{'thisentrymorebody'} eq Gm_Constants::EMPTY ){ $entryreturn =~ s/{{entrymorebodyfirstwords ($firstwordscount)}}//isg; } else { my $grabmorebodywords = $entryVars->{'thisentrymorebody'}; if( $grabmorebodywords =~ m/{{link/i ){ $grabmorebodywords =~ s/({{linkmo) (http|https|ftp)(:\/\/\S+?) (.+?)(\|)(.+?)(}})/$4/isg; $grabmorebodywords =~ s/({{link) (http|https|ftp)(:\/\/\S+?)(}})/$2$3/isg; $grabmorebodywords =~ s/({{link) (http|https|ftp)(:\/\/\S+?) (.+?)(}})/$4/isg; # ADDED {{linkblank}} TEMPLATE VARIABLE TO USE target="_blank" TO OPEN NEW WINDOWS $grabmorebodywords =~ s/({{linkblankmo) (http|https|ftp)(:\/\/\S+?) (.+?)(\|)(.+?)(}})/$4/isg; $grabmorebodywords =~ s/({{linkblank) (http|https|ftp)(:\/\/\S+?)(}})/$2$3/isg; $grabmorebodywords =~ s/({{linkblank) (http|https|ftp)(:\/\/\S+?) (.+?)(}})/$4/isg; } if ($grabmorebodywords =~ m/{{email/i) { $grabmorebodywords =~ s/({{emailmo) (\S+\@\S+?) (.+?)(\|)(.+?)(}})/$3/isg; $grabmorebodywords =~ s/({{email) (\S+\@\S+?)(}})/$2/isg; $grabmorebodywords =~ s/({{email) (\S+\@\S+?) (.+?)(}})/$3/isg; } $grabmorebodywords =~ s/<([^>]|\n)*>/ /g; $grabmorebodywords =~ s/{{(.*?)}}/ /g; $grabmorebodywords =~ s/\n/ /g; $grabmorebodywords =~ s/\r/ /g; $grabmorebodywords =~ s/\|\*\|/ /g; $grabmorebodywords =~ s/^\s+//; $grabmorebodywords =~ s/\s+$//; $grabmorebodywords =~ s/\s{2,}/ /g; my @grabmorebodywordslist = split (/ /, $grabmorebodywords); my @finalmorebodywordslist = (); if( $firstwordscount < 1 ){ $firstwordscount = 1; } for( my $i = 0; $i < $firstwordscount; $i++ ){ # $finalmorebodywordslist[$i] = $grabmorebodywordslist[$i]; push( @finalmorebodywordslist, $grabmorebodywordslist[$i] ) if( defined( $grabmorebodywordslist[$i] ) ); } my $finalmorebodyfirstwords = join (' ', @finalmorebodywordslist); $finalmorebodyfirstwords =~ s/^\s+//; $finalmorebodyfirstwords =~ s/\s+$//; $finalmorebodyfirstwords =~ s/\s{2,}//g; if( substr($finalmorebodyfirstwords, -1) =~ /\W/ ){ chop($finalmorebodyfirstwords); ## TODO: CHOMP? } if( substr($finalmorebodyfirstwords, -1) eq ' ' ){ chop($finalmorebodyfirstwords); ## TODO: CHOMP? } $entryreturn =~ s/{{entrymorebodyfirstwords ($firstwordscount)}}/$finalmorebodyfirstwords/isg; } } } } if (($entryreturn =~ m/link}}/i) || ($entryreturn =~ m/{{morepreface}}/i)) { $entryreturn =~ s/{{karmalink}}/$entryVars->{'thisentrykarmalink'}/gi; $entryreturn =~ s/{{commentslink}}/$entryVars->{'thisentrycommentslink'}/gi; $entryreturn =~ s/{{pagelink}}/$entryVars->{'thisentrypagelink'}/gi; $entryreturn =~ s/{{pageindexlink}}/$entryVars->{'thisentrypageindexlink'}/gi; $entryreturn =~ s/{{pagearchiveindexlink}}/$entryVars->{'thisentrypagearchiveindexlink'}/gi; $entryreturn =~ s/{{pagearchivelogindexlink}}/$entryVars->{'thisentrypagearchivelogindexlink'}/gi; $entryreturn =~ s/{{pagesmartindexlink}}/$entryVars->{'thisentrypagesmartindexlink'}/gi; $entryreturn =~ s/{{commentspostlink}}/$entryVars->{'thisentrycommentspostlink'}/gi; $entryreturn =~ s/{{authorsmartlink}}/$entryVars->{'thisentryauthorsmartlink'}/gi; } if( ($entryreturn =~ m/karma}}/i) || ($entryreturn =~ m/karmalink}}/i) ){ $entryreturn =~ s/{{positivekarmalink}}/$entryVars->{'thisentrypositivekarmalink'}/gi; $entryreturn =~ s/{{negativekarmalink}}/$entryVars->{'thisentrynegativekarmalink'}/gi; $entryreturn =~ s/{{positivekarma}}/$entryVars->{'thisentrypositivekarma'}/gi; $entryreturn =~ s/{{negativekarma}}/$entryVars->{'thisentrynegativekarma'}/gi; $entryreturn =~ s/{{totalkarma}}/$entryVars->{'thisentrytotalkarma'}/gi; } if( $entryreturn =~ m/{{smart/i ){ if ($entryVars->{'thisentrymusic'} ne Gm_Constants::EMPTY) { $entryreturn =~ s/{{smartentrymusic}}/$TEMPLATES->{'gmsmartentrymusictemplate'}/gi; } else { $entryreturn =~ s/{{smartentrymusic}}//gi; } if ($entryVars->{'thisentrymood'} ne Gm_Constants::EMPTY) { $entryreturn =~ s/{{smartentrymood}}/$TEMPLATES->{'gmsmartentrymoodtemplate'}/gi; } else { $entryreturn =~ s/{{smartentrymood}}//gi; } } if( $entryreturn =~ m/{{entry/i ){ $entryreturn =~ s/{{entrysubject}}/$entryVars->{'thisentrysubject'}/gi; # ADDED 1 TEMPLATE VARIABLE SO THAT I CAN STRIP THE HTML CODE FROM THE ENTRYSUBJECT # WHEN IT IS USED IN THE