";
}
$input_attr .= " aioseop_{$opts['type']}_type";
$display_row_template = '
';
return sprintf( $display_row_template, $input_attr, $name, $label_text, $id_attr, $this->get_option_html( $args ) );
}
/**
* Display options for settings pages and metaboxes, allows for filtering settings, custom display options.
*
* @param null $location
* @param null $meta_args
*/
function display_options( $location = null, $meta_args = null ) {
static $location_settings = array();
$defaults = null;
$prefix = $this->get_prefix( $location );
$help_link = '';
if ( is_array( $meta_args['args'] ) && ! empty( $meta_args['args']['default_options'] ) ) {
$defaults = $meta_args['args']['default_options'];
}
if ( ! empty( $meta_args['callback_args'] ) && ! empty( $meta_args['callback_args']['help_link'] ) ) {
$help_link = $meta_args['callback_args']['help_link'];
}
if ( ! empty( $help_link ) ) {
echo "
" . __( 'Help', 'all-in-one-seo-pack' ) . '';
}
if ( ! isset( $location_settings[ $prefix ] ) ) {
$current_options = apply_filters( "{$this->prefix}display_options", $this->get_current_options( array(), $location, $defaults ), $location );
$settings = apply_filters( "{$this->prefix}display_settings", $this->setting_options( $location, $defaults ), $location, $current_options );
$current_options = apply_filters( "{$this->prefix}override_options", $current_options, $location, $settings );
$location_settings[ $prefix ]['current_options'] = $current_options;
$location_settings[ $prefix ]['settings'] = $settings;
} else {
$current_options = $location_settings[ $prefix ]['current_options'];
$settings = $location_settings[ $prefix ]['settings'];
}
// $opts["snippet"]["default"] = sprintf( $opts["snippet"]["default"], "foo", "bar", "moby" );
$container = "
";
if ( is_array( $meta_args['args'] ) && ! empty( $meta_args['args']['options'] ) ) {
$args = array();
$arg_keys = array();
foreach ( $meta_args['args']['options'] as $a ) {
if ( ! empty( $location ) ) {
$key = $prefix . $location . '_' . $a;
if ( ! isset( $settings[ $key ] ) ) {
$key = $a;
}
} else {
$key = $prefix . $a;
}
if ( isset( $settings[ $key ] ) ) {
$arg_keys[ $key ] = 1;
} elseif ( isset( $settings[ $a ] ) ) {
$arg_keys[ $a ] = 1;
}
}
$setting_keys = array_keys( $settings );
foreach ( $setting_keys as $s ) {
if ( ! empty( $arg_keys[ $s ] ) ) {
$args[ $s ] = $settings[ $s ];
}
}
} else {
$args = $settings;
}
foreach ( $args as $name => $opts ) {
// List of valid element attributes.
$attr_list = array( 'class', 'style', 'readonly', 'disabled', 'size', 'placeholder', 'autocomplete' );
if ( 'textarea' == $opts['type'] ) {
$attr_list = array_merge( $attr_list, array( 'rows', 'cols' ) );
}
// Set element attribute values.
$attr = '';
foreach ( $attr_list as $a ) {
if ( isset( $opts[ $a ] ) ) {
$attr .= ' ' . $a . '="' . esc_attr( $opts[ $a ] ) . '" ';
}
}
$opt = '';
if ( isset( $current_options[ $name ] ) ) {
$opt = $current_options[ $name ];
}
if ( 'none' == $opts['label'] && 'submit' == $opts['type'] && false == $opts['save'] ) {
$opt = $opts['name'];
}
if ( 'html' == $opts['type'] && empty( $opt ) && false == $opts['save'] ) {
$opt = $opts['default'];
}
$newArgs = array(
'name' => $name,
'options' => $opts,
'attr' => $attr,
'value' => $opt,
'prefix' => $prefix,
);
if ( ! empty( $opts['nowrap'] ) ) {
echo $this->get_option_html( $newArgs );
} else {
if ( $container ) {
echo $container;
$container = '';
}
echo $this->get_option_row( $name, $opts, $newArgs );
}
}
if ( ! $container ) {
echo '
';
}
}
/**
* Sanitize Domain
*
* @since ?
*
* @param $domain
* @return mixed|string
*/
function sanitize_domain( $domain ) {
$domain = trim( $domain );
$domain = AIOSEOP_PHP_Functions::strtolower( $domain );
if ( 0 === AIOSEOP_PHP_Functions::strpos( $domain, 'http://' ) ) {
$domain = AIOSEOP_PHP_Functions::substr( $domain, 7 );
} elseif ( 0 === AIOSEOP_PHP_Functions::strpos( $domain, 'https://' ) ) {
$domain = AIOSEOP_PHP_Functions::substr( $domain, 8 );
}
$domain = untrailingslashit( $domain );
return $domain;
}
/** Sanitize options
*
* @param null $location
*/
function sanitize_options( $location = null ) {
foreach ( $this->setting_options( $location ) as $k => $v ) {
if ( isset( $this->options[ $k ] ) ) {
if ( ! empty( $v['sanitize'] ) ) {
$type = $v['sanitize'];
} else {
$type = $v['type'];
}
switch ( $type ) {
case 'multiselect':
// fall through.
case 'multicheckbox':
$this->options[ $k ] = urlencode_deep( $this->options[ $k ] );
break;
case 'textarea':
// #1363: prevent characters like ampersand in title and description (in social meta module) from getting changed to &
if ( ! ( 'opengraph' === $location && in_array( $k, array( 'aiosp_opengraph_hometitle', 'aiosp_opengraph_description' ), true ) ) ) {
$this->options[ $k ] = wp_kses_post( $this->options[ $k ] );
}
$this->options[ $k ] = htmlspecialchars( $this->options[ $k ], ENT_QUOTES, 'UTF-8' );
break;
case 'filename':
$this->options[ $k ] = sanitize_file_name( $this->options[ $k ] );
break;
case 'address':
foreach ( $this->options[ $k ] as &$address_value ) {
$address_value = wp_kses_post( $address_value );
}
break;
case 'url':
// fall through.
case 'text':
$this->options[ $k ] = wp_kses_post( $this->options[ $k ] );
// fall through.
case 'checkbox':
// fall through.
case 'radio':
// fall through.
case 'select':
// fall through.
default:
if ( ! is_array( $this->options[ $k ] ) ) {
$this->options[ $k ] = esc_attr( $this->options[ $k ] );
}
}
}
}
}
/**
* Display metaboxes with display_options()
*
* @param $post
* @param $metabox
*/
function display_metabox( $post, $metabox ) {
$this->display_options( $metabox['args']['location'], $metabox );
}
/**
* Handle resetting options to defaults.
*
* @param null $location
* @param bool $delete
*/
function reset_options( $location = null, $delete = false ) {
if ( true === $delete ) {
$this->delete_class_option( $delete );
$this->options = array();
}
$default_options = $this->default_options( $location );
foreach ( $default_options as $k => $v ) {
$this->options[ $k ] = $v;
}
$this->update_class_option( $this->options );
}
/**
* Handle Settings Updates
*
* Handle option resetting and updating.
*
* @since ?
*
* @param null $location
* @return mixed|string|void
*/
function handle_settings_updates( $location = null ) {
$message = '';
if (
(
isset( $_POST['action'] ) &&
'aiosp_update_module' == $_POST['action'] &&
(
isset( $_POST['Submit_Default'] ) ||
isset( $_POST['Submit_All_Default'] ) ||
! empty( $_POST['Submit'] )
)
)
) {
$nonce = $_POST['nonce-aioseop'];
if ( ! wp_verify_nonce( $nonce, 'aioseop-nonce' ) ) {
die( __( 'Security Check - If you receive this in error, log out and back in to WordPress', 'all-in-one-seo-pack' ) );
}
if ( isset( $_POST['Submit_Default'] ) || isset( $_POST['Submit_All_Default'] ) ) {
/* translators: This message confirms that the options have been reset. */
$message = __( 'Options Reset.', 'all-in-one-seo-pack' );
if ( isset( $_POST['Submit_All_Default'] ) ) {
$this->reset_options( $location, true );
do_action( 'aioseop_options_reset' );
} else {
$this->reset_options( $location );
}
}
if ( ! empty( $_POST['Submit'] ) ) {
/* translators: %s is a placeholder and will be replace with the name of the plugin. */
$message = sprintf( __( '%s Options Updated.', 'all-in-one-seo-pack' ), AIOSEOP_PLUGIN_NAME );
$default_options = $this->default_options( $location );
$prefix = $this->prefix;
foreach ( $this->default_options as $k => $option_arr ) {
if ( isset( $option_arr['type'] ) && 'address' === $option_arr['type'] ) {
$address_values = array(
'street_address' => '',
'address_locality' => '',
'address_region' => '',
'postal_code' => '',
'address_country' => '',
);
foreach ( $address_values as $address_key => &$address_value ) {
if ( isset( $_POST[ $prefix . $k . '_' . $address_key ] ) ) {
$address_value = stripslashes_deep( $_POST[ $prefix . $k . '_' . $address_key ] );
}
}
$this->options[ $prefix . $k ] = $address_values;
} elseif ( isset( $_POST[ $prefix . $k ] ) ) {
$this->options[ $prefix . $k ] = stripslashes_deep( $_POST[ $prefix . $k ] );
} else {
$this->options[ $prefix . $k ] = '';
}
}
$this->sanitize_options( $location );
$this->options = apply_filters( $this->prefix . 'update_options', $this->options, $location );
$this->update_class_option( $this->options );
wp_cache_flush();
}
do_action( $this->prefix . 'settings_update', $this->options, $location );
}
return $message;
}
/** Update / reset settings, printing options, sanitizing, posting back
*
* @param null $location
*/
function display_settings_page( $location = null ) {
if ( null != $location ) {
$location_info = $this->locations[ $location ];
}
$name = null;
if ( $location && isset( $location_info['name'] ) ) {
$name = $location_info['name'];
}
if ( ! $name ) {
$name = $this->name;
}
$message = $this->handle_settings_updates( $location );
$this->settings_page_init();
?>
prefix . 'settings_header_errors', $location );
$errors = ob_get_clean();
echo $errors;
?>
";
}
?>
prefix . 'settings_header', $location );
?>
prefix . 'settings_footer', $location );
do_action( 'aioseop_global_settings_footer', $location );
?>
locations[ $location ]['prefix'] ) ) {
return $this->locations[ $location ]['prefix'];
}
return $this->prefix;
}
/** Sets up initial settings
*
* @param null $location
* @param null $defaults
*
* @return array
*/
function setting_options( $location = null, $defaults = null ) {
if ( null === $defaults ) {
$defaults = $this->default_options;
}
$prefix = $this->get_prefix( $location );
$opts = array();
if ( null == $location || null === $this->locations[ $location ]['options'] ) {
$options = $defaults;
} else {
$options = array();
$prefix = "{$prefix}{$location}_";
if ( ! empty( $this->locations[ $location ]['default_options'] ) ) {
$options = $this->locations[ $location ]['default_options'];
}
foreach ( $this->locations[ $location ]['options'] as $opt ) {
if ( isset( $defaults[ $opt ] ) ) {
$options[ $opt ] = $defaults[ $opt ];
}
}
}
if ( ! $prefix ) {
$prefix = $this->prefix;
}
if ( ! empty( $options ) ) {
foreach ( $options as $k => $v ) {
if ( ! isset( $v['name'] ) ) {
$v['name'] = AIOSEOP_PHP_Functions::ucwords( strtr( $k, '_', ' ' ) );
}
if ( ! isset( $v['type'] ) ) {
$v['type'] = 'checkbox';
}
if ( ! isset( $v['default'] ) ) {
$v['default'] = null;
}
if ( ! isset( $v['initial_options'] ) ) {
$v['initial_options'] = $v['default'];
}
if ( 'custom' == $v['type'] && ( ! isset( $v['nowrap'] ) ) ) {
$v['nowrap'] = true;
} elseif ( ! isset( $v['nowrap'] ) ) {
$v['nowrap'] = null;
}
if ( isset( $v['condshow'] ) ) {
if ( ! is_array( $this->script_data ) ) {
$this->script_data = array();
}
if ( ! isset( $this->script_data['condshow'] ) ) {
$this->script_data['condshow'] = array();
}
$this->script_data['condshow'][ $prefix . $k ] = $v['condshow'];
}
if ( 'submit' == $v['type'] ) {
if ( ! isset( $v['save'] ) ) {
$v['save'] = false;
}
if ( ! isset( $v['label'] ) ) {
$v['label'] = 'none';
}
if ( ! isset( $v['prefix'] ) ) {
$v['prefix'] = false;
}
} else {
if ( ! isset( $v['label'] ) ) {
$v['label'] = null;
}
}
if ( 'hidden' == $v['type'] ) {
if ( ! isset( $v['label'] ) ) {
$v['label'] = 'none';
}
if ( ! isset( $v['prefix'] ) ) {
$v['prefix'] = false;
}
}
if ( ( 'text' == $v['type'] ) && ( ! isset( $v['size'] ) ) ) {
$v['size'] = 57;
}
if ( 'textarea' == $v['type'] ) {
if ( ! isset( $v['cols'] ) ) {
$v['cols'] = 57;
}
if ( ! isset( $v['rows'] ) ) {
$v['rows'] = 2;
}
}
if ( ! isset( $v['save'] ) ) {
$v['save'] = true;
}
if ( ! isset( $v['prefix'] ) ) {
$v['prefix'] = true;
}
if ( $v['prefix'] ) {
$opts[ $prefix . $k ] = $v;
} else {
$opts[ $k ] = $v;
}
}
}
return $opts;
}
/**
* Generates just the default option names and values
*
* @since 2.4.13 Applies filter before final return.
*
* @param null $location
* @param null $defaults
*
* @return array
*/
function default_options( $location = null, $defaults = null ) {
$prefix = $this->get_prefix( $location );
$options = $this->setting_options( $location, $defaults );
$opts = array();
foreach ( $options as $k => $v ) {
if ( $v['save'] ) {
$opts[ $k ] = $v['default'];
}
}
return apply_filters( $prefix . 'default_options', $opts, $location );
}
/**
* Gets the current options stored for a given location.
*
* @since 2.4.14 Added taxonomy options.
*
* @param array $opts
* @param null $location
* @param null $defaults
* @param null $post
*
* @return array
*/
function get_current_options( $opts = array(), $location = null, $defaults = null, $post = null ) {
$prefix = $this->get_prefix( $location );
$get_opts = '';
if ( empty( $location ) ) {
$type = 'settings';
} else {
$type = $this->locations[ $location ]['type'];
}
if ( 'settings' === $type ) {
$get_opts = $this->get_class_option();
} elseif ( 'metabox' == $type ) {
if ( null == $post ) {
global $post;
}
if (
(
isset( $_GET['taxonomy'] ) &&
isset( $_GET['tag_ID'] )
) ||
is_category() ||
is_tag() ||
is_tax()
) {
$term_id = isset( $_GET['tag_ID'] ) ? (int) $_GET['tag_ID'] : 0;
$term_id = $term_id ? $term_id : get_queried_object()->term_id;
if ( AIOSEOPPRO ) {
$get_opts = AIO_ProGeneral::getprotax( $get_opts );
$get_opts = get_term_meta( $term_id, '_' . $prefix . $location, true );
}
} elseif ( isset( $post ) ) {
$get_opts = get_post_meta( $post->ID, '_' . $prefix . $location, true );
}
}
if ( is_home() && ! is_front_page() ) {
// If we're on the non-front page blog page, WP doesn't really know its post meta data so we need to get that manually for social meta.
$get_opts = get_post_meta( get_option( 'page_for_posts' ), '_' . $prefix . $location, true );
}
$defs = $this->default_options( $location, $defaults );
if ( empty( $get_opts ) ) {
$get_opts = $defs;
} else {
$get_opts = wp_parse_args( $get_opts, $defs );
}
$opts = wp_parse_args( $opts, $get_opts );
return $opts;
}
/** Updates the options array in the module; loads saved settings with get_option() or uses defaults
*
* @param array $opts
* @param null $location
* @param null $defaults
*/
function update_options( $opts = array(), $location = null, $defaults = null ) {
if ( null === $location ) {
$type = 'settings';
} else {
$type = $this->locations[ $location ][ $type ];
}
if ( 'settings' === $type ) {
$get_opts = $this->get_class_option();
}
if ( false === $get_opts ) {
$get_opts = $this->default_options( $location, $defaults );
} else {
$this->setting_options( $location, $defaults );
} // hack -- make sure this runs anyhow, for now -- pdb
$this->options = wp_parse_args( $opts, $get_opts );
}
}
}