コード例 #1
0
function tdomf_notify_poster_rejected($post_id)
{
    global $wpdb;
    if (wp_is_post_revision($post_id)) {
        tdomf_log_message_extra("tdomf_notify_poster_rejected: post {$post_id} is a revision -- do nothing.");
        return $post_id;
    }
    $email = get_post_meta($post_id, TDOMF_KEY_NOTIFY_EMAIL, true);
    tdomf_log_message_extra("tdomf_notify_poster_rejected: {$email}");
    delete_post_meta($post_id, TDOMF_KEY_NOTIFY_EMAIL);
    if (get_post_meta($post_id, TDOMF_KEY_SPAM, true)) {
        tdomf_log_message_extra("tdomf_notify_poster_rejected: post {$post_id} is spam -- do nothing.");
        return $post_id;
    }
    if (tdomf_check_email_address($email)) {
        tdomf_log_message("Attempting to send notification email to {$email} for rejected post {$post_id}!");
        $postdata = get_postdata($post_id);
        $title = $postdata['Title'];
        $form_id = get_post_meta($post_id, TDOMF_KEY_FORM_ID, true);
        if ($form_id == false || !tdomf_form_exists($form_id)) {
            $form_id = tdomf_get_first_form_id();
        }
        $subject = tdomf_widget_notify_get_message($form_id, 'rejected_subject', true, $post_id);
        $notify_message = tdomf_widget_notify_get_message($form_id, 'rejected', true, $post_id);
        // Use custom from field
        //
        if (tdomf_get_option_form(TDOMF_OPTION_FROM_EMAIL, $form_id)) {
            // We can modify the "from" field by using the "header" option at the end!
            //
            $headers = "MIME-Version: 1.0\n" . "From: " . tdomf_get_option_form(TDOMF_OPTION_FROM_EMAIL, $form_id) . "\n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";
            return @wp_mail($email, $subject, $notify_message, $headers);
        } else {
            return @wp_mail($email, $subject, $notify_message);
        }
    }
    return $post_id;
}
コード例 #2
0
ファイル: tdomf-spam.php プロジェクト: TheReaCompany/pooplog
function tdomf_ham_post($post_id)
{
    if (!get_option(TDOMF_OPTION_SPAM)) {
        return;
    }
    $akismet_key = get_option(TDOMF_OPTION_SPAM_AKISMET_KEY);
    if (empty($akismet_key)) {
        tdomf_log_message("No Akismet key set, cannot submit ham for {$post_id}!", TDOMF_LOG_ERROR);
        return;
    }
    if (!get_post($post_id)) {
        tdomf_log_message("Post with ID {$post_id} does not exist!", TDOMF_LOG_ERROR);
        return;
    }
    if (!get_post_meta($post_id, TDOMF_KEY_FLAG, true)) {
        tdomf_log_message("{$post_id} is not managed by TDOMF - will not submit as ham!", TDOMF_LOG_BAD);
        return;
    }
    if (!get_post_meta($post_id, TDOMF_KEY_SPAM, true)) {
        tdomf_log_message("{$post_id} is not set as spam!", TDOMF_LOG_BAD);
        return;
    }
    $query_data = array();
    $query_data['user_ip'] = get_post_meta($post_id, TDOMF_KEY_IP, true);
    $query_data['user_agent'] = get_post_meta($post_id, TDOMF_KEY_USER_AGENT, true);
    $query_data['referrer'] = get_post_meta($post_id, TDOMF_KEY_REFERRER, true);
    $query_data['blog'] = get_option('home');
    $query_data['comment_type'] = 'new-submission';
    if (get_post_meta($post_id, TDOMF_KEY_USER_ID, true)) {
        $user = get_userdata(get_post_meta($post_id, TDOMF_KEY_USER_ID, true));
        $query_data['comment_author_email'] = $user->user_email;
        if (!empty($user->user_url)) {
            $query_data['comment_author_url'] = $user->user_url;
        }
        $query_data['comment_author'] = $user->display_name;
    } else {
        if (get_post_meta($post_id, TDOMF_KEY_NAME, true)) {
            $query_data['comment_author'] = get_post_meta($post_id, TDOMF_KEY_NAME, true);
        }
        if (get_post_meta($post_id, TDOMF_KEY_EMAIL, true)) {
            $query_data['comment_author_email'] = get_post_meta($post_id, TDOMF_KEY_EMAIL, true);
        }
        if (get_post_meta($post_id, TDOMF_KEY_WEB, true)) {
            $query_data['comment_author_url'] = get_post_meta($post_id, TDOMF_KEY_WEB, true);
        }
    }
    # test - should trigger spam response
    #$query_data['comment_author'] = 'viagra-test-123';
    $post_data = wp_get_single_post($post_id, ARRAY_A);
    $query_data['comment_content'] = $post_data['post_content'];
    /*if($live) {
         $ignore = array( 'HTTP_COOKIE' );
    	   foreach ( $_SERVER as $key => $value )
    	   if ( !in_array( $key, $ignore ) ) {
              $post_data["$key"] = $value;
         }
      }*/
    $query_string = '';
    foreach ($query_data as $key => $data) {
        $query_string .= $key . '=' . urlencode(stripslashes($data)) . '&';
    }
    tdomf_log_message_extra("{$akismet_key}.rest.akismet.com/1.1/comment-check<br/>{$query_string}");
    $response = tdomf_akismet_send($query_string, $akismet_key . ".rest.akismet.com", "/1.1/submit-ham", 80);
    // unflag spam
    //
    delete_post_meta($post_id, TDOMF_KEY_SPAM);
    $spam_count = get_option(TDOMF_STAT_SPAM);
    if ($spam_count == false) {
        add_option(TDOMF_STAT_SPAM, 0);
    } else {
        update_option(TDOMF_STAT_SPAM, $spam_count--);
    }
    $submitted_count = get_option(TDOMF_STAT_SUBMITTED);
    if ($submitted_count == false) {
        add_option(TDOMF_STAT_SUBMITTED, 1);
    } else {
        update_option(TDOMF_STAT_SUBMITTED, $submitted_count++);
    }
    tdomf_log_message("{$post_id} has been submitted as ham to Akismet<br/><pre>" . var_export($response, true) . "</pre>");
}
コード例 #3
0
function tdomf_recursive_mkdir($path, $mode = 0777)
{
    $path = trim($path);
    // TODO For versions > PHP 5.1.6, a trailing slash in mkdir causes problems!
    #clearstatcache();
    if (@is_dir($path)) {
        tdomf_log_message("{$path} exists");
        return true;
    }
    // A full windows path uses ":" compared to unix
    if (eregi(':', $path)) {
        $isWin = true;
    }
    $dirs = explode(DIRECTORY_SEPARATOR, $path);
    $count = count($dirs);
    $path = '';
    $prevpath = '';
    for ($i = 0; $i < $count; ++$i) {
        // store previous path
        $prevpath = $path;
        if ($i == 0 && $isWin) {
            // if windows, do not insert a SLASH for the first directory
            // "\c:\\" is an invalid path in Windows
            // -- thanks to "feelexit" on the TDOMF forums for fix
            $path .= $dirs[$i];
        } else {
            $path .= DIRECTORY_SEPARATOR . $dirs[$i];
        }
        // sometimes double slashes get added to path (differences between PHP4
        // and PHP5 and BSD systems etc.) and cause problems with open_basedir
        // matching and other things. Might as well fix it here.
        //
        $path = ereg_replace("//", "/", $path);
        if (!@is_dir($path) && $path != "/") {
            tdomf_log_message("Attempting to create directory {$path}");
            if (get_option(TDOMF_OPTION_EXTRA_LOG_MESSAGES)) {
                // Some debug code to check for safe_mode compatibility, only enabled
                // if option is enabled!
                // about to create directory (that's not root), check safe mode
                // for debugging only - no fix here!
                if ($i > 0 && ini_get('safe_mode')) {
                    // only check gid or uid if path not in include dir (if include dir
                    // is set of course)
                    $check_gid = true;
                    if (ini_get('safe_mode_include_dir') != NULL) {
                        $include_dirs = ini_get('safe_mode_include_dir');
                        if ($isWin) {
                            $include_dirs = explode(";", $include_dirs);
                        } else {
                            $include_dirs = explode(":", $include_dirs);
                        }
                        if (!empty($include_dirs)) {
                            foreach ($include_dirs as $inc_dir) {
                                // safe_mode_include_dir is actually just a prefix
                                if (substr($prevpath, 0, strlen($inc_dir)) == $inc_dir) {
                                    tdomf_log_message("{$prevpath} matches a path in safe_mode_include_dir: " + $inc_dir, TDOMF_LOG_GOOD);
                                    $check_gid = false;
                                }
                            }
                        }
                        if ($check_gid) {
                            tdomf_log_message("{$prevpath} does not match any path in safe_mode_include_dir: " + ini_get('safe_mode_include_dir'), TDOMF_LOG_BAD);
                        }
                    }
                    if ($check_gid) {
                        // gid or uid
                        if (ini_get('safe_mode_gid')) {
                            $myid = @getmygid();
                            $myid_posix = @posix_getgid();
                            $pathid = @filegroup($prevpath);
                            // log message
                            if ($pathid != $myid) {
                                tdomf_log_message("Safe Mode Enabled: May not be able to create path {$path} because {$prevpath} has gid {$pathid}. This script has gid {$myid}", TDOMF_LOG_BAD);
                            }
                            if ($pathid != $myid_posix) {
                                tdomf_log_message("Safe Mode Enabled: May not be able to create path {$path} because {$prevpath} has gid {$pathid}. This process has gid {$myid_posix}", TDOMF_LOG_BAD);
                            }
                        } else {
                            $myid = @getmyuid();
                            $myid_posix = @posix_getuid();
                            $pathid = @fileowner($prevpath);
                            // log message
                            if ($pathid != $myid) {
                                tdomf_log_message("Safe Mode Enabled: May not be able to create path {$path} because {$prevpath} has uid {$pathid}. This script has uid {$myid}", TDOMF_LOG_BAD);
                            }
                            if ($pathid != $myid_posix) {
                                tdomf_log_message("Safe Mode Enabled: May not be able to create path {$path} because {$prevpath} has uid {$pathid}. This process has uid {$myid_posix}", TDOMF_LOG_BAD);
                            }
                        }
                    }
                }
                // check open_basedir (seperate to safe_mode)
                if (ini_get('open_basedir') != NULL) {
                    $open_basedir_match = false;
                    $op_dirs = ini_get('open_basedir');
                    if ($isWin) {
                        $op_dirs = explode(";", $op_dirs);
                    } else {
                        $op_dirs = explode(":", $op_dirs);
                    }
                    if (!empty($op_dirs)) {
                        foreach ($op_dirs as $inc_dir) {
                            // open_basedir is actually just a prefix
                            if (substr($prevpath, 0, strlen($inc_dir)) == $inc_dir) {
                                tdomf_log_message("{$prevpath} matches a path in open_basedir: " + $inc_dir, TDOMF_LOG_GOOD);
                                $check_gid = false;
                            }
                        }
                    }
                    if ($check_gid) {
                        tdomf_log_message("{$prevpath} does not match any path in open_basedir: " + ini_get('open_basedir'), TDOMF_LOG_BAD);
                    }
                }
            }
        } else {
            tdomf_log_message_extra("Looking at {$path}");
            if (@is_link($path)) {
                tdomf_log_message_extra("{$path} is a symbolic link");
            }
        }
        // In safe_mode, is_dir may return false for a valid path. So, if in
        // safe_mode and is_dir returns false, try and create directory but
        // ignore and suppress errors
        //
        if (ini_get('safe_mode') || ini_get('open_basedir')) {
            if (!@is_dir($path)) {
                @mkdir(trim($path), $mode);
            }
        } else {
            // Not in safe mode, is_dir should work all the time. Therefore
            // break out if mkdir fails!
            if (!@is_dir($path) && !@mkdir(trim($path), $mode)) {
                tdomf_log_message("Error when attempting to create {$path}!", TDOMF_LOG_ERROR);
                return false;
            }
            // use real path (only if we are pretty certain it won't break)
            $path = @realpath($path);
        }
    }
    if (@is_dir($path)) {
        tdomf_log_message("The directory {$path} was successfully created!", TDOMF_LOG_GOOD);
    } else {
        tdomf_log_message("The directory {$path} was not created!", TDOMF_LOG_BAD);
    }
    return true;
}
コード例 #4
0
function tdomf_register_form_widget_admin_error($id, $name, $callback, $modes = array())
{
    global $tdomf_form_widgets_admin_errors, $tdomf_form_widgets;
    $id = sanitize_title($id);
    if (!isset($tdomf_form_widgets[$id])) {
        tdomf_log_message_extra("Admin Error: Widget {$id} has not be registered!...", TDOMF_LOG_ERROR);
        return;
    }
    if (isset($tdomf_form_widgets_admin_errors[$id])) {
        tdomf_log_message_extra("Admin Error widget {$id} already exists. Overwriting...");
    }
    $tdomf_form_widgets_admin_errors[$id]['name'] = $name;
    $tdomf_form_widgets_admin_errors[$id]['cb'] = $callback;
    $tdomf_form_widgets_admin_errors[$id]['params'] = array_slice(func_get_args(), 4);
    $tdomf_form_widgets_admin_errors[$id]['modes'] = $modes;
}
コード例 #5
0
                             break;
                         case 2:
                             $errors .= sprintf(__("Sorry but %s was too big. It was greater than %s. It exceeded the configured maximum.<br/>", "tdomf"), $upload_file_name, tdomf_filesize_format($options['size']));
                             break;
                         case 3:
                             $errors .= sprintf(__("Sorry but only part of %s was uploaded.<br/>", "tdomf"), $upload_file_name);
                             break;
                         case 4:
                             $errors .= __("Sorry file does not exist.<br/>", "tdomf");
                             break;
                         default:
                             $errors .= sprintf(__("Upload of %s failed for an unknown reason. (%s)<br/>", "tdomf"), $upload_file_name, $upload_error);
                             break;
                     }
                 } else {
                     tdomf_log_message_extra("No file here", TDOMF_LOG_ERROR);
                 }
             }
         }
         // Store in session!
         $mysessionfiles = array_merge($myfiles, $mysessionfiles);
         $form_data['uploadfiles_' . $form_id . '_' . $index] = $mysessionfiles;
         // Recount
         $sessioncount = 0;
         for ($i = 0; $i < $options['max']; $i++) {
             if (file_exists($mysessionfiles[$i]['path'])) {
                 $sessioncount++;
             }
         }
     }
 }
コード例 #6
0
ファイル: tdomf-db.php プロジェクト: TheReaCompany/pooplog
function tdomf_session_get($key = 0)
{
    global $wpdb;
    // grab session key
    //
    if ($key == 0 && !isset($_COOKIE['tdomf_' . COOKIEHASH])) {
        tdomf_log_message_extra("No cookie present");
        return false;
    } else {
        if ($key == 0) {
            $key = $_COOKIE['tdomf_' . COOKIEHASH];
        }
    }
    $table_name = $wpdb->prefix . TDOMF_DB_TABLE_SESSIONS;
    $query = "SELECT * \n            FROM {$table_name} \n            WHERE session_key = '" . $wpdb->escape($key) . "'";
    $retValue = $wpdb->get_row($query);
    if ($retValue == null) {
        tdomf_log_message_extra("Cookie found but no session data! Deleting cookie key.", TDOMF_LOG_ERROR);
        // delete cookie (it's invalid)
        @setcookie('tdomf_' . COOKIEHASH, "", time() - 60000);
        return false;
    }
    return maybe_unserialize($retValue->session_data);
}