Author Topic: Improvement suggestions for some core functions  (Read 141 times)

arcturus

  • Beginner
  • *
  • Posts: 12
  • VirtueMart Version: 3.4.2
Improvement suggestions for some core functions
« on: October 09, 2018, 21:37:02 pm »
Hello,

A lot of SEO validators require the width and height of an image to be defined. So, in this sense, I suggest adding this option to
/administrator/components/com_virtuemart/helpers/mediahandler.php (function displayIt() ).

Also, I have noticed that relative images which's src attribute begins without the slash ("/") (e.g. <img src="images/..." etc./>) are not displayed at all in the VM backend.

In this sense, I would suggest some slight modifications that correct those two problems mentioned above (adding the width and height attributes, and making sure the image relative src begins with slash, to be displayed well in the backend):

in
/administrator/components/com_virtuemart/helpers/mediahandler.php
- line 604, after
Code: [Select]
if($lightbox){:

Code: [Select]
$urlfull=$root.$file_url;
if( (substr($urlfull,0,4) != "http") and (substr($urlfull,0,1) != "/")) $urlfull = '/' . $urlfull;
$size = getimagesize($_SERVER['DOCUMENT_ROOT'].'/'.$file_url);
$image = '<img src="' . $urlfull . '" alt="' . $file_alt . '" title="' . $file_alt . '" ' . $args . ' width="'.$size[0].'" height="'.$size[1].'"/>';

- line 627 after
Code: [Select]
} else {
Code: [Select]
$size = getimagesize($_SERVER['DOCUMENT_ROOT'].'/'.$file_url);#added
if((substr($file_url,0,4)!="http")and(substr($file_url,0,1)!="/"))$file_url = '/'.$file_url;
return '<img src="' . $file_url . '" alt="' . $file_alt . '" title="' . $file_alt . '" ' . $args . ' width="'.$size[0].'" height="'.$size[1].'"/>'.$desc;

I also noticed that sometimes the images with relative paths throw an error while being embedded in PDF (getimagesize and other image functions need the correct path of the image - absolute path, or relative path to the tcpdf_images.php file), so I corrected that in tcpdf_images.php:

- line 170
add
Code: [Select]
if(substr($file,0,7)=='/images')$file=substr($file,1,strlen($file)-1);before
Code: [Select]
$a = getimagesize($file);in order that the image path to not have the leading slash, for being able to be embedded into the frontend PDF.

Maybe an alternative to displaying images correctly in the backend (those which's path begins in frontend, as it were, e.g. "images/virtuemart_store/etc...") would be to modify the backend VM template.

Cheers,
George Acu
https://www.proxima-mundi.ro

Now I'm using Joomla 3.8.12 and VM 3.4.2 (php 7.1)
Cheers,
George
https://www.proxima-mundi.ro

Now I'm using Joomla 3.8.13 and VM 3.4.2 (php 7.1)

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 3389
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 &amp; 3.0.x.y
Re: Improvement suggestions for some core functions
« Reply #1 on: October 10, 2018, 00:15:17 am »
You proposal need some changes, you should use Joomla coding & definitions to prevent problems in some servers(windows for eg.).
$_SERVER['DOCUMENT_ROOT'] is JPATH_ROOT
full Url can be forced in the displayIt function i think ?
Forcing width and height !!?!?
This break many responsive templates i think. Have you do some advanced test ?


arcturus

  • Beginner
  • *
  • Posts: 12
  • VirtueMart Version: 3.4.2
Re: Improvement suggestions for some core functions
« Reply #2 on: October 10, 2018, 01:58:34 am »
Actually I did not do extensive tests. This whole thing started from seeing that the VM images are not displayed correctly in backend (products, categories etc.), since those images are located in frontend and their relative src begins without slash.
I guess the backend VM template would have to undergo some changes, in order to display correctly the links/images that are actually located in frontend.

I think relative links are preferable, because they also save HTML "space"/bytes (no need to repeat the main domain at all in the HTML code), and the website containing them can be moved etc. (there are many benefits).

In regards to "width" and "height" attributes for images, they are meant only for SEO reasons, as the sizes specified in the CSS for those images (in responsive templates) override those and would not trouble responsive templates.
Cheers,
George
https://www.proxima-mundi.ro

Now I'm using Joomla 3.8.13 and VM 3.4.2 (php 7.1)

arcturus

  • Beginner
  • *
  • Posts: 12
  • VirtueMart Version: 3.4.2
Re: Improvement suggestions for some core functions
« Reply #3 on: October 10, 2018, 09:37:25 am »
Maybe the displayIt() function would do some check first: if the images are displayed in the backend, it should put a slash before the relative src of the images, and if not - not  :).
Cheers,
George
https://www.proxima-mundi.ro

Now I'm using Joomla 3.8.13 and VM 3.4.2 (php 7.1)

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 3389
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 &amp; 3.0.x.y
Re: Improvement suggestions for some core functions
« Reply #4 on: October 10, 2018, 11:32:48 am »
The slash must always be here in the relative link, so a developer may have made a mistake.
It's only the method that I do not agree with.