* * Copyright (C) 2003 Free Software Foundation * * -------------------------------------------------------------------------* * This library is part of the eGroupWare API * * http://www.egroupware.org/api * * ------------------------------------------------------------------------ * * This program is Free Software; you can redistribute it and/or modify it * * under the terms of the GNU General Public License as published by the * * Free Software Foundation; either version 2 of the License, or (at your * * option) any later version. * \**************************************************************************/ /* $Id$ */ //NOTE This class still needs to be documented and the stubbed methods fixed! class validator { var $error; function clear_error () { $this->nonfree_call(); } /* check if string contains any whitespace */ function has_space ($text) { return ereg("( |\n|\t|\r)+", $text); } function chconvert ($fragment) { $this->nonfree_call(); } function get_perms ($fileName) { $this->nonfree_call(); } function is_sane ($filename) { $this->nonfree_call(); } /* strips all whitespace from a string */ function strip_space ($text) { return ereg_replace("( |\n|\t|\r)+", '', $text); } function is_allnumbers ($text) { $this->nonfree_call(); } function strip_numbers ($text) { $this->nonfree_call(); } function is_allletters ($text) { $this->nonfree_call(); } function strip_letters ($text) { $this->nonfree_call(); } function has_html ($text='') { return ($text != $this->strip_html($text)); } function strip_html ($text='') { return strip_tags($text); } function has_metas ($text='') { return ($text != $this->strip_metas($text)); } function strip_metas ($text = "") { $metas = array('$','^','*','(',')','+','[',']','.','?'); return str_replace($metas, '', stripslashes($text)); } function custom_strip ($Chars, $text = "") { $this->nonfree_call(); } function array_echo ($array, $name='Array') { echo '
'; print_r($array); echo ''; } function is_email ($address='') { list($user, $domain) = explode('@', $address); if(!($user && $domain)) { return false; } if(!$this->has_space($user) && $this->is_host($domain)) { return true; } } function is_url ($url='') { //echo "Checking $url
"; $uris = array( 'ftp' => True, 'https' => True, 'http' => True, ); $url_elements = parse_url($url); //echo ''; //print_r($url_elements); //echo ''; if(!is_array($url_elements)) { return false; } //echo 'Scheme ' . $url_elements['scheme']; if(@$uris[$url_elements['scheme']]) { //echo ' is valid
host ' . $url_elements['host']; if( eregi("[a-z]", $url_elements['host']) ) { //echo ' is name
'; return $this->is_hostname($url_elements['host']); } else { //echo ' is ip
'; return $this->is_ipaddress($url_elements['host']); } } else { //echo ' is invalid
'; return $false; } } //the url may be valid, but this method can't test all types function url_responds ($url='') { if(!$this->is_url($url)) { return false; } $fp=@fopen($url); if($fp) { fclose($fp); return true; } else { return false; } } function is_phone ($Phone='') { $this->nonfree_call(); } function is_hostname ($hostname='') { //echo "Checking $hostname
"; $segs = explode('.', $hostname); if(is_array($segs)) { foreach($segs as $seg) { //echo "Checking $seg
"; if(eregi("[a-z0-9\-]{0,62}",$seg)) { $return = True; } if(!$return) { return False; } } return True; } return False; } function is_bigfour ($tld) { $this->nonfree_call(); } function is_host ($hostname='', $type='ANY') { if($this->is_hostname($hostname)) { return checkdnsrr($hostname, $type); } else { return false; } } function is_ipaddress ($ip='') { if(strlen($ip) <= 15) { $segs = explode('.', $ip); if(count($segs) != 4) { return false; } foreach($segs as $seg) { if( ($seg < 0) || ($seg >= 255) ) { return false; } } return true; } else { return false; } } function ip_resolves ($ip='') { if($this->is_ipaddress($ip)) { return !strcmp($hostname, gethostbyaddr($ip)); } else { return false; } } function browser_gen () { $this->nonfree_call(); } function is_state ($State = "") { $this->nonfree_call(); } function is_zip ($zipcode = "") { $this->nonfree_call(); } function is_country ($countrycode='') { $this->nonfree_call(); } function nonfree_call() { echo 'class.validator.inc.php used to contain code that was not Free '; echo 'Software (see '; echo 'definition , therefore it has been removed.
'; echo 'If you are a application maintainer, please update your app. '; echo 'If you are a user, please file a bug report on '; echo ''; echo 'our project page at sourceforge.net. Please copy and paste '; echo 'the following information into the bug report:
'; echo 'Summary: ' . $GLOBALS['phpgw_info']['flags']['currentapp']; echo 'calls class.validator.inc.php'; echo 'Information:
The call was found when calling: ' . $_SERVER['QUERY_STRING']; echo '
This application will now halt!
'; echo 'Return to Home Screen'; exit; } } ?>