<?php
if (!empty($_GET['showSource']))
{
 
show_source(__FILE__);
 die();
}
#### Starts here

require('gDNS.phps');

$keyword_order = array('bn','bpa','bar','bsa','sa','s','cn','fn','ln','nn','dob','g','pa','a1','a2','a3','tc','sp','pc','c','ll','o','d','jt','hi','ft','ky','f_c','f_ft','f_bar','tc_FR','bar_FR','c_FR','ft_FR','tc_FR');

class 
tel_anzeige
{
 var 
$languages             = array();
 var 
$keyword_categories = array();
 var 
$service_prefixes   = array();
 var 
$domData             = array();
 var 
$icons                 = array();
 var 
$docWrite             false;
 var 
$writeCache         '';
 var 
$dns                 null;
 var 
$google_api_code     '';

 function 
__construct()
 {
  global 
$lang;

  
$this->dns = new gDNS(false);
  
  
$this->languages = array('de'=>'Deutsch''en'=>'English''ru'=>'???????');
  
# 'es'=>'Español', 'fr'=>'Français', 'it'=>'Italiano');
     
   
$this->icons = array(
    
'sip'        => 'voip',
    
'h323'        => 'voip',
    
'skype'        => 'voip',
    
'tel'         => 'phone',
    
'sms'        => 'messaging',
    
'ems'        => 'messaging',
    
'mms'        => 'messaging',
    
'email'        => 'email',
    
'mailto'    => 'email',
    
'web'        => 'weblink',
    
'http'        => 'weblink',
    
'ftp'         => 'ftp',
    
'im'         => 'im',
    
'aim'         => 'im',
    
'ymsgr'     => 'im',
    
'msn'         => 'im',
    
'xmpp'         => 'im'
    
'username'     => 'username',
    
'user'         => 'username',
    
'name'        => 'username',
    
'crypto'    => 'crypto',
    
'mobile'    => 'mobile',
    
'fax'        => 'fax',
    
'prs'        => 'prs'
    
);
 }
 
 function 
set_google_api_code$apicode )
 {
  
$this->google_api_code $apicode;
 }
 
 function 
keyword_order($a$b)
 {
  global 
$keyword_order;
 
  
$a array_search($a$keyword_order);
  
$b array_search($b$keyword_order);
 
  if (
$a == $b)
   return 
0;
 
  return (
$a $b) ? -1;;
 } 
 
 function 
getData($domain)
 {
    if( 
$this->dns->Query$domain'*'true'IN''195.253.51.64'true ) ) 
    { 
     
$result $this->dns->getRecords$this->dns->cur_domain );
     
$this->dns->clearRecords$this->dns->cur_domain );
     
     
$this->getTXT($result);
     
$this->getLOC($result);
     
$this->getNAPTR($result);
     
     unset(
$result);
    }    
 }
 
 function 
getLOC($result)
 {
  if (!empty(
$result[$this->dns->cur_domain]['IN']['LOC'][0]['Responce'])) 
   
$this->domData['loc'] = $result[$this->dns->cur_domain]['IN']['LOC'][0]['Responce'];
 }
 
 function 
getTXT($result)
 {   
     
$filter array_reverse(explode('.'$this->dns->cur_domain));

     
$this->domData['keywords'] = array();
     foreach(
$result[$this->dns->cur_domain]['IN']['TXT'] AS $k=>$val)
     {    


      if (
count($val['Responce'])>1)
      {
       
$tmp = array();
       
$o $val['Responce'];

       for( 
$i=$i<count($o) ; $i+=)
        if (
$o[$i]{0}!='.')
        {
         
$o[$i] = strtr($o[$i], array('addressLine[1]'=>'a1',
                                      
'addressLine[2]'=>'a2',    
                                      
'addressLine[3]'=>'a3',
                                      
'postalCode'=>'pc',
                                      
'country'=>'c',
                                      
'townCity'=>'tc',
                                      
'firstName'=>'fn',
                                      
'lastName'=>'ln',
                                      
'nickName'=>'nn',
                                      
'organization'=>'o',
                                    ));
         if (
$o[$i]!=$this->dns->cur_domain)                                            
          
$tmp$o[$i] ] = @$o[($i+1)];
        }
        
        if (!empty(
$tmp) && !isset($tmp['pddx'])) // den pddx Record brauchen wir eh nicht
         
$this->domData['keywords'][] = $tmp;  
        unset(
$tmp);
       
      } else {
      
       
$this->domData['txt'] .= $val['Responce'][0];
      }    
     }
 }
 
 function 
