10, 'minhours' => '1', ); update_option( 'zcmail', $option ); } // todo don't autoload values, only needed in admin and on form page! } /** * Clean up when uninstalled, delete settings from db */ function zcmail_uninstall() { delete_option( 'zcmail' ); } /** * Reset the configuration. Used for default configuration as well. * Get sane, localized defaults and get current user's email address. * * @since 0.1.0 * @todo should return the values, not update the options... */ function zcmail_reset() { // wtf... plugin activation hook runs before init?! zcmail_load_translation_file(); global $user_email; $default = array( 'version' => '0.4.0', // 'create new field' label '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', 'must' => false, ), ), // fixed config shouldn't be localized, breaks on language switch // FIXME now we need to move from strings to consts 'config' => array( 'to' => $user_email, 'js' => 'Enabled', 'css' => 'Enabled', 'homelink' => 'In the footer', 'flood' => array( 'maxmails' => 10, 'minhours' => '1', ), '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', ), ), 'log' => array(), ); $default = zcmail_uasort($default); update_option( 'zcmail', $default ); } /** * Sort fields by position * * @param array $data multiple fields * @return array multiple sorted fields */ function zcmail_uasort($data) { uasort($data['fields'], 'zcmail_uasort_callback'); return($data); } /** * Callback for uasort, see http://php.net/manual/function.uasort.php * * @param array $a single field * @param array $b single field * * @return array sorted fields */ function zcmail_uasort_callback($a, $b) { return ($a['pos'] < $b['pos'] ) ? -1 : 1; } /** * Print the options page * * @todo make this more readable... * @todo check if we should encode html entities in field labels */ function zcmail_options_page() { // Check permissions if (current_user_can('manage_options')) { ?>
$field ) { $option['fields'][$key] = array_merge($field, $updated_fields[$key]); } // strip slashes from labels foreach ( $option['fields'] as $fieldname => $values ) { $option['fields'][$fieldname]['label'] = stripslashes($values['label']); } // sort the result $option = zcmail_uasort( $option ); update_option( 'zcmail', $option ); echo '
' . __( 'Fields saved', 'zero-conf-mail' ) . '
'; break; case 'config': $config = $_POST['config']; // TODO will this work for arrays? foreach( $config as $key => $value ) { $option['config'][$key] = $value; } // TODO checkboxes don't submit anything if unchecked, so we can't simply // merge... // And check that the whole form was submitted... this is ugly code... if ( !isset( $_POST['config']['css'] ) && isset( $_POST['config']['to'] ) ) { $option['config']['css'] = 'Disabled'; } // TODO wouldn't objects be handy? $option['config']['flood']['maxmails'] = intval( $option['config']['flood']['maxmails'] ); $option['config']['flood']['minhours'] = intval( $option['config']['flood']['minhours'] ); if( $option['config']['flood']['maxmails'] == 0 ) { $option['config']['flood']['maxmails'] = 1; } if( $option['config']['flood']['minhours'] == 0 ) { $option['config']['flood']['minhours'] = 1; } update_option( 'zcmail', $option ); echo '
' . __( 'Settings saved', 'zero-conf-mail' ) . '
'; break; case 'reset': zcmail_reset(); $option = get_option( 'zcmail' ); echo '
' . __( 'The default configuration was restored', 'zero-conf-mail' ) . '
'; break; case 'add': $new = $_POST['new']; $option['fields'][] = $new; $option = zcmail_uasort( $option ); update_option( 'zcmail', $option ); echo '
' . __( 'Field added', 'zero-conf-mail' ) . '
'; break; case 'delete': $position = intval( $_POST['position'] ); foreach ( $option['fields'] as $key => $fields ) { if ( intval( $fields['pos'] ) == $position ) { if ( !is_string( $key ) ) { // FIXME unset( $option['fields'][$key] ); echo '
' . sprintf( __( "Field with position %s deleted", 'zero-conf-mail' ), $position ) . '
'; } else { echo '
' . __( 'Can not delete this field', 'zero-conf-mail' ) . '
'; } } } update_option( 'zcmail', $option ); break; } } $option = get_option( 'zcmail' ); ?>


[zcmail] into the page content.' ,'zero-conf-mail' )?>

%s.", 'zero-conf-mail' ), $option['config']['to'] ) ?>


Careful! This will delete any customizations you have made and will also translate the form into your language if possible.', 'zero-conf-mail' ) ?>

$field ) { ?>