Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 13 additions & 94 deletions src/class-tiny-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -661,85 +661,6 @@ public function render_size_checkboxes_description(
echo '</p>';
}

public function render_resize() {
$strong = array(
'strong' => array(),
);

echo '<div class="tiny-resize-unavailable" style="display: none">';
esc_html_e(
'Enable compression of the original image size for more options.',
'tiny-compress-images'
);
echo '</div>';

$id = self::get_prefixed_name( 'resize_original_enabled' );
$name = self::get_prefixed_name( 'resize_original[enabled]' );
$checked = ( $this->get_resize_enabled() ? ' checked="checked"' : '' );

$label = esc_html__(
'Resize the original image',
'tiny-compress-images'
);

echo '<div class="tiny-resize-available">';
echo '<input type="checkbox" id="' . $id . '" name="' . $name .
'" value="on" ' . $checked . '/>';
echo '<label for="' . $id . '">' . $label . '</label><br>';

echo '<div class="tiny-resize-available tiny-resize-resolution">';
echo '<span>';
echo wp_kses(
__(
// phpcs:ignore Generic.Files.LineLength
'<strong>Save space</strong> by setting a maximum width and height for all images uploaded.',
'tiny-compress-images'
),
$strong
);
echo '<br>';
echo wp_kses(
__(
// phpcs:ignore Generic.Files.LineLength
'Resizing takes <strong>1 additional compression</strong> for each image that is larger.',
'tiny-compress-images'
),
$strong
);
echo '</span>';
echo '<div class="tiny-resize-inputs">';
printf( '%s: ', esc_html__( 'Max Width', 'tiny-compress-images' ) );
$this->render_resize_input( 'width' );
printf( '%s: ', esc_html__( 'Max Height', 'tiny-compress-images' ) );
$this->render_resize_input( 'height' );
echo '</div></div></div>';

$this->render_preserve_input(
'creation',
esc_html__(
'Preserve creation date and time in the original image',
'tiny-compress-images'
)
);

$this->render_preserve_input(
'copyright',
esc_html__(
'Preserve copyright information in the original image',
'tiny-compress-images'
)
);

$this->render_preserve_input(
'location',
esc_html__(
'Preserve GPS location in the original image',
'tiny-compress-images'
) . ' ' .
esc_html__( '(JPEG only)', 'tiny-compress-images' )
);
}

