/[corp_html]/mnogo/common.inc
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /mnogo/common.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations)
Wed Mar 27 16:00:18 2002 UTC (22 years, 1 month ago) by dpavlin
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +0 -0 lines
FILE REMOVED
*** empty log message ***

1 dpavlin 1.1 <?
2    
3     // -----------------------------------------------
4     // exit_local()
5     // -----------------------------------------------
6     function exit_local($print_err = 1) {
7     drop_temp_table($print_err);
8     exit;
9     }
10    
11     // -----------------------------------------------
12     // print_error_local($str)
13     // -----------------------------------------------
14     function print_error_local($str){
15     global $error;
16    
17     $error=$str;
18    
19     print_template('error');
20     print_template('bottom');
21    
22     exit_local(0);
23     }
24    
25     // -----------------------------------------------
26     // get_dict_tab(word)
27     // -----------------------------------------------
28     function get_dict_tab($word) {
29     global $dict_table;
30    
31     if (strlen($word)>16) return $dict_table[17];
32     return $dict_table[strlen($word)];
33     }
34    
35     // -----------------------------------------------
36     // is_stopword($word)
37     // -----------------------------------------------
38     function is_stopword($word) {
39     global $DEBUG;
40     global $stopword_arr;
41    
42     if ($stopword_arr[$word]) return ($stopword_arr[$word]);
43    
44     $query="SELECT count(*) FROM stopword WHERE word='$word'";
45     if($DEBUG) echo "is_stopword(): ",$query,"<BR><HR>";
46    
47     if (!($res=db_query($query))) print_error_local('Query error: '.$query."\n<BR>".db_error());
48    
49     $row=db_fetchrow($res);
50     db_freeresult($res);
51    
52     $stopword_arr[$word]=$row[0];
53    
54     return ($row[0]);
55     }
56    
57     // -----------------------------------------------
58     // get_doc_count()
59     // -----------------------------------------------
60     function get_doc_count() {
61     global $DEBUG;
62    
63     $query="SELECT count(*) FROM url";
64     if($DEBUG) echo "get_doc_count(): ",$query,"<BR><HR>";
65    
66     if (!($res=db_query($query))) print_error_local('Query error: '.$query."\n<BR>".db_error());
67    
68     $row=db_fetchrow($res);
69     db_freeresult($res);
70    
71     return ($row[0]);
72     }
73    
74    
75     // -----------------------------------------------
76     // drop_temp_table()
77     // -----------------------------------------------
78     function drop_temp_table($print_err) {
79     global $temp_table;
80     global $DEBUG;
81     global $error;
82    
83     if ($temp_table != "") {
84     $drop_temp_query="DROP TABLE $temp_table";
85     if($DEBUG) echo "drop_temp_table(): ",$drop_temp_query,"<BR><HR>";
86    
87     if (!db_query($drop_temp_query)) {
88     if (! $print_err) {
89     print('Query error: '.$drop_temp_query."\n<BR>".db_error());
90     } else {
91     $error='Query error: '.$drop_temp_query."\n<BR>".db_error();
92     print_template('error');
93     print_template('bottom');
94     }
95     exit();
96     }
97     }
98     }
99    
100     // -----------------------------------------------
101     // track_query($query,$time,$found)
102     // -----------------------------------------------
103     function track_query($query,$time,$found) {
104     global $trackquery;
105     global $DEBUG;
106    
107     if ($trackquery != 'yes') return;
108    
109     $q="INSERT INTO qtrack VALUES ( '$query', $time, $found)";
110     if($DEBUG) echo "track_query(): ",$q,"<BR><HR>";
111    
112     if (!db_query($q)) print('Query error: '.$q."\n<BR>".db_error());
113     }
114    
115     // -----------------------------------------------
116     // format_lastmod($lastmod)
117     // -----------------------------------------------
118     function format_lastmod($lastmod) {
119     global $db_format;
120    
121     $temp=$lastmod;
122     if ($db_format == '3.1') {
123     if (!$temp) $temp = 'undefined';
124     else $temp = strftime('%a, %d %b %Y %H:%M:%S %Z',$temp);
125     } else {
126     if ($temp == '') $temp = 'undefined';
127     }
128    
129     return $temp;
130     }
131    
132     // -----------------------------------------------
133     // format_dp($dp)
134     // -----------------------------------------------
135     function format_dp($dp) {
136     $result=0;
137    
138     while ($dp != '') {
139     if (preg_match('/^([\-\+]?\d+)([sMhdmy]?)/',$dp,$param)) {
140     switch ($param[2]) {
141     case 's': $multiplier=1; break;
142     case 'M': $multiplier=60; break;
143     case 'h': $multiplier=3600; break;
144     case 'd': $multiplier=3600*24; break;
145     case 'm': $multiplier=3600*24*31; break;
146     case 'y': $multiplier=3600*24*365; break;
147     default: $multiplier=1;
148     }
149    
150     $result += $param[1]*$multiplier;
151     $dp=preg_replace("/^[\-\+]?\d+$param[2]/",'',$dp);
152     } else {
153     return 0;
154     }
155     }
156    
157     return $result;
158     }
159    
160     // -----------------------------------------------
161     // format_userdate($date)
162     // -----------------------------------------------
163     function format_userdate($date) {
164     $result=0;
165    
166     if (preg_match('/^(\d+)\/(\d+)\/(\d+)$/',$date,$param)) {
167     $day=$param[1];
168     $mon=$param[2];
169     $year=$param[3];
170    
171     $result=mktime(0,0,0,$mon,$day,$year);
172     }
173    
174     return $result;
175     }
176    
177     // -----------------------------------------------
178     // load_cs($cat)
179     // -----------------------------------------------
180     function load_cs($cat) {
181     global $DEBUG;
182     global $self;
183    
184     $query="SELECT path,link,name
185     FROM categories
186     WHERE path LIKE '$cat"."__'
187     ORDER BY NAME ASC";
188    
189     if($DEBUG) echo "load_cs(): ",$query,"<BR><HR>";
190    
191     if (!($res=db_query($query))) print('Query error: '.$query."\n<BR>".db_error());
192    
193     while($row=db_fetchrow($res)) {
194     $path=$row[0];
195     $link=$row[1];
196     $name=$row[2];
197    
198     if (substr($path,strlen($path)-2,2)=='@@') {
199     $result .= "<a href=\"$self?cat=$link\">@ $name</a><br>\n";
200     } else {
201     $result .= "<a href=\"$self?cat=$path\">$name</a><br>\n";
202     }
203     }
204     db_freeresult($res);
205    
206     return $result;
207     }
208    
209     // -----------------------------------------------
210     // load_cp($cat)
211     // -----------------------------------------------
212     function load_cp($cat) {
213     global $DEBUG;
214     global $self;
215     global $cp_arr;
216    
217     if ($cp_arr[$cat]) return ($cp_arr[$cat]);
218    
219     $link_path=$cat;
220     $link_name='';
221    
222     while ($link_path!='') {
223     $query="SELECT name FROM categories WHERE path='$link_path'";
224    
225     if($DEBUG) echo "load_cp(): ",$query,"<BR><HR>";
226    
227     if (!($res=db_query($query))) {
228     print_error_local('Query error: '.$query."\n<BR>".db_error());
229     }
230    
231     $row=db_fetchrow($res);
232     db_freeresult($res);
233    
234     if (!$row) {
235     $link_path=substr($link_path,0,strlen($link_path)-2);
236     continue;
237     }
238    
239     $row[0]=htmlspecialchars($row[0]);
240    
241     $link_name = " > <a href=\"$self?cat=$link_path\">$row[0]</a>".$link_name;
242    
243     $link_path=substr($link_path,0,strlen($link_path)-2);
244     }
245    
246     $query="SELECT name FROM categories WHERE path='' OR path IS NULL";
247    
248     if($DEBUG) echo "load_cp(): ",$query,"<BR><HR>";
249    
250     if (!($res=db_query($query))) {
251     print_error_local('Query error: '.$query."\n<BR>".db_error());
252     }
253    
254     $row=db_fetchrow($res);
255     db_freeresult($res);
256    
257     if ($row) {
258     $row[0]=htmlspecialchars($row[0]);
259     $link_name = " > <a href=\"$self?cat=\">$row[0]</a>".$link_name;
260     } else {
261     $link_name='';
262     }
263    
264     $cp_arr[$cat]=$link_name;
265    
266     return $link_name;
267     }
268    
269    
270     // -----------------------------------------------
271     // get_micro_time()
272     // -----------------------------------------------
273     function get_micro_time() {
274     if (function_exists('microtime')) {
275     $result=microtime();
276     if (ereg('([0-9\.\,]+) +([0-9]+)',$result,$param)) {
277     $result=$param[2]+$param[1];
278     }
279     } else {
280     $result=time();
281     }
282     return $result;
283     }
284    
285     // -----------------------------------------------
286     // suggest_soundex($word)
287     // -----------------------------------------------
288     function suggest_soundex($word) {
289     global $DEBUG;
290     global $soundex_words;
291     global $all_words;
292    
293     global $ps,$o,$m,$cat,$dt, $dp, $dx, $dm, $dy, $dd, $db, $de;
294     global $ul_local,$ue_local,$t_local,$db_local,$de_local,$lang_local;
295    
296     if (preg_match('/\d/',$word)) return '';
297    
298     $sdx = soundex($word);
299     if($DEBUG) echo "suggest_soundex($word): sdx=$sdx<BR>\n";
300    
301     if ($sdx == '0000') return '';
302    
303     $query="SELECT word FROM soundex WHERE soundex='$sdx'";
304    
305     if($DEBUG) echo "suggest_soundex($word): ",$query,"<BR><HR>\n";
306    
307     if (!($res=db_query($query))) {
308     print_error_local('Query error: '.$query."\n<BR>".db_error());
309     }
310    
311     if($DEBUG) echo "suggest_soundex($word): words found: ";
312     while ($row=db_fetchrow($res)) {
313     $word=$row[0];
314    
315     if ($soundex_words[$word]) continue;
316    
317     $flag=0;
318     for($i=0; $i<count($all_words); $i++) {
319     if ($all_words[$i] == $word) {
320     $flag=1;
321     break;
322     }
323     }
324     if ($flag) continue;
325    
326     $soundex_words[$word] = 1;
327    
328     if($DEBUG) echo "$word ";
329     $word_local=urlencode($word);
330     $result .= "<a href=\"$PHP_SELF?q=$word_local&m=$m".
331     ($ps==20?'':"&ps=$ps").
332     ($t==''?'':"&t=$t_local").
333     ($ul==''?'':"&ul=$ul_local").
334     ($ue==''?'':"&ue=$ue_local").
335     (!$o?'':"&o=$o").
336     ($dt=='back'?'':"&dt=$dt").
337     (!$dp?'':"&dp=$dp").
338     (!$dx?'':"&dx=$dx").
339     ($dd=='01'?'':"&dd=$dd").
340     (!$dm?'':"&dm=$dm").
341     ($dy=='1970'?'':"&dy=$dy").
342     ($db=='01/01/1970'?'':"&db=$db_local").
343     ($de=='31/12/2020'?'':"&de=$de_local").
344     ($cat==''?'':"&cat=$cat").
345     ($lang==''?'':"&lang=$lang_local").
346     "\">$word</a> ";
347     }
348     if($DEBUG) echo "<br>";
349    
350     db_freeresult($res);
351    
352     return $result;
353    
354     }
355    
356     ?>

  ViewVC Help
Powered by ViewVC 1.1.26