File: setup.php

package info (click to toggle)
squirrelmail 1%3A1.2.6-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 8,300 kB
  • ctags: 4,949
  • sloc: php: 21,297; perl: 2,538; sh: 350; ansic: 122; makefile: 69
file content (489 lines) | stat: -rw-r--r-- 20,137 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
<?php

/**
 * setup.php
 *
 * Copyright (c) 1999-2002 The SquirrelMail Project Team
 * Licensed under the GNU GPL. For full terms see the file COPYING.
 *
 * $Id: setup.php,v 1.5 2001/12/23 07:42:39 thomppj Exp $
 */

/* Easy plugin that sends the body of the message to a new browser
window using the specified translator.  It can also translate your
outgoing message if you send it to someone in a different country. 

  Languages from i18n, incorporated in the auto-language selection:
    en - English
    no - Norwegian (Bokm&aring;l)
    no_NO_ny - Norwegian (Nynorsk)
    de - Deutsch
    ru - Russian KOI8-R
    pl - Polish
    sv - Swedish
    nl - Dutch
    pt_BR - Portuguese (Brazil)
    fr - French
    it - Italian
    cs - Czech
    es - Spanish
    ko - Korean
*/


/* Initialize the translation plugin */
function squirrelmail_plugin_init_translate() {
  global $squirrelmail_plugin_hooks;

  $squirrelmail_plugin_hooks['read_body_bottom']['translate'] = 'translate_read_form';
  $squirrelmail_plugin_hooks['optpage_register_block']['translate'] = 'translate_optpage_register_block';
  $squirrelmail_plugin_hooks['loading_prefs']['translate'] = 'translate_pref';
  $squirrelmail_plugin_hooks['compose_button_row']['translate'] = 'translate_button';
}


/* Show the translation for a message you're reading */
function translate_read_form() {
    global $color, $translate_server;
    global $body, $translate_dir;
    global $translate_show_read;

    if (!$translate_show_read) {
        return;
    }
    
    $translate_dir = 'to';
            
    $new_body = $body;
    $pos = strpos($new_body,
            '">Download this as a file</A></CENTER><BR></SMALL>');
    if (is_int($pos)) {
        $new_body = substr($new_body, 0, $pos);
    }
                     
    $trans = get_html_translation_table('HTMLENTITIES');
    $trans[' '] = '&nbsp;';
    $trans = array_flip($trans);
    $new_body = strtr($new_body, $trans);

    $new_body = urldecode($new_body);
    $new_body = strip_tags($new_body);
              
    /* I really don't like this next part ... */
    $new_body = str_replace('"', "''", $new_body);
    $new_body = strtr($new_body, "\n", ' ');
    
    $function = 'translate_form_' . $translate_server;
    $function($new_body);
}

function translate_table_end() {                     
  ?></td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
  </form>
  <?php
}


function translate_button() {
    global $translate_show_send;
  
    if (! $translate_show_send) {
        return;
    }
}


function translate_optpage_register_block() {
    global $optpage_blocks;
    $optpage_blocks[] = array(
        'name' => _("Translation Options"),
        'url'  => '../plugins/translate/options.php',
        'desc' => _("Which translator should be used when you get messages in a different language?"),
        'js'   => false
    );
}

function translate_pref() { 
    global $username, $data_dir;
    global $translate_server, $translate_location;
    global $translate_show_send, $translate_show_read;
    global $translate_same_window;

    $translate_server = getPref($data_dir, $username, 'translate_server');
    if ($translate_server == '') {
        $translate_server = 'babelfish';
    }
    
    $translate_location = getPref($data_dir, $username, 'translate_location');
    if ($translate_location == '') {
        $translate_location = 'center';
    }
    
    $translate_show_send = getPref($data_dir, $username, 'translate_show_send');
    $translate_show_read = getPref($data_dir, $username, 'translate_show_read');
    $translate_same_window = getPref($data_dir, $username, 'translate_same_window');
}


/**
 * This function could be sped up.
 * It basically negates the process if a ! is found in the beginning and
 * matches a * at the end with 0 or more characters.
 */
function translate_does_it_match_language($test) {
    global $squirrelmail_language;
    $true = 1;
    $false = 0;
    $index = 0;
    $smindex = 0;
  
    if (! $test || ! $squirrelmail_language) {
        return $false;
    }
      
    if ($test[$index] == '!') {
        $index ++;
        $true = 0;
        $false = 1;
    }
    
    if (($index == 0) && ($test == $squirrelmail_language)) {
        return $true;
    }
      
    while ($test[$index]) {
        if ($test[$index] == '*') {
            return $true;
        }
        if ($test[$index] != $squirrelmail_language[$smindex]) {
            return $false;
        }
        $index ++;
        $smindex ++;
    }
      
    return $false;
}


