Skip to content

Instantly share code, notes, and snippets.

@arudmin
Last active May 7, 2018 06:40
Show Gist options
  • Save arudmin/f48e5aa1252eba5a45dcc99978eb13c4 to your computer and use it in GitHub Desktop.
Save arudmin/f48e5aa1252eba5a45dcc99978eb13c4 to your computer and use it in GitHub Desktop.
images_as_url.ocmod.xml
<?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