function row2text($row) { $text = ''; $flag = 0; $i = 0; foreach ($row as $var => $val) { if ($flag == 1) { $text .= ", "; } elseif ($flag == 2) { $text .= ",\n"; } $flag = 1; //Variable if (is_numeric($var)) { if ($var[0] == '0') { $text .= "'{$var}'=>"; } else { if ($var !== $i) { $text .= "{$var}=>"; } $i = $var; } } else { $text .= "'{$var}'=>"; } $i++; //letter if (is_array($val)) { $text .= "array(" . row2text($val) . ")"; $flag = 2; } else { $text .= "\"{$val}\""; } } return $text; }
function openinviter_conf() { if ($_SERVER['REQUEST_METHOD'] == 'POST') { $options = array(); $ers = array(); if (empty($_POST['message_body_box'])) { $ers['message'] = __("Message missing"); } elseif (strlen($_POST['message_body_box']) < 15) { $ers['message'] = __("Message body too short. Minimum length: 15 chars"); } else { $options['message_body'] = $_POST['message_body_box']; } if (empty($_POST['message_subject_box'])) { $ers['message_subject'] = __("Message subject missing"); } elseif (strlen($_POST['message_subject_box']) < 5) { $ers['message_subject'] = __("Message subject too short. Minimum length: 5 chars"); } else { $options['message_subject'] = $_POST['message_subject_box']; } if (empty($_POST['username_box'])) { $ers['username'] = __("OpenInviter.com Username missing"); } else { $options['username'] = $_POST['username_box']; } if (empty($_POST['private_key_box'])) { $ers['private_key'] = __("OpenInviter.com Private Key missing"); } elseif (!is_md5($_POST['private_key_box'])) { $ers['private_key'] = __("Invalid OpenInviter.com Private Key"); } else { $options['private_key'] = $_POST['private_key_box']; } if (empty($_POST['transport_box'])) { $ers['transport'] = __("Transport missing"); } else { $options['transport'] = $_POST['transport_box']; } if (empty($_POST['cookie_path_box'])) { $ers['cookie'] = __("Cookie path missing"); } else { $options['cookie_path'] = $_POST['cookie_path_box']; } if (empty($_POST['local_debug_box'])) { $ers['local_debug'] = __("Local debugger setting missing"); } else { $options['local_debug'] = $_POST['local_debug_box'] == 'off' ? false : $_POST['local_debug_box']; } if (empty($_POST['remote_debug_box'])) { $ers['remote_debug'] = __("Remote debugger setting missing"); } else { $options['remote_debug'] = $_POST['remote_debug_box'] == 'on' ? true : false; } if (!isset($_POST['filter_emails_box'])) { $options['filter_emails'] = false; } else { $options['filter_emails'] = true; } if (count($ers) == 0) { if (!get_option('openinviter_settings')) { add_option('openinviter_settings', $options); } else { update_option('openinviter_settings', $options); } $path = WP_PLUGIN_DIR . "/openinviter-for-wordpress/oi_includes/config.php"; $file_contents = "<?php\n"; $file_contents .= "\$openinviter_settings=array(\n" . row2text($options) . "\n);\n"; $file_contents .= "?>"; file_put_contents($path, $file_contents); echo "<div id='message' class='updated fade'><p><strong>" . __('Options saved.') . "</strong></p></div>"; } else { echo "<div id='message' class='error'><p><strong>" . __('Errors encountered:') . "</strong>"; foreach ($ers as $er) { echo "<br> {$er}"; } echo "</p></div>"; } } else { $options = get_option('openinviter_settings'); global $openinviter_options; foreach ($openinviter_options['settings'] as $key => $val) { if (!isset($options[$key])) { $options[$key] = $val['default']; } } } $transports = array('curl' => __('cURL'), 'wget' => __('WGET')); $local_debugs = array('off' => __('None'), 'on_error' => __('Errors only'), 'always' => __('Always')); $remote_debugs = array('off' => __('Off'), 'on' => __('On')); $contents = "<div class='wrap'><h2>" . __('OpenInviter Configuration') . "</h2>\n\t\t\t<div class='narrow'><form action='' method='POST' style='margin: auto; width: 600px;'><p>\n\t\t\t" . sprintf(__('<strong>Tip</strong>: You can get your API details (username and private key) from <a href="%1$s">OpenInviter.com</a>. If you don\'t have an OpenInviter.com account you can sign up at <a href="%2$s">OpenInviter.com</a>.'), 'http://openinviter.com/get_key.php', 'http://openinviter.com/register.php') . "</p>\n\t\t\t\t<table>\n\t\t\t\t<tr><td valign='top'><strong><label for='message_body_box'>" . __("Invite message body") . "</label></strong></td><td><textarea rows='5' cols='47' id='message_body_box' name='message_body_box'>{$options['message_body']}</textarea></td></tr>\n\t\t\t\t<tr><td valign='top'><strong><label for='message_subject_box'>" . __("Invite message subject") . "</label></strong></td><td><input type='text' id='message_subject_box' name='message_subject_box' value='{$options['message_subject']}' style='font-family: 'Courier New', Courier, mono; font-size: 1.5em;' size='50' /></td></tr>\n\t\t\t\t<tr><td colspan='2' align='right'>The <strong>%s</strong> in the message subject will be replaced with the sender</td></tr>\n\t\t\t\t<tr><td colspan='2'> </td></tr>\n\t\t\t\t<tr><td><strong><label for='username_box'>" . __('OpenInviter.com Username') . "</label></strong></td><td><input id='username_box' name='username_box' type='text' value='{$options['username']}' style='font-family: 'Courier New', Courier, mono; font-size: 1.5em;' size='50' /></td></tr>\n\t\t\t\t<tr><td><strong><label for='private_key_box'>" . __('OpenInviter.com Private Key') . "</label></strong></td><td><input id='private_key_box' name='private_key_box' type='text' value='{$options['private_key']}' style='font-family: 'Courier New', Courier, mono; font-size: 1.5em;' size='50' /></td></tr>\n\t\t\t\t<tr><td><strong><label for='transport_box'>" . __("Transport") . "</label></strong></td><td><select id='transport_box' name='transport_box'><option value=''></option>"; foreach ($transports as $value => $name) { $contents .= "<option value='{$value}'" . ($options['transport'] == $value ? ' selected' : '') . ">{$name}</option>"; } $contents .= "</select></td></tr>\n\t\t\t\t<tr><td><strong><label for='cookie_path_box'>" . __("Cookie path") . "</label></strong></td><td><input type='text' id='cookie_path_box' name='cookie_path_box' value='{$options['cookie_path']}' style='font-family: 'Courier New', Courier, mono; font-size: 1.5em;' size='50' /></td></tr>\n\t\t\t\t<tr><td><strong><label for='local_debug_box'>" . __('Local debugger') . "</label></strong></td><td><select id='local_debug_box' name='local_debug_box'><option value=''></option>"; if ($options['local_debug'] === false) { $options['local_debug'] = 'off'; } if ($options['remote_debug'] === false) { $options['remote_debug'] = 'off'; } else { $options['remote_debug'] = 'on'; } foreach ($local_debugs as $value => $name) { $contents .= "<option value='{$value}'" . ($options['local_debug'] == $value ? ' selected' : '') . ">{$name}</option>"; } $contents .= "</select></td></tr>\n\t\t\t\t<tr><td><strong><label for='remote_debug_box'>" . __('Remote debugger') . "</label></strong></td><td><select id='remote_debug_box' name='remote_debug_box'><option value=''></option>"; foreach ($remote_debugs as $value => $name) { $contents .= "<option value='{$value}'" . ($options['remote_debug'] == $value ? ' selected' : '') . ">{$name}</option>"; } $contents .= "</select></td></tr>\n\t\t\t\t<tr><td><strong><label for='filter_emails_box'>" . __('Filter emails') . "</label></strong></td><td><input id='filter_emails_box' name='filter_emails_box' type='checkbox' value='Y'" . ($options['filter_emails'] ? ' checked' : '') . "></td></tr>\n\t\t\t\t<tr><td colspan='2' align='center'><p class='submit'><input type='submit' id='submit' name='save' value='" . __("Save options") . "' /></p></td></tr>\n\t\t\t\t</table>\n\t\t\t</form>\n\t\t\t</div>\n\t\t</div>"; echo $contents; }