getNAPTR($result)
 { 
  
// NAPTR Record
  
$this->domData['contacts'] = array();
  foreach(
$result[$this->dns->cur_domain]['IN']['NAPTR'] AS $k=>$val)
   if (!empty(
$val['Responce'][4])) // subpages gehen mm noch nicht mit der gDNS Class
   
{
    
preg_match('/^\!\^\.\*\$\!(.*)\!$/'$val['Responce'][4], $arr); 
    @list(
$k$v) = explode(':'$arr[1], 2);
    
$data = (!empty($v))?ltrim($v'/'):((empty($arr[1]))?$val['Responce'][4]:$arr[1]);
       
    
$tmp = array('data'=>$data'label'=>'''location'=>'''ctype'=>'');

    foreach(
explode('+'str_replace('E2U+'''$val['Responce'][3])) AS $l)
    {
     @list(
$k$v) = explode(':'$l);
    
     switch(
strtolower($k))
     {
      case 
'x-lbl':
          
$tmp['label'] = $v;
          break;

      case 
'x-mobile'
          
$tmp['location'] = 'mobile';
          break;

      case 
'x-home':
          
$tmp['location'] = 'home';
          break;

      case 
'x-work':
          
$tmp['location'] = 'work';
          break;

      case 
'x-transit':
          
$tmp['location'] = 'transit';
          break;

      case 
'x-main':
          
$tmp['location'] = 'main';
          break;

      case 
'x-prs':
          
$tmp['location'] = 'prs';
          break;

      case 
'sip':
      case 
'h323':
      case 
'voice':
      case 
'sms':
      case 
'ems':
      case 
'mms':
      case 
'email':
      case 
'web':
      case 
'ft':
      case 
'fax':
      case 
'x-voice':
      case 
'x-im':
          
$tmp['ctype'] = strtolower($k).':'.$v;
          break;
     }
    }
    
    
$this->domData['contacts'][] = $tmp;    
   }
 }
 
 function 
viewNAPTR()
 { 
  foreach(
$this->domData['contacts'] AS $row)
  {
   
$infos $this->service_prefixes[$row['ctype']];
   
   
$icon 'info';
   foreach(
explode(':'$row['ctype']) AS $t)
    if (isset(
$this->icons[$t]))
    {
     
$icon $this->icons[$t];
     break;
    }
    
   
$this->printLine('<div class="'.$icon.'">');
   
$this->printLine('<span class="service">'.htmlentities(((!empty($row['label']))?$row['label'].' ':'').$infos[0].' '.$row['location'], ENT_QUOTES'UTF-8').'</span><br>');
   
$this->printLine('<a class="trim" href="'.htmlentities($infos[1].$row['data']).'">'.htmlentities($row['data'], ENT_QUOTES'UTF-8').'</a>');
   
$this->printLine('</div>');
  }
 } 
 
 function 
viewKEYWORDS()
 {
  
$keywords = array();
   
  if (!empty(
$this->domData['keywords']))
  {   
   
$this->printLine('<div class="keywords">');
   
$this->printLine('<span class="service">'.$this->keyword_categories['ky'].'</span>'); 
   
$this->printLine('<ul id="keywords">');
   
   foreach(
$this->domData['keywords'] AS $kws)
   {
    
uksort($kws, array('tel_anzeige''keyword_order')); 
    
    
reset($kws);
    if (
count($kws)==1)
    {
     if (
key($kws) == 'hi')
     {
     
$this->printLine('<li>');
     
$this->printLine('   <h4>'.htmlentities($this->keyword_categories[key($kws)], ENT_QUOTES'UTF-8').' - <span>'.htmlentities(current($kws), ENT_QUOTES'UTF-8').'</span></h4>');
     
$this->printLine('   <p>'.nl2br(htmlentities(current($kws), ENT_QUOTES'UTF-8')).'</p>');
     
$this->printLine('<li>');
     
     } else {
      
$this->printLine('<li>');
      
$this->printLine('   <p>'.nl2br(htmlentities(current($kws), ENT_QUOTES'UTF-8')).'</p>');
      
$this->printLine('<li>');
     }
    } elseif(
count($kws)==2) {  
    
     
$this->printLine('<li>');
     
$this->printLine('   <h4>'.htmlentities($this->keyword_categories[key($kws)], ENT_QUOTES'UTF-8').' - <span>'.htmlentities(current($kws), ENT_QUOTES'UTF-8').'</span></h4>');
     
next($kws);
     
$this->printLine('   <p>'.nl2br(htmlentities(current($kws), ENT_QUOTES'UTF-8')).'</p>');
     
$this->printLine('<li>');
    } else {
    
     
$this->printLine('<li>');
     
$this->printLine('   <h4>'.htmlentities($this->keyword_categories[trim(key($kws))], ENT_QUOTES'UTF-8').' - <span>'.htmlentities(current($kws), ENT_QUOTES'UTF-8').'</span></h4>');
     
$this->printLine('      <ul>');
     
next($kws);
     while (
$val current($kws)) 
     {
      
$this->printLine('     <li>'.htmlentities($valENT_QUOTES'UTF-8').'</li>');
      
next($kws);
     }
    
     
$this->printLine('      </ul>');
     
$this->printLine('</li>');

    }     
   
   }
   
$this->printLine('</ul>');
   
$this->printLine('</div>');
  }
 }
 
 function 
view($domain)
 {
  
$this->getLang($domain);
  
  include(
'../contact_lang/'.$this->lang.'.phps');
  
$this->keyword_categories $keyword_categories;
  
$this->service_prefixes   $service_prefixes
 
  
$this->getData($domain);
   
  if (empty(
$_REQUEST['noCss']))
  {
   
# $this->printLine('<link href="http://contact.jepaa.com/css/contact.css" rel="stylesheet" type="text/css" />');
   
$this->printLine('<link href="http://www.jepaa.com/css/proxy.css" rel="stylesheet" type="text/css" />');
   
# $this->printLine('<link href="http://contact.jepaa.com/css/layout.css" rel="stylesheet" type="text/css" />'."\n\n";
  
}
  
  
$this->printLine('<div id="tel_contacts">');
  
$this->printLine('<br>');
  
$this->printLine(nl2br(htmlentities($this->domData['txt'], ENT_QUOTES'UTF-8')));
    
  
$this->viewNAPTR(); 
    
  if (!empty(
$this->domData['loc']['latitude']))
  {    
   
$pos_string  preg_replace('/([0-9]+):([0-9]+):([0-9\.]+) ([NSWE]+)/''$1 $2 $3 $4 '$this->domData['loc']['latitude']);
   
$pos_string .= preg_replace('/([0-9]+):([0-9]+):([0-9\.]+) ([NSWE]+)/''$1 $2 $3 $4'$this->domData['loc']['longitude']);

   
$dez_string $this->loc_format($pos_string'dez');    

   
$pos_string .= ' '.
                 
//(INT)$this->domData['loc']['altitude'].'m '. // hat irgend wo ne make
                 
'0m '
                 (INT)
$this->domData['loc']['size'].'m '.
                 (INT)
$this->domData['loc']['horiz_pre'].'m '.
                 (INT)
$this->domData['loc']['vert_pre'].'m';
   
    
   
$this->printLine('<div class="location">');
  
   
$this->printLine('<span class="service">'.$this->keyword_categories['ll'].'</span><br>'); 
   
$this->printLine('<a target="_blank" href="http://maps.google.com/maps?f=q&amp;hl=en&amp;geocode=&amp;q='.$dez_string.'">'.$pos_string.'<br></a><br>');
   
   if (!empty(
$this->google_api_code))
   {
    
$gpos str_replace('+'', '$dez_string);
    
$this->printLine('<script src="http://maps.google.com/maps?file=api&v=2&key='.$this->google_api_code.'"></script>');
    
$this->printLine('<script type="text/javascript">');
    
$this->printLine('function load() {');
    
$this->printLine(' if (GBrowserIsCompatible()) {');
    
$this->printLine('  var map = new GMap2(document.getElementById(\'google_so_map\'));');
    
$this->printLine('  map.addControl(new GSmallMapControl('.$gpos.'));');
    
$this->printLine('  map.addControl(new GMapTypeControl('.$gpos.'));'); 
    
$this->printLine('  map.setCenter(new GLatLng('.$gpos.'), 14, G_NORMAL_MAP);');
    
$this->printLine('  var point = new GLatLng('.$gpos.');');
    
$this->printLine('  var beck = new GMarker(point);');
    
$this->printLine('  map.addOverlay(beck);');
    
$this->printLine('  beck.openInfoWindowHtml(html);');
    
$this->printLine(' }');
    
$this->printLine('}');
    
$this->printLine('window.onload=load;');
    
$this->printLine('</script>');
    
$this->printLine('<div id="google_so_map">&nbsp;</div>');
   } else {
   
    
$this->printLine('<span class="service">Location</span><br>');
    
$this->printLine('<a target="_blank" href="http://maps.google.com/maps?f=q&amp;hl=en&amp;geocode=&amp;q='.$dez_string.'">[View in Google Maps]<br></a>');
   }

   
$this->printLine('</div>'); 
  }    
    
  
$this->viewKEYWORDS(); 
  
$this->printLine('</div>');
  
  
$this->printCache();
 }
 
 function 
printLine($line)
 {
  if (
$this->docWrite==true) {
   
$this->writeCache .= strtr($line, array("\n"=>''"\r"=>''));
  } else {
   echo 
$line."\n";
  } 
 }
 
 function 
printCache()
 {
  if (!empty(
$this->writeCache))
   echo 
'document.write(\''.$this->writeCache.'\')'
 }
 
 function 
prefered_language($http_accept_language='auto')
 {
    if (
$http_accept_language == 'auto'
     
$http_accept_language $_SERVER['HTTP_ACCEPT_LANGUAGE'];

    
preg_match_all("/([[:alpha:]]{1,8})(-([[:alpha:]|-]{1,8}))?" .
                   
"(\s*;\s*q\s*=\s*(1\.0{0,3}|0\.\d{0,3}))?\s*(,|$)/i",
                   
$http_accept_language$hitsPREG_SET_ORDER);

    
// default language (in case of no hits) is the first in the array
    
$bestlang array_keys($this->languages);
    
$bestlang $bestlang[0];
    
$bestqval 0;

    foreach (
$hits as $arr) {
        
// read data from the array of this hit
        
$langprefix strtolower ($arr[1]);
        if (!empty(
$arr[3])) {
            
$langrange strtolower ($arr[3]);
            
$language $langprefix '-' $langrange;
        }
        else 
$language $langprefix;
        
$qvalue 1.0;
        if (!empty(
$arr[5])) $qvalue floatval($arr[5]);
     
        
// find q-maximal language 
        
if (!empty($this->languages[$language]) && ($qvalue $bestqval)) {
            
$bestlang $language;
            
$bestqval $qvalue;
        }
        
// if no direct hit, try the prefix only but decrease q-value by 10% (as http_negotiate_language does)
        
else if (!empty($this->languages[$languageprefix]) && (($qvalue*0.9) > $bestqval)) {
            
$bestlang $languageprefix;
            
$bestqval $qvalue*0.9;
        }
    }
    
    return 
$bestlang;
 }

 function 
getLang()
 {
  if (empty(
$_COOKIE['Jepaa_Lang']))
  {
   
$this->lang $this->prefered_language();
   
setcookie('Jepaa_Lang'$this->langtime()+(3600*24*30));    
  } else {

   
$this->lang substr($_COOKIE['Jepaa_Lang'], 07);
  }
  
  return 
$this->lang;
 }
 
 function 
setLang($lang)
 {
  
$this->lang substr($lang07);
  
setcookie('Jepaa_Lang'$this->langtime()+(3600*24*30));
  
$_COOKIE['Jepaa_Lang'] = $this->lang;
 }
 
 function 
loc_format($loc$type='dez')
 {
  
preg_match('/([0-9]+) ([0-9]+) ([0-9\.]+) (N|S+) ([0-9]+) ([0-9]+) ([0-9\.]+) (E|W+)/'$loc$d);

  switch(
$type)
  {
   case 
'grad':

           
$ret  = ($d[4]=='S')?'-':'+';
           
$ret .= $d[1].'° '.$d[2].'\' '.number_format($d[3], 3'.''').'", ';
           
$ret .= ($d[8]=='W')?'-':'+';
           
$ret .= $d[5].'° '.$d[6].'\' '.number_format($d[7], 3'.''').'"';
           return 
$ret;

           break;

   case 
'dez':
          
$x $d[1]+($d[2]/60)+($d[3]/3600);
          
$y $d[5]+($d[6]/60)+($d[7]/3600);


           if (
$d[4]=='S')
            
$x $x*-1;
            
           if (
$d[8]=='W')
             
$y $y*-1;

           return 
number_format($x3'.''').'+'.number_format($y3'.''');

           break;
   default:
           return 
$loc;
           break;
  }
 } 


$ptd  = new tel_anzeige();

if (!empty(
$_REQUEST['lang']))
 
$ptd->setLang($_REQUEST['lang']);
 
header('Content-Type: text/html; charset=utf-8'); 

if (!empty(
$_REQUEST['docWrite']))
 
$ptd->docWrite true;
 
$ptd->set_google_api_code('ABQIAAAAFryg5vHcGsXH-72z_1VQiBQTORyUV5oG8gbLTAU1gVnlsvFhhBQsPmTJC7brhLyizjognV6gJ2zvgQ');
 
$ptd->view($_REQUEST['domain']);
?>