Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature attachment details modal #202

Conversation

Code-BeautifulWeb
Copy link
Contributor

@bradvin Please have a look on recent Commits for Image Attachment Modal feature!

@bradvin bradvin changed the base branch from master to feature/new-attachment-modal August 20, 2022 07:00
foogallery.php Outdated Show resolved Hide resolved
foogallery.php Outdated Show resolved Hide resolved
@bradvin
Copy link
Member

bradvin commented Aug 20, 2022

The PHP logic should be in a separate PHP class, not in foogallery.php. Example : includes/admin/class-attachment-modal.php.

The CSS can be moved into css/admin-foogallery.css

I want this feature to be able to be turned on/off in settings, so that if there are issues with the modal logic, the user can revert back to how it works at the moment with an admin setting. This will mean a check in the JS to allow the old way of working and the new to also work based on a setting.

@Code-BeautifulWeb
Copy link
Contributor Author

@bradvin The Feedback for this PR is attended and pushed to the git though commit "PR 202 Changes", please have a look!

$foogallery_button_url = get_post_meta( $img_id, '_foogallery_button_url', true );
$foogallery_product = get_post_meta( $img_id, '_foogallery_product', true );
$panning = '';
$progress = get_post_meta( $gallery_id, FOOGALLERY_META_WATERMARK_PROGRESS, true );
$category_taxonomy = 'foogallery_attachment_category';
$tag_taxonomy = 'foogallery_attachment_tag';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather use constant FOOGALLERY_ATTACHMENT_TAXONOMY_TAG

@bradvin
Copy link
Member

bradvin commented Aug 26, 2022

There is a lot of logic in function open_foogallery_image_edit_modal_ajax. Both for setting variables and for displaying the tabs.

Break this up into separate private functions for each tab. 1 function to set the variables and another for displaying the tab. This might mean you would need to set all the variables in a class level private array. And then in the display methods, you pull data from the array. (I hope this makes sense?)

This way, the code is neater and easier to maintain. Also, you can also conditionally call the functions for tabs that are in pro features (taxonomies, exif, woocommerce etc). I am thinking that all the tabs for free features are included in this file, and then a custom action hook is called. Then for example, specific logic for EXIF can be moved to the pro exif class file. Similar for taxonomies etc. (for now, keep all the pro functions in this file separated out, and then move them to their final destination files in a later commit.)

@bradvin
Copy link
Member

bradvin commented Aug 26, 2022

The modal takes a while to load (due to all the data it is fetching etc) witch is understandable.

Rather show a blank modal immediately after clicking on the "i" for a thumb. And show a loading spinner while it is loading everything behind the scenes.

