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

Refactor: Update getimagesize() Function to Accept Image Paths Instead of URLs #226

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ArchanRD
Copy link
Contributor

Fixes

Fixes #187 by @brylie

Description

The function getimagesize() takes image as parameter and returns the image size i.e height and width. In this PR, we replace image url with image path to fix this issue.

Technical details

This issue doesn't occur everytime, however in some cases when a website:

  • Has basic auth
  • Timesout while loading the image

the image may not be accessible through the image url, hence calling the getimagesize() with image url may not work always. Also everytime getimagesize() function is called, the server sends a request to load the image increasing execution time. Hence I've chosen to pass image path instead of image url in getimagesize(). This solution handles the above 2 cases as well as addresses the performace issue of the code.

Tests

As described above, this situation doesn't always occur, so it may be difficult to test.

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the default branch of the repository (main or master).
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no
    visible errors.

Developer Certificate of Origin

For the purposes of this DCO, "license" is equivalent to "license or public domain dedication," and "open source license" is equivalent to "open content license or public domain dedication."

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@ArchanRD ArchanRD requested review from a team as code owners March 10, 2024 14:04
@ArchanRD ArchanRD requested review from Shafiya-Heena, possumbilities and Cronus1007 and removed request for a team March 10, 2024 14:04
@cc-open-source-bot cc-open-source-bot added this to Code Review in Active Sprint Mar 10, 2024
@possumbilities
Copy link
Contributor

possumbilities commented Mar 14, 2024

@ArchanRD Thank you for this contribution!

Maybe I'm missing something, but why not make the change further up the chain of functionality like here, so that the image_url when passed to the function later behaves normally rather than relying on the function to further modify/cleanup the url?

@ArchanRD
Copy link
Contributor Author

Hey @possumbilities, I tried to do that but I found that the image_url is comming from license in wp_options. If I change the update_site_option call here to add a new key image_path, then anyone updating to this plugin will break it's functionality, since they won't have image_path key in the DB. We will likely require a small migration change for that solution to work. Since that would become more complicated solution I thought we should go with this simpler approach.

@ArchanRD
Copy link
Contributor Author

I have simplified the implementation a bit, so it's essentially a one liner change ( but GH is showing it a bit differently though ).

@@ -1125,10 +1125,11 @@ public function license_html_rdfa( $deed_url, $license_name, $image_url,
$title_work, $is_singular, $attribute_url,
$attribute_text, $source_work_url,
$extra_permissions_url, $additional_attribution_txt, $title, $title_url, $author, $author_url ) {
list($img_width, $img_height) = getimagesize( $image_url );
$lazy = function_exists('wp_lazy_loading_enabled') && wp_lazy_loading_enabled('img', 'license_html_rdfa');
$image_path = str_replace( CCPLUGIN__URL, CCPLUGIN__DIR, $image_url );
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe the two global variables here should be properly escaped. The value of $image_url is already escaped in its definition further up in the file, but the use of these two globals here doesn't provide them as escaped values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Active Sprint
  
Code Review
Development

Successfully merging this pull request may close these issues.

Warning: getimagesize: failed to open stream
2 participants