Make listcommands work with php 4.0.4 and 4.0.5. Thanks Oyku Gencay.
[squirrelmail.git] / plugins / listcommands / setup.php
CommitLineData
73ee43b1 1<?php
519f07d7 2
3/**
4 * setup.php
5 *
76911253 6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
519f07d7 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
73ee43b1 8 *
9 * Implementation of RFC 2369 for SquirrelMail.
10 * When viewing a message from a mailinglist complying with this RFC,
11 * this plugin displays a menu which gives the user a choice of mailinglist
12 * commands such as (un)subscribe, help and list archives.
13 *
519f07d7 14 * $Id$
73ee43b1 15 */
519f07d7 16
17function squirrelmail_plugin_init_listcommands () {
73ee43b1 18 global $squirrelmail_plugin_hooks;
19
20 $squirrelmail_plugin_hooks['read_body_header']['listcommands'] = 'plugin_listcommands_menu';
21}
22
d54c9a9c 23function plugin_listcommands_menu() {
83feb57a 24 global $passed_id, $passed_ent_id, $color, $mailbox,
25 $message, $compose_new_win;
73ee43b1 26
d54c9a9c 27 /**
28 * Array of commands we can deal with from the header. The Reply option
29 * is added later because we generate it using the Post information.
73ee43b1 30 */
83feb57a 31 $fieldsdescr = array('post' => _("Post to List"),
32 'reply' => _("Reply to List"),
33 'subscribe' => _("Subscribe"),
34 'unsubscribe' => _("Unsubscribe"),
35 'archive' => _("List Archives"),
36 'owner' => _("Contact Listowner"),
37 'help' => _("Help"));
ff5d0719 38 $output = array();
83feb57a 39
40 foreach ($message->rfc822_header->mlist as $cmd => $actions) {
41
42 /* I don't know this action... skip it */
53b3a6f0 43 /* array_key_exists works only in >= 4.1 */
44 if ( !in_array($cmd, array_keys($fieldsdescr)) ) {
83feb57a 45 continue;
d54c9a9c 46 }
d54c9a9c 47
83feb57a 48 /* proto = {mailto,href} */
49 $proto = array_shift(array_keys($actions));
50 $act = array_shift($actions);
73ee43b1 51
83feb57a 52 if ($proto == 'mailto') {
050722c4 53
83feb57a 54 if (($cmd == 'post') || ($cmd == 'owner')) {
73ee43b1 55 $url = 'compose.php?';
050722c4 56 } else {
f6f50b4d 57 $url = "../plugins/listcommands/mailout.php?action=$cmd&amp;";
73ee43b1 58 }
83feb57a 59 $url .= 'send_to=' . strtr($act,'?','&');
050722c4 60
9c3e6cd4 61 if ($compose_new_win == '1') {
b1379bdf 62 $output[] = "<a href=\"javascript:void(0)\" onclick=\"comp_in_new('$url')\">" . $fieldsdescr[$cmd] . '</a>';
9c3e6cd4 63 }
64 else {
b1379bdf 65 $output[] = '<a href="' . $url . '">' . $fieldsdescr[$cmd] . '</a>';
9c3e6cd4 66 }
83feb57a 67 if ($cmd == 'post') {
d6ba3a2d 68 $url .= '&amp;passed_id='.$passed_id.
69 '&amp;mailbox='.urlencode($mailbox).
70 (isset($passed_ent_id)?'&amp;passed_ent_id='.$passed_ent_id:'');
71 $url .= '&amp;action=reply';
91e33f2c 72 if ($compose_new_win == '1') {
b1379bdf 73 $output[] = "<a href=\"javascript:void(0)\" onclick=\"comp_in_new('$url')\">" . $fieldsdescr['reply'] . '</a>';
9feb4369 74 } else {
b1379bdf 75 $output[] = '<a href="' . $url . '">' . $fieldsdescr['reply'] . '</a>';
91e33f2c 76 }
9c3e6cd4 77 }
9feb4369 78 } else if ($proto == 'href') {
b1379bdf 79 $output[] = '<a href="' . $act . '" target="_blank">'
80 . $fieldsdescr[$cmd] . '</a>';
73ee43b1 81 }
73ee43b1 82 }
83
73ee43b1 84 if (count($output) > 0) {
b1379bdf 85 echo '<tr>';
86 echo html_tag('td', '<b>' . _("Mailing List") . ':&nbsp;&nbsp;</b>',
87 'right', '', 'valign="middle" width="20%"') . "\n";
88 echo html_tag('td', '<small>' . implode('&nbsp;|&nbsp;', $output) . '</small>',
89 'left', $color[0], 'valign="middle" width="80%"') . "\n";
90 echo '</tr>';
73ee43b1 91 }
050722c4 92}
d54c9a9c 93
94?>