foogallery.php Outdated
foreach ( $img_tags as $tag ) {
$selected_tags[] = $tag->term_id;
}
$categories = $terms = get_terms( array(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why also set $terms?

foogallery.php Outdated Show resolved Hide resolved
'foogallery_crop_pos_val' => 'center,center',
'foogallery_override_thumbnail' => '',
);

public function __construct() {
add_action( 'wp_ajax_open_foogallery_image_edit_modal', array( $this, 'open_foogallery_image_edit_modal_ajax' ) );
add_action( 'admin_footer', array( $this, 'foogallery_image_editor_modal' ) );
add_filter( 'foogallery_attachment_custom_fields', array( $this, 'foogallery_add_override_thumbnail_field' ) );
add_action( 'wp_ajax_foogallery_save_modal_metadata', array( $this, 'foogallery_save_modal_metadata' ) );
Copy link
Member

@bradvin bradvin Sep 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename function foogallery_save_modal_metadata to ajax_save_modal

'foogallery_crop_pos_val' => 'center,center',
'foogallery_override_thumbnail' => '',
);

public function __construct() {
add_action( 'wp_ajax_open_foogallery_image_edit_modal', array( $this, 'open_foogallery_image_edit_modal_ajax' ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename function open_foogallery_image_edit_modal_ajax to ajax_open_modal

@@ -410,7 +138,7 @@ public function foogallery_add_override_thumbnail_field( $fields ) {
}

public function foogallery_save_modal_metadata() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function is not secure. It needs a call to wp_verify_nonce

wp_die();
}

private function set_image_modal_vars( $args = array() ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function needs to be split into multiple functions, based on the separate tabs, like it was done for the tab content.

Use a filter to hook into and set the variables for the different tabs. Something like:
$this->img_modal = apply_filters( 'foogallery_attachment_modal_data', $this->img_modal, $args );

<?php do_action( 'foogallery_img_modal_tabs_view' ); ?>
</div>
<div class="tab-panels">
<?php do_action( 'foogallery_img_modal_tab_content', $_POST ); ?>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pass $this->img_modal into the action rather than $_POST

<?php }

public function foogallery_img_modal_tab_content_main( $args = array() ) {
$img_modal = $this->set_image_modal_vars( $args );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if $this->img_modal is passed into this function, then you do not need to do this.

<section id="foogallery-panel-main" class="tab-panel active" data-nonce="<?php echo $this->img_modal['nonce'];?>">
<div class="settings">
<span class="setting" data-setting="title">
<label for="attachment-details-two-column-title" class="name">Title</label>
Copy link
Member

@bradvin bradvin Sep 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use i8ln functions for all text. For example in this case:
<?php _e('Title', 'foogallery'); ?>

</select>
</span>
<span class="setting" data-setting="custom_class">
<label for="attachments-foogallery-custom-class" class="name">Custom Class</label>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please replace all text with i8ln functions. refer to the coding standards

@bradvin
Copy link
Member

bradvin commented Sep 3, 2022

Some changes that are needed, after review. I will add a comment for each one

Save refactor: saving the modal data is done at different times at the moment (when input's change etc). Include a 'Save Attachment Details' button at bottom right corner of the modal. When the button is clicked, a spinner must be shown next to the button; all the data from all tabs can be scraped into an array; all data sent to the server. The save function can call a do_action and then similar to how tab display is split into functions, the saving can also be split into different functions per tab.

@bradvin
Copy link
Member

bradvin commented Sep 3, 2022

Change the left image section:

  • the attachment thumb is currently shown. Rather show the medium size image for the attachment, so the true aspect ratio can be seen.
  • include a button next to 'Edit Image' for 'Open Full Size Image' which opens the fullsize image in a new tab
  • Move the info under 'Info' tab to rather be above the image:
    image

@bradvin
Copy link
Member

bradvin commented Sep 3, 2022

The selected tab should not have a line underneath:
image

@bradvin
Copy link
Member

bradvin commented Sep 3, 2022

Generate Watermark Image - at the moment, this generates ALL watermarks for all the attachments in the gallery. This should rather only generate the watermark image for the current image we are viewing the modal for.

A new ajax function should be added to generate the watermark. Within this function, you can do something like this:
$protection = new FooGallery_Pro_Protection(); $protection->generate_watermark( $attachment_id );

Please note I had to change the FooGallery_Pro_Protection class to make the generate_watermark public, so please pull code (ade284c)

After the watermark is successfully generated, then show the image

@bradvin
Copy link
Member

bradvin commented Sep 3, 2022

EXIF data is being saved to $image_meta['image_data'] but it should be saved to $image_meta['image_meta']

so that it can be picked up by the EXIF feature. Look in class-foogallery-pro-exif.php

@bradvin
Copy link
Member

bradvin commented Sep 3, 2022

Alternate Thumbnail changes:

  • need a button to clear the Alternate Thumbnail if it is previously been selected.
  • after selecting an alternate thumbnail, the alternate thumbnail preview section needs to be shown (so it can be cleared if required)

@bradvin
Copy link
Member

bradvin commented Sep 3, 2022

Add the ability to view attachment details for the next/prev attachment within the gallery. This is done on the attachment edit modal built into WP:

image

The next / previous attachment ID will need to be calculated and passed to the modal so that these buttons can work

@bradvin bradvin merged commit 3d4b2e7 into fooplugins:feature/new-attachment-modal Sep 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants