The MU forums have moved to WordPress.org

wpmu-mailer (fixed version) kills my 'script (8 posts)

  1. Farms2
    Member
    Posted 17 years ago #

    So, have played around with Inviz's wpmu mailer plugin to make it work (thanks to quenting's corrections), 'de-cynicalise' it (by removing all mentions of spam and replacing them with 'email') and getting rid of the 'tags' (cos they never worked).

    But... when I upload it to mu-plugins it stuffs up teh write pages - making the 'Add categories' box be replaced by a big white block and all the options maximised... take it out and everything works again.

    I'm guessing this has something to do with javascript (of which I know even less that php - which is extra scary).

    Am I right? Is there an easy way to fix it? Many thanx! James

    <?
    /*
    Plugin Name: WPMU Mailer
    Description: Mass emailer for WPMU
    Version: 2
    License: GPL
    Author: Inviz
    Author URI: http://inviz.personart.ru
    */
    /*
    FOR ALL THOSE WHO WANT TO EDIT THIS:
    Folks, okay, i accept editing, edit it for your own purposes.
    BUT
    If u edited only some lines:
    DO NOT RELEASE IT WITH YOUR OWN COPYRIGHTS.
    Inviz, With luv.
    */
    add_action('admin_menu', 'mailer_menu');
    add_action('admin_head', 'mailer_installation');
    add_action('profile_personal_options','mailer_user_options');
    add_action('personal_options_update','mailer_user_options_update');
    function mailer_menu() {
    if (is_site_admin()) {
    add_submenu_page('post-new.php', 'mail', 'mail', 0, 'mailer', 'mailer');
    }
    }
    function user_recieve_spam($email) {
    global $wpmuBaseTablePrefix,$wpdb,$no_spam;
    if (!$no_spam) //not selected
    $no_spam=$wpdb->get_col('SELECT user_email FROM '.$wpmuBaseTablePrefix."spam");
    if (!$no_spam) //selected, but nothing in the table
    return false;
    else
    return in_array($email,$no_spam) ? true : false;
    }
    function mailer_installation() {
    global $wpdb,$wpmuBaseTablePrefix,$url;
    $wpdb->hide_errors();
    //checking if table exists -> installation is okay
    $T= $wpdb->get_var('select 1 from '.$wpmuBaseTablePrefix.'spam');
    if($T===null and $T!='0')
    $wpdb->query("CREATE TABLE ".$wpmuBaseTablePrefix."spam(
    id INT NOT NULL AUTO_INCREMENT ,
    user_email VARCHAR( 255 ) NOT NULL ,
    PRIMARY KEY ( id )
    ) TYPE = MYISAM ;");
    $wpdb->show_errors();
    }
    function get_current_user_email() {
    global $wpdb;
    return $wpdb->get_var( "SELECT user_email FROM $wpdb->users WHERE ID = '".get_current_user_id()."'" );
    }
    function mailer_user_options_update() {
    global $wpdb,$wpmuBaseTablePrefix;
    if (user_recieve_spam(get_current_user_email()) && $_POST['recieve_spam']==false) {
    $delete=$wpdb->query('DELETE FROM wp_spam WHERE user_email = "'.get_current_user_email().'"');
    } elseif (!user_recieve_spam(get_current_user_email()) && $_POST['recieve_spam']==true) {
    $wpdb->query('INSERT INTO wp_spam ( id , user_email )
    VALUES (
    "", "'.get_current_user_email().'"
    );');
    }
    }
    function mailer_user_options() {
    global $wpdb,$wpmuBaseTablePrefix;
    ?>
    <tr valign="top">
    <th scope="row">Newsletter:</th>
    <td><label for="recieve_spam">
    <input name="recieve_spam" type="checkbox" id="recieve_spam" <?php if (!$delete && user_recieve_spam(get_current_user_email())) echo 'checked="checked"'?>/>
    Do not recieve edublogs.org email newsletter</label></p></td>
    </tr>
    <?php
    }
    function mailer() {
    global $wpdb,$wpmuBaseTablePrefix,$current_site;
    if ($_POST && $_POST['from'] && $_POST['subject'] && $_POST['content']) {
    $users = $wpdb->get_results("SELECT user_email as mail, ID as id,user_url as url,user_login as login, display_name as name
    FROM ".$wpmuBaseTablePrefix."users GROUP BY user_email;",ARRAY_A);
    $headers = "From: ".$_POST['from']."rn" .
    'X-Mailer: PHP/' . phpversion() . "rn" .
    "MIME-Version: 1.0rn" .
    "Content-Type: text/html; charset=utf-8rn" .
    "Content-Transfer-Encoding: 8bitrnrn";
    $url=$current_site->domain . $current_site->path;
    $from=$_POST['from'];
    foreach ($users as $user) {
    if (!user_recieve_spam($user['mail'])) {
    $subject=$_POST['subject'];
    $message=$_POST['content'];
    $search[]='%%MYURL%%';
    $replace[]=$url;
    $search[]='%%NAME%%';
    $replace[]=$user['name'];
    $search[]='%%URL%%';
    $replace[]=$user['url'];
    $search[]='%%LOGIN%%';
    $replace[]=$user['login'];
    $search[]='%%MAIL%%';
    $replace[]=$user['mail'];
    $message=nl2br($message);
    $subject=str_replace($search,$replace,$subject);
    $message=str_replace($search,$replace,$message);
    if ($_POST['debug'])
    echo "<hr /><strong>TO:</strong>".$user['mail']."<BR /><strong>SUBJ:</strong>".$subject."<BR /><strong>BODY:</strong>".$message."<BR /><strong>HDRS:</strong>".$headers."<BR /><hr />";
    else
    mail ($user['mail'],$subject,$message,$headers);
    $sent++;
    unset($search,$replace);
    }
    }
    }
    ?>
    <div class='wrap'>
    <?php
    if ($sent) {
    $unspammed=$wpdb->get_var('SELECT count(id) FROM '.$wpmuBaseTablePrefix.'spam;');
    ?>
    <h2>Email successful</h2>
    <div class="updated fade" id="message">
    <table class='editform'>
    <tr><th scope='row' valign='top' width="150">Users emailed: </th><td><?=$sent?></td></tr>
    <tr><th scope='row' valign='top'>Users unemailed: </th><td><?=$unspammed?></td></tr>
    <tr><th scope='row' valign='top'>Users total: </th><td><?=$sent+$unspammed?></td></tr>
    <tr><th scope='row' valign='top'>Email subj: </th><td><?=$subject?></td></tr>
    <tr><th scope='row' valign='top'>Email body: </th><td><?=$message?></td></tr>
    </table>
    </div>
    <?php
    } elseif ($_POST) {
    ?>
    <h2>Email failed</h2>
    <div class="error fade" id="message">
    Sorry!
    </div>
    <?php
    }
    ?>
    <h2>Email form</h2>
    <form method="POST">
    <table class='editform'>
    <tr><th scope='row' valign='top' width="150">From: </th><td><input type='text' name='from' value="<?=$wpdb->get_var("SELECT user_email FROM ".$wpmuBaseTablePrefix."users WHERE ID=1;")?>"/></td></tr>
    <tr><th scope='row' valign='top'>Mail Subject: </th><td><input type='text' name='subject' /></td></tr>
    <tr><th scope='row' valign='top'>Mail Body: </th><td>
    <textarea name="content" id="content" title="true" rows="7" style="width:500px "></textarea>
    <script type="text/javascript">
    <!--
    edCanvas = document.getElementById('content');
    //-->
    </script>
    </td></tr>
    <tr><th>Test message</th><td><input type="checkbox" name="debug" checked /> </td></tr>
    <tr><th valign='top'><input type='submit' value="Email all users!" onClick="(confirm('Sure?')=='false') return false;" /></th></tr>
    </table>
    </form>
    </div>
    <?php
    }
    ?>

  2. suleiman
    Member
    Posted 17 years ago #

    what does this plugin do? Allow the admin to e-mail all blog users or allow users to e-mail their blog subscribers/other people?

  3. Farms2
    Member
    Posted 17 years ago #

    Allows admin to email all users... it's VERY useful!

  4. Farms2
    Member
    Posted 17 years ago #

    Had a thought... maybe it's down to the insert in post-new.php?

    Anyone with more knowledge than me know anything about this?

  5. suleiman
    Member
    Posted 17 years ago #

    did you ever fix this problem farms?

  6. Farms2
    Member
    Posted 17 years ago #

    Very odd - seems to be working just fine now... can't deal with apostrophes though so, um, avoid conjunctions :)

  7. Farms2
    Member
    Posted 17 years ago #

    Anyone else having problems - it'd be great if we could scale this up a bit.

  8. Ovidiu
    Member
    Posted 17 years ago #

    are you talking about the same plugin that was modified and made available here: http://wpmudevorg.wordpress.com/project/Mass-Mailer

    this one seems to work for me, but only tested with a few users so no guarantee

About this Topic