Modification.xml

From SMFMods

Jump to: navigation, search


Modification XML files (often referred to as "modification.xml" as this is the file name commonly used) are files that contain a list of changes done to SMF's files. If your mod needs to edit some of SMF's files, you'll need a modification.xml file.

In its simplest form, a modification.xml file might look like (this is an excerpt of the SMFShop install_SMF1-1.xml file):

<?xml version="1.0"?>
<?xml-stylesheet href="modification.xsl" type="text/xsl"?>
<!DOCTYPE modification SYSTEM "http://www.simplemachines.org/xml/modification">
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	ATTENTION: If you are trying to install this manually, you should try
	the package manager.  If it will not work for you, please take a look
	at the following for information on this format:
		http://mods.simplemachines.org/docs/manual-install.php
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
 
<modification xmlns="http://www.simplemachines.org/xml/modification" xmlns:smf="http://www.simplemachines.org/">
	<id>Daniel15:SMFShop</id>
	<version>3.0</version>
 
	<file name="$boarddir/index.php">
		<operation>
			<search position="before"><![CDATA[
		'.xml' => array('News.php', 'ShowXmlFeed'),
]]></search>
			<add><![CDATA[
		// Begin SMFShop code
		'shop' => array('shop/Shop.php', 'Shop'),
		'shop_general' => array('shop/ShopAdmin.php', 'ShopGeneral'),
		'shop_inventory' => array('shop/ShopAdmin.php', 'ShopInventory'),
		'shop_items_add' => array('shop/ShopAdmin.php', 'ShopItemsAdd'),
		'shop_items_edit' => array('shop/ShopAdmin.php', 'ShopItemsEdit'),
		'shop_restock' => array('shop/ShopAdmin.php', 'ShopRestock'),
		'shop_usergroup' => array('shop/ShopAdmin.php', 'ShopUserGroup'),	
		'shop_cat' => array('shop/ShopAdmin.php', 'ShopCategories'),
		// End SMFShop code
]]></add>
		</operation>
	</file>
</modification>

The id and version tags should be the same as the ones in the package-info.xml file.

[edit] <file> sections

Compared to a package-info.xml file, a modification.xml file is a lot simpler. It consists of multiple file elements, one for each file edited:

<file name="$boarddir/index.php">

The name attribute specified the name of the file to edit ($boarddir, etc are documented on the package-info.xml page). There is also an optional error attribute, which should be set to skip if the file may not exist (eg. for files that should only be edited if another language is installed):

<file name="$languagedir/Modification.turkish.php" error="skip">

[edit] Operations

Inside this <file> element, there are multiple "operations". Each operation consists of a "search" tag, and a "add" tag. Inside the search tag is what to search for, and inside the add tag is what to add.

<operation>
	<search position="before"><![CDATA[
What to search for.
]]></search>
	<add><![CDATA[
What to add.
]]></add>
</operation>

The CDATA tags keep everything clean, by escaping symbols like < and >. [1]

The "position" attribute is the position of the search code relative to the code you're adding. Some people get confused over this. So, in this example, the code we're searching for is before the code we're adding (in other words, the code we're adding will be added after the code we're searching for).


[edit] References

  1. http://www.w3schools.com/xml/xml_cdata.asp
Personal tools