1
|
|
|
#!/usr/local/bin/php -q |
|
|
|
|
2
|
|
|
<?php |
3
|
|
|
/*************************************************************************** |
4
|
|
|
* For license information see doc/license.txt |
5
|
|
|
* |
6
|
|
|
* Unicode Reminder メモ |
7
|
|
|
* |
8
|
|
|
* Dieses Script erstellt den Suchindex für Ortsnamen aus den Daten der |
9
|
|
|
* Opengeodb. (Obsolet, dieser Suchindex wird nicht verwendet.) |
10
|
|
|
***************************************************************************/ |
11
|
|
|
|
12
|
|
|
$opt['rootpath'] = __DIR__ . '/../../'; |
13
|
|
|
require_once __DIR__ . '/../../lib2/cli.inc.php'; |
14
|
|
|
require_once __DIR__ . '/../../lib2/search/search.inc.php'; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
sql('DELETE FROM geodb_search'); |
18
|
|
|
|
19
|
|
|
$rs = sql( |
20
|
|
|
"SELECT `loc_id`, `text_val` |
21
|
|
|
FROM `geodb_textdata` |
22
|
|
|
WHERE `text_type` = 500100000 |
23
|
|
|
AND text_locale IN ('da', 'de', 'en', 'fi', 'fr', 'it', 'nl', 'rm')" |
24
|
|
|
); |
25
|
|
|
|
26
|
|
|
while ($r = sql_fetch_array($rs)) { |
27
|
|
|
$simpleTexts = search_text2sort($r['text_val']); |
28
|
|
|
$simpleTextsArray = explode_multi($simpleTexts, ' -/,'); |
29
|
|
|
|
30
|
|
|
foreach ($simpleTextsArray as $text) { |
31
|
|
|
if ($text !== '') { |
32
|
|
|
if (nonAlpha($text)) { |
33
|
|
|
die($text . "\n"); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
$simpleText = search_text2simple($text); |
37
|
|
|
|
38
|
|
|
sql( |
39
|
|
|
"INSERT INTO `geodb_search` (`loc_id`, `sort`, `simple`, `simplehash`) |
40
|
|
|
VALUES ('&1', '&2', '&3', '&4')", |
41
|
|
|
$r['loc_id'], |
42
|
|
|
$text, |
43
|
|
|
$simpleText, |
44
|
|
|
sprintf('%u', crc32($simpleText)) |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
mysql_free_result($rs); |
50
|
|
|
|
51
|
|
View Code Duplication |
function nonAlpha($str) |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
$strLength = mb_strlen($str); |
54
|
|
|
for ($i = 0; $i < $strLength; $i ++) { |
55
|
|
|
if (!((ord(mb_substr($str, $i, 1)) >= ord('a')) && (ord(mb_substr($str, $i, 1)) <= ord('z')))) { |
56
|
|
|
return true; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return false; |
61
|
|
|
} |
62
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.