<commit_before><?php

/**
 * Class toolkit_achievement_earners_widget.
 *
 * Create our achievement earners list.
 *
 * @since 1.0.0
 */
class toolkit_achievement_earners_widget extends WP_Widget {

	public $directory_url = '';

	/**
	 * Put everything together.
	 *
	 * @since 1.0.0
	 */
	public function __construct() {
		global $toolbox;
		$this->directory_url  = $toolbox->directory_url;

		$widget_ops = array(
			'classname' => 'badgeos_toolkit_achievement_earners_class',
			'description' => __( 'Displays all earners of specified achievements.', 'badgeos-toolkit' )
		);
		parent::__construct( 'toolkit_achievement_earners_widget', __( 'BadgeOS ToolKit Achievement Earners List', 'badgeos-toolkit' ), $widget_ops );

		if ( is_active_widget( false, false, $this->id_base ) ) {
			add_action( 'wp_enqueue_scripts', array( $this, 'styles_scripts' ) );
		}
	}

	/**
	 * Enqueue any necessary stylesheets or scripts.
	 *
	 * @since 1.0.0
	 */
	public function styles_scripts() {

	}

	/**
	 * Helper function for widget form() method display.
	 *
	 * @since 1.0.0
	 *
	 * @param array $args Arguments to be used with the input type output.
	 *
	 * @return string $value HTML output for the input type.
	 */
	public function form_input_text( $args = array() ) {
		$label = esc_attr( $args['label'] );
		$name  = esc_attr( $args['name'] );
		$id    = esc_attr( $args['id'] );
		$value = esc_attr( $args['value'] );

		printf(
			'<p><label for="%1$s">%2$s</label><input type="text" class="widefat" name="%3$s" id="%1$s" value="%4$s" /></p>',
			$id,
			$label,
			$name,
			$value
		);
	}

	/**
	 * Output our form for the WP Admin.
	 *
	 * @param array $instance Values for our current widget instance.
	 *
	 * @return string HTML output for the form method.
	 */
	public function form( $instance ) {
		$defaults = array(
			'title' => __( 'Achievement Earners', 'badgeos' ),
			'achievement_ids' => '',
		);
		$instance = wp_parse_args( (array) $instance, $defaults );

		$this->form_input_text(
			array(
				'label' => __( 'Title:', 'badgeos-toolkit'),
				'name' => $this->get_field_name( 'title' ),
				'id' => $this->get_field_id( 'title' ),
				'value' => $instance['title']
			)
		);
		$this->form_input_text(
			array(
				'label' => __( 'Achievement IDs to display, separated by commas:', 'badgeos-toolkit'),
				'name' => $this->get_field_name( 'achievement_ids' ),
				'id' => $this->get_field_id( 'achievement_ids' ),
				'value' => $instance['achievement_ids']
			)
		);
		?>
			<p>
				<label>
					<input type="checkbox" id="<?php echo $this->get_field_name( 'point_total' ); ?>" name="<?php echo $this->get_field_name( 'point_total' ); ?>" <?php checked( $instance['point_total'], 'on' ); ?> />
					<?php _e( 'Display user\'s total points', 'badgeos-toolkit' ); ?>
				</label>
			</p>
			<p>
				<?php _e( 'Display only the following Achievement Types:', 'badgeos-toolkit' ); ?><br />
				<?php
				$achievements = badgeos_get_achievement_types();
				foreach ( $achievements as $achievement_slug => $achievement ) {

					if ( $achievement['single_name'] == 'step' ) {
						continue;
					}

					# if achievement displaying exists in the saved array it is enabled for display
					$checked = checked( in_array( $achievement_slug, $set_achievements ), true, false );

					printf(
						'<label for="%s"><input type="checkbox" name="%s[]" id="%s" value="%s" %s /> %s</label><br/>',
						$this->get_field_name( 'set_achievements' ) . '_' . esc_attr( $achievement_slug ),
						$this->get_field_name( 'set_achievements' ),
						$this->get_field_name( 'set_achievements' ) . '_' . esc_attr( $achievement_slug ),
						esc_attr( $achievement_slug ),
						$checked,
						esc_html( ucfirst( $achievement[ 'plural_name' ] ) )
					);
				}
				?>
			</p>
        <?php
	}