public function render_compression_timing_radiobutton(
$name,
$label,
Expand Down Expand Up @@ -776,25 +697,23 @@ public function render_compression_timing_radiobutton(
}

public function render_preserve_input( $name, $description ) {
echo '<p class="tiny-preserve">';
$id = sprintf( self::get_prefixed_name( 'preserve_data_%s' ), $name );
$field = sprintf( self::get_prefixed_name( 'preserve_data[%s]' ), $name );
$checked = ( $this->get_preserve_enabled( $name ) ? ' checked="checked"' : '' );
$label = esc_html( $description, 'tiny-compress-images' );
echo '<input type="checkbox" id="' . $id . '" name="' . $field .
'" value="on" ' . $checked . '/>';
echo '<label for="' . $id . '">' . $label . '</label>';
echo '<br>';
echo '</p>';
$data = array(
'id' => sprintf( self::get_prefixed_name( 'preserve_data_%s' ), $name ),
'field' => sprintf( self::get_prefixed_name( 'preserve_data[%s]' ), $name ),
'checked' => $this->get_preserve_enabled( $name ),
'label' => $description,
);
include plugin_dir_path( __FILE__ ) . 'views/settings-original-image-preserve.php';
}

public function render_resize_input( $name ) {
$id = sprintf( self::get_prefixed_name( 'resize_original_%s' ), $name );
$field = sprintf( self::get_prefixed_name( 'resize_original[%s]' ), $name );
$settings = get_option( self::get_prefixed_name( 'resize_original' ) );
$value = isset( $settings[ $name ] ) ? $settings[ $name ] : '2048';
echo '<input type="number" id="' . $id . '" name="' . $field .
'" value="' . $value . '" size="5" />';
$data = array(
'id' => sprintf( self::get_prefixed_name( 'resize_original_%s' ), $name ),
'field' => sprintf( self::get_prefixed_name( 'resize_original[%s]' ), $name ),
'value' => isset( $settings[ $name ] ) ? $settings[ $name ] : '2048',
);
include plugin_dir_path( __FILE__ ) . 'views/settings-original-image-original.php';
}

public function get_compression_count() {
Expand Down
7 changes: 7 additions & 0 deletions src/views/settings-original-image-original.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<input
type="number"
id="<?php echo esc_attr( $data['id'] ); ?>"
name="<?php echo esc_attr( $data['field'] ); ?>"
value="<?php echo esc_attr( $data['value'] ); ?>"
size="5"
/>
11 changes: 11 additions & 0 deletions src/views/settings-original-image-preserve.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<p class="tiny-preserve">
<input type="checkbox"
id="<?php echo esc_attr( $data['id'] ); ?>"
name="<?php echo esc_attr( $data['field'] ); ?>"
<?php checked( $data['checked'] ); ?>
value="on"
/>
<label for="<?php echo esc_attr( $data['id'] ); ?>">
<?php echo esc_html( $data['label'] ); ?>
</label>
</p>
97 changes: 97 additions & 0 deletions src/views/settings-original-image.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

$strong = array(
'strong' => array(),
);

?>

<tr>
<th scope="row"><?php esc_html_e( 'Original image', 'tiny-compress-images' ); ?></th>
<td>
<div class="tiny-resize-unavailable" style="display: none">
<?php
esc_html_e(
'Enable compression of the original image size for more options.',
'tiny-compress-images'
);
?>
</div>
<div class="tiny-resize-available">
<?php
$resize_original_enabled_id = self::get_prefixed_name( 'resize_original_enabled' );
$resize_original_enabled_name = self::get_prefixed_name( 'resize_original[enabled]' );
$resize_original_enabled = $this->get_resize_enabled();
?>
<input
type="checkbox"
id="<?php echo esc_attr( $resize_original_enabled_id ); ?>"
name="<?php echo esc_attr( $resize_original_enabled_name ); ?>"
value="on"
<?php checked( $resize_original_enabled ); ?> />
<label for="<?php echo esc_attr( $resize_original_enabled_id ); ?>">
<?php
esc_html_e(
'Resize the original image',
'tiny-compress-images'
);
?>
</label><br>
<div class="tiny-resize-available tiny-resize-resolution">
<span>
<?php
echo wp_kses(
__(
'<strong>Save space</strong> by setting a maximum width and height for all images uploaded.',
'tiny-compress-images'
),
$strong
);
?>
<br>
<?php
echo wp_kses(
__(
'Resizing takes <strong>1 additional compression</strong> for each image that is larger.',
'tiny-compress-images'
),
$strong
);
?>
</span>

<div class="tiny-resize-inputs">
<?php esc_html_e( 'Max Width', 'tiny-compress-images' ); ?>:
<?php $this->render_resize_input( 'width' ); ?>
<?php esc_html_e( 'Max Height', 'tiny-compress-images' ); ?>:
<?php $this->render_resize_input( 'height' ); ?>
</div>
</div>

<?php
$this->render_preserve_input(
'creation',
esc_html__(
'Preserve creation date and time in the original image',
'tiny-compress-images'
)
);
$this->render_preserve_input(
'copyright',
esc_html__(
'Preserve copyright information in the original image',
'tiny-compress-images'
)
);
$this->render_preserve_input(
'location',
esc_html__(
'Preserve GPS location in the original image',
'tiny-compress-images'
) . ' ' .
esc_html__( '(JPEG only)', 'tiny-compress-images' )
);
?>
</div>
</td>
</tr>
7 changes: 1 addition & 6 deletions src/views/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,7 @@
<?php $this->render_format_conversion(); ?>
</td>
</tr>
<tr>
<th scope="row"><?php esc_html_e( 'Original image', 'tiny-compress-images' ); ?></th>
<td>
<?php $this->render_resize(); ?>
</td>
</tr>
<?php require plugin_dir_path( __FILE__ ) . 'settings-original-image.php'; ?>
</tbody>
</table>

Expand Down
Loading