コード例 #1
0
    function email_diagnostic_log()
    {
        $dlog = get_option('feedwordpress_diagnostics_log', array());
        if ($this->has_emailed_diagnostics($dlog)) {
            if ($this->ready_to_email_diagnostics($dlog)) {
                // No news is good news; only send if
                // there are some messages to send.
                $body = NULL;
                if (!isset($dlog['mesg'])) {
                    $dlog['mesg'] = array();
                }
                foreach ($dlog['mesg'] as $sect => $mesgs) {
                    if (count($mesgs) > 0) {
                        if (is_null($body)) {
                            $body = '';
                        }
                        $paradigm = reset($mesgs);
                        $body .= "<h2>" . ucfirst($sect) . " issues</h2>\n" . "<table>\n" . "<thead><tr>\n";
                        foreach ($paradigm as $col => $value) {
                            $body .= '<th scope="col">' . $col . "</th>\n";
                        }
                        $body .= "</tr></thead>\n" . "<tbody>\n";
                        foreach ($mesgs as $line) {
                            $body .= "<tr>\n";
                            foreach ($line as $col => $cell) {
                                if (is_numeric($cell)) {
                                    $cell = date('j-M-y, h:i a', $cell);
                                }
                                $class = strtolower(preg_replace('/\\s+/', '-', $col));
                                $body .= "<td class=\"{$class}\">{$cell}</td>";
                            }
                            $body .= "</tr>\n";
                        }
                        $body .= "</tbody>\n</table>\n\n";
                    }
                }
                $body = apply_filters('feedwordpress_diagnostic_email_body', $body, $dlog);
                if (!is_null($body)) {
                    $home = feedwordpress_display_url(get_bloginfo('url'));
                    $subj = apply_filters('feedwordpress_diagnostic_email_subject', $home . " syndication issues", $dlog);
                    $agent = 'FeedWordPress ' . FEEDWORDPRESS_VERSION;
                    $body = <<<EOMAIL
<html>
<head>
<title>{$subj}</title>
<style type="text/css">
\tbody { background-color: white; color: black; }
\ttable { width: 100%; border: 1px solid black; }
\ttable thead tr th { background-color: #ff7700; color: white; border-bottom: 1px solid black; }
\ttable thead tr { border-bottom: 1px solid black; }
\ttable tr { vertical-align: top; }
\ttable .since { width: 20%; }
\ttable .time { width: 20%; }
\ttable .most-recently { width: 20%; }
\ttable .message { width: auto; }
</style>
</head>
<body>
<h1>Syndication Issues encountered by {$agent} on {$home}</h1>
{$body}
</body>
</html>

EOMAIL;
                    $ded = get_option('feedwordpress_diagnostics_email_destination', 'admins');
                    // e-mail address
                    if (preg_match('/^mailto:(.*)$/', $ded, $ref)) {
                        $recipients = array($ref[1]);
                        // userid
                    } elseif (preg_match('/^user:(.*)$/', $ded, $ref)) {
                        $userdata = get_userdata((int) $ref[1]);
                        $recipients = array($userdata->user_email);
                        // admins
                    } else {
                        $recipients = FeedWordPressDiagnostic::admin_emails();
                    }
                    foreach ($recipients as $email) {
                        add_filter('wp_mail_content_type', array('FeedWordPress', 'allow_html_mail'));
                        wp_mail($email, $subj, $body);
                        remove_filter('wp_mail_content_type', array('FeedWordPress', 'allow_html_mail'));
                    }
                }
                // Clear the logs
                $dlog['mesg']['persistent'] = array();
                $dlog['mesg']['occurrent'] = array();
                // Set schedule for next update
                $dlog['schedule']['last'] = time();
            }
        } else {
            $dlog['schedule'] = array('freq' => 24 * 60 * 60, 'last' => time());
        }
        update_option('feedwordpress_diagnostics_log', $dlog);
    }
コード例 #2
0
	function email_diagnostic_log ($params = array()) {
		$params = wp_parse_args($params, array(
		"force" => false,
		));

		$dlog = get_option('feedwordpress_diagnostics_log', array());
		
		if ($this->has_emailed_diagnostics($dlog)) :
			if ($this->ready_to_email_diagnostics($dlog)) :
				// No news is good news; only send if
				// there are some messages to send.
				$body = NULL;
				if (!isset($dlog['mesg'])) : $dlog['mesg'] = array(); endif;
				
				foreach ($dlog['mesg'] as $sect => $mesgs) :
					if (count($mesgs) > 0) :
						if (is_null($body)) : $body = ''; endif;
						
						$paradigm = reset($mesgs);
						$body .= "<h2>".ucfirst($sect)." issues</h2>\n"
							."<table>\n"
							."<thead><tr>\n";
						foreach ($paradigm as $col => $value) :
							$body .= '<th scope="col">'.$col."</th>\n";
						endforeach;
						$body .= "</tr></thead>\n"
							."<tbody>\n";
						
						foreach ($mesgs as $line) :
							$body .= "<tr>\n";
							foreach ($line as $col => $cell) :
								if (is_numeric($cell)) :
									$cell = date('j-M-y, h:i a', $cell);
								endif;
								$class = strtolower(preg_replace('/\s+/', '-', $col));
								$body .= "<td class=\"$class\">${cell}</td>";
							endforeach;
							$body .= "</tr>\n";
						endforeach;
						
						$body .= "</tbody>\n</table>\n\n";
					endif;
				endforeach;
				
				$body = apply_filters('feedwordpress_diagnostic_email_body', $body, $dlog);
				if (!is_null($body)) :
					$home = feedwordpress_display_url(get_bloginfo('url'));
					$subj = apply_filters('feedwordpress_diagnostic_email_subject', $home . " syndication issues", $dlog);
					$agent = 'FeedWordPress '.FEEDWORDPRESS_VERSION;
					$body = <<<EOMAIL
<html>
<head>
<title>$subj</title>
<style type="text/css">
	body { background-color: white; color: black; }
	table { width: 100%; border: 1px solid black; }
	table thead tr th { background-color: #ff7700; color: white; border-bottom: 1px solid black; }
	table thead tr { border-bottom: 1px solid black; }
	table tr { vertical-align: top; }
	table .since { width: 20%; }
	table .time { width: 20%; }
	table .most-recently { width: 20%; }
	table .message { width: auto; }
</style>
</head>
<body>
<h1>Syndication Issues encountered by $agent on $home</h1>
$body
</body>
</html>

EOMAIL;

					$ded = get_option('feedwordpress_diagnostics_email_destination', 'admins');

					// e-mail address
					if (preg_match('/^mailto:(.*)$/', $ded, $ref)) :
						$recipients = array($ref[1]);
						
					// userid
					elseif (preg_match('/^user:(.*)$/', $ded, $ref)) :
						$userdata = get_userdata((int) $ref[1]);
						$recipients = array($userdata->user_email);
					
					// admins
					else :
						$recipients = FeedWordPressDiagnostic::admin_emails();
					endif;

					$mesgId = 'feedwordpress+'.time().'@'.$home;
					$parentId = get_option('feedwordpress_diagnostics_email_root_message_id', NULL);

					$head = array("Message-ID: <$mesgId>");
					if (!is_null($parentId)) :
						// We've already sent off a diagnostic message in the past. Let's do some
						// magic to help with threading, in the hopes that all diagnostic messages
						// get threaded together.
						$head[] = "References: <$parentId>";
						$head[] = "In-Reply-To: <$parentId>";
						$subj = "Re: ".$subj;
					else :
						// This is the first of its kind. Let's mark it as such.
						update_option('feedwordpress_diagnostics_email_root_message_id', $mesgId);
					endif;
					$head = apply_filters('feedwordpress_diagnostic_email_headers', $head);

					foreach ($recipients as $email) :						
						add_filter('wp_mail_content_type', array('FeedWordPress', 'allow_html_mail'));
						wp_mail($email, $subj, $body, $head);
						remove_filter('wp_mail_content_type', array('FeedWordPress', 'allow_html_mail'));
					endforeach;
				endif;
				
				// Clear the logs
				$dlog['mesg']['persistent'] = array();
				$dlog['mesg']['occurrent'] = array();
				
				// Set schedule for next update
				$dlog['schedule']['last'] = time();
			endif;
		else :
			$dlog['schedule'] = array(
				'freq' => 24 /*hr*/ * 60 /*min*/ * 60 /*s*/,
				'last' => time(),
			);
		endif;
		
		update_option('feedwordpress_diagnostics_log', $dlog);
	} /* FeedWordPress::email_diagnostic_log () */