' . wp_nonce_field( 'save_settings', 'yoast_ga_nonce', null, false ); } /** * Return the form end tag and the submit button * * @param string $button_label * @param string $name * @param string $onclick * * @return null|string */ public static function end_form( $button_label = null, $name = 'submit', $onclick = null ) { if ( $button_label === null ) { $button_label = __( 'Save changes', 'google-analytics-for-wordpress' ); } $output = null; $output .= '
'; $output .= ' $type, 'id' => 'yoast-ga-form-' . $type . '-' . self::$form_namespace . '-' . $id . '', 'name' => $name, 'class' => 'ga-form ga-form-' . $type . ' ', ); if ( $type == 'checkbox' ) { $attributes['value'] = '1'; if ( $input_value == 1 ) { $attributes['checked'] = 'checked'; } } else { $attributes['value'] = stripslashes( $input_value ); } $input .= ''; if ( ! is_null( $text_label ) ) { $input .= ''; } // If we get a description, append it to this select field in a new row if ( ! is_null( $description ) ) { $input .= self::show_help( $id, $description ); } $input .= '
'; return $input; } /** * Generate a select box * * @param string $title * @param string $name * @param array $values * @param null|string $description * @param bool $multiple * @param string $empty_text * * @return null|string */ public static function select( $title, $name, $values, $description = null, $multiple = false, $empty_text = null ) { $select = null; $id = str_replace( '[', '-', $name ); $id = str_replace( ']', '', $id ); $select .= '
'; if ( ! is_null( $title ) ) { $select .= self::label( $id, $title, 'select' ); // ''; } if ( $multiple ) { $select .= ''; if ( ! is_null( $empty_text ) ) { $select .= ''; } } if ( count( $values ) >= 1 ) { $select_value = self::get_formfield_from_options( $name ); foreach ( $values as $optgroup => $value ) { if ( ! empty( $value['items'] ) ) { $select .= self::create_optgroup( $optgroup, $value, $select_value ); } else { $select .= self::option( $select_value, $value ); } } } $select .= ''; if ( ! is_null( $description ) ) { $select .= self::show_help( $id, $description ); } $select .= '
'; return $select; } /** * Generate a textarea field * * @param string $title * @param string $name * @param null|string $description * * @return null|string */ public static function textarea( $title, $name, $description = null ) { $text = null; $id = Yoast_GA_Options::instance()->option_prefix . '_' . $name; $textarea_value = self::get_formfield_from_options( $name ); $text .= '
'; if ( ! is_null( $title ) ) { $text .= ''; } $text .= ''; if ( ! is_null( $description ) ) { $text .= self::show_help( $id, $description ); } $text .= '
'; return $text; } /** * Parsing a option string for select * * @param string $select_value * @param string $value * * @return string */ private static function option( $select_value, $value ) { if ( is_array( $select_value ) ) { if ( in_array( esc_attr( $value['id'] ), $select_value ) ) { return ''; } else { return ''; } } else { return ''; } } /** * Show a question mark with help * * @param string $id * @param string $description * * @return string */ public static function show_help( $id, $description ) { $help = '' . esc_attr( $description ) . ''; return $help; } /** * Will parse the optgroups. * * @param array $values * * @return array */ public static function parse_optgroups( $values ) { $optgroups = array(); foreach ( $values as $key => $value ) { foreach ( $value['items'] as $subitem ) { $optgroups[ $subitem['name'] ]['items'] = $subitem['items']; } } return $optgroups; } /** * Creates a label * * @param string $id * @param string $title * @param string $type * * @return string */ private static function label( $id, $title, $type ) { return ''; } /** * Creates a optgroup with the items. If items contain items it will create a nested optgroup * * @param string $optgroup * @param array $value * @param array $select_value * * @return string */ private static function create_optgroup( $optgroup, $value, $select_value ) { $optgroup = ''; foreach ( $value['items'] as $option ) { if ( ! empty( $option['items'] ) ) { $optgroup .= self::create_optgroup( esc_attr( $option['name'] ), $option, $select_value ); } else { $optgroup .= self::option( $select_value, $option ); } } $optgroup .= ''; return $optgroup; } /** * Getting the value from the option, if it doesn't exist return empty string * * @param string $name * * @return string */ private static function get_formfield_from_options( $name ) { static $options; if ( $options === null ) { $options = Yoast_GA_Options::instance()->get_options(); } // Catch a notice if the option doesn't exist, yet return ( isset( $options[ $name ] ) ) ? $options[ $name ] : ''; } /** * Parsing given array with attributes as an attribute string * * @param array $attributes_to_parse * * @return string */ private static function parse_attributes( $attributes_to_parse ) { $parsed_attributes = ''; foreach ( $attributes_to_parse as $attribute_name => $attribute_value ) { $parsed_attributes .= $attribute_name . '="' . $attribute_value . '" '; } return trim( $parsed_attributes ); } }