Webserver software – Virtual Quick Mod tutorial (PHP)

vQmod logo

Website

Met vQmod kun je “virtueel” aanpassingen maken aan een PHP broncode zonder dat bronbestanden aangepast worden, zo kun je heel makkelijk wat experimenteren en debuggen.

Het is oorspronkelijk bedoelt voor Opencart, maar je kan vQmod ook zelf toepassen op bestanden.

Wat heb je nodig?
1) vQmod software

Aan de slag
1) Maak een folder aan en pak vQmod uit in die folder, zodat je de volgende structuur krijgt:

2) Maak een “test” bestand aan in de hoofdmap genaamd “testbestand.php“, met daarin de volgende inhoud:

Ps. Als je bovenstaand bestand in de webbrowser open, krijg je ABC te zien.

3) In het kort werkt vQmod zo: Manipuleert “core” bestanden met wijzigingen in XML opgegeven bestanden en slaat de wijzigingen op in een “temp/cache” folder.

Maak een folder aan genaamd xml in de vQmod folder, de structuur ziet er nu zo uit:

Maak een XML bestand aan in de XML folder genaamd “test.xml” met daarin de volgende inhoud:

In dit bestand geef je de bestandsnaam op en de wijzigingen die daarin aangemaakt moeten worden, de structuur is nu als volgt:

Ps. de naam van het bestand maakt niet uit, zolang er geen vreemde karakters in zitten en eindigd op XML, alle XML bestanden in deze folder worden doorgelezen.

In het bovenstaande XML bestand wordt er naar de string “ABC” gezocht en deze wordt vervangen naar “123“.

Maak een index.php bestand aan, vQmod werkt namelijk met includes van php bestanden, alleen op deze manier worden de bestanden “gemanipuleerd”. geef index.php de volgende inhoud:

De structuur is nu:

Als je nu de browser open zie je 123 staan, zonder dat de core bestanden zijn aangepast!

Ps. er wordt een cache bestand aangemaakt, zoals bijvoorbeeld: “vqmod\vqcache\vq2-testbestand.php

Let op: Zorg dat alle folder schrijfbaar zijn en/of de juiste machtigingen hebben, anders werkt vQmod niet!


Enkele voorbeelden (ENG):

“Replace” Example

  1. Create a new text file and call it “replace-demo.xml”
  2. Add the minimum required xml structure

Input

$var = 'ABC';

Script

Output

“Before” Example

  1. Create a new text file and call it “before-demo.xml”
  2. Add the minimum required xml structure

Input

$var = 'ABC';

Script

Output

“After” Example

  1. Create a new text file and call it “after-demo.xml”
  2. Add the minimum required xml structure

Input

$var = 'ABC';

Script

Output

<ignoreif> tag Example (2.3.0+)

  1. Create a new text file and call it “ignoreif-after-demo.xml”
  2. Add the minimum required xml structure

Input

Script

Output

Multiple files and a base path example (2.3.0+)

Sometimes you require adding the same modification to a number of files at once. Rather than having to do this for individual files and duplicating code for each, you can specify multiple files at once delimited by commas. You can also specify a base path to be used if the files are in a common directory. For example, suppose you want to replace ABC with 123 in the following files

  • /path/to/a.php
  • /path/to/b.php
  • /path/to/c.php
  1. Create a new text file and call it “multi-file-demo.xml”
  2. Add the minimum required xml structure

Input (all files)

$var = 'ABC';

Script

Output (all files)

$var = '123';

‘Multi-line Replace’ Example

vQmod is limited to a single-line search, but you can use the “offset” attribute to blindly blanket additional lines of code in the replace.

  • Create a new text file and call it “multi-replace-demo.xml”
  • Add the minimum required xml structure
  • To replace multiple lines we use the “offset” attribute with replace. Count the number of total lines to replace and subtract one as the main line is already covered by the replace command. In this example, there are 8 lines of code, so offset would be 7. When possible it’s advised to avoid doing this

Input

Script

Output

Note there are still 7 blank lines. The offset clears the extra 7 lines of code from the input, but the replaced code is added in place of the initial line. So there will be 7 extra spaces after the new code, but it will not affect the code functionality, only the look of the vqcache file which is of no importance.