News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Improvement suggestions for some core functions

Started by man.of.earth, October 09, 2018, 21:37:02 PM

Previous topic - Next topic

man.of.earth

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 if($lightbox){:

$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 } else {

$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 if(substr($file,0,7)=='/images')$file=substr($file,1,strlen($file)-1);
before
$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)

Studio 42

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 ?


man.of.earth

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.

man.of.earth

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  :).

Studio 42

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.