Location: PHPKode > scripts > GPX Mapper & CMS > gpx-mapper-cms/cl.Cms.php
<?

/*		
	CL CMS Class
	Version: 1.0 
	Author: David Boardman
	URL: http://www.netzfunk.org/?usr=d
	Licenced under Creative Commons Attribution-NonCommercial-ShareAlike 2.5

	If redistributed in any form, please include credits and a link to http://www.netzfunk.org/?usr=d
*/

class clCms{
	var $config;
	var $lid;
	
	function clCms($config){
		$this->config=$config;	
	}

	function connectDB(){  //connessione al db cultural_luggage
		$this->lid = mysql_connect($this->config["DB_server"],$this->config["DB_user"],$this->config["DB_pwd"]);
		mysql_select_db($this->config["DB_name"]);
	}
	
	function closeDB(){  //chiudi connessione db
		mysql_close($this->lid);
	}

	function checkPOI($t,$r){
		$t=@mysql_num_rows(mysql_query("SELECT * FROM poi WHERE titolo='$t';",$this->lid));		
		$r=@mysql_num_rows(mysql_query("SELECT * FROM poi WHERE raggio='$r';",$this->lid));
		return array("titolo"=>$t,"raggio"=>$r);
	}
	
	function checkContext($c){
		return @mysql_num_rows(mysql_query("SELECT * FROM context WHERE titolo='$c';",$this->lid));
	}
	
	function cleanStr($str){
		$str=str_replace("'","\'",$str);
		$str=str_replace('"','\"',$str);
		$str=htmlspecialchars($str);
		$str=strip_tags($str);
		return $this->convertSymbolsToEntities($str);
	}

    function convertSymbolsToEntities($string){
        static $symbols = 
            array(
                '‚', 'ƒ', '„', '…', '†', '‡', 'ˆ', '‰', 'þ', '‹', 'Œ', '‘', '’', '“', '”', 
                '•', '–', '—', '˜', '™', 'š', '›', 'œ', 'Ÿ', '€', 'Æ', 'Á', 'Â', 'À', 'Å', 
                'Ã', 'Ä', 'Ç', 'Ð', 'É', 'Ê', 'È', 'Ë', 'Í', 'Î', 'Ì', 'Ï', 'Ñ', 'Ó', 'Ô', 
                'Ò', 'Ø', 'Õ', 'Ö', 'Þ', 'Ú', 'Û', 'Ù', 'Ü', 'Ý', 'á', 'â', 'æ', 'à', 'å', 
                'ã', 'ä', 'ç', 'é', 'ê', 'è', 'ð', 'ë', 'í', 'î', 'ì', 'ï', 'ñ', 'ó', 'ô', 
                'ò', 'ø', 'õ', 'ö', 'ß', 'þ', 'ú', 'û', 'ù', 'ü', 'ý', 'ÿ', '¡', '£', '¤', 
                '¥', '¦', '§', '¨', '©', 'ª', '«', '¬', '­', '®', '¯', '°', '±', '²', '³', 
                '´', 'µ', '¶', '·', '¸', '¹', 'º', '»', '¼', '½', '¾', '¿', '×', '÷', '¢', 
                '…', 'µ');
        static $entities = 
            array(
                '&#8218;',  '&#402;',   '&#8222;',  '&#8230;',  '&#8224;',  '&#8225;',  '&#710;', 
                '&#8240;',  '&#352;',   '&#8249;',  '&#338;',   '&#8216;',  '&#8217;',  '&#8220;', 
                '&#8221;',  '&#8226;',  '&#8211;',  '&#8212;',  '&#732;',   '&#8482;',  '&#353;', 
                '&#8250;',  '&#339;',   '&#376;',   '&#8364;',  '&aelig;',  '&aacute;', '&acirc;',  
                '&agrave;', '&aring;',  '&atilde;', '&auml;',   '&ccedil;', '&eth;',    '&eacute;', 
                '&ecirc;',  '&egrave;', '&euml;',   '&iacute;', '&icirc;',  '&igrave;', '&iuml;',   
                '&ntilde;', '&oacute;', '&ocirc;',  '&ograve;', '&oslash;', '&otilde;', '&ouml;',   
                '&thorn;',  '&uacute;', '&ucirc;',  '&ugrave;', '&uuml;',   '&yacute;', '&aacute;', 
                '&acirc;',  '&aelig;',  '&agrave;', '&aring;',  '&atilde;', '&auml;',   '&ccedil;', 
                '&eacute;', '&ecirc;',  '&egrave;', '&eth;',    '&euml;',   '&iacute;', '&icirc;',  
                '&igrave;', '&iuml;',   '&ntilde;', '&oacute;', '&ocirc;',  '&ograve;', '&oslash;', 
                '&otilde;', '&ouml;',   '&szlig;',  '&thorn;',  '&uacute;', '&ucirc;',  '&ugrave;', 
                '&uuml;',   '&yacute;', '&yuml;',   '&iexcl;',  '&pound;',  '&curren;', '&yen;',    
                '&brvbar;', '&sect;',   '&uml;',    '&copy;',   '&ordf;',   '&laquo;',  '&not;',    
                '&shy;',    '&reg;',    '&macr;',   '&deg;',    '&plusmn;', '&sup2;',   '&sup3;',   
                '&acute;',  '&micro;',  '&para;',   '&middot;', '&cedil;',  '&sup1;',   '&ordm;',   
                '&raquo;',  '&frac14;', '&frac12;', '&frac34;', '&iquest;', '&times;',  '&divide;', 
                '&cent;',   '...',      '&micro;');

            return str_replace($symbols, $entities, $string);
    }
	
