Fix incorrect stristr() parameter order
[squirrelmail.git] / plugins / spamcop / setup.php
index f62b441f3a5b473942a8f38be61545992ed97267..fbb2d4791cf71effc1927198ade105e54434d454 100755 (executable)
@@ -1,18 +1,15 @@
 <?php
+
 /**
  * setup.php -- SpamCop plugin - setup script
  *
- * @copyright (c) 1999-2005 The SquirrelMail Project Team
+ * @copyright &copy; 1999-2009 The SquirrelMail Project Team
  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package plugins
  * @subpackage spamcop
  */
 
-/** Disable Quick Reporting by default */
-global $spamcop_quick_report;
-$spamcop_quick_report = false;
-
 /**
  * Initialize the plugin
  * @access private
@@ -30,36 +27,13 @@ function squirrelmail_plugin_init_spamcop() {
         'spamcop_while_sending';
 }
 
-
 /**
  * Loads spamcop settings and validates some of values (make '' into 'default', etc.)
  * @access private
  */
 function spamcop_load() {
-    global $username, $data_dir, $spamcop_enabled, $spamcop_delete, $spamcop_save,
-           $spamcop_method, $spamcop_id, $spamcop_quick_report, $spamcop_type;
-
-    $spamcop_enabled = getPref($data_dir, $username, 'spamcop_enabled');
-    $spamcop_delete = getPref($data_dir, $username, 'spamcop_delete');
-    $spamcop_save = getPref($data_dir, $username, 'spamcop_save',true);
-    $spamcop_method = getPref($data_dir, $username, 'spamcop_method');
-    $spamcop_type = getPref($data_dir, $username, 'spamcop_type');
-    $spamcop_id = getPref($data_dir, $username, 'spamcop_id');
-    if ($spamcop_method == '') {
-        // Default to web_form. It is faster.
-        $spamcop_method = 'web_form';
-        setPref($data_dir, $username, 'spamcop_method', $spamcop_method);
-    }
-    if (! $spamcop_quick_report && $spamcop_method=='quick_email') {
-        $spamcop_method = 'web_form';
-        setPref($data_dir, $username, 'spamcop_method', $spamcop_method);
-    }
-    if ($spamcop_type == '') {
-        $spamcop_type = 'free';
-        setPref($data_dir, $username, 'spamcop_type', $spamcop_type);
-    }
-    if ($spamcop_id == '')
-        $spamcop_enabled = 0;
+    include_once(SM_PATH . 'plugins/spamcop/functions.php');
+    spamcop_load_function();
 }
 
 
@@ -67,50 +41,9 @@ function spamcop_load() {
  * Shows spamcop link on the read-a-message screen
  * @access private
  */
-function spamcop_show_link() {
-    global $spamcop_enabled, $spamcop_method, $spamcop_quick_report,$javascript_on;
-
-    if (! $spamcop_enabled)
-        return;
-
-    /* GLOBALS */
-    sqgetGlobalVar('passed_id',    $passed_id,    SQ_FORM);
-    sqgetGlobalVar('passed_ent_id',$passed_ent_id,SQ_FORM);
-    sqgetGlobalVar('mailbox',      $mailbox,      SQ_FORM);
-    if ( sqgetGlobalVar('startMessage', $startMessage, SQ_FORM) ) {
-        $startMessage = (int)$startMessage;
-    }
-    /* END GLOBALS */
-
-    // catch unset passed_ent_id
-    if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_FORM) ) {
-        $passed_ent_id = 0;
-    }
-
-    echo "<br />\n";
-
-    /*
-       Catch situation when user uses quick_email and does not update
-       preferences. User gets web_form link. If prefs are set to
-       quick_email format - they will be updated after clicking the link
-     */
-    if (! $spamcop_quick_report && $spamcop_method=='quick_email') {
-        $spamcop_method = 'web_form';
-    }
-
-    // Javascript is used only in web based reporting
-    // don't insert javascript if javascript is disabled
-    if ($spamcop_method == 'web_form' && $javascript_on) {
-?><script language="javascript" type="text/javascript">
-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">');
-document.write("<?php echo _("Report as Spam"); ?>");
-document.write("</a>");
-</script><?php
-    } else {
-?><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); ?>">
-<?php echo _("Report as Spam"); ?></a>
-<?php
-    }
+function spamcop_show_link(&$links) {
+    include_once(SM_PATH . 'plugins/spamcop/functions.php');
+    spamcop_show_link_function($links);
 }
 
 /**
@@ -118,45 +51,16 @@ document.write("</a>");
  * @access private
  */
 function spamcop_options() {
-    global $optpage_blocks;
-
-    $optpage_blocks[] = array(
-            'name' => _("SpamCop - Spam Reporting"),
-            'url' => '../plugins/spamcop/options.php',
-            '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."),
-            'js' => false
-            );
+    include_once(SM_PATH . 'plugins/spamcop/functions.php');
+    spamcop_options_function();
 }
 
 
 /**
- * When we send the email, we optionally trash it then too
+ * Process messages submitted by email
  * @access private
  */
 function spamcop_while_sending() {
-    global $mailbox, $spamcop_delete, $spamcop_save, $spamcop_is_composing, $auto_expunge,
-           $username, $key, $imapServerAddress, $imapPort;
-
-    if (sqgetGlobalVar('spamcop_is_composing' , $spamcop_is_composing)) {
-        // delete spam message
-        if ($spamcop_delete) {
-            $imapConnection = sqimap_login($username, $key, $imapServerAddress,
-                $imapPort, 0);
-            sqimap_mailbox_select($imapConnection, $mailbox);
-            sqimap_msgs_list_delete($imapConnection, $mailbox, array($spamcop_is_composing));
-            if ($auto_expunge)
-                sqimap_mailbox_expunge($imapConnection, $mailbox, true);
-        }
-        if (! $spamcop_save) {
-            // disable use of send folder.
-            // Temporally override in order to disable saving of 'reply anyway' messages.
-            global $default_move_to_sent;
-            $default_move_to_sent=false;
-        }
-        // change default email composition setting. Plugin always operates in right frame.
-        // make sure that compose.php redirects to right page. Temporally override.
-        global $compose_new_win;
-        $compose_new_win = false;
-    }
+    include_once(SM_PATH . 'plugins/spamcop/functions.php');
+    spamcop_while_sending_function();
 }
-?>
\ No newline at end of file