<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="http://www.fustrate.com/dev/sources/Other/modification.xsl"?>
<!DOCTYPE modification SYSTEM "http://www.simplemachines.org/xml/modification">
<modification xmlns="http://www.simplemachines.org/xml/modification" xmlns:smf="http://www.simplemachines.org/">
	<id>fustrate:twitly</id>
	<version>1.0.2</version>

	<file name="$sourcedir/Post.php">
		<operation>
			<search position="replace"><![CDATA[

	// Are we posting this to Twitter?
	if (allowedTo('post_twitter') && $board_info['allow_twitter'] && isset($_POST['post_twitter']) && isset($modSettings['twitter_login']) && isset($modSettings['twitter_pass'])){
		$tweet = $_POST['subject'];

		// Can we use bit.ly? Add it to the beginning of the tweet.
		if (isset($modSettings['bitly_login']) && isset($modSettings['bitly_key'])){
			// Just in case it wasn't global before, cuz we'll need it
			global $scripturl;

			// Save it for the check further on.
			$can_bitly = true;

			$tweet = create_bitly($scripturl . '?topic=' . $topic . (isset($_REQUEST['msg']) ? '.msg' . $_REQUEST['msg'] . '#msg' . $_REQUEST['msg'] : '')) . ' ' . $tweet;
		}

		// Let's take a look at the first lines of the topic - is it twitterish?
		$lines = explode("<br />", $msgOptions['body']);

		if (isset($can_bitly) && file_get_contents(($lines[0]))){
			$tweet .= ' ' . create_bitly(trim($lines[0]));

			// Remove the first line for the next part.
			$lines = array_slice($lines, 1);
		}

		// Add the new first line, for any #stuff or @things (I don't use twitter, so excuse my noobishness)
		if (in_array(substr($lines[0], 0, 1), array('#', '@')))
			$tweet .= ' ' . $lines[0];

		update_twitter($tweet);
	}]]></search>
			<add><![CDATA[

	// Are we posting this to Twitter?
	if (allowedTo('post_twitter') && $board_info['allow_twitter'] && isset($_POST['post_twitter']) && isset($modSettings['twitter_login']) && isset($modSettings['twitter_pass'])){
		$tweet = $_POST['subject'];

		// Can we use bit.ly? Add it to the beginning of the tweet.
		if (isset($modSettings['bitly_login']) && isset($modSettings['bitly_key'])){
			// Just in case it wasn't global before, cuz we'll need it
			global $scripturl;

			// Save it for the check further on.
			$can_bitly = true;

			$message_id = !empty($_REQUEST['msg']) ? $_REQUEST['msg'] : $msgOptions['id'];

			$tweet = create_bitly($scripturl . '?topic=' . $topic . '.msg' . $message_id . '%23msg' . $message_id) . ' ' . $tweet;
		}

		if (!isset($_POST['ignore_twitter'])){
			// Let's take a look at the first lines of the topic - is it twitterish?
			$lines = explode("<br />", $msgOptions['body']);

			if (isset($can_bitly) && file_get_contents(($lines[0]))){
				$tweet .= ' ' . create_bitly(trim($lines[0]));

				// Remove the first line for the next part.
				$lines = array_slice($lines, 1);
			}

			// Add the new first line, for any #stuff or @things (I don't use twitter, so excuse my noobishness)
			if (in_array(substr($lines[0], 0, 1), array('#', '@')))
				$tweet .= ' ' . $lines[0];
		}

		update_twitter($tweet);
	}]]></add>
		</operation>
	</file>

	<file name="$themedir/Post.template.php">
		<operation>
			<search position="replace"><![CDATA[
														<td class="smalltext"><label for="post_twitter"><input type="checkbox" name="post_twitter" id="post_twitter" class="check" /> ' . $txt['post_to_twitter'] . '</label></td>
														<td class="smalltext"></td>]]></search>
			<add><![CDATA[
														<td class="smalltext"><label for="post_twitter"><input type="checkbox" name="post_twitter" id="post_twitter" class="check" /> ' . $txt['post_to_twitter'] . '</label></td>
														<td class="smalltext"><label for="ignore_twitter"><input type="checkbox" name="ignore_twitter" id="ignore_twitter" class="check" /> ' . $txt['ignore_twitter'] . '</label></td>]]></add>
		</operation>
	</file>

	<file name="$languagedir/Modifications.english.php">
		<operation>
			<search position="before"><![CDATA[
$txt['post_to_twitter'] = 'Post to Twitter';]]></search>
			<add><![CDATA[
$txt['ignore_twitter'] = 'Minimal Tweet';]]></add>
		</operation>
	</file>

	<file name="$languagedir/Modifications.english-utf8.php" error="skip">
		<operation>
			<search position="before"><![CDATA[
$txt['post_to_twitter'] = 'Post to Twitter';]]></search>
			<add><![CDATA[
$txt['ignore_twitter'] = 'Minimal Tweet';]]></add>
		</operation>
	</file>
</modification>
