コード例 #1
0
 function findPlacename($placename)
 {
     global $places;
     //only way to get the array into the compare functions
     global $USER;
     global $CONF, $memcache;
     $mkey = strtolower(trim($placename)) . '.v5';
     //need to invalidate the whole cache.
     //fails quickly if not using memcached!
     $places =& $memcache->name_get('g', $mkey);
     if ($places) {
         return $places;
     }
     $db = $this->_getDB();
     $ismore = 0;
     $placename = str_replace('?', '', $placename, $ismore);
     $places = array();
     if (is_numeric($placename)) {
         if ($placename > 10000000) {
             $places = $db->GetAll("select name as full_name,'PPL' as dsg, e, n, reference_index,'' as adm1_name from loc_towns where id=" . $db->Quote($placename - 10000000));
         } elseif ($placename > 1000000) {
             $places = $db->GetAll("select `def_nam` as full_name,'PPL' as dsg,`east` as e,`north` as n,1 as reference_index,`full_county` as adm1_name from os_gaz where seq=" . $db->Quote($placename - 1000000));
         } else {
             $places = $db->GetAll("select full_name,dsg,e,n,loc_placenames.reference_index,loc_adm1.name as adm1_name from loc_placenames left join loc_adm1 on (loc_placenames.adm1 = loc_adm1.adm1 and  loc_adm1.country = loc_placenames.country) where id=" . $db->Quote($placename));
         }
     } elseif (!$ismore) {
         list($placename, $county) = preg_split('/\\s*,\\s*/', $placename);
         if (!empty($county)) {
             $qcount = $db->Quote($county);
             $places = $db->GetAll("select `def_nam` as full_name,'PPL' as dsg,`east` as e,`north` as n,1 as reference_index,`full_county` as adm1_name,code_name as dsg_name,(seq + 1000000) as id,km_ref as gridref from os_gaz inner join os_gaz_code using (f_code) where def_nam=" . $db->Quote($placename) . " and (full_county = {$qcount} OR hcounty = {$qcount})");
         } else {
             $qplacename = $db->Quote($placename);
             $sql_where = "def_nam={$qplacename}";
             $sql_where2 = "full_name={$qplacename}";
             if (strpos($placename, ' ') !== FALSE) {
                 $county = $db->getOne("select `name` from os_gaz_county where {$qplacename} LIKE CONCAT('%',name)");
                 if (!empty($county)) {
                     $qcount = $db->Quote($county);
                     $placename = preg_replace("/\\s+{$county}/i", '', $placename);
                     $qplacename = $db->Quote($placename);
                     $sql_where .= " or (def_nam={$qplacename} and full_county = {$qcount})";
                     $sql_where2 .= " or full_name={$qplacename}";
                     //we cant search easily on county here!
                 }
             }
             //todo need to 'union'  with other gazetterr! (as if one match in each then will no work!)
             $places = $db->GetAll("select `def_nam` as full_name,'PPL' as dsg,`east` as e,`north` as n,1 as reference_index,`full_county` as adm1_name,code_name as dsg_name,(seq + 1000000) as id,km_ref as gridref from os_gaz inner join os_gaz_code using (f_code) where {$sql_where}");
             if (count($places) == 0) {
                 $places = $db->GetAll("select full_name,dsg,e,n,reference_index,id,loc_dsg.name as dsg_name from loc_placenames inner join loc_dsg on (loc_placenames.dsg = loc_dsg.code) where full_name={$qplacename}");
                 if ($c = count($places)) {
                     require_once 'geograph/conversions.class.php';
                     $conv = new Conversions();
                     foreach ($places as $id => $row) {
                         if (empty($row['gridref'])) {
                             list($places[$id]['gridref'], ) = $conv->national_to_gridref($row['e'], $row['n'], 4, $row['reference_index']);
                         }
                         $places[$id]['full_name'] = _utf8_decode($row['full_name']);
                     }
                 }
             }
         }
     }
     if (count($places) == 1) {
         #we done!
     } else {
         $limit = strlen($placename) > 3 ? 60 : 20;
         $limi2 = 40;
         if ($USER->registered) {
             $limit *= 2;
             $limi2 *= 2;
         }
         //starts with (both gaz's)
         $places = $db->GetAll($sql = "\r\n\t\t\t(select\r\n\t\t\t\t(seq + 1000000) as id,\r\n\t\t\t\t`def_nam` as full_name,\r\n\t\t\t\t'PPL' as dsg,`east` as e,`north` as n,\r\n\t\t\t\tcode_name as dsg_name,\r\n\t\t\t\t1 as reference_index,\r\n\t\t\t\t`full_county` as adm1_name,\r\n\t\t\t\t`hcounty` as hist_county,\r\n\t\t\t\tkm_ref as gridref\r\n\t\t\tfrom \r\n\t\t\t\tos_gaz\r\n\t\t\t\tinner join os_gaz_code using (f_code)\r\n\t\t\twhere\r\n\t\t\t\tos_gaz.f_code IN ('C','T','O') AND\r\n\t\t\t\t`def_nam` LIKE " . $db->Quote($placename . '%') . "\r\n\t\t\tlimit {$limit}) UNION\r\n\t\t\t(select \r\n\t\t\t\tid, \r\n\t\t\t\tfull_name,\r\n\t\t\t\tdsg,e,n,\r\n\t\t\t\tloc_dsg.name as dsg_name,\r\n\t\t\t\tloc_placenames.reference_index,\r\n\t\t\t\tloc_adm1.name as adm1_name,\r\n\t\t\t\t'' as hist_county,\r\n\t\t\t\t'' as gridref\r\n\t\t\tfrom \r\n\t\t\t\tloc_placenames\r\n\t\t\t\tinner join loc_dsg on (loc_placenames.dsg = loc_dsg.code) \r\n\t\t\t\tleft join loc_adm1 on (loc_placenames.adm1 = loc_adm1.adm1 and  loc_adm1.country = loc_placenames.country)\r\n\t\t\twhere\r\n\t\t\t\tdsg LIKE 'PPL%' AND loc_placenames.reference_index != 1 AND\r\n\t\t\t\tfull_name LIKE " . $db->Quote($placename . '%') . "\r\n\t\t\tgroup by gns_ufi\r\n\t\t\tLIMIT {$limit})");
         if (isset($_GET['debug'])) {
             print "<pre>{$sql}</pre>count = " . count($places) . "<hr>";
         }
         if (count($places) < 10 || $ismore) {
             //sounds like (OS)
             $places = array_merge($places, $db->GetAll("\r\n\t\t\t\tselect\r\n\t\t\t\t\t(seq + 1000000) as id,\r\n\t\t\t\t\t`def_nam` as full_name,\r\n\t\t\t\t\t'PPL' as dsg,`east` as e,`north` as n,\r\n\t\t\t\t\tcode_name as dsg_name,\r\n\t\t\t\t\t1 as reference_index,\r\n\t\t\t\t\t`full_county` as adm1_name,\r\n\t\t\t\t\t`hcounty` as hist_county,\r\n\t\t\t\t\tkm_ref as gridref\r\n\t\t\t\tfrom \r\n\t\t\t\t\tos_gaz\r\n\t\t\t\t\tinner join os_gaz_code using (f_code)\r\n\t\t\t\twhere\r\n\t\t\t\t\tos_gaz.f_code IN ('C','T','O') AND\r\n\t\t\t\t\tdef_nam_soundex = SOUNDEX(" . $db->Quote($placename) . ") AND\r\n\t\t\t\t\tdef_nam NOT LIKE " . $db->Quote($placename . '%') . "\r\n\t\t\t\tlimit {$limi2}"));
             if (isset($_GET['debug'])) {
                 print "<pre>{$sql}</pre>count = " . count($places) . "<hr>";
             }
         }
         if (count($places) < 10 || $ismore) {
             //contains (OS)
             $places = array_merge($places, $db->GetAll($sql = "\r\n\t\t\t\tselect\r\n\t\t\t\t\t(seq + 1000000) as id,\r\n\t\t\t\t\t`def_nam` as full_name,\r\n\t\t\t\t\t'PPL' as dsg,`east` as e,`north` as n,\r\n\t\t\t\t\tcode_name as dsg_name,\r\n\t\t\t\t\t1 as reference_index,\r\n\t\t\t\t\t`full_county` as adm1_name,\r\n\t\t\t\t\t`hcounty` as hist_county,\r\n\t\t\t\t\tkm_ref as gridref\r\n\t\t\t\tfrom \r\n\t\t\t\t\tos_gaz\r\n\t\t\t\t\tinner join os_gaz_code using (f_code)\r\n\t\t\t\twhere\r\n\t\t\t\t\tos_gaz.f_code IN ('C','T','O') AND\r\n\t\t\t\t\t`def_nam` LIKE " . $db->Quote('%' . $placename . '%') . " AND\r\n\t\t\t\t\t`def_nam` NOT LIKE " . $db->Quote($placename . '%') . "\r\n\t\t\t\tlimit {$limi2}"));
             if (isset($_GET['debug'])) {
                 print "{$limi2}<pre>{$sql}</pre>count = " . count($places) . "<hr>";
             }
         }
         if (count($places) < 10 || $ismore) {
             //search the widest possible
             $places2 = $db->GetAll($sql = "\r\n\t\t\t\t(select\r\n\t\t\t\t\t(seq + 1000000) as id,\r\n\t\t\t\t\t`def_nam` as full_name,\r\n\t\t\t\t\t'PPL' as dsg,`east` as e,`north` as n,\r\n\t\t\t\t\tcode_name as dsg_name,\r\n\t\t\t\t\t1 as reference_index,\r\n\t\t\t\t\t`full_county` as adm1_name,\r\n\t\t\t\t\t`hcounty` as hist_county,\r\n\t\t\t\t\tkm_ref as gridref\r\n\t\t\t\tfrom \r\n\t\t\t\t\tos_gaz\r\n\t\t\t\t\tinner join os_gaz_code using (f_code)\r\n\t\t\t\twhere\r\n\t\t\t\t\tos_gaz.f_code NOT IN ('C','T','O') AND\r\n\t\t\t\t\t( `def_nam` LIKE " . $db->Quote('%' . $placename . '%') . "\r\n\t\t\t\t\tOR def_nam_soundex = SOUNDEX(" . $db->Quote($placename) . ") )\r\n\t\t\t\torder by \r\n\t\t\t\t\tdef_nam = " . $db->Quote($placename) . " desc,\r\n\t\t\t\t\tdef_nam_soundex = SOUNDEX(" . $db->Quote($placename) . ") desc\r\n\t\t\t\tlimit {$limi2}) UNION\r\n\t\t\t\t(select \r\n\t\t\t\t\tid, \r\n\t\t\t\t\tfull_name,\r\n\t\t\t\t\tdsg,e,n,\r\n\t\t\t\t\tloc_dsg.name as dsg_name,\r\n\t\t\t\t\tloc_placenames.reference_index,\r\n\t\t\t\t\tloc_adm1.name as adm1_name,\r\n\t\t\t\t\t'' as hist_county,\r\n\t\t\t\t\t'' as gridref\r\n\t\t\t\tfrom \r\n\t\t\t\t\tloc_placenames\r\n\t\t\t\t\tinner join loc_dsg on (loc_placenames.dsg = loc_dsg.code) \r\n\t\t\t\t\tleft join loc_adm1 on (loc_placenames.adm1 = loc_adm1.adm1 and  loc_adm1.country = loc_placenames.country)\r\n\t\t\t\twhere\r\n\t\t\t\t\tfull_name LIKE " . $db->Quote('%' . $placename . '%') . "\r\n\t\t\t\t\tOR full_name_soundex = SOUNDEX(" . $db->Quote($placename) . ")\r\n\t\t\t\tgroup by gns_ufi\r\n\t\t\t\torder by \r\n\t\t\t\t\tfull_name = " . $db->Quote($placename) . " desc,\r\n\t\t\t\t\tfull_name_soundex = SOUNDEX(" . $db->Quote($placename) . ") desc\r\n\t\t\t\tLIMIT {$limi2})");
             if (isset($_GET['debug'])) {
                 print "<pre>{$sql}</pre>count2 = " . count($places2) . "<hr>";
             }
             if (count($places2)) {
                 if (count($places)) {
                     foreach ($places2 as $i2 => $place2) {
                         $found = 0;
                         $look = str_replace("-", ' ', $place2['full_name']);
                         foreach ($places as $i => $place) {
                             if ($place['full_name'] == $look && $place['reference_index'] == $place2['reference_index'] && ($d = pow($place['e'] - $place2['e'], 2) + pow($place['n'] - $place2['n'], 2)) && $d < 5000 * 5000) {
                                 $found = 1;
                                 break;
                             }
                         }
                         if (!$found) {
                             array_push($places, $place2);
                         }
                     }
                 } else {
                     $places =& $places2;
                 }
             }
         }
         # loc_towns
         if (count($places) < 10 || $ismore) {
             //search the widest possible
             //km_ref as gridref
             //county from loc_hier?
             //	`full_county` as adm1_name,
             $places2 = $db->GetAll($sql = "\r\n\t\t\t\tselect\r\n\t\t\t\t\t(id + 10000000) as id,\r\n\t\t\t\t\tname as full_name,\r\n\t\t\t\t\t'PPL' as dsg, e, n,\r\n\t\t\t\t\t'' as dsg_name,\r\n\t\t\t\t\treference_index,\r\n\t\t\t\t\t'' as adm1_name,\r\n\t\t\t\t\t'' as hist_county,\r\n\t\t\t\t\t'' as gridref\r\n\t\t\t\tfrom \r\n\t\t\t\t\tloc_towns\r\n\t\t\t\twhere\r\n\t\t\t\t\t( name LIKE " . $db->Quote('%' . $placename . '%') . "\r\n\t\t\t\t\tOR name SOUNDS LIKE " . $db->Quote($placename) . ")\r\n\t\t\t\torder by \r\n\t\t\t\t\tname = " . $db->Quote($placename) . " desc,\r\n\t\t\t\t\tname SOUNDS LIKE " . $db->Quote($placename) . " desc\r\n\t\t\t\tlimit {$limi2}");
             if (isset($_GET['debug'])) {
                 print "<pre>{$sql}</pre>count2 = " . count($places2) . "<hr>";
             }
             if (count($places2)) {
                 if (count($places)) {
                     foreach ($places2 as $i2 => $place2) {
                         $found = 0;
                         $look = str_replace("-", ' ', $place2['full_name']);
                         foreach ($places as $i => $place) {
                             if ($place['full_name'] == $look && $place['reference_index'] == $place2['reference_index'] && ($d = pow($place['e'] - $place2['e'], 2) + pow($place['n'] - $place2['n'], 2)) && $d < 5000 * 5000) {
                                 $found = 1;
                                 break;
                             }
                         }
                         if (!$found) {
                             array_push($places, $place2);
                         }
                     }
                 } else {
                     $places =& $places2;
                 }
             }
         }
         if ($c = count($places)) {
             require_once 'geograph/conversions.class.php';
             $conv = new Conversions();
             foreach ($places as $id => $row) {
                 if (empty($row['gridref'])) {
                     list($places[$id]['gridref'], ) = $conv->national_to_gridref($row['e'], $row['n'], 4, $row['reference_index']);
                 }
                 $places[$id]['full_name'] = _utf8_decode($row['full_name']);
             }
             if ($c > 14) {
                 $placename = strtolower($placename);
                 foreach ($places as $id => $row) {
                     $p1 = strtolower($row['full_name']);
                     if (strpos($p1, $placename) === FALSE && levenshtein(strtolower($p1), $placename) > strlen($row['full_name']) / 2) {
                         unset($places[$id]);
                     }
                 }
             }
         }
     }
     //fails quickly if not using memcached!
     $memcache->name_set('g', $mkey, $places, $memcache->compress, $memcache->period_long);
     return $places;
 }
