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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装