<?xml version="1.0"?>
<!DOCTYPE modification SYSTEM "http://www.simplemachines.org/xml/modification">
<modification xmlns="http://www.simplemachines.org/xml/modification" xmlns:smf="http://www.simplemachines.org/">
	<name>AJAX Personal Text</name>
	<id>yodaofdarkness:ajaxpersonal</id>
	<version>1.0.2</version>
	<homepage>http://www.fustrate.com</homepage>

	<file name="$sourcedir/Load.php">

		<operation>
			<search position="before"><![CDATA[
		'ignoreusers' => $user_info['ignoreusers'],]]></search>
			<add><![CDATA[
		'personal_text' => censorText($user_info['personal_text']),]]></add>
		</operation>

		<operation>
			<search position="before"><![CDATA[
	elseif ($set == 'minimal')
	{
		$select_columns = '
			mem.id_member, mem.member_name, mem.real_name, mem.email_address, mem.hide_email, mem.date_registered,]]></search>
			<add><![CDATA[ mem.personal_text,]]></add>
		</operation>

		<operation>
			<search position="before"><![CDATA[
		'permissions' => array(),]]></search>
			<add><![CDATA[
		'personal_text' => isset($user_settings['personal_text']) ? $user_settings['personal_text'] : '',]]></add>
		</operation>
	</file>

	<file name="$sourcedir/Xml.php">
		<operation>
			<search position="before"><![CDATA[
		'messageicons' => array(
			'function' => 'ListMessageIcons',
		),]]></search>
			<add><![CDATA[
		'personal' => array(
			'function' => 'PersonalText',
		),]]></add>
		</operation>

		<operation>
			<search position="end" />
			<add><![CDATA[
function PersonalText()
{
	global $context;

	updateMemberData($context['user']['id'], array('personal_text' => htmlspecialchars(quoted_printable_decode(html_entity_decode(censorText($_REQUEST['text']), ENT_QUOTES, $context['character_set'])))));

	$context['sub_template'] = 'personal_text';
}
]]></add>
		</operation>
	</file>

	<file name="$themedir/scripts/script.js">
		<operation>
			<search position="end" />
			<add><![CDATA[

// A global array containing all PersonalText objects.
var aPersonalText = new Array();

// *** PersonalText object.
function PersonalText(oOptions)
{
	if (!window.XMLHttpRequest)
		return;

	this.opt = oOptions;
	this.funcMousedownHandler = null;
	this.funcParent = this;

	this.initText();
}

// Make that personal text editable!
PersonalText.prototype.initText = function ()
{
	var personal_text = document.getElementById("update_personal_text");
	setOuterHTML(personal_text, '<span style="font-size: 80%; padding: 3px;" id="update_personal_text" title="' + this.opt.sLabelPersonalText + '" onclick="aPersonalText[0].showEdit();" onmouseover="aPersonalText[0].onBoxHover(this, true)" onmouseout="aPersonalText[0].onBoxHover(this, false)" style="cursor: ' + (is_ie && !is_ie6up ? 'hand' : 'pointer') + ';">' + personal_text.innerHTML + '</span>');
}

// Event for the mouse hovering over the text.
PersonalText.prototype.onBoxHover = function (oDiv, bMouseOver)
{
	oDiv.style.border = bMouseOver ? this.opt.iBoxBorderWidthHover + 'px solid ' + this.opt.sBoxBorderColorHover : '';
	oDiv.style.background = bMouseOver ? this.opt.sBoxBackgroundHover : this.opt.sBoxBackground;
}

// Show the input after the user has clicked the text.
PersonalText.prototype.showEdit = function ()
{
	var personal_text = document.getElementById("update_personal_text");
	setOuterHTML(personal_text, '<span style="font-size: 80%;" id="update_personal_text_span"><form style="display: inline;" onsubmit="aPersonalText[0].onInputSubmit(); return false;"><input type="hidden" id="old_personal_text" value="' + smf_htmlspecialchars(personal_text.innerHTML) + '" /><input size="50" type="text" id="new_personal_text" value="' + smf_htmlspecialchars(personal_text.innerHTML) + '" /> <input type="submit" value="' + this.opt.sLabelSubmitText + '" onclick="aPersonalText[0].onInputSubmit();" /> <input type="button" value="' + this.opt.sLabelCancelText + '" onclick="' + this.opt.sBackReference + '.cancelEdit();" /></form></span>');
}

// Make that personal text editable (again)!
PersonalText.prototype.cancelEdit = function ()
{
	var personal_text = document.getElementById("update_personal_text_span");
	var old_personal_text = document.getElementById("old_personal_text");
	setOuterHTML(personal_text, '<span style="font-size: 80%; padding: 3px;" id="update_personal_text" title="' + aPersonalText[0].sLabelPersonalText + '" onclick="aPersonalText[0].showEdit();" onmouseover="aPersonalText[0].onBoxHover(this, true)" onmouseout="aPersonalText[0].onBoxHover(this, false)" style="cursor: ' + (is_ie && !is_ie6up ? 'hand' : 'pointer') + ';">' + old_personal_text.value + '</span>');
}

// Event handler for clicking submit.
PersonalText.prototype.onInputSubmit = function ()
{
	var personal_text = document.getElementById("update_personal_text_span");
	var new_personal_text = document.getElementById("new_personal_text").value.php_to8bit();
	var new_personal_text_plain = document.getElementById("new_personal_text").value;
	
	ajax_indicator(true);
	sendXMLDocument(smf_prepareScriptUrl(this.opt.sScriptUrl) + 'action=xmlhttp;sa=personal', 'text=' + escape(new_personal_text));
	ajax_indicator(false);

	setOuterHTML(personal_text, '<span style="font-size: 80%; padding: 3px;" id="update_personal_text" title="' + aPersonalText[0].sLabelPersonalText + '" onclick="aPersonalText[0].showEdit();" onmouseover="aPersonalText[0].onBoxHover(this, true)" onmouseout="aPersonalText[0].onBoxHover(this, false)" style="cursor: ' + (is_ie && !is_ie6up ? 'hand' : 'pointer') + ';">' + new_personal_text_plain + '</span>');
}]]></add>
		</operation>
	</file>

	<file name="$themedir/index.template.php">
		<!-- // ONLY DO ONE OF THESE THREE MODIFICATIONS! -->
		<!-- // If it really doesn't look right in your theme, try a different one. -->

		<!-- // This is for the Babylon theme -->
		<operation error="ignore">
			<search position="before"><![CDATA[
		if (!empty($context['open_mod_reports']) && $context['show_open_reports'])
			echo '
								<a href="', $scripturl, '?action=moderate;area=reports">', sprintf($txt['mod_reports_waiting'], $context['open_mod_reports']), '</a>';]]></search>
			<add><![CDATA[
		echo '<br />
								<span style="font-size: 80%; padding: 3px;" id="update_personal_text">', !empty($context['user']['personal_text']) ? $context['user']['personal_text'] : $txt['ajax_personal_text_none'], '</span>
					<script language="JavaScript" type="text/javascript"><!-- // -->
						// Ajaxify that personal text!
						if (typeof(window.XMLHttpRequest) != "undefined")
						{
							aPersonalText[0] = new PersonalText({
								sBackReference: "aPersonalText[0]",
								sScriptUrl: "', $scripturl, '",
								sLabelPersonalText: "', $txt['personal_text'], '",
								sLabelSubmitText: "', $txt['save'], '",
								sLabelCancelText: "', $txt['modify_cancel'], '",
								sBoxBackground: "transparent",
								sBoxBackgroundHover: "#ffffff",
								iBoxBorderWidthHover: 1,
								sBoxBorderColorHover: "#adadad" ,
								sItemBorder: "1px solid #ffffff",
								sItemBorderHover: "1px dotted gray",
								sItemBackground: "transparent",
								sItemBackgroundHover: "#e0e0f0"
							});
						}
					</script>]]></add>
		</operation>

		<!-- // This is for the Classic theme -->
		<operation error="ignore">
			<search position="before"><![CDATA[
	// Show a random news item? (or you could pick one from news_lines...)
	if (!empty($settings['enable_news']))
		echo '
		<tr class="windowbg2">
			<td colspan="2" height="24" class="tborder" style="border-width: 1px 0 0 0; padding-left: 1ex;">
				<b>', $txt['news'], ':</b> ', $context['random_news_line'], '
			</td>
		</tr>';]]></search>
			<add><![CDATA[
	// Show the AJAX Personal Text!
	echo '
		<tr class="windowbg2">
			<td colspan="2" height="24" class="tborder" style="border-width: 1px 0 0 0; padding-left: 1ex;">
				<span style="font-size: 80%; padding: 3px;" id="update_personal_text">', !empty($context['user']['personal_text']) ? $context['user']['personal_text'] : $txt['ajax_personal_text_none'], '</span>
					<script language="JavaScript" type="text/javascript"><!-- // -->
						// Ajaxify that personal text!
						if (typeof(window.XMLHttpRequest) != "undefined")
						{
							aPersonalText[0] = new PersonalText({
								sBackReference: "aPersonalText[0]",
								sScriptUrl: "', $scripturl, '",
								sLabelPersonalText: "', $txt['personal_text'], '",
								sLabelSubmitText: "', $txt['save'], '",
								sLabelCancelText: "', $txt['modify_cancel'], '",
								sBoxBackground: "transparent",
								sBoxBackgroundHover: "#ffffff",
								iBoxBorderWidthHover: 1,
								sBoxBorderColorHover: "#adadad" ,
								sItemBorder: "1px solid #ffffff",
								sItemBorderHover: "1px dotted gray",
								sItemBackground: "transparent",
								sItemBackgroundHover: "#e0e0f0"
							});
						}
					</script>
			</td>
		</tr>';]]></add>
		</operation>
	
		<!-- // Semantic themes, introduced in SMF 2.0 Beta 4 -->
		<operation error="ignore">
			<search position="before"><![CDATA[
	if ($context['user']['is_logged'])
		echo '
			<li id="name">', $txt['hello_member_ndt'], ' <em>', $context['user']['name'], '</em>]]></search>
			<add><![CDATA[ &raquo; <span style="font-size: 80%; padding: 3px;" id="update_personal_text">', !empty($context['user']['personal_text']) ? $context['user']['personal_text'] : $txt['ajax_personal_text_none'], '</span>
					<script language="JavaScript" type="text/javascript"><!-- // -->
						// Ajaxify that personal text!
						if (typeof(window.XMLHttpRequest) != "undefined")
						{
							aPersonalText[0] = new PersonalText({
								sBackReference: "aPersonalText[0]",
								sScriptUrl: "', $scripturl, '",
								sLabelPersonalText: "', $txt['personal_text'], '",
								sLabelSubmitText: "', $txt['save'], '",
								sLabelCancelText: "', $txt['modify_cancel'], '",
								sBoxBackground: "transparent",
								sBoxBackgroundHover: "#ffffff",
								iBoxBorderWidthHover: 1,
								sBoxBorderColorHover: "#adadad" ,
								sItemBorder: "1px solid #ffffff",
								sItemBorderHover: "1px dotted gray",
								sItemBackground: "transparent",
								sItemBackgroundHover: "#e0e0f0"
							});
						}
					</script>]]></add>
		</operation>
	
		<!-- // And this should be for all other themes -->
		<operation error="ignore">
			<search position="before"><![CDATA[
					<span style="font-size: 130%;"> ', $txt['hello_member_ndt'], ' <b>', $context['user']['name'] , '</b></span>]]></search>
			<add><![CDATA[ &raquo; <span style="font-size: 80%; padding: 3px;" id="update_personal_text">', !empty($context['user']['personal_text']) ? $context['user']['personal_text'] : $txt['ajax_personal_text_none'], '</span>
					<script language="JavaScript" type="text/javascript"><!-- // -->
						// Ajaxify that personal text!
						if (typeof(window.XMLHttpRequest) != "undefined")
						{
							aPersonalText[0] = new PersonalText({
								sBackReference: "aPersonalText[0]",
								sScriptUrl: "', $scripturl, '",
								sLabelPersonalText: "', $txt['personal_text'], '",
								sLabelSubmitText: "', $txt['save'], '",
								sLabelCancelText: "', $txt['modify_cancel'], '",
								sBoxBackground: "transparent",
								sBoxBackgroundHover: "#ffffff",
								iBoxBorderWidthHover: 1,
								sBoxBorderColorHover: "#adadad" ,
								sItemBorder: "1px solid #ffffff",
								sItemBorderHover: "1px dotted gray",
								sItemBackground: "transparent",
								sItemBackgroundHover: "#e0e0f0"
							});
						}
					</script>]]></add>
		</operation>
	</file>

	<file name="$themedir/Xml.template.php">
		<operation>
			<search position="end" />
			<add><![CDATA[
function template_personal_text()
{
	global $context;

	echo '<', '?xml version="1.0" encoding="', $context['character_set'], '"?', '>
<smf>
	<roflcopter value="2kcashmunee" />
</smf>';
}
]]></add>
		</operation>
	</file>

	<file name="$languagedir/Modifications.english.php">
		<operation>
			<search position="end" />
			<add><![CDATA[
$txt['ajax_personal_text_none'] = '<i>No Personal Text</i>';
$txt['personal_text'] = 'Personal Text';]]></add>
		</operation>
	</file>

	<file name="$languagedir/Modifications.english-utf8.php" error="ignore">
		<operation>
			<search position="end" />
			<add><![CDATA[
$txt['ajax_personal_text_none'] = '<i>No Personal Text</i>';
$txt['personal_text'] = 'Personal Text';]]></add>
		</operation>
	</file>

</modification>
