Example #1
0
function pkwk_mail_notify($subject, $message, $footer = array())
{
    global $smtp_server, $smtp_auth, $notify_to, $notify_from, $notify_header;
    static $_to, $_headers, $_after_pop;
    // Init and lock
    if (!isset($_to)) {
        if (!PKWK_OPTIMISE) {
            // Validation check
            $func = 'pkwk_mail_notify(): ';
            $mail_regex = '/[^@]+@[^@]{1,}\\.[^@]{2,}/';
            if (!preg_match($mail_regex, $notify_to)) {
                die($func . 'Invalid $notify_to');
            }
            if (!preg_match($mail_regex, $notify_from)) {
                die($func . 'Invalid $notify_from');
            }
            if ($notify_header != '') {
                $header_regex = "/\\A(?:\r\n|\r|\n)|\r\n\r\n/";
                if (preg_match($header_regex, $notify_header)) {
                    die($func . 'Invalid $notify_header');
                }
                if (preg_match('/^From:/im', $notify_header)) {
                    die($func . 'Redundant \'From:\' in $notify_header');
                }
            }
        }
        $_to = $notify_to;
        $_headers = 'X-Mailer: PukiWiki/' . S_VERSION . ' PHP/' . phpversion() . "\r\n" . 'From: ' . $notify_from;
        // Additional header(s) by admin
        if ($notify_header != '') {
            $_headers .= "\r\n" . $notify_header;
        }
        $_after_pop = $smtp_auth;
    }
    if ($subject == '' || $message == '' && empty($footer)) {
        return false;
    }
    // Subject:
    if (isset($footer['PAGE'])) {
        $subject = str_replace('$page', $footer['PAGE'], $subject);
    }
    // Footer
    if (isset($footer['REMOTE_ADDR'])) {
        $footer['REMOTE_ADDR'] =& $_SERVER['REMOTE_ADDR'];
    }
    if (isset($footer['USER_AGENT'])) {
        $footer['USER_AGENT'] = '(' . UA_PROFILE . ') ' . UA_NAME . '/' . UA_VERS;
    }
    if (!empty($footer)) {
        $_footer = '';
        if ($message != '') {
            $_footer = "\n" . str_repeat('-', 30) . "\n";
        }
        foreach ($footer as $key => $value) {
            $_footer .= $key . ': ' . $value . "\n";
        }
        $message .= $_footer;
    }
    // Wait POP/APOP auth completion
    if ($_after_pop) {
        $result = pop_before_smtp();
        if ($result !== true) {
            die($result);
        }
    }
    ini_set('SMTP', $smtp_server);
    mb_language(LANG);
    if ($_headers == '') {
        return mb_send_mail($_to, $subject, $message);
    } else {
        return mb_send_mail($_to, $subject, $message, $_headers);
    }
}
Example #2
0
function file_write($dir,$page,$str,$notimestamp=FALSE)
{
	global $post,$update_exec;
	global $_msg_invalidiwn;
	global $notify,$notify_diff_only,$notify_to,$notify_from,$notify_subject,$notify_header;
	global $smtp_server,$smtp_auth;
	
	if (!is_pagename($page))
	{
		die_message(
			str_replace('$1',htmlspecialchars($page),
				str_replace('$2','WikiName',$_msg_invalidiwn)
			)
		);
	}
	$page = strip_bracket($page);
	$timestamp = FALSE;
	$file = $dir.encode($page).'.txt';
	
	if ($dir == DATA_DIR and $str == '' and file_exists($file))
	{
		unlink($file);
	}
	if ($str != '')
	{
		$str = preg_replace("/\r/",'',$str);
		$str = rtrim($str)."\n";
		
		if ($notimestamp and file_exists($file))
		{
			$timestamp = filemtime($file) - LOCALZONE;
		}
		
		$fp = fopen($file,'w')
			or die_message('cannot write page file or diff file or other'.htmlspecialchars($page).'<br />maybe permission is not writable or filename is too long');
		flock($fp,LOCK_EX);
		fputs($fp,$str);
		flock($fp,LOCK_UN);
		fclose($fp);
		if ($timestamp)
		{
			touch($file,$timestamp + LOCALZONE);
		}
	}
	
	// is_pageのキャッシュをクリアする。
	is_page($page,TRUE);
	
	if (!$timestamp and $dir == DATA_DIR)
	{
		put_lastmodified();
	}
	
	if ($update_exec and $dir == DATA_DIR)
	{
		system($update_exec.' > /dev/null &');
	}
	
	if ($notify and $dir == DIFF_DIR)
	{
		if ($notify_diff_only)
		{
			// 差分だけを送信する
			$str = preg_replace('/^[^-+].*\n/m','',$str);
		}
		if ($smtp_auth)
		{
			pop_before_smtp();
		}
 		$subject = str_replace('$page',$page,$notify_subject);
		ini_set('SMTP',$smtp_server);
 		mb_language(LANG);
 		mb_send_mail($notify_to,$subject,$str,$notify_header);
	}
}