'0.1.0',
// currently used for new fields
'blueprints' => array(
'new' => array(
'label' => __('Your new field', 'zero-conf-mail'),
'type' => 'text',
'must' => false,
'pos' => 0,
),
),
'fields' => array(
'name' => array(
'pos' => 10,
'label' => __('Your name', 'zero-conf-mail'),
'type' => 'text',
'must' => true,
),
'from' => array(
'pos' => 20,
'label' => __('Your email', 'zero-conf-mail'),
'type' => 'email',
'must' => true,
),
'subject' => array(
'pos' => 30,
'label' => __('Subject', 'zero-conf-mail'),
'type' => 'text',
'must' => false,
),
'body' => array(
'pos' => 40,
'label' => __('Your message', 'zero-conf-mail'),
'type' => 'textarea',
'must' => true,
),
'submit' => array(
'pos' => 50,
'label' => __('Send message', 'zero-conf-mail'),
'type' => 'submit',
),
),
// FIXME config shouldn't be localized, breaks on language switch
'config' => array(
'to' => $user_email,
'js' => 'Enabled',
'homelink' => 'In the footer',
'messages' => array(
'failure' => __('Please fill out all fields!', 'zero-conf-mail'),
'success' => __('Your message has been sent. Thank you!', 'zero-conf-mail'),
),
'input_types' => array(
'text',
'textarea',
'email',
'submit',
),
'advanced' => 'Disabled',
'homelink_choices' => array(
'Below the form',
'In the footer',
'Nowhere',
),
'enable_choices' => array(
'Enabled',
'Disabled',
),
),
);
$default = zcmail_uasort($default);
update_option('zcmail', $default );
}
/*
* The shortcode. Parse POST data and/or show the form.
* TODO make readable
*/
function zcmail_shortcode() {
?>
$values) {
// TODO I guess this should be safe, as a[] = 0 => a[0] = 0
// Only add custom fields
if (is_integer($field)) {
$message .= "\n";
$message .= $option['fields'][$field]['label'] . ": $values";
}
}
zcmail_sendmail($option['config']['to'], $from, $subject, $message );
echo '
';
_e('Your message has been sent. Thank you!', 'zero-conf-mail');
echo '
';
}
else {
echo '
';
_e('Please fill out all fields!', 'zero-conf-mail');
echo '
';
zcmail_printform();
}
}
else {
zcmail_printform();
} ?>
$value) {
if ($value['type'] == 'text' || $value['type'] == 'textarea') {
// catch all mandatory fields that haven't been modified
if ( $value['must'] == __('Enabled', 'zero-conf-mail') && $input[$def] == $value['label'] ) {
//echo "error: " . $input[$def] . " unchanged";
return false;
}
// catch all mandatory fields that are empty
elseif ( $value['must'] == __('Enabled', 'zero-conf-mail') && $input[$def] == '' ) {
//echo "error: " . $value['label'] . $input[$def] . " empty";
return false;
}
}
if ($value['type'] == 'email') {
// catch all mandatory invalid mail addresses
if ( $value['must'] == 'Enabled' && $value['type'] == 'email' && !is_email($input[$def]) ) {
//echo "error: " . $input[$def] . " no mail";
return false;
}
}
}
return true;
}
/*
* Sort field definitions by id
* Parameters: (array) field definitions
* Return: (array) sorted field definitions
*/
function zcmail_uasort($data) {
uasort($data['fields'], 'zcmail_uasort_callback');
return($data);
}
/*
* Callback for uasort, see http://php.net/manual/function.uasort.php
* Parameters: (array) single field definition, (array) single field definition
* Return: (int)
*/
function zcmail_uasort_callback($a, $b) {
return ($a['pos'] < $b['pos'] ) ? -1 : 1;
}
/*
* Send a mail
* Parameters: (str) to, (str) from, (str) subject, (str) body
*/
function zcmail_sendmail($to, $from, $subject, $body) {
// Add message footer
$body .= "\n\n---\n" . __('Sent with Zero Conf Mail: ', 'zero-conf-mail');
$body .= __('http://www.nkuttler.de/wordpress/zero-conf-mail/', 'zero-conf-mail');
$body .= "\n\n" . __('Blog: ', 'zero-conf-mail');
$body .= get_bloginfo('home');
$body .= "\n" . __('IP : ', 'zero-conf-mail');
$body .= $_SERVER['REMOTE_ADDR'];
mail(
$to,
'[' . get_bloginfo('name') . '] ' . $subject,
$body,
"From: $from"
);
}
/*
* Perform (basic) sanitization of user input.
* Parameters: (str) string
* Return: (str)
*/
function zcmail_sanitize($string) {
$string = htmlspecialchars($string, ENT_QUOTES);;
return $string;
}
/*****************************************************************************
*
* Here are mostly view helper functions
* TODO better logic / view separation
*
*****************************************************************************/
/*
* Print the options page
* TODO make this more readable...
*/
function zcmail_options_page() {
// Check permissions
if (current_user_can('manage_options')) { ?>
'; var_dump( get_option('zcmail') ); echo '';
$data = $_POST;
// TODO update codex nonce docs.....
unset($_POST['_wp_http_referer']);
unset($_POST['_wpnonce']);
switch ($_POST['pass']) {
case 'admin_fields':
$option = get_option('zcmail');
$updated_fields = $_POST;
unset($updated_fields['pass']);
// TODO Why have config + fileds been mixed?
$option['config']['js'] = $updated_fields['config_js'];
unset($updated_fields['config_js']);
// TODO Check if we should encode all html entities...
// stripslashes from all fields
foreach ($updated_fields as &$field) {
foreach($field as &$value) {
$value = stripslashes($value);
}
unset($value);
}
unset($field);
// merge new into old values
foreach ($option['fields'] as $key => $field) {
$option['fields'][$key] = array_merge($field, $updated_fields[$key]);
}
// sort the result
$option = zcmail_uasort($option);
update_option('zcmail', $option);
break;
case 'config':
$config = $_POST['config'];
$option = get_option('zcmail');
// TODO this probably won't work for arrays...
foreach($config as $key => $value) {
$option['config'][$key] = $value;
}
update_option('zcmail', $option);
break;
case 'reset':
zcmail_reset();
break;
case 'add':
$option = get_option('zcmail');
$new = $_POST['new'];
$option['fields'][] = $new;
$option = zcmail_uasort($option);
update_option('zcmail', $option);
_e('I added a field', 'zero-conf-mail');
break;
}
?>
[zcmail] into the page content." ,'zero-conf-mail' )?>
Careful! This will delete any customization you have made!') ?>
$field ) {
?>
|
|
|
|
|
|
if ($advanced == 'Enabled') { ?>
|
|
|
class="zcmail_text" />
Zero Conf Mail
}