I18n fixes
[squirrelmail.git] / plugins / spamcop / setup.php
1 <?php
2 /**
3 * setup.php -- SpamCop plugin - setup script
4 *
5 * @copyright (c) 1999-2004 The SquirrelMail development team
6 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
7 * @version $Id$
8 * @package plugins
9 * @subpackage spamcop
10 */
11
12 /** @ignore */
13 require_once(SM_PATH . 'functions/global.php');
14
15 /** Disable Quick Reporting by default */
16 $spamcop_quick_report = false;
17
18 /**
19 * Initialize the plugin
20 * @access private
21 */
22 function squirrelmail_plugin_init_spamcop() {
23 global $squirrelmail_plugin_hooks, $data_dir, $username,
24 $spamcop_is_composing;
25
26 $squirrelmail_plugin_hooks['optpage_register_block']['spamcop'] =
27 'spamcop_options';
28 $squirrelmail_plugin_hooks['loading_prefs']['spamcop'] =
29 'spamcop_load';
30 $squirrelmail_plugin_hooks['read_body_header_right']['spamcop'] =
31 'spamcop_show_link';
32
33 sqgetGlobalVar('spamcop_is_composing' , $spamcop_is_composing);
34
35 if (isset($spamcop_is_composing)) {
36 $squirrelmail_plugin_hooks['compose_send']['spamcop'] =
37 'spamcop_while_sending';
38 }
39 }
40
41
42 /**
43 * Loads spamcop settings and validates some of values (make '' into 'default', etc.)
44 * @access private
45 */
46 function spamcop_load() {
47 global $username, $data_dir, $spamcop_enabled, $spamcop_delete,
48 $spamcop_method, $spamcop_id, $spamcop_quick_report, $spamcop_type;
49
50 $spamcop_enabled = getPref($data_dir, $username, 'spamcop_enabled');
51 $spamcop_delete = getPref($data_dir, $username, 'spamcop_delete');
52 $spamcop_method = getPref($data_dir, $username, 'spamcop_method');
53 $spamcop_type = getPref($data_dir, $username, 'spamcop_type');
54 $spamcop_id = getPref($data_dir, $username, 'spamcop_id');
55 if ($spamcop_method == '') {
56 // Default to web_form. It is faster.
57 $spamcop_method = 'web_form';
58 setPref($data_dir, $username, 'spamcop_method', $spamcop_method);
59 }
60 if (! $spamcop_quick_report && $spamcop_method=='quick_email') {
61 $spamcop_method = 'web_form';
62 setPref($data_dir, $username, 'spamcop_method', $spamcop_method);
63 }
64 if ($spamcop_type == '') {
65 $spamcop_type = 'free';
66 setPref($data_dir, $username, 'spamcop_type', $spamcop_type);
67 }
68 if ($spamcop_id == '')
69 $spamcop_enabled = 0;
70 }
71
72
73 /**
74 * Shows spamcop link on the read-a-message screen
75 * @access private
76 */
77 function spamcop_show_link() {
78 global $spamcop_enabled, $spamcop_method, $spamcop_quick_report,$javascript_on;
79
80 if (! $spamcop_enabled)
81 return;
82
83 /* GLOBALS */
84 sqgetGlobalVar('passed_id', $passed_id, SQ_FORM);
85 sqgetGlobalVar('passed_ent_id',$passed_ent_id,SQ_FORM);
86 sqgetGlobalVar('mailbox', $mailbox, SQ_FORM);
87 sqgetGlobalVar('startMessage', $startMessage, SQ_FORM);
88 /* END GLOBALS */
89
90 // catch unset passed_ent_id
91 if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_FORM) ) {
92 $passed_ent_id = 0;
93 }
94
95 echo "<br>\n";
96
97 /*
98 Catch situation when user use quick_email and does not update
99 preferences. User gets web_form link. If prefs are set to
100 quick_email format - they will be updated after clicking the link
101 */
102 if (! $spamcop_quick_report && $spamcop_method=='quick_email') {
103 $spamcop_method = 'web_form';
104 }
105
106 // Javascript is used only in web based reporting
107 // don't insert javascript if javascript is disabled
108 if ($spamcop_method == 'web_form' && $javascript_on) {
109 ?><script language="javascript" type="text/javascript">
110 document.write('<a href="../plugins/spamcop/spamcop.php?passed_id=<?PHP echo urlencode($passed_id); ?>&amp;js_web=1&amp;mailbox=<?PHP echo urlencode($mailbox); ?>&amp;passed_ent_id=<?PHP echo urlencode($passed_ent_id); ?>" target="_blank">');
111 document.write("<?PHP echo _("Report as Spam"); ?>");
112 document.write("</a>");
113 </script><?PHP
114 } else {
115 ?><a href="../plugins/spamcop/spamcop.php?passed_id=<?PHP echo urlencode($passed_id); ?>&amp;mailbox=<?PHP echo urlencode($mailbox); ?>&amp;startMessage=<?PHP echo urlencode($startMessage); ?>&amp;passed_ent_id=<?PHP echo urlencode($passed_ent_id); ?>">
116 <?PHP echo _("Report as Spam"); ?></a>
117 <?PHP
118 }
119 }
120
121 /**
122 * Show spamcop options block
123 * @access private
124 */
125 function spamcop_options()
126 {
127 global $optpage_blocks;
128
129 $optpage_blocks[] = array(
130 'name' => _("SpamCop - Spam Reporting"),
131 'url' => '../plugins/spamcop/options.php',
132 'desc' => _("Help fight the battle against unsolicited email. SpamCop reads the spam email and determines the correct addresses to send complaints to. Quite fast, really smart, and easy to use."),
133 'js' => false
134 );
135 }
136
137
138 /**
139 * When we send the email, we optionally trash it then too
140 * @access private
141 */
142 function spamcop_while_sending()
143 {
144 global $mailbox, $spamcop_delete, $spamcop_is_composing, $auto_expunge,
145 $username, $key, $imapServerAddress, $imapPort;
146
147 if ($spamcop_delete) {
148 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
149 $imapPort, 0);
150 sqimap_mailbox_select($imapConnection, $mailbox);
151 sqimap_messages_delete($imapConnection, $spamcop_is_composing,
152 $spamcop_is_composing, $mailbox);
153 if ($auto_expunge)
154 sqimap_mailbox_expunge($imapConnection, $mailbox, true);
155 }
156 }
157
158 ?>