123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- class Helper{
- const METRES_TO_FEET=3.2808399;
- const KILOMETRES_TO_MILES=0.621371192;
-
- public static function TableMaker($data,$buttonText="Submit",$action="",$method="post") {
- ob_start();
- echo '<form action="',$action,'" method="',$method,'"><table>';
- foreach ($data as $datum){
- if (!isset($datum['value']))
- $datum['value']="";
- if (!isset($datum['type']))
- $datum['type']="text";
-
- $html="";
- switch ($datum['type']) {
- case "select":
- $html="<select id=\"$datum[name]\" name=\"$datum[name]\">";
- foreach ($datum['options'] as $value=>$option){
- $html.="<option value=\"$value\"";
- if ($value==$datum['value'])
- $html.="selected=\"selected\"";
- $html.=">$option</option>";
- }
- $html.="</select>";
- break;
- case "checkbox":
- $checked="";
- if ($datum['checked'])
- $checked='checked="checked"';
- $html="<input type=\"checkbox\" id=\"$datum[name]\" name=\"$datum[name]\" $checked />";
- break;
- default:
- $html="<input id=\"$datum[name]\" name=\"$datum[name]\" type=\"$datum[type]\" value=\"$datum[value]\" />";
- break;
- }
- if ($datum['type']=="hidden"){
- echo $html;
- continue;
- }
-
- echo '<tr><td><label for="',$datum['name'],'">',$datum['display'],': </label></td>',
- '<td>',$html,'</td></tr>';
- }
- echo '<tr><td></td><td><input name="submit_form" type="submit" value="',$buttonText,'" /></td></tr>',
- '</table></form>';
- return ob_get_clean();
- }
-
- public static function IsValidEmail($email){
- if( !preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/",$email))
- return false;
- return true;
- list($userName, $mailDomain)=explode("@", $email);
- if (checkdnsrr($mailDomain,"MX"))
- return true;
- else
- return false;
- }
-
- public static function DeleteCookie($cookie){
- unset($_COOKIE[$cookie]);
- setcookie($cookie,null,-1,'/');
- }
-
- public static function GetMaxUploadString(){
- $maxUpload=(int)ini_get('upload_max_filesize');
- $maxPost=(int)ini_get('post_max_size');
- $memoryLimit=(int)ini_get('memory_limit');
- $size=min($maxUpload, $maxPost, $memoryLimit);
- return $size.'MB';
- }
-
- public static function MakeStringUrlSafe($string){
- $string=strtolower($string);
- $string=preg_replace('/[^a-zA-Z0-9]+/', '-', $string);
- return $string;
- }
-
- //stolen (with a few edits) from http://stackoverflow.com/questions/5695145/how-to-read-and-write-to-an-ini-file-with-php
- public static function WriteINIFile($array,$path,$hasSections){
- $content="";
- if ($hasSections) {
- foreach ($array as $key=>$elem) {
- $content.="\n[".$key."]\n";
- foreach ($elem as $key2=>$elem2) {
- if (is_array($elem2)) {
- for ($i=0; $i<count($elem2); $i++) {
- $content.=$key2."[]=".$elem2[$i]."\n";
- }
- } else if ($elem2=="")
- $content.=$key2."=\"\"\n";
- else
- $content.=$key2."=".$elem2."\n";
- }
- }
- } else {
- foreach ($array as $key=>$elem) {
- if (is_array($elem)) {
- for ($i=0; $i<count($elem); $i++) {
- $content.=$key."[]=".$elem[$i]."\n";
- }
- } else if ($elem=="")
- $content.=$key."=\"\"\n";
- else
- $content.=$key."=".$elem."\n";
- }
- }
- if (!$handle=fopen($path, 'w')) {
- return false;
- }
- $content=trim($content);
- $success=fwrite($handle, $content);
- fclose($handle);
- return $success;
- }
- }
|