function translate_lang_opt($from, $to, $value, $text) {
    global $translate_dir;

    $ret = '  <option value="' . $value . '"';

    if (translate_does_it_match_language($to) && ($translate_dir == 'to')) {
        $ret .= ' SELECTED';
    }

    if (translate_does_it_match_language($from) && ($translate_dir == 'from')) {
        $ret .= ' SELECTED';
    }

    $ret .= '>' . $text . "</option>\n";

    return( $ret );
}


function translate_new_form($action) {
    global $translate_dir, $translate_new_window, $translate_location;
    global $color, $translate_same_window;

    echo '<form action="';
  
    if ($translate_dir == 'to') {
        echo $action;
    } else {
        echo 'translate.php';
    }
  
    echo '" method="post"';
  
    if (!$translate_same_window) {
        echo ' target="_blank"';
    }

    echo ">\n";

    ?><table align="<?php echo $translate_location ?>" cellpadding=3 cellspacing=0 border=0 bgcolor=<?php echo $color[10] ?>>
    <tr>
      <td>
        <table cellpadding=2 cellspacing=1 border=0 bgcolor="<?php echo $color[5] ?>">
          <tr>
            <td><?php
}

function translate_form_babelfish($message) {
    translate_new_form('http://babelfish.altavista.com/translate.dyn');
?>
    <input type="hidden" name="doit" value="done">
    <input type="hidden" name="BabelFishFrontPage" value="yes">
    <input type="hidden" name="bblType" value="urltext">
    <input type="hidden" name="urltext" value="<?php echo $message; ?>">
    <select name="lp"><?php
        echo translate_lang_opt('en',  'fr',  'en_fr',
                                sprintf( _("%s to %s"),
                                         _("English"),
                                         _("French"))) .
             translate_lang_opt('',    'de',  'en_de',
                                sprintf( _("%s to %s"),
                                         _("English"),
                                         _("German"))) .
             translate_lang_opt('',    'it',  'en_it',
                                sprintf( _("%s to %s"),
                                         _("English"),
                                         _("Italian"))) .
             translate_lang_opt('',    'pt*', 'en_pt',
                                sprintf( _("%s to %s"),
                                         _("English"),
                                         _("Portuguese"))) .
             translate_lang_opt('',    'es',  'en_es',
                                sprintf( _("%s to %s"),
                                         _("English"),
                                         _("Spanish"))) .
             translate_lang_opt('fr',  'en',  'fr_en',
                                sprintf( _("%s to %s"),
                                         _("French"),
                                         _("English"))) .
             translate_lang_opt('de',  '',    'de_en',
                                sprintf( _("%s to %s"),
                                         _("German"),
                                         _("English"))) .
             translate_lang_opt('it',  '',    'it_en',
                                sprintf( _("%s to %s"),
                                         _("Italian"),
                                         _("English"))) .
             translate_lang_opt('pt*', '',    'pt_en',
                                sprintf( _("%s to %s"),
                                         _("Portuguese"),
                                         _("English"))) .
             translate_lang_opt('es',  '',    'es_en',
                                sprintf( _("%s to %s"),
                                         _("Spanish"),
                                         _("English"))) .
             translate_lang_opt('',    '',    'de_fr',
                                sprintf( _("%s to %s"),
                                         _("German"),
                                         _("French"))) .
             translate_lang_opt('',    '',    'fr_de',
                                sprintf( _("%s to %s"),
                                         _("French"),
                                         _("German"))) .
             translate_lang_opt('ru',  '',    'ru_en',
                                sprintf( _("%s to %s"),
                                         _("Russian"),
                                         _("English")));
    echo '</select>'.
         'Babelfish: <input type="Submit" value="' . _("Translate") . '">';

    translate_table_end();
}

function translate_form_go($message) {
    translate_new_form('http://translator.go.com/cb/trans_entry');
?>
    <input type=hidden name=input_type value=text>
    <select name=lp><?php
        echo translate_lang_opt('en', 'es', 'en_sp',
                                sprintf( _("%s to %s"),
                                         _("English"),
                                         _("Spanish"))) .
             translate_lang_opt('',   'fr', 'en_fr',
                                sprintf( _("%s to %s"),
                                         _("English"),
                                         _("French"))) .
             translate_lang_opt('',   'de', 'en_ge',
                                sprintf( _("%s to %s"),
                                         _("English"),
                                         _("German"))) .
             translate_lang_opt('',   'it', 'en_it',
                                sprintf( _("%s to %s"),
                                         _("English"),
                                         _("Italian"))) .
             translate_lang_opt('',   'pt', 'en_pt',
                                sprintf( _("%s to %s"),
                                         _("English"),
                                         _("Portuguese"))) .
             translate_lang_opt('es', 'en', 'sp_en',
                                sprintf( _("%s to %s"),
                                         _("Spanish"),
                                         _("English"))) .
             translate_lang_opt('fr', '',   'fr_en',
                                sprintf( _("%s to %s"),
                                         _("French"),
                                         _("English"))) .
             translate_lang_opt('de', '',   'ge_en',
                                sprintf( _("%s to %s"),
                                         _("German"),
                                         _("English"))) .
             translate_lang_opt('it', '',   'it_en',
                                sprintf( _("%s to %s"),
                                         _("Italian"),
                                         _("English"))) .
             translate_lang_opt('pt', '',   'pt_en',
                                sprintf( _("%s to %s"),
                                         _("Portuguese"),
                                         _("English")));
    echo '</select>'.
         "<input type=\"hidden\" name=\"text\" value=\"$message\">".
         'Go.com: <input type="Submit" value="' . _("Translate") . '">';

    translate_table_end();
}

