Last active
May 7, 2018 06:40
-
-
Save arudmin/f48e5aa1252eba5a45dcc99978eb13c4 to your computer and use it in GitHub Desktop.
images_as_url.ocmod.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<modification> | |
<name>Images as URL for OpenCart 2.x</name> | |
<code>00000002</code> | |
<version>0.78</version> | |
<author>Arudmin</author> | |
<link>https://gist.github.com/arudmin/</link> | |
<file path="catalog/model/tool/image.php"> | |
<operation> | |
<search><![CDATA[if (!is_file(DIR_IMAGE . $filename)) {]]></search> | |
<add position="before"><![CDATA[/*]]></add> | |
</operation> | |
<operation> | |
<search><![CDATA[$extension = pathinfo($filename, PATHINFO_EXTENSION);]]></search> | |
<add position="before"><![CDATA[*/ | |
if (!is_file(DIR_IMAGE . $filename)) { | |
if (filter_var($filename, FILTER_VALIDATE_URL)) { | |
$image_dir = 'temp'; | |
$image_name = basename($filename); | |
$image_path = 'catalog/' . $image_dir . '/' . $image_name; | |
if (!is_file(DIR_IMAGE . $image_path)) { | |
if (!is_dir(dirname(DIR_IMAGE . $image_path))){ | |
@mkdir(dirname(DIR_IMAGE . $image_path), 0700); | |
} | |
$filename = file_put_contents(DIR_IMAGE . $image_path, file_get_contents($filename)) ? $image_path : 'no_image.jpg'; | |
} else { | |
$filename = $image_path; | |
} | |
} else { | |
if (is_file(DIR_IMAGE . 'no_image.jpg')) { | |
$filename = 'no_image.jpg'; | |
} elseif (is_file(DIR_IMAGE . 'no_image.png')) { | |
$filename = 'no_image.png'; | |
} else { | |
return; | |
} | |
} | |
} | |
]]></add> | |
</operation> | |
</file> | |
</modification> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment