Tag: hack

Down and Dirty PHP mailer with backup CSV

<?php
if($_POST){
	//set up variables
	$to = '';
	$from = '';
	$cc = '';
	$bcc = '';
	$subject = '';
	$backup_filename = '';
	//loop through fields
	foreach($_POST AS $k => $v){
		$message .= '<li>'.$k.': '.$v."</li>\n";
		$csv_header .= $k.',';
		$csv_record .= $v.',';
	}
	//clean up for csv
	$csv_header .= "\n";
	$csv_record .= "\n";
	//htmlize message
	$message = '<html>
	<head>
	  <title>'.$subject.'</title>
	</head>
	<body>
	  <ul>'.$message.'</ul>
	</body>
	</html>';
	// To send HTML mail, the Content-type header must be set
	$headers  = 'MIME-Version: 1.0' . "\r\n";
	$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
	// Additional headers
	//$headers .= 'To:' . $to . "\r\n";
	$headers .= 'From:' . $from . "\r\n";
	$headers .= 'Cc:'. $cc . "\r\n";
	$headers .= 'Bcc:'. $bcc . "\r\n";
	// Mail it
	mail($to, $subject, $message, $headers);
	//store backup data
	if (!file_exists($backup_filename)) {
		$csv_record = $csv_header.$csv_record;
	}
	if (!$handle = fopen($backup_filename, 'a')) {
		exit;
	}
	if (fwrite($handle, $csv_record) === FALSE) {
		exit;
	}
	fclose($handle);
	//done.
}

Changing post restrictions in the DB.

$s2data = get_option('ws_plugin__s2member_options');
if($s2data['level1_posts']==''){
	$recipes = get_posts(array('numberposts' => -1,'post_type' => 'msd_recipe'));
	foreach($recipes AS $r){
		$protected[] = $r->ID;
	}
	$s2data['level1_posts'] = implode(',', $protected);
	update_option('ws_plugin__s2member_options', $s2data);
	print 'recipes protected';
}