aboutsummaryrefslogtreecommitdiff
path: root/h-source/Library/Functions.php
diff options
context:
space:
mode:
authorYuchen Pei <me@ypei.me>2021-07-29 14:17:20 +1000
committerYuchen Pei <me@ypei.me>2021-07-29 14:17:20 +1000
commit3ff03dc4f0a72432b34c00da620272cf011e4ddd (patch)
tree5746711ba17a91aed56c6529ea8cceb06c3ad16a /h-source/Library/Functions.php
parentcd4534aa10ba3b122963992741721289fa50d0ab (diff)
Publishing h-node.org code.
- this is the h-node.org code, except - removed a js file (3x copies at three different locations) without license / copyright headers - /Js/linkToForm.js - /Public/Js/linkToForm.js - /admin/Public/Js/linkToForm.js - removed config files containing credentials - /Application/Include/params.php - /Config/Config.php - /admin/Application/Include/params.php - /admin/Config/Config.php - added license and copyright header to one php file - /admin/Library/ErrorReporting.php (almost identical to /Library/ErrorReporting.php which has the headers)
Diffstat (limited to 'h-source/Library/Functions.php')
-rwxr-xr-xh-source/Library/Functions.php186
1 files changed, 7 insertions, 179 deletions
diff --git a/h-source/Library/Functions.php b/h-source/Library/Functions.php
index ef86812..1477680 100755
--- a/h-source/Library/Functions.php
+++ b/h-source/Library/Functions.php
@@ -2,7 +2,7 @@
// EasyGiant is a PHP framework for creating and managing dynamic content
//
-// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com)
+// Copyright (C) 2009 - 2011 Antonio Gallo
// See COPYRIGHT.txt and LICENSE.txt.
//
// This file is part of EasyGiant
@@ -108,24 +108,12 @@ SANITIZE DEEP
function stripslashesDeep($value) {
if(get_magic_quotes_gpc()) {#if stripslashes
- return array_map_recursive('stripslashes', $value);
+ return array_map('stripslashes', $value);
}
return $value;
}
-//from http://www.php.net/array_map#112857
-function array_map_recursive($callback, $array) {
- foreach ($array as $key => $value) {
- if (is_array($array[$key])) {
- $array[$key] = array_map_recursive($callback, $array[$key]);
- }
- else {
- $array[$key] = call_user_func($callback, $array[$key]);
- }
- }
- return $array;
-}
-
+
function sanitizeHtmlDeep($value) {
return array_map('sanitizeHtml', $value);
}
@@ -175,9 +163,7 @@ function sha1Deep($value)
return array_map('sha1', $value);
}
-function strip_tagsDeep($value) {
- return array_map('strip_tags', $value);
-}
+
@@ -242,75 +228,6 @@ function wrap($string,$tag_class) {#wrap the string with the tag and its class
return $str_front.$string.$str_rear;
}
-//check that $date is a ISO date (YYYY-MM-DD)
-function checkIsoDate($date)
-{
- if (preg_match('/^[0-9]{4}\-[0-9]{2}\-[0-9]{2}$/',$date))
- {
- $dateArray = explode('-',$date);
- if ((int)$dateArray[1] <= 12 and (int)$dateArray[1] >= 1 )
- {
- if ((int)$dateArray[2] >= 1 and (int)$dateArray[2] <= 31)
- {
- return checkdate((int)$dateArray[1],(int)$dateArray[2],(int)$dateArray[0]);
- }
- }
- }
- return false;
-}
-
-//check if $string is an integer string
-function checkInteger($string)
-{
- if (preg_match('/^\-?[0-9]{1,}$/',$string))
- {
- return true;
- }
- return false;
-}
-
-//check if $string is decimal with the format indicated in $format
-//$format: M,D M is the maximum number of digits, D is the number of digits to the right of the decimal point
-function checkDecimal($string, $format)
-{
- $t = explode(",",$format);
- $M = (int)$t[0];
- $D = (int)$t[1];
- $I = $M - $D;
-
- if (preg_match("/^[0-9]{1,$I}(\.[0-9]{1,$D})?$/",$string))
- {
- return true;
- }
- return false;
-}
-
-//get label name from field name
-function getFieldLabel($fieldName)
-{
- if (class_exists("Lang_".Params::$language."_Formats_Fields"))
- {
- return call_user_func(array("Lang_".Params::$language."_Formats_Fields", "getLabel"), $fieldName);
- }
-
- return call_user_func(array("Lang_En_Formats_Fields", "getLabel"), $fieldName);
-
-// if (strstr($fieldName,","))
-// {
-// $temp = explode(",",$fieldName);
-// for ($i=0; $i< count($temp); $i++)
-// {
-// $temp[$i] = getFieldLabel($temp[$i]);
-// }
-// return implode (" and ",$temp);
-// }
-// else
-// {
-// $fieldName = str_replace("_"," ", $fieldName);
-// return ucfirst($fieldName);
-// }
-}
-
//generate a random password
//$start: start number of mt_rand
//$end: end number of mt_rand
@@ -349,7 +266,7 @@ function getIp()
$ip = sanitizeIp($_SERVER["HTTP_X_FORWARDED_FOR"]);
} else if (!empty($_SERVER["HTTP_CLIENT_IP"])) {
$ip = sanitizeIp($_SERVER["HTTP_CLIENT_IP"]);
- } else if (!empty($_SERVER["REMOTE_ADDR"])) {
+ } else {
$ip = sanitizeIp($_SERVER["REMOTE_ADDR"]);
}
} else {
@@ -357,7 +274,7 @@ function getIp()
$ip = sanitizeIp(getenv( 'HTTP_X_FORWARDED_FOR' ));
} else if ( getenv( 'HTTP_CLIENT_IP' ) !== false ) {
$ip = sanitizeIp(getenv( 'HTTP_CLIENT_IP' ));
- } else if ( getenv( 'REMOTE_ADDR' ) !== false ) {
+ } else {
$ip = sanitizeIp(getenv( 'REMOTE_ADDR' ));
}
}
@@ -377,76 +294,6 @@ function getUserAgent() {
}
}
-//encode a string to drop ugly characters
-function encode($url)
-{
- $url = utf8_decode(html_entity_decode($url,ENT_QUOTES,'UTF-8'));
-
- $temp = null;
-
- for ($i=0;$i<eg_strlen($url); $i++)
- {
-// echo substr($url,$i,1)."<br />";
- if (strcmp(substr($url,$i,1),' ') === 0)
- {
- $temp .= '_';
- }
- else if (strcmp(substr($url,$i,1),"'") === 0)
- {
- $temp .= '';
- }
- else
- {
- if (preg_match('/^[a-zA-Z\_0-9]$/',substr($url,$i,1)))
- {
- $temp .= substr($url,$i,1);
- }
- else
- {
- $temp .= '_';
- }
- }
- }
-
- $temp = urlencode($temp);
- return $temp;
-}
-
-function callFunction($function, $string, $caller = "CallFunction")
-{
- if (strstr($function,'::')) //static method
- {
- $temp = explode('::',$function);
-
- if (!method_exists($temp[0],$temp[1]))
- {
- throw new Exception('Error in <b>'.$caller.'</b>: method <b>'.$temp[1].'</b> of class <b>'.$temp[0].'</b> does not exists.');
- }
-
- return call_user_func(array($temp[0], $temp[1]),$string);
- }
- else if (strstr($function,'.')) //method
- {
- $temp = explode('.',$function);
-
- $obj = new $temp[0]; //new instance of the object
-
- if (!method_exists($obj,$temp[1]))
- {
- throw new Exception('Error in <b>'.$caller.'</b>: method <b>'.$temp[1].'</b> of class <b>'.$temp[0].'</b> does not exists.');
- }
-
- return call_user_func(array($obj, $temp[1]),$string);
- }
- else //function
- {
- if (!function_exists($function)) {
- throw new Exception('Error in <b>'.$caller.'</b>: function <b>'.$function.'</b> does not exists.');
- }
- //apply the function
- return call_user_func($function,$string);
- }
-}
function xml_encode($string)
{
@@ -457,23 +304,4 @@ function xml_encode($string)
}
return strtr($string, $trans);
-}
-
-//Convert Hex Color to RGB
-//http://bavotasan.com/2011/convert-hex-color-to-rgb-using-php/
-function hex2rgb($hex) {
- $hex = str_replace("#", "", $hex);
-
- if(strlen($hex) == 3) {
- $r = hexdec(substr($hex,0,1).substr($hex,0,1));
- $g = hexdec(substr($hex,1,1).substr($hex,1,1));
- $b = hexdec(substr($hex,2,1).substr($hex,2,1));
- } else {
- $r = hexdec(substr($hex,0,2));
- $g = hexdec(substr($hex,2,2));
- $b = hexdec(substr($hex,4,2));
- }
- $rgb = array($r, $g, $b);
- //return implode(",", $rgb); // returns the rgb values separated by commas
- return $rgb; // returns an array with the rgb values
-}
+} \ No newline at end of file