function translate_form_intertran($message) {
    translate_new_form('http://www.tranexp.com:2000/InterTran');
    echo '<INPUT TYPE="hidden" NAME="topframe" VALUE="yes">'.
         '<INPUT TYPE="hidden" NAME="type" VALUE="text">'.
         "<input type=\"hidden\" name=\"text\" value=\"$message\">";

    $left = '<SELECT name="from">' .
        translate_lang_opt('pt_BR', '',    'pob', _("Brazilian Portuguese")).
        translate_lang_opt('',      '',    'bul', _("Bulgarian") . ' (CP 1251)').
        translate_lang_opt('',      '',    'cro', _("Croatian") . ' (CP 1250)').
        translate_lang_opt('cs',    '',    'che', _("Czech") . ' (CP 1250)').
        translate_lang_opt('',      '',    'dan', _("Danish")).
        translate_lang_opt('nl',    '',    'dut', _("Dutch")).
        translate_lang_opt('en',    '!en', 'eng', _("English")).
        translate_lang_opt('',      '',    'spe', _("European Spanish")).
        translate_lang_opt('',      '',    'fin', _("Finnish")).
        translate_lang_opt('fr',    '',    'fre', _("French")).
        translate_lang_opt('de',    '',    'ger', _("German")).
        translate_lang_opt('',      '',    'grk', _("Greek")).
        translate_lang_opt('',      '',    'hun', _("Hungarian") . ' (CP 1250)').
        translate_lang_opt('',      '',    'ice', _("Icelandic")).
        translate_lang_opt('it',    '',    'ita', _("Italian")).
        translate_lang_opt('',      '',    'jpn', _("Japanese") . ' (Shift JIS)').
        translate_lang_opt('',      '',    'spl', _("Latin American Spanish")).
        translate_lang_opt('no*',   '',    'nor', _("Norwegian")).
        translate_lang_opt('pl',    '',    'pol', _("Polish") . ' (ISO 8859-2)').
        translate_lang_opt('',      '',    'poe', _("Portuguese")).
        translate_lang_opt('',      '',    'rom', _("Romanian") . ' (CP 1250)').
        translate_lang_opt('ru',    '',    'rus', _("Russian") . ' (CP 1251)').
        translate_lang_opt('',      '',    'sel', _("Serbian") . ' (CP 1250)').
        translate_lang_opt('',      '',    'slo', _("Slovenian") . ' (CP 1250)').
        translate_lang_opt('es',    '',    'spa', _("Spanish")).
        translate_lang_opt('sv',    '',    'swe', _("Swedish")).
        translate_lang_opt('',      '',    'wel', _("Welsh")).
        '</SELECT>';

    $right = '<SELECT name="to">'.
        translate_lang_opt('',    'pt_BR', 'pob', _("Brazilian Portuguese")).
        translate_lang_opt('',    '',      'bul', _("Bulgarian") . ' (CP 1251)').
        translate_lang_opt('',    '',      'cro', _("Croatian") . ' (CP 1250)').
        translate_lang_opt('',    'cs',    'che', _("Czech") . ' (CP 1250)').
        translate_lang_opt('',    '',      'dan', _("Danish")).
        translate_lang_opt('',    'nl',    'dut', _("Dutch")).
        translate_lang_opt('!en', 'en',    'eng', _("English")).
        translate_lang_opt('',    '',      'spe', _("European Spanish")).
        translate_lang_opt('',    '',      'fin', _("Finnish")).
        translate_lang_opt('',    'fr',    'fre', _("French")).
        translate_lang_opt('',    'de',    'ger', _("German")).
        translate_lang_opt('',    '',      'grk', _("Greek")).
        translate_lang_opt('',    '',      'hun', _("Hungarian") . ' (CP 1250)').
        translate_lang_opt('',    '',      'ice', _("Icelandic")).
        translate_lang_opt('',    'it',    'ita', _("Italian")).
        translate_lang_opt('',    '',      'jpn', _("Japanese") . ' (Shift JIS)').
        translate_lang_opt('',    '',      'spl', _("Latin American Spanish")).
        translate_lang_opt('',    'no*',   'nor', _("Norwegian")).
        translate_lang_opt('',    'pl',    'pol', _("Polish") . ' (ISO 8859-2)').
        translate_lang_opt('',    '',      'poe', _("Portuguese")).
        translate_lang_opt('',    '',      'rom', _("Romanian") . ' (CP 1250)').
        translate_lang_opt('',    'ru',    'rus', _("Russian") . ' (CP 1251)').
        translate_lang_opt('',    '',      'sel', _("Serbian") . ' (CP 1250)').
        translate_lang_opt('',    '',      'slo', _("Slovenian") . ' (CP 1250)').
        translate_lang_opt('',    'es',    'spa', _("Spanish")).
        translate_lang_opt('',    'sv',    'swe', _("Swedish")).
        translate_lang_opt('',    '',      'wel', _("Welsh")).
        '</SELECT>';
    printf( _("%s to %s"), $left, $right );
    echo 'InterTran: <input type=submit value="' . _("Translate") . '">';

    translate_table_end();
}