	/**
	 * Update our widget values.
	 *
	 * @param array $new_instance Newly entered widget data.
	 * @param array $old_instance Current values for widget data.
	 *
	 * @return array $instance Sanitized new data to save.
	 */
	public function update( $new_instance, $old_instance ) {
		$instance = $old_instance;

		$instance['title']            = sanitize_text_field( $new_instance['title'] );
		$instance['number']           = absint( $new_instance['number'] );
		$instance['point_total']      = ( ! empty( $new_instance['point_total'] ) ) ? sanitize_text_field( $new_instance['point_total'] ) : '';
		$instance['set_achievements'] = array_map( 'sanitize_text_field', $new_instance['set_achievements'] );

		return $instance;
	}

	/**
	 * Output the frontend widget display.<commit_msg>remove unneeded form fields<commit_after><?php

/**
 * Class toolkit_achievement_earners_widget.
 *
 * Create our achievement earners list.
 *
 * @since 1.0.0
 */
class toolkit_achievement_earners_widget extends WP_Widget {

	public $directory_url = '';

	/**
	 * Put everything together.
	 *
	 * @since 1.0.0
	 */
	public function __construct() {
		global $toolbox;
		$this->directory_url  = $toolbox->directory_url;

		$widget_ops = array(
			'classname' => 'badgeos_toolkit_achievement_earners_class',
			'description' => __( 'Displays all earners of specified achievements.', 'badgeos-toolkit' )
		);
		parent::__construct( 'toolkit_achievement_earners_widget', __( 'BadgeOS ToolKit Achievement Earners List', 'badgeos-toolkit' ), $widget_ops );

		if ( is_active_widget( false, false, $this->id_base ) ) {
			add_action( 'wp_enqueue_scripts', array( $this, 'styles_scripts' ) );
		}
	}

	/**
	 * Enqueue any necessary stylesheets or scripts.
	 *
	 * @since 1.0.0
	 */
	public function styles_scripts() {

	}

	/**
	 * Helper function for widget form() method display.
	 *
	 * @since 1.0.0
	 *
	 * @param array $args Arguments to be used with the input type output.
	 *
	 * @return string $value HTML output for the input type.
	 */
	public function form_input_text( $args = array() ) {
		$label = esc_attr( $args['label'] );
		$name  = esc_attr( $args['name'] );
		$id    = esc_attr( $args['id'] );
		$value = esc_attr( $args['value'] );

		printf(
			'<p><label for="%1$s">%2$s</label><input type="text" class="widefat" name="%3$s" id="%1$s" value="%4$s" /></p>',
			$id,
			$label,
			$name,
			$value
		);
	}

	/**
	 * Output our form for the WP Admin.
	 *
	 * @param array $instance Values for our current widget instance.
	 *
	 * @return string HTML output for the form method.
	 */
	public function form( $instance ) {
		$defaults = array(
			'title' => __( 'Achievement Earners', 'badgeos' ),
			'achievement_ids' => '',
		);
		$instance = wp_parse_args( (array) $instance, $defaults );

		$this->form_input_text(
			array(
				'label' => __( 'Title:', 'badgeos-toolkit'),
				'name' => $this->get_field_name( 'title' ),
				'id' => $this->get_field_id( 'title' ),
				'value' => $instance['title']
			)
		);
		$this->form_input_text(
			array(
				'label' => __( 'Achievement IDs to display, separated by commas:', 'badgeos-toolkit'),
				'name' => $this->get_field_name( 'achievement_ids' ),
				'id' => $this->get_field_id( 'achievement_ids' ),
				'value' => $instance['achievement_ids']
			)
		);
	}

	/**
	 * Update our widget values.
	 *
	 * @param array $new_instance Newly entered widget data.
	 * @param array $old_instance Current values for widget data.
	 *
	 * @return array $instance Sanitized new data to save.
	 */
	public function update( $new_instance, $old_instance ) {
		$instance = $old_instance;

		$instance['title']            = sanitize_text_field( $new_instance['title'] );
		$instance['number']           = absint( $new_instance['number'] );
		$instance['point_total']      = ( ! empty( $new_instance['point_total'] ) ) ? sanitize_text_field( $new_instance['point_total'] ) : '';
		$instance['set_achievements'] = array_map( 'sanitize_text_field', $new_instance['set_achievements'] );

		return $instance;
	}

	/**
	 * Output the frontend widget display.
{'fraction_non_alphanumeric': 0.16713233426466853, 'fraction_numerical': 0.004318008636017272, 'mean_word_length': 3.637809187279152, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 80, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2759342', 'n_tokens_mistral': 3078, 'n_tokens_neox': 2723, 'n_words': 614}