<?xml version="1.0" encoding="utf-8"?>
<modification>
    <name>Journal2</name>
    <code>default</code>
    <version>1.0</version>
    <author>DigitalAtelier</author>
    <link>http://journal.digital-atelier.com</link>

    <!--

        Loader fix for accessing journal2 object from $this

    -->

    <file path="system/engine/loader.php">
        <operation>
            <search><![CDATA[public function __construct($registry) {]]></search>
            <add position="before">
                /* Journal2 modification */
                public function __get($key) {
                    return $this->registry->get($key);
                }

                public function __set($key, $value) {
                    $this->registry->set($key, $value);
                }
                /* End of Journal2 modification */
            </add>
        </operation>
    </file>

    <!--

        Admin Shortcut menu

    -->

    <file path="admin/controller/common/menu.php">
        <operation>
            <search><![CDATA[$this->load->language('common/menu');]]></search>
            <add position="after"><![CDATA[
                $this->load->model('setting/extension');
                $extensions = $this->model_setting_extension->getInstalled('module');
                if (in_array('journal2', $extensions)) {
                    $data['journal2'] = $this->url->link('module/journal2', 'token=' . $this->session->data['token'], 'SSL');
                    $data['journal2_clear_cache'] = $this->url->link('module/journal2/clear_cache', 'token=' . $this->session->data['token'], 'SSL');
                    $this->session->data['j2_redirect'] = isset($this->request->get['route']) ? $this->request->get['route'] : null;
                } else {
                    $data['journal2'] = '';
                }
            ]]></add>
        </operation>
    </file>

    <file path="admin/view/template/common/menu.tpl">
        <operation>
            <search><![CDATA[<li><a class="parent"><?php echo $text_marketing; ?></a>]]></search>
            <add position="after" offset="7"><![CDATA[
                <?php if ($journal2): ?>
                <li id="journal2-menu"><a class="parent" href="<?php echo $journal2; ?>"><img class="fa fw" style="margin-left: 4px; padding-right: 6px; margin-top:-3px;" src="view/journal2/css/icons/j.png" alt=""/><span>Journal</span></a>
                    <ul>
                        <li><a href="<?php echo $journal2; ?>">Dashboard</a></li>
                        <li><a href="<?php echo $journal2_clear_cache; ?>">Clear Cache</a></li>
                    </ul>
                </li>
                <?php endif; ?>
            ]]></add>
        </operation>
    </file>

    <!--

        Include Journal Newsletter subscribers when sending emails

    -->

    <file path="admin/controller/marketing/contact.php">
        <operation>
            <search><![CDATA[$this->load->model('sale/customer');]]></search>
            <add position="after"><![CDATA[$this->load->model('journal2/newsletter');]]></add>
        </operation>

        <operation>
            <search index="0"><![CDATA[$email_total = $this->model_sale_customer->getTotalCustomers($customer_data);]]></search>
            <add position="replace"><![CDATA[$email_total = $this->model_journal2_newsletter->getTotalSubscribers();]]></add>
        </operation>

        <operation>
            <search index="0"><![CDATA[$results = $this->model_sale_customer->getCustomers($customer_data);]]></search>
            <add position="replace"><![CDATA[$results = $this->model_journal2_newsletter->getSubscribers($customer_data);]]></add>
        </operation>
    </file>

    <!--

        Backup / Restore fix

    -->

    <file path="admin/controller/tool/backup.php">
        <operation>
            <search><![CDATA[$this->error['warning'] = $this->language->get('error_empty');]]></search>
            <add position="replace"><![CDATA[
            $err_code = isset($this->request->files['import']['error']) ? $this->request->files['import']['error'] : null;
            if ($err_code !== null) {
                $this->error['warning'] = $this->language->get('error_upload_' . $this->request->files['import']['error']);
                if ($err_code == '1' || $err_code == '2') {
                    $this->error['warning'] .= '<br />You can find more information <a href="http://stackoverflow.com/a/2184541" target="_blank">here</a> or contact your hosting provider.';
                }
            } else {
                $this->error['warning'] = $this->language->get('error_empty');
            }
            ]]></add>
        </operation>

        <operation>
            <search><![CDATA[public function index() {]]></search>
            <add position="after"><![CDATA[
                $data['max_upload_limit']  = '<p style="margin-top: 15px;">php.ini path: <b>' . php_ini_loaded_file() . '</b></p>';
                $data['max_upload_limit'] .= '<p>upload_max_filesize: <b>' . ini_get('upload_max_filesize') .  '</b></p>';
                $data['max_upload_limit'] .= '<p>post_max_size: <b>' . ini_get('post_max_size') .  '</b></p>';
                $data['max_upload_limit'] .= '<p><a href="http://stackoverflow.com/a/2184541" target="_blank">How to increase them</a></p>';
            ]]></add>
        </operation>
    </file>

    <file path="admin/view/template/tool/backup.tpl">
        <operation>
            <search><![CDATA[<input type="file" name="import" id="input-import" />]]></search>
            <add position="replace"><![CDATA[<input type="file" name="import" id="input-import" /><?php echo $max_upload_limit; ?>]]></add>
        </operation>
    </file>

    <file path="admin/model/tool/backup.php">
        <operation>
            <search><![CDATA[$values .= '\'' . $value . '\', ';]]></search>
            <add position="before"><![CDATA[
                /* json fix */
                if (in_array($table, array(
                    DB_PREFIX . 'journal2_config',
                    DB_PREFIX . 'journal2_modules',
                    DB_PREFIX . 'journal2_newsletter',
                    DB_PREFIX . 'journal2_settings',
                    DB_PREFIX . 'journal2_skins',
                ))) {
                    $value = str_replace('\n', '\\\n', $value);
                }
                /* end json fix */
            ]]></add>
        </operation>

        <operation>
            <search><![CDATA[$output .= 'TRUNCATE TABLE `' . $table . '`;' . "\n\n";]]></search>
            <add position="after"><![CDATA[
                /* journal skins fix */
                if ($table === DB_PREFIX . 'journal2_skins') {
                    $output .= "ALTER TABLE `" . $table . "` AUTO_INCREMENT = 100;" . "\n\n";
                }
            ]]></add>
        </operation>

        <operation>
            <search><![CDATA[$sql = trim($sql);]]></search>
            <add position="after"><![CDATA[
            if (strpos($sql, '-- EXPORT FOR') === 0) {
                $version = (int)str_replace('-- EXPORT FOR: ', '', $sql);
                if (Front::$IS_OC2 && $version !== 2) {
                    die('Version mismatch: You have OpenCart 2.x but the imported file is for OpenCart 1.5.x, go back and export the correct setup.');
                }
                if (!Front::$IS_OC2 && $version !== 1) {
                    die('Version mismatch: You have OpenCart 1.5.x but the imported file is for OpenCart 2.x, go back and export the correct setup.');
                }
            }

            $sql = str_replace('`oc_', '`' . DB_PREFIX, $sql);
            ]]></add>
        </operation>
    </file>

    <!--

        Improve header & footer performance

    -->

    <file path="catalog/controller/common/header.php">
        <operation>
            <search position="replace" trim="true"><![CDATA[$categories = $this->model_catalog_category->getCategories(0);]]></search>
            <add><![CDATA[$categories = strpos($this->config->get('config_template'), 'journal2') === 0 ? array() : $this->model_catalog_category->getCategories(0);]]></add>
        </operation>
    </file>

    <file path="catalog/controller/common/footer.php">
        <operation>
            <search position="replace" trim="true"><![CDATA[foreach ($this->model_catalog_information->getInformations() as $result) {]]></search>
            <add><![CDATA[foreach (strpos($this->config->get('config_template'), 'journal2') === 0 ? array() : $this->model_catalog_information->getInformations() as $result) {]]></add>
        </operation>
    </file>

    <!--

        Html Minifier

    -->

    <file path="system/library/response.php">
        <operation>
            <search><![CDATA[if ($this->output) {]]></search>
            <add position="after"><![CDATA[
                if (defined('JOURNAL_INSTALLED')) {
                    global $registry;
                    $is_ajax = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest';
                    $is_get = !empty($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) === 'get';
                    $ignored_routes = array(
                        'journal2/assets/css',
                        'journal2/assets/js',
                        'feed/google_sitemap'
                    );
                    $request = $registry->get('request');
                    $current_route = isset($request->get['route']) ? $request->get['route'] : null;
                    $ignored_route = $current_route !== null && in_array($current_route, $ignored_routes);
                    $journal2 = $registry->get('journal2');
                    if (!$ignored_route && !$is_ajax && $is_get && !$journal2->settings->get('config_system_settings.developer_mode') && $journal2->settings->get('config_system_settings.minify_html')) {
                        $this->output = Minify_HTML::minify($this->output, array(
                            'xhtml' => false,
                            'jsMinifier' => 'j2_js_minify'
                        ));
                        if (Journal2Cache::$page_cache_file) {
                            file_put_contents(Journal2Cache::$page_cache_file, $this->output);
                        }
                    }
                }
            ]]></add>
        </operation>
    </file>

    <!--

        Serve images from other url

    -->

    <file path="catalog/model/tool/image.php">
        <operation>
            <search><![CDATA[return $this->config->get('config_ssl') . 'image/' . $new_image;]]></search>
            <add position="replace"><![CDATA[return (defined('HTTPS_STATIC_CDN') ? HTTPS_STATIC_CDN : $this->config->get('config_ssl')) . 'image/' . $new_image;]]></add>
        </operation>
        <operation>
            <search><![CDATA[return $this->config->get('config_url') . 'image/' . $new_image;]]></search>
            <add position="replace"><![CDATA[return (defined('HTTP_STATIC_CDN') ? HTTP_STATIC_CDN : $this->config->get('config_url')) . 'image/' . $new_image;]]></add>
        </operation>
    </file>

    <!--

        Fix crop image

    -->

    <file path="catalog/model/tool/image.php">
        <operation>
            <search><![CDATA[public function resize($filename, $width, $height) {]]></search>
            <add position="replace"><![CDATA[public function resize($filename, $width, $height, $type = '') {]]></add>
        </operation>
        <operation>
            <search><![CDATA[$image->resize($width, $height);]]></search>
            <add position="replace"><![CDATA[$image->resize($width, $height, $type);]]></add>
        </operation>
    </file>

    <!--

        Journal2 modules tweak

    -->

    <file path="admin/model/extension/module.php">
        <operation>
            <search><![CDATA[$this->db->query("DELETE FROM `" . DB_PREFIX . "layout_module` WHERE `code` LIKE '%." . (int)$module_id . "'");]]></search>
            <add position="replace"><![CDATA[$this->db->query("DELETE FROM `" . DB_PREFIX . "layout_module` WHERE `code` LIKE '%." . (int)$module_id . "' AND `code` NOT LIKE 'journal2_%'");]]></add>
        </operation>

        <operation>
            <search><![CDATA[public function deleteModulesByCode($code) {]]></search>
            <add position="after"><![CDATA[
            if (strpos($code, 'journal2_') === 0) {
                return;
            }
            ]]></add>
        </operation>
    </file>

    <file path="admin/model/design/layout.php">
        <operation>
            <search><![CDATA[$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "layout_module WHERE layout_id = '" . (int)$layout_id . "'");]]></search>
            <add position="replace"><![CDATA[$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "layout_module WHERE layout_id = '" . (int)$layout_id . "' AND `code` NOT LIKE 'journal2_%'");]]></add>
        </operation>

        <operation>
            <search index="0"><![CDATA[$this->db->query("DELETE FROM " . DB_PREFIX . "layout_module WHERE layout_id = '" . (int)$layout_id . "'");]]></search>
            <add position="replace"><![CDATA[$this->db->query("DELETE FROM " . DB_PREFIX . "layout_module WHERE layout_id = '" . (int)$layout_id . "' AND `code` NOT LIKE 'journal2_%'");]]></add>
        </operation>
    </file>

    <file path="catalog/controller/common/{content_top,content_bottom,column_left,column_right}.php">
        <operation>
            <search><![CDATA[$part = explode('.', $module['code']);]]></search>
            <add position="after"><![CDATA[
            if (strpos($module['code'], 'journal2_') === 0) {
                if ($this->config->get($part[0] . '_' . $module['layout_module_id'] . '_status')) {
                    $action = $this->load->controller('module/' . $part[0], array(
                        'position'  => $module['position'],
                        'layout_id' => $layout_id,
                        'module_id' => $part[1]
                    ));
                    if ($action) {
                        $data['modules'][] = $action;
                    }
                }
                continue;
            }
            ]]></add>
        </operation>
    </file>

    <file path="catalog/model/design/layout.php">
        <operation>
            <search><![CDATA[$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "layout_module WHERE layout_id = '" . (int)$layout_id . "' AND position = '" . $this->db->escape($position) . "' ORDER BY sort_order");]]></search>
            <add position="replace"><![CDATA[$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "layout_module WHERE (layout_id = -1 OR layout_id = '" . (int)$layout_id . "') AND position = '" . $this->db->escape($position) . "' ORDER BY sort_order");]]></add>
        </operation>
    </file>

    <!--

        Special Countdown

    -->

    <file path="catalog/controller/product/product.php">
        <operation>
            <search><![CDATA[if ((float)$product_info['special']) {]]></search>
            <add position="after"><![CDATA[
                if (strpos($this->config->get('config_template'), 'journal2') === 0 && $this->journal2->settings->get('show_countdown_product_page', 'on') == 'on') {
                    $this->load->model('journal2/product');
                    $date_end = $this->model_journal2_product->getSpecialCountdown($this->request->get['product_id']);
                    if ($date_end === '0000-00-00') {
                        $date_end = false;
                    }
                    $data['date_end'] = $date_end;
                }
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[$data['products'][] = array(]]></search>
            <add position="before"><![CDATA[
                $date_end = false;
                if (strpos($this->config->get('config_template'), 'journal2') === 0 && $special && $this->journal2->settings->get('show_countdown', 'never') !== 'never') {
                    $this->load->model('journal2/product');
                    $date_end = $this->model_journal2_product->getSpecialCountdown($result['product_id']);
                    if ($date_end === '0000-00-00') {
                        $date_end = false;
                    }
                }
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA['special'     => $special,]]></search>
            <add position="after"><![CDATA[
                'date_end'       => $date_end,
            ]]></add>
        </operation>
    </file>

    <file path="catalog/controller/product/{category.php,search.php,manufacturer.php,special.php}">
        <operation>
            <search><![CDATA[$data['products'][] = array(]]></search>
            <add position="before"><![CDATA[
                $date_end = false;
                if (strpos($this->config->get('config_template'), 'journal2') === 0 && $special && $this->journal2->settings->get('show_countdown', 'never') !== 'never') {
                    $this->load->model('journal2/product');
                    $date_end = $this->model_journal2_product->getSpecialCountdown($result['product_id']);
                    if ($date_end === '0000-00-00') {
                        $date_end = false;
                    }
                }
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA['special'     => $special,]]></search>
            <add position="after"><![CDATA[
                'date_end'       => $date_end,
            ]]></add>
        </operation>
    </file>

    <!--

        Notification Image

    -->

    <file path="catalog/controller/checkout/cart.php">
        <operation>
            <search><![CDATA[$json['success'] = sprintf($this->language->get('text_success'), $this->url->link('product/product', 'product_id=' . $this->request->post['product_id']), $product_info['name'], $this->url->link('checkout/cart'));]]></search>
            <add position="before"><![CDATA[
			    $this->load->model('tool/image');
                $json['image'] = Journal2Utils::resizeImage($this->model_tool_image, $product_info['image'], $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height'));
            ]]></add>
        </operation>
    </file>

    <file path="catalog/controller/account/wishlist.php">
        <operation>
            <search><![CDATA[$json['total'] = sprintf($this->language->get('text_wishlist'), (isset($this->session->data['wishlist']) ? count($this->session->data['wishlist']) : 0));]]></search>
            <add position="before"><![CDATA[
                $this->load->model('tool/image');
                $json['image'] = Journal2Utils::resizeImage($this->model_tool_image, $product_info['image'], $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height'));
            ]]></add>
        </operation>
    </file>

    <file path="catalog/controller/product/compare.php">
        <operation>
            <search><![CDATA[$json['success'] = sprintf($this->language->get('text_success'), $this->url->link('product/product', 'product_id=' . $this->request->post['product_id']), $product_info['name'], $this->url->link('product/compare'));]]></search>
            <add position="before"><![CDATA[
			    $this->load->model('tool/image');
                $json['image'] = Journal2Utils::resizeImage($this->model_tool_image, $product_info['image'], $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height'));
            ]]></add>
        </operation>
    </file>

    <!--

        No Image Cart fix

    -->

    <file path="catalog/controller/{common,checkout}/cart.php">
        <operation>
            <search><![CDATA[$image = '';]]></search>
            <add position="replace"><![CDATA[$image = $this->model_tool_image->resize('no_image.png', $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height'));]]></add>
        </operation>
    </file>

    <!--

        No Image Product Page fix

    -->

    <file path="catalog/controller/product/product.php">
        <operation>
            <search position="replace"><![CDATA[$data['popup'] = '';]]></search>
            <add><![CDATA[$data['popup'] = $this->model_tool_image->resize('no_image.png', $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height'));]]></add>
        </operation>
        <operation>
            <search position="replace"><![CDATA[$data['thumb'] = '';]]></search>
            <add><![CDATA[$data['thumb'] = $this->model_tool_image->resize('no_image.png', $this->config->get('config_image_thumb_width'), $this->config->get('config_image_thumb_height'));]]></add>
        </operation>
    </file>

    <!--

        Brand enhancements Product Page

    -->

    <file path="catalog/controller/product/product.php">
        <operation>
            <search><![CDATA[$data['manufacturer'] = $product_info['manufacturer'];]]></search>
            <add position="after"><![CDATA[
			if (strpos($this->config->get('config_template'), 'journal2') === 0) {
			    $this->load->model('catalog/manufacturer');
                $manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($product_info['manufacturer_id']);
                if ($manufacturer_info && $manufacturer_info['image'] && $this->journal2->settings->get('manufacturer_image', '0') == '1') {
                    $this->journal2->settings->set('manufacturer_image', 'on');
                    $data['manufacturer_image_width'] = $this->journal2->settings->get('manufacturer_image_width', 100);
                    $data['manufacturer_image_height'] = $this->journal2->settings->get('manufacturer_image_height', 100);
                    $data['manufacturer_image'] = Journal2Utils::resizeImage($this->model_tool_image, $manufacturer_info['image'], $data['manufacturer_image_width'], $data['manufacturer_image_height']);
                    switch ($this->journal2->settings->get('manufacturer_image_additional_text', 'none')) {
                        case 'brand':
                            $data['manufacturer_image_name'] = $product_info['manufacturer'];
                            break;
                        case 'custom':
                            $data['manufacturer_image_name'] = $this->journal2->settings->get('manufacturer_image_custom_text');
                            break;
                    }
                }
			}
            ]]></add>
        </operation>
    </file>

    <!--

        Product Gallery first image fix

    -->

    <file path="catalog/controller/product/product.php">
        <operation>
            <search><![CDATA[$data['popup'] = $this->model_tool_image->resize($product_info['image'], $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height'));]]></search>
            <add position="before"><![CDATA[$data['popup_fixed'] = $this->model_tool_image->resize($product_info['image'], $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height'));]]></add>
        </operation>
        <operation>
            <search><![CDATA[$data['thumb'] = $this->model_tool_image->resize($product_info['image'], $this->config->get('config_image_thumb_width'), $this->config->get('config_image_thumb_height'));]]></search>
            <add position="before"><![CDATA[$data['thumb_fixed'] = $this->model_tool_image->resize($product_info['image'], $this->config->get('config_image_additional_width'), $this->config->get('config_image_additional_height'));]]></add>
        </operation>
        <operation>
            <search><![CDATA[$this->model_tool_image->resize($option_value['image'], 50, 50),]]></search>
            <add position="replace"><![CDATA[strpos($this->config->get('config_template'), 'journal2') === 0 ? Journal2Utils::resizeImage($this->model_tool_image, $option_value['image'], $this->journal2->settings->get('product_page_options_push_image_width', 30), $this->journal2->settings->get('product_page_options_push_image_height', 30), 'crop') : $this->model_tool_image->resize($option_value['image'], 50, 50),]]></add>
        </operation>
    </file>

    <!--

        Product Labels

    -->

    <file path="catalog/controller/product/product.php">
        <operation>
            <search index="0"><![CDATA[$this->load->model('catalog/product');]]></search>
            <add position="after"><![CDATA[
                $this->load->model('journal2/product');
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[if ($product_info['quantity'] <= 0) {]]></search>
            <add position="before"><![CDATA[
                if (true && $product_info['quantity'] <= 0) {
                    $data['stock_status'] = 'outofstock';
                }
                if (true && $product_info['quantity'] > 0) {
                    $data['stock_status'] = 'instock';
                }
                $data['labels'] = $this->model_journal2_product->getLabels($product_info['product_id']);
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA['thumb'       => $image,]]></search>
            <add position="after"><![CDATA[
                'labels'        => $this->model_journal2_product->getLabels($result['product_id']),
            ]]></add>
        </operation>
    </file>

    <file path="catalog/controller/product/compare.php">
        <operation>
            <search><![CDATA[$this->load->model('catalog/product');]]></search>
            <add position="after"><![CDATA[
                $this->load->model('journal2/product');
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA['thumb'        => $image,]]></search>
            <add position="after"><![CDATA[
                'labels'        => $this->model_journal2_product->getLabels($product_info['product_id']),
            ]]></add>
        </operation>
    </file>

    <file path="catalog/controller/{module,product}/{category,search,special,manufacturer,bestseller,latest,special}.php">
        <operation>
            <search><![CDATA[$this->load->model('catalog/product');]]></search>
            <add position="after"><![CDATA[
                $this->load->model('journal2/product');
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA['thumb'       => $image,]]></search>
            <add position="after"><![CDATA[
                'labels'        => $this->model_journal2_product->getLabels($result['product_id']),
            ]]></add>
        </operation>
    </file>

    <file path="catalog/controller/module/featured.php">
        <operation>
            <search><![CDATA[$this->load->model('catalog/product');]]></search>
            <add position="after"><![CDATA[
                $this->load->model('journal2/product');
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA['thumb'       => $image,]]></search>
            <add position="after"><![CDATA[
                'labels'        => $this->model_journal2_product->getLabels($product_id),
            ]]></add>
        </operation>
    </file>

    <!--

        Product Second Image

    -->

    <file path="catalog/controller/product/product.php">
        <operation>
            <search><![CDATA[$data['products'][] = array(]]></search>
            <add position="before"><![CDATA[
                $additional_images = $this->model_catalog_product->getProductImages($result['product_id']);

                $image2 = false;

                if (count($additional_images) > 0) {
                    $image2 = $this->model_tool_image->resize($additional_images[0]['image'], $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
                }
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA['thumb'       => $image,]]></search>
            <add position="after"><![CDATA[
                'thumb2'       => $image2,
            ]]></add>
        </operation>
    </file>

    <file path="catalog/controller/{module,product}/{category,search,special,manufacturer,bestseller,latest,special}.php">
        <operation>
            <search><![CDATA[$data['products'][] = array(]]></search>
            <add position="before"><![CDATA[
                $additional_images = $this->model_catalog_product->getProductImages($result['product_id']);

                $image2 = false;

                if (count($additional_images) > 0) {
                    $image2 = $this->model_tool_image->resize($additional_images[0]['image'], $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
                }
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA['thumb'       => $image,]]></search>
            <add position="after"><![CDATA[
                'thumb2'       => $image2,
            ]]></add>
        </operation>
    </file>

    <file path="catalog/controller/module/featured.php">
        <operation>
            <search><![CDATA[$data['products'][] = array(]]></search>
            <add position="before"><![CDATA[
                $additional_images = $this->model_catalog_product->getProductImages($product_id);

                $image2 = false;

                if (count($additional_images) > 0) {
                    $image2 = $this->model_tool_image->resize($additional_images[0]['image'], $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
                }
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA['thumb'       => $image,]]></search>
            <add position="after"><![CDATA[
                'thumb2'       => $image2,
            ]]></add>
        </operation>
    </file>

    <!--

        Journal Blog

    -->

    <file path="catalog/controller/feed/google_sitemap.php">
        <operation>
            <search><![CDATA[$output .= '</urlset>';]]></search>
            <add position="before"><![CDATA[
            $this->load->model('journal2/blog');

			foreach ($this->model_journal2_blog->getCategories() as $category) {
				$output .= '<url>';
				$output .= '<loc>' . $this->url->link('journal2/blog', 'journal_blog_category_id=' . $category['category_id']) . '</loc>';
				$output .= '<changefreq>weekly</changefreq>';
				$output .= '<priority>1</priority>';
				$output .= '</url>';

				foreach ($this->model_journal2_blog->getPosts(array('category_id' => $category['category_id'])) as $post) {
					$output .= '<url>';
					$output .= '<loc>' . $this->url->link('journal2/blog/post', 'journal_blog_category_id=' . $category['category_id'] . '&journal_blog_post_id=' . $post['post_id']) . '</loc>';
					$output .= '<changefreq>weekly</changefreq>';
					$output .= '<priority>1</priority>';
					$output .= '</url>';
				}

			}
            ]]></add>
        </operation>
    </file>

    <file path="catalog/controller/common/seo_url.php">
        <operation>
            <search><![CDATA[if ($query->num_rows) {]]></search>
            <add position="before"><![CDATA[
                if ($part && !$query->num_rows) {
                    $sql = "
                        SELECT CONCAT('journal_blog_category_id=', category_id) as query FROM " . DB_PREFIX . "journal2_blog_category_description
                        WHERE keyword = '" . $this->db->escape($part) . "'
                        UNION
                        SELECT CONCAT('journal_blog_post_id=', post_id) as query FROM " . DB_PREFIX . "journal2_blog_post_description
                        WHERE keyword = '" . $this->db->escape($part) . "'
                    ";
                    $query = $this->db->query($sql);
                }

                if (!$query->num_rows) {
                    $this->load->model('journal2/blog');
                    $journal_blog_keywords = $this->model_journal2_blog->getBlogKeywords();

                    if($part && is_array($journal_blog_keywords) && (in_array($part, $journal_blog_keywords))) {
                        $this->request->get['route'] = 'journal2/blog';
                        continue;
                    }
                }
            ]]></add>
        </operation>

        <operation>
            <search><![CDATA[if ($url[0] == 'product_id') {]]></search>
            <add position="before"><![CDATA[
                    if ($url[0] == 'journal_blog_post_id') {
                        $this->request->get['journal_blog_post_id'] = $url[1];
                    }

                    if ($url[0] == 'journal_blog_category_id') {
                        $this->request->get['journal_blog_category_id'] = $url[1];
                    }
            ]]></add>
        </operation>

        <operation>
            <search><![CDATA[if (!isset($this->request->get['route'])) {]]></search>
            <add position="before"><![CDATA[
                    if (isset($this->request->get['journal_blog_post_id'])) {
                        $this->request->get['route'] = 'journal2/blog/post';
			        } else if (isset($this->request->get['journal_blog_category_id'])) {
                        $this->request->get['route'] = 'journal2/blog';
                    }
            ]]></add>
        </operation>

        <operation>
            <search><![CDATA[public function rewrite($link) {]]></search>
            <add position="after"><![CDATA[
                $this->load->model('journal2/blog');
                $is_journal2_blog = false;
            ]]></add>
        </operation>

        <operation>
            <search><![CDATA[$key == 'path']]></search>
            <add position="before"><![CDATA[
                } elseif ($key == 'journal_blog_post_id') {
                    $is_journal2_blog = true;
                    if ($journal_blog_keyword = $this->model_journal2_blog->rewritePost($value)) {
                        $url .= '/' . $journal_blog_keyword;
                        unset($data[$key]);
                    }
                } elseif ($key == 'journal_blog_category_id') {
                    $is_journal2_blog = true;
                    if ($journal_blog_keyword = $this->model_journal2_blog->rewriteCategory($value)) {
                        $url .= '/' . $journal_blog_keyword;
                        unset($data[$key]);
                    }
                } elseif (isset($data['route']) && $data['route'] == 'journal2/blog') {
                    if (!isset($data['journal_blog_post_id']) && !isset($data['journal_blog_category_id'])) {
                        if ($journal_blog_keyword = $this->model_journal2_blog->getBlogKeyword()) {
                            $url .= '/' . $journal_blog_keyword;
                            unset($data[$key]);
                        }
                    }
            ]]></add>
        </operation>

        <operation>
            <search><![CDATA[if ($url) {]]></search>
            <add position="before"><![CDATA[
            if ($is_journal2_blog && $this->model_journal2_blog->getBlogKeyword()) {
                $url = '/' . $this->model_journal2_blog->getBlogKeyword() . $url;
            }]]></add>
        </operation>
    </file>

    <file path="catalog/controller/common/{column_left.php,column_right.php,content_top.php,content_bottom.php}">
        <operation>
            <search><![CDATA[$layout_id = 0;]]></search>
            <add  position="after"><![CDATA[
                $this->load->model('journal2/blog');

                if ($route == 'journal2/blog' && isset($this->request->get['journal_blog_category_id'])) {
			        $layout_id = $this->model_journal2_blog->getBlogCategoryLayoutId($this->request->get['journal_blog_category_id']);
		        }

		        if ($route == 'journal2/blog/post' && isset($this->request->get['journal_blog_post_id'])) {
			        $layout_id = $this->model_journal2_blog->getBlogPostLayoutId($this->request->get['journal_blog_post_id']);
		        }
            ]]></add>
        </operation>
    </file>

    <!--

        Imagemanager fix

    -->

    <file path="admin/controller/common/filemanager.php">
        <operation>
            <search><![CDATA[. 'catalog]]></search>
            <add position="replace"><![CDATA[. ']]></add>
        </operation>
        <operation>
            <search><![CDATA[$name = str_split(basename($image), 14);]]></search>
            <add position="before"><![CDATA[
            // Ignore cache, flags and templates directories
			if (strpos($image, DIR_IMAGE . '/cache') === 0 || strpos($image, DIR_IMAGE . '/flags') === 0 || strpos($image, DIR_IMAGE . '/templates') === 0) {
				continue;
			}
            ]]></add>
        </operation>
    </file>

    <file path="admin/view/template/common/filemanager.tpl">
        <operation>
            <search><![CDATA[<div class="modal-dialog modal-lg">]]></search>
            <add position="before"><![CDATA[
            <?php $is_ajax = isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest'; ?>
            <?php $ckeditor = isset($this->request->get['CKEditorFuncNum']) ? $this->request->get['CKEditorFuncNum'] : null; ?>
            <?php $imgpath = HTTP_CATALOG . 'image';  ?>
            <?php $base = $this->request->server['HTTPS'] ? HTTPS_SERVER : HTTP_SERVER; ?>
            <?php if (!$is_ajax): ?>
            <!DOCTYPE html>
            <html dir="ltr" lang="en">
            <head>
                <meta charset="UTF-8" />
                <title>Image Manager</title>
                <base href="<?php echo $base; ?>" />
                <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" />
                <script type="text/javascript" src="view/javascript/jquery/jquery-2.1.1.min.js"></script>
                <script type="text/javascript" src="view/javascript/bootstrap/js/bootstrap.min.js"></script>
                <link href="view/javascript/bootstrap/css/bootstrap.css" rel="stylesheet" />
                <link href="view/javascript/font-awesome/css/font-awesome.min.css" type="text/css" rel="stylesheet" />
                <link type="text/css" href="view/stylesheet/stylesheet.css" rel="stylesheet" media="screen" />
                <script src="view/javascript/common.js" type="text/javascript"></script>
                <?php if ($ckeditor): ?>
                <script>
                var ckeditor = <?php echo $ckeditor; ?>;
                var imgpath = '<?php echo $imgpath; ?>';
                </script>
                <?php endif; ?>
                <style>
                #modal-image .modal-dialog{
                    width:100%;
                    margin: 0 auto;
                }
                .modal-header .close{
                display:none;
                }
                </style>
            </head>
            <body>
            <div id="modal-image">
            <?php endif; ?>
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[$('a.directory').on('click', function(e) {]]></search>
            <add position="before"><![CDATA[
            if (typeof (ckeditor) !== 'undefined') {
                $('a.thumbnail').off('click').on('click', function(e) {
                    e.preventDefault();

                    window.opener.CKEDITOR.tools.callFunction(ckeditor, imgpath + $(this).parent().find('input').attr('value'));

                    self.close();
                });
            }
            ]]></add>
        </operation>
        <operation>
            <search index="1"><![CDATA[//--></script>]]></search>
            <add position="after"><![CDATA[
            <?php if (!$is_ajax): ?>
                </div>
            </body>
            </html>
            <?php endif; ?>
            ]]></add>
        </operation>
    </file>

</modification>