	function checkOrient($coord,$sel){
		if(strtolower($coord)==strtolower($sel)) return "selected";	
	}
	
	function checkLink($l){
		if(!file_exists($this->config['mainfolder'].$this->config['poifolder']."/".$l.".htm")){
			$l=str_replace(".htm","",$l);
			$l=str_replace(".html","",$l);				
			$l=str_replace("á","a",$l);
			$l=str_replace("à","a",$l);
			$l=str_replace("é","e",$l);
			$l=str_replace("è","e",$l);
			$l=str_replace("í","i",$l);
			$l=str_replace("ì","i",$l);
			$l=str_replace("ó","o",$l);
			$l=str_replace("ò","o",$l);
			$l=str_replace("ú","u",$l);
			$l=str_replace("ù","u",$l);
			$l=str_replace("(","",$l);
			$l=str_replace(")","",$l);
			$l=str_replace(".","",$l);
			$l=str_replace(",","",$l);
			$l=str_replace(";","",$l);
			$l=str_replace(":","",$l);
			$l=str_replace("'","",$l);
			$l=str_replace("*","",$l);
			$l=str_replace('"','',$l);
			$l=str_replace("/","",$l);
			$l=str_replace("[","",$l);
			$l=str_replace("]","",$l);
			$l=str_replace(" ","_",$l);
			return $l;
		}
		else{
			exit("<p align='center'>Esiste già un file POI con nome '<strong>$l.htm</strong>'.<br/><br/><a href='javascript:history.back()'>Torna indietro</a></p>");
		}
	}
	
	function pointCoord($coord){  // CONVERTE LA VIRGOLA DELL'INSERIMENTO IN UN PUNTO
		$coord=str_replace(",",".",$coord);
		return doubleval($coord);	
	}
	
	function createHTML($filename,$title,$desc,$geodata,$meta,$style,$script){
		$master=implode("",file($this->config['mainfolder'].$this->config['poifolder']."/_master.htm"));
		$content=str_replace("####TITLE####",$title,$master);
		$m="<meta name='description' content='$desc'>\n<meta name='geoposition' content='$geodata'>\n";
		$content=str_replace("####META####",$m,$content);
		$content=str_replace("####BODY####","<h1>$title</h1>$desc",$content);
		$content=str_replace("####SCRIPT####","",$content);
		$content=str_replace("####STYLE####","",$content);
		$path=$this->config['mainfolder'].$this->config['poifolder']."/";
		if(!is_writable($path)){
			exit("Check permissions on \"".$path."\" directory.");
		}
		$filename=$path.$filename.".htm";
		$this->nome_arq = $filename; 
			
		$this->myfile = @fopen($this->nome_arq, "w+"); 
		if (!$this->myfile){
		  echo "Operazione non valida.";
		}
		else{
			fputs($this->myfile,$content); 
			fclose($this->myfile); 
		}		
	}
	
	function optContext($id){
		$q="SELECT * FROM context ORDER BY id ASC;";
		$r=mysql_query($q,$this->lid);
		$list="";
		while($l=mysql_fetch_array($r)){
			echo "------ ID $id ID2 ".$l['id'];
			if($id==$l['id']) $list.="<option value=\"".$l['id']."\" selected>".$l['titolo']."</option>\n";
			else $list.="<option value=\"".$l['id']."\">".$l['titolo']."</option>\n";
		}
		return $list;
	}
	
	function goMain(){
		return "<script type=\"text/javascript\">top.location='?task=';</script>";
	}
		
}


?>
Return current item: GPX Mapper & CMS