dongzhang6021 2017-05-31 21:35
浏览 90
已采纳

OpenCart OCmod使用“底部”

I am trying to create a OCmod extension for OpenCart 2.3.0.2 that prevents (as much as possible) the ability to copy/download content from a client's website. I tested the code by manually adding it in the files that I call in the extension and it works as it should.

Here is the OCmod extension I created:

<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>

The extension seems to work alright (preventing right click and CTRL commands) until it gets to the first "before" operation that should prevent users from dragging the photos without a link to open them in a new tab.

I need to insert that CSS at the bottom of the stylesheet.css. Does OCmod supports "bottom" or is it achievable only with vQmod?

  • 写回答

1条回答 默认 最新

  • douxie0824 2017-07-19 19:22
    关注

    OCMOD Missing Attributes: top, bottom, ibefore, iafter

    But u can use REGEX. If u need Bottom of file for example, use:

    <search regex="true" limit="1"><![CDATA[($)]]></search>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起