function translate_form_gpltrans($message) {
    translate_new_form('http://www.translator.cx/cgi-bin/gplTrans');
    echo '<select name="toenglish">';
    translate_lang_opt('en',  '!en', 'no',  'From English');
    translate_lang_opt('!en', 'en',  'yes', 'To English');
    echo '</select><select name="language">'.
        translate_lang_opt('nl', 'nl', 'dutch_dict',      _("Dutch")).
        translate_lang_opt('fr', 'fr', 'french_dict',     _("French")).
        translate_lang_opt('de', 'de', 'german_dict',     _("German")).
        translate_lang_opt('',   '',   'indonesian_dict', _("Indonesian")).
        translate_lang_opt('it', 'it', 'italian_dict',    _("Italian")).
        translate_lang_opt('',   '',   'latin_dict',      _("Latin")).
        translate_lang_opt('pt', 'pt', 'portuguese_dict', _("Portuguese")).
        translate_lang_opt('es', 'es', 'spanish_dict',    _("Spanish")).
        '</select>'.
        "<input type=hidden name=text value=\"$message\">".
        'GPLTrans: <input type="submit" value="' . _("Translate") . '">';

    translate_table_end();
}

function translate_form_dictionary($message) {
    translate_new_form('http://translate.dictionary.com:8800/systran/cgi');
    echo '<INPUT TYPE=HIDDEN NAME=partner VALUE=LEXICO>'.
         "<input type=hidden name=urltext value=\"$message\">".
         '<SELECT NAME="lp">'.
         translate_lang_opt('en',  'fr', 'en_fr',
                            sprintf( _("%s to %s"),
                                     _("English"),
                                     _("French"))) .
         translate_lang_opt('',    'de', 'en_de',
                            sprintf( _("%s to %s"),
                                     _("English"),
                                     _("German"))) .
         translate_lang_opt('',    'it', 'en_it',
                            sprintf( _("%s to %s"),
                                     _("English"),
                                     _("Italian"))) .
         translate_lang_opt('',    'pt*', 'en_pt',
                            sprintf( _("%s to %s"),
                                     _("English"),
                                     _("Portuguese"))) .
         translate_lang_opt('',    'es', 'en_sp',
                            sprintf( _("%s to %s"),
                                     _("English"),
                                     _("Spanish"))) .
         translate_lang_opt('fr',  '', 'fr_en',
                            sprintf( _("%s to %s"),
                                     _("French"),
                                     _("English"))) .
         translate_lang_opt('',    '', 'fr_ge',
                            sprintf( _("%s to %s"),
                                     _("French"),
                                     _("German"))) .
         translate_lang_opt('',    '', 'ge_fr',
                            sprintf( _("%s to %s"),
                                     _("German"),
                                     _("French"))) .
         translate_lang_opt('de',  '', 'de_en',
                            sprintf( _("%s to %s"),
                                     _("German"),
                                     _("English"))) .
         translate_lang_opt('it',  '', 'it_en',
                            sprintf( _("%s to %s"),
                                     _("Italian"),
                                     _("English"))) .
         translate_lang_opt('pt*', '', 'pt_en',
                            sprintf( _("%s to %s"),
                                     _("Portuguese"),
                                     _("English"))) .
         translate_lang_opt('es',  '', 'sp_en',
                            sprintf( _("%s to %s"),
                                     _("Spanish"),
                                     _("English"))) .
         '<\SELECT>'.
         'Dictionary.com: <INPUT TYPE="submit" VALUE="'._("Translate").'">';

  translate_table_end();
}
?>