コード例 #2
0
function smarty_function_place($params)
{
    global $CONF;
    $place = $params['place'];
    $t = '';
    if ($CONF['lang'] == 'de') {
        if ($place['distance'] > 3) {
            $t .= $place['distance'] - 0.01 . " km entfernt von ";
        } elseif (!$place['isin']) {
            $t .= "<span title=\"etwa " . ($place['distance'] - 0.01) . " km entfernt\">in der Nähe</span> von ";
        }
    } else {
        if ($place['distance'] > 3) {
            $t .= $place['distance'] - 0.01 . " km from ";
        } elseif (!$place['isin']) {
            $t .= "<span title=\"about " . ($place['distance'] - 0.01) . " km from\">near</span> to ";
        }
    }
    $place['full_name'] = _utf8_decode($place['full_name']);
    if (!ctype_lower($place['full_name'])) {
        $t .= "<b>" . recaps($place['full_name']) . "</b><small><i>";
    } else {
        $t .= "<b>{$place['full_name']}</b><small><i>";
    }
    $t = str_replace(' And ', '</b> and <b>', $t);
    if ($place['adm1_name'] && $place['adm1_name'] != $place['reference_name'] && $place['adm1_name'] != $place['full_name'] && !preg_match('/\\(general\\)$/', $place['adm1_name'])) {
        $parts = explode('/', $place['adm1_name']);
        if (!ctype_lower($parts[0])) {
            if (isset($parts[1]) && $parts[0] == $parts[1]) {
                unset($parts[1]);
            }
            $t .= ", " . recaps(implode('/', $parts));
        } else {
            $t .= ", {$place['adm1_name']}";
        }
    } elseif ($place['hist_county']) {
        $t .= ", {$place['hist_county']}";
    }
    $t .= ", {$place['reference_name']}</i></small>";
    $tag = isset($params['h3']) ? 'h3' : 'span';
    $t2 = "<{$tag}";
    if (!empty($params['h3']) && strlen($params['h3']) > 1) {
        $t2 .= $params['h3'];
    }
    if ($place['hist_county']) {
        $t2 .= " title=\"" . substr($place['full_name'], 0, 12) . ": Historic County - {$place['hist_county']}";
        if ($place['hist_county'] == $place['adm1_name']) {
            $t2 .= ", and modern Administrative Area of the same name";
        } else {
            $t2 .= ", modern Administrative Area - {$place['adm1_name']}";
        }
        $t2 .= "\"";
    }
    $t = $t2 . ">" . $t . "</{$tag}>";
    return $t;
}
コード例 #3
0
			$src_array = explode(',',$param[$this_scheme]['sources']);
			$theoriginalnumber = $thenumber;
			if ($theoriginalnumber !='')
			{
			   foreach($src_array as $source_name)
			   {
				$thenumber = $theoriginalnumber;
				if($debug)
				{
					$start_time = mctime_float();
				}
				$caller_id = '';
				$run_param = isset($param[substr($this_scheme,5).'_'.$source_name]) ? $param[substr($this_scheme,5).'_'.$source_name] : array();

				eval('include("source-'.$source_name.'.php");');
				$caller_id = _utf8_decode($caller_id);
				if(($first_caller_id == '') && ($caller_id != ''))
				{
					$first_caller_id = $caller_id;
					$winning_source = $source_name;
					if($debug)
					{
						$end_time_whole = mctime_float();
					}
				}

				if($debug)
				{
					if($caller_id != '')
					{
						print "'" . utf8_encode($caller_id)."'<br>\nresult <img src='images/scrollup.gif'> took ".number_format((mctime_float()-$start_time),4)." seconds.<br>\n<br>\n";