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

[4.0] Select image/audio/video/document file from Media Manager #34634

Merged
merged 58 commits into from
Jul 2, 2021

Conversation

dgrammatiko
Copy link
Contributor

@dgrammatiko dgrammatiko commented Jun 26, 2021

Pull Request for Issue #32642 and https://www.facebook.com/groups/joomlanospam/posts/10157777796480997/?__cft__[0]=AZXC8G44TJLPO0QeEbytZwSVaZX2YpNFHjOUcx1xUqyJjBUZGqgh763LWT-Lx2xKyvJfIm-LQO6wUquCrqneOLqSAlx3AOpRDAxnMrliJHTTK1AIkT4Mh-BVfJCJjMVFEyDYelefuWE8UMA3X6_-XUFRasmSPT8VNhUVlOln0Ujj4LCrwnBYH_QLfColkn2QEkk&__tn__=%2CO%2CP-R

Apparently, the Joomla community finds it totally fine to use software that is based on a javascript that's 2 major versions behind. It's not fine for me thus the PR...

Summary of Changes

  • Reworked the media select Javascript
  • Changed the one field for all the supported extensions to multiple fileds in Media Manager (this needs to be communicated as it's a B/C break, and also it needs updates to the sql files)
  • Reworked/added file types in the vue App (the files need to enable the preview)

Please extract this
Archive.zip
to the images directory, or use your own mp3/mp4/pdf files

Testing Instructions

  • Apply the PR or downlad the installable from github

  • If you're applying the PR then go to the Media manager options and

  • Make sure the legal mime types are: image/jpeg,image/gif,image/png,image/bmp,audio/mp3,video/mp4,application/msword,application/excel,application/pdf,application/powerpoint,text/plain,application/x-zip

  • the video extensions are mp4

  • the audio extensions are mp3

  • the document extensions are odg,odp,ods,odt,pdf,png,ppt,txt,xcf,xls,csv

  • and finally the images extensions are: bmp,gif,jpg,jpeg,png,ico This is IMPORTANT

  • Go to tinyMCE and:

  • Select the image from the CMS Content dropdown

  • Then select the video file, click on the controls and embed checkboxes, change the width and height and then click select image at the bottom of the modal

  • Press couple returns type Video Link and select the text you just wrote

  • Then select the video file, without selecting the controls and embed checkboxes (width and height is irrelevant here) and then click select image at the bottom of the modal

  • Check the produced HTML by clicking the toggle button under the editor

  • Select the image from the CMS Content dropdown

  • Then select the audio file, click on the controls and embed checkboxes and then click select image at the bottom of the modal

  • Press couple returns type Audio Link and select the text you just wrote

  • Then select the audio file, without selecting the controls and embed checkboxes and then click select image at the bottom of the modal

  • Check the produced HTML by clicking the toggle button under the editor

  • Select the image from the CMS Content dropdown

  • Then select the PDF file, click on the embed checkboxe change the width and height and then click select image at the bottom of the modal

  • Press couple returns type PDF Link and select the text you just wrote

  • Then select the PDF file, without selecting the embed checkboxe and then click select image at the bottom of the modal

  • Check the produced HTML by clicking the toggle button under the editor

  • your final html should look like:

<p><video controls="controls" width="800" height="600">
<source src="/images/flower.mp4" type="video/mp4" /></video></p>
<p> </p>
<p><a href="images/flower.mp4" download="">Video Link</a></p>
<p> </p>
<p><audio src="images/t-rex-roar.mp3" controls="controls"></audio></p>
<p> </p>
<p><a href="images/t-rex-roar.mp3" download="">Audio Link</a></p>
<p> </p>
<p><object data="images/core_xy_exploded_infographic1.pdf" type="application/pdf" width="800" height="600">
You don't have a pdf plugin, but you can <a download="" href="/images/core_xy_exploded_infographic1.pdf"> download the pdf file.</a></object></p>
<p> </p>
<p><a href="images/core_xy_exploded_infographic1.pdf" download="">PDF Link</a></p>
  • Check that the insertion of an image is still ok

  • Check that the media FIELDS (intro/fulltext images) are still functional

  • Finally save the article and visit it in the front end. That's it.

  • Edit the definition of the intro image

    <field
    name="image_intro"
    type="media"
    label="COM_CONTENT_FIELD_INTRO_LABEL"
    />
    by adding types="images,audios"

  • Test the field, you should be able now to select images and audio files, also try to upload an unsupported file (eg video and pdf)

  • Repeat with different combinations types="images,audios,videos,documents"

Actual result BEFORE applying this Pull Request

Impossible to select/embed anything other than an image file

Expected result AFTER applying this Pull Request

It's ok to select/embed audio, video, document files
Screenshot 2021-06-26 at 23 04 08
Screenshot 2021-06-26 at 23 04 38
Screenshot 2021-06-26 at 23 04 28
Screenshot 2021-06-26 at 23 04 18

Front end:
j4 local_index php_teststststtsts

Documentation Changes Required

There are few todos that I skipped here:

  • sql files
  • remove renamed files
  • rename the xtd button image to media as the image is confusing now

@wilsonge @laoneo any feedback?

@joomla-cms-bot joomla-cms-bot added Language Change This is for Translators NPM Resource Changed This Pull Request can't be tested by Patchtester PR-4.0-dev labels Jun 26, 2021
@brianteeman
Copy link
Contributor

looking forward to testing this tomorrow

@brianteeman
Copy link
Contributor

Tested using your supplied files. Only the pdf uploads. The mp3 and mp4 give a generic cant be uploaded message.
Tested a larger 5mb mp4 and it doesnt appear to do anything. No upload, no error, nothing
Sometimes after one of the failures the session is killed and you have to log in again

@brianteeman
Copy link
Contributor

The problem was in your test instructions. Better to clear the existing values in the options and then save in order to get the defaults. If it had been customised at all it would fail

@brianteeman
Copy link
Contributor

Click on a pdf file and then click on the three dots
Check the console

media-manager.min.js?6a2a37958931d4cd9934c0d049a970a8:1 Uncaught (in promise) TypeError: Cannot read property 'focus' of undefined
    at Proxy.<anonymous> (media-manager.min.js?6a2a37958931d4cd9934c0d049a970a8:1)

@brianteeman
Copy link
Contributor

mp4 files have previews but there is no preview icon (you need to double click on the file to see the preview)

pdf files do not have previews but you can still double click on the file and the previous item is displayed

@brianteeman
Copy link
Contributor

If you dont check the box "Use native elements" before inserting then nothing added to the article

@richard67
Copy link
Member

For files and folder deletion on update with script.php you can leave it to @wilsonge and me. One of us will run the tool to generate the lists of files and folders when this PR has been merged and before the next release after that. So it does not need to be done in this PR. But if you want to do it here because you wanna make it right, I can help later.

For SQL scripts we have to decide how much we want to touch the media manager options on update. Since it will be at least risky and hacky trying to add single values to the json, we might have to completely replace the params so people would lose their settings on update if they have changed some. I can help with making the update SQL but not with
making the decision if we want that or not.

@brianteeman
Copy link
Contributor

@richard67 whichever is decided on the sql there should be a postinstallation message. either saying the settings have been reset to the defaults or saying that you can update the settings to add support for pdf, etc

@richard67
Copy link
Member

@richard67 whichever is decided on the sql there should be a postinstallation message. either saying the settings have been reset to the defaults or saying that you can update the settings to add support for pdf, etc

Yeah, that makes sense. Personally I'd prefer the "We don't touch the settings and let the postinstall message tell people that they can update their settings to add support for PDF and so on" approach.

It can be that we have already an update SQL touching these parameters when updating from 3.10. If this is the case, we could modify that one to set them right. I have to check if there is one.

@brianteeman
Copy link
Contributor

IIRC we discussed this when I added webp support (or tried to)

@richard67
Copy link
Member

I've just checked: It seems there is no update SQL script where we already touch the params of the com_media extension. So there is no need to modify such a script.

@dgrammatiko
Copy link
Contributor Author

dgrammatiko commented Jun 27, 2021

If you dont check the box "Use native elements" before inserting then nothing added to the article

Fixed, there are 3 modes: embed, insert asa link with predefined text, insert as a link with selected text from the editor (the 2nd was missing)

mp4 files have previews but there is no preview icon (you need to double click on the file to see the preview)

The preview needs refactoring so it can handle all the file types, also I thought that removing the magnifying glass I removed the preview but I totally forgot the double click FIXED

Click on a pdf file and then click on the three dots
Check the console

Some side effect from copy/pasting, investigating FIXED

The problem was in your test instructions. Better to clear the existing values in the options and then save in order to get the defaults. If it had been customised at all it would fail

Will update the instructions for existing installations

A comment about SQL files and B/C:

  • Since J4 supports multiple local adapters the images adapter should be sniffed on update time and the default directory for media files should be media-uploads or something similar. Having audio, video or other files under a directory images is weird but maybe I'm heretic here. My point is that this can be done in a non B/C breaking way with a post install script for updates. Also doing it this way means that we get rid of runtime code that we have right now to do the adjustment, sounds more solid solution to me anyways.
    Anyways I'm ok whatever the decision is here, post install message or not or whatever...

@richard67
Copy link
Member

A comment about SQL files and B/C:

* Since J4 supports multiple local adapters the `images` adapter should be sniffed on `update` time and the default directory for media files should be `media-uploads` or something similar. Having audio, video or other files under a directory `images` is weird but maybe I'm heretic here. My point is that this can be done in a non B/C breaking way with a post install script for updates. Also doing it this way means that we get rid of runtime code that we have right now to do the adjustment, sounds more solid solution to me anyways.
  Anyways I'm ok whatever the decision is here, post install message or not or whatever...

@dgrammatiko It would be good to have that post install script or procedure. But that would maybe be better a new routine in the script.php than an update SQL script. If necessary @joomdonation could have a look on it.

@brianteeman
Copy link
Contributor

Preview of video now working correctly

Preview of pdf - almost - the preview opens but its black. Clicking on rotate makes it appear (maybe that will give a clue)

Audio file will not upload

@dgrammatiko
Copy link
Contributor Author

Audio file will not upload

Make sure the legal mime types are: image/jpeg,image/gif,image/png,image/bmp,audio/mp3,video/mp4,application/msword,application/excel,application/pdf,application/powerpoint,text/plain,application/x-zip

@brianteeman
Copy link
Contributor

Checked that twice before posting

image/jpeg,image/gif,image/png,image/bmp,audio/mp3,video/mp4,application/msword,application/excel,application/pdf,application/powerpoint,text/plain,application/x-zip

@brianteeman
Copy link
Contributor

Article intro and full image
This works when selecting an image (as before)
However you can select a non image file - instead of some type of error message saying "this isnt an image etc" it just silently returns

@dgrammatiko
Copy link
Contributor Author

it just silently returns

Yes, I couldn't decide what would be the best scenario for this case so I silently ignored anything non-image. This might need an alert or something similar.

Checked that twice before posting

There's something fishy as the tests are also failing for no obvious reason

@richard67
Copy link
Member

@dgrammatiko Here the screenshot from drone from system tests: https://ci.joomla.org/artifacts/joomla/joomla-cms/4.0-dev/34634/system-tests/45401/MediaListCest.showsDefaultFilesAndFolders.mysql.fail.png

It says "syntax error, unexpected ')'".

Here the part of the log with the test where it fails:

MediaListCest: Test that it shows the joomla default media files and folders.
89s
325Signature: MediaListCest:showsDefaultFilesAndFolders
89s
326Test: tests/Codeception/acceptance/administrator/components/com_media/MediaListCest.php:showsDefaultFilesAndFolders
89s
327Scenario --
89s
328 I do administrator login 
89s
329  [Cookies] [{"name":"0cd014c79b960a69d3b33ac5245b0833","value":"2c944nm5pml9uatbrlgsjngk43","path":"/","domain":"localhost","expiry":1624893164,"secure":false,"httpOnly":false}]
89s
330  [Snapshot] Restored "ci-admin" session snapshot
89s
331 I create directory "images/test-dir"
89s
332   I get suite configuration 
89s
333   I get suite configuration 
89s
334 Created /tests/www/test-install/images/test-dir
89s
335 I am on page "administrator/index.php?option=com_media&..."
89s
336  [GET] http://localhost/test-install/administrator/index.php?option=com_media&path=local-images:/
89s
337 I wait for media loaded 
90s
338   I wait for element {"class":"media-loader"},3
90s
339   I wait for element not visible {"class":"media-loader"}
90s
340   I wait 1
90s
341 I see contents ["banners","headers","sampledata","joomla_black.png","powered_by.png"]
91s
342   I see element {"class":"media-browser-item"}
91s
343 I delete directory "images/test-dir"
91s
344   I get suite configuration 
91s
345 Deleted /tests/www/test-install/images/test-dir
91s
346 I execute js "window.sessionStorage.removeItem("joomla...."
91s
347  Screenshot and page source were saved into '/********/src/tests/Codeception/_output/' dir
91s
348 FAIL 

Does that help?

@dgrammatiko
Copy link
Contributor Author

Does that help?

Yup, turns out PHP is far away from becoming a functional programming language...

@wilsonge
Copy link
Contributor

wilsonge commented Jul 2, 2021

This seems to important to not merge right now given it has b/c implications. Although it's not great given our point of RC. Thankyou so much @dgrammatiko for your hard work on this!

@brianteeman
Copy link
Contributor

woohoo!!!

@dgrammatiko dgrammatiko deleted the —media-select-v2—4.0-dev branch July 2, 2021 08:57
@dgrammatiko
Copy link
Contributor Author

Thanks

@wilsonge the B/C break is the change of some of the com_media params and to be honest here even what I did here is not perfect. An ideal solution is to have a data structure like

{
  supported: [
    {
      extension: 'png',
      mine: 'image/png',
      preview: true,
      upload: true
    }
  ]
}

That will allow to remove the hardcoded preview extensions in the com_media app (vue) and also if done right (subforms?) it will be easier in the backend (eg have a pool that users enable/disable, instead of typing tings)

JFIELD_MEDIA_WIDTH_LABEL="Width"
JFIELD_MEDIA_TITLE_LABEL="Title"
; Do not translate the text between the {}
JFIELD_MEDIA_UNSUPPORTED="You don't have a {extension} plugin, but you can {tag} download the {extension} file.</a>"
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that it is combined. But is everything true in this line? Confused by the end of the line.

@dgrammatiko

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, yes ... where does that closing anchor tag belong to?

Copy link
Contributor

Choose a reason for hiding this comment

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

There is also the same ending in another line. Copy / paste

Copy link
Member

Choose a reason for hiding this comment

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

@Kostelano Maybe you can make an issue, or if you have more time make a PR to fix it? It would need to get that text shown and then check the original markup. Browser inspection tools might repair the invalid markup and so not show any mistake, so it could be tricky.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The first part is here

${Joomla.Text._('JFIELD_MEDIA_UNSUPPORTED').replace('{tag}', `<a download href="${Joomla.selectedMediaFile.url}">`).replace(/{extension}/g, Joomla.selectedMediaFile.extension)}

Copy link
Member

Choose a reason for hiding this comment

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

I see ... not nice, but ok ... thanks for reporting back.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just realized that the closing tag shouldn't be in the ini file. Well, my bad 😞

Copy link
Member

@richard67 richard67 Jul 5, 2021

Choose a reason for hiding this comment

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

You can make a PR ... but it should be soon because there might be language freeze for J4 in near future.

<div class="media-browser-item-preview">
<div class="file-background">
<div class="file-icon">
<span class="fas fa-file-pdf" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please improve this to reflect their respective icons instead of a PDF icon for all document types? Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What would be the appropriate icon? Also you can PR the change yourself nothing too fancy here 😉

Copy link
Contributor

Choose a reason for hiding this comment

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

pdf icon for .pdf
word icon for .doc
excel icon for .xls
otherwise default to generic file icon for the other extensions

Copy link
Member

Choose a reason for hiding this comment

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

Don’t forget docx, docm, xlsx and xlsm

Copy link
Contributor

Choose a reason for hiding this comment

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

You can do this in pure css so that the markup doesnt have to contain everything. See this example https://gschoppe.com/uncategorized/add-auto-sensing-file-type-icons-to-lists-of-downloads-with-fontawesome-and-css/

Copy link
Contributor Author

@dgrammatiko dgrammatiko Jan 16, 2022

Choose a reason for hiding this comment

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

So change line 10 to <span v-bind:class="getFileClass" />
and add after line 44 (after the data(){} ):

  computed: {
    /* Get the hashed URL */
    getFileClass: (item) => {
      switch (item.mime_type) {
        case 'application/pdf':
          return 'fas fa-file-pdf';
        case 'application/msword':
        case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
          return 'fas fa-file-word';
        case 'application/vnd.ms-excel':
        case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
          return 'fas fa-file-excel';
        case 'application/vnd.ms-powerpoint':
        case 'application/vnd.openxmlformats-officedocument.presentationml.presentation':
          return 'fas fa-file-powerpoint';
        default:
          return 'fas fa-file';
      }
    },
  },

Modify it to your taste

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can do this in pure css so that the markup doesnt have to contain everything.

Actually, on the web, the extensions are totally FOOBAR. The only way to tell what a type of a file really is, is by checking the mime type. The mime type is not available to the HTML/CSS unless the application actually passes it either as a class or a data attribute.

What I'm saying is that you can have a totally valid PDF (or whatever) without any extension. Actually, Joomla should never ever do anything based on the extensions as this is a huge SECURITY risk.

/rant

Copy link
Contributor

Choose a reason for hiding this comment

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

and add after line 44 (after the data(){} ):

Should it be after line 177 in the same file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

brianteeman added a commit to brianteeman/joomla-cms that referenced this pull request Sep 23, 2023
simple pr to correct an error from joomla#34634 where png was added twice
@brianteeman brianteeman mentioned this pull request Sep 23, 2023
4 tasks
laoneo pushed a commit that referenced this pull request Oct 28, 2023
* [4.3] Remove duplicate png

simple pr to correct an error from #34634 where png was added twice

* Update base.sql

* Update base.sql
heelc29 added a commit to heelc29/joomla that referenced this pull request Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Language Change This is for Translators NPM Resource Changed This Pull Request can't be tested by Patchtester
Projects
None yet
Development

Successfully merging this pull request may close these issues.