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:

  • Simple and high performing code. 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.
  • Multiline matching which is not possible in vQmod.
  • Allowing line offsets both before AND after.
  • Virtual files meaning define your new files inside the vmod instead of uploading them separately.
  • Replace all the contents of a file (Deprecated in vQmod 2.40).
  • Cache serializing to JSON instead of PHP serialize() allowing up to 300% faster performance in fetching cache.
  • Regular expression path aliases

Concept

<?xml version="1.0" encoding="UTF-8"?>
<vmod>
  <title>Sample</title>
  <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 ...
  ]]></install>
 
  <uninstall><![CDATA[
    ... php code ...
  ]]></uninstall>
 
  <new filename="path/for/newfile.php"><![CDATA[
  ... php code ...
  ]]></new>
 
  <file path="path/to/" name="file.php,anotherfile.php">
    <operation onerror="warning|ignore|cancel">
      <find indexes="1" trim="true|false" regexp="false"><![CDATA[
        ... php code ...
      ]]></find>
      <ignoreif trim="true|false" regex="true|false"><![CDATA[
        ... php code ...
      ]]></ignoreif>
      <insert position="top|bottom|before|after|replace" offset-before="0" offset-after="0" trim="true|false" regexp="true|false"><![CDATA[
        ... php code ...
      ]]></insert>
    </operation>
  </file>
</vmod>

Lightweight Example

example.xml
<?xml version="1.0" encoding="UTF-8"?>
<vmod>
  <title>Example</title>
  <description>This is an example modification</description>
  <version>1.0</version>
  <author>acme.com</author>
 
  <file name="path/to/file.php">
    <operation>
      <find><![CDATA[
        I like green tomatoes.
      ]]></find>
      <insert position="replace"><![CDATA[
        I like green apples.
      ]]></insert>
    </operation>
  </file>
</vmod>

Examples

Inline Matching

    <operation>
      <find><![CDATA[tomatoes]]></find>
      <insert position="replace"><![CDATA[apples]]></insert>
    </operation>

Multiline Matching

    <operation>
      <find><![CDATA[
        I like green tomatoes.
        What do you like?
      ]]></find>
      <insert position="replace"><![CDATA[
        I like green apples.
        Do you have apples?
      ]]></insert>
    </operation>

Scripting

vmod > title

vmod > description

vmod > version

vmod > author

vmod > alias

vmod > file: path

vmod > file: name

vmod > file: path

vmod > file: filename

vmod > file > operation

vmod > file > operation > find

vmod > file > operation > find: regexp

vmod > file > operation > insert: trim

vmod > file > operation > insert: regexp

vmod.txt · Last modified: 2020/05/18 00:46 by admin