package Gm_Utils;
###############################################################################
# Greymatter 1.7.2
# Copyright (c)2000-2007, 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
###############################################################################
require Exporter;
@ISA = qw(Exporter);
@EXPORT_OK = qw( println ); ## export on request, no pollution
## Gm Storage
# This package groups functions that deal with miscelaneous and various functionality.
# Not all functions have to be exported, but some very very very common ones.
#
# CONVENTIONS
# 1. Return a string rather than printing, this is just more elegant. Leave prints
# to the calling subroutine
# 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.
# 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.
use strict;
use warnings;
use Gm_Constants;
use Gm_Trace;
## TODO, make this stuff POD, at least its a standard ...
## Print Line
# Will print a given line with a newline character at the end. Handly for
# changing newline if ever needed.
# ARG1: The line to print
sub println {
my (@lines) = @_; ## this should: || (), but not sure if works?
my $line = join( "\n", @lines );
print( $line."\n" );
}
## to Web Safe
# Will filter a given line and make websafe, for editing in textarea
# ARG1: The line to filter
# DEPRECATES: delouse
sub toWebSafe {
my $l = shift(@_);
# |*| to newline character
$l =~ s/\|\*\|/\n/g;
# changing ≶ to |AMP|lg;, why? Who knows...
$l =~ s/&([A-Za-z0-9\#]+);/\|AMP\|$1;/g;
# making < and > websafe
$l =~ s/\</g;
$l =~ s/>/\>/g;
# making quote websafe
$l =~ s/"/\"/g;
return($l);
}
## to Store Safe
# Will filter a given line and make storesafe, for editing in textarea
# ARG1: The line to filter
# DEPRECATES: relouse
sub toStoreSafe {
my $l = shift(@_);
# newline character to |*|
$l =~ s/\n/\|\*\|/g;
# removeing newline character?
$l =~ s/\r//g;
# making websafe < and > to normal
$l =~ s/\<//g;
# make websafe quote to normal
$l =~ s/\"/"/g;
# ???
$l =~ s/\|AMP\|([A-Za-z0-9\#]+);/&$1;/g;
return($l);
}
## to Config Safe
# Will filter a given line and make configsave, for storeing
# ARG1: The line to filter
# TODO: CAN THIS ENHANCE STORE ? AND JUST USE STORESAFE
# DEPRECATES: configdelouse
sub toConfigSafe {
my $l = shift(@_);
# remove pipe?
$l =~ s/\|//g;
# remove newline?
$l =~ s/\n//g;
# remove carriage return
$l =~ s/\r//g;
# remove leading spaces
$l =~ s/^\s+//;
# remove trailing spaces
$l =~ s/\s+$//;
return($l);
}
## hack Web Test
# Will test for a hack attempts against web data,
# these are hack attempts against the user
# ARG1: The text to test for iframes and other hackish stuff
# RETURNS: 1 if a hack is detected, 0 otherwise
sub hackWebTest {
my $text = shift(@_) || '';
my $ret_val = 0;
# Testing for someone trying to insert ...
if( $text =~ m/<\s*?\?/gi ){
$ret_val = 1;
}
# Testing for someone trying to insert