Opencart / OCmod - Search for one OR another line of code - opencart

I'm working on a modification for Opencart, using OCmod. Initially, I started writing it for Opencart 2 (It's actually done and working). Now, I'm upgrating it for OC3.
Here's a quick example of what's going wrong.
Previously, I wrote this for OC2:
<operation>
<search><![CDATA[
'status' => ($result['status']) ? $this->language->get('text_enabled') : $this->language->get('text_disabled'),
]]></search>
<add position="replace"><![CDATA[
'status' => ($result['status']),
]]></add>
</operation>
The problem is: As of OC3, this part of the code:
'status' => ($result['status']) ...
has been changed to:
'status' => $result['status'] ...
Therefore, the line will not be found, and the replacement will not be made.
For that reason, if I wish to publish my modification for both versions, I'll have to release two different versions of my modification.
I wonder if there's a way of telling OCmod to search for one of the two lines, and then change the one it finds. That way, I could have only one code working for both versions.
I've tried duplicating that piece of code, making it look for both lines, but my modification stops working since one of the lines is not found.
Any ideas on how to go around this?

SOLVED
It turns out, OCmod allows you to select just a piece of the code, not just full lines.
Since I only needed to delete the last portion of the line, I did this:
<operation>
<search><![CDATA[
? $this->language->get('text_enabled') : $this->language->get('text_disabled'),
]]></search>
<add position="replace"><![CDATA[
,
]]></add>
</operation>
Also, if it helps anyone, having OCmod to look for a file that doesn't exist will not cause an error.
That was helpful since file "product_list.tpl" has been renamed to "product_list.twig" in Opencart 3. So, in my install.xml file, I was able to write a modification for both files, even though one of them will not be found depending on the OpenCart version.

Related

selecting multiple files modification not works with ocmod on oprencart on ver 2.0.2.0, 2.0.3.1

am already test my modifications on ver 2.0.2.0, 2.0.3.1, and find that modifications on muti file like:
<file path="system/{engine,library}/{action,loader,config,language}*.php">
not works now, am back to modifications docs, and its not update yet:
https://github.com/opencart/opencart/wiki/Modification-System
i is there change on multi file modifications? or its bug?
Same for me in 2.2.0.0.
This will not work in 2.2.0.0 (although it would in 2.1.0.x):
<file path="catalog/file-1.php,catalog/file-2.php,catalog/file-3.php">
But this will work in 2.2.0.0:
<file path="catalog/file-{1,2,3}.php">
yes i find it, in file system/modification.xml
it was
<file path="system/{engine,library}/{action,loader,config,language}*.php">
now you can do it like this
<file path="system/engine/action.php,system/engine/loader.php,system/library/config.php,system/library/language.php">
after i debug the code i found this
error in modifications
it seems there big hole there..
so you can use this to downgrade modifications to ver 2.0.1.1
modification.ocmod.zip
this mod will remove all current mods, so you need upload them again
you may need to use this ocmod, if you have error in FTP
localcopy.ocmod.xml

How to remove comments when server returns a JSP page?

Which class of tomcat is responsible for converting .jsp file to .class file? I want to see the source code written for the conversion. My aim is to check the logic how scriptlet comments are eliminated and based on that I'll write my own code that will remove HTML comments as well (I've not decided how will I implement it).
I am sure source code should be available as it's open source.
Or is it possible to implement some kind of filter so the each time server returns a JSP page it removes the comments. I can replace all HTML comments into Scriptlet comments. But I want to ensure, if someone use html comments in future, it is not displayed. It's basically for security.
[Added]
As per the suggestion given by JB Nizet, we will be modifying build.xml file to remove comments. I have come up with this to remove HTML comments -
<target name="-trim.html.comments">
<echo message="Inside trim html comments" />
<fileset id="html.fileset" dir="${build.dir}" includes="**/*.jsp, **/*.html" />
<!-- HTML Comments -->
<replaceregexp replace="" flags="g" match="\<![ \r\n\t]*(--([^\-]|[\r\n]|-[^\-])*--[ \r\n\t]*)\>">
<fileset refid="html.fileset"/>
</replaceregexp>
</target>
However, I am not sure how to remove comments that starts with // or /* */. Any suggestion how can I do so? I have searched over internet but didn't get a clue.
We are using ant script for build.
[Added]
To remove single line comment that starts with // I am using below regex. But somehow it's not working. Can anyone please help me what I'm doing wrong? Thanks in advance.
<replaceregexp flags="gs" match="?:^\s*\/\/(?:.*)$" replace="">
Rather than doing it in Tomcat, use Apache directly. It supports modules which do exactly what you need. mod pagespeed is probably closest to what you want; mod deflate may be configurable to do the same thing, though it also compresses the data, which might be overkill.
As a nice side-effect, this allows you to leave your handy comments in and they'll be served to your internal users (developers) who use port 8080, while those using port 80 will see only the minified product.

HTML5 PushState Regex Issue

