stop loading functions in setup.php
[squirrelmail.git] / plugins / spamcop / setup.php
1 <?php
2 /**
3 * setup.php -- SpamCop plugin - setup script
4 *
5 * @copyright (c) 1999-2005 The SquirrelMail Project 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 /** Disable Quick Reporting by default */
13 global $spamcop_quick_report;
14 $spamcop_quick_report = false;
15
16 /**
17 * Initialize the plugin
18 * @access private
19 */
20 function squirrelmail_plugin_init_spamcop() {
21 global $squirrelmail_plugin_hooks;
22
23 $squirrelmail_plugin_hooks['optpage_register_block']['spamcop'] =
24 'spamcop_options';
25 $squirrelmail_plugin_hooks['loading_prefs']['spamcop'] =
26 'spamcop_load';
27 $squirrelmail_plugin_hooks['read_body_header_right']['spamcop'] =
28 'spamcop_show_link';
29 $squirrelmail_plugin_hooks['compose_send']['spamcop'] =
30 'spamcop_while_sending';
31 }
32
33
34 /**
35 * Loads spamcop settings and validates some of values (make '' into 'default', etc.)
36 * @access private
37 */
38 function spamcop_load() {
39 global $username, $data_dir, $spamcop_enabled, $spamcop_delete, $spamcop_save,
40 $spamcop_method, $spamcop_id, $spamcop_quick_report, $spamcop_type;
41
42 $spamcop_enabled = getPref($data_dir, $username, 'spamcop_enabled');
43 $spamcop_delete = getPref($data_dir, $username, 'spamcop_delete');
44 $spamcop_save = getPref($data_dir, $username, 'spamcop_save',true);
45 $spamcop_method = getPref($data_dir, $username, 'spamcop_method');
46 $spamcop_type = getPref($data_dir, $username, 'spamcop_type');
47 $spamcop_id = getPref($data_dir, $username, 'spamcop_id');
48 if ($spamcop_method == '') {
49 // Default to web_form. It is faster.
50 $spamcop_method = 'web_form';
51 setPref($data_dir, $username, 'spamcop_method', $spamcop_method);
52 }
53 if (! $spamcop_quick_report && $spamcop_method=='quick_email') {
54 $spamcop_method = 'web_form';
55 setPref($data_dir, $username, 'spamcop_method', $spamcop_method);
56 }
57 if ($spamcop_type == '') {
58 $spamcop_type = 'free';
59 setPref($data_dir, $username, 'spamcop_type', $spamcop_type);
60 }
61 if ($spamcop_id == '')
62 $spamcop_enabled = 0;
63 }
64
65
66 /**
67 * Shows spamcop link on the read-a-message screen
68 * @access private
69 */
70 function spamcop_show_link() {
71 global $spamcop_enabled, $spamcop_method, $spamcop_quick_report,$javascript_on;
72
73 if (! $spamcop_enabled)
74 return;
75
76 /* GLOBALS */
77 sqgetGlobalVar('passed_id', $passed_id, SQ_FORM);
78 sqgetGlobalVar('passed_ent_id',$passed_ent_id,SQ_FORM);
79 sqgetGlobalVar('mailbox', $mailbox, SQ_FORM);
80 if ( sqgetGlobalVar('startMessage', $startMessage, SQ_FORM) ) {
81 $startMessage = (int)$startMessage;
82 }
83 /* END GLOBALS */
84
85 // catch unset passed_ent_id
86 if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_FORM) ) {
87 $passed_ent_id = 0;
88 }
89
90 echo "<br />\n";
91
92 /*
93 Catch situation when user uses quick_email and does not update
94 preferences. User gets web_form link. If prefs are set to
95 quick_email format - they will be updated after clicking the link
96 */
97 if (! $spamcop_quick_report && $spamcop_method=='quick_email') {
98 $spamcop_method = 'web_form';
99 }
100
101 // Javascript is used only in web based reporting
102 // don't insert javascript if javascript is disabled
103 if ($spamcop_method == 'web_form' && $javascript_on) {
104 ?><script language="javascript" type="text/javascript">
105 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">');
106 document.write("<?php echo _("Report as Spam"); ?>");
107 document.write("</a>");
108 </script><?php
109 } else {
110 ?><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); ?>">
111 <?php echo _("Report as Spam"); ?></a>
112 <?php
113 }
114 }
115
116 /**
117 * Show spamcop options block
118 * @access private
119 */
120 function spamcop_options() {
121 global $optpage_blocks;
122
123 $optpage_blocks[] = array(
124 'name' => _("SpamCop - Spam Reporting"),
125 'url' => '../plugins/spamcop/options.php',
126 '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."),
127 'js' => false
128 );
129 }
130
131
132 /**
133 * When we send the email, we optionally trash it then too
134 * @access private
135 */
136 function spamcop_while_sending() {
137 global $mailbox, $spamcop_delete, $spamcop_save, $spamcop_is_composing, $auto_expunge,
138 $username, $key, $imapServerAddress, $imapPort;
139
140 if (sqgetGlobalVar('spamcop_is_composing' , $spamcop_is_composing)) {
141 // delete spam message
142 if ($spamcop_delete) {
143 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
144 $imapPort, 0);
145 sqimap_mailbox_select($imapConnection, $mailbox);
146 sqimap_msgs_list_delete($imapConnection, $mailbox, array($spamcop_is_composing));
147 if ($auto_expunge)
148 sqimap_mailbox_expunge($imapConnection, $mailbox, true);
149 }
150 if (! $spamcop_save) {
151 // disable use of send folder.
152 // Temporally override in order to disable saving of 'reply anyway' messages.
153 global $default_move_to_sent;
154 $default_move_to_sent=false;
155 }
156 // change default email composition setting. Plugin always operates in right frame.
157 // make sure that compose.php redirects to right page. Temporally override.
158 global $compose_new_win;
159 $compose_new_win = false;
160 }
161 }
162 ?>