<modification> 
    <code>Lightning2</code> 
    <name>OpenCart Lightning</name> 
	<id>OpenCart Lightning</id> 
	<version>2.2</version>
	<author><![CDATA[MaxD http://devs.mx]]></author>

    <file path="system/engine/registry.php">
        <operation error="skip">
            <search position="before"><![CDATA[ function get( ]]></search>
            <add position="before"><![CDATA[ public function __construct() { global $registry; if (!$registry) $registry = $this; } //Lightning]]></add>
        </operation>
    </file>

    <file path="system/library/image.php">
        <operation error="skip">
            <search position="replace"><![CDATA[ imagejpeg($this->image, $file, $quality); ]]></search>
            <add position="replace"><![CDATA[ imagejpeg($this->image, $file, 85); //Lightning]]></add>
        </operation>
    </file>

    <file path="system/library/image.php">
        <operation error="skip">
            <search position="after"><![CDATA[ imagedestroy($this->image); ]]></search>
            <add position="after"><![CDATA[ if (function_exists('Waq')) Waq($file); //Lightning]]></add>
        </operation>
    </file>

    <file name="system/journal2/*.php,system/journal2/classes/*.php">
        <operation>
            <search regex="true">
                <![CDATA[~(require|include)(_once)?\(([^)]+)~]]>
            </search>
            <add position="replace">
                <![CDATA[$1$2(modification($3)]]>
            </add>
        </operation>
    </file>

    <file name="system/journal2/*.php,system/journal2/classes/*.php">
        <operation>
            <search regex="true">
                <![CDATA[~(require|include)(_once)?\(([^)]+)~]]>
            </search>
            <add position="replace">
                <![CDATA[$1$2(modification($3)]]>
            </add>
        </operation>
    </file>

    <file path="admin/model/journal2/*.php">
        <operation error="skip">
            <search position="replace"><![CDATA[ require_once DIR_SYSTEM . 'journal2/classes/journal2_cache.php'; ]]></search>
            <add position="replace"><![CDATA[ require_once(modification(DIR_SYSTEM.'journal2/classes/journal2_cache.php')); ]]></add>
        </operation>
    </file>

    <file path="admin/controller/module/journal2.php">
        <operation error="skip">
            <search position="replace"><![CDATA[ require_once DIR_SYSTEM . 'journal2/classes/journal2_cache.php'; ]]></search>
            <add position="replace"><![CDATA[ require_once(modification(DIR_SYSTEM.'journal2/classes/journal2_cache.php')); ]]></add>
        </operation>
    </file>

    <file error="skip" path="system/journal2/classes/journal2_cache.php">
        <operation error="skip">
            <search position="before"><![CDATA[ Journal2Cache::$mobile_detect = new Mobile_Detect(); ]]></search>
            <add position="before"><![CDATA[ if (class_exists('Light_Mobile_Detect')) Journal2Cache::$mobile_detect = new Light_Mobile_Detect(); else // Lightning ]]></add>
        </operation>
    </file>

    <file error="skip" path="system/journal2/classes/journal2_cache.php">
        <operation error="skip">
            <search position="after"><![CDATA[ function deleteCache ]]></search>
            <add position="after"><![CDATA[ if ($pattern=="*") $pattern="*.html"; elseif (!strpos($pattern, ".html")) return; //Lightning ]]></add>
        </operation>
    </file>

    <file error="skip" path="system/journal2/classes/journal2_minifier.php">
        <operation error="skip">
            <search position="before"><![CDATA[ /* return link tag */ ]]></search>
            <add position="before"><![CDATA[ if (function_exists('Wdu')) if (isset($combined_css_file)) Wdu($this->path . $combined_css_file); else Wdu($this->path . $combined_js_file); //Lightning ]]></add>
        </operation>
    </file>

    <file error="skip" path="system/journal2/startup.php">
        <operation error="skip">
            <search position="before"><![CDATA[ if (php_sapi_name() === "cli") { ]]></search>
            <add position="before"><![CDATA[ if (!function_exists('Wed')) // Lightning ]]></add>
        </operation>
    </file>

    <file path="admin/model/localisation/currency.php">
        <operation error="skip"> 
            <search position="before"><![CDATA[ $curl = curl_init(); ]]></search> 
            <add position="before"><![CDATA[ if (isset($query) and !$query->rows) return; //Lightning ]]></add> 
        </operation> 
    </file> 
 
    <file path="admin/view/template/common/header.tpl">
        <operation error="skip">
            <search position="before"><![CDATA[ <ul class="nav pull-right"> ]]></search>
            <add position="before"><![CDATA[ <ul class="nav pull-left"><!-light-><style type="text/css"> #lightning_container { margin-top: 11px !important; margin-right: 20px; } </style></ul> ]]></add>
        </operation>
    </file> 
 
    <file path="admin/view/template/common/header.tpl">
        <operation error="log"> 
            <search position="replace"><![CDATA[ <!-light-> ]]></search>
            <add position="replace"><![CDATA[ 
             <?php if (!empty($GLOBALS["registry"])) if ($GLOBALS["registry"]->get("user")->hasPermission("modify", "setting/setting") and !in_array($GLOBALS["registry"]->get("request")->get["route"], explode(" ", "module/psmsitemapgenerator"))) { ?>
             <link rel="stylesheet" type="text/css" href="http<?php if (!empty($_SERVER["HTTPS"]) or (!empty($_SERVER["SERVER_PORT"]) && $_SERVER["SERVER_PORT"] == 443) or (!empty($_SERVER["HTTP_X_FORWARDED_PROTO"]) && $_SERVER["HTTP_X_FORWARDED_PROTO"] == "https") or (!empty($_SERVER["HTTP_X_FORWARDED_PROTOCOL"]) && $_SERVER["HTTP_X_FORWARDED_PROTOCOL"] == "https")) echo 's' ?>://lightning.devs.mx/service/css/tetha2.css" />
             <?php global $os; if ($os) echo '<style type="text/css"> #menu { padding:0; } </style>' ?>

              <li id="lightning"></li>
              <script type="text/javascript">

                  var lu = true;
                  var lv = true;
                  var lt = false;

                  function Ul() {
                      if (!lu) return;
                      if (!lv) return;
                      lu = false;
                      $.get('../index.php?li_op=t&rd='+Date.now(),false, function(data) {
                          if (data.indexOf("lightning_menu")==-1)
                                $('#lightning').html("<a style='background:white; padding:5px' target='_blank' href='http://lightning.devs.mx/fix-index-php-problem/'>Click to fix Lightning <b>index.php</b> problem</a>");
                          else $('#lightning').html(data);
                      },"html").done(function() { lu = true; });
                  }

                  function li_live() {
                    $(".li_logos").css("-webkit-filter", "brightness(100%)");
                    $(".li_req" ).each(function(index) {
                      var live = $(this).hasClass("li_req_live");
                      var time = $(this).find(".li_live_time");
                      var t = +time.html();
                      t = parseFloat(t + 0.1);

                      if (t>0)
                         $(this).find(".li_req_bar").css("width", 40*t);
                      else if (t<0 && !live) {
                        $(this).css("margin-left", ((5+t)*10)+"px");
                      }
                      if (t==0)
                       if (live) $(this).show();
                       else {
                         $(this).css("background", "none").css("border", "none");
                         $(this).find(".li_req_on").remove();
                         $(this).find(".li_req_bar").remove();
                         $(this).animate({height:0, padding:0, margin:0},300);
                         return;
                       }
                      var ft = +$(this).find(".li_time").html();
                      if (ft && t>=ft) {
                        t = -5;
                        $(this).removeClass("li_req_live");
                        $(this).find(".li_req_bar").css("width", 40*ft);
                        if (!$("#li_percent").length) {
                            $(".lightning_bar strong").html(ft + " sec");
                            var width = 190 / 5 * ft + 10;
                            if (width>200) width = 200;
                            var color = "#9e3c3c";
                            if (ft<2) color = "#3065b5";
                            else if (ft<4) color = "#82701b";
                            $("#li_bar").css("width", width + "px").css("background-color", color);
                            $(".li_logos").css("-webkit-filter", "brightness(120%)");
                        }
                      }
                      time.html(t.toFixed(1));
                    });
                  }

                  $(document).ready(function(){
                      setInterval('Ul()', 5000);
                      Ul();
                      setInterval('li_live()', 100);
                      li_live();
                  });

                  $(window).focus(function() {
                        lv = true;
                        Ul();
                    });

                    $(window).blur(function() {
                        lv = false;
                    });

                    var li_genx = false;

                    function li_gen() {
                        li_genx = true;
                        $.get('../index.php?li_op=gen&cd='+Date.now(),false, function(data) {
                                  if (!data) {
                                    $('#li_percent').html(100);
                                    $('#li_bar').css('width','200px');
                                    li_genx = false;
                                    return;
                                  }
                                  $('#li_bar').css('width',data['width']);
                                  $('#li_percent').html(data['percent']);
                                  $('#li_pages').html(data['pages']);
                                  $('#li_psize').html(data['psize']);
                                  li_gen();
                              }, 'json');
                    }
              </script> 
        <?php } ?> 
 
    ]]></add>
        </operation> 
    </file>

    <file path="catalog/model/tool/online.php">
        <operation error="log">
            <search position="after"><![CDATA[ line( ]]></search>
            <add  position="after"><![CDATA[ if (function_exists('Wbt') and Wbt()) return; // Lightning  ]]></add>
        </operation>
    </file>

    <file path="system/library/session.php">
        <operation error="skip">
            <search position="before"><![CDATA[ if (!session_id()) { ]]></search>
            <add  position="before"><![CDATA[ if (function_exists('Waa') and ($this->data = Waa())) return; // Lightning  ]]></add>
        </operation>
    </file>

    <file path="system/library/session.php">
        <operation error="skip">
            <search position="after"><![CDATA[ start($key = 'default' ]]></search>
            <add  position="after"><![CDATA[ if ($key == 'default' && function_exists('Waa') && ($this->data = Waa())) return; // Lightning  ]]></add>
        </operation>
    </file>

    <file path="system/engine/front.php">
        <operation error="log">
            <search position="before"><![CDATA[ while ($action ]]></search>
            <add position="before"><![CDATA[ if (function_exists('Wal')) Wal(); // Lightning  ]]></add>
        </operation>
    </file>

    <file path="system/library/db*.php"> 
        <operation error="log"> 
            <search position="before"><![CDATA[ class D ]]></search> 
            <add position="before"><![CDATA[ if (file_exists(DIR_SYSTEM.'lightning/beta.php')) require_once DIR_SYSTEM.'lightning/beta.php'; // Lightning ]]></add> 
        </operation>
        <operation error="skip">
            <search position="after"><![CDATA[ $this->adaptor = ]]></search>
            <add position="after"><![CDATA[ global $db; $db = $this; if (function_exists('Wbu')) Wbu($this->adaptor); // Lightning ]]></add>
        </operation>
    </file>

    <file path="system/library/db*.php">
        <operation error="skip">
            <search position="after"><![CDATA[ $this->db = ]]></search>
            <add position="after"><![CDATA[ if (function_exists('Wbu')) Wbu($this->db); // Lightning ]]></add>
        </operation>
    </file>

    <file path="catalog/controller/checkout/cart.php">
        <operation error="log">
            <search position="after"><![CDATA[ $json['total'] =  ]]></search>
            <add position="after"><![CDATA[ if (function_exists('Wbr')) { global $light_modify_cart; if (!$light_modify_cart) $cht=1; else if (VERSION<"2.0") $cht=$this->getChild('module/cart'); else $cht=$this->load->controller('common/cart'); Wbr($this->cart->countProducts(),$cht); } //Lightning ]]></add>
        </operation>
    </file>

    <file error="skip" path="catalog/controller/module/cart.php">
        <operation error="skip">
            <search position="before"><![CDATA[ $this->response->setOutput($this->render());  ]]></search>
            <add position="before"><![CDATA[ if (function_exists('Wbr')) { global $light_modify_cart; if ($light_modify_cart) { $output = $this->render(); Wbr($this->cart->countProducts(), $output); $this->response->setOutput($output); return; } else Wbr($this->cart->countProducts(), 1); } //Lightning ]]></add>
        </operation>
    </file>

    <file error="skip" path="system/library/cart.php">
        <operation error="skip">
            <search position="after"><![CDATA[ $this->session->data['cart'] = array();  ]]></search>
            <add position="after"><![CDATA[ if (function_exists('Wbr')) Wbr(); //Lightning ]]></add>
        </operation>
    </file>

    <file error="skip" path="system/library/cart/cart.php">
        <operation error="skip">
            <search position="after"><![CDATA[ $this->session->data['cart'] = array();  ]]></search>
            <add position="after"><![CDATA[ if (function_exists('Wbr')) Wbr(); //Lightning ]]></add>
        </operation>
    </file>

    <file path="system/library/config.php">
        <operation error="skip">
            <search position="after"><![CDATA[ function set($key, $value) { ]]></search>
            <add position="after"><![CDATA[  if (function_exists('Wds')) Wds($key, $value); //Lightning ]]></add>
        </operation>
    </file>

    <file path="system/library/url.php">
        <operation error="skip">
            <search position="replace"><![CDATA[ return $this->rewrite($url); ]]></search>
            <add position="replace"><![CDATA[  $url = $this->rewrite($url); 
                            return $url; ]]></add>
        </operation>
    </file>

    <file path="system/library/url.php">
        <operation error="skip">
            <search position="before"><![CDATA[ return $url ]]></search>
            <add position="before"><![CDATA[ if (function_exists('Wah') and !empty($route)) { Wah($route, $url); Wci($route.$args.$connection, $url);} //Lightning ]]></add>
        </operation>
    </file>

    <file path="system/library/url.php">
        <operation error="skip">
            <search position="after"><![CDATA[ $secure = false) { ]]></search>
            <add position="after"><![CDATA[ $connection = $secure; if (function_exists('Wci') && ($r = Wci($route.$args.$connection))!==-1) {Wah($route, $r); return $r;} //Lightning ]]></add>
        </operation>
    </file>

    <file path="system/library/url.php">
        <operation error="skip">
            <search position="after"><![CDATA[ $connection = 'NONSSL') { ]]></search>
            <add position="after"><![CDATA[ if (function_exists('Wci') && ($r = Wci($route.$args.$connection))!==-1) {Wah($route, $r); return $r;} //Lightning ]]></add>
        </operation>
    </file>

    <file path="system/engine/loader.php">
        <operation error="skip">
            <search position="replace"><![CDATA[ function view(  ]]></search>
            <add position="replace"><![CDATA[ function org_view( ]]></add>
        </operation>
        <operation error="skip">
            <search position="before"><![CDATA[ function org_view(  ]]></search>
            <add position="before"><![CDATA[ public function view($route, $data = array()) { $res = $this->org_view($route, $data); if (function_exists('Wbo')) Wbo($route, $res); return $res; } ]]></add>
        </operation>
    </file>

    <file error="skip" path="system/library/customer.php">
        <operation error="skip">
            <search position="after"><![CDATA[ $this->session = $registry->get('session');  ]]></search>
            <add position="after"><![CDATA[ if (function_exists('Wbn') and ($t=Wbn())) {
			$this->customer_id = $t["customer_id"];
			$this->firstname = $t["firstname"];
			$this->lastname = $t["lastname"];
			$this->email = $t["email"];
			$this->customer_group_id = 0;
		} ]]></add>
        </operation>
        <operation error="skip">
            <search position="before"><![CDATA[ $this->session->data['customer_id'] = $customer_query->row['customer_id'];  ]]></search>
            <add position="before"><![CDATA[ if (function_exists('Wbs')) Wbs($customer_query->row); //Lightning ]]></add>
        </operation>
    </file>

    <file error="skip" path="system/library/cart/customer.php">
        <operation error="skip">
            <search position="after"><![CDATA[ $this->session = $registry->get('session');  ]]></search>
            <add position="after"><![CDATA[ if (function_exists('Wbn') and ($t=Wbn())) {
			$this->customer_id = $t["customer_id"];
			$this->firstname = $t["firstname"];
			$this->lastname = $t["lastname"];
			$this->email = $t["email"];
		} ]]></add>
        </operation>
        <operation error="skip">
            <search position="before"><![CDATA[ $this->session->data['customer_id'] = $customer_query->row['customer_id'];  ]]></search>
            <add position="before"><![CDATA[ if (function_exists('Wbs')) Wbs($customer_query->row); //Lightning ]]></add>
        </operation>
    </file>

    <file error="skip" path="catalog/model/account/wishlist.php">
        <operation error="skip">
            <search position="before"><![CDATA[ return $query->row['total'];  ]]></search>
            <add position="before"><![CDATA[ if (function_exists('Weh') and ($r=Weh($query->row['total']))) return $r; //Lightning ]]></add>
        </operation>
    </file>

    <file path="system/library/response.php">
        <operation error="log">
            <search position="before"><![CDATA[ echo $ou  ]]></search>
            <add position="before"><![CDATA[ if (function_exists('Wt')) if (Wt()) return; //Lightning]]></add>
        </operation>
        <operation error="log">
            <search position="before"><![CDATA[ $this->level = $level;  ]]></search>
            <add position="before"><![CDATA[ global $light_ob; if (!$light_ob) //Lightning]]></add>
        </operation>
    </file>

    <file path="system/library/request.php">
        <operation error="skip">
            <search position="after"><![CDATA[ $this->server =  ]]></search>
            <add position="after"><![CDATA[ if ($this->server["REQUEST_METHOD"] == "POST" && isset($this->get["route"]) && isset($this->get["token"]) && function_exists('Wco')) Wco($this->get["route"]); //Lightning ]]></add>
        </operation>
    </file>

    <!-- Brainy Filter workaround -->

    <file path="catalog/model/catalog/product.php">
        <operation error="skip">
            <search position="replace"><![CDATA[ public function getTotalProducts($data = array()) { ]]></search>
            <add position="replace"><![CDATA[ public function getTotalProducts($data = array())
             { ]]></add>
        </operation>
    </file>

    <file path="catalog/model/catalog/product.php">
        <operation error="skip">
            <search position="replace" offset="1"><![CDATA[ public function getTotalProducts($data = array()) ]]></search>
            <add position="replace" offset="1"><![CDATA[ public function getTotalProducts($data = array()) { ]]></add>
        </operation>
    </file>
 
    <file path="catalog/model/catalog/product.php"> 
        <operation error="skip"> 
            <search position="replace"><![CDATA[ public function getTotalProducts($data = array())
    { ]]></search>
            <add position="replace"><![CDATA[ public function getTotalProducts($data = array()) { ]]></add>
        </operation> 
    </file>

    <file path="catalog/model/catalog/product.php">
        <operation error="log">
            <search position="after"><![CDATA[ function getTotalProducts( ]]></search>
            <add position="after"><![CDATA[ if (function_exists('Wdn') and ($r=Wdn(func_get_args()))>=0) return $r; // Lightning ]]></add>
        </operation>
    </file>

</modification> 