<commit_before><?php

/**
 * WordPress link manager property.
 */
class Papi_Property_Link extends Papi_Property {

	/**
	 * The convert type.
	 *
	 * @var string
	 */
	public $convert_type = 'object';

	/**
	 * The default value.
	 *
	 * @var array
	 */
	public $default_value = [];

	/**
	 * Link fields.
	 *
	 * @var array
	 */
	protected $link_fields = [
		'post_id',
		'url',
		'title',
		'target'
	];

	/**
	 * Delete value from the database.
	 *
	 * @param  string $slug
	 * @param  int    $post_id
	 * @param  string $type
	 *
	 * @return bool
	 */
	public function delete_value( $slug, $post_id, $type ) {
		$values = $this->load_value( null, $slug, $post_id );
		$values = is_object( $values ) ? (array) $values : $values;
		$result = true;

		foreach ( array_keys( $values ) as $key ) {
			$out    = papi_delete_property_meta_value( $post_id, $slug . '_' . $key );
			$result = $out ? $result : $out;
		}

		if ( $result ) {
			$result = papi_delete_property_meta_value( $post_id, $slug );
		}

		return $result;
	}

	/**
	 * Format the value of the property before it's returned
	 * to WordPress admin or the site.
	 *
	 * @param  mixed  $value
	 * @param  string $slug
	 * @param  int    $post_id
	 *
	 * @return mixed
	 */
	public function format_value( $value, $slug, $post_id ) {
		return (object) $this->prepare_link_array( $value, $slug );
	}

	/**
	 * Get default settings.
	 *
	 * @return array
	 */
	public function get_default_settings() {
		return [];
	}

	/**
	 * Load value from database.
	 *
	 * @param  mixed  $value
	 * @param  string $slug
	 * @param  int    $post_id
	 *
	 * @return array
	 */
	public function load_value( $value, $slug, $post_id ) {
		return (object) $this->prepare_link_array( $value, $slug );
	}

	/**
	 * Render property html.
	 */
	public function html() {
		$value  = $this->get_value();
		$value  = is_array( $value ) || is_object( $value ) ? $value : [];
		$value  = (object) $value;
		$exists = ! empty( $value->url );
		?>
		<div class="papi-property-link" data-replace-slug="true" data-slug="<?php echo esc_attr( $this->html_name() ); ?>">
			<input type="hidden" name="<?php echo esc_attr( $this->html_name() ); ?>" value="<?php echo $exists ? 1 : ''; ?>">

			<?php if ( $exists ): ?>
				<table class="papi-table link-table">
					<tbody>
						<tr>
							<td><?php esc_html_e( 'URL', 'papi' ); ?></td><commit_msg>Fix load value for link property for standalone properties<commit_after><?php

/**
 * WordPress link manager property.
 */
class Papi_Property_Link extends Papi_Property {

	/**
	 * The convert type.
	 *
	 * @var string
	 */
	public $convert_type = 'object';

	/**
	 * The default value.
	 *
	 * @var array
	 */
	public $default_value = [];

	/**
	 * Link fields.
	 *
	 * @var array
	 */
	protected $link_fields = [
		'post_id',
		'url',
		'title',
		'target'
	];

	/**
	 * Delete value from the database.
	 *
	 * @param  string $slug
	 * @param  int    $post_id
	 * @param  string $type
	 *
	 * @return bool
	 */
	public function delete_value( $slug, $post_id, $type ) {
		$values = $this->load_value( null, $slug, $post_id );
		$values = is_object( $values ) ? (array) $values : $values;
		$result = true;

		foreach ( array_keys( $values ) as $key ) {
			$out    = papi_delete_property_meta_value( $post_id, $slug . '_' . $key );
			$result = $out ? $result : $out;
		}

		if ( $result ) {
			$result = papi_delete_property_meta_value( $post_id, $slug );
		}

		return $result;
	}

	/**
	 * Format the value of the property before it's returned
	 * to WordPress admin or the site.
	 *
	 * @param  mixed  $value
	 * @param  string $slug
	 * @param  int    $post_id
	 *
	 * @return mixed
	 */
	public function format_value( $value, $slug, $post_id ) {
		return (object) $this->prepare_link_array( $value, $slug );
	}

	/**
	 * Get default settings.
	 *
	 * @return array
	 */
	public function get_default_settings() {
		return [];
	}

	/**
	 * Load value from database.
	 *
	 * @param  mixed  $value
	 * @param  string $slug
	 * @param  int    $post_id
	 *
	 * @return array
	 */
	public function load_value( $value, $slug, $post_id ) {
		if ( is_array( $value ) || is_object( $value ) ) {
			$values = $value;
		} else {
			$values = $this->link_fields;

			foreach ( $values as $index => $key ) {
				$values[$key] = papi_get_property_meta_value(
					$post_id,
					sprintf( '%s_%s', $slug, $key ),
					$this->get_meta_type()
				);
				unset( $values[$index] );
			}
		}

		return (object) $this->prepare_link_array( $values, $slug );
	}

	/**
	 * Render property html.
	 */
	public function html() {
		$value  = $this->get_value();
		$value  = is_array( $value ) || is_object( $value ) ? $value : [];
		$value  = (object) $value;
		$exists = ! empty( $value->url );
		?>
		<div class="papi-property-link" data-replace-slug="true" data-slug="<?php echo esc_attr( $this->html_name() ); ?>">
			<input type="hidden" name="<?php echo esc_attr( $this->html_name() ); ?>" value="<?php echo $exists ? 1 : ''; ?>">

			<?php if ( $exists ): ?>
				<table class="papi-table link-table">
					<tbody>
						<tr>
							<td><?php esc_html_e( 'URL', 'papi' ); ?></td>
{'fraction_non_alphanumeric': 0.17477617750097313, 'fraction_numerical': 0.00038925652004671076, 'mean_word_length': 2.8843537414965987, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 46, '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': '5618645', 'n_tokens_mistral': 2042, 'n_tokens_neox': 1836, 'n_words': 458}