I've been experimenting with Backbone for a project I'm working on, and I've been having problems with getting Backbone's 'pushState' functioning how I'd like to.
I've got a simple project consisting of 4 views, and a router. I'm routing via the id of the elements if it matters in this case. When I go to the hash for one of the views (http://example.com/backbonetest/#step1), it's displayed correctly, and the url is changed. This is what I'd expect to happen here, but the problem comes when I try and navigate to the same thing without the hash in it (http://example.com/backbonetest/step1). I get a 404 on the server (IIS) which is to be expected, as the page doesn't exist.
What I've been trying to do all day is write a regex expression for IIS which would catch and rewrite the url, removing the fragment at the end of the url so the page is served correctly. I'd rather simply rewrite the url than having a physical file with the same name, as the content of the page will be dynamically generated, and will require scripts to get the content anyway.
The issue I've come across may be related to how I need to have the folders/scripts/styles structured on the file system. I was hoping to be able to have the whole example contained within the /backbonetest/ folder. For scripts, 'backbonetest/scripts' and so on.
I made a list of URLs which I've been testing my regex expressions against, and the results I've been trying to achieve:
Input: Output:
2
a2
ab2
ab22
step2
script.js script.js
scripts/ scripts/
555/stuff 555/stuff
scripts/script.js scripts/script.js
Edit: I've since found that the url which is used does not include the preceding slash,
which is why Qtax's solution doesn't work in IIS. The new input structure is shown above.
The '/555/stuff' url I would expect to 404 as normal. I only want to rewrite the url if there are no subdirectories defined other than the current one, and if the url doesn't reference an explicit file (one with an extension for example).
I've been scouring the net all day for a solution to this, as well as experimenting with regexr, but not managed to come up with the proper solution to my problem. After not finding a single thing anywhere, I'm thinking I must be looking at this the wrong way...
Can anyone help me out please?
After much head/desk banging, I've come up with the solution. It's irritatingly simple for all the fuss it's caused:
^[^\./]+$
Essentially:
Replace if the url doesn't contain a '/' or a '.' anywhere in it.
This should now be a solution for anyone using IIS with Backbone and HTML5 push state. Just pop it in the web.config in the root of your app, and change the rewrite action to ".", and it should just work.
This melted my brain all morning!
I've added to this - In my scenario, I have an API project which sits in an API virtual directory (to eliminate the need for CORS) - I obviously don't want to rewrite any of the PAI calls, so I re-wrote mine as follows - you can do similar for your API URLs if needed...
<rule name="Handle PushState">
<match url="^[^\./]+[^\./api]+(.*)$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="." />
</rule>

Magento - catalog.xml not using correct template

Noob developing a Magento theme and I can't seem to figure out why Magento is not using the path I specify in the setTemplate action on catalog.xml.
I've got my own theme in /app/design/frontend/default/mycustomtheme and I've been patching files over from the base and making changes.
I've copied over /app/design/frontend/base/default/layout/catalog.xml to my custom theme at /app/design/frontend/default/mycustomtheme/layout/catalog.xml. I've set the template to be a specific phtml file...
<catalog_product_view translate="label">
<label>Catalog Product View (Any)</label>
<!-- Mage_Catalog -->
<reference name="root">
<action method="setTemplate"><template>page/2column.phtml</template></action>
</reference>
Yet it's not working. Can someone spot what the problem might be? I've got all cache disabled and other changes I make I can see immediately, just not this one.
edit: I should note, if I change something else in the catalog_product_view xml node I see those changes are reflected. For instance if I remove <action method="addJs"><script>varien/product.js</script></action> then I see the reference is removed in the rendered html file.
edit2: Adding images to address questions ...
did you setup-up / configured the theme from your store backend?
Yes, and it's actually loading the correct header and footer, and it's properly styled.
Are you sure you have such template under /app/design/frontend/default/mycustomtheme/template/page/ directory?
Yes, I can confirm the file is there
OMG. The (one and only) product I was testing on had a specific layout set under the "Design" section. So I guess that was overriding anything I had set in catalog.xml
I'd like to have the 3 hours of my life back.

Docbook+Ant: Could not find variable with the name of fop.extensions

After a lot of spent time trying to get my article to compile in Ant with Docbook, I can't seem to make FO compilation work. I'm using Xalan 2.7.0, and everything else (both single-page and chunked HTML) compiles perfectly. It's only when I try to compile to FO that I get this error:
Fatal Error! org.apache.xml.utils.WrappedRuntimeException: Could not find variable with the name of fop.extensions Cause: org.apache.xml.utils.WrappedRuntimeException: Could not find variable with the name of fop.extensions
This is pretty strange and I can't seem to resolve it. I even added a <param> value defining the variable it "can't find:"
<xslt style="docbook-xsl/fo/fo.xsl" in="documents/book.xml"
out="output.fo">
<classpath>
<fileset dir="lib" includes="**/*"/>
</classpath>
<param name="fop.extensions" expression="1"/>
</xslt>
Is there anything I can do to resolve this issue? It's really weird if you ask me. (Again, using the same code as above, all of my other Docbook compilation works just fine)
Instead of using fo/fo.xsl, try fo/docbook.xsl. That is the main stylesheet for XSL-FO output.