Developers

Modification System

Commentics provides a modification system to avoid editing core files. This helps preserve your changes when upgrading and makes it easy to install modules. To use the modification system you just create an XML file describing which file you want to edit and the code you want to add/replace. After uploading the XML file to the /system/modification/ folder, Commentics will virtually modify the core file without actually doing so. The virtually modified file will be saved to /system/cache/modification/.

Let's dive straight into an example:

                        <?xml version="1.0" encoding="utf-8"?>
                        <modification>
                          <name>Comment Count</name>
                          <version>1.0</version>
                          <author>Steven</author>
                          <link>https://commentics.com</link>
                         
                          <file path="frontend/controller/main/comments.php">
                            <operation>
                              <search><![CDATA[
                              $this->data['lang_heading_comments'] .= ' (' . $this->data['total'] . ')';
                              ]]></search>
                              <add position="replace"><![CDATA[
                              $this->data['lang_heading_comments'] .= ' [' . $this->data['total'] . ']';
                              ]]></add>
                            </operation>
                          </file>
                         
                        </modification>
                    

In the above example, we're changing the comments heading, e.g. "Comments (27)". More specifically, we're changing the curly brackets to square brackets, resulting in "Comments [27]"

The 'name, 'version, 'author' and 'link' tags are only informational so put what you like there.

Let's look at the other tags.

file

The location of the file you want to modify. Using "backend/" will work even if you've renamed your backend folder.

operation

You can have many operation tags within the file tag.

search

The piece of code that you want to modify. It's best to search for the smallest amount of code possible as this gives the highest chance that it will stay unchanged when upgrading.

add

The piece of code you want to add. Use the 'position' attribute to determine where the piece of code is added. Possible values are 'before', 'after' and 'replace'. You can also add an attribute called 'offset'. For example if you want to add the piece of code 2 lines after the search, use position="after" offset="2".

Other Notes

The filename of the XML file can be anything. However it's wise to give it a descriptive filename so you'll know what it's meant for without having to open it.

If the searched code is changed in an upgrade, meaning the XML file can no longer find it, the worst that will happen is the modification will be aborted and the original, core code will be used. Also a log file will be created in /system/logs/ explaining what happened.