User Tools

Site Tools


vmod

vMod by LiteCart

vMod is a virtual modification technology specially developed for LiteCart. The work is inspired by vQmod originally created by Qphoria.

vMod focuses on lightweight and simplicity but also introduces features previously not seen in vQmod. Some of the notorious differences are:

  • Super optimized and simple. A little over half the footprint of vQmod (16 kb instead of 26kb).
  • String aliases allowing you to define one value for all occurrences in the file.
  • Configurable with user defined settings
  • Multiline matching supported
  • Allowing line offsets both before AND after.
  • Cache serializing to JSON instead of PHP serialize() allowing up to 300% faster performance in fetching cache.
  • Regular expression path aliases

Basic Example

storage/addons/my_fancy_addon/vmod.xml
<?xml version="1.0" encoding="UTF-8"?>
<vmod>
  <namee>My Fancy Add-on</name>
  <description>This is an example modification</description>
  <version>1.0</version>
  <author>acme.com</author>
 
  <file name="path/to/file.php">
    <operation method="replace">
      <find><![CDATA[
        I like green tomatoes.
      ]]></find>
      <insert><![CDATA[
        I like green apples.
      ]]></insert>
    </operation>
  </file>
</vmod>

Cheat Sheet

<?xml version="1.0" encoding="UTF-8"?>
<vmod marketplace-id="123456">
  <name>Sample</name>
  <description>This is a sample modification</description>
  <version>1.0</version>
  <author>acme.com</author>
  <priority>0</priority>
 
  <alias key="foo" value="bar" />
 
  <setting>
    <title>Foo</title>
    <description>Description of foo.</description>
    <key>foo</key>
    <function>text()</function>
    <default_value>bar</default_value>
  </setting>
 
  <install><![CDATA[
  ...PHP code that runs during install...
  ]]></install>
 
  <uninstall><![CDATA[
  ...PHP code that runs during uninstall...
  ]]></uninstall>
 
  <upgrade version="1.1"><![CDATA[
  ...PHP code that runs after installing an update...
  ]]></upgrade>
 
  <file name="path/or/glob*/to/{file1,file2}.php">
    <operation method="top|bottom|before|after|replace" type="multiline|inline|regex" onerror="warning|ignore|cancel">
      <find indexes="1,3" offset-before="0" offset-after="0"><![CDATA[
        ...
      ]]></find>
 
      <insert><![CDATA[
        ...
      ]]></insert>
    </operation>
  </file>
</vmod>

Examples

Inline Matching

    <operation method="replace" type="inline">
      <find><![CDATA[oranges]]></find>
      <insert><![CDATA[apples]]></insert>
    </operation>

Multiline Matching

    <operation>
      <find method="replace" type="multiline"><![CDATA[
        I like apples.
        I like oranges.
      ]]></find>
      <insert><![CDATA[
        I like apples and oranges.
      ]]></insert>
    </operation>

Regular Expression Matching

    <operation method="replace" type="regex">
      <find><![CDATA[#^I like (apples)\.$#m]]></find>
      <insert position="replace"><![CDATA[I don't like $1.]]></insert>
    </operation>

Alias

Alias is a way to define a repetitive value or content.

  <alias key="foo" value="bar" />

A defined alias will substitute all occurences of {alias:keyname} in the code with the defined value.

Settings

Settings will allow the merchant to configure the vMod by collecting user defined settings. The settings will be output in the code by the use of a snippet tag {setting:keyname}.

  <setting>
    <title>Foo</title>
    <description>Description of foo.</description>
    <key>foo</key>
    <function>text()</function>
    <default_value>bar</default_value>
  </setting>

The example above will produce an alias {setting:foo} that is substituted in the code with the actual value configured by the merchant.

For a list of helper functions that can be used for setting values see form_draw_function() in includes/functions/func_form.inc.php. Commmonly used functions are text(), textarea(), password(), number(), decimal(), date(), toggle(“y/n”), select(“a”,“b”).

vmod.txt · Last modified: 2022/10/17 22:18 by tim