OpenCart OCmod使用"底部"

时间:2017-05-31 21:35:07

标签: php opencart

我正在尝试为OpenCart 2.3.0.2创建一个OCmod扩展,以防止(尽可能)从客户端网站复制/下载内容。我通过手动将代码添加到我在扩展中调用的文件来测试代码,它可以正常工作。

这是我创建的OCmod扩展程序:

<modification>
    <name>Copy protection</name>
    <version>v1.0</version>
    <author>SporeDev</author>
    <code>copy-protection</code>    
    <file path="catalog/view/theme/*/template/common/header.tpl">
        <!-- Insert the JS call required in the header -->
        <operation>
            <search><![CDATA[<body]]></search>
            <add position="replace"><![CDATA[<body onkeypress="return disableCtrlKeyCombination(event);" onkeydown="return disableCtrlKeyCombination(event);"]]></add>
        </operation>
        <!-- Insert the JS call required in the header -->
        <operation>
            <search><![CDATA[</head>]]></search>
            <add position="before"><![CDATA[<script>function clickIE(){if(document.all)return!1}function clickNS(e){if((document.layers||document.getElementById&&!document.all)&&(2==e.which||3==e.which))return!1}function disableCtrlKeyCombination(e){var n,o,t=new Array("a","n","c","x","v","j","w");if(window.event?(n=window.event.keyCode,o=!!window.event.ctrlKey):(n=e.which,o=!!e.ctrlKey),o)for(i=0;i<t.length;i++)if(t[i].toLowerCase()==String.fromCharCode(n).toLowerCase())return alert("Key combination CTRL + "+String.fromCharCode(n)+" has been disabled."),!1;return!0}document.onkeypress=function(e){if(123==(e=e||window.event).keyCode)return!1},document.onmousedown=function(e){if(123==(e=e||window.event).keyCode)return!1},document.onkeydown=function(e){if(123==(e=e||window.event).keyCode)return!1};var message="Sorry, right-click has been disabled";document.layers?(document.captureEvents(Event.MOUSEDOWN),document.onmousedown=clickNS):(document.onmouseup=clickNS,document.oncontextmenu=clickIE),document.oncontextmenu=new Function("return false");</script>]]></add>
        </operation>
    </file> 
    <!-- Modify the CSS to prevent dragging the photo in a new tab -->
    <file path="catalog/view/theme/*/stylesheet/stylesheet.css">
        <operation>
            <search><![CDATA[]]></search>
            <add position="bottom"><![CDATA[body{-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none} img{-moz-user-select:none;-webkit-user-select:none;-ms-user-select:none;user-select:none;-webkit-user-drag:none;user-drag:none;-webkit-touch-callout:none}]]></add>
        </operation>
    </file> 
    <!-- Modify the img tag to prevent dragging the photo in a new tab -->
    <file path="catalog/view/theme/*/template/product/product.tpl">
        <operation>
            <search><![CDATA[<img]]></search>
            <add position="replace"><![CDATA[<img draggable="false" ondragstart="return false;"]]></add>
        </operation>
    </file> 
    <!-- Modify the lightbox img tag to prevent dragging the photo in a new tab -->
    <file path="catalog/view/javascript/jquery/magnific/jquery.magnific-popup.min.js">
        <operation>
            <search><![CDATA[<img]]></search>
            <add position="replace"><![CDATA[<img draggable="false" ondragstart="return false;"]]></add>
        </operation>
    </file>     
</modification>

扩展似乎正常工作(防止右键单击和CTRL命令),直到它到达第一个&#34;之前&#34;应该阻止用户拖动照片而没有链接在新标签页中打开它们的操作。

我需要在stylesheet.css的底部插入CSS。 OCmod是否支持&#34;底部&#34;或者只能用vQmod实现?

1 个答案:

答案 0 :(得分:2)

OCMOD缺少属性:top,bottom,ibefore,iafter

但你可以使用REGEX。例如,如果您需要文件底部,请使用:

<search regex="true" limit="1"><![CDATA[($)]]></search>