/** * Constructor. * * @param array $args { * An array of arguments. * * @type string $host The server name. (eg. imap.gmail.com) * @type int $port The port number used by the server name. * @type string $username The username used to login to the server. * @type string $password The password used to login to the server. * @type bool $validatecert Whether to validate certificates from TLS/ * SSL server. Defaults to true. * @type string $mailbox The mailbox to open. Defaults to 'INBOX'. * @type int $retries How many times to try reconnection on failure. * Defaults to 1. * @type bool $reconnect Are we attempting a reconnection? Defaults to false. * } * @param resource $connection The IMAP resource if attempting a reconnection. * @return resource|bool The IMAP resource on success. Boolean false on failure. */ public function __construct($args = array(), $connection = false) { $this->args = wp_parse_args($args, array('host' => bp_rbe_get_setting('servername'), 'port' => bp_rbe_get_setting('port'), 'username' => bp_rbe_get_setting('username'), 'password' => bp_rbe_get_setting('password') ? bp_rbe_decode(array('string' => bp_rbe_get_setting('password'), 'key' => wp_salt())) : false, 'validatecert' => true, 'mailbox' => 'INBOX', 'retries' => 1, 'reconnect' => false)); $this->connection = $connection; }
/** * Renders the output of a form field in the admin area. * * I like this better than {@link add_settings_field()} so sue me! * Uses {@link BP_Reply_By_Email_Admin::field()} and {@link BP_Reply_By_Email_Admin::get_option()}. * * @param array $args Arguments for the field */ protected function render_field($args = '') { $defaults = array('type' => 'text', 'labelname' => '', 'labelfor' => true, 'name' => '', 'desc' => '', 'size' => 'regular', 'value' => '', 'options' => array(), 'default' => ''); $r = wp_parse_args($args, $defaults); echo '<tr class="' . $this->field($r['name'], true, false) . '">'; if ($r['labelfor']) { echo '<th scope="row"><label for="' . $this->field($r['name'], true, false) . '">' . $r['labelname'] . '</label></th>'; } else { echo '<th scope="row">' . $r['labelname'] . '</th>'; } echo '<td>'; switch ($r['type']) { case 'checkbox': ?> <fieldset> <legend class="screen-reader-text"><span><?php echo $r['labelname']; ?> </span></legend> <label for="<?php $this->field($r['name'], true); ?> "> <input type="checkbox" name="<?php $this->field($r['name']); ?> " id="<?php $this->field($r['name'], true); ?> " value="1" <?php if (!empty($this->settings[$r['name']])) { checked($this->settings[$r['name']], 1); } ?> /> <?php echo $r['desc']; ?> </label> <br /> </fieldset> <?php break; case 'select': $selected = array_key_exists($this->settings[$r['name']], $r['options']) ? $this->settings[$r['name']] : $r['default']; ?> <select id="<?php $this->field($r['name'], true); ?> " name="<?php $this->field($r['name']); ?> "> <?php foreach ($r['options'] as $key => $option) { echo '<option value="' . esc_attr($key) . '"'; if ($selected == $key) { echo ' selected="selected"'; } echo '>' . esc_html($option) . '</option>'; } ?> </select> <?php if ($r['desc']) { echo '<p class="description">' . $r['desc'] . '</p>'; } break; case 'text': case 'password': $value = $this->get_option($r['name'], false); if ($r['type'] == 'password') { $value = bp_rbe_decode(array('string' => $value, 'key' => wp_salt())); } ?> <input class="<?php echo $r['size']; ?> -text" value="<?php echo $value; ?> " name="<?php $this->field($r['name']); ?> " id="<?php $this->field($r['name'], true); ?> " type="<?php echo $r['type']; ?> " /> <?php if ($r['desc']) { echo '<p class="description">' . $r['desc'] . '</p>'; } break; } echo '</td>'; echo '</tr>'; }
/** * Decodes the encoded querystring from {@link BP_Reply_By_Email_Parser::get_querystring()}. * Then, extracts the params into an array. * * @uses bp_rbe_decode() To decode the encoded querystring * @uses wp_parse_str() WP's version of parse_str() to parse the querystring * @return mixed Either an array of params on success or false on failure */ protected static function get_parameters() { // new items will always have "-new" appended to the querystring // we need to strip "-new" to get the querystring if (self::is_new_item()) { // check to see if user ID is set, if not, return false if (empty(self::$user->ID)) { return false; } $new = strrpos(self::$querystring, '-new'); if ($new !== false) { // get rid of "-new" from the querystring $qs = substr(self::$querystring, 0, $new); } else { /** * If new item querystring isn't default, let plugins render querystring. * * Plugins should return a querystring matching whitelisted parameters from the * 'bp_rbe_allowed_params' filter. * * @since 1.0-RC4 * * @param string $qs Current string. */ $qs = (string) apply_filters('bp_rbe_new_item_querystring', self::$querystring); } } else { $qs = self::$querystring; } // only decode if querystring is a hexadecimal string if (ctype_xdigit($qs)) { // New posted items will pass $user_id along with $qs for decoding // This is done as an additional security measure because the "From" header // can be spoofed and is similar to how Basecamp handles posting new items if (self::is_new_item()) { // pass $user_id to bp_rbe_decode() $qs = apply_filters('bp_rbe_decode_qs', bp_rbe_decode(array('string' => $qs, 'param' => self::$user->ID)), $qs, self::$user->ID); // Replied items will use the regular $qs for decoding } else { $qs = apply_filters('bp_rbe_decode_qs', bp_rbe_decode(array('string' => self::$querystring)), $qs, false); } } // These are the default params we want to check for $defaults = array('a' => false, 'p' => false, 't' => false, 'm' => false, 'g' => false); // Let 3rd-party plugins whitelist additional params $defaults = apply_filters('bp_rbe_allowed_params', $defaults, $qs); // Parse querystring into an array wp_parse_str($qs, $params); // Only allow parameters set from $defaults through $params = array_intersect_key($params, $defaults); // If no params, return false if (empty($params)) { return false; } return $params; }