My "Help Me" Thread - learning XML

AWC108

New Member
Hi guys,

I understand and know enough about HTML and CSS (if not I'll learn more). I want to code vBulletin Plugins. I downloaded a simple addon only plugin to understand what each line means. I do understand some of it but most make me lost!

If you guys could kindly help me work through these helps, I will really appreciate it. I want to code a lot but I don't know how.

Here is a test I downloaded.

Personal Notepad
Download : zSHARE - product-personal_notepad.xml
Info : Personal Notepad for 3.7 - vBulletin.org Forum

Install Note
INSTALLATION

1. Import product-personal_notepad.xml through the Admin CP.
2. Edit the Personal Notepad options in the vBulletin options if desired. (It is automatically turned on upon installation, so if you want to start using it right away without worrying about the options, you can.)
3. If desired, edit the default message that appears for members who have not put anything into their personal notepads - search for the phrase personal_notepad_explanation in the Admin CP and edit the language of your choice.
4. There is no 4. You're done. Go inform your members of the addition.

Things I don't get what they do/where they come from/need explanation:
- how does the <installcode> work? how did the coder get $db
- where is $stylevar[align=right] come from? don't see it in vB variables if there is, what are its values?
- will love a quick explanation of what each section does

PHP:
<?xml version="1.0" encoding="ISO-8859-1"?>

<product productid="personal_notepad" active="1">
	<title>Personal Notepad</title>
	<description>Give users a personal notepad they can store text in.</description>
	<version>4.1</version>
	<url>http://www.vbulletin.org/forum/showthread.php?t=181811</url>
	<versioncheckurl><![CDATA[http://www.vbulletin.org/forum/misc.php?do=checkversion&t=181811]]></versioncheckurl>
	<dependencies>
	</dependencies>
	<codes>
		<code version="1.0">
			<installcode><![CDATA[$db->query_write("
ALTER TABLE " . TABLE_PREFIX . "usertextfield
ADD notepad TEXT
");]]></installcode>
			<uninstallcode><![CDATA[$db->query_write("
ALTER TABLE " . TABLE_PREFIX . "usertextfield
DROP notepad
");]]></uninstallcode>
		</code>
	</codes>
	<templates>
		<template name="personal_notepad" templatetype="template" date="1214328259" username="Butterfree" version="4.0"><![CDATA[<form name="personalnotepad" method="post" action="usercp.php$session[sessionurl_q]">
<table class="tborder" width="100%" cellspacing="$stylevar[cellspacing]" cellpadding="$stylevar[cellpadding]" align="center">
<thead>
<tr>
<td class="tcat"><a style="float:$stylevar[align=right];" href="#top" onclick="return toggle_collapse('notepad');"><img id="collapseimg_notepad" src="$stylevar[imgdir_button]/collapse_tcat$vbcollapse[collapseimg_notepad].gif" alt="" border="0"></a> $vbphrase[personal_notepad]</td>
</tr>
</thead>
<tbody id="collapseobj_notepad" style="$vbcollapse[collapseobj_notepad]">
<tr>
<td class="panelsurround" align="center">
<div class="panel">
<textarea name="notepad" id="notepad" rows="7" cols="$vboptions[personal_notepad_cols]"<if condition="$vbulletin->options['personal_notepad_liquid']"> style="width:95%"</if>><if condition="$vbulletin->userinfo['notepad']">{$vbulletin->userinfo['notepad']}<else />$vbphrase[personal_notepad_explanation]</if></textarea>
<div class="smallfont" style="<if condition="$vbulletin->options['personal_notepad_liquid']">text-align:left;</if>width:95%;margin:auto"><if condition="$vbulletin->options['personal_notepad_liquid']"><span style="float:$stylevar[align=right]"><phrase 1="$notepadlength" 2="$vboptions[personal_notepad_maxlength]">$vbphrase[you_have_used_x_y_characters]</phrase></span></if> <a href="#" onclick="return resize_notepad(true)">$vbphrase[increase_size]</a> <a href="#" onclick="return resize_notepad(false)">$vbphrase[decrease_size]</a><if condition="!$vbulletin->options['personal_notepad_liquid']"><br /><phrase 1="$notepadlength" 2="$vboptions[personal_notepad_maxlength]">$vbphrase[you_have_used_x_y_characters]</phrase></if>
</div>
</div>
<div style="margin-top:$stylevar[cellpadding]px">
<input type="hidden" name="do" value="savenotepad" />
<input type="hidden" name="securitytoken" value="$bbuserinfo[securitytoken]" />
<input type="submit" value="$vbphrase[save_notepad]" />
</div>
</td>
</tr>
</tbody>
</table>
</form>
<script type="text/javascript">
var notepad = fetch_object('notepad');
var counter = fetch_object('notepad_charcounter');

function checklength() {
   if (notepad.value.length > {$vbulletin->options['personal_notepad_maxlength']}) {
      counter.className = "highlight";
   }
   else {
      counter.className = "";
   }
   counter.innerHTML = notepad.value.length;
}

function resize_notepad (add) {
   if (add) {
      notepad.rows += 5;
   }
   else {
      notepad.rows -= 5;
   }
   return false;
}

notepad.onkeyup = checklength;
<if condition="!$vbulletin->userinfo['notepad']">notepad.onfocus = function() { notepad.innerHTML = ""; notepad.onfocus = ""; };</if>
checklength();
</script>
<br />]]></template>
	</templates>
	<plugins>
		<plugin active="1" executionorder="5">
			<title>Cache the Personal Notepad template</title>
			<hookname>cache_templates</hookname>
			<phpcode><![CDATA[if (THIS_SCRIPT == 'usercp')
{
   $globaltemplates[] = 'personal_notepad';
}]]></phpcode>
		</plugin>
		<plugin active="1" executionorder="5">
			<title>Save personal notepad and add template</title>
			<hookname>usercp_complete</hookname>
			<phpcode><![CDATA[if ($vbulletin->options['personal_notepad_onoff'] AND (is_member_of($vbulletin->userinfo, explode(",", $vbulletin->options['personal_notepad_usergroups'])) OR $vbulletin->options['personal_notepad_usergroups'] == ""))
{
	if ($_REQUEST['do'] == 'savenotepad')
	{
		$vbulletin->input->clean_gpc('p', 'notepad', TYPE_STR);
		if (strlen($vbulletin->GPC['notepad']) > $vbulletin->options['personal_notepad_maxlength'])
		{
			standard_error(fetch_error('personal_notepad_input_too_long'));
		}
		else
		{
			$userdata =& datamanager_init('User', $vbulletin, ERRTYPE_STANDARD);
			$userdata->set_existing($vbulletin->userinfo);
			$userdata->setr('notepad', $vbulletin->GPC['notepad']);
			$userdata->save();

			$vbulletin->url = 'usercp.php' . $vbulletin->session->vars['sessionurl_q'];
			eval(print_standard_redirect('redirect_notepad_saved', true, true));
		}
	}
	$notepadlength = strlen($vbulletin->userinfo['notepad']);
	eval('$template_hook["usercp_main_pos' . $vbulletin->options['notepad_location'] . '"] .= "' . fetch_template('personal_notepad') . '";');
}]]></phpcode>
		</plugin>
		<plugin active="1" executionorder="5">
			<title>Notepad is in usertextfield</title>
			<hookname>userdata_doset</hookname>
			<phpcode><![CDATA[if ($fieldname == 'notepad')
{
   $tables = array('usertextfield');
}]]></phpcode>
		</plugin>
		<plugin active="1" executionorder="5">
			<title>Make notepad valid</title>
			<hookname>userdata_start</hookname>
			<phpcode><![CDATA[$this->validfields['notepad'] = array(TYPE_NOHTML, REQ_NO);]]></phpcode>
		</plugin>
	</plugins>
	<phrases>
		<phrasetype name="Error Messages" fieldname="error">
			<phrase name="personal_notepad_input_too_long" date="1194112473" username="Butterfree" version="1.1"><![CDATA[Your Personal Notepad exceeded the administrator's set character limit for the notepad.]]></phrase>
		</phrasetype>
		<phrasetype name="Front-End Redirect Messages" fieldname="frontredirect">
			<phrase name="notepad_saved" date="0" username="" version=""><![CDATA[Your personal notepad has been saved.]]></phrase>
		</phrasetype>
		<phrasetype name="User Tools (global)" fieldname="user">
			<phrase name="personal_notepad" date="0" username="" version=""><![CDATA[Personal Notepad]]></phrase>
			<phrase name="personal_notepad_explanation" date="1212859538" username="Butterfree" version="4.0"><![CDATA[This is your personal notepad, where you can store whatever you like up to the character limit - post drafts, threads you want to remember to reply to, or whatever else crosses your mind. You are the only person who can see this notepad, so go wild - it's not encrypted in the database, however, so don't put sensitive information in here.]]></phrase>
			<phrase name="save_notepad" date="1194278470" username="Butterfree" version="3.0"><![CDATA[Save Notepad]]></phrase>
			<phrase name="you_have_used_x_y_characters" date="1194278609" username="Butterfree" version="3.0"><![CDATA[You have used <span id="notepad_charcounter">{1}</span>/{2} characters.]]></phrase>
		</phrasetype>
		<phrasetype name="vBulletin Settings" fieldname="vbsettings">
			<phrase name="setting_notepad_location_desc" date="1212860186" username="Butterfree" version="4.0"><![CDATA[Where on the User CP main page the personal notepad should be located. Valid locations are 1, 2, 3, 4, 5 and 6; 1 is at the very top of the User CP main page while 6 is at the very bottom, and the other four place it in between the various notifications.]]></phrase>
			<phrase name="setting_notepad_location_title" date="1212860186" username="Butterfree" version="4.0"><![CDATA[Personal Notepad Location]]></phrase>
			<phrase name="setting_personal_notepad_cols_desc" date="1194107231" username="Butterfree" version="1.1"><![CDATA[The width of the Personal Notepad, in columns. This does not apply if the notepad is liquid-width.]]></phrase>
			<phrase name="setting_personal_notepad_cols_title" date="1194107231" username="Butterfree" version="1.1"><![CDATA[Notepad width]]></phrase>
			<phrase name="setting_personal_notepad_liquid_desc" date="1194106943" username="Butterfree" version="1.1"><![CDATA[If yes, the Personal Notepad will stretch to completely fill the box around it. If no, it will be centered and fixed-width and the width can be edited below.]]></phrase>
			<phrase name="setting_personal_notepad_liquid_title" date="1194106943" username="Butterfree" version="1.1"><![CDATA[Make Personal Notepad liquid-width?]]></phrase>
			<phrase name="setting_personal_notepad_maxlength_desc" date="1194106797" username="Butterfree" version="1.1"><![CDATA[Specify the maximum number of characters that users may input into their Personal Notepad. Maximum allowed by the database is 65535 characters.]]></phrase>
			<phrase name="setting_personal_notepad_maxlength_title" date="1194106797" username="Butterfree" version="1.1"><![CDATA[Maximum input for Personal Notepad]]></phrase>
			<phrase name="setting_personal_notepad_onoff_desc" date="1194106617" username="Butterfree" version="1.1"><![CDATA[Select No if you want to disable the Personal Notepad.]]></phrase>
			<phrase name="setting_personal_notepad_onoff_title" date="1194106617" username="Butterfree" version="1.1"><![CDATA[Enable Personal Notepad?]]></phrase>
			<phrase name="setting_personal_notepad_usergroups_desc" date="1194280077" username="Butterfree" version="3.0"><![CDATA[The usergroup IDs that may use the Personal Notepad, separated by commas. Leave blank to allow any usergroup to use it. Example: 5,6,7]]></phrase>
			<phrase name="setting_personal_notepad_usergroups_title" date="1194280077" username="Butterfree" version="3.0"><![CDATA[Usergroups allowed to use Personal Notepad]]></phrase>
			<phrase name="settinggroup_personal_notepad" date="1194106503" username="Butterfree" version="1.1"><![CDATA[Personal Notepad]]></phrase>
		</phrasetype>
	</phrases>
	<options>
		<settinggroup name="personal_notepad" displayorder="6700">
			<setting varname="personal_notepad_onoff" displayorder="1">
				<datatype>boolean</datatype>
				<optioncode>yesno</optioncode>
				<defaultvalue>1</defaultvalue>
			</setting>
			<setting varname="personal_notepad_maxlength" displayorder="2">
				<datatype>number</datatype>
				<defaultvalue>65535</defaultvalue>
			</setting>
			<setting varname="personal_notepad_liquid" displayorder="12">
				<datatype>boolean</datatype>
				<optioncode>yesno</optioncode>
				<defaultvalue>0</defaultvalue>
			</setting>
			<setting varname="personal_notepad_cols" displayorder="22">
				<datatype>number</datatype>
				<defaultvalue>45</defaultvalue>
			</setting>
			<setting varname="personal_notepad_usergroups" displayorder="32">
				<datatype>free</datatype>
				<validationcode><![CDATA[return (preg_match('#^(\d+,*)*$#', $data) > 0);]]></validationcode>
			</setting>
			<setting varname="notepad_location" displayorder="42">
				<datatype>posint</datatype>
				<defaultvalue>1</defaultvalue>
			</setting>
		</settinggroup>
	</options>
	<helptopics>
	</helptopics>
	<cronentries>
	</cronentries>
	<faqentries>
	</faqentries>
